From 2c960fca1a3610bea34ed16621ecf6ba336a44ad Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Wed, 22 May 2019 10:38:40 -0700 Subject: [PATCH] App Bubble control page should always be available, even if off globally There is API to open up the app-specific bubble page, therefor, we should always show the toggle. The previous work to move bubbles to developer settings broke this. This CL adds a param to the controller to note whether it's the app specific page or not (since controller is also used for channel settings) to enable this behaviour. Added a test for this situation. Test: make -j40 RunSettingsRoboTests ROBOTEST_FILTER=Bubble Bug: 131846917 Change-Id: I72b1f4b5b033d1b24281061cfa6bed4d734dfcb1 --- .../AppBubbleNotificationSettings.java | 2 +- .../notification/BubblePreferenceController.java | 6 ++++-- .../ChannelNotificationSettings.java | 2 +- .../BubblePreferenceControllerTest.java | 16 +++++++++++++++- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/com/android/settings/notification/AppBubbleNotificationSettings.java b/src/com/android/settings/notification/AppBubbleNotificationSettings.java index 7214a88168f..2517573f0ad 100644 --- a/src/com/android/settings/notification/AppBubbleNotificationSettings.java +++ b/src/com/android/settings/notification/AppBubbleNotificationSettings.java @@ -64,7 +64,7 @@ public class AppBubbleNotificationSettings extends NotificationSettingsBase impl controllers.add(new BubblePreferenceController(context, fragment != null ? fragment.getChildFragmentManager() : null, - new NotificationBackend())); + new NotificationBackend(), true /* isAppPage */)); return controllers; } diff --git a/src/com/android/settings/notification/BubblePreferenceController.java b/src/com/android/settings/notification/BubblePreferenceController.java index 6196549d124..b68f11db0c8 100644 --- a/src/com/android/settings/notification/BubblePreferenceController.java +++ b/src/com/android/settings/notification/BubblePreferenceController.java @@ -41,11 +41,13 @@ public class BubblePreferenceController extends NotificationPreferenceController static final int SYSTEM_WIDE_OFF = 0; private FragmentManager mFragmentManager; + private boolean mIsAppPage; public BubblePreferenceController(Context context, @Nullable FragmentManager fragmentManager, - NotificationBackend backend) { + NotificationBackend backend, boolean isAppPage) { super(context, backend); mFragmentManager = fragmentManager; + mIsAppPage = isAppPage; } @Override @@ -58,7 +60,7 @@ public class BubblePreferenceController extends NotificationPreferenceController if (!super.isAvailable()) { return false; } - if (!isGloballyEnabled()) { + if (!mIsAppPage && !isGloballyEnabled()) { return false; } if (mChannel != null) { diff --git a/src/com/android/settings/notification/ChannelNotificationSettings.java b/src/com/android/settings/notification/ChannelNotificationSettings.java index 7f0f926bbae..8399a494994 100644 --- a/src/com/android/settings/notification/ChannelNotificationSettings.java +++ b/src/com/android/settings/notification/ChannelNotificationSettings.java @@ -115,7 +115,7 @@ public class ChannelNotificationSettings extends NotificationSettingsBase { mControllers.add(new DndPreferenceController(context, mBackend)); mControllers.add(new NotificationsOffPreferenceController(context)); mControllers.add(new BubblePreferenceController(context, getChildFragmentManager(), - mBackend)); + mBackend, false /* isAppPage */)); return new ArrayList<>(mControllers); } } diff --git a/tests/robotests/src/com/android/settings/notification/BubblePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/BubblePreferenceControllerTest.java index 67324e95845..aafefb51823 100644 --- a/tests/robotests/src/com/android/settings/notification/BubblePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/BubblePreferenceControllerTest.java @@ -78,6 +78,7 @@ public class BubblePreferenceControllerTest { private FragmentManager mFragmentManager; private BubblePreferenceController mController; + private BubblePreferenceController mAppPageController; @Before public void setUp() { @@ -87,7 +88,10 @@ public class BubblePreferenceControllerTest { shadowApplication.setSystemService(Context.USER_SERVICE, mUm); mContext = RuntimeEnvironment.application; when(mFragmentManager.beginTransaction()).thenReturn(mock(FragmentTransaction.class)); - mController = spy(new BubblePreferenceController(mContext, mFragmentManager, mBackend)); + mController = spy(new BubblePreferenceController(mContext, mFragmentManager, mBackend, + false /* isAppPage */)); + mAppPageController = spy(new BubblePreferenceController(mContext, mFragmentManager, + mBackend, true /* isAppPage */)); } @Test @@ -150,6 +154,16 @@ public class BubblePreferenceControllerTest { assertFalse(mController.isAvailable()); } + @Test + public void testIsAvailable_app_evenIfOffGlobally() { + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + mAppPageController.onResume(appRow, null, null, null); + Settings.Secure.putInt(mContext.getContentResolver(), + NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF); + + assertTrue(mAppPageController.isAvailable()); + } + @Test public void testIsAvailable_app() { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();