Create BubbleMetadata use it instead of app overlay intent
* BubbleMetadata encapsulates necessary info to display a bubble
* Replaces app overlay intent usages with BubbleMetadata
* Renames existing bubble APIs to use 'bubble' rather than 'app overlay'
Bug: 111236845
Test: existing tests pass
Change-Id: I6a85d3c41dda47139fb8d960cadf1c8e109cf29b
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 20eebe7..7323e93 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -2311,22 +2311,22 @@
}
@Override
- public boolean areAppOverlaysAllowed(String pkg) {
- return areAppOverlaysAllowedForPackage(pkg, Binder.getCallingUid());
+ public boolean areBubblesAllowed(String pkg) {
+ return areBubblesAllowedForPackage(pkg, Binder.getCallingUid());
}
@Override
- public boolean areAppOverlaysAllowedForPackage(String pkg, int uid) {
- enforceSystemOrSystemUIOrSamePackage("Caller not system or systemui or same package",
- pkg);
- return mPreferencesHelper.areAppOverlaysAllowed(pkg, uid);
+ public boolean areBubblesAllowedForPackage(String pkg, int uid) {
+ enforceSystemOrSystemUIOrSamePackage(pkg,
+ "Caller not system or systemui or same package");
+ return mPreferencesHelper.areBubblessAllowed(pkg, uid);
}
@Override
- public void setAppOverlaysAllowed(String pkg, int uid, boolean allowed) {
+ public void setBubblesAllowed(String pkg, int uid, boolean allowed) {
checkCallerIsSystem();
- mPreferencesHelper.setAppOverlaysAllowed(pkg, uid, allowed);
+ mPreferencesHelper.setBubblesAllowed(pkg, uid, allowed);
handleSavePolicyFile();
}
diff --git a/services/core/java/com/android/server/notification/PreferencesHelper.java b/services/core/java/com/android/server/notification/PreferencesHelper.java
index 28f6972..7a21aa2 100644
--- a/services/core/java/com/android/server/notification/PreferencesHelper.java
+++ b/services/core/java/com/android/server/notification/PreferencesHelper.java
@@ -81,7 +81,7 @@
private static final String ATT_NAME = "name";
private static final String ATT_UID = "uid";
private static final String ATT_ID = "id";
- private static final String ATT_APP_OVERLAY = "overlay";
+ private static final String ATT_ALLOW_BUBBLE = "allow_bubble";
private static final String ATT_PRIORITY = "priority";
private static final String ATT_VISIBILITY = "visibility";
private static final String ATT_IMPORTANCE = "importance";
@@ -94,8 +94,9 @@
private static final int DEFAULT_VISIBILITY = NotificationManager.VISIBILITY_NO_OVERRIDE;
private static final int DEFAULT_IMPORTANCE = NotificationManager.IMPORTANCE_UNSPECIFIED;
private static final boolean DEFAULT_SHOW_BADGE = true;
- private static final boolean DEFAULT_ALLOW_APP_OVERLAY = true;
+ private static final boolean DEFAULT_ALLOW_BUBBLE = true;
private static final boolean DEFAULT_OEM_LOCKED_IMPORTANCE = false;
+
/**
* Default value for what fields are user locked. See {@link LockableAppFields} for all lockable
* fields.
@@ -108,7 +109,7 @@
@IntDef({LockableAppFields.USER_LOCKED_IMPORTANCE})
public @interface LockableAppFields {
int USER_LOCKED_IMPORTANCE = 0x00000001;
- int USER_LOCKED_APP_OVERLAY = 0x00000002;
+ int USER_LOCKED_BUBBLE = 0x00000002;
}
// pkg|uid => PackagePreferences
@@ -176,7 +177,7 @@
XmlUtils.readBooleanAttribute(
parser, ATT_SHOW_BADGE, DEFAULT_SHOW_BADGE),
XmlUtils.readBooleanAttribute(
- parser, ATT_APP_OVERLAY, DEFAULT_ALLOW_APP_OVERLAY));
+ parser, ATT_ALLOW_BUBBLE, DEFAULT_ALLOW_BUBBLE));
r.importance = XmlUtils.readIntAttribute(
parser, ATT_IMPORTANCE, DEFAULT_IMPORTANCE);
r.priority = XmlUtils.readIntAttribute(
@@ -272,11 +273,11 @@
private PackagePreferences getOrCreatePackagePreferences(String pkg, int uid) {
return getOrCreatePackagePreferences(pkg, uid,
DEFAULT_IMPORTANCE, DEFAULT_PRIORITY, DEFAULT_VISIBILITY, DEFAULT_SHOW_BADGE,
- DEFAULT_ALLOW_APP_OVERLAY);
+ DEFAULT_ALLOW_BUBBLE);
}
private PackagePreferences getOrCreatePackagePreferences(String pkg, int uid, int importance,
- int priority, int visibility, boolean showBadge, boolean allowAppOverlay) {
+ int priority, int visibility, boolean showBadge, boolean allowBubble) {
final String key = packagePreferencesKey(pkg, uid);
synchronized (mPackagePreferences) {
PackagePreferences
@@ -290,7 +291,7 @@
r.priority = priority;
r.visibility = visibility;
r.showBadge = showBadge;
- r.appOverlay = allowAppOverlay;
+ r.allowBubble = allowBubble;
try {
createDefaultChannelIfNeeded(r);
@@ -392,7 +393,7 @@
|| r.channels.size() > 0
|| r.groups.size() > 0
|| r.delegate != null
- || r.appOverlay != DEFAULT_ALLOW_APP_OVERLAY;
+ || r.allowBubble != DEFAULT_ALLOW_BUBBLE;
if (hasNonDefaultSettings) {
out.startTag(null, TAG_PACKAGE);
out.attribute(null, ATT_NAME, r.pkg);
@@ -405,8 +406,8 @@
if (r.visibility != DEFAULT_VISIBILITY) {
out.attribute(null, ATT_VISIBILITY, Integer.toString(r.visibility));
}
- if (r.appOverlay != DEFAULT_ALLOW_APP_OVERLAY) {
- out.attribute(null, ATT_APP_OVERLAY, Boolean.toString(r.appOverlay));
+ if (r.allowBubble != DEFAULT_ALLOW_BUBBLE) {
+ out.attribute(null, ATT_ALLOW_BUBBLE, Boolean.toString(r.allowBubble));
}
out.attribute(null, ATT_SHOW_BADGE, Boolean.toString(r.showBadge));
out.attribute(null, ATT_APP_USER_LOCKED_FIELDS,
@@ -452,14 +453,28 @@
out.endTag(null, TAG_RANKING);
}
- public void setAppOverlaysAllowed(String pkg, int uid, boolean allowed) {
+ /**
+ * Sets whether bubbles are allowed.
+ *
+ * @param pkg the package to allow or not allow bubbles for.
+ * @param uid the uid to allow or not allow bubbles for.
+ * @param allowed whether bubbles are allowed.
+ */
+ public void setBubblesAllowed(String pkg, int uid, boolean allowed) {
PackagePreferences p = getOrCreatePackagePreferences(pkg, uid);
- p.appOverlay = allowed;
- p.lockedAppFields = p.lockedAppFields | LockableAppFields.USER_LOCKED_APP_OVERLAY;
+ p.allowBubble = allowed;
+ p.lockedAppFields = p.lockedAppFields | LockableAppFields.USER_LOCKED_BUBBLE;
}
- public boolean areAppOverlaysAllowed(String pkg, int uid) {
- return getOrCreatePackagePreferences(pkg, uid).appOverlay;
+ /**
+ * Whether bubbles are allowed.
+ *
+ * @param pkg the package to check if bubbles are allowed for
+ * @param uid the uid to check if bubbles are allowed for.
+ * @return whether bubbles are allowed.
+ */
+ public boolean areBubblessAllowed(String pkg, int uid) {
+ return getOrCreatePackagePreferences(pkg, uid).allowBubble;
}
public int getAppLockedFields(String pkg, int uid) {
@@ -1232,8 +1247,8 @@
if (original.canShowBadge() != update.canShowBadge()) {
update.lockFields(NotificationChannel.USER_LOCKED_SHOW_BADGE);
}
- if (original.isAppOverlayAllowed() != update.isAppOverlayAllowed()) {
- update.lockFields(NotificationChannel.USER_LOCKED_ALLOW_APP_OVERLAY);
+ if (original.isBubbleAllowed() != update.isBubbleAllowed()) {
+ update.lockFields(NotificationChannel.USER_LOCKED_ALLOW_BUBBLE);
}
}
@@ -1654,7 +1669,7 @@
int priority = DEFAULT_PRIORITY;
int visibility = DEFAULT_VISIBILITY;
boolean showBadge = DEFAULT_SHOW_BADGE;
- boolean appOverlay = DEFAULT_ALLOW_APP_OVERLAY;
+ boolean allowBubble = DEFAULT_ALLOW_BUBBLE;
int lockedAppFields = DEFAULT_LOCKED_APP_FIELDS;
boolean oemLockedImportance = DEFAULT_OEM_LOCKED_IMPORTANCE;
List<String> futureOemLockedChannels = new ArrayList<>();
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
index 83c1c76..94b21af 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java
@@ -3511,9 +3511,9 @@
}
@Test
- public void testAppOverlay() throws Exception {
- mBinderService.setAppOverlaysAllowed(PKG, mUid, false);
- assertFalse(mBinderService.areAppOverlaysAllowedForPackage(PKG, mUid));
+ public void testBubble() throws Exception {
+ mBinderService.setBubblesAllowed(PKG, mUid, false);
+ assertFalse(mBinderService.areBubblesAllowedForPackage(PKG, mUid));
}
@Test
diff --git a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java
index 0fcfea7..24a1f8c 100644
--- a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java
+++ b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java
@@ -809,7 +809,7 @@
channel.setBypassDnd(true);
channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
channel.setShowBadge(true);
- channel.setAllowAppOverlay(false);
+ channel.setAllowBubbles(false);
int lockMask = 0;
for (int i = 0; i < NotificationChannel.LOCKABLE_FIELDS.length; i++) {
lockMask |= NotificationChannel.LOCKABLE_FIELDS[i];
@@ -826,7 +826,7 @@
assertFalse(savedChannel.canBypassDnd());
assertFalse(Notification.VISIBILITY_SECRET == savedChannel.getLockscreenVisibility());
assertEquals(channel.canShowBadge(), savedChannel.canShowBadge());
- assertEquals(channel.canOverlayApps(), savedChannel.canOverlayApps());
+ assertEquals(channel.canBubble(), savedChannel.canBubble());
verify(mHandler, never()).requestSort();
}
@@ -840,7 +840,7 @@
channel.setBypassDnd(true);
channel.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
channel.setShowBadge(true);
- channel.setAllowAppOverlay(false);
+ channel.setAllowBubbles(false);
int lockMask = 0;
for (int i = 0; i < NotificationChannel.LOCKABLE_FIELDS.length; i++) {
lockMask |= NotificationChannel.LOCKABLE_FIELDS[i];
@@ -857,7 +857,7 @@
assertFalse(savedChannel.canBypassDnd());
assertFalse(Notification.VISIBILITY_SECRET == savedChannel.getLockscreenVisibility());
assertEquals(channel.canShowBadge(), savedChannel.canShowBadge());
- assertEquals(channel.canOverlayApps(), savedChannel.canOverlayApps());
+ assertEquals(channel.canBubble(), savedChannel.canBubble());
}
@Test
@@ -969,16 +969,16 @@
}
@Test
- public void testLockFields_appOverlay() {
+ public void testLockFields_allowBubble() {
mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, getChannel(), true, false);
assertEquals(0,
mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, getChannel().getId(), false)
.getUserLockedFields());
final NotificationChannel update = getChannel();
- update.setAllowAppOverlay(false);
+ update.setAllowBubbles(false);
mHelper.updateNotificationChannel(PKG_N_MR1, UID_N_MR1, update, true);
- assertEquals(NotificationChannel.USER_LOCKED_ALLOW_APP_OVERLAY,
+ assertEquals(NotificationChannel.USER_LOCKED_ALLOW_BUBBLE,
mHelper.getNotificationChannel(PKG_N_MR1, UID_N_MR1, update.getId(), false)
.getUserLockedFields());
}
@@ -2161,30 +2161,30 @@
}
@Test
- public void testAllowAppOverlay_defaults() throws Exception {
- assertTrue(mHelper.areAppOverlaysAllowed(PKG_O, UID_O));
+ public void testAllowBubbles_defaults() throws Exception {
+ assertTrue(mHelper.areBubblessAllowed(PKG_O, UID_O));
ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false);
mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper);
loadStreamXml(baos, false);
- assertTrue(mHelper.areAppOverlaysAllowed(PKG_O, UID_O));
+ assertTrue(mHelper.areBubblessAllowed(PKG_O, UID_O));
assertEquals(0, mHelper.getAppLockedFields(PKG_O, UID_O));
}
@Test
- public void testAllowAppOverlay_xml() throws Exception {
- mHelper.setAppOverlaysAllowed(PKG_O, UID_O, false);
- assertFalse(mHelper.areAppOverlaysAllowed(PKG_O, UID_O));
- assertEquals(PreferencesHelper.LockableAppFields.USER_LOCKED_APP_OVERLAY,
+ public void testAllowBubbles_xml() throws Exception {
+ mHelper.setBubblesAllowed(PKG_O, UID_O, false);
+ assertFalse(mHelper.areBubblessAllowed(PKG_O, UID_O));
+ assertEquals(PreferencesHelper.LockableAppFields.USER_LOCKED_BUBBLE,
mHelper.getAppLockedFields(PKG_O, UID_O));
ByteArrayOutputStream baos = writeXmlAndPurge(PKG_O, UID_O, false);
mHelper = new PreferencesHelper(getContext(), mPm, mHandler, mMockZenModeHelper);
loadStreamXml(baos, false);
- assertFalse(mHelper.areAppOverlaysAllowed(PKG_O, UID_O));
- assertEquals(PreferencesHelper.LockableAppFields.USER_LOCKED_APP_OVERLAY,
+ assertFalse(mHelper.areBubblessAllowed(PKG_O, UID_O));
+ assertEquals(PreferencesHelper.LockableAppFields.USER_LOCKED_BUBBLE,
mHelper.getAppLockedFields(PKG_O, UID_O));
}
@@ -2290,14 +2290,14 @@
mHelper.lockChannelsForOEM(new String[] {PKG_O});
NotificationChannel update = new NotificationChannel("a", "a", IMPORTANCE_NONE);
- update.setAllowAppOverlay(false);
+ update.setAllowBubbles(false);
mHelper.updateNotificationChannel(PKG_O, UID_O, update, true);
assertEquals(IMPORTANCE_HIGH,
mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false).getImportance());
assertEquals(false,
- mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false).canOverlayApps());
+ mHelper.getNotificationChannel(PKG_O, UID_O, a.getId(), false).canBubble());
mHelper.updateNotificationChannel(PKG_O, UID_O, update, true);