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:
Beverly
2018-07-02 16:46:11 -04:00
parent ee8bf5d463
commit b00cef308e
9 changed files with 45 additions and 36 deletions

View File

@@ -117,7 +117,7 @@ abstract public class AbstractZenModePreferenceController extends
} }
protected int getZenDuration() { protected int getZenDuration() {
return Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.ZEN_DURATION, return Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.ZEN_DURATION,
0); 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_URI = Settings.Global.getUriFor(Settings.Global.ZEN_MODE);
private final Uri ZEN_MODE_CONFIG_ETAG_URI = Settings.Global.getUriFor( private final Uri ZEN_MODE_CONFIG_ETAG_URI = Settings.Global.getUriFor(
Settings.Global.ZEN_MODE_CONFIG_ETAG); Settings.Global.ZEN_MODE_CONFIG_ETAG);
private final Uri ZEN_MODE_DURATION_URI = Settings.Global.getUriFor( private final Uri ZEN_MODE_DURATION_URI = Settings.Secure.getUriFor(
Settings.Global.ZEN_DURATION); Settings.Secure.ZEN_DURATION);
private final Preference mPreference; private final Preference mPreference;

View File

@@ -16,10 +16,10 @@
package com.android.settings.notification; 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.content.Context;
import android.provider.Settings.Global; import android.provider.Settings.Secure;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment; import com.android.settings.SettingsPreferenceFragment;
@@ -33,7 +33,7 @@ public class ChargingSoundPreferenceController extends SettingPrefController {
Lifecycle lifecycle) { Lifecycle lifecycle) {
super(context, parent, lifecycle); super(context, parent, lifecycle);
mPreference = new SettingPref( 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 @Override

View File

@@ -21,6 +21,7 @@ import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.net.Uri; import android.net.Uri;
import android.provider.Settings.Global; import android.provider.Settings.Global;
import android.provider.Settings.Secure;
import android.provider.Settings.System; import android.provider.Settings.System;
import com.android.settings.SettingsPreferenceFragment; import com.android.settings.SettingsPreferenceFragment;
@@ -34,6 +35,7 @@ import androidx.preference.TwoStatePreference;
public class SettingPref { public class SettingPref {
public static final int TYPE_GLOBAL = 1; public static final int TYPE_GLOBAL = 1;
public static final int TYPE_SYSTEM = 2; public static final int TYPE_SYSTEM = 2;
public static final int TYPE_SECURE = 3;
protected final int mType; protected final int mType;
private final String mKey; private final String mKey;
@@ -132,6 +134,8 @@ public class SettingPref {
return Global.getUriFor(setting); return Global.getUriFor(setting);
case TYPE_SYSTEM: case TYPE_SYSTEM:
return System.getUriFor(setting); return System.getUriFor(setting);
case TYPE_SECURE:
return Secure.getUriFor(setting);
} }
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
@@ -142,6 +146,8 @@ public class SettingPref {
return Global.putInt(cr, setting, value); return Global.putInt(cr, setting, value);
case TYPE_SYSTEM: case TYPE_SYSTEM:
return System.putInt(cr, setting, value); return System.putInt(cr, setting, value);
case TYPE_SECURE:
return Secure.putInt(cr, setting, value);
} }
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
@@ -152,6 +158,8 @@ public class SettingPref {
return Global.getInt(cr, setting, def); return Global.getInt(cr, setting, def);
case TYPE_SYSTEM: case TYPE_SYSTEM:
return System.getInt(cr, setting, def); return System.getInt(cr, setting, def);
case TYPE_SECURE:
return Secure.getInt(cr, setting, def);
} }
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }

View File

@@ -136,8 +136,8 @@ public class ZenModeBackend {
} }
protected void saveVisualEffectsPolicy(int category, boolean suppress) { protected void saveVisualEffectsPolicy(int category, boolean suppress) {
Settings.Global.putInt(mContext.getContentResolver(), Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Global.ZEN_SETTINGS_UPDATED, 1); Settings.Secure.ZEN_SETTINGS_UPDATED, 1);
int suppressedEffects = getNewSuppressedEffects(suppress, category); int suppressedEffects = getNewSuppressedEffects(suppress, category);
savePolicy(mPolicy.priorityCategories, mPolicy.priorityCallSenders, savePolicy(mPolicy.priorityCategories, mPolicy.priorityCallSenders,

View File

@@ -97,14 +97,14 @@ public class ZenModeButtonPreferenceController extends AbstractZenModePreference
private void updateZenButtonOnClickListener() { private void updateZenButtonOnClickListener() {
int zenDuration = getZenDuration(); int zenDuration = getZenDuration();
switch (zenDuration) { switch (zenDuration) {
case Settings.Global.ZEN_DURATION_PROMPT: case Settings.Secure.ZEN_DURATION_PROMPT:
mZenButtonOn.setOnClickListener(v -> { mZenButtonOn.setOnClickListener(v -> {
mMetricsFeatureProvider.action(mContext, mMetricsFeatureProvider.action(mContext,
MetricsProto.MetricsEvent.ACTION_ZEN_TOGGLE_DND_BUTTON, false); MetricsProto.MetricsEvent.ACTION_ZEN_TOGGLE_DND_BUTTON, false);
new SettingsEnableZenModeDialog().show(mFragment, TAG); new SettingsEnableZenModeDialog().show(mFragment, TAG);
}); });
break; break;
case Settings.Global.ZEN_DURATION_FOREVER: case Settings.Secure.ZEN_DURATION_FOREVER:
mZenButtonOn.setOnClickListener(v -> { mZenButtonOn.setOnClickListener(v -> {
mMetricsFeatureProvider.action(mContext, mMetricsFeatureProvider.action(mContext,
MetricsProto.MetricsEvent.ACTION_ZEN_TOGGLE_DND_BUTTON, false); MetricsProto.MetricsEvent.ACTION_ZEN_TOGGLE_DND_BUTTON, false);

View File

@@ -62,8 +62,8 @@ public class ZenOnboardingActivity extends Activity {
setMetricsLogger(new MetricsLogger()); setMetricsLogger(new MetricsLogger());
Context context = getApplicationContext(); Context context = getApplicationContext();
Settings.Global.putInt(context.getContentResolver(), Settings.Secure.putInt(context.getContentResolver(),
Settings.Global.ZEN_SETTINGS_SUGGESTION_VIEWED, 1); Settings.Secure.ZEN_SETTINGS_SUGGESTION_VIEWED, 1);
setupUI(); setupUI();
} }
@@ -135,8 +135,8 @@ public class ZenOnboardingActivity extends Activity {
mMetrics.action(MetricsEvent.ACTION_ZEN_ONBOARDING_KEEP_CURRENT_SETTINGS); mMetrics.action(MetricsEvent.ACTION_ZEN_ONBOARDING_KEEP_CURRENT_SETTINGS);
} }
Settings.Global.putInt(getApplicationContext().getContentResolver(), Settings.Secure.putInt(getApplicationContext().getContentResolver(),
Settings.Global.ZEN_SETTINGS_UPDATED, 1); Settings.Secure.ZEN_SETTINGS_UPDATED, 1);
finishAndRemoveTask(); finishAndRemoveTask();
} }
@@ -160,11 +160,11 @@ public class ZenOnboardingActivity extends Activity {
NotificationManager nm = context.getSystemService(NotificationManager.class); NotificationManager nm = context.getSystemService(NotificationManager.class);
if (NotificationManager.Policy.areAllVisualEffectsSuppressed( if (NotificationManager.Policy.areAllVisualEffectsSuppressed(
nm.getNotificationPolicy().suppressedVisualEffects)) { nm.getNotificationPolicy().suppressedVisualEffects)) {
Settings.Global.putInt(context.getContentResolver(), Settings.Secure.putInt(context.getContentResolver(),
Settings.Global.ZEN_SETTINGS_UPDATED, 1); Settings.Secure.ZEN_SETTINGS_UPDATED, 1);
} }
return Settings.Global.getInt(context.getContentResolver(), return Settings.Secure.getInt(context.getContentResolver(),
Settings.Global.ZEN_SETTINGS_UPDATED, 0) != 0; Settings.Secure.ZEN_SETTINGS_UPDATED, 0) != 0;
} }
private static boolean showSuggestion(Context context) { private static boolean showSuggestion(Context context) {
@@ -173,8 +173,8 @@ public class ZenOnboardingActivity extends Activity {
// SHOW_ZEN_SETTINGS_SUGGESTION is also true when: // SHOW_ZEN_SETTINGS_SUGGESTION is also true when:
// - automatic rule has started DND and user has not seen the first use dialog // - automatic rule has started DND and user has not seen the first use dialog
return Settings.Global.getInt(context.getContentResolver(), return Settings.Secure.getInt(context.getContentResolver(),
Settings.Global.SHOW_ZEN_SETTINGS_SUGGESTION, 0) != 0; Settings.Secure.SHOW_ZEN_SETTINGS_SUGGESTION, 0) != 0;
} }

View File

@@ -17,13 +17,14 @@
package com.android.settings.notification; package com.android.settings.notification;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.provider.Settings.Global; import android.provider.Settings.Secure;
import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -80,7 +81,7 @@ public class ChargingSoundPreferenceControllerTest {
@Test @Test
public void displayPreference_chargingSoundEnabled_shouldCheckedPreference() { public void displayPreference_chargingSoundEnabled_shouldCheckedPreference() {
Global.putInt(mContentResolver, Global.CHARGING_SOUNDS_ENABLED, 1); Secure.putInt(mContentResolver, Secure.CHARGING_SOUNDS_ENABLED, 1);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
@@ -89,7 +90,7 @@ public class ChargingSoundPreferenceControllerTest {
@Test @Test
public void displayPreference_chargingSoundDisabled_shouldUncheckedPreference() { public void displayPreference_chargingSoundDisabled_shouldUncheckedPreference() {
Global.putInt(mContentResolver, Global.CHARGING_SOUNDS_ENABLED, 0); Secure.putInt(mContentResolver, Secure.CHARGING_SOUNDS_ENABLED, 0);
mController.displayPreference(mScreen); mController.displayPreference(mScreen);
@@ -102,7 +103,7 @@ public class ChargingSoundPreferenceControllerTest {
mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, true); 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); .isEqualTo(1);
} }
@@ -112,7 +113,7 @@ public class ChargingSoundPreferenceControllerTest {
mPreference.getOnPreferenceChangeListener().onPreferenceChange(mPreference, false); 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); .isEqualTo(0);
} }
} }

View File

@@ -78,8 +78,8 @@ public class ZenModeDurationPreferenceControllerTest {
@Test @Test
public void updateState_DurationForever() { public void updateState_DurationForever() {
Settings.Global.putInt(mContentResolver, Settings.Global.ZEN_DURATION, Settings.Secure.putInt(mContentResolver, Settings.Secure.ZEN_DURATION,
Settings.Global.ZEN_DURATION_FOREVER); Settings.Secure.ZEN_DURATION_FOREVER);
final Preference mockPref = mock(Preference.class); final Preference mockPref = mock(Preference.class);
mController.updateState(mockPref); mController.updateState(mockPref);
@@ -88,8 +88,8 @@ public class ZenModeDurationPreferenceControllerTest {
@Test @Test
public void updateState_DurationPrompt() { public void updateState_DurationPrompt() {
Settings.Global.putInt(mContentResolver, Settings.Global.ZEN_DURATION, Settings.Secure.putInt(mContentResolver, Settings.Secure.ZEN_DURATION,
Settings.Global.ZEN_DURATION_PROMPT); Settings.Secure.ZEN_DURATION_PROMPT);
final Preference mockPref = mock(Preference.class); final Preference mockPref = mock(Preference.class);
mController.updateState(mockPref); mController.updateState(mockPref);
@@ -100,7 +100,7 @@ public class ZenModeDurationPreferenceControllerTest {
@Test @Test
public void updateState_DurationCustom() { public void updateState_DurationCustom() {
int zenDuration = 45; int zenDuration = 45;
Settings.Global.putInt(mContentResolver, Settings.Global.ZEN_DURATION, Settings.Secure.putInt(mContentResolver, Settings.Secure.ZEN_DURATION,
zenDuration); zenDuration);
final Preference mockPref = mock(Preference.class); final Preference mockPref = mock(Preference.class);
mController.updateState(mockPref); mController.updateState(mockPref);

View File

@@ -177,16 +177,16 @@ public class ZenOnboardingActivityTest {
setShowSettingsSuggestion(true); setShowSettingsSuggestion(true);
setWithinTimeThreshold(true); setWithinTimeThreshold(true);
assertThat(isSuggestionComplete(mContext)).isTrue(); assertThat(isSuggestionComplete(mContext)).isTrue();
assertThat(Settings.Global.getInt(mContext.getContentResolver(), assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Global.ZEN_SETTINGS_UPDATED, -1)).isEqualTo(1); Settings.Secure.ZEN_SETTINGS_UPDATED, -1)).isEqualTo(1);
} }
private void setZenUpdated(boolean updated) { private void setZenUpdated(boolean updated) {
int zenUpdated = updated ? 1 : 0; int zenUpdated = updated ? 1 : 0;
Settings.Global.putInt(mContext.getContentResolver(), Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Global.ZEN_SETTINGS_UPDATED, zenUpdated); Settings.Secure.ZEN_SETTINGS_UPDATED, zenUpdated);
} }
private void setWithinTimeThreshold(boolean withinTime) { private void setWithinTimeThreshold(boolean withinTime) {
@@ -208,8 +208,8 @@ public class ZenOnboardingActivityTest {
showZenSuggestion = 1; showZenSuggestion = 1;
} }
Settings.Global.putInt(mContext.getContentResolver(), Settings.Secure.putInt(mContext.getContentResolver(),
Settings.Global.SHOW_ZEN_SETTINGS_SUGGESTION, showZenSuggestion); Settings.Secure.SHOW_ZEN_SETTINGS_SUGGESTION, showZenSuggestion);
} }
private SharedPreferences getSharedPreferences() { private SharedPreferences getSharedPreferences() {