Merge "Hide some previously exempt notifications" into pi-dev

am: afbc128d57

Change-Id: I05f866352f64ad7ddfc0534bdf84ce118a94212f
This commit is contained in:
Julia Reynolds
2018-05-03 15:21:46 -07:00
committed by android-build-merger
2 changed files with 70 additions and 0 deletions

View File

@@ -16,6 +16,11 @@
package com.android.systemui.statusbar;
import static android.app.Notification.CATEGORY_ALARM;
import static android.app.Notification.CATEGORY_CALL;
import static android.app.Notification.CATEGORY_EVENT;
import static android.app.Notification.CATEGORY_MESSAGE;
import static android.app.Notification.CATEGORY_REMINDER;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST;
@@ -52,6 +57,7 @@ import com.android.systemui.statusbar.notification.InflationException;
import com.android.systemui.statusbar.phone.NotificationGroupManager;
import com.android.systemui.statusbar.phone.StatusBar;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.statusbar.policy.ZenModeController;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -68,6 +74,7 @@ public class NotificationData {
private final Environment mEnvironment;
private HeadsUpManager mHeadsUpManager;
final ZenModeController mZen = Dependency.get(ZenModeController.class);
final ForegroundServiceController mFsc = Dependency.get(ForegroundServiceController.class);
public static final class Entry {
@@ -474,6 +481,10 @@ public class NotificationData {
}
protected boolean isExemptFromDndVisualSuppression(Entry entry) {
if (isNotificationBlockedByPolicy(entry.notification.getNotification())) {
return false;
}
if ((entry.notification.getNotification().flags
& Notification.FLAG_FOREGROUND_SERVICE) != 0) {
return true;
@@ -487,6 +498,26 @@ public class NotificationData {
return false;
}
/**
* Categories that are explicitly called out on DND settings screens are always blocked, if
* DND has flagged them, even if they are foreground or system notifications that might
* otherwise visually bypass DND.
*/
protected boolean isNotificationBlockedByPolicy(Notification n) {
if (isCategory(CATEGORY_CALL, n)
|| isCategory(CATEGORY_MESSAGE, n)
|| isCategory(CATEGORY_ALARM, n)
|| isCategory(CATEGORY_EVENT, n)
|| isCategory(CATEGORY_REMINDER, n)) {
return true;
}
return false;
}
private boolean isCategory(String category, Notification n) {
return Objects.equals(n.category, category);
}
public int getImportance(String key) {
if (mRankingMap != null) {
getRanking(key, mTmpRanking);

View File

@@ -18,6 +18,11 @@ package com.android.systemui.statusbar;
import static android.app.AppOpsManager.OP_ACCEPT_HANDOVER;
import static android.app.AppOpsManager.OP_CAMERA;
import static android.app.Notification.CATEGORY_ALARM;
import static android.app.Notification.CATEGORY_CALL;
import static android.app.Notification.CATEGORY_EVENT;
import static android.app.Notification.CATEGORY_MESSAGE;
import static android.app.Notification.CATEGORY_REMINDER;
import static junit.framework.Assert.assertEquals;
@@ -312,6 +317,40 @@ public class NotificationDataTest extends SysuiTestCase {
assertFalse(mNotificationData.shouldSuppressAmbient(entry));
}
@Test
public void testIsNotExemptFromDndVisualSuppression_hiddenCategories() {
initStatusBarNotification(false);
when(mMockStatusBarNotification.getKey()).thenReturn(
TEST_EXEMPT_DND_VISUAL_SUPPRESSION_KEY);
NotificationData.Entry entry = new NotificationData.Entry(mMockStatusBarNotification);
entry.mIsSystemNotification = true;
when(mMockStatusBarNotification.getNotification()).thenReturn(
new Notification.Builder(mContext, "").setCategory(CATEGORY_CALL).build());
assertFalse(mNotificationData.isExemptFromDndVisualSuppression(entry));
assertTrue(mNotificationData.shouldSuppressAmbient(entry));
when(mMockStatusBarNotification.getNotification()).thenReturn(
new Notification.Builder(mContext, "").setCategory(CATEGORY_REMINDER).build());
assertFalse(mNotificationData.isExemptFromDndVisualSuppression(entry));
when(mMockStatusBarNotification.getNotification()).thenReturn(
new Notification.Builder(mContext, "").setCategory(CATEGORY_ALARM).build());
assertFalse(mNotificationData.isExemptFromDndVisualSuppression(entry));
when(mMockStatusBarNotification.getNotification()).thenReturn(
new Notification.Builder(mContext, "").setCategory(CATEGORY_EVENT).build());
assertFalse(mNotificationData.isExemptFromDndVisualSuppression(entry));
when(mMockStatusBarNotification.getNotification()).thenReturn(
new Notification.Builder(mContext, "").setCategory(CATEGORY_MESSAGE).build());
assertFalse(mNotificationData.isExemptFromDndVisualSuppression(entry));
}
private void initStatusBarNotification(boolean allowDuringSetup) {
Bundle bundle = new Bundle();
bundle.putBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, allowDuringSetup);