Commit 2befca1c authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

Move SharedPrefs keys from settings to ChromePreferenceKeys.

Use SharedPreferencesManager consistently instead of SharedPreferences
directly. Move the usages to methods in SigninPreferencesManager.

Bug: 1022108
Change-Id: I02d3ff82006722ab92420880342b26e4b6583bd7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2020804
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: default avatarNatalie Chouinard <chouinard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737156}
parent be2478a3
......@@ -7,9 +7,10 @@ package org.chromium.chrome.browser.settings.developer;
import android.os.Bundle;
import android.support.v7.preference.PreferenceFragmentCompat;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeVersionInfo;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.settings.SettingsUtils;
import org.chromium.components.version_info.Channel;
import org.chromium.components.version_info.VersionConstants;
......@@ -19,7 +20,6 @@ import org.chromium.components.version_info.VersionConstants;
*/
public class DeveloperSettings extends PreferenceFragmentCompat {
private static final String UI_PREF_BETA_STABLE_HINT = "beta_stable_hint";
private static final String PREF_DEVELOPER_ENABLED = "developer";
// Non-translated strings:
private static final String MSG_DEVELOPER_OPTIONS_TITLE = "Developer options";
......@@ -28,14 +28,13 @@ public class DeveloperSettings extends PreferenceFragmentCompat {
// Always enabled on canary, dev and local builds, otherwise can be enabled by tapping the
// Chrome version in Settings>About multiple times.
if (VersionConstants.CHANNEL <= Channel.DEV) return true;
return ContextUtils.getAppSharedPreferences().getBoolean(PREF_DEVELOPER_ENABLED, false);
return SharedPreferencesManager.getInstance().readBoolean(
ChromePreferenceKeys.SETTINGS_DEVELOPER_ENABLED, false);
}
public static void setDeveloperSettingsEnabled() {
ContextUtils.getAppSharedPreferences()
.edit()
.putBoolean(PREF_DEVELOPER_ENABLED, true)
.apply();
SharedPreferencesManager.getInstance().writeBoolean(
ChromePreferenceKeys.SETTINGS_DEVELOPER_ENABLED, true);
}
@Override
......
......@@ -12,8 +12,9 @@ import android.support.v7.preference.PreferenceFragmentCompat;
import androidx.annotation.IntDef;
import androidx.annotation.VisibleForTesting;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.settings.SettingsUtils;
import org.chromium.chrome.browser.tracing.TracingController;
import org.chromium.chrome.browser.tracing.TracingNotificationManager;
......@@ -43,9 +44,6 @@ public class TracingSettings
@VisibleForTesting
static final String UI_PREF_TRACING_STATUS = "tracing_status";
private static final String PREF_TRACING_CATEGORIES = "tracing_categories";
private static final String PREF_TRACING_MODE = "tracing_mode";
// Non-translated strings:
private static final String MSG_TRACING_TITLE = "Tracing";
private static final String MSG_PRIVACY_NOTICE =
......@@ -97,8 +95,8 @@ public class TracingSettings
* @return the current set of all enabled categories, irrespective of their type.
*/
public static Set<String> getEnabledCategories() {
Set<String> enabled =
ContextUtils.getAppSharedPreferences().getStringSet(PREF_TRACING_CATEGORIES, null);
Set<String> enabled = SharedPreferencesManager.getInstance().readStringSet(
ChromePreferenceKeys.SETTINGS_DEVELOPER_TRACING_CATEGORIES, null);
if (enabled == null) {
enabled = new HashSet<>();
// By default, enable all default categories.
......@@ -139,10 +137,8 @@ public class TracingSettings
enabled.add(category);
}
}
ContextUtils.getAppSharedPreferences()
.edit()
.putStringSet(PREF_TRACING_CATEGORIES, enabled)
.apply();
SharedPreferencesManager.getInstance().writeStringSet(
ChromePreferenceKeys.SETTINGS_DEVELOPER_TRACING_CATEGORIES, enabled);
}
/**
......@@ -160,8 +156,9 @@ public class TracingSettings
* "record-as-much-as-possible", or "record-continuously".
*/
public static String getSelectedTracingMode() {
return ContextUtils.getAppSharedPreferences().getString(
PREF_TRACING_MODE, TRACING_MODES.keySet().iterator().next());
return SharedPreferencesManager.getInstance().readString(
ChromePreferenceKeys.SETTINGS_DEVELOPER_TRACING_MODE,
TRACING_MODES.keySet().iterator().next());
}
/**
......@@ -172,10 +169,8 @@ public class TracingSettings
*/
public static void setSelectedTracingMode(String tracingMode) {
assert TRACING_MODES.containsKey(tracingMode);
ContextUtils.getAppSharedPreferences()
.edit()
.putString(PREF_TRACING_MODE, tracingMode)
.apply();
SharedPreferencesManager.getInstance().writeString(
ChromePreferenceKeys.SETTINGS_DEVELOPER_TRACING_MODE, tracingMode);
}
@Override
......
......@@ -8,7 +8,6 @@ import android.app.Activity;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.text.SpannableString;
......@@ -19,8 +18,9 @@ import android.widget.TextView;
import androidx.annotation.VisibleForTesting;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.tab.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.document.TabDelegate;
import org.chromium.chrome.browser.util.UrlConstants;
......@@ -33,10 +33,6 @@ import org.chromium.ui.text.SpanApplier;
public class OtherFormsOfHistoryDialogFragment extends DialogFragment implements
DialogInterface.OnClickListener {
public static final String PREF_OTHER_FORMS_OF_HISTORY_DIALOG_SHOWN =
"org.chromium.chrome.browser.settings.privacy."
+ "PREF_OTHER_FORMS_OF_HISTORY_DIALOG_SHOWN";
private static final String TAG = "OtherFormsOfHistoryDialogFragment";
/**
......@@ -84,7 +80,7 @@ public class OtherFormsOfHistoryDialogFragment extends DialogFragment implements
// Remember that the dialog about other forms of browsing history has been shown
// to the user.
recordDialogWasShown(getActivity(), true);
recordDialogWasShown(true);
// Finishes the ClearBrowsingDataPreferences activity that created this dialog.
getActivity().finish();
......@@ -92,32 +88,27 @@ public class OtherFormsOfHistoryDialogFragment extends DialogFragment implements
/**
* Sets the preference indicating whether this dialog was already shown.
* @param activity The Activity storing the preference.
* @param shown Whether the dialog was shown.
*/
private static void recordDialogWasShown(Activity activity, boolean shown) {
SharedPreferences preferences =
ContextUtils.getAppSharedPreferences();
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean(PREF_OTHER_FORMS_OF_HISTORY_DIALOG_SHOWN, shown);
editor.apply();
private static void recordDialogWasShown(boolean shown) {
SharedPreferencesManager.getInstance().writeBoolean(
ChromePreferenceKeys.SETTINGS_PRIVACY_OTHER_FORMS_OF_HISTORY_DIALOG_SHOWN, shown);
}
/**
* @return Whether the dialog has already been shown to the user before.
*/
static boolean wasDialogShown() {
return ContextUtils.getAppSharedPreferences().getBoolean(
PREF_OTHER_FORMS_OF_HISTORY_DIALOG_SHOWN, false);
return SharedPreferencesManager.getInstance().readBoolean(
ChromePreferenceKeys.SETTINGS_PRIVACY_OTHER_FORMS_OF_HISTORY_DIALOG_SHOWN, false);
}
/**
* For testing purposes, resets the preference indicating that this dialog has been shown
* to false.
* @param activity The Activity storing the preference.
*/
@VisibleForTesting
static void clearShownPreferenceForTesting(Activity activity) {
recordDialogWasShown(activity, false);
static void clearShownPreferenceForTesting() {
recordDialogWasShown(false);
}
}
......@@ -30,8 +30,10 @@ import androidx.annotation.Nullable;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.Pref;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.profiles.ProfileAccountManagementMetrics;
import org.chromium.chrome.browser.settings.ChromeBasePreference;
......@@ -76,13 +78,6 @@ public class AccountManagementFragment extends PreferenceFragmentCompat
*/
public static final String SHOW_GAIA_SERVICE_TYPE_EXTRA = "ShowGAIAServiceType";
/**
* SharedPreference name for the preference that disables signing out of Chrome.
* Signing out is forever disabled once Chrome signs the user in automatically
* if the device has a child account or if the device is an Android EDU device.
*/
private static final String SIGN_OUT_ALLOWED = "auto_signed_in_school_account";
public static final String PREF_ACCOUNTS_CATEGORY = "accounts_category";
public static final String PREF_PARENTAL_SETTINGS = "parental_settings";
public static final String PREF_PARENT_ACCOUNTS = "parent_accounts";
......@@ -420,7 +415,8 @@ public class AccountManagementFragment extends PreferenceFragmentCompat
* @return Whether the sign out is not disabled due to a child/EDU account.
*/
private static boolean getSignOutAllowedPreferenceValue() {
return ContextUtils.getAppSharedPreferences().getBoolean(SIGN_OUT_ALLOWED, true);
return SharedPreferencesManager.getInstance().readBoolean(
ChromePreferenceKeys.SETTINGS_SYNC_SIGN_OUT_ALLOWED, true);
}
/**
......@@ -429,9 +425,7 @@ public class AccountManagementFragment extends PreferenceFragmentCompat
* @param isAllowed True if the sign out is not disabled due to a child/EDU account
*/
public static void setSignOutAllowedPreferenceValue(boolean isAllowed) {
ContextUtils.getAppSharedPreferences()
.edit()
.putBoolean(SIGN_OUT_ALLOWED, isAllowed)
.apply();
SharedPreferencesManager.getInstance().writeBoolean(
ChromePreferenceKeys.SETTINGS_SYNC_SIGN_OUT_ALLOWED, isAllowed);
}
}
......@@ -26,7 +26,6 @@ import android.widget.TextView;
import androidx.annotation.VisibleForTesting;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.metrics.RecordUserAction;
......@@ -36,6 +35,8 @@ import org.chromium.chrome.browser.init.BrowserParts;
import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
import org.chromium.chrome.browser.init.EmptyBrowserParts;
import org.chromium.chrome.browser.notifications.channels.SiteChannelsManager;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.searchwidget.SearchWidgetProvider;
import org.chromium.chrome.browser.settings.SettingsLauncher;
import org.chromium.chrome.browser.settings.about.AboutChromeSettings;
......@@ -61,8 +62,6 @@ public class ManageSpaceActivity extends AppCompatActivity implements View.OnCli
private static final int OPTION_CLEAR_APP_DATA = 2;
private static final int OPTION_MAX = 3;
private static final String PREF_FAILED_BUILD_VERSION = "ManagedSpace.FailedBuildVersion";
private TextView mUnimportantSiteDataSizeText;
private TextView mSiteDataSizeText;
private Button mClearUnimportantButton;
......@@ -126,8 +125,8 @@ public class ManageSpaceActivity extends AppCompatActivity implements View.OnCli
try {
String productVersion = AboutChromeSettings.getApplicationVersion(
this, ChromeVersionInfo.getProductVersion());
String failedVersion = ContextUtils.getAppSharedPreferences().getString(
PREF_FAILED_BUILD_VERSION, null);
String failedVersion = SharedPreferencesManager.getInstance().readString(
ChromePreferenceKeys.SETTINGS_WEBSITE_FAILED_BUILD_VERSION, null);
if (TextUtils.equals(failedVersion, productVersion)) {
parts.onStartupFailure();
return;
......@@ -137,9 +136,8 @@ public class ManageSpaceActivity extends AppCompatActivity implements View.OnCli
// java-side the pref will be written before the process dies. We want to make sure we
// don't attempt to start the browser process and have it kill chrome. This activity is
// used to clear data for the chrome app, so it must be particularly error resistant.
ContextUtils.getAppSharedPreferences().edit()
.putString(PREF_FAILED_BUILD_VERSION, productVersion)
.commit();
SharedPreferencesManager.getInstance().writeStringSync(
ChromePreferenceKeys.SETTINGS_WEBSITE_FAILED_BUILD_VERSION, productVersion);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
......@@ -174,9 +172,8 @@ public class ManageSpaceActivity extends AppCompatActivity implements View.OnCli
protected void onStop() {
super.onStop();
ContextUtils.getAppSharedPreferences().edit()
.putString(PREF_FAILED_BUILD_VERSION, null)
.apply();
SharedPreferencesManager.getInstance().writeString(
ChromePreferenceKeys.SETTINGS_WEBSITE_FAILED_BUILD_VERSION, null);
}
@VisibleForTesting
......
......@@ -281,8 +281,7 @@ public class ClearBrowsingDataFragmentTest {
public void testDialogAboutOtherFormsOfBrowsingHistory() {
// Sign in.
SigninTestUtil.addAndSignInTestAccount();
OtherFormsOfHistoryDialogFragment.clearShownPreferenceForTesting(
mActivityTestRule.getActivity());
OtherFormsOfHistoryDialogFragment.clearShownPreferenceForTesting();
// History is not selected. We still need to select some other datatype, otherwise the
// "Clear" button won't be enabled.
......
......@@ -505,6 +505,24 @@ public final class ChromePreferenceKeys {
public static final String SEARCH_ENGINE_CHOICE_REQUESTED_TIMESTAMP =
"search_engine_choice_requested_timestamp";
public static final String SETTINGS_DEVELOPER_ENABLED = "developer";
public static final String SETTINGS_DEVELOPER_TRACING_CATEGORIES = "tracing_categories";
public static final String SETTINGS_DEVELOPER_TRACING_MODE = "tracing_mode";
/**
* SharedPreference name for the preference that disables signing out of Chrome.
* Signing out is forever disabled once Chrome signs the user in automatically
* if the device has a child account or if the device is an Android EDU device.
*/
public static final String SETTINGS_SYNC_SIGN_OUT_ALLOWED = "auto_signed_in_school_account";
public static final String SETTINGS_PRIVACY_OTHER_FORMS_OF_HISTORY_DIALOG_SHOWN =
"org.chromium.chrome.browser.settings.privacy."
+ "PREF_OTHER_FORMS_OF_HISTORY_DIALOG_SHOWN";
public static final String SETTINGS_WEBSITE_FAILED_BUILD_VERSION =
"ManagedSpace.FailedBuildVersion";
public static final String SHARING_LAST_SHARED_CLASS_NAME = "last_shared_class_name";
public static final String SHARING_LAST_SHARED_PACKAGE_NAME = "last_shared_package_name";
......@@ -839,6 +857,12 @@ public final class ChromePreferenceKeys {
SEARCH_ENGINE_CHOICE_DEFAULT_TYPE_BEFORE,
SEARCH_ENGINE_CHOICE_PRESENTED_VERSION,
SEARCH_ENGINE_CHOICE_REQUESTED_TIMESTAMP,
SETTINGS_DEVELOPER_ENABLED,
SETTINGS_DEVELOPER_TRACING_CATEGORIES,
SETTINGS_DEVELOPER_TRACING_MODE,
SETTINGS_PRIVACY_OTHER_FORMS_OF_HISTORY_DIALOG_SHOWN,
SETTINGS_SYNC_SIGN_OUT_ALLOWED,
SETTINGS_WEBSITE_FAILED_BUILD_VERSION,
SHARING_LAST_SHARED_CLASS_NAME,
SHARING_LAST_SHARED_PACKAGE_NAME,
SIGNIN_ACCOUNTS_CHANGED,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment