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

Commit 4509ce73 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Add settings for notification bubbling

And a new api to consolidate that information for notification
listeners

Test: atest
Bug: 123543052
Change-Id: I61d1718ef5b5bb8ab824d4c3efff511669266313
parent 5bfb2b7b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -41693,6 +41693,7 @@ package android.service.notification {
  public static class NotificationListenerService.Ranking {
    ctor public NotificationListenerService.Ranking();
    method public boolean canBubble();
    method public boolean canShowBadge();
    method public android.app.NotificationChannel getChannel();
    method public int getImportance();
+1 −0
Original line number Diff line number Diff line
@@ -1815,6 +1815,7 @@ package android.provider {
    field @Deprecated public static final String ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES = "enabled_notification_policy_access_packages";
    field public static final String LOCATION_ACCESS_CHECK_DELAY_MILLIS = "location_access_check_delay_millis";
    field public static final String LOCATION_ACCESS_CHECK_INTERVAL_MILLIS = "location_access_check_interval_millis";
    field public static final String NOTIFICATION_BUBBLES = "notification_bubbles";
    field @RequiresPermission(android.Manifest.permission.WRITE_SECURE_SETTINGS) public static final String SYNC_PARENT_SOUNDS = "sync_parent_sounds";
    field public static final String USER_SETUP_COMPLETE = "user_setup_complete";
    field public static final String VOICE_INTERACTION_SERVICE = "voice_interaction_service";
+1 −9
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ public final class NotificationChannel implements Parcelable {
    private static final String ATT_FG_SERVICE_SHOWN = "fgservice";
    private static final String ATT_GROUP = "group";
    private static final String ATT_BLOCKABLE_SYSTEM = "blockable_system";
    private static final String ATT_ALLOW_BUBBLE = "allow_bubble";
    private static final String ATT_ALLOW_BUBBLE = "can_bubble";
    private static final String DELIMITER = ",";

    /**
@@ -611,14 +611,6 @@ public final class NotificationChannel implements Parcelable {
     * shade, in a floating window on top of other apps.
     */
    public boolean canBubble() {
        return isBubbleAllowed() && getImportance() >= IMPORTANCE_HIGH;
    }

    /**
     * Like {@link #canBubble()}, but only checks the permission, not the importance.
     * @hide
     */
    public boolean isBubbleAllowed() {
        return mAllowBubbles;
    }

+12 −0
Original line number Diff line number Diff line
@@ -8294,6 +8294,16 @@ public final class Settings {
        private static final Validator NOTIFICATION_BADGING_VALIDATOR = BOOLEAN_VALIDATOR;
        /**
         * Whether the notification bubbles are globally enabled
         * The value is boolean (1 or 0).
         * @hide
         */
        @TestApi
        public static final String NOTIFICATION_BUBBLES = "notification_bubbles";
        private static final Validator NOTIFICATION_BUBBLES_VALIDATOR = BOOLEAN_VALIDATOR;
        /**
         * Whether notifications are dismissed by a right-to-left swipe (instead of a left-to-right
         * swipe).
@@ -8605,6 +8615,7 @@ public final class Settings {
            ASSIST_GESTURE_WAKE_ENABLED,
            VR_DISPLAY_MODE,
            NOTIFICATION_BADGING,
            NOTIFICATION_BUBBLES,
            NOTIFICATION_DISMISS_RTL,
            QS_AUTO_ADDED_TILES,
            SCREENSAVER_ENABLED,
@@ -8767,6 +8778,7 @@ public final class Settings {
            VALIDATORS.put(ASSIST_GESTURE_WAKE_ENABLED, ASSIST_GESTURE_WAKE_ENABLED_VALIDATOR);
            VALIDATORS.put(VR_DISPLAY_MODE, VR_DISPLAY_MODE_VALIDATOR);
            VALIDATORS.put(NOTIFICATION_BADGING, NOTIFICATION_BADGING_VALIDATOR);
            VALIDATORS.put(NOTIFICATION_BUBBLES, NOTIFICATION_BUBBLES_VALIDATOR);
            VALIDATORS.put(NOTIFICATION_DISMISS_RTL, NOTIFICATION_DISMISS_RTL_VALIDATOR);
            VALIDATORS.put(QS_AUTO_ADDED_TILES, QS_AUTO_ADDED_TILES_VALIDATOR);
            VALIDATORS.put(SCREENSAVER_ENABLED, SCREENSAVER_ENABLED_VALIDATOR);
+29 −2
Original line number Diff line number Diff line
@@ -1503,6 +1503,7 @@ public abstract class NotificationListenerService extends Service {
        private boolean mNoisy;
        private ArrayList<Notification.Action> mSmartActions;
        private ArrayList<CharSequence> mSmartReplies;
        private boolean mCanBubble;

        public Ranking() {}

@@ -1677,6 +1678,17 @@ public abstract class NotificationListenerService extends Service {
            return mLastAudiblyAlertedMs;
        }

        /**
         * Returns whether the user has allowed bubbles globally, at the app level, and at the
         * channel level for this notification.
         *
         * <p>This does not take into account the current importance of the notification, the
         * current DND state, or whether the posting app is foreground.</p>
         */
        public boolean canBubble() {
            return mCanBubble;
        }

        /** @hide */
        public boolean isNoisy() {
            return mNoisy;
@@ -1693,7 +1705,7 @@ public abstract class NotificationListenerService extends Service {
                ArrayList<SnoozeCriterion> snoozeCriteria, boolean showBadge,
                int userSentiment, boolean hidden, long lastAudiblyAlertedMs,
                boolean noisy, ArrayList<Notification.Action> smartActions,
                ArrayList<CharSequence> smartReplies) {
                ArrayList<CharSequence> smartReplies, boolean canBubble) {
            mKey = key;
            mRank = rank;
            mIsAmbient = importance < NotificationManager.IMPORTANCE_LOW;
@@ -1713,6 +1725,7 @@ public abstract class NotificationListenerService extends Service {
            mNoisy = noisy;
            mSmartActions = smartActions;
            mSmartReplies = smartReplies;
            mCanBubble = canBubble;
        }

        /**
@@ -1766,6 +1779,7 @@ public abstract class NotificationListenerService extends Service {
        private ArrayMap<String, Boolean> mNoisy;
        private ArrayMap<String, ArrayList<Notification.Action>> mSmartActions;
        private ArrayMap<String, ArrayList<CharSequence>> mSmartReplies;
        private boolean[] mCanBubble;

        private RankingMap(NotificationRankingUpdate rankingUpdate) {
            mRankingUpdate = rankingUpdate;
@@ -1796,7 +1810,7 @@ public abstract class NotificationListenerService extends Service {
                    getChannel(key), getOverridePeople(key), getSnoozeCriteria(key),
                    getShowBadge(key), getUserSentiment(key), getHidden(key),
                    getLastAudiblyAlerted(key), getNoisy(key), getSmartActions(key),
                    getSmartReplies(key));
                    getSmartReplies(key), canBubble(key));
            return rank >= 0;
        }

@@ -1972,6 +1986,19 @@ public abstract class NotificationListenerService extends Service {
            return mSmartReplies.get(key);
        }

        private boolean canBubble(String key) {
            synchronized (this) {
                if (mRanks == null) {
                    buildRanksLocked();
                }
                if (mCanBubble == null) {
                    mCanBubble = mRankingUpdate.getCanBubble();
                }
            }
            int keyIndex = mRanks.getOrDefault(key, -1);
            return keyIndex >= 0 ? mCanBubble[keyIndex] : false;
        }

        // Locked by 'this'
        private void buildRanksLocked() {
            String[] orderedKeys = mRankingUpdate.getOrderedKeys();
Loading