Use Settings.Secure values, not Global values
The following Settings are being moved to Settings.Secure from Settings.Global since they are settings that exist per user - CHARGING_SOUNDS_ENABLED - CHARGING_VIBRATION_ENABLED - ZEN_DURATION - SHOW_ZEN_UPGRADE_NOTIFICATION - SHOW_ZEN_SETTINGS_SUGGESTION - ZEN_SETTINGS_UPDATE - ZEN_SETTINGS_SUGGESTION_VIEWED Bug: 110926544 Test: make ROBOTEST_FILTER=ZenModeDurationPreferenceControllerTest RunSettingsRoboTests Change-Id: I3e3d6f6653b81a121fbda7d2f9f1b75651f536b7
This commit is contained in:
@@ -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;
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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();
|
||||
}
|
||||
|
@@ -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,
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -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() {
|
||||
|
Reference in New Issue
Block a user