From 9e2ec5fa07738701ded59a171090e6078f478503 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Thu, 7 Jun 2018 15:45:41 -0400 Subject: [PATCH] Hide block pref on non-configurable channels Test: robotests Bug: 109875297 Change-Id: I164ae2e07d178db9e84746e5c59f0968e6c77eae --- .../NotificationPreferenceController.java | 6 ++-- .../BlockPreferenceControllerTest.java | 1 + .../NotificationPreferenceControllerTest.java | 28 +++++++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/notification/NotificationPreferenceController.java b/src/com/android/settings/notification/NotificationPreferenceController.java index 49bb08ef154..1ce42c28433 100644 --- a/src/com/android/settings/notification/NotificationPreferenceController.java +++ b/src/com/android/settings/notification/NotificationPreferenceController.java @@ -138,11 +138,11 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc protected boolean isChannelBlockable() { if (mChannel != null && mAppRow != null) { - if (!mAppRow.systemApp) { - return true; + if (!isChannelConfigurable()) { + return mChannel.getImportance() == IMPORTANCE_NONE; } - return mChannel.isBlockableSystem() + return mChannel.isBlockableSystem() || !mAppRow.systemApp || mChannel.getImportance() == IMPORTANCE_NONE; } return false; diff --git a/tests/robotests/src/com/android/settings/notification/BlockPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/BlockPreferenceControllerTest.java index a13946e775e..bdc7d69fe24 100644 --- a/tests/robotests/src/com/android/settings/notification/BlockPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/BlockPreferenceControllerTest.java @@ -138,6 +138,7 @@ public class BlockPreferenceControllerTest { public void testIsAvailable_nonSystemApp() { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); appRow.systemApp = false; + appRow.lockedChannelId = "not this"; NotificationChannel channel = mock(NotificationChannel.class); when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH); mController.onResume(appRow, channel, null, null); diff --git a/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java index 7eeee98982c..38790b3e32a 100644 --- a/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java @@ -261,6 +261,34 @@ public class NotificationPreferenceControllerTest { assertTrue(mController.isChannelBlockable()); } + @Test + public void testIsChannelBlockable_notConfigurable() { + String sameId = "apples"; + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + appRow.systemApp = false; + appRow.lockedChannelId = sameId; + NotificationChannel channel = mock(NotificationChannel.class); + when(channel.getId()).thenReturn(sameId); + when(channel.getImportance()).thenReturn(IMPORTANCE_DEFAULT); + + mController.onResume(appRow, channel, null, null); + assertFalse(mController.isChannelBlockable()); + } + + @Test + public void testIsChannelBlockable_notConfigurableButBlocked() { + String sameId = "apples"; + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + appRow.systemApp = false; + appRow.lockedChannelId = sameId; + NotificationChannel channel = mock(NotificationChannel.class); + when(channel.getId()).thenReturn(sameId); + when(channel.getImportance()).thenReturn(IMPORTANCE_NONE); + + mController.onResume(appRow, channel, null, null); + assertTrue(mController.isChannelBlockable()); + } + @Test public void testIsChannelGroupBlockable_nonSystemBlockable() { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();