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

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

Update the setting to use Global instead of secure, deprecate old one

Deprecates the Secure setting so it's clear we're not using it anymore.

Since this work is for a QPR we need to listen for both the new Global
setting as well as the old Secure setting so that CTS may pass without
code changes:
* When the secure setting is changed (only CTS uses it now), the global
  setting will also be updated.
* When the global setting is changed (i.e. switching developer toggle), the
  global setting is updated and so is the secure setting.

Test: atest NotificationManagerTest
Bug: 137876221
Change-Id: Ib4623689aa4ec1fc79e2ec130702fdf9785834d8
parent b4ad2fc1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2368,7 +2368,7 @@ package android.provider {
    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_BADGING = "notification_badging";
    field public static final String NOTIFICATION_BUBBLES = "notification_bubbles";
    field @Deprecated 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";
+6 −0
Original line number Diff line number Diff line
@@ -8687,10 +8687,16 @@ public final class Settings {
         * Whether the notification bubbles are globally enabled
         * The value is boolean (1 or 0).
         * @hide
         * @deprecated use {@link Global#NOTIFICATION_BUBBLES} instead.
         */
        @TestApi
        @Deprecated
        public static final String NOTIFICATION_BUBBLES = "notification_bubbles";
        /**
         * @deprecated use {@link Global#NOTIFICATION_BUBBLES_VALIDATOR} instead.
         */
        @Deprecated
        private static final Validator NOTIFICATION_BUBBLES_VALIDATOR = BOOLEAN_VALIDATOR;
        /**
+1 −1
Original line number Diff line number Diff line
@@ -2153,7 +2153,7 @@ class SettingsProtoDumpUtil {
                Settings.Secure.NOTIFICATION_BADGING,
                SecureSettingsProto.Notification.BADGING);
        dumpSetting(s, p,
                Settings.Secure.NOTIFICATION_BUBBLES,
                Settings.Global.NOTIFICATION_BUBBLES,
                SecureSettingsProto.Notification.BUBBLES);
        dumpSetting(s, p,
                Settings.Secure.SHOW_NOTE_ABOUT_NOTIFICATION_HIDING,
+41 −4
Original line number Diff line number Diff line
@@ -91,6 +91,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
import static com.android.server.am.PendingIntentRecord.FLAG_ACTIVITY_SENDER;
import static com.android.server.am.PendingIntentRecord.FLAG_BROADCAST_SENDER;
import static com.android.server.am.PendingIntentRecord.FLAG_SERVICE_SENDER;
import static com.android.server.notification.PreferencesHelper.DEFAULT_ALLOW_BUBBLE;
import static com.android.server.utils.PriorityDump.PRIORITY_ARG;
import static com.android.server.utils.PriorityDump.PRIORITY_ARG_CRITICAL;
import static com.android.server.utils.PriorityDump.PRIORITY_ARG_NORMAL;
@@ -1358,8 +1359,10 @@ public class NotificationManagerService extends SystemService {
    private final class SettingsObserver extends ContentObserver {
        private final Uri NOTIFICATION_BADGING_URI
                = Settings.Secure.getUriFor(Settings.Secure.NOTIFICATION_BADGING);
        private final Uri NOTIFICATION_BUBBLES_URI
                = Settings.Secure.getUriFor(Settings.Global.NOTIFICATION_BUBBLES);
        private final Uri NOTIFICATION_BUBBLES_URI_GLOBAL
                = Settings.Global.getUriFor(Settings.Global.NOTIFICATION_BUBBLES);
        private final Uri NOTIFICATION_BUBBLES_URI_SECURE
                = Settings.Secure.getUriFor(Settings.Secure.NOTIFICATION_BUBBLES);
        private final Uri NOTIFICATION_LIGHT_PULSE_URI
                = Settings.System.getUriFor(Settings.System.NOTIFICATION_LIGHT_PULSE);
        private final Uri NOTIFICATION_RATE_LIMIT_URI
@@ -1377,7 +1380,9 @@ public class NotificationManagerService extends SystemService {
                    false, this, UserHandle.USER_ALL);
            resolver.registerContentObserver(NOTIFICATION_RATE_LIMIT_URI,
                    false, this, UserHandle.USER_ALL);
            resolver.registerContentObserver(NOTIFICATION_BUBBLES_URI,
            resolver.registerContentObserver(NOTIFICATION_BUBBLES_URI_GLOBAL,
                    false, this, UserHandle.USER_ALL);
            resolver.registerContentObserver(NOTIFICATION_BUBBLES_URI_SECURE,
                    false, this, UserHandle.USER_ALL);
            update(null);
        }
@@ -1404,9 +1409,41 @@ public class NotificationManagerService extends SystemService {
            if (uri == null || NOTIFICATION_BADGING_URI.equals(uri)) {
                mPreferencesHelper.updateBadgingEnabled();
            }
            if (uri == null || NOTIFICATION_BUBBLES_URI.equals(uri)) {
            // In QPR we moved the setting to Global rather than Secure so that the setting
            // applied to work profiles. Unfortunately we need to maintain both to pass CTS without
            // a change to CTS outside of a normal letter release.
            if (uri == null || NOTIFICATION_BUBBLES_URI_GLOBAL.equals(uri)) {
                syncBubbleSettings(resolver, NOTIFICATION_BUBBLES_URI_GLOBAL);
                mPreferencesHelper.updateBubblesEnabled();
            }
            if (NOTIFICATION_BUBBLES_URI_SECURE.equals(uri)) {
                syncBubbleSettings(resolver, NOTIFICATION_BUBBLES_URI_SECURE);
            }
        }

        private void syncBubbleSettings(ContentResolver resolver, Uri settingToFollow) {
            boolean followSecureSetting = settingToFollow.equals(NOTIFICATION_BUBBLES_URI_SECURE);

            int secureSettingValue = Settings.Secure.getInt(resolver,
                    Settings.Secure.NOTIFICATION_BUBBLES, DEFAULT_ALLOW_BUBBLE ? 1 : 0);
            int globalSettingValue = Settings.Global.getInt(resolver,
                    Settings.Global.NOTIFICATION_BUBBLES, DEFAULT_ALLOW_BUBBLE ? 1 : 0);

            if (globalSettingValue == secureSettingValue) {
                return;
            }

            if (followSecureSetting) {
                // Global => secure
                Settings.Global.putInt(resolver,
                        Settings.Global.NOTIFICATION_BUBBLES,
                        secureSettingValue);
            } else {
                // Secure => Global
                Settings.Secure.putInt(resolver,
                        Settings.Secure.NOTIFICATION_BADGING,
                        globalSettingValue);
            }
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -100,7 +100,7 @@ public class PreferencesHelper implements RankingConfig {
    @VisibleForTesting
    static final boolean DEFAULT_HIDE_SILENT_STATUS_BAR_ICONS = false;
    private static final boolean DEFAULT_SHOW_BADGE = true;
    private static final boolean DEFAULT_ALLOW_BUBBLE = true;
    static final boolean DEFAULT_ALLOW_BUBBLE = true;
    private static final boolean DEFAULT_OEM_LOCKED_IMPORTANCE  = false;
    private static final boolean DEFAULT_APP_LOCKED_IMPORTANCE  = false;