From bd2bb06567100eff0a22d48e53059bce7a94e44f Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Thu, 28 Mar 2019 16:41:36 -0400 Subject: [PATCH] Prevent oem locked and default apps from being blocked Test: robotests Fixes: 129358763 Change-Id: I999b017f9f7389424e499a44cfac43711acbbbea --- .../NotificationPreferenceController.java | 5 ++++ .../NotificationPreferenceControllerTest.java | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/com/android/settings/notification/NotificationPreferenceController.java b/src/com/android/settings/notification/NotificationPreferenceController.java index 3f535fb074f..d2b7c43d8bb 100644 --- a/src/com/android/settings/notification/NotificationPreferenceController.java +++ b/src/com/android/settings/notification/NotificationPreferenceController.java @@ -126,6 +126,11 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc return mChannel.getImportance() == IMPORTANCE_NONE; } + if (mChannel.isImportanceLockedByOEM() + || mChannel.isImportanceLockedByCriticalDeviceFunction()) { + return false; + } + return mChannel.isBlockableSystem() || !mAppRow.systemApp || mChannel.getImportance() == IMPORTANCE_NONE; } diff --git a/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java index 2368af5f94b..9c53a7bfec0 100644 --- a/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java @@ -317,6 +317,30 @@ public class NotificationPreferenceControllerTest { assertTrue(mController.isChannelGroupBlockable()); } + @Test + public void testIsChannelBlockable_oemLocked() { + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + appRow.systemApp = false; + NotificationChannel channel = mock(NotificationChannel.class); + when(channel.isImportanceLockedByOEM()).thenReturn(true); + when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT); + + mController.onResume(appRow, channel, null, null); + assertFalse(mController.isChannelBlockable()); + } + + @Test + public void testIsChannelBlockable_criticalDeviceFunction() { + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + appRow.systemApp = false; + NotificationChannel channel = mock(NotificationChannel.class); + when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true); + when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT); + + mController.onResume(appRow, channel, null, null); + assertFalse(mController.isChannelBlockable()); + } + @Test public void testIsChannelGroupBlockable_SystemNotBlockable() { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();