Merge "Properly consider non-blockable channels"

This commit is contained in:
Julia Reynolds
2018-06-11 20:48:54 +00:00
committed by Android (Google) Code Review
5 changed files with 45 additions and 6 deletions

View File

@@ -438,7 +438,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
*/
public boolean getIsNonblockable() {
boolean isNonblockable = Dependency.get(NotificationBlockingHelperManager.class)
.isNonblockablePackage(mStatusBarNotification.getPackageName());
.isNonblockable(mStatusBarNotification.getPackageName(),
mEntry.channel.getId());
// If the SystemNotifAsyncTask hasn't finished running or retrieved a value, we'll try once
// again, but in-place on the main thread this time. This should rarely ever get called.

View File

@@ -144,8 +144,15 @@ public class NotificationBlockingHelperManager {
/**
* Returns whether the given package name is in the list of non-blockable packages.
*/
public boolean isNonblockablePackage(String packageName) {
return mNonBlockablePkgs.contains(packageName);
public boolean isNonblockable(String packageName, String channelName) {
return mNonBlockablePkgs.contains(packageName)
|| mNonBlockablePkgs.contains(makeChannelKey(packageName, channelName));
}
// Format must stay in sync with frameworks/base/core/res/res/values/config.xml
// config_nonBlockableNotificationPackages
private String makeChannelKey(String pkg, String channel) {
return pkg + ":" + channel;
}
@VisibleForTesting
@@ -157,4 +164,10 @@ public class NotificationBlockingHelperManager {
void setBlockingHelperRowForTest(ExpandableNotificationRow blockingHelperRowForTest) {
mBlockingHelperRow = blockingHelperRowForTest;
}
@VisibleForTesting
void setNonBlockablePkgs(String[] pkgsAndChannels) {
mNonBlockablePkgs = new HashSet<>();
Collections.addAll(mNonBlockablePkgs, pkgsAndChannels);
}
}

View File

@@ -147,6 +147,7 @@ public class NotificationBlockingHelperManagerTest extends SysuiTestCase {
// of the child row.
ExpandableNotificationRow childRow = groupRow.getChildrenContainer().getViewAtPosition(0);
childRow.getEntry().userSentiment = USER_SENTIMENT_NEGATIVE;
assertFalse(childRow.getIsNonblockable());
assertTrue(mBlockingHelperManager.perhapsShowBlockingHelper(childRow, mMenuRow));
@@ -220,6 +221,24 @@ public class NotificationBlockingHelperManagerTest extends SysuiTestCase {
verify(mEntryManager).updateNotifications();
}
@Test
public void testNonBlockable_package() {
mBlockingHelperManager.setNonBlockablePkgs(new String[] {"banana", "strawberry:pie"});
assertFalse(mBlockingHelperManager.isNonblockable("orange", "pie"));
assertTrue(mBlockingHelperManager.isNonblockable("banana", "pie"));
}
@Test
public void testNonBlockable_channel() {
mBlockingHelperManager.setNonBlockablePkgs(new String[] {"banana", "strawberry:pie"});
assertFalse(mBlockingHelperManager.isNonblockable("strawberry", "shortcake"));
assertTrue(mBlockingHelperManager.isNonblockable("strawberry", "pie"));
}
private ExpandableNotificationRow createBlockableRowSpy() throws Exception {
ExpandableNotificationRow row = spy(mHelper.createRow());
when(row.getIsNonblockable()).thenReturn(false);

View File

@@ -280,7 +280,7 @@ public class NotificationGutsManagerTest extends SysuiTestCase {
any(PackageManager.class),
any(INotificationManager.class),
eq(statusBarNotification.getPackageName()),
isNull(),
any(NotificationChannel.class),
anyInt(),
eq(statusBarNotification),
any(NotificationInfo.CheckSaveListener.class),
@@ -306,7 +306,7 @@ public class NotificationGutsManagerTest extends SysuiTestCase {
any(PackageManager.class),
any(INotificationManager.class),
eq(statusBarNotification.getPackageName()),
isNull(),
any(NotificationChannel.class),
anyInt(),
eq(statusBarNotification),
any(NotificationInfo.CheckSaveListener.class),

View File

@@ -16,10 +16,13 @@
package com.android.systemui.statusbar;
import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.Instrumentation;
import android.app.Notification;
import android.app.NotificationChannel;
import android.content.Context;
import android.os.UserHandle;
import android.service.notification.StatusBarNotification;
@@ -118,7 +121,7 @@ public class NotificationTestHelper {
R.layout.custom_view_dark))
.build();
Notification.Builder notificationBuilder =
new Notification.Builder(mContext)
new Notification.Builder(mContext, "channelId")
.setSmallIcon(R.drawable.ic_person)
.setContentTitle("Title")
.setContentText("Text")
@@ -166,6 +169,9 @@ public class NotificationTestHelper {
NotificationData.Entry entry = new NotificationData.Entry(sbn);
entry.row = row;
entry.createIcons(mContext, sbn);
entry.channel = new NotificationChannel(
notification.getChannelId(), notification.getChannelId(), IMPORTANCE_DEFAULT);
entry.channel.setBlockableSystem(true);
NotificationInflaterTest.runThenWaitForInflation(
() -> row.updateNotification(entry),
row.getNotificationInflater());