Merge "Fix issue with media notifs being misbucketed" into qt-dev

This commit is contained in:
Ned Burns
2019-07-25 00:34:18 +00:00
committed by Android (Google) Code Review
10 changed files with 44 additions and 25 deletions

View File

@@ -15,7 +15,6 @@
package com.android.systemui.statusbar; package com.android.systemui.statusbar;
import android.content.pm.UserInfo; import android.content.pm.UserInfo;
import android.service.notification.StatusBarNotification;
import android.util.SparseArray; import android.util.SparseArray;
import com.android.systemui.statusbar.notification.collection.NotificationEntry; import com.android.systemui.statusbar.notification.collection.NotificationEntry;
@@ -58,7 +57,7 @@ public interface NotificationLockscreenUserManager {
boolean shouldHideNotifications(int userId); boolean shouldHideNotifications(int userId);
boolean shouldHideNotifications(String key); boolean shouldHideNotifications(String key);
boolean shouldShowOnKeyguard(StatusBarNotification sbn); boolean shouldShowOnKeyguard(NotificationEntry entry);
boolean isAnyProfilePublicMode(); boolean isAnyProfilePublicMode();

View File

@@ -33,7 +33,6 @@ import android.os.ServiceManager;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.provider.Settings; import android.provider.Settings;
import android.service.notification.StatusBarNotification;
import android.util.Log; import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import android.util.SparseBooleanArray; import android.util.SparseBooleanArray;
@@ -302,7 +301,7 @@ public class NotificationLockscreenUserManagerImpl implements
Notification.VISIBILITY_SECRET; Notification.VISIBILITY_SECRET;
} }
public boolean shouldShowOnKeyguard(StatusBarNotification sbn) { public boolean shouldShowOnKeyguard(NotificationEntry entry) {
if (getEntryManager() == null) { if (getEntryManager() == null) {
Log.wtf(TAG, "mEntryManager was null!", new Throwable()); Log.wtf(TAG, "mEntryManager was null!", new Throwable());
return false; return false;
@@ -310,10 +309,10 @@ public class NotificationLockscreenUserManagerImpl implements
boolean exceedsPriorityThreshold; boolean exceedsPriorityThreshold;
if (NotificationUtils.useNewInterruptionModel(mContext) if (NotificationUtils.useNewInterruptionModel(mContext)
&& hideSilentNotificationsOnLockscreen()) { && hideSilentNotificationsOnLockscreen()) {
exceedsPriorityThreshold = getEntryManager().getNotificationData().isHighPriority(sbn); exceedsPriorityThreshold = entry.isTopBucket();
} else { } else {
exceedsPriorityThreshold = exceedsPriorityThreshold =
!getEntryManager().getNotificationData().isAmbient(sbn.getKey()); !getEntryManager().getNotificationData().isAmbient(entry.key);
} }
return mShowLockscreenNotifications && exceedsPriorityThreshold; return mShowLockscreenNotifications && exceedsPriorityThreshold;
} }

View File

@@ -394,15 +394,13 @@ public class NotificationViewHierarchyManager implements DynamicPrivacyControlle
int userId = entry.notification.getUserId(); int userId = entry.notification.getUserId();
boolean suppressedSummary = mGroupManager.isSummaryOfSuppressedGroup( boolean suppressedSummary = mGroupManager.isSummaryOfSuppressedGroup(
entry.notification) && !entry.isRowRemoved(); entry.notification) && !entry.isRowRemoved();
boolean showOnKeyguard = mLockscreenUserManager.shouldShowOnKeyguard(entry boolean showOnKeyguard = mLockscreenUserManager.shouldShowOnKeyguard(entry);
.notification);
if (!showOnKeyguard) { if (!showOnKeyguard) {
// min priority notifications should show if their summary is showing // min priority notifications should show if their summary is showing
if (mGroupManager.isChildInGroupWithSummary(entry.notification)) { if (mGroupManager.isChildInGroupWithSummary(entry.notification)) {
NotificationEntry summary = mGroupManager.getLogicalGroupSummary( NotificationEntry summary = mGroupManager.getLogicalGroupSummary(
entry.notification); entry.notification);
if (summary != null && mLockscreenUserManager.shouldShowOnKeyguard( if (summary != null && mLockscreenUserManager.shouldShowOnKeyguard(summary)) {
summary.notification)) {
showOnKeyguard = true; showOnKeyguard = true;
} }
} }

View File

@@ -25,7 +25,6 @@ import android.service.notification.NotificationListenerService.RankingMap;
import android.service.notification.SnoozeCriterion; import android.service.notification.SnoozeCriterion;
import android.service.notification.StatusBarNotification; import android.service.notification.StatusBarNotification;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.Slog;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.Dependency; import com.android.systemui.Dependency;
@@ -108,10 +107,19 @@ public class NotificationData {
boolean bSystemMax = bImportance >= NotificationManager.IMPORTANCE_HIGH boolean bSystemMax = bImportance >= NotificationManager.IMPORTANCE_HIGH
&& isSystemNotification(nb); && isSystemNotification(nb);
boolean isHeadsUp = a.getRow().isHeadsUp();
if (isHeadsUp != b.getRow().isHeadsUp()) { boolean aHeadsUp = a.getRow().isHeadsUp();
return isHeadsUp ? -1 : 1; boolean bHeadsUp = b.getRow().isHeadsUp();
} else if (isHeadsUp) {
// HACK: This should really go elsewhere, but it's currently not straightforward to
// extract the comparison code and we're guaranteed to touch every element, so this is
// the best place to set the buckets for the moment.
a.setIsTopBucket(aHeadsUp || aMedia || aSystemMax || a.isHighPriority());
b.setIsTopBucket(bHeadsUp || bMedia || bSystemMax || b.isHighPriority());
if (aHeadsUp != bHeadsUp) {
return aHeadsUp ? -1 : 1;
} else if (aHeadsUp) {
// Provide consistent ranking with headsUpManager // Provide consistent ranking with headsUpManager
return mHeadsUpManager.compare(a, b); return mHeadsUpManager.compare(a, b);
} else if (a.getRow().showingAmbientPulsing() != b.getRow().showingAmbientPulsing()) { } else if (a.getRow().showingAmbientPulsing() != b.getRow().showingAmbientPulsing()) {

View File

@@ -173,6 +173,8 @@ public final class NotificationEntry {
*/ */
private boolean mHighPriority; private boolean mHighPriority;
private boolean mIsTopBucket;
public NotificationEntry(StatusBarNotification n) { public NotificationEntry(StatusBarNotification n) {
this(n, null); this(n, null);
} }
@@ -220,6 +222,18 @@ public final class NotificationEntry {
this.mHighPriority = highPriority; this.mHighPriority = highPriority;
} }
/**
* @return True if the notif should appear in the "top" or "important" section of notifications
* (as opposed to the "bottom" or "silent" section). This is usually the same as
* {@link #isHighPriority()}, but there are certain exceptions, such as media notifs.
*/
public boolean isTopBucket() {
return mIsTopBucket;
}
public void setIsTopBucket(boolean isTopBucket) {
mIsTopBucket = isTopBucket;
}
public boolean isBubble() { public boolean isBubble() {
return (notification.getNotification().flags & FLAG_BUBBLE) != 0; return (notification.getNotification().flags & FLAG_BUBBLE) != 0;
} }

View File

@@ -133,7 +133,7 @@ class NotificationSectionsManager implements StackScrollAlgorithm.SectionProvide
if (child instanceof ExpandableNotificationRow if (child instanceof ExpandableNotificationRow
&& child.getVisibility() != View.GONE) { && child.getVisibility() != View.GONE) {
ExpandableNotificationRow row = (ExpandableNotificationRow) child; ExpandableNotificationRow row = (ExpandableNotificationRow) child;
if (!row.getEntry().isHighPriority()) { if (!row.getEntry().isTopBucket()) {
firstGentleNotifIndex = i; firstGentleNotifIndex = i;
mFirstGentleNotif = row; mFirstGentleNotif = row;
break; break;
@@ -248,7 +248,7 @@ class NotificationSectionsManager implements StackScrollAlgorithm.SectionProvide
View child = mParent.getChildAt(i); View child = mParent.getChildAt(i);
if (child.getVisibility() != View.GONE && child instanceof ExpandableNotificationRow) { if (child.getVisibility() != View.GONE && child instanceof ExpandableNotificationRow) {
ExpandableNotificationRow row = (ExpandableNotificationRow) child; ExpandableNotificationRow row = (ExpandableNotificationRow) child;
if (!row.getEntry().isHighPriority()) { if (!row.getEntry().isTopBucket()) {
break; break;
} else { } else {
lastChildBeforeGap = row; lastChildBeforeGap = row;

View File

@@ -5776,7 +5776,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
currentIndex++; currentIndex++;
boolean beforeSpeedBump; boolean beforeSpeedBump;
if (mHighPriorityBeforeSpeedBump) { if (mHighPriorityBeforeSpeedBump) {
beforeSpeedBump = row.getEntry().isHighPriority(); beforeSpeedBump = row.getEntry().isTopBucket();
} else { } else {
beforeSpeedBump = !row.getEntry().ambient; beforeSpeedBump = !row.getEntry().ambient;
} }
@@ -5834,9 +5834,9 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
case ROWS_ALL: case ROWS_ALL:
return true; return true;
case ROWS_HIGH_PRIORITY: case ROWS_HIGH_PRIORITY:
return row.getEntry().isHighPriority(); return row.getEntry().isTopBucket();
case ROWS_GENTLE: case ROWS_GENTLE:
return !row.getEntry().isHighPriority(); return !row.getEntry().isTopBucket();
default: default:
throw new IllegalArgumentException("Unknown selection: " + selection); throw new IllegalArgumentException("Unknown selection: " + selection);
} }

View File

@@ -734,8 +734,7 @@ public class NotificationPanelView extends PanelView implements
if (suppressedSummary) { if (suppressedSummary) {
continue; continue;
} }
if (!mLockscreenUserManager.shouldShowOnKeyguard( if (!mLockscreenUserManager.shouldShowOnKeyguard(row.getEntry())) {
row.getStatusBarNotification())) {
continue; continue;
} }
if (row.isRemoved()) { if (row.isRemoved()) {

View File

@@ -38,7 +38,6 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.UserManager; import android.os.UserManager;
import android.provider.Settings; import android.provider.Settings;
import android.service.notification.StatusBarNotification;
import android.testing.AndroidTestingRunner; import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper; import android.testing.TestableLooper;
@@ -48,6 +47,7 @@ import com.android.systemui.Dependency;
import com.android.systemui.SysuiTestCase; import com.android.systemui.SysuiTestCase;
import com.android.systemui.statusbar.notification.NotificationEntryManager; import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.collection.NotificationData; import com.android.systemui.statusbar.notification.collection.NotificationData;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager;
import com.android.systemui.statusbar.policy.DeviceProvisionedController; import com.android.systemui.statusbar.policy.DeviceProvisionedController;
@@ -166,7 +166,7 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1); Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1);
when(mNotificationData.isHighPriority(any())).thenReturn(false); when(mNotificationData.isHighPriority(any())).thenReturn(false);
assertTrue(mLockscreenUserManager.shouldShowOnKeyguard(mock(StatusBarNotification.class))); assertTrue(mLockscreenUserManager.shouldShowOnKeyguard(mock(NotificationEntry.class)));
} }
@Test @Test
@@ -179,7 +179,7 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0); Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0);
when(mNotificationData.isHighPriority(any())).thenReturn(false); when(mNotificationData.isHighPriority(any())).thenReturn(false);
assertFalse(mLockscreenUserManager.shouldShowOnKeyguard(mock(StatusBarNotification.class))); assertFalse(mLockscreenUserManager.shouldShowOnKeyguard(mock(NotificationEntry.class)));
} }
private class TestNotificationLockscreenUserManager private class TestNotificationLockscreenUserManager

View File

@@ -263,6 +263,8 @@ public class NotificationSectionsManagerTest extends SysuiTestCase {
when(notifRow.getVisibility()).thenReturn(View.VISIBLE); when(notifRow.getVisibility()).thenReturn(View.VISIBLE);
when(notifRow.getEntry().isHighPriority()) when(notifRow.getEntry().isHighPriority())
.thenReturn(children[i] == ChildType.HIPRI); .thenReturn(children[i] == ChildType.HIPRI);
when(notifRow.getEntry().isTopBucket())
.thenReturn(children[i] == ChildType.HIPRI);
when(notifRow.getParent()).thenReturn(mNssl); when(notifRow.getParent()).thenReturn(mNssl);
child = notifRow; child = notifRow;
break; break;