@Override public boolean onPreferenceChange(Preference preference, Object newValue) { // CrashDumpUploadPreference listens to its own PreferenceChanged to update its text. // We have replaced the listener. If we do run into a CrashDumpUploadPreference change, // we will call onPreferenceChange to change the displayed text. if (preference instanceof CrashDumpUploadPreference) { ((CrashDumpUploadPreference) preference).onPreferenceChange(preference, newValue); } // NetworkPredictionPreference listens to its own PreferenceChanged to update its text. // We have replaced the listener. If we do run into a NetworkPredictionPreference change, // we will call onPreferenceChange to change the displayed text. if (preference instanceof NetworkPredictionPreference) { ((NetworkPredictionPreference) preference).onPreferenceChange(preference, newValue); } String key = preference.getKey(); if (PREF_SEARCH_SUGGESTIONS.equals(key)) { PrefServiceBridge.getInstance().setSearchSuggestEnabled((boolean) newValue); } else if (PREF_SAFE_BROWSING.equals(key)) { PrefServiceBridge.getInstance().setSafeBrowsingEnabled((boolean) newValue); } else if (PREF_SAFE_BROWSING_EXTENDED_REPORTING.equals(key)) { PrefServiceBridge.getInstance().setSafeBrowsingExtendedReportingEnabled((boolean) newValue); } else if (PREF_NETWORK_PREDICTIONS.equals(key)) { PrefServiceBridge.getInstance() .setNetworkPredictionOptions(NetworkPredictionOptions.stringToEnum((String) newValue)); PrecacheLauncher.updatePrecachingEnabled(getActivity()); } else if (PREF_NETWORK_PREDICTIONS_NO_CELLULAR.equals(key)) { PrefServiceBridge.getInstance() .setNetworkPredictionOptions( (boolean) newValue ? NetworkPredictionOptions.NETWORK_PREDICTION_ALWAYS : NetworkPredictionOptions.NETWORK_PREDICTION_NEVER); PrecacheLauncher.updatePrecachingEnabled(getActivity()); } else if (PREF_NAVIGATION_ERROR.equals(key)) { PrefServiceBridge.getInstance().setResolveNavigationErrorEnabled((boolean) newValue); } else if (PREF_CRASH_DUMP_UPLOAD_NO_CELLULAR.equals(key)) { PrefServiceBridge.getInstance().setCrashReporting((boolean) newValue); } else if (PREF_CRASH_DUMP_UPLOAD.equals(key)) { PrivacyPreferencesManager.getInstance(getActivity()).setUploadCrashDump((String) newValue); } return true; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PrivacyPreferencesManager privacyPrefManager = PrivacyPreferencesManager.getInstance(getActivity()); privacyPrefManager.migrateNetworkPredictionPreferences(); addPreferencesFromResource(R.xml.privacy_preferences); getActivity().setTitle(R.string.prefs_privacy); setHasOptionsMenu(true); mManagedPreferenceDelegate = createManagedPreferenceDelegate(); NetworkPredictionPreference networkPredictionPref = (NetworkPredictionPreference) findPreference(PREF_NETWORK_PREDICTIONS); ChromeBaseCheckBoxPreference networkPredictionNoCellularPref = (ChromeBaseCheckBoxPreference) findPreference(PREF_NETWORK_PREDICTIONS_NO_CELLULAR); NetworkPredictionOptions networkPredictionOptions = PrefServiceBridge.getInstance().getNetworkPredictionOptions(); PreferenceScreen preferenceScreen = getPreferenceScreen(); boolean isMobileNetworkCapable = privacyPrefManager.isMobileNetworkCapable(); if (isMobileNetworkCapable) { preferenceScreen.removePreference(networkPredictionNoCellularPref); networkPredictionPref.setValue(networkPredictionOptions.enumToString()); networkPredictionPref.setOnPreferenceChangeListener(this); networkPredictionPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate); } else { preferenceScreen.removePreference(networkPredictionPref); networkPredictionNoCellularPref.setChecked( networkPredictionOptions != NetworkPredictionOptions.NETWORK_PREDICTION_NEVER); networkPredictionNoCellularPref.setOnPreferenceChangeListener(this); networkPredictionNoCellularPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate); } // Display the correct settings fragment according to the user experiment group and to type // of the device, by removing not applicable preference fragments. CrashDumpUploadPreference uploadCrashDumpPref = (CrashDumpUploadPreference) findPreference(PREF_CRASH_DUMP_UPLOAD); ChromeBaseCheckBoxPreference uploadCrashDumpNoCellularPref = (ChromeBaseCheckBoxPreference) findPreference(PREF_CRASH_DUMP_UPLOAD_NO_CELLULAR); if (privacyPrefManager.isCellularExperimentEnabled()) { preferenceScreen.removePreference(uploadCrashDumpNoCellularPref); preferenceScreen.removePreference(uploadCrashDumpPref); } else { preferenceScreen.removePreference(findPreference(PREF_USAGE_AND_CRASH_REPORTING)); if (isMobileNetworkCapable) { preferenceScreen.removePreference(uploadCrashDumpNoCellularPref); uploadCrashDumpPref.setOnPreferenceChangeListener(this); uploadCrashDumpPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate); } else { preferenceScreen.removePreference(uploadCrashDumpPref); uploadCrashDumpNoCellularPref.setOnPreferenceChangeListener(this); uploadCrashDumpNoCellularPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate); } } ChromeBaseCheckBoxPreference navigationErrorPref = (ChromeBaseCheckBoxPreference) findPreference(PREF_NAVIGATION_ERROR); navigationErrorPref.setOnPreferenceChangeListener(this); navigationErrorPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate); ChromeBaseCheckBoxPreference searchSuggestionsPref = (ChromeBaseCheckBoxPreference) findPreference(PREF_SEARCH_SUGGESTIONS); searchSuggestionsPref.setOnPreferenceChangeListener(this); searchSuggestionsPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate); if (!ContextualSearchFieldTrial.isEnabled()) { preferenceScreen.removePreference(findPreference(PREF_CONTEXTUAL_SEARCH)); } ChromeBaseCheckBoxPreference safeBrowsingExtendedReportingPref = (ChromeBaseCheckBoxPreference) findPreference(PREF_SAFE_BROWSING_EXTENDED_REPORTING); safeBrowsingExtendedReportingPref.setOnPreferenceChangeListener(this); safeBrowsingExtendedReportingPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate); ChromeBaseCheckBoxPreference safeBrowsingPref = (ChromeBaseCheckBoxPreference) findPreference(PREF_SAFE_BROWSING); safeBrowsingPref.setOnPreferenceChangeListener(this); safeBrowsingPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate); if (!SafeBrowsingFieldTrial.isEnabled()) { preferenceScreen.removePreference(findPreference(PREF_SAFE_BROWSING_EXTENDED_REPORTING)); preferenceScreen.removePreference(findPreference(PREF_SAFE_BROWSING)); } ButtonPreference clearBrowsingData = (ButtonPreference) findPreference(PREF_CLEAR_BROWSING_DATA); clearBrowsingData.setOnPreferenceClickListener( new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { showClearBrowsingDialog(); return true; } }); if (getArguments() != null) { boolean showClearBrowsingData = getArguments().getBoolean(SHOW_CLEAR_BROWSING_DATA_EXTRA, false); if (showClearBrowsingData) showClearBrowsingDialog(); } updateSummaries(); }