Merge "Move remaining tests over to using NotificationEntryBuilder"

This commit is contained in:
TreeHugger Robot
2019-09-16 15:12:39 +00:00
committed by Android (Google) Code Review
24 changed files with 335 additions and 259 deletions

View File

@@ -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;
}

View File

@@ -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) {

View File

@@ -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));
}
}

View File

@@ -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) {

View File

@@ -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!";

View File

@@ -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);
}

View File

@@ -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<CharSequence> smartReplies) {
mRankingBuilder.setSmartReplies(smartReplies);
return this;
}
public NotificationEntryBuilder setSmartReplies(CharSequence... smartReplies) {
mRankingBuilder.setSmartReplies(smartReplies);
return this;
}
}

View File

@@ -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;
}
}
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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(

View File

@@ -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;
}

View File

@@ -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<CharSequence> smartReplies) {
mSmartReplies = smartReplies;
return this;
}
public RankingBuilder setSmartReplies(CharSequence... smartReplies) {
mSmartReplies = new ArrayList<>(Arrays.asList(smartReplies));
return this;
}
private static <E> ArrayList<E> copyList(List<E> list) {
if (list == null) {
return null;

View File

@@ -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,

View File

@@ -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

View File

@@ -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";

View File

@@ -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);

View File

@@ -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<Notification.Action> appGeneratedSmartActions =
Collections.singletonList(createContextualAction("appGeneratedAction"));
mMockStatusBarNotification.getNotification().actions =
appGeneratedSmartActions.toArray(new Notification.Action[0]);
List<Notification.Action> 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<Notification.Action> systemGeneratedSmartActions =
createActions("systemGeneratedAction");
SnoozeCriterion snoozeCriterion = new SnoozeCriterion("id", "explanation", "confirmation");
ArrayList<SnoozeCriterion> 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<Notification.Action> createActions(String... titles) {
ArrayList<Notification.Action> actions = new ArrayList<>();
for (String title : titles) {
actions.add(createAction(title));
}
return actions;
}
}

View File

@@ -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),

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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);
}