From 636c379f2e2af3a4ba9d58b43ab72929ab9a0120 Mon Sep 17 00:00:00 2001 From: Ned Burns Date: Wed, 11 Sep 2019 16:59:07 -0400 Subject: [PATCH] Move remaining tests over to using NotificationEntryBuilder Remove the need for the dreaded NotificationEntry.buildForTest(). Test: atest Change-Id: Ic9938acc729da2dfa806f2ecf1f3fe4577b46cd2 --- .../collection/NotificationEntry.java | 34 +-- .../ForegroundServiceControllerTest.java | 8 +- ...groundServiceNotificationListenerTest.java | 26 +- .../systemui/bubbles/BubbleDataTest.java | 3 +- .../android/systemui/bubbles/BubbleTest.java | 25 +- .../AlertingNotificationManagerTest.java | 8 +- .../statusbar/NotificationEntryBuilder.java | 11 +- .../statusbar/NotificationEntryHelper.java | 21 ++ .../statusbar/NotificationListenerTest.java | 7 +- .../NotificationRemoteInputManagerTest.java | 17 +- .../statusbar/NotificationTestHelper.java | 32 +-- .../NotificationViewHierarchyManagerTest.java | 4 +- .../systemui/statusbar/RankingBuilder.java | 11 + .../systemui/statusbar/SbnBuilder.java | 16 ++ .../statusbar/SmartReplyControllerTest.java | 4 +- .../NotificationListControllerTest.java | 23 +- .../VisualStabilityManagerTest.java | 4 +- .../collection/NotificationDataTest.java | 251 ++++++++++-------- .../logging/NotificationLoggerTest.java | 13 +- .../row/NotificationMenuRowTest.java | 11 +- .../phone/HeadsUpManagerPhoneTest.java | 5 +- .../phone/NotificationGroupTestHelper.java | 24 +- .../StatusBarNotificationPresenterTest.java | 25 +- .../statusbar/policy/SmartReplyViewTest.java | 11 +- 24 files changed, 335 insertions(+), 259 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java index d1b05603223d2..71cdcf748679a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java @@ -148,35 +148,11 @@ public final class NotificationEntry { private boolean mPulseSupressed; public NotificationEntry( - StatusBarNotification sbn, + @NonNull StatusBarNotification sbn, @NonNull Ranking ranking) { - this(sbn, ranking, false); - } - - private NotificationEntry( - StatusBarNotification sbn, - Ranking ranking, - boolean isTest) { this.key = sbn.getKey(); - this.notification = sbn; - - // TODO: Update tests to no longer need to pass null ranking - if (ranking != null) { - setRanking(ranking); - } else if (!isTest) { - throw new IllegalArgumentException("Ranking cannot be null"); - } - } - - /** - * Method for old tests that build NotificationEntries without a ranking. - * - * @deprecated Use NotificationEntryBuilder instead. - */ - @VisibleForTesting - @Deprecated - public static NotificationEntry buildForTest(StatusBarNotification sbn) { - return new NotificationEntry(sbn, null, true); + setNotification(sbn); + setRanking(ranking); } /** The key for this notification. Guaranteed to be immutable and unique */ @@ -218,6 +194,10 @@ public final class NotificationEntry { * TODO: Make this package-private */ public void setRanking(@NonNull Ranking ranking) { + if (!ranking.getKey().equals(key)) { + throw new IllegalArgumentException("New key " + ranking.getKey() + + " doesn't match existing key " + key); + } mRanking = ranking; } diff --git a/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java index 9aeb147cc7250..5c4ef18b61a6a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java @@ -393,8 +393,12 @@ public class ForegroundServiceControllerTest extends SysuiTestCase { } private void entryRemoved(StatusBarNotification notification) { - mEntryListener.onEntryRemoved(NotificationEntry.buildForTest(notification), - null, false); + mEntryListener.onEntryRemoved( + new NotificationEntryBuilder() + .setSbn(notification) + .build(), + null, + false); } private void entryAdded(StatusBarNotification notification, int importance) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceNotificationListenerTest.java b/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceNotificationListenerTest.java index 5943b02b4e4a5..212c93dc576db 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceNotificationListenerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceNotificationListenerTest.java @@ -17,19 +17,17 @@ package com.android.systemui; import static com.android.systemui.ForegroundServiceLifetimeExtender.MIN_FGS_TIME_MS; +import static com.android.systemui.statusbar.NotificationEntryHelper.modifySbn; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import android.app.Notification; -import android.service.notification.NotificationListenerService.Ranking; -import android.service.notification.StatusBarNotification; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; +import com.android.systemui.statusbar.NotificationEntryBuilder; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import org.junit.Before; @@ -40,7 +38,6 @@ import org.junit.runner.RunWith; @SmallTest public class ForegroundServiceNotificationListenerTest extends SysuiTestCase { private ForegroundServiceLifetimeExtender mExtender = new ForegroundServiceLifetimeExtender(); - private StatusBarNotification mSbn; private NotificationEntry mEntry; private Notification mNotif; @@ -52,10 +49,9 @@ public class ForegroundServiceNotificationListenerTest extends SysuiTestCase { .setContentText("Text") .build(); - mSbn = mock(StatusBarNotification.class); - when(mSbn.getNotification()).thenReturn(mNotif); - - mEntry = new NotificationEntry(mSbn, mock(Ranking.class)); + mEntry = new NotificationEntryBuilder() + .setNotification(mNotif) + .build(); } /** @@ -66,21 +62,27 @@ public class ForegroundServiceNotificationListenerTest extends SysuiTestCase { // Extend the lifetime of a FGS notification iff it has not been visible // for the minimum time mNotif.flags |= Notification.FLAG_FOREGROUND_SERVICE; - when(mSbn.getPostTime()).thenReturn(System.currentTimeMillis()); + modifySbn(mEntry) + .setPostTime(System.currentTimeMillis()) + .build(); assertTrue(mExtender.shouldExtendLifetime(mEntry)); } @Test public void testShouldExtendLifetime_shouldNot_foreground() { mNotif.flags |= Notification.FLAG_FOREGROUND_SERVICE; - when(mSbn.getPostTime()).thenReturn(System.currentTimeMillis() - MIN_FGS_TIME_MS - 1); + modifySbn(mEntry) + .setPostTime(System.currentTimeMillis() - MIN_FGS_TIME_MS - 1) + .build(); assertFalse(mExtender.shouldExtendLifetime(mEntry)); } @Test public void testShouldExtendLifetime_shouldNot_notForeground() { mNotif.flags = 0; - when(mSbn.getPostTime()).thenReturn(System.currentTimeMillis() - MIN_FGS_TIME_MS - 1); + modifySbn(mEntry) + .setPostTime(System.currentTimeMillis() - MIN_FGS_TIME_MS - 1) + .build(); assertFalse(mExtender.shouldExtendLifetime(mEntry)); } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleDataTest.java b/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleDataTest.java index 238cfd78bfaf8..392a7cbc4d6cc 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleDataTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleDataTest.java @@ -37,6 +37,7 @@ import androidx.test.filters.SmallTest; import com.android.systemui.SysuiTestCase; import com.android.systemui.bubbles.BubbleData.TimeSource; +import com.android.systemui.statusbar.NotificationEntryBuilder; import com.android.systemui.statusbar.NotificationTestHelper; import com.android.systemui.statusbar.notification.collection.NotificationEntry; @@ -878,7 +879,7 @@ public class BubbleDataTest extends SysuiTestCase { when(sbn.getNotification()).thenReturn(notification); // NotificationEntry -> StatusBarNotification -> Notification -> BubbleMetadata - return NotificationEntry.buildForTest(sbn); + return new NotificationEntryBuilder().setSbn(sbn).build(); } private void setCurrentTime(long time) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleTest.java b/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleTest.java index 04cf4bb4c94bb..57578611e3f23 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/bubbles/BubbleTest.java @@ -19,19 +19,16 @@ package com.android.systemui.bubbles; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.when; import android.app.Notification; import android.os.Bundle; -import android.service.notification.NotificationListenerService.Ranking; -import android.os.UserHandle; -import android.service.notification.StatusBarNotification; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import androidx.test.filters.SmallTest; import com.android.systemui.SysuiTestCase; +import com.android.systemui.statusbar.NotificationEntryBuilder; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import org.junit.Before; @@ -44,8 +41,6 @@ import org.mockito.MockitoAnnotations; @RunWith(AndroidTestingRunner.class) @TestableLooper.RunWithLooper public class BubbleTest extends SysuiTestCase { - @Mock - private StatusBarNotification mStatusBarNotification; @Mock private Notification mNotif; @@ -57,27 +52,15 @@ public class BubbleTest extends SysuiTestCase { public void setUp() { MockitoAnnotations.initMocks(this); - when(mStatusBarNotification.getKey()).thenReturn("key"); - when(mStatusBarNotification.getNotification()).thenReturn(mNotif); - when(mStatusBarNotification.getUser()).thenReturn(new UserHandle(0)); mExtras = new Bundle(); mNotif.extras = mExtras; - mEntry = NotificationEntry.buildForTest(mStatusBarNotification); + mEntry = new NotificationEntryBuilder() + .setNotification(mNotif) + .build(); mBubble = new Bubble(mContext, mEntry); } - @Test - public void testInitialization() { - final Ranking ranking = new Ranking(); - - final NotificationEntry entry = new NotificationEntry(mStatusBarNotification, ranking); - - assertEquals("key", entry.key()); - assertEquals(mStatusBarNotification, entry.sbn()); - assertEquals(ranking, entry.ranking()); - } - @Test public void testGetUpdateMessage_default() { final String msg = "Hello there!"; diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/AlertingNotificationManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/AlertingNotificationManagerTest.java index e6f36e6abbfd4..cf5a12fcc2afb 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/AlertingNotificationManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/AlertingNotificationManagerTest.java @@ -129,7 +129,9 @@ public class AlertingNotificationManagerTest extends SysuiTestCase { public void setUp() { mTestHandler = Handler.createAsync(Looper.myLooper()); mSbn = createNewNotification(0 /* id */); - mEntry = NotificationEntry.buildForTest(mSbn); + mEntry = new NotificationEntryBuilder() + .setSbn(mSbn) + .build(); mEntry.setRow(mRow); mAlertingNotificationManager = createAlertingNotificationManager(); @@ -180,7 +182,9 @@ public class AlertingNotificationManagerTest extends SysuiTestCase { public void testReleaseAllImmediately() { for (int i = 0; i < TEST_NUM_NOTIFICATIONS; i++) { StatusBarNotification sbn = createNewNotification(i); - NotificationEntry entry = NotificationEntry.buildForTest(sbn); + NotificationEntry entry = new NotificationEntryBuilder() + .setSbn(sbn) + .build(); entry.setRow(mRow); mAlertingNotificationManager.showNotification(entry); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationEntryBuilder.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationEntryBuilder.java index ded3ba592abe3..fcfdd11a19069 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationEntryBuilder.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationEntryBuilder.java @@ -38,7 +38,6 @@ import java.util.ArrayList; public class NotificationEntryBuilder { private final SbnBuilder mSbnBuilder = new SbnBuilder(); private final RankingBuilder mRankingBuilder = new RankingBuilder(); - private StatusBarNotification mSbn = null; public NotificationEntry build() { @@ -193,8 +192,18 @@ public class NotificationEntryBuilder { return this; } + public NotificationEntryBuilder setSmartActions(Notification.Action... smartActions) { + mRankingBuilder.setSmartActions(smartActions); + return this; + } + public NotificationEntryBuilder setSmartReplies(ArrayList smartReplies) { mRankingBuilder.setSmartReplies(smartReplies); return this; } + + public NotificationEntryBuilder setSmartReplies(CharSequence... smartReplies) { + mRankingBuilder.setSmartReplies(smartReplies); + return this; + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationEntryHelper.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationEntryHelper.java index b5168c6452d1d..33b0d2c32ba16 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationEntryHelper.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationEntryHelper.java @@ -17,6 +17,7 @@ package com.android.systemui.statusbar; import android.service.notification.NotificationListenerService.Ranking; +import android.service.notification.StatusBarNotification; import com.android.internal.annotations.VisibleForTesting; import com.android.systemui.statusbar.notification.collection.NotificationEntry; @@ -27,6 +28,10 @@ public class NotificationEntryHelper { return new ModifiedRankingBuilder(entry); } + public static ModifiedSbnBuilder modifySbn(NotificationEntry entry) { + return new ModifiedSbnBuilder(entry); + } + public static class ModifiedRankingBuilder extends RankingBuilder { private final NotificationEntry mTarget; @@ -42,4 +47,20 @@ public class NotificationEntryHelper { return ranking; } } + + public static class ModifiedSbnBuilder extends SbnBuilder { + private final NotificationEntry mTarget; + + private ModifiedSbnBuilder(NotificationEntry target) { + super(target.sbn()); + mTarget = target; + } + + @Override + public StatusBarNotification build() { + final StatusBarNotification sbn = super.build(); + mTarget.setNotification(sbn); + return sbn; + } + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationListenerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationListenerTest.java index 55ce8d60f2b4c..86869bd659004 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationListenerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationListenerTest.java @@ -38,7 +38,6 @@ import com.android.systemui.Dependency; import com.android.systemui.SysuiTestCase; import com.android.systemui.statusbar.notification.NotificationEntryManager; import com.android.systemui.statusbar.notification.collection.NotificationData; -import com.android.systemui.statusbar.notification.collection.NotificationEntry; import org.junit.Before; import org.junit.Test; @@ -91,7 +90,11 @@ public class NotificationListenerTest extends SysuiTestCase { @Test public void testNotificationUpdateCallsUpdateNotification() { - when(mNotificationData.get(mSbn.getKey())).thenReturn(NotificationEntry.buildForTest(mSbn)); + when(mNotificationData.get(mSbn.getKey())) + .thenReturn( + new NotificationEntryBuilder() + .setSbn(mSbn) + .build()); mListener.onNotificationPosted(mSbn, mRanking); TestableLooper.get(this).processAllMessages(); verify(mEntryManager).updateNotification(mSbn, mRanking); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationRemoteInputManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationRemoteInputManagerTest.java index 99d09f18eca68..852ddb2ae7108 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationRemoteInputManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationRemoteInputManagerTest.java @@ -63,7 +63,6 @@ public class NotificationRemoteInputManagerTest extends SysuiTestCase { @Mock private NotificationLockscreenUserManager mLockscreenUserManager; private TestableNotificationRemoteInputManager mRemoteInputManager; - private StatusBarNotification mSbn; private NotificationEntry mEntry; private RemoteInputHistoryExtender mRemoteInputHistoryExtender; private SmartReplyHistoryExtender mSmartReplyHistoryExtender; @@ -78,9 +77,13 @@ public class NotificationRemoteInputManagerTest extends SysuiTestCase { () -> mock(ShadeController.class), mStateController, Handler.createAsync(Looper.myLooper())); - mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID, - 0, new Notification(), UserHandle.CURRENT, null, 0); - mEntry = NotificationEntry.buildForTest(mSbn); + mEntry = new NotificationEntryBuilder() + .setPkg(TEST_PACKAGE_NAME) + .setOpPkg(TEST_PACKAGE_NAME) + .setUid(TEST_UID) + .setNotification(new Notification()) + .setUser(UserHandle.CURRENT) + .build(); mEntry.setRow(mRow); mRemoteInputManager.setUpWithPresenterForTest(mCallback, @@ -94,7 +97,7 @@ public class NotificationRemoteInputManagerTest extends SysuiTestCase { @Test public void testPerformOnRemoveNotification() { when(mController.isRemoteInputActive(mEntry)).thenReturn(true); - mRemoteInputManager.onPerformRemoveNotification(mEntry, mSbn.getKey()); + mRemoteInputManager.onPerformRemoveNotification(mEntry, mEntry.key()); verify(mController).removeRemoteInput(mEntry, null); } @@ -175,7 +178,9 @@ public class NotificationRemoteInputManagerTest extends SysuiTestCase { // Setup a notification entry with 1 remote input. StatusBarNotification newSbn = mRemoteInputManager.rebuildNotificationWithRemoteInput(mEntry, "A Reply", false); - NotificationEntry entry = NotificationEntry.buildForTest(newSbn); + NotificationEntry entry = new NotificationEntryBuilder() + .setSbn(newSbn) + .build(); // Try rebuilding to add another reply. newSbn = mRemoteInputManager.rebuildNotificationWithRemoteInput(entry, "Reply 2", true); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java index b1e76120b752d..de77af8f4d14a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationTestHelper.java @@ -299,17 +299,7 @@ public class NotificationTestHelper { row.setGroupManager(mGroupManager); row.setHeadsUpManager(mHeadsUpManager); row.setAboveShelfChangedListener(aboveShelf -> {}); - StatusBarNotification sbn = new StatusBarNotification( - pkg, - pkg, - mId++, - null /* tag */, - uid, - 2000 /* initialPid */, - notification, - userHandle, - null /* overrideGroupKey */, - System.currentTimeMillis()); + final NotificationChannel channel = new NotificationChannel( notification.getChannelId(), @@ -317,14 +307,20 @@ public class NotificationTestHelper { importance); channel.setBlockableSystem(true); - NotificationEntry entry = new NotificationEntry( - sbn, - new RankingBuilder() - .setKey(sbn.getKey()) - .setChannel(channel) - .build()); + NotificationEntry entry = new NotificationEntryBuilder() + .setPkg(pkg) + .setOpPkg(pkg) + .setId(mId++) + .setUid(uid) + .setInitialPid(2000) + .setNotification(notification) + .setUser(userHandle) + .setPostTime(System.currentTimeMillis()) + .setChannel(channel) + .build(); + entry.setRow(row); - entry.createIcons(mContext, sbn); + entry.createIcons(mContext, entry.sbn()); row.setEntry(entry); row.getNotificationInflater().addInflationFlags(extraInflationFlags); NotificationContentInflaterTest.runThenWaitForInflation( diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationViewHierarchyManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationViewHierarchyManagerTest.java index 388cf582237b0..9e7250412499f 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationViewHierarchyManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationViewHierarchyManagerTest.java @@ -120,7 +120,9 @@ public class NotificationViewHierarchyManagerTest extends SysuiTestCase { private NotificationEntry createEntry() throws Exception { ExpandableNotificationRow row = mHelper.createRow(); - NotificationEntry entry = NotificationEntry.buildForTest(row.getStatusBarNotification()); + NotificationEntry entry = new NotificationEntryBuilder() + .setSbn(row.getStatusBarNotification()) + .build(); entry.setRow(row); return entry; } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/RankingBuilder.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/RankingBuilder.java index b45077ade3e3d..05f179ed4620a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/RankingBuilder.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/RankingBuilder.java @@ -24,6 +24,7 @@ import android.service.notification.NotificationListenerService.Ranking; import android.service.notification.SnoozeCriterion; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -192,11 +193,21 @@ public class RankingBuilder { return this; } + public RankingBuilder setSmartActions(Notification.Action... smartActions) { + mSmartActions = new ArrayList<>(Arrays.asList(smartActions)); + return this; + } + public RankingBuilder setSmartReplies(@NonNull ArrayList smartReplies) { mSmartReplies = smartReplies; return this; } + public RankingBuilder setSmartReplies(CharSequence... smartReplies) { + mSmartReplies = new ArrayList<>(Arrays.asList(smartReplies)); + return this; + } + private static ArrayList copyList(List list) { if (list == null) { return null; diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/SbnBuilder.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/SbnBuilder.java index a9aab7f56cd33..9bc962c77019e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/SbnBuilder.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/SbnBuilder.java @@ -37,6 +37,22 @@ public class SbnBuilder { private String mOverrideGroupKey; private long mPostTime; + public SbnBuilder() { + } + + public SbnBuilder(StatusBarNotification source) { + mPkg = source.getPackageName(); + mOpPkg = source.getOpPkg(); + mId = source.getId(); + mTag = source.getTag(); + mUid = source.getUid(); + mInitialPid = source.getInitialPid(); + mNotification = source.getNotification(); + mUser = source.getUser(); + mOverrideGroupKey = source.getOverrideGroupKey(); + mPostTime = source.getPostTime(); + } + public StatusBarNotification build() { return new StatusBarNotification( mPkg, diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/SmartReplyControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/SmartReplyControllerTest.java index e54ea6a7c8f98..88fb3e1d5c198 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/SmartReplyControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/SmartReplyControllerTest.java @@ -97,7 +97,9 @@ public class SmartReplyControllerTest extends SysuiTestCase { mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID, 0, mNotification, new UserHandle(ActivityManager.getCurrentUser()), null, 0); - mEntry = NotificationEntry.buildForTest(mSbn); + mEntry = new NotificationEntryBuilder() + .setSbn(mSbn) + .build(); } @Test diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationListControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationListControllerTest.java index e42d1558afa95..a145c1251f570 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationListControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationListControllerTest.java @@ -30,7 +30,6 @@ import android.app.ActivityManager; import android.app.AppOpsManager; import android.app.Notification; import android.os.UserHandle; -import android.service.notification.StatusBarNotification; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.util.ArraySet; @@ -41,6 +40,7 @@ import com.android.internal.statusbar.NotificationVisibility; import com.android.systemui.ForegroundServiceController; import com.android.systemui.R; import com.android.systemui.SysuiTestCase; +import com.android.systemui.statusbar.NotificationEntryBuilder; import com.android.systemui.statusbar.notification.collection.NotificationData; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.stack.NotificationListContainer; @@ -222,19 +222,14 @@ public class NotificationListControllerTest extends SysuiTestCase { .setContentTitle("Title") .setContentText("Text"); - StatusBarNotification notification = - new StatusBarNotification( - TEST_PACKAGE_NAME, - TEST_PACKAGE_NAME, - mNextNotifId, - null, - TEST_UID, - 0, - n.build(), - new UserHandle(ActivityManager.getCurrentUser()), - null, - 0); - return NotificationEntry.buildForTest(notification); + return new NotificationEntryBuilder() + .setPkg(TEST_PACKAGE_NAME) + .setOpPkg(TEST_PACKAGE_NAME) + .setId(mNextNotifId) + .setUid(TEST_UID) + .setNotification(n.build()) + .setUser(new UserHandle(ActivityManager.getCurrentUser())) + .build(); } private static final String TEST_PACKAGE_NAME = "test"; diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/VisualStabilityManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/VisualStabilityManagerTest.java index 49229ca050c3b..6a4ddc7ec2026 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/VisualStabilityManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/VisualStabilityManagerTest.java @@ -25,13 +25,13 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.os.Handler; -import android.service.notification.StatusBarNotification; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import androidx.test.filters.SmallTest; import com.android.systemui.SysuiTestCase; +import com.android.systemui.statusbar.NotificationEntryBuilder; import com.android.systemui.statusbar.NotificationPresenter; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; @@ -62,7 +62,7 @@ public class VisualStabilityManagerTest extends SysuiTestCase { mVisualStabilityManager.setUpWithPresenter(mock(NotificationPresenter.class)); mVisualStabilityManager.setVisibilityLocationProvider(mLocationProvider); - mEntry = NotificationEntry.buildForTest(mock(StatusBarNotification.class)); + mEntry = new NotificationEntryBuilder().build(); mEntry.setRow(mRow); when(mRow.getEntry()).thenReturn(mEntry); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotificationDataTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotificationDataTest.java index 365b80b507231..9bcbfbc836b33 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotificationDataTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotificationDataTest.java @@ -27,6 +27,7 @@ import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static android.app.NotificationManager.IMPORTANCE_LOW; import static android.app.NotificationManager.IMPORTANCE_MIN; +import static com.android.systemui.statusbar.NotificationEntryHelper.modifySbn; import static com.android.systemui.statusbar.notification.collection.NotificationDataTest.TestableNotificationData.OVERRIDE_CHANNEL; import static com.android.systemui.statusbar.notification.collection.NotificationDataTest.TestableNotificationData.OVERRIDE_IMPORTANCE; import static com.android.systemui.statusbar.notification.collection.NotificationDataTest.TestableNotificationData.OVERRIDE_RANK; @@ -70,7 +71,10 @@ import com.android.systemui.ForegroundServiceController; import com.android.systemui.InitController; import com.android.systemui.SysuiTestCase; import com.android.systemui.plugins.statusbar.StatusBarStateController; +import com.android.systemui.statusbar.NotificationEntryBuilder; import com.android.systemui.statusbar.NotificationTestHelper; +import com.android.systemui.statusbar.RankingBuilder; +import com.android.systemui.statusbar.SbnBuilder; import com.android.systemui.statusbar.notification.collection.NotificationData.KeyguardEnvironment; import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; import com.android.systemui.statusbar.phone.NotificationGroupManager; @@ -83,9 +87,7 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; -import java.util.List; import java.util.Map; @SmallTest @@ -98,8 +100,8 @@ public class NotificationDataTest extends SysuiTestCase { private static final NotificationChannel NOTIFICATION_CHANNEL = new NotificationChannel("id", "name", NotificationChannel.USER_LOCKED_IMPORTANCE); - private final StatusBarNotification mMockStatusBarNotification = - mock(StatusBarNotification.class); + private NotificationEntry mEntry; + @Mock ForegroundServiceController mFsc; @Mock @@ -113,9 +115,10 @@ public class NotificationDataTest extends SysuiTestCase { public void setUp() throws Exception { com.android.systemui.util.Assert.sMainLooper = TestableLooper.get(this).getLooper(); MockitoAnnotations.initMocks(this); - when(mMockStatusBarNotification.getUid()).thenReturn(UID_NORMAL); - when(mMockStatusBarNotification.cloneLight()).thenReturn(mMockStatusBarNotification); - when(mMockStatusBarNotification.getKey()).thenReturn("mock_key"); + + mEntry = new NotificationEntryBuilder() + .setUid(UID_NORMAL) + .build(); when(mMockPackageManager.checkUidPermission( eq(Manifest.permission.NOTIFICATION_DURING_SETUP), @@ -231,57 +234,57 @@ public class NotificationDataTest extends SysuiTestCase { public void testIsExemptFromDndVisualSuppression_foreground() { initStatusBarNotification(false); - Notification n = mMockStatusBarNotification.getNotification(); - n.flags = Notification.FLAG_FOREGROUND_SERVICE; - NotificationEntry entry = NotificationEntry.buildForTest(mMockStatusBarNotification); - entry.setRow(mRow); - mNotificationData.add(entry); + mEntry.sbn().getNotification().flags = Notification.FLAG_FOREGROUND_SERVICE; + mEntry.setRow(mRow); + mNotificationData.add(mEntry); Bundle override = new Bundle(); override.putInt(OVERRIDE_VIS_EFFECTS, 255); - mNotificationData.rankingOverrides.put(entry.key, override); + mNotificationData.rankingOverrides.put(mEntry.key, override); - assertTrue(entry.isExemptFromDndVisualSuppression()); - assertFalse(entry.shouldSuppressAmbient()); + assertTrue(mEntry.isExemptFromDndVisualSuppression()); + assertFalse(mEntry.shouldSuppressAmbient()); } @Test public void testIsExemptFromDndVisualSuppression_media() { initStatusBarNotification(false); - Notification n = mMockStatusBarNotification.getNotification(); + Notification n = mEntry.sbn().getNotification(); Notification.Builder nb = Notification.Builder.recoverBuilder(mContext, n); nb.setStyle(new Notification.MediaStyle().setMediaSession(mock(MediaSession.Token.class))); n = nb.build(); - when(mMockStatusBarNotification.getNotification()).thenReturn(n); - NotificationEntry entry = NotificationEntry.buildForTest(mMockStatusBarNotification); - entry.setRow(mRow); - mNotificationData.add(entry); + modifySbn(mEntry) + .setNotification(n) + .build(); + mEntry.setRow(mRow); + mNotificationData.add(mEntry); Bundle override = new Bundle(); override.putInt(OVERRIDE_VIS_EFFECTS, 255); - mNotificationData.rankingOverrides.put(entry.key, override); + mNotificationData.rankingOverrides.put(mEntry.key, override); - assertTrue(entry.isExemptFromDndVisualSuppression()); - assertFalse(entry.shouldSuppressAmbient()); + assertTrue(mEntry.isExemptFromDndVisualSuppression()); + assertFalse(mEntry.shouldSuppressAmbient()); } @Test public void testIsExemptFromDndVisualSuppression_system() { initStatusBarNotification(false); - NotificationEntry entry = NotificationEntry.buildForTest(mMockStatusBarNotification); - entry.setRow(mRow); - entry.mIsSystemNotification = true; - mNotificationData.add(entry); + mEntry.setRow(mRow); + mEntry.mIsSystemNotification = true; + mNotificationData.add(mEntry); Bundle override = new Bundle(); override.putInt(OVERRIDE_VIS_EFFECTS, 255); - mNotificationData.rankingOverrides.put(entry.key, override); + mNotificationData.rankingOverrides.put(mEntry.key, override); - assertTrue(entry.isExemptFromDndVisualSuppression()); - assertFalse(entry.shouldSuppressAmbient()); + assertTrue(mEntry.isExemptFromDndVisualSuppression()); + assertFalse(mEntry.shouldSuppressAmbient()); } @Test public void testIsNotExemptFromDndVisualSuppression_hiddenCategories() { initStatusBarNotification(false); - NotificationEntry entry = NotificationEntry.buildForTest(mMockStatusBarNotification); + NotificationEntry entry = new NotificationEntryBuilder() + .setUid(UID_NORMAL) + .build(); entry.setRow(mRow); entry.mIsSystemNotification = true; Bundle override = new Bundle(); @@ -289,58 +292,65 @@ public class NotificationDataTest extends SysuiTestCase { mNotificationData.rankingOverrides.put(entry.key, override); mNotificationData.add(entry); - when(mMockStatusBarNotification.getNotification()).thenReturn( - new Notification.Builder(mContext, "").setCategory(CATEGORY_CALL).build()); - + modifySbn(entry) + .setNotification( + new Notification.Builder(mContext, "").setCategory(CATEGORY_CALL).build()) + .build(); assertFalse(entry.isExemptFromDndVisualSuppression()); assertTrue(entry.shouldSuppressAmbient()); - when(mMockStatusBarNotification.getNotification()).thenReturn( - new Notification.Builder(mContext, "").setCategory(CATEGORY_REMINDER).build()); - + modifySbn(entry) + .setNotification( + new Notification.Builder(mContext, "") + .setCategory(CATEGORY_REMINDER) + .build()) + .build(); assertFalse(entry.isExemptFromDndVisualSuppression()); - when(mMockStatusBarNotification.getNotification()).thenReturn( - new Notification.Builder(mContext, "").setCategory(CATEGORY_ALARM).build()); - + modifySbn(entry) + .setNotification( + new Notification.Builder(mContext, "").setCategory(CATEGORY_ALARM).build()) + .build(); assertFalse(entry.isExemptFromDndVisualSuppression()); - when(mMockStatusBarNotification.getNotification()).thenReturn( - new Notification.Builder(mContext, "").setCategory(CATEGORY_EVENT).build()); - + modifySbn(entry) + .setNotification( + new Notification.Builder(mContext, "").setCategory(CATEGORY_EVENT).build()) + .build(); assertFalse(entry.isExemptFromDndVisualSuppression()); - when(mMockStatusBarNotification.getNotification()).thenReturn( - new Notification.Builder(mContext, "").setCategory(CATEGORY_MESSAGE).build()); - + modifySbn(entry) + .setNotification( + new Notification.Builder(mContext, "") + .setCategory(CATEGORY_MESSAGE) + .build()) + .build(); assertFalse(entry.isExemptFromDndVisualSuppression()); } @Test public void testCreateNotificationDataEntry_RankingUpdate() { - Ranking ranking = mock(Ranking.class); - initStatusBarNotification(false); + StatusBarNotification sbn = new SbnBuilder().build(); + sbn.getNotification().actions = + new Notification.Action[] { createContextualAction("appGeneratedAction") }; - List appGeneratedSmartActions = - Collections.singletonList(createContextualAction("appGeneratedAction")); - mMockStatusBarNotification.getNotification().actions = - appGeneratedSmartActions.toArray(new Notification.Action[0]); - - List systemGeneratedSmartActions = - Collections.singletonList(createAction("systemGeneratedAction")); - when(ranking.getSmartActions()).thenReturn(systemGeneratedSmartActions); - - when(ranking.getChannel()).thenReturn(NOTIFICATION_CHANNEL); - - when(ranking.getUserSentiment()).thenReturn(Ranking.USER_SENTIMENT_NEGATIVE); + ArrayList systemGeneratedSmartActions = + createActions("systemGeneratedAction"); SnoozeCriterion snoozeCriterion = new SnoozeCriterion("id", "explanation", "confirmation"); ArrayList snoozeCriterions = new ArrayList<>(); snoozeCriterions.add(snoozeCriterion); - when(ranking.getSnoozeCriteria()).thenReturn(snoozeCriterions); + + Ranking ranking = new RankingBuilder() + .setKey(sbn.getKey()) + .setSmartActions(systemGeneratedSmartActions) + .setChannel(NOTIFICATION_CHANNEL) + .setUserSentiment(Ranking.USER_SENTIMENT_NEGATIVE) + .setSnoozeCriteria(snoozeCriterions) + .build(); NotificationEntry entry = - new NotificationEntry(mMockStatusBarNotification, ranking); + new NotificationEntry(sbn, ranking); assertEquals(systemGeneratedSmartActions, entry.getSmartActions()); assertEquals(NOTIFICATION_CHANNEL, entry.getChannel()); @@ -366,10 +376,15 @@ public class NotificationDataTest extends SysuiTestCase { Notification notification = new Notification.Builder(mContext, "test") .addExtras(bundle) .build(); - StatusBarNotification sbn = new StatusBarNotification("pkg", "pkg", 0, "tag", 0, 0, - notification, mContext.getUser(), "", 0); - NotificationEntry entry = NotificationEntry.buildForTest(sbn); + NotificationEntry entry = new NotificationEntryBuilder() + .setPkg("pkg") + .setOpPkg("pkg") + .setTag("tag") + .setNotification(notification) + .setUser(mContext.getUser()) + .setOverrideGroupKey("") + .build(); entry.setHasSentReply(); assertTrue(entry.isLastMessageFromReply()); @@ -472,9 +487,14 @@ public class NotificationDataTest extends SysuiTestCase { Notification aN = new Notification.Builder(mContext, "test") .setStyle(new Notification.MessagingStyle("")) .build(); - StatusBarNotification aSbn = new StatusBarNotification("pkg", "pkg", 0, "tag", 0, 0, - aN, mContext.getUser(), "", 0); - NotificationEntry a = NotificationEntry.buildForTest(aSbn); + NotificationEntry a = new NotificationEntryBuilder() + .setPkg("pkg") + .setOpPkg("pkg") + .setTag("tag") + .setNotification(aN) + .setUser(mContext.getUser()) + .setOverrideGroupKey("") + .build(); a.setRow(mock(ExpandableNotificationRow.class)); a.setIsHighPriority(false); @@ -486,9 +506,14 @@ public class NotificationDataTest extends SysuiTestCase { Notification bN = new Notification.Builder(mContext, "test") .setStyle(new Notification.MessagingStyle("")) .build(); - StatusBarNotification bSbn = new StatusBarNotification("pkg2", "pkg2", 0, "tag", 0, 0, - bN, mContext.getUser(), "", 0); - NotificationEntry b = NotificationEntry.buildForTest(bSbn); + NotificationEntry b = new NotificationEntryBuilder() + .setPkg("pkg2") + .setOpPkg("pkg2") + .setTag("tag") + .setNotification(bN) + .setUser(mContext.getUser()) + .setOverrideGroupKey("") + .build(); b.setIsHighPriority(true); b.setRow(mock(ExpandableNotificationRow.class)); @@ -507,9 +532,14 @@ public class NotificationDataTest extends SysuiTestCase { Notification aN = new Notification.Builder(mContext, "test") .setStyle(new Notification.MessagingStyle("")) .build(); - StatusBarNotification aSbn = new StatusBarNotification("pkg", "pkg", 0, "tag", 0, 0, - aN, mContext.getUser(), "", 0); - NotificationEntry a = NotificationEntry.buildForTest(aSbn); + NotificationEntry a = new NotificationEntryBuilder() + .setPkg("pkg") + .setOpPkg("pkg") + .setTag("tag") + .setNotification(aN) + .setUser(mContext.getUser()) + .setOverrideGroupKey("") + .build(); a.setRow(mock(ExpandableNotificationRow.class)); a.setIsHighPriority(false); @@ -521,9 +551,14 @@ public class NotificationDataTest extends SysuiTestCase { Notification bN = new Notification.Builder(mContext, "test") .setStyle(new Notification.MessagingStyle("")) .build(); - StatusBarNotification bSbn = new StatusBarNotification("pkg2", "pkg2", 0, "tag", 0, 0, - bN, mContext.getUser(), "", 0); - NotificationEntry b = NotificationEntry.buildForTest(bSbn); + NotificationEntry b = new NotificationEntryBuilder() + .setPkg("pkg2") + .setOpPkg("pkg2") + .setTag("tag") + .setNotification(bN) + .setUser(mContext.getUser()) + .setOverrideGroupKey("") + .build(); b.setRow(mock(ExpandableNotificationRow.class)); b.setIsHighPriority(false); @@ -540,23 +575,19 @@ public class NotificationDataTest extends SysuiTestCase { Notification notification = new Notification.Builder(mContext, "test") .build(); - StatusBarNotification sbn = new StatusBarNotification( - "pkg", - "pkg", - 0, - "tag", - 0, - 0, - notification, - mContext.getUser(), - "", - 0); + NotificationEntry entry = new NotificationEntryBuilder() + .setPkg("pkg") + .setOpPkg("pkg") + .setTag("tag") + .setNotification(notification) + .setUser(mContext.getUser()) + .setOverrideGroupKey("") + .build(); Bundle override = new Bundle(); override.putInt(OVERRIDE_IMPORTANCE, IMPORTANCE_DEFAULT); - mNotificationData.rankingOverrides.put(sbn.getKey(), override); + mNotificationData.rankingOverrides.put(entry.key(), override); - NotificationEntry entry = NotificationEntry.buildForTest(sbn); entry.setRow(mRow); mNotificationData.add(entry); @@ -567,23 +598,20 @@ public class NotificationDataTest extends SysuiTestCase { public void testSort_properlySetsIsNotTopBucket() { Notification notification = new Notification.Builder(mContext, "test") .build(); - StatusBarNotification sbn = new StatusBarNotification( - "pkg", - "pkg", - 0, - "tag", - 0, - 0, - notification, - mContext.getUser(), - "", - 0); + + NotificationEntry entry = new NotificationEntryBuilder() + .setPkg("pkg") + .setOpPkg("pkg") + .setTag("tag") + .setNotification(notification) + .setUser(mContext.getUser()) + .setOverrideGroupKey("") + .build(); Bundle override = new Bundle(); override.putInt(OVERRIDE_IMPORTANCE, IMPORTANCE_LOW); - mNotificationData.rankingOverrides.put(sbn.getKey(), override); + mNotificationData.rankingOverrides.put(entry.key(), override); - NotificationEntry entry = NotificationEntry.buildForTest(sbn); entry.setRow(mRow); mNotificationData.add(entry); @@ -597,7 +625,9 @@ public class NotificationDataTest extends SysuiTestCase { Notification notification = new Notification.Builder(mContext, "test") .addExtras(bundle) .build(); - when(mMockStatusBarNotification.getNotification()).thenReturn(notification); + modifySbn(mEntry) + .setNotification(notification) + .build(); } public static class TestableNotificationData extends NotificationData { @@ -684,6 +714,11 @@ public class NotificationDataTest extends SysuiTestCase { ? overrides.getCharSequenceArrayList(OVERRIDE_SMART_REPLIES) : currentReplies, overrides.getBoolean(OVERRIDE_BUBBLE, outRanking.canBubble())); + } else { + outRanking.populate( + new RankingBuilder() + .setKey(key) + .build()); } return true; } @@ -704,4 +739,12 @@ public class NotificationDataTest extends SysuiTestCase { title, PendingIntent.getBroadcast(getContext(), 0, new Intent("Action"), 0)).build(); } + + private ArrayList createActions(String... titles) { + ArrayList actions = new ArrayList<>(); + for (String title : titles) { + actions.add(createAction(title)); + } + return actions; + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/logging/NotificationLoggerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/logging/NotificationLoggerTest.java index ff3a2e2247881..24cd056b789c1 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/logging/NotificationLoggerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/logging/NotificationLoggerTest.java @@ -29,7 +29,6 @@ import android.app.Notification; import android.os.Handler; import android.os.Looper; import android.os.UserHandle; -import android.service.notification.StatusBarNotification; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; @@ -40,6 +39,7 @@ import com.android.internal.statusbar.NotificationVisibility; import com.android.systemui.Dependency; import com.android.systemui.SysuiTestCase; import com.android.systemui.UiOffloadThread; +import com.android.systemui.statusbar.NotificationEntryBuilder; import com.android.systemui.statusbar.NotificationListener; import com.android.systemui.statusbar.StatusBarStateControllerImpl; import com.android.systemui.statusbar.notification.NotificationEntryListener; @@ -93,10 +93,13 @@ public class NotificationLoggerTest extends SysuiTestCase { when(mEntryManager.getNotificationData()).thenReturn(mNotificationData); - StatusBarNotification sbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, - 0, null, TEST_UID, - 0, new Notification(), UserHandle.CURRENT, null, 0); - mEntry = NotificationEntry.buildForTest(sbn); + mEntry = new NotificationEntryBuilder() + .setPkg(TEST_PACKAGE_NAME) + .setOpPkg(TEST_PACKAGE_NAME) + .setUid(TEST_UID) + .setNotification(new Notification()) + .setUser(UserHandle.CURRENT) + .build(); mEntry.setRow(mRow); mLogger = new TestableNotificationLogger(mListener, Dependency.get(UiOffloadThread.class), diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationMenuRowTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationMenuRowTest.java index 096acf9d9ce4f..9eba4ebeb994b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationMenuRowTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationMenuRowTest.java @@ -28,9 +28,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import android.app.NotificationChannel; import android.provider.Settings; -import android.service.notification.StatusBarNotification; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.testing.TestableLooper.RunWithLooper; @@ -40,7 +38,7 @@ import android.view.ViewGroup; import androidx.test.filters.SmallTest; import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin; -import com.android.systemui.statusbar.RankingBuilder; +import com.android.systemui.statusbar.NotificationEntryBuilder; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.utils.leaks.LeakCheckedTest; @@ -61,11 +59,7 @@ public class NotificationMenuRowTest extends LeakCheckedTest { public void setup() { injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES); mRow = mock(ExpandableNotificationRow.class); - NotificationEntry entry = new NotificationEntry( - mock(StatusBarNotification.class), - new RankingBuilder() - .setChannel(mock(NotificationChannel.class)) - .build()); + NotificationEntry entry = new NotificationEntryBuilder().build(); when(mRow.getEntry()).thenReturn(entry); } @@ -75,7 +69,6 @@ public class NotificationMenuRowTest extends LeakCheckedTest { NOTIFICATION_NEW_INTERRUPTION_MODEL, 0); } - @Test public void testAttachDetach() { NotificationMenuRowPlugin row = new NotificationMenuRow(mContext); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhoneTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhoneTest.java index de3623f86c442..ef9665a808484 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhoneTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhoneTest.java @@ -32,6 +32,7 @@ import androidx.test.filters.SmallTest; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.statusbar.AlertingNotificationManager; import com.android.systemui.statusbar.AlertingNotificationManagerTest; +import com.android.systemui.statusbar.NotificationEntryBuilder; import com.android.systemui.statusbar.notification.VisualStabilityManager; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.policy.AccessibilityManagerWrapper; @@ -121,7 +122,9 @@ public class HeadsUpManagerPhoneTest extends AlertingNotificationManagerTest { @Test public void testCanRemoveImmediately_notTopEntry() { - NotificationEntry laterEntry = NotificationEntry.buildForTest(createNewNotification(1)); + NotificationEntry laterEntry = new NotificationEntryBuilder() + .setSbn(createNewNotification(1)) + .build(); laterEntry.setRow(mRow); mHeadsUpManager.showNotification(mEntry); mHeadsUpManager.showNotification(laterEntry); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationGroupTestHelper.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationGroupTestHelper.java index e33545bba7a2d..f1a7905d1d423 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationGroupTestHelper.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/NotificationGroupTestHelper.java @@ -24,9 +24,9 @@ import android.app.ActivityManager; import android.app.Notification; import android.content.Context; import android.os.UserHandle; -import android.service.notification.StatusBarNotification; import com.android.systemui.R; +import com.android.systemui.statusbar.NotificationEntryBuilder; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; @@ -76,22 +76,18 @@ public final class NotificationGroupTestHelper { .setGroupSummary(isSummary) .setGroup(TEST_GROUP_ID) .build(); - StatusBarNotification sbn = new StatusBarNotification( - TEST_PACKAGE_NAME /* pkg */, - TEST_PACKAGE_NAME, - id, - null /* tag */, - 0, /* uid */ - 0 /* initialPid */, - notif, - new UserHandle(ActivityManager.getCurrentUser()), - null /* overrideGroupKey */, - 0 /* postTime */); - NotificationEntry entry = NotificationEntry.buildForTest(sbn); + NotificationEntry entry = new NotificationEntryBuilder() + .setPkg(TEST_PACKAGE_NAME) + .setOpPkg(TEST_PACKAGE_NAME) + .setId(id) + .setNotification(notif) + .setUser(new UserHandle(ActivityManager.getCurrentUser())) + .build(); + ExpandableNotificationRow row = mock(ExpandableNotificationRow.class); entry.setRow(row); when(row.getEntry()).thenReturn(entry); - when(row.getStatusBarNotification()).thenReturn(sbn); + when(row.getStatusBarNotification()).thenReturn(entry.sbn()); when(row.isInflationFlagSet(anyInt())).thenReturn(true); return entry; } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenterTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenterTest.java index 45cd1e17ff93a..24ec1097ea8bf 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenterTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenterTest.java @@ -24,8 +24,6 @@ import android.app.Notification; import android.app.StatusBarManager; import android.content.Context; import android.metrics.LogMaker; -import android.os.UserHandle; -import android.service.notification.StatusBarNotification; import android.support.test.metricshelper.MetricsAsserts; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; @@ -39,6 +37,7 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.logging.testing.FakeMetricsLogger; import com.android.systemui.SysuiTestCase; import com.android.systemui.statusbar.CommandQueue; +import com.android.systemui.statusbar.NotificationEntryBuilder; import com.android.systemui.statusbar.notification.ActivityLaunchAnimator; import com.android.systemui.statusbar.notification.DynamicPrivacyController; import com.android.systemui.statusbar.notification.NotificationAlertingManager; @@ -84,29 +83,35 @@ public class StatusBarNotificationPresenterTest extends SysuiTestCase { @Test public void testHeadsUp_disabledStatusBar() { Notification n = new Notification.Builder(getContext(), "a").build(); - StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, - UserHandle.of(0), null, 0); - NotificationEntry entry = NotificationEntry.buildForTest(sbn); + NotificationEntry entry = new NotificationEntryBuilder() + .setPkg("a") + .setOpPkg("a") + .setTag("a") + .setNotification(n) + .build(); mCommandQueue.disable(DEFAULT_DISPLAY, StatusBarManager.DISABLE_EXPAND, 0, false /* animate */); TestableLooper.get(this).processAllMessages(); assertFalse("The panel shouldn't allow heads up while disabled", - mStatusBar.canHeadsUp(entry, sbn)); + mStatusBar.canHeadsUp(entry, entry.sbn())); } @Test public void testHeadsUp_disabledNotificationShade() { Notification n = new Notification.Builder(getContext(), "a").build(); - StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n, - UserHandle.of(0), null, 0); - NotificationEntry entry = NotificationEntry.buildForTest(sbn); + NotificationEntry entry = new NotificationEntryBuilder() + .setPkg("a") + .setOpPkg("a") + .setTag("a") + .setNotification(n) + .build(); mCommandQueue.disable(DEFAULT_DISPLAY, 0, StatusBarManager.DISABLE2_NOTIFICATION_SHADE, false /* animate */); TestableLooper.get(this).processAllMessages(); assertFalse("The panel shouldn't allow heads up while notitifcation shade disabled", - mStatusBar.canHeadsUp(entry, sbn)); + mStatusBar.canHeadsUp(entry, entry.sbn())); } @Test diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java index 9831ce3c07cee..0c6f25786190c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SmartReplyViewTest.java @@ -23,7 +23,6 @@ import static junit.framework.Assert.assertTrue; import static junit.framework.Assert.fail; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -37,7 +36,6 @@ import android.content.IntentFilter; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.graphics.drawable.Icon; -import android.service.notification.StatusBarNotification; import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.view.View; @@ -53,6 +51,7 @@ import com.android.systemui.R; import com.android.systemui.SysuiTestCase; import com.android.systemui.plugins.ActivityStarter; import com.android.systemui.plugins.ActivityStarter.OnDismissAction; +import com.android.systemui.statusbar.NotificationEntryBuilder; import com.android.systemui.statusbar.SmartReplyController; import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.phone.KeyguardDismissUtil; @@ -140,10 +139,10 @@ public class SmartReplyViewTest extends SysuiTestCase { .setSmallIcon(R.drawable.ic_person) .setContentTitle("Title") .setContentText("Text").build(); - StatusBarNotification sbn = mock(StatusBarNotification.class); - when(sbn.getNotification()).thenReturn(mNotification); - when(sbn.getKey()).thenReturn(TEST_NOTIFICATION_KEY); - mEntry = NotificationEntry.buildForTest(sbn); + + mEntry = new NotificationEntryBuilder() + .setNotification(mNotification) + .build(); mActionIcon = Icon.createWithResource(mContext, R.drawable.ic_person); }