Move more NotificationEntry members to getters
Move lastAudiblyAlertedMs, ambient, and importance to Ranking-derived
getters.
Add convenience builders for SBN and NotificationEntry.
Test: atest
Change-Id: I6d098f46a3c6f7c628e7d7dbbfc75e2feb0e1636
diff --git a/packages/SystemUI/src/com/android/systemui/ForegroundServiceNotificationListener.java b/packages/SystemUI/src/com/android/systemui/ForegroundServiceNotificationListener.java
index 96b62ac..d85dd8d 100644
--- a/packages/SystemUI/src/com/android/systemui/ForegroundServiceNotificationListener.java
+++ b/packages/SystemUI/src/com/android/systemui/ForegroundServiceNotificationListener.java
@@ -50,12 +50,12 @@
notificationEntryManager.addNotificationEntryListener(new NotificationEntryListener() {
@Override
public void onPendingEntryAdded(NotificationEntry entry) {
- addNotification(entry.notification, entry.importance);
+ addNotification(entry.notification, entry.getImportance());
}
@Override
public void onPostEntryUpdated(NotificationEntry entry) {
- updateNotification(entry.notification, entry.importance);
+ updateNotification(entry.notification, entry.getImportance());
}
@Override
diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java
index 94d9ede..67fc3e3 100644
--- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java
+++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleController.java
@@ -511,7 +511,7 @@
void updateBubble(NotificationEntry notif, boolean suppressFlyout) {
// If this is an interruptive notif, mark that it's interrupted
- if (notif.importance >= NotificationManager.IMPORTANCE_HIGH) {
+ if (notif.getImportance() >= NotificationManager.IMPORTANCE_HIGH) {
notif.setInterruption();
}
mBubbleData.notificationEntryUpdated(notif, suppressFlyout);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationViewHierarchyManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationViewHierarchyManager.java
index 66a0619..50d9bae 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationViewHierarchyManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationViewHierarchyManager.java
@@ -436,7 +436,7 @@
}
row.showAppOpsIcons(entry.mActiveAppOps);
- row.setLastAudiblyAlertedMs(entry.lastAudiblyAlertedMs);
+ row.setLastAudiblyAlertedMs(entry.getLastAudiblyAlertedMs());
}
Trace.beginSection("NotificationPresenter#onUpdateRowStates");
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java
index 0032174..c9d467f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryManager.java
@@ -471,7 +471,7 @@
NotificationUiAdjustment adjustment =
NotificationUiAdjustment.extractFromNotificationEntry(entry);
oldAdjustments.put(entry.key, adjustment);
- oldImportances.put(entry.key, entry.importance);
+ oldImportances.put(entry.key, entry.getImportance());
}
// Populate notification entries from the new rankings.
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInterruptionStateProvider.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInterruptionStateProvider.java
index 150667b..69bce74 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInterruptionStateProvider.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationInterruptionStateProvider.java
@@ -244,7 +244,7 @@
return false;
}
- if (entry.importance < NotificationManager.IMPORTANCE_HIGH) {
+ if (entry.getImportance() < NotificationManager.IMPORTANCE_HIGH) {
if (DEBUG_HEADS_UP) {
Log.d(TAG, "No heads up: unimportant notification: " + sbn.getKey());
}
@@ -307,7 +307,7 @@
return false;
}
- if (entry.importance < NotificationManager.IMPORTANCE_DEFAULT) {
+ if (entry.getImportance() < NotificationManager.IMPORTANCE_DEFAULT) {
if (DEBUG_HEADS_UP) {
Log.d(TAG, "No pulsing: not important enough: " + sbn.getKey());
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/VisualStabilityManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/VisualStabilityManager.java
index 4a6c7d2..6fe4abe 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/VisualStabilityManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/VisualStabilityManager.java
@@ -73,7 +73,7 @@
@Override
public void onPreEntryUpdated(NotificationEntry entry) {
final boolean mAmbientStateHasChanged =
- entry.ambient != entry.getRow().isLowPriority();
+ entry.isAmbient() != entry.getRow().isLowPriority();
if (mAmbientStateHasChanged) {
mLowPriorityReorderingViews.add(entry);
}
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 6f5fe8b..c5c21a4 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
@@ -38,7 +38,6 @@
import android.content.Context;
import android.graphics.drawable.Icon;
import android.os.Bundle;
-import android.os.Parcelable;
import android.os.SystemClock;
import android.service.notification.NotificationListenerService.Ranking;
import android.service.notification.SnoozeCriterion;
@@ -90,10 +89,7 @@
public StatusBarNotification notification;
private Ranking mRanking;
- public long lastAudiblyAlertedMs;
public boolean noisy;
- public boolean ambient;
- public int importance;
public StatusBarIconView icon;
public StatusBarIconView expandedIcon;
public StatusBarIconView centeredIcon;
@@ -243,9 +239,6 @@
public void setRanking(@NonNull Ranking ranking) {
mRanking = ranking;
- lastAudiblyAlertedMs = ranking.getLastAudiblyAlertedMillis();
- importance = ranking.getImportance();
- ambient = ranking.isAmbient();
snoozeCriteria = ranking.getSnoozeCriteria();
userSentiment = ranking.getUserSentiment();
systemGeneratedSmartActions = ranking.getSmartActions() == null
@@ -262,6 +255,18 @@
return mRanking.getChannel();
}
+ public long getLastAudiblyAlertedMs() {
+ return mRanking.getLastAudiblyAlertedMillis();
+ }
+
+ public boolean isAmbient() {
+ return mRanking.isAmbient();
+ }
+
+ public int getImportance() {
+ return mRanking.getImportance();
+ }
+
public void setInterruption() {
interruption = true;
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationRowBinderImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationRowBinderImpl.java
index 247c31f..60cf995 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationRowBinderImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationRowBinderImpl.java
@@ -214,7 +214,7 @@
// no-op here.
}
} else {
- if (oldImportance != null && entry.importance != oldImportance) {
+ if (oldImportance != null && entry.getImportance() != oldImportance) {
if (entry.rowExists()) {
entry.getRow().onNotificationRankingUpdated();
}
@@ -228,7 +228,7 @@
PackageManager pmUser,
StatusBarNotification sbn,
ExpandableNotificationRow row) {
- row.setIsLowPriority(entry.ambient);
+ row.setIsLowPriority(entry.isAmbient());
// Extract target SDK version.
try {
@@ -248,7 +248,7 @@
row.setOnActivatedListener(mPresenter);
boolean useIncreasedCollapsedHeight =
- mMessagingUtil.isImportantMessaging(sbn, entry.importance);
+ mMessagingUtil.isImportantMessaging(sbn, entry.getImportance());
boolean useIncreasedHeadsUp = useIncreasedCollapsedHeight
&& !mPresenter.isPresenterFullyCollapsed();
row.setUseIncreasedCollapsedHeight(useIncreasedCollapsedHeight);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java
index 3e8825d..7ed8306 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java
@@ -325,7 +325,7 @@
mDeviceProvisionedController.isDeviceProvisioned(),
row.getIsNonblockable(),
isForBlockingHelper,
- row.getEntry().importance,
+ row.getEntry().getImportance(),
row.getEntry().isHighPriority());
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
index 6a611a6..1c9b225 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
@@ -5782,7 +5782,7 @@
if (mHighPriorityBeforeSpeedBump) {
beforeSpeedBump = row.getEntry().isTopBucket();
} else {
- beforeSpeedBump = !row.getEntry().ambient;
+ beforeSpeedBump = !row.getEntry().isAmbient();
}
if (beforeSpeedBump) {
speedBumpIndex = currentIndex;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java
index bec53a1..320243b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java
@@ -411,7 +411,7 @@
if (DEBUG) {
Log.d(TAG, "No Fullscreen intent: suppressed by DND: " + entry.key);
}
- } else if (entry.importance < NotificationManager.IMPORTANCE_HIGH) {
+ } else if (entry.getImportance() < NotificationManager.IMPORTANCE_HIGH) {
if (DEBUG) {
Log.d(TAG, "No Fullscreen intent: not important enough: " + entry.key);
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java
index ccd2138..9aeb147 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/ForegroundServiceControllerTest.java
@@ -37,6 +37,7 @@
import androidx.test.runner.AndroidJUnit4;
import com.android.internal.messages.nano.SystemMessageProto;
+import com.android.systemui.statusbar.NotificationEntryBuilder;
import com.android.systemui.statusbar.notification.NotificationEntryListener;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
@@ -397,14 +398,18 @@
}
private void entryAdded(StatusBarNotification notification, int importance) {
- NotificationEntry entry = NotificationEntry.buildForTest(notification);
- entry.importance = importance;
+ NotificationEntry entry = new NotificationEntryBuilder()
+ .setSbn(notification)
+ .setImportance(importance)
+ .build();
mEntryListener.onPendingEntryAdded(entry);
}
private void entryUpdated(StatusBarNotification notification, int importance) {
- NotificationEntry entry = NotificationEntry.buildForTest(notification);
- entry.importance = importance;
+ NotificationEntry entry = new NotificationEntryBuilder()
+ .setSbn(notification)
+ .setImportance(importance)
+ .build();
mEntryListener.onPostEntryUpdated(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
new file mode 100644
index 0000000..2ae287b
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationEntryBuilder.java
@@ -0,0 +1,137 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.statusbar;
+
+import android.annotation.Nullable;
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager.Importance;
+import android.os.UserHandle;
+import android.service.notification.StatusBarNotification;
+
+import com.android.systemui.statusbar.notification.collection.NotificationEntry;
+
+import java.util.ArrayList;
+
+/**
+ * Combined builder for constructing a NotificationEntry and its associated StatusBarNotification
+ * and Ranking. Is largely a proxy for the SBN and Ranking builders, but does a little extra magic
+ * to make sure the keys match between the two, etc.
+ *
+ * Only for use in tests.
+ */
+public class NotificationEntryBuilder {
+ private final SbnBuilder mSbnBuilder = new SbnBuilder();
+ private final RankingBuilder mRankingBuilder = new RankingBuilder();
+
+ private StatusBarNotification mSbn = null;
+
+ public NotificationEntry build() {
+ StatusBarNotification sbn = mSbn != null ? mSbn : mSbnBuilder.build();
+ mRankingBuilder.setKey(sbn.getKey());
+ return new NotificationEntry(sbn, mRankingBuilder.build());
+ }
+
+ /**
+ * Sets the SBN directly. If set, causes all calls to delegated SbnBuilder methods to be
+ * ignored.
+ */
+ public NotificationEntryBuilder setSbn(@Nullable StatusBarNotification sbn) {
+ mSbn = sbn;
+ return this;
+ }
+
+ /* Delegated to SbnBuilder */
+
+ public NotificationEntryBuilder setPkg(String pkg) {
+ mSbnBuilder.setPkg(pkg);
+ return this;
+ }
+
+ public NotificationEntryBuilder setOpPkg(String opPkg) {
+ mSbnBuilder.setOpPkg(opPkg);
+ return this;
+ }
+
+ public NotificationEntryBuilder setId(int id) {
+ mSbnBuilder.setId(id);
+ return this;
+ }
+
+ public NotificationEntryBuilder setTag(String tag) {
+ mSbnBuilder.setTag(tag);
+ return this;
+ }
+
+ public NotificationEntryBuilder setUid(int uid) {
+ mSbnBuilder.setUid(uid);
+ return this;
+ }
+
+ public NotificationEntryBuilder setInitialPid(int initialPid) {
+ mSbnBuilder.setInitialPid(initialPid);
+ return this;
+ }
+
+ public NotificationEntryBuilder setNotification(Notification notification) {
+ mSbnBuilder.setNotification(notification);
+ return this;
+ }
+
+ public NotificationEntryBuilder setUser(UserHandle user) {
+ mSbnBuilder.setUser(user);
+ return this;
+ }
+
+ public NotificationEntryBuilder setOverrideGroupKey(String overrideGroupKey) {
+ mSbnBuilder.setOverrideGroupKey(overrideGroupKey);
+ return this;
+ }
+
+ public NotificationEntryBuilder setPostTime(long postTime) {
+ mSbnBuilder.setPostTime(postTime);
+ return this;
+ }
+
+ /* Delegated to RankingBuilder */
+
+ public NotificationEntryBuilder setImportance(@Importance int importance) {
+ mRankingBuilder.setImportance(importance);
+ return this;
+ }
+
+ public NotificationEntryBuilder setUserSentiment(int userSentiment) {
+ mRankingBuilder.setUserSentiment(userSentiment);
+ return this;
+ }
+
+ public NotificationEntryBuilder setChannel(NotificationChannel channel) {
+ mRankingBuilder.setChannel(channel);
+ return this;
+ }
+
+ public NotificationEntryBuilder setSmartActions(
+ ArrayList<Notification.Action> smartActions) {
+ mRankingBuilder.setSmartActions(smartActions);
+ return this;
+ }
+
+ public NotificationEntryBuilder setSmartReplies(ArrayList<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
new file mode 100644
index 0000000..b5168c6
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationEntryHelper.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.statusbar;
+
+import android.service.notification.NotificationListenerService.Ranking;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.systemui.statusbar.notification.collection.NotificationEntry;
+
+@VisibleForTesting
+public class NotificationEntryHelper {
+ public static ModifiedRankingBuilder modifyRanking(NotificationEntry entry) {
+ return new ModifiedRankingBuilder(entry);
+ }
+
+ public static class ModifiedRankingBuilder extends RankingBuilder {
+ private final NotificationEntry mTarget;
+
+ private ModifiedRankingBuilder(NotificationEntry target) {
+ super(target.ranking());
+ mTarget = target;
+ }
+
+ @Override
+ public Ranking build() {
+ final Ranking ranking = super.build();
+ mTarget.setRanking(ranking);
+ return ranking;
+ }
+ }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationInterruptionStateProviderTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationInterruptionStateProviderTest.java
index b044595..1eaf293 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationInterruptionStateProviderTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationInterruptionStateProviderTest.java
@@ -40,9 +40,7 @@
import android.hardware.display.AmbientDisplayConfiguration;
import android.os.PowerManager;
import android.os.RemoteException;
-import android.os.UserHandle;
import android.service.dreams.IDreamManager;
-import android.service.notification.StatusBarNotification;
import android.testing.AndroidTestingRunner;
import androidx.test.filters.SmallTest;
@@ -231,15 +229,17 @@
public void testCanAlertCommon_false_suppressedForGroups() {
ensureStateForAlertCommon();
- Notification n = new Notification.Builder(getContext(), "a")
- .setGroup("a")
- .setGroupSummary(true)
- .setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN)
+ NotificationEntry entry = new NotificationEntryBuilder()
+ .setPkg("a")
+ .setOpPkg("a")
+ .setTag("a")
+ .setNotification(new Notification.Builder(getContext(), "a")
+ .setGroup("a")
+ .setGroupSummary(true)
+ .setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN)
+ .build())
+ .setImportance(IMPORTANCE_DEFAULT)
.build();
- StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n,
- UserHandle.of(0), null, 0);
- NotificationEntry entry = NotificationEntry.buildForTest(sbn);
- entry.importance = IMPORTANCE_DEFAULT;
assertThat(mNotifInterruptionStateProvider.canAlertCommon(entry)).isFalse();
}
@@ -549,11 +549,15 @@
.setContentText("content text")
.setBubbleMetadata(data)
.build();
- StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n,
- UserHandle.of(0), null, 0);
- NotificationEntry entry = NotificationEntry.buildForTest(sbn);
- entry.notification.getNotification().flags |= FLAG_BUBBLE;
- entry.importance = IMPORTANCE_HIGH;
+ n.flags |= FLAG_BUBBLE;
+ NotificationEntry entry = new NotificationEntryBuilder()
+ .setPkg("a")
+ .setOpPkg("a")
+ .setTag("a")
+ .setNotification(n)
+ .setImportance(IMPORTANCE_HIGH)
+ .build();
+
entry.canBubble = true;
return entry;
}
@@ -563,11 +567,14 @@
.setContentTitle("title")
.setContentText("content text")
.build();
- StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n,
- UserHandle.of(0), null, 0);
- NotificationEntry entry = NotificationEntry.buildForTest(sbn);
- entry.importance = importance;
- return entry;
+
+ return new NotificationEntryBuilder()
+ .setPkg("a")
+ .setOpPkg("a")
+ .setTag("a")
+ .setNotification(n)
+ .setImportance(importance)
+ .build();
}
/**
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 bbdc4b7..3123365 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/RankingBuilder.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/RankingBuilder.java
@@ -18,10 +18,12 @@
import android.app.Notification;
import android.app.NotificationChannel;
+import android.app.NotificationManager.Importance;
import android.service.notification.NotificationListenerService.Ranking;
import android.service.notification.SnoozeCriterion;
import java.util.ArrayList;
+import java.util.List;
/**
* Standard builder class for Ranking objects. For use in tests that need to craft the underlying
@@ -33,27 +35,52 @@
private boolean mMatchesInterruptionFilter = false;
private int mVisibilityOverride = 0;
private int mSuppressedVisualEffects = 0;
- private int mImportance = 0;
+ @Importance private int mImportance = 0;
private CharSequence mExplanation = "test_explanation";
private String mOverrideGroupKey = null;
private NotificationChannel mChannel = null;
- private ArrayList<String> mOverridePeople = null;
+ private ArrayList<String> mAdditionalPeople = null;
private ArrayList<SnoozeCriterion> mSnoozeCriteria = null;
- private boolean mShowBadge = false;
+ private boolean mCanShowBadge = false;
private int mUserSentiment = 0;
- private boolean mHidden = false;
+ private boolean mIsSuspended = false;
private long mLastAudiblyAlertedMs = 0;
private boolean mNoisy = false;
private ArrayList<Notification.Action> mSmartActions = null;
private ArrayList<CharSequence> mSmartReplies = null;
private boolean mCanBubble = false;
+ public RankingBuilder() {
+ }
+
+ public RankingBuilder(Ranking ranking) {
+ mKey = ranking.getKey();
+ mRank = ranking.getRank();
+ mMatchesInterruptionFilter = ranking.matchesInterruptionFilter();
+ mVisibilityOverride = ranking.getVisibilityOverride();
+ mSuppressedVisualEffects = ranking.getSuppressedVisualEffects();
+ mImportance = ranking.getImportance();
+ mExplanation = ranking.getImportanceExplanation();
+ mOverrideGroupKey = ranking.getOverrideGroupKey();
+ mChannel = ranking.getChannel();
+ mAdditionalPeople = copyList(ranking.getAdditionalPeople());
+ mSnoozeCriteria = copyList(ranking.getSnoozeCriteria());
+ mCanShowBadge = ranking.canShowBadge();
+ mUserSentiment = ranking.getUserSentiment();
+ mIsSuspended = ranking.isSuspended();
+ mLastAudiblyAlertedMs = ranking.getLastAudiblyAlertedMillis();
+ mNoisy = ranking.isNoisy();
+ mSmartActions = copyList(ranking.getSmartActions());
+ mSmartReplies = copyList(ranking.getSmartReplies());
+ mCanBubble = ranking.canBubble();
+ }
+
public RankingBuilder setKey(String key) {
mKey = key;
return this;
}
- public RankingBuilder setImportance(int importance) {
+ public RankingBuilder setImportance(@Importance int importance) {
mImportance = importance;
return this;
}
@@ -90,11 +117,11 @@
mExplanation,
mOverrideGroupKey,
mChannel,
- mOverridePeople,
+ mAdditionalPeople,
mSnoozeCriteria,
- mShowBadge,
+ mCanShowBadge,
mUserSentiment,
- mHidden,
+ mIsSuspended,
mLastAudiblyAlertedMs,
mNoisy,
mSmartActions,
@@ -102,4 +129,12 @@
mCanBubble);
return ranking;
}
+
+ private static <E> ArrayList<E> copyList(List<E> list) {
+ if (list == null) {
+ return null;
+ } else {
+ return new ArrayList<>(list);
+ }
+ }
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/SbnBuilder.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/SbnBuilder.java
new file mode 100644
index 0000000..a9aab7f
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/SbnBuilder.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.statusbar;
+
+import android.app.Notification;
+import android.os.UserHandle;
+import android.service.notification.StatusBarNotification;
+
+/**
+ * Convenience builder for {@link StatusBarNotification} since its constructor is terrifying.
+ *
+ * Only for use in tests.
+ */
+public class SbnBuilder {
+ private String mPkg = "test_pkg";
+ private String mOpPkg;
+ private int mId;
+ private String mTag;
+ private int mUid;
+ private int mInitialPid;
+ private Notification mNotification = new Notification();
+ private UserHandle mUser = UserHandle.of(0);
+ private String mOverrideGroupKey;
+ private long mPostTime;
+
+ public StatusBarNotification build() {
+ return new StatusBarNotification(
+ mPkg,
+ mOpPkg,
+ mId,
+ mTag,
+ mUid,
+ mInitialPid,
+ mNotification,
+ mUser,
+ mOverrideGroupKey,
+ mPostTime);
+ }
+
+ public SbnBuilder setPkg(String pkg) {
+ mPkg = pkg;
+ return this;
+ }
+
+ public SbnBuilder setOpPkg(String opPkg) {
+ mOpPkg = opPkg;
+ return this;
+ }
+
+ public SbnBuilder setId(int id) {
+ mId = id;
+ return this;
+ }
+
+ public SbnBuilder setTag(String tag) {
+ mTag = tag;
+ return this;
+ }
+
+ public SbnBuilder setUid(int uid) {
+ mUid = uid;
+ return this;
+ }
+
+ public SbnBuilder setInitialPid(int initialPid) {
+ mInitialPid = initialPid;
+ return this;
+ }
+
+ public SbnBuilder setNotification(Notification notification) {
+ mNotification = notification;
+ return this;
+ }
+
+ public SbnBuilder setUser(UserHandle user) {
+ mUser = user;
+ return this;
+ }
+
+ public SbnBuilder setOverrideGroupKey(String overrideGroupKey) {
+ mOverrideGroupKey = overrideGroupKey;
+ return this;
+ }
+
+ public SbnBuilder setPostTime(long postTime) {
+ mPostTime = postTime;
+ return this;
+ }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java
index 36b143b..c6b155d 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/NotificationEntryManagerTest.java
@@ -65,6 +65,7 @@
import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
+import com.android.systemui.statusbar.NotificationEntryBuilder;
import com.android.systemui.statusbar.NotificationLifetimeExtender;
import com.android.systemui.statusbar.NotificationListener;
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
@@ -237,9 +238,16 @@
.setSmallIcon(R.drawable.ic_person)
.setContentTitle("Title")
.setContentText("Text");
- mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID,
- 0, n.build(), new UserHandle(ActivityManager.getCurrentUser()), null, 0);
- mEntry = NotificationEntry.buildForTest(mSbn);
+
+ mEntry = new NotificationEntryBuilder()
+ .setPkg(TEST_PACKAGE_NAME)
+ .setOpPkg(TEST_PACKAGE_NAME)
+ .setUid(TEST_UID)
+ .setNotification(n.build())
+ .setUser(new UserHandle(ActivityManager.getCurrentUser()))
+ .build();
+ mSbn = mEntry.sbn();
+
mEntry.expandedIcon = mock(StatusBarIconView.class);
mEntryManager = new TestableNotificationEntryManager(mContext);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java
index a14557b..c56a168 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRowTest.java
@@ -18,6 +18,7 @@
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
+import static com.android.systemui.statusbar.NotificationEntryHelper.modifyRanking;
import static com.android.systemui.statusbar.notification.row.NotificationContentInflater.FLAG_CONTENT_VIEW_ALL;
import static com.android.systemui.statusbar.notification.row.NotificationContentInflater.FLAG_CONTENT_VIEW_HEADS_UP;
import static com.android.systemui.statusbar.notification.row.NotificationContentInflater.FLAG_CONTENT_VIEW_PUBLIC;
@@ -51,7 +52,6 @@
import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.NotificationTestHelper;
-import com.android.systemui.statusbar.RankingBuilder;
import com.android.systemui.statusbar.notification.AboveShelfChangedListener;
import com.android.systemui.statusbar.notification.stack.NotificationChildrenContainer;
@@ -328,11 +328,11 @@
// Give each child a unique channel id/name.
int i = 0;
for (ExpandableNotificationRow childRow : childRows) {
- childRow.getEntry().setRanking(new RankingBuilder()
+ modifyRanking(childRow.getEntry())
.setChannel(
new NotificationChannel(
"id" + i, "dinnertime" + i, IMPORTANCE_DEFAULT))
- .build());
+ .build();
i++;
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationBlockingHelperManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationBlockingHelperManagerTest.java
index a26cdbd..07dd68f 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationBlockingHelperManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationBlockingHelperManagerTest.java
@@ -21,6 +21,8 @@
import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEUTRAL;
import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_POSITIVE;
+import static com.android.systemui.statusbar.NotificationEntryHelper.modifyRanking;
+
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
@@ -44,7 +46,6 @@
import com.android.systemui.bubbles.BubbleController;
import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
import com.android.systemui.statusbar.NotificationTestHelper;
-import com.android.systemui.statusbar.RankingBuilder;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.util.Assert;
@@ -142,11 +143,11 @@
ExpandableNotificationRow groupRow = createBlockableGroupRowSpy(10);
int i = 0;
for (ExpandableNotificationRow childRow : groupRow.getNotificationChildren()) {
- childRow.getEntry().setRanking(new RankingBuilder()
+ modifyRanking(childRow.getEntry())
.setChannel(
new NotificationChannel(
Integer.toString(i++), "", IMPORTANCE_DEFAULT))
- .build());
+ .build();
}
groupRow.getEntry().userSentiment = USER_SENTIMENT_NEGATIVE;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java
index 09c4179..cf805af 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java
@@ -22,6 +22,8 @@
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.service.notification.NotificationListenerService.Ranking.USER_SENTIMENT_NEGATIVE;
+import static com.android.systemui.statusbar.NotificationEntryHelper.modifyRanking;
+
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
@@ -62,7 +64,6 @@
import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
import com.android.systemui.statusbar.NotificationPresenter;
import com.android.systemui.statusbar.NotificationTestHelper;
-import com.android.systemui.statusbar.RankingBuilder;
import com.android.systemui.statusbar.notification.NotificationActivityStarter;
import com.android.systemui.statusbar.notification.VisualStabilityManager;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
@@ -371,8 +372,10 @@
NotificationInfo notificationInfoView = mock(NotificationInfo.class);
ExpandableNotificationRow row = spy(mHelper.createRow());
row.setBlockingHelperShowing(true);
- row.getEntry().userSentiment = USER_SENTIMENT_NEGATIVE;
- row.getEntry().importance = IMPORTANCE_DEFAULT;
+ modifyRanking(row.getEntry())
+ .setUserSentiment(USER_SENTIMENT_NEGATIVE)
+ .setImportance(IMPORTANCE_DEFAULT)
+ .build();
row.getEntry().setIsHighPriority(true);
when(row.getIsNonblockable()).thenReturn(false);
StatusBarNotification statusBarNotification = row.getStatusBarNotification();
@@ -499,10 +502,9 @@
try {
ExpandableNotificationRow row = mHelper.createRow(nb.build());
- row.getEntry().setRanking(
- new RankingBuilder()
- .setChannel(mTestNotificationChannel)
- .build());
+ modifyRanking(row.getEntry())
+ .setChannel(mTestNotificationChannel)
+ .build();
return row;
} catch (Exception e) {
fail();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
index a1afd1d..f3ec2dd 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarTest.java
@@ -51,9 +51,7 @@
import android.os.Looper;
import android.os.PowerManager;
import android.os.RemoteException;
-import android.os.UserHandle;
import android.service.dreams.IDreamManager;
-import android.service.notification.StatusBarNotification;
import android.support.test.metricshelper.MetricsAsserts;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
@@ -88,6 +86,7 @@
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.KeyguardIndicationController;
import com.android.systemui.statusbar.NavigationBarController;
+import com.android.systemui.statusbar.NotificationEntryBuilder;
import com.android.systemui.statusbar.NotificationListener;
import com.android.systemui.statusbar.NotificationLockscreenUserManager;
import com.android.systemui.statusbar.NotificationMediaManager;
@@ -417,10 +416,14 @@
.setGroupSummary(true)
.setGroupAlertBehavior(Notification.GROUP_ALERT_SUMMARY)
.build();
- StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n,
- UserHandle.of(0), null, 0);
- NotificationEntry entry = NotificationEntry.buildForTest(sbn);
- entry.importance = IMPORTANCE_HIGH;
+
+ NotificationEntry entry = new NotificationEntryBuilder()
+ .setPkg("a")
+ .setOpPkg("a")
+ .setTag("a")
+ .setNotification(n)
+ .setImportance(IMPORTANCE_HIGH)
+ .build();
assertTrue(mNotificationInterruptionStateProvider.shouldHeadsUp(entry));
}
@@ -438,10 +441,14 @@
.setGroupSummary(true)
.setGroupAlertBehavior(Notification.GROUP_ALERT_CHILDREN)
.build();
- StatusBarNotification sbn = new StatusBarNotification("a", "a", 0, "a", 0, 0, n,
- UserHandle.of(0), null, 0);
- NotificationEntry entry = NotificationEntry.buildForTest(sbn);
- entry.importance = IMPORTANCE_HIGH;
+
+ NotificationEntry entry = new NotificationEntryBuilder()
+ .setPkg("a")
+ .setOpPkg("a")
+ .setTag("a")
+ .setNotification(n)
+ .setImportance(IMPORTANCE_HIGH)
+ .build();
assertFalse(mNotificationInterruptionStateProvider.shouldHeadsUp(entry));
}
@@ -455,11 +462,16 @@
when(mHeadsUpSuppressor.canHeadsUp(any(), any())).thenReturn(true);
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)
+ .setImportance(IMPORTANCE_HIGH)
+ .build();
+
entry.suppressedVisualEffects = SUPPRESSED_EFFECT_PEEK;
- entry.importance = IMPORTANCE_HIGH;
assertFalse(mNotificationInterruptionStateProvider.shouldHeadsUp(entry));
}
@@ -473,10 +485,14 @@
when(mHeadsUpSuppressor.canHeadsUp(any(), any())).thenReturn(true);
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);
- entry.importance = IMPORTANCE_HIGH;
+
+ NotificationEntry entry = new NotificationEntryBuilder()
+ .setPkg("a")
+ .setOpPkg("a")
+ .setTag("a")
+ .setNotification(n)
+ .setImportance(IMPORTANCE_HIGH)
+ .build();
assertTrue(mNotificationInterruptionStateProvider.shouldHeadsUp(entry));
}