diff --git a/src/com/android/settings/notification/AbstractZenModePreferenceController.java b/src/com/android/settings/notification/AbstractZenModePreferenceController.java index 5d92279ca5a..791e28c3cf1 100644 --- a/src/com/android/settings/notification/AbstractZenModePreferenceController.java +++ b/src/com/android/settings/notification/AbstractZenModePreferenceController.java @@ -117,7 +117,7 @@ abstract public class AbstractZenModePreferenceController extends } protected int getZenDuration() { - return Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.ZEN_DURATION, + return Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.ZEN_DURATION, 0); } @@ -125,8 +125,8 @@ abstract public class AbstractZenModePreferenceController extends private final Uri ZEN_MODE_URI = Settings.Global.getUriFor(Settings.Global.ZEN_MODE); private final Uri ZEN_MODE_CONFIG_ETAG_URI = Settings.Global.getUriFor( Settings.Global.ZEN_MODE_CONFIG_ETAG); - private final Uri ZEN_MODE_DURATION_URI = Settings.Global.getUriFor( - Settings.Global.ZEN_DURATION); + private final Uri ZEN_MODE_DURATION_URI = Settings.Secure.getUriFor( + Settings.Secure.ZEN_DURATION); private final Preference mPreference; diff --git a/src/com/android/settings/notification/ChargingSoundPreferenceController.java b/src/com/android/settings/notification/ChargingSoundPreferenceController.java index fccde6a56e3..c7cd232a031 100644 --- a/src/com/android/settings/notification/ChargingSoundPreferenceController.java +++ b/src/com/android/settings/notification/ChargingSoundPreferenceController.java @@ -16,10 +16,10 @@ package com.android.settings.notification; -import static com.android.settings.notification.SettingPref.TYPE_GLOBAL; +import static com.android.settings.notification.SettingPref.TYPE_SECURE; import android.content.Context; -import android.provider.Settings.Global; +import android.provider.Settings.Secure; import com.android.settings.R; import com.android.settings.SettingsPreferenceFragment; @@ -33,7 +33,7 @@ public class ChargingSoundPreferenceController extends SettingPrefController { Lifecycle lifecycle) { super(context, parent, lifecycle); mPreference = new SettingPref( - TYPE_GLOBAL, KEY_CHARGING_SOUNDS, Global.CHARGING_SOUNDS_ENABLED, DEFAULT_ON); + TYPE_SECURE, KEY_CHARGING_SOUNDS, Secure.CHARGING_SOUNDS_ENABLED, DEFAULT_ON); } @Override diff --git a/src/com/android/settings/notification/SettingPref.java b/src/com/android/settings/notification/SettingPref.java index a651e6ac655..f7152fa19a3 100644 --- a/src/com/android/settings/notification/SettingPref.java +++ b/src/com/android/settings/notification/SettingPref.java @@ -21,6 +21,7 @@ import android.content.Context; import android.content.res.Resources; import android.net.Uri; import android.provider.Settings.Global; +import android.provider.Settings.Secure; import android.provider.Settings.System; import com.android.settings.SettingsPreferenceFragment; @@ -34,6 +35,7 @@ import androidx.preference.TwoStatePreference; public class SettingPref { public static final int TYPE_GLOBAL = 1; public static final int TYPE_SYSTEM = 2; + public static final int TYPE_SECURE = 3; protected final int mType; private final String mKey; @@ -132,6 +134,8 @@ public class SettingPref { return Global.getUriFor(setting); case TYPE_SYSTEM: return System.getUriFor(setting); + case TYPE_SECURE: + return Secure.getUriFor(setting); } throw new IllegalArgumentException(); } @@ -142,6 +146,8 @@ public class SettingPref { return Global.putInt(cr, setting, value); case TYPE_SYSTEM: return System.putInt(cr, setting, value); + case TYPE_SECURE: + return Secure.putInt(cr, setting, value); } throw new IllegalArgumentException(); } @@ -152,6 +158,8 @@ public class SettingPref { return Global.getInt(cr, setting, def); case TYPE_SYSTEM: return System.getInt(cr, setting, def); + case TYPE_SECURE: + return Secure.getInt(cr, setting, def); } throw new IllegalArgumentException(); } diff --git a/src/com/android/settings/notification/ZenModeBackend.java b/src/com/android/settings/notification/ZenModeBackend.java index 8242e3e9883..d63bed47637 100644 --- a/src/com/android/settings/notification/ZenModeBackend.java +++ b/src/com/android/settings/notification/ZenModeBackend.java @@ -136,8 +136,8 @@ public class ZenModeBackend { } protected void saveVisualEffectsPolicy(int category, boolean suppress) { - Settings.Global.putInt(mContext.getContentResolver(), - Settings.Global.ZEN_SETTINGS_UPDATED, 1); + Settings.Secure.putInt(mContext.getContentResolver(), + Settings.Secure.ZEN_SETTINGS_UPDATED, 1); int suppressedEffects = getNewSuppressedEffects(suppress, category); savePolicy(mPolicy.priorityCategories, mPolicy.priorityCallSenders, diff --git a/src/com/android/settings/notification/ZenModeButtonPreferenceController.java b/src/com/android/settings/notification/ZenModeButtonPreferenceController.java index ac9aaba632d..03e63e3a648 100644 --- a/src/com/android/settings/notification/ZenModeButtonPreferenceController.java +++ b/src/com/android/settings/notification/ZenModeButtonPreferenceController.java @@ -97,14 +97,14 @@ public class ZenModeButtonPreferenceController extends AbstractZenModePreference private void updateZenButtonOnClickListener() { int zenDuration = getZenDuration(); switch (zenDuration) { - case Settings.Global.ZEN_DURATION_PROMPT: + case Settings.Secure.ZEN_DURATION_PROMPT: mZenButtonOn.setOnClickListener(v -> { mMetricsFeatureProvider.action(mContext, MetricsProto.MetricsEvent.ACTION_ZEN_TOGGLE_DND_BUTTON, false); new SettingsEnableZenModeDialog().show(mFragment, TAG); }); break; - case Settings.Global.ZEN_DURATION_FOREVER: + case Settings.Secure.ZEN_DURATION_FOREVER: mZenButtonOn.setOnClickListener(v -> { mMetricsFeatureProvider.action(mContext, MetricsProto.MetricsEvent.ACTION_ZEN_TOGGLE_DND_BUTTON, false); diff --git a/src/com/android/settings/notification/ZenOnboardingActivity.java b/src/com/android/settings/notification/ZenOnboardingActivity.java index 99bc1723c1e..3f12358f8ef 100644 --- a/src/com/android/settings/notification/ZenOnboardingActivity.java +++ b/src/com/android/settings/notification/ZenOnboardingActivity.java @@ -62,8 +62,8 @@ public class ZenOnboardingActivity extends Activity { setMetricsLogger(new MetricsLogger()); Context context = getApplicationContext(); - Settings.Global.putInt(context.getContentResolver(), - Settings.Global.ZEN_SETTINGS_SUGGESTION_VIEWED, 1); + Settings.Secure.putInt(context.getContentResolver(), + Settings.Secure.ZEN_SETTINGS_SUGGESTION_VIEWED, 1); setupUI(); } @@ -135,8 +135,8 @@ public class ZenOnboardingActivity extends Activity { mMetrics.action(MetricsEvent.ACTION_ZEN_ONBOARDING_KEEP_CURRENT_SETTINGS); } - Settings.Global.putInt(getApplicationContext().getContentResolver(), - Settings.Global.ZEN_SETTINGS_UPDATED, 1); + Settings.Secure.putInt(getApplicationContext().getContentResolver(), + Settings.Secure.ZEN_SETTINGS_UPDATED, 1); finishAndRemoveTask(); } @@ -160,11 +160,11 @@ public class ZenOnboardingActivity extends Activity { NotificationManager nm = context.getSystemService(NotificationManager.class); if (NotificationManager.Policy.areAllVisualEffectsSuppressed( nm.getNotificationPolicy().suppressedVisualEffects)) { - Settings.Global.putInt(context.getContentResolver(), - Settings.Global.ZEN_SETTINGS_UPDATED, 1); + Settings.Secure.putInt(context.getContentResolver(), + Settings.Secure.ZEN_SETTINGS_UPDATED, 1); } - return Settings.Global.getInt(context.getContentResolver(), - Settings.Global.ZEN_SETTINGS_UPDATED, 0) != 0; + return Settings.Secure.getInt(context.getContentResolver(), + Settings.Secure.ZEN_SETTINGS_UPDATED, 0) != 0; } private static boolean showSuggestion(Context context) { @@ -173,8 +173,8 @@ public class ZenOnboardingActivity extends Activity { // SHOW_ZEN_SETTINGS_SUGGESTION is also true when: // - automatic rule has started DND and user has not seen the first use dialog - return Settings.Global.getInt(context.getContentResolver(), - Settings.Global.SHOW_ZEN_SETTINGS_SUGGESTION, 0) != 0; + return Settings.Secure.getInt(context.getContentResolver(), + Settings.Secure.SHOW_ZEN_SETTINGS_SUGGESTION, 0) != 0; } diff --git a/tests/robotests/src/com/android/settings/notification/ChargingSoundPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ChargingSoundPreferenceControllerTest.java index d54ef6fc3cc..2796049154c 100644 --- a/tests/robotests/src/com/android/settings/notification/ChargingSoundPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/ChargingSoundPreferenceControllerTest.java @@ -17,13 +17,14 @@ package com.android.settings.notification; import static com.google.common.truth.Truth.assertThat; + import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import android.content.ContentResolver; import android.content.Context; -import android.provider.Settings.Global; +import android.provider.Settings.Secure; import com.android.settings.testutils.SettingsRobolectricTestRunner; @@ -80,7 +81,7 @@ public class ChargingSoundPreferenceControllerTest { @Test public void displayPreference_chargingSoundEnabled_shouldCheckedPreference() { - Global.putInt(mContentResolver, Global.CHARGING_SOUNDS_ENABLED, 1); + Secure.putInt(mContentResolver, Secure.CHARGING_SOUNDS_ENABLED, 1); mController.displayPreference(mScreen); @@ -89,7 +90,7 @@ public class ChargingSoundPreferenceControllerTest { @Test public void displayPreference_chargingSoundDisabled_shouldUncheckedPreference() { - Global.putInt(mContentResolver, Global.CHARGING_SOUNDS_ENABLED, 0); + Secure.putInt(mContentResolver, Secure.CHARGING_SOUNDS_ENABLED, 0); mController.displayPreference(mScreen); @@ -102,7 +103,7 @@ public class ChargingSoundPreferenceControllerTest { mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, true); - assertThat(Global.getInt(mContentResolver, Global.CHARGING_SOUNDS_ENABLED, 1)) + assertThat(Secure.getInt(mContentResolver, Secure.CHARGING_SOUNDS_ENABLED, 1)) .isEqualTo(1); } @@ -112,7 +113,7 @@ public class ChargingSoundPreferenceControllerTest { mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, false); - assertThat(Global.getInt(mContentResolver, Global.CHARGING_SOUNDS_ENABLED, 1)) + assertThat(Secure.getInt(mContentResolver, Secure.CHARGING_SOUNDS_ENABLED, 1)) .isEqualTo(0); } } diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeDurationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeDurationPreferenceControllerTest.java index b748bcb9a9d..bbb2142882f 100644 --- a/tests/robotests/src/com/android/settings/notification/ZenModeDurationPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/ZenModeDurationPreferenceControllerTest.java @@ -78,8 +78,8 @@ public class ZenModeDurationPreferenceControllerTest { @Test public void updateState_DurationForever() { - Settings.Global.putInt(mContentResolver, Settings.Global.ZEN_DURATION, - Settings.Global.ZEN_DURATION_FOREVER); + Settings.Secure.putInt(mContentResolver, Settings.Secure.ZEN_DURATION, + Settings.Secure.ZEN_DURATION_FOREVER); final Preference mockPref = mock(Preference.class); mController.updateState(mockPref); @@ -88,8 +88,8 @@ public class ZenModeDurationPreferenceControllerTest { @Test public void updateState_DurationPrompt() { - Settings.Global.putInt(mContentResolver, Settings.Global.ZEN_DURATION, - Settings.Global.ZEN_DURATION_PROMPT); + Settings.Secure.putInt(mContentResolver, Settings.Secure.ZEN_DURATION, + Settings.Secure.ZEN_DURATION_PROMPT); final Preference mockPref = mock(Preference.class); mController.updateState(mockPref); @@ -100,7 +100,7 @@ public class ZenModeDurationPreferenceControllerTest { @Test public void updateState_DurationCustom() { int zenDuration = 45; - Settings.Global.putInt(mContentResolver, Settings.Global.ZEN_DURATION, + Settings.Secure.putInt(mContentResolver, Settings.Secure.ZEN_DURATION, zenDuration); final Preference mockPref = mock(Preference.class); mController.updateState(mockPref); diff --git a/tests/robotests/src/com/android/settings/notification/ZenOnboardingActivityTest.java b/tests/robotests/src/com/android/settings/notification/ZenOnboardingActivityTest.java index 58468334c19..5b031aacc78 100644 --- a/tests/robotests/src/com/android/settings/notification/ZenOnboardingActivityTest.java +++ b/tests/robotests/src/com/android/settings/notification/ZenOnboardingActivityTest.java @@ -177,16 +177,16 @@ public class ZenOnboardingActivityTest { setShowSettingsSuggestion(true); setWithinTimeThreshold(true); assertThat(isSuggestionComplete(mContext)).isTrue(); - assertThat(Settings.Global.getInt(mContext.getContentResolver(), - Settings.Global.ZEN_SETTINGS_UPDATED, -1)).isEqualTo(1); + assertThat(Settings.Secure.getInt(mContext.getContentResolver(), + Settings.Secure.ZEN_SETTINGS_UPDATED, -1)).isEqualTo(1); } private void setZenUpdated(boolean updated) { int zenUpdated = updated ? 1 : 0; - Settings.Global.putInt(mContext.getContentResolver(), - Settings.Global.ZEN_SETTINGS_UPDATED, zenUpdated); + Settings.Secure.putInt(mContext.getContentResolver(), + Settings.Secure.ZEN_SETTINGS_UPDATED, zenUpdated); } private void setWithinTimeThreshold(boolean withinTime) { @@ -208,8 +208,8 @@ public class ZenOnboardingActivityTest { showZenSuggestion = 1; } - Settings.Global.putInt(mContext.getContentResolver(), - Settings.Global.SHOW_ZEN_SETTINGS_SUGGESTION, showZenSuggestion); + Settings.Secure.putInt(mContext.getContentResolver(), + Settings.Secure.SHOW_ZEN_SETTINGS_SUGGESTION, showZenSuggestion); } private SharedPreferences getSharedPreferences() {