Move feature-level Bubble setting into developer options; default to off

Functionality:
* Moves feature-level setting into developer settings (apps section)
* Adds bubbles in developer options under "apps" section
* Configures the app-specific bubble toggle in notifications settings
  to be hidden / shown based on the developer setting
* Configures the channel-specific bubble toggle in notification channel
  settings to be hidden / shown based on the developer setting

Tests:
* Anything that might be assuming that it's globally enabled now has
  a bit to enable it globally in that test
* There is a logic change now where the app-level setting would be available
  even if off globally, now that is not true -- if it's off globally the
  app-level is no longer available
* Adds tests for the developer setting

Test: make -j40 RunSettingsRoboTests ROBOTEST_FILTER="Bubble"
Bug: 131845765
Change-Id: I5f6bf74e5ada3fc023571825cca10d7bddc60e6e
This commit is contained in:
Mady Mellor
2019-05-06 16:54:07 -07:00
parent d204d6c33f
commit 32fa736dd6
18 changed files with 268 additions and 544 deletions

View File

@@ -22,6 +22,9 @@ import static android.app.NotificationManager.IMPORTANCE_LOW;
import static android.app.NotificationManager.IMPORTANCE_NONE;
import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
import static com.android.settings.notification.BubblePreferenceController.SYSTEM_WIDE_OFF;
import static com.android.settings.notification.BubblePreferenceController.SYSTEM_WIDE_ON;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -96,6 +99,7 @@ public class BubblePreferenceControllerTest {
@Test
public void testIsAvailable_notIfAppBlocked() {
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.banned = true;
mController.onResume(appRow, mock(NotificationChannel.class), null, null);
@@ -104,6 +108,7 @@ public class BubblePreferenceControllerTest {
@Test
public void testIsAvailable_notIfChannelBlocked() {
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_NONE);
@@ -113,6 +118,7 @@ public class BubblePreferenceControllerTest {
@Test
public void testIsAvailable_channel_notIfAppOff() {
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.allowBubbles = false;
NotificationChannel channel = mock(NotificationChannel.class);
@@ -123,12 +129,13 @@ public class BubblePreferenceControllerTest {
}
@Test
public void testIsAvailable_ifOffGlobally_app() {
public void testIsNotAvailable_ifOffGlobally_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, 0);
Settings.Secure.putInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
assertTrue(mController.isAvailable());
assertFalse(mController.isAvailable());
}
@Test
@@ -137,7 +144,8 @@ public class BubblePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, 0);
Settings.Secure.putInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
assertFalse(mController.isAvailable());
}
@@ -146,7 +154,7 @@ public class BubblePreferenceControllerTest {
public void testIsAvailable_app() {
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
mController.onResume(appRow, null, null, null);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, 1);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
assertTrue(mController.isAvailable());
}
@@ -159,7 +167,7 @@ public class BubblePreferenceControllerTest {
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID);
mController.onResume(appRow, channel, null, null);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, 1);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
assertTrue(mController.isAvailable());
}
@@ -171,7 +179,7 @@ public class BubblePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, 1);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
assertTrue(mController.isAvailable());
}
@@ -183,7 +191,7 @@ public class BubblePreferenceControllerTest {
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH);
mController.onResume(appRow, channel, null, null);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, 1);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
assertFalse(mController.isAvailable());
}
@@ -203,6 +211,7 @@ public class BubblePreferenceControllerTest {
@Test
public void testUpdateState_channelNotBlockable() {
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.isImportanceLockedByCriticalDeviceFunction()).thenReturn(true);
@@ -216,6 +225,7 @@ public class BubblePreferenceControllerTest {
@Test
public void testUpdateState_channel() {
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
NotificationChannel channel = mock(NotificationChannel.class);
when(channel.canBubble()).thenReturn(true);
@@ -235,6 +245,7 @@ public class BubblePreferenceControllerTest {
@Test
public void testUpdateState_app() {
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.label = "App!";
appRow.allowBubbles = true;
@@ -256,7 +267,8 @@ public class BubblePreferenceControllerTest {
@Test
public void testUpdateState_app_offGlobally() {
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, 0);
Settings.Secure.putInt(mContext.getContentResolver(),
NOTIFICATION_BUBBLES, SYSTEM_WIDE_OFF);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.label = "App!";
appRow.allowBubbles = true;
@@ -269,6 +281,7 @@ public class BubblePreferenceControllerTest {
@Test
public void testOnPreferenceChange_on_channel() {
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.allowBubbles = true;
NotificationChannel channel =
@@ -288,6 +301,7 @@ public class BubblePreferenceControllerTest {
@Test
public void testOnPreferenceChange_off_channel() {
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.allowBubbles = true;
NotificationChannel channel =
@@ -307,6 +321,7 @@ public class BubblePreferenceControllerTest {
@Test
public void testOnPreferenceChange_on_app() {
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.allowBubbles = false;
mController.onResume(appRow, null, null, null);
@@ -324,6 +339,7 @@ public class BubblePreferenceControllerTest {
@Test
public void testOnPreferenceChange_off_app() {
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, SYSTEM_WIDE_ON);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.allowBubbles = true;
mController.onResume(appRow, null, null, null);
@@ -341,7 +357,8 @@ public class BubblePreferenceControllerTest {
@Test
public void testOnPreferenceChange_on_app_offGlobally() {
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES, 0);
Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BUBBLES,
SYSTEM_WIDE_OFF);
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
appRow.allowBubbles = false;
mController.onResume(appRow, null, null, null);