Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ea13b234 authored by Mady Mellor's avatar Mady Mellor
Browse files

Allow a list of packages to be whitelisted to auto-bubble

If the notification has metadata (regardless if from experiment or not)
and that package has been whitelisted, then it will automatically bubble.

Supports multiple packages as long as it's in a comma separated list.

Test: manual:

1) set some packages to be whitelisted:
adb shell settings put secure whitelisted_auto_bubble_apps com.instagram.android,com.google.android.calendar,com.google.android.apps.photos

2) enable message bubbles / any bubbles:
adb shell settings put secure allow_any_notifs_to_bubble 1

3) get a notification that has enough info to bubble from one of those apps
=> it autobubbles

4) get an update to that notification
=> it goes to the bubble

Bug: 145763712
Change-Id: Ic2c26968dcb345e088044a73b30fef82d65552ae
parent 30672941
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -705,6 +705,10 @@ public class BubbleController implements ConfigurationController.ConfigurationLi

            if (mNotificationInterruptionStateProvider.shouldBubbleUp(entry)
                    && (canLaunchInActivityView(mContext, entry) || wasAdjusted)) {
                if (wasAdjusted && !previouslyUserCreated) {
                    // Gotta treat the auto-bubbled / whitelisted packaged bubbles as usercreated
                    mUserCreatedBubbles.add(entry.getKey());
                }
                updateBubble(entry);
            }
        }
@@ -721,6 +725,10 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
                // It was previously a bubble but no longer a bubble -- lets remove it
                removeBubble(entry.getKey(), DISMISS_NO_LONGER_BUBBLE);
            } else if (shouldBubble) {
                if (wasAdjusted && !previouslyUserCreated) {
                    // Gotta treat the auto-bubbled / whitelisted packaged bubbles as usercreated
                    mUserCreatedBubbles.add(entry.getKey());
                }
                updateBubble(entry);
            }
        }
+25 −3
Original line number Diff line number Diff line
@@ -66,6 +66,8 @@ public class BubbleExperimentConfig {
    private static final String ALLOW_SHORTCUTS_TO_BUBBLE = "allow_shortcuts_to_bubble";
    private static final boolean ALLOW_SHORTCUT_TO_BUBBLE_DEFAULT = false;

    private static final String WHITELISTED_AUTO_BUBBLE_APPS = "whitelisted_auto_bubble_apps";

    /**
     * When true, if a notification has the information necessary to bubble (i.e. valid
     * contentIntent and an icon or image), then a {@link android.app.Notification.BubbleMetadata}
@@ -102,6 +104,24 @@ public class BubbleExperimentConfig {
                ALLOW_SHORTCUT_TO_BUBBLE_DEFAULT ? 1 : 0) != 0;
    }

    /**
     * Returns whether the provided package is whitelisted to bubble.
     */
    static boolean isPackageWhitelistedToAutoBubble(Context context, String packageName) {
        String unsplitList = Settings.Secure.getString(context.getContentResolver(),
                WHITELISTED_AUTO_BUBBLE_APPS);
        if (unsplitList != null) {
            // We expect the list to be separated by commas and no white space (but we trim in case)
            String[] packageList = unsplitList.split(",");
            for (int i = 0; i < packageList.length; i++) {
                if (packageList[i].trim().equals(packageName)) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * If {@link #allowAnyNotifToBubble(Context)} is true, this method creates and adds
     * {@link android.app.Notification.BubbleMetadata} to the notification entry as long as
@@ -113,6 +133,8 @@ public class BubbleExperimentConfig {
            boolean previouslyUserCreated) {
        Notification.BubbleMetadata metadata = null;
        boolean addedMetadata = false;
        boolean whiteListedToAutoBubble =
                isPackageWhitelistedToAutoBubble(context, entry.getSbn().getPackageName());

        Notification notification = entry.getSbn().getNotification();
        boolean isMessage = Notification.MessagingStyle.class.equals(
@@ -170,9 +192,9 @@ public class BubbleExperimentConfig {
            }
        }

        if (previouslyUserCreated && addedMetadata) {
            // Update to a previous bubble, set its flag now so the update goes
            // to the bubble.
        boolean bubbleForWhitelist = whiteListedToAutoBubble && (addedMetadata || hasMetadata);
        if ((previouslyUserCreated && addedMetadata) || bubbleForWhitelist) {
            // Update to a previous bubble (or new autobubble), set its flag now.
            if (DEBUG_EXPERIMENTS) {
                Log.d(TAG, "Setting FLAG_BUBBLE for: " + entry.getKey());
            }