Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 14 | * limitations under the License |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 15 | */ |
| 16 | |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 18 | |
| 19 | import static junit.framework.Assert.assertNotNull; |
| 20 | import static junit.framework.Assert.assertNull; |
| 21 | import static junit.framework.Assert.assertTrue; |
| 22 | |
| 23 | import static org.junit.Assert.assertEquals; |
| 24 | import static org.mockito.ArgumentMatchers.any; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 25 | import static org.mockito.ArgumentMatchers.eq; |
| 26 | import static org.mockito.Mockito.doAnswer; |
Mady Mellor | 0ad5b9d | 2019-01-08 14:59:55 -0800 | [diff] [blame] | 27 | import static org.mockito.Mockito.inOrder; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 28 | import static org.mockito.Mockito.mock; |
| 29 | import static org.mockito.Mockito.never; |
| 30 | import static org.mockito.Mockito.verify; |
| 31 | import static org.mockito.Mockito.when; |
| 32 | |
| 33 | import android.app.ActivityManager; |
| 34 | import android.app.Notification; |
Dan Sandler | 1d958f8 | 2018-01-09 21:10:26 -0500 | [diff] [blame] | 35 | import android.app.NotificationManager; |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 36 | import android.app.PendingIntent; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 37 | import android.content.Context; |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 38 | import android.content.Intent; |
| 39 | import android.graphics.drawable.Icon; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 40 | import android.os.Handler; |
| 41 | import android.os.Looper; |
| 42 | import android.os.UserHandle; |
| 43 | import android.service.notification.NotificationListenerService; |
| 44 | import android.service.notification.StatusBarNotification; |
| 45 | import android.support.test.filters.SmallTest; |
| 46 | import android.testing.AndroidTestingRunner; |
| 47 | import android.testing.TestableLooper; |
Ned Burns | a5dad55 | 2019-01-29 17:59:10 -0500 | [diff] [blame] | 48 | import android.util.ArraySet; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 49 | import android.widget.FrameLayout; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 50 | |
Ned Burns | a5dad55 | 2019-01-29 17:59:10 -0500 | [diff] [blame] | 51 | import androidx.annotation.NonNull; |
| 52 | |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 53 | import com.android.internal.logging.MetricsLogger; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 54 | import com.android.systemui.Dependency; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 55 | import com.android.systemui.ForegroundServiceController; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 56 | import com.android.systemui.InitController; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 57 | import com.android.systemui.R; |
| 58 | import com.android.systemui.SysuiTestCase; |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 59 | import com.android.systemui.statusbar.NotificationLifetimeExtender; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 60 | import com.android.systemui.statusbar.NotificationListener; |
| 61 | import com.android.systemui.statusbar.NotificationLockscreenUserManager; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 62 | import com.android.systemui.statusbar.NotificationPresenter; |
| 63 | import com.android.systemui.statusbar.NotificationRemoteInputManager; |
| 64 | import com.android.systemui.statusbar.RemoteInputController; |
| 65 | import com.android.systemui.statusbar.SmartReplyController; |
| 66 | import com.android.systemui.statusbar.StatusBarIconView; |
Mady Mellor | 0ad5b9d | 2019-01-08 14:59:55 -0800 | [diff] [blame] | 67 | import com.android.systemui.statusbar.notification.collection.NotificationData; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 68 | import com.android.systemui.statusbar.notification.collection.NotificationData.KeyguardEnvironment; |
| 69 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Ned Burns | c586467 | 2019-02-20 12:57:29 -0500 | [diff] [blame] | 70 | import com.android.systemui.statusbar.notification.collection.NotificationRowBinder; |
| 71 | import com.android.systemui.statusbar.notification.collection.NotificationRowBinderImpl; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 72 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
Ned Burns | 1a5e22f | 2019-02-14 15:11:52 -0500 | [diff] [blame] | 73 | import com.android.systemui.statusbar.notification.row.NotificationContentInflater.InflationFlag; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 74 | import com.android.systemui.statusbar.notification.row.NotificationGutsManager; |
| 75 | import com.android.systemui.statusbar.notification.row.RowInflaterTask; |
| 76 | import com.android.systemui.statusbar.notification.stack.NotificationListContainer; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 77 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 78 | import com.android.systemui.statusbar.phone.ShadeController; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 79 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
| 80 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 81 | |
| 82 | import org.junit.Before; |
| 83 | import org.junit.Test; |
| 84 | import org.junit.runner.RunWith; |
| 85 | import org.mockito.ArgumentCaptor; |
Mady Mellor | 0ad5b9d | 2019-01-08 14:59:55 -0800 | [diff] [blame] | 86 | import org.mockito.InOrder; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 87 | import org.mockito.Mock; |
| 88 | import org.mockito.MockitoAnnotations; |
| 89 | |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 90 | import java.util.ArrayList; |
| 91 | import java.util.Arrays; |
Ned Burns | a5dad55 | 2019-01-29 17:59:10 -0500 | [diff] [blame] | 92 | import java.util.Set; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 93 | import java.util.concurrent.CountDownLatch; |
| 94 | import java.util.concurrent.TimeUnit; |
| 95 | |
| 96 | @SmallTest |
| 97 | @RunWith(AndroidTestingRunner.class) |
| 98 | @TestableLooper.RunWithLooper |
| 99 | public class NotificationEntryManagerTest extends SysuiTestCase { |
| 100 | private static final String TEST_PACKAGE_NAME = "test"; |
| 101 | private static final int TEST_UID = 0; |
| 102 | |
| 103 | @Mock private NotificationPresenter mPresenter; |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 104 | @Mock private KeyguardEnvironment mEnvironment; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 105 | @Mock private ExpandableNotificationRow mRow; |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 106 | @Mock private NotificationListContainer mListContainer; |
Ned Burns | c586467 | 2019-02-20 12:57:29 -0500 | [diff] [blame] | 107 | @Mock private NotificationEntryListener mEntryListener; |
| 108 | @Mock private NotificationRowBinderImpl.BindRowCallback mBindCallback; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 109 | @Mock private HeadsUpManager mHeadsUpManager; |
| 110 | @Mock private NotificationListenerService.RankingMap mRankingMap; |
| 111 | @Mock private RemoteInputController mRemoteInputController; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 112 | |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 113 | // Dependency mocks: |
| 114 | @Mock private ForegroundServiceController mForegroundServiceController; |
| 115 | @Mock private NotificationLockscreenUserManager mLockscreenUserManager; |
| 116 | @Mock private NotificationGroupManager mGroupManager; |
| 117 | @Mock private NotificationGutsManager mGutsManager; |
| 118 | @Mock private NotificationRemoteInputManager mRemoteInputManager; |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 119 | @Mock private NotificationListener mNotificationListener; |
| 120 | @Mock private DeviceProvisionedController mDeviceProvisionedController; |
| 121 | @Mock private VisualStabilityManager mVisualStabilityManager; |
| 122 | @Mock private MetricsLogger mMetricsLogger; |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 123 | @Mock private SmartReplyController mSmartReplyController; |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 124 | @Mock private RowInflaterTask mAsyncInflationTask; |
Ned Burns | ef2ef6c | 2019-01-02 16:48:08 -0500 | [diff] [blame] | 125 | @Mock private NotificationRowBinder mMockedRowBinder; |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 126 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 127 | private NotificationEntry mEntry; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 128 | private StatusBarNotification mSbn; |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 129 | private TestableNotificationEntryManager mEntryManager; |
| 130 | private CountDownLatch mCountDownLatch; |
| 131 | |
| 132 | private class TestableNotificationEntryManager extends NotificationEntryManager { |
| 133 | private final CountDownLatch mCountDownLatch; |
| 134 | |
Gus Prevas | ca1b6f7 | 2018-12-28 10:53:11 -0500 | [diff] [blame] | 135 | TestableNotificationEntryManager(Context context) { |
Eliot Courtney | 6c313d3 | 2017-12-14 19:57:51 +0900 | [diff] [blame] | 136 | super(context); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 137 | mCountDownLatch = new CountDownLatch(1); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 138 | } |
| 139 | |
Mady Mellor | 0ad5b9d | 2019-01-08 14:59:55 -0800 | [diff] [blame] | 140 | public void setNotificationData(NotificationData data) { |
| 141 | mNotificationData = data; |
| 142 | } |
| 143 | |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 144 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 145 | public void onAsyncInflationFinished(NotificationEntry entry, |
Ned Burns | 1a5e22f | 2019-02-14 15:11:52 -0500 | [diff] [blame] | 146 | @InflationFlag int inflatedFlags) { |
Kevin | d4660b2 | 2018-09-27 10:57:35 -0700 | [diff] [blame] | 147 | super.onAsyncInflationFinished(entry, inflatedFlags); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 148 | |
| 149 | mCountDownLatch.countDown(); |
| 150 | } |
| 151 | |
| 152 | public CountDownLatch getCountDownLatch() { |
| 153 | return mCountDownLatch; |
| 154 | } |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 155 | |
| 156 | public ArrayList<NotificationLifetimeExtender> getLifetimeExtenders() { |
| 157 | return mNotificationLifetimeExtenders; |
| 158 | } |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 159 | } |
| 160 | |
Dan Sandler | 1d958f8 | 2018-01-09 21:10:26 -0500 | [diff] [blame] | 161 | private void setUserSentiment(String key, int sentiment) { |
| 162 | doAnswer(invocationOnMock -> { |
| 163 | NotificationListenerService.Ranking ranking = (NotificationListenerService.Ranking) |
| 164 | invocationOnMock.getArguments()[1]; |
| 165 | ranking.populate( |
| 166 | key, |
| 167 | 0, |
| 168 | false, |
| 169 | 0, |
| 170 | 0, |
| 171 | NotificationManager.IMPORTANCE_DEFAULT, |
| 172 | null, null, |
Julia Reynolds | 4509ce7 | 2019-01-31 13:12:43 -0500 | [diff] [blame] | 173 | null, null, null, true, sentiment, false, -1, false, null, null, false); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 174 | return true; |
| 175 | }).when(mRankingMap).getRanking(eq(key), any(NotificationListenerService.Ranking.class)); |
| 176 | } |
| 177 | |
| 178 | private void setSmartActions(String key, ArrayList<Notification.Action> smartActions) { |
| 179 | doAnswer(invocationOnMock -> { |
| 180 | NotificationListenerService.Ranking ranking = (NotificationListenerService.Ranking) |
| 181 | invocationOnMock.getArguments()[1]; |
| 182 | ranking.populate( |
| 183 | key, |
| 184 | 0, |
| 185 | false, |
| 186 | 0, |
| 187 | 0, |
| 188 | NotificationManager.IMPORTANCE_DEFAULT, |
| 189 | null, null, |
| 190 | null, null, null, true, |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 191 | NotificationListenerService.Ranking.USER_SENTIMENT_NEUTRAL, false, -1, |
Julia Reynolds | 4509ce7 | 2019-01-31 13:12:43 -0500 | [diff] [blame] | 192 | false, smartActions, null, false); |
Dan Sandler | 1d958f8 | 2018-01-09 21:10:26 -0500 | [diff] [blame] | 193 | return true; |
| 194 | }).when(mRankingMap).getRanking(eq(key), any(NotificationListenerService.Ranking.class)); |
| 195 | } |
| 196 | |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 197 | @Before |
| 198 | public void setUp() { |
| 199 | MockitoAnnotations.initMocks(this); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 200 | mDependency.injectMockDependency(ShadeController.class); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 201 | mDependency.injectTestDependency(ForegroundServiceController.class, |
| 202 | mForegroundServiceController); |
| 203 | mDependency.injectTestDependency(NotificationLockscreenUserManager.class, |
| 204 | mLockscreenUserManager); |
| 205 | mDependency.injectTestDependency(NotificationGroupManager.class, mGroupManager); |
| 206 | mDependency.injectTestDependency(NotificationGutsManager.class, mGutsManager); |
| 207 | mDependency.injectTestDependency(NotificationRemoteInputManager.class, mRemoteInputManager); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 208 | mDependency.injectTestDependency(NotificationListener.class, mNotificationListener); |
| 209 | mDependency.injectTestDependency(DeviceProvisionedController.class, |
| 210 | mDeviceProvisionedController); |
| 211 | mDependency.injectTestDependency(VisualStabilityManager.class, mVisualStabilityManager); |
| 212 | mDependency.injectTestDependency(MetricsLogger.class, mMetricsLogger); |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 213 | mDependency.injectTestDependency(SmartReplyController.class, mSmartReplyController); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 214 | mDependency.injectTestDependency(KeyguardEnvironment.class, mEnvironment); |
Eliot Courtney | 8f56b0e | 2017-12-14 18:54:28 +0900 | [diff] [blame] | 215 | |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 216 | mCountDownLatch = new CountDownLatch(1); |
| 217 | |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 218 | mDependency.injectTestDependency(Dependency.MAIN_HANDLER, |
| 219 | Handler.createAsync(Looper.myLooper())); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 220 | when(mRemoteInputManager.getController()).thenReturn(mRemoteInputController); |
Eliot Courtney | 2b4c3a0 | 2017-11-27 13:27:46 +0900 | [diff] [blame] | 221 | when(mListContainer.getViewParentForNotification(any())).thenReturn( |
| 222 | new FrameLayout(mContext)); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 223 | |
| 224 | Notification.Builder n = new Notification.Builder(mContext, "") |
| 225 | .setSmallIcon(R.drawable.ic_person) |
| 226 | .setContentTitle("Title") |
| 227 | .setContentText("Text"); |
| 228 | mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID, |
| 229 | 0, n.build(), new UserHandle(ActivityManager.getCurrentUser()), null, 0); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 230 | mEntry = new NotificationEntry(mSbn); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 231 | mEntry.expandedIcon = mock(StatusBarIconView.class); |
| 232 | |
Gus Prevas | ca1b6f7 | 2018-12-28 10:53:11 -0500 | [diff] [blame] | 233 | mEntryManager = new TestableNotificationEntryManager(mContext); |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 234 | Dependency.get(InitController.class).executePostInitTasks(); |
Gus Prevas | 8621bd2 | 2018-12-20 15:04:25 -0500 | [diff] [blame] | 235 | mEntryManager.setUpWithPresenter(mPresenter, mListContainer, mHeadsUpManager); |
| 236 | mEntryManager.addNotificationEntryListener(mEntryListener); |
Gus Prevas | 8ba88a8 | 2018-12-18 11:13:44 -0500 | [diff] [blame] | 237 | |
Ned Burns | c586467 | 2019-02-20 12:57:29 -0500 | [diff] [blame] | 238 | NotificationRowBinderImpl notificationRowBinder = |
| 239 | new NotificationRowBinderImpl(mContext, true /* allowLongPress */); |
Gus Prevas | 8ba88a8 | 2018-12-18 11:13:44 -0500 | [diff] [blame] | 240 | notificationRowBinder.setUpWithPresenter( |
| 241 | mPresenter, mListContainer, mHeadsUpManager, mEntryManager, mBindCallback); |
| 242 | notificationRowBinder.setNotificationClicker(mock(NotificationClicker.class)); |
Ned Burns | c586467 | 2019-02-20 12:57:29 -0500 | [diff] [blame] | 243 | mEntryManager.setRowBinder(notificationRowBinder); |
Dan Sandler | 1d958f8 | 2018-01-09 21:10:26 -0500 | [diff] [blame] | 244 | |
| 245 | setUserSentiment(mEntry.key, NotificationListenerService.Ranking.USER_SENTIMENT_NEUTRAL); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | @Test |
| 249 | public void testAddNotification() throws Exception { |
| 250 | com.android.systemui.util.Assert.isNotMainThread(); |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 251 | TestableLooper.get(this).processAllMessages(); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 252 | |
| 253 | doAnswer(invocation -> { |
| 254 | mCountDownLatch.countDown(); |
| 255 | return null; |
Gus Prevas | 8ba88a8 | 2018-12-18 11:13:44 -0500 | [diff] [blame] | 256 | }).when(mBindCallback).onBindRow(any(), any(), any(), any()); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 257 | |
| 258 | // Post on main thread, otherwise we will be stuck waiting here for the inflation finished |
| 259 | // callback forever, since it won't execute until the tests ends. |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 260 | mEntryManager.addNotification(mSbn, mRankingMap); |
| 261 | TestableLooper.get(this).processMessages(1); |
| 262 | assertTrue(mCountDownLatch.await(10, TimeUnit.SECONDS)); |
| 263 | assertTrue(mEntryManager.getCountDownLatch().await(10, TimeUnit.SECONDS)); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 264 | |
| 265 | // Check that no inflation error occurred. |
Gus Prevas | ca1b6f7 | 2018-12-28 10:53:11 -0500 | [diff] [blame] | 266 | verify(mEntryListener, never()).onInflationError(any(), any()); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 267 | |
| 268 | // Row inflation: |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 269 | ArgumentCaptor<NotificationEntry> entryCaptor = ArgumentCaptor.forClass( |
| 270 | NotificationEntry.class); |
Gus Prevas | 8ba88a8 | 2018-12-18 11:13:44 -0500 | [diff] [blame] | 271 | verify(mBindCallback).onBindRow(entryCaptor.capture(), any(), eq(mSbn), any()); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 272 | NotificationEntry entry = entryCaptor.getValue(); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 273 | verify(mRemoteInputManager).bindRow(entry.getRow()); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 274 | |
| 275 | // Row content inflation: |
Gus Prevas | 8621bd2 | 2018-12-20 15:04:25 -0500 | [diff] [blame] | 276 | verify(mEntryListener).onNotificationAdded(entry); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 277 | verify(mPresenter).updateNotificationViews(); |
| 278 | |
| 279 | assertEquals(mEntryManager.getNotificationData().get(mSbn.getKey()), entry); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 280 | assertNotNull(entry.getRow()); |
Dan Sandler | 1d958f8 | 2018-01-09 21:10:26 -0500 | [diff] [blame] | 281 | assertEquals(mEntry.userSentiment, |
| 282 | NotificationListenerService.Ranking.USER_SENTIMENT_NEUTRAL); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | @Test |
| 286 | public void testUpdateNotification() throws Exception { |
| 287 | com.android.systemui.util.Assert.isNotMainThread(); |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 288 | TestableLooper.get(this).processAllMessages(); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 289 | |
| 290 | mEntryManager.getNotificationData().add(mEntry); |
| 291 | |
Dan Sandler | 1d958f8 | 2018-01-09 21:10:26 -0500 | [diff] [blame] | 292 | setUserSentiment(mEntry.key, NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE); |
| 293 | |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 294 | mEntryManager.updateNotification(mSbn, mRankingMap); |
| 295 | TestableLooper.get(this).processMessages(1); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 296 | // Wait for content update. |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 297 | assertTrue(mEntryManager.getCountDownLatch().await(10, TimeUnit.SECONDS)); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 298 | |
Gus Prevas | ca1b6f7 | 2018-12-28 10:53:11 -0500 | [diff] [blame] | 299 | verify(mEntryListener, never()).onInflationError(any(), any()); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 300 | |
Mady Mellor | 0ad5b9d | 2019-01-08 14:59:55 -0800 | [diff] [blame] | 301 | verify(mEntryListener).onPreEntryUpdated(mEntry); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 302 | verify(mPresenter).updateNotificationViews(); |
Mady Mellor | 0ad5b9d | 2019-01-08 14:59:55 -0800 | [diff] [blame] | 303 | verify(mEntryListener).onPostEntryUpdated(mEntry); |
| 304 | |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 305 | assertNotNull(mEntry.getRow()); |
Dan Sandler | 1d958f8 | 2018-01-09 21:10:26 -0500 | [diff] [blame] | 306 | assertEquals(mEntry.userSentiment, |
| 307 | NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | @Test |
Mady Mellor | 0ad5b9d | 2019-01-08 14:59:55 -0800 | [diff] [blame] | 311 | public void testUpdateNotification_prePostEntryOrder() throws Exception { |
| 312 | com.android.systemui.util.Assert.isNotMainThread(); |
| 313 | TestableLooper.get(this).processAllMessages(); |
| 314 | |
| 315 | NotificationData notifData = mock(NotificationData.class); |
| 316 | when(notifData.get(mEntry.key)).thenReturn(mEntry); |
| 317 | |
| 318 | mEntryManager.setNotificationData(notifData); |
| 319 | |
| 320 | mEntryManager.updateNotification(mSbn, mRankingMap); |
| 321 | TestableLooper.get(this).processMessages(1); |
| 322 | // Wait for content update. |
| 323 | assertTrue(mEntryManager.getCountDownLatch().await(10, TimeUnit.SECONDS)); |
| 324 | |
| 325 | verify(mEntryListener, never()).onInflationError(any(), any()); |
| 326 | |
| 327 | // Ensure that update callbacks happen in correct order |
| 328 | InOrder order = inOrder(mEntryListener, notifData, mPresenter, mEntryListener); |
| 329 | order.verify(mEntryListener).onPreEntryUpdated(mEntry); |
| 330 | order.verify(notifData).filterAndSort(); |
| 331 | order.verify(mPresenter).updateNotificationViews(); |
| 332 | order.verify(mEntryListener).onPostEntryUpdated(mEntry); |
| 333 | |
| 334 | assertNotNull(mEntry.getRow()); |
| 335 | } |
| 336 | |
| 337 | @Test |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 338 | public void testRemoveNotification() throws Exception { |
| 339 | com.android.systemui.util.Assert.isNotMainThread(); |
| 340 | |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 341 | mEntry.setRow(mRow); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 342 | mEntryManager.getNotificationData().add(mEntry); |
| 343 | |
Jason Monk | 6dceace | 2018-05-15 20:24:07 -0400 | [diff] [blame] | 344 | mEntryManager.removeNotification(mSbn.getKey(), mRankingMap); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 345 | |
Gus Prevas | ca1b6f7 | 2018-12-28 10:53:11 -0500 | [diff] [blame] | 346 | verify(mEntryListener, never()).onInflationError(any(), any()); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 347 | |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 348 | verify(mPresenter).updateNotificationViews(); |
Ned Burns | ef2ef6c | 2019-01-02 16:48:08 -0500 | [diff] [blame] | 349 | verify(mEntryListener).onEntryRemoved( |
| 350 | mEntry, null, false /* removedByUser */); |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 351 | verify(mRow).setRemoved(); |
| 352 | |
| 353 | assertNull(mEntryManager.getNotificationData().get(mSbn.getKey())); |
| 354 | } |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 355 | |
| 356 | @Test |
Ned Burns | ef2ef6c | 2019-01-02 16:48:08 -0500 | [diff] [blame] | 357 | public void testRemoveNotification_onEntryRemoveNotFiredIfEntryDoesntExist() { |
| 358 | com.android.systemui.util.Assert.isNotMainThread(); |
| 359 | |
| 360 | mEntryManager.removeNotification("not_a_real_key", mRankingMap); |
| 361 | |
| 362 | verify(mEntryListener, never()).onEntryRemoved( |
| 363 | mEntry, null, false /* removedByUser */); |
| 364 | } |
| 365 | |
| 366 | @Test |
| 367 | public void testRemoveNotification_whilePending() throws InterruptedException { |
| 368 | com.android.systemui.util.Assert.isNotMainThread(); |
| 369 | |
| 370 | mEntryManager.setRowBinder(mMockedRowBinder); |
| 371 | |
| 372 | mEntryManager.addNotification(mSbn, mRankingMap); |
| 373 | mEntryManager.removeNotification(mSbn.getKey(), mRankingMap); |
| 374 | |
| 375 | verify(mEntryListener, never()).onEntryRemoved( |
| 376 | mEntry, null, false /* removedByUser */); |
Kenny Guy | 8cc15d2 | 2018-05-09 09:50:55 +0100 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | @Test |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 380 | public void testUpdateNotificationRanking() { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 381 | when(mDeviceProvisionedController.isDeviceProvisioned()).thenReturn(true); |
| 382 | when(mEnvironment.isDeviceProvisioned()).thenReturn(true); |
| 383 | when(mEnvironment.isNotificationForCurrentProfiles(any())).thenReturn(true); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 384 | |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 385 | mEntry.setRow(mRow); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 386 | mEntry.setInflationTask(mAsyncInflationTask); |
| 387 | mEntryManager.getNotificationData().add(mEntry); |
| 388 | setSmartActions(mEntry.key, new ArrayList<>(Arrays.asList(createAction()))); |
| 389 | |
| 390 | mEntryManager.updateNotificationRanking(mRankingMap); |
Kevin | d4660b2 | 2018-09-27 10:57:35 -0700 | [diff] [blame] | 391 | verify(mRow).setEntry(eq(mEntry)); |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 392 | assertEquals(1, mEntry.systemGeneratedSmartActions.size()); |
| 393 | assertEquals("action", mEntry.systemGeneratedSmartActions.get(0).title); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | @Test |
| 397 | public void testUpdateNotificationRanking_noChange() { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 398 | when(mDeviceProvisionedController.isDeviceProvisioned()).thenReturn(true); |
| 399 | when(mEnvironment.isNotificationForCurrentProfiles(any())).thenReturn(true); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 400 | |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 401 | mEntry.setRow(mRow); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 402 | mEntryManager.getNotificationData().add(mEntry); |
| 403 | setSmartActions(mEntry.key, null); |
| 404 | |
| 405 | mEntryManager.updateNotificationRanking(mRankingMap); |
Kevin | d4660b2 | 2018-09-27 10:57:35 -0700 | [diff] [blame] | 406 | verify(mRow, never()).setEntry(eq(mEntry)); |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 407 | assertEquals(0, mEntry.systemGeneratedSmartActions.size()); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | @Test |
| 411 | public void testUpdateNotificationRanking_rowNotInflatedYet() { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 412 | when(mDeviceProvisionedController.isDeviceProvisioned()).thenReturn(true); |
| 413 | when(mEnvironment.isNotificationForCurrentProfiles(any())).thenReturn(true); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 414 | |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 415 | mEntry.setRow(null); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 416 | mEntryManager.getNotificationData().add(mEntry); |
| 417 | setSmartActions(mEntry.key, new ArrayList<>(Arrays.asList(createAction()))); |
| 418 | |
| 419 | mEntryManager.updateNotificationRanking(mRankingMap); |
Kevin | d4660b2 | 2018-09-27 10:57:35 -0700 | [diff] [blame] | 420 | verify(mRow, never()).setEntry(eq(mEntry)); |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 421 | assertEquals(1, mEntry.systemGeneratedSmartActions.size()); |
| 422 | assertEquals("action", mEntry.systemGeneratedSmartActions.get(0).title); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | @Test |
| 426 | public void testUpdateNotificationRanking_pendingNotification() { |
Jason Monk | 297c04e | 2018-08-23 17:16:59 -0400 | [diff] [blame] | 427 | when(mDeviceProvisionedController.isDeviceProvisioned()).thenReturn(true); |
| 428 | when(mEnvironment.isNotificationForCurrentProfiles(any())).thenReturn(true); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 429 | |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 430 | mEntry.setRow(null); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 431 | mEntryManager.mPendingNotifications.put(mEntry.key, mEntry); |
| 432 | setSmartActions(mEntry.key, new ArrayList<>(Arrays.asList(createAction()))); |
| 433 | |
| 434 | mEntryManager.updateNotificationRanking(mRankingMap); |
Kevin | d4660b2 | 2018-09-27 10:57:35 -0700 | [diff] [blame] | 435 | verify(mRow, never()).setEntry(eq(mEntry)); |
Gustav Sennton | 1463d83 | 2018-11-06 16:12:48 +0000 | [diff] [blame] | 436 | assertEquals(1, mEntry.systemGeneratedSmartActions.size()); |
| 437 | assertEquals("action", mEntry.systemGeneratedSmartActions.get(0).title); |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 438 | } |
| 439 | |
Ned Burns | a5dad55 | 2019-01-29 17:59:10 -0500 | [diff] [blame] | 440 | @Test |
| 441 | public void testLifetimeExtenders_ifNotificationIsRetainedItIsntRemoved() { |
| 442 | // GIVEN an entry manager with a notification |
| 443 | mEntryManager.setRowBinder(mMockedRowBinder); |
| 444 | mEntryManager.getNotificationData().add(mEntry); |
| 445 | |
| 446 | // GIVEN a lifetime extender that always tries to extend lifetime |
| 447 | NotificationLifetimeExtender extender = mock(NotificationLifetimeExtender.class); |
| 448 | when(extender.shouldExtendLifetime(mEntry)).thenReturn(true); |
| 449 | mEntryManager.addNotificationLifetimeExtender(extender); |
| 450 | |
| 451 | // WHEN the notification is removed |
| 452 | mEntryManager.removeNotification(mEntry.key, mRankingMap); |
| 453 | |
| 454 | // THEN the extender is asked to manage the lifetime |
| 455 | verify(extender).setShouldManageLifetime(mEntry, true); |
| 456 | // THEN the notification is retained |
| 457 | assertNotNull(mEntryManager.getNotificationData().get(mSbn.getKey())); |
| 458 | verify(mEntryListener, never()).onEntryRemoved(mEntry, null, false); |
| 459 | } |
| 460 | |
| 461 | @Test |
| 462 | public void testLifetimeExtenders_whenRetentionEndsNotificationIsRemoved() { |
| 463 | // GIVEN an entry manager with a notification whose life has been extended |
| 464 | mEntryManager.setRowBinder(mMockedRowBinder); |
| 465 | mEntryManager.getNotificationData().add(mEntry); |
| 466 | final FakeNotificationLifetimeExtender extender = new FakeNotificationLifetimeExtender(); |
| 467 | mEntryManager.addNotificationLifetimeExtender(extender); |
| 468 | mEntryManager.removeNotification(mEntry.key, mRankingMap); |
| 469 | assertTrue(extender.isManaging(mEntry.key)); |
| 470 | |
| 471 | // WHEN the extender finishes its extension |
| 472 | extender.setExtendLifetimes(false); |
| 473 | extender.getCallback().onSafeToRemove(mEntry.key); |
| 474 | |
| 475 | // THEN the notification is removed |
| 476 | assertNull(mEntryManager.getNotificationData().get(mSbn.getKey())); |
| 477 | verify(mEntryListener).onEntryRemoved(mEntry, null, false); |
| 478 | } |
| 479 | |
| 480 | @Test |
| 481 | public void testLifetimeExtenders_whenNotificationUpdatedRetainersAreCanceled() { |
| 482 | // GIVEN an entry manager with a notification whose life has been extended |
| 483 | mEntryManager.setRowBinder(mMockedRowBinder); |
| 484 | mEntryManager.getNotificationData().add(mEntry); |
| 485 | NotificationLifetimeExtender extender = mock(NotificationLifetimeExtender.class); |
| 486 | when(extender.shouldExtendLifetime(mEntry)).thenReturn(true); |
| 487 | mEntryManager.addNotificationLifetimeExtender(extender); |
| 488 | mEntryManager.removeNotification(mEntry.key, mRankingMap); |
| 489 | |
| 490 | // WHEN the notification is updated |
| 491 | mEntryManager.updateNotification(mEntry.notification, mRankingMap); |
| 492 | |
| 493 | // THEN the lifetime extension is canceled |
| 494 | verify(extender).setShouldManageLifetime(mEntry, false); |
| 495 | } |
| 496 | |
| 497 | @Test |
| 498 | public void testLifetimeExtenders_whenNewExtenderTakesPrecedenceOldExtenderIsCanceled() { |
| 499 | // GIVEN an entry manager with a notification |
| 500 | mEntryManager.setRowBinder(mMockedRowBinder); |
| 501 | mEntryManager.getNotificationData().add(mEntry); |
| 502 | |
| 503 | // GIVEN two lifetime extenders, the first which never extends and the second which |
| 504 | // always extends |
| 505 | NotificationLifetimeExtender extender1 = mock(NotificationLifetimeExtender.class); |
| 506 | when(extender1.shouldExtendLifetime(mEntry)).thenReturn(false); |
| 507 | NotificationLifetimeExtender extender2 = mock(NotificationLifetimeExtender.class); |
| 508 | when(extender2.shouldExtendLifetime(mEntry)).thenReturn(true); |
| 509 | mEntryManager.addNotificationLifetimeExtender(extender1); |
| 510 | mEntryManager.addNotificationLifetimeExtender(extender2); |
| 511 | |
| 512 | // GIVEN a notification was lifetime-extended and extender2 is managing it |
| 513 | mEntryManager.removeNotification(mEntry.key, mRankingMap); |
| 514 | verify(extender1, never()).setShouldManageLifetime(mEntry, true); |
| 515 | verify(extender2).setShouldManageLifetime(mEntry, true); |
| 516 | |
| 517 | // WHEN the extender1 changes its mind and wants to extend the lifetime of the notif |
| 518 | when(extender1.shouldExtendLifetime(mEntry)).thenReturn(true); |
| 519 | mEntryManager.removeNotification(mEntry.key, mRankingMap); |
| 520 | |
| 521 | // THEN extender2 stops managing the notif and extender1 starts managing it |
| 522 | verify(extender1).setShouldManageLifetime(mEntry, true); |
| 523 | verify(extender2).setShouldManageLifetime(mEntry, false); |
| 524 | } |
| 525 | |
Gustav Sennton | 744e7e1 | 2019-01-31 14:45:03 +0000 | [diff] [blame] | 526 | /** |
| 527 | * Ensure that calling NotificationEntryManager.performRemoveNotification() doesn't crash when |
| 528 | * given a notification that has already been removed from NotificationData. |
| 529 | */ |
| 530 | @Test |
| 531 | public void testPerformRemoveNotification_removedEntry() { |
| 532 | mEntryManager.getNotificationData().remove(mSbn.getKey(), null /* ranking */); |
| 533 | mEntryManager.performRemoveNotification(mSbn); |
| 534 | } |
| 535 | |
Tony Mak | 628cb93 | 2018-06-19 18:30:41 +0100 | [diff] [blame] | 536 | private Notification.Action createAction() { |
| 537 | return new Notification.Action.Builder( |
| 538 | Icon.createWithResource(getContext(), android.R.drawable.sym_def_app_icon), |
| 539 | "action", |
| 540 | PendingIntent.getBroadcast(getContext(), 0, new Intent("Action"), 0)).build(); |
| 541 | } |
Ned Burns | a5dad55 | 2019-01-29 17:59:10 -0500 | [diff] [blame] | 542 | |
| 543 | private static class FakeNotificationLifetimeExtender implements NotificationLifetimeExtender { |
| 544 | private NotificationSafeToRemoveCallback mCallback; |
| 545 | private boolean mExtendLifetimes = true; |
| 546 | private Set<String> mManagedNotifs = new ArraySet<>(); |
| 547 | |
| 548 | @Override |
| 549 | public void setCallback(@NonNull NotificationSafeToRemoveCallback callback) { |
| 550 | mCallback = callback; |
| 551 | } |
| 552 | |
| 553 | @Override |
| 554 | public boolean shouldExtendLifetime(@NonNull NotificationEntry entry) { |
| 555 | return mExtendLifetimes; |
| 556 | } |
| 557 | |
| 558 | @Override |
| 559 | public void setShouldManageLifetime( |
| 560 | @NonNull NotificationEntry entry, |
| 561 | boolean shouldManage) { |
| 562 | final boolean hasEntry = mManagedNotifs.contains(entry.key); |
| 563 | if (shouldManage) { |
| 564 | if (hasEntry) { |
| 565 | throw new RuntimeException("Already managing this entry: " + entry.key); |
| 566 | } |
| 567 | mManagedNotifs.add(entry.key); |
| 568 | } else { |
| 569 | if (!hasEntry) { |
| 570 | throw new RuntimeException("Not managing this entry: " + entry.key); |
| 571 | } |
| 572 | mManagedNotifs.remove(entry.key); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | public void setExtendLifetimes(boolean extendLifetimes) { |
| 577 | mExtendLifetimes = extendLifetimes; |
| 578 | } |
| 579 | |
| 580 | public NotificationSafeToRemoveCallback getCallback() { |
| 581 | return mCallback; |
| 582 | } |
| 583 | |
| 584 | public boolean isManaging(String notificationKey) { |
| 585 | return mManagedNotifs.contains(notificationKey); |
| 586 | } |
| 587 | } |
Eliot Courtney | a6d8cf2 | 2017-10-20 13:26:58 +0900 | [diff] [blame] | 588 | } |