Java Code Examples for org.chromium.chrome.browser.preferences.PrefServiceBridge#getInstance()
The following examples show how to use
org.chromium.chrome.browser.preferences.PrefServiceBridge#getInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FirstRunGlueImpl.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * Synchronizes first run native and Java preferences. * Must be called after native initialization. */ public static void cacheFirstRunPrefs() { SharedPreferences javaPrefs = ContextUtils.getAppSharedPreferences(); PrefServiceBridge prefsBridge = PrefServiceBridge.getInstance(); // Set both Java and native prefs if any of the three indicators indicate ToS has been // accepted. This needed because: // - Old versions only set native pref, so this syncs Java pref. // - Backup & restore does not restore native pref, so this needs to update it. // - checkAnyUserHasSeenToS() may be true which needs to sync its state to the prefs. boolean javaPrefValue = javaPrefs.getBoolean(CACHED_TOS_ACCEPTED_PREF, false); boolean nativePrefValue = prefsBridge.isFirstRunEulaAccepted(); boolean userHasSeenTos = ToSAckedReceiver.checkAnyUserHasSeenToS(ContextUtils.getApplicationContext()); if (javaPrefValue || nativePrefValue || userHasSeenTos) { if (!javaPrefValue) { javaPrefs.edit().putBoolean(CACHED_TOS_ACCEPTED_PREF, true).apply(); } if (!nativePrefValue) { prefsBridge.setEulaAccepted(); } } }
Example 2
Source File: PrivacyPreferences.java From AndroidChromium with Apache License 2.0 | 6 votes |
private ManagedPreferenceDelegate createManagedPreferenceDelegate() { return new ManagedPreferenceDelegate() { @Override public boolean isPreferenceControlledByPolicy(Preference preference) { String key = preference.getKey(); PrefServiceBridge prefs = PrefServiceBridge.getInstance(); if (PREF_NAVIGATION_ERROR.equals(key)) { return prefs.isResolveNavigationErrorManaged(); } if (PREF_SEARCH_SUGGESTIONS.equals(key)) { return prefs.isSearchSuggestManaged(); } if (PREF_SAFE_BROWSING_EXTENDED_REPORTING.equals(key) || PREF_SAFE_BROWSING_SCOUT_REPORTING.equals(key)) { return prefs.isSafeBrowsingExtendedReportingManaged(); } if (PREF_SAFE_BROWSING.equals(key)) { return prefs.isSafeBrowsingManaged(); } if (PREF_NETWORK_PREDICTIONS.equals(key)) { return prefs.isNetworkPredictionManaged(); } return false; } }; }
Example 3
Source File: LocationCategory.java From AndroidChromium with Apache License 2.0 | 6 votes |
@Override public boolean showPermissionBlockedMessage(Context context) { if (enabledForChrome(context) && enabledGlobally()) { return false; } // The only time we don't want to show location as blocked in system is when Chrome also // blocks Location by policy (because then turning it on in the system isn't going to // turn on location in Chrome). PrefServiceBridge prefs = PrefServiceBridge.getInstance(); if (!LocationSettings.getInstance().isChromeLocationSettingEnabled() && !prefs.isAllowLocationUserModifiable()) { return false; } return true; }
Example 4
Source File: FirstRunGlueImpl.java From 365browser with Apache License 2.0 | 6 votes |
/** * Synchronizes first run native and Java preferences. * Must be called after native initialization. */ public static void cacheFirstRunPrefs() { SharedPreferences javaPrefs = ContextUtils.getAppSharedPreferences(); PrefServiceBridge prefsBridge = PrefServiceBridge.getInstance(); // Set both Java and native prefs if any of the three indicators indicate ToS has been // accepted. This needed because: // - Old versions only set native pref, so this syncs Java pref. // - Backup & restore does not restore native pref, so this needs to update it. // - checkAnyUserHasSeenToS() may be true which needs to sync its state to the prefs. boolean javaPrefValue = javaPrefs.getBoolean(CACHED_TOS_ACCEPTED_PREF, false); boolean nativePrefValue = prefsBridge.isFirstRunEulaAccepted(); boolean userHasSeenTos = ToSAckedReceiver.checkAnyUserHasSeenToS(ContextUtils.getApplicationContext()); boolean isFirstRunComplete = FirstRunStatus.getFirstRunFlowComplete(); if (javaPrefValue || nativePrefValue || userHasSeenTos || isFirstRunComplete) { if (!javaPrefValue) { javaPrefs.edit().putBoolean(CACHED_TOS_ACCEPTED_PREF, true).apply(); } if (!nativePrefValue) { prefsBridge.setEulaAccepted(); } } }
Example 5
Source File: PrivacyPreferences.java From 365browser with Apache License 2.0 | 6 votes |
private ManagedPreferenceDelegate createManagedPreferenceDelegate() { return new ManagedPreferenceDelegate() { @Override public boolean isPreferenceControlledByPolicy(Preference preference) { String key = preference.getKey(); PrefServiceBridge prefs = PrefServiceBridge.getInstance(); if (PREF_NAVIGATION_ERROR.equals(key)) { return prefs.isResolveNavigationErrorManaged(); } if (PREF_SEARCH_SUGGESTIONS.equals(key)) { return prefs.isSearchSuggestManaged(); } if (PREF_SAFE_BROWSING_EXTENDED_REPORTING.equals(key) || PREF_SAFE_BROWSING_SCOUT_REPORTING.equals(key)) { return prefs.isSafeBrowsingExtendedReportingManaged(); } if (PREF_SAFE_BROWSING.equals(key)) { return prefs.isSafeBrowsingManaged(); } if (PREF_NETWORK_PREDICTIONS.equals(key)) { return prefs.isNetworkPredictionManaged(); } return false; } }; }
Example 6
Source File: ContextualSearchUma.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * @return The code for the Contextual Search preference. */ private static int getPreferenceValue() { PrefServiceBridge preferences = PrefServiceBridge.getInstance(); if (preferences.isContextualSearchUninitialized()) { return PREFERENCE_UNINITIALIZED; } else if (preferences.isContextualSearchDisabled()) { return PREFERENCE_DISABLED; } return PREFERENCE_ENABLED; }
Example 7
Source File: ContextualSearchUma.java From 365browser with Apache License 2.0 | 5 votes |
/** * @return The code for the Contextual Search preference. */ private static int getPreferenceValue() { PrefServiceBridge preferences = PrefServiceBridge.getInstance(); if (preferences.isContextualSearchUninitialized()) { return PREFERENCE_UNINITIALIZED; } else if (preferences.isContextualSearchDisabled()) { return PREFERENCE_DISABLED; } return PREFERENCE_ENABLED; }
Example 8
Source File: SiteSettingsCategory.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Returns whether the current category is managed either by enterprise policy or by the * custodian of a supervised account. */ public boolean isManaged() { PrefServiceBridge prefs = PrefServiceBridge.getInstance(); if (showBackgroundSyncSites()) return prefs.isBackgroundSyncManaged(); if (showCameraSites()) return !prefs.isCameraUserModifiable(); if (showCookiesSites()) return prefs.isAcceptCookiesManaged(); if (showGeolocationSites()) { return !prefs.isAllowLocationUserModifiable(); } if (showJavaScriptSites()) return prefs.javaScriptManaged(); if (showMicrophoneSites()) return !prefs.isMicUserModifiable(); if (showPopupSites()) return prefs.isPopupsManaged(); return false; }
Example 9
Source File: UmaSessionStats.java From delion with Apache License 2.0 | 5 votes |
/** * Updating Android preferences according to equivalent native preferences so that the values * can be retrieved while native preferences are not accessible. */ private void updatePreferences() { PrivacyPreferencesManager prefManager = PrivacyPreferencesManager.getInstance(); // Update cellular experiment preference. Cellular experiment is ON by default. boolean cellularExperiment = true; if (TextUtils.equals("false", VariationsAssociatedData.getVariationParamValue( "UMA_EnableCellularLogUpload", "Enabled"))) { cellularExperiment = false; } prefManager.setCellularExperiment(cellularExperiment); // Migrate to new preferences for cellular experiment. if (cellularExperiment) { PrefServiceBridge prefBridge = PrefServiceBridge.getInstance(); // If the native preference metrics reporting has not been set, then initialize it // based on the older android preference. if (!prefBridge.hasSetMetricsReporting()) { prefBridge.setMetricsReportingEnabled(prefManager.isUploadCrashDumpEnabled()); } // Set new Android preference for usage and crash reporting. prefManager.setUsageAndCrashReporting(prefBridge.isMetricsReportingEnabled()); } // Make sure preferences are in sync. prefManager.syncUsageAndCrashReportingPrefs(); }
Example 10
Source File: ChromeActivitySessionTracker.java From AndroidChromium with Apache License 2.0 | 5 votes |
/** * Update the accept languages after changing Android locale setting. Doing so kills the * Activities but it doesn't kill the Application, so this should be called in * {@link #onStart} instead of {@link #initialize}. */ private void updateAcceptLanguages() { PrefServiceBridge instance = PrefServiceBridge.getInstance(); String localeString = LocaleUtils.getDefaultLocaleListString(); if (hasLocaleChanged(localeString)) { instance.resetAcceptLanguages(localeString); // Clear cache so that accept-languages change can be applied immediately. // TODO(changwan): The underlying BrowsingDataRemover::Remove() is an asynchronous call. // So cache-clearing may not be effective if URL rendering can happen before // OnBrowsingDataRemoverDone() is called, in which case we may have to reload as well. // Check if it can happen. instance.clearBrowsingData( null, new int[]{ BrowsingDataType.CACHE }, TimePeriod.ALL_TIME); } }
Example 11
Source File: CustomTabsConnection.java From 365browser with Apache License 2.0 | 5 votes |
@VisibleForTesting boolean maySpeculate(CustomTabsSessionToken session) { if (!DeviceClassManager.enablePrerendering()) return false; PrefServiceBridge prefs = PrefServiceBridge.getInstance(); if (prefs.isBlockThirdPartyCookiesEnabled()) return false; // TODO(yusufo): The check for prerender in PrivacyManager now checks for the network // connection type as well, we should either change that or add another check for custom // tabs. Then PrivacyManager should be used to make the below check. if (!prefs.getNetworkPredictionEnabled()) return false; if (DataReductionProxySettings.getInstance().isDataReductionProxyEnabled()) return false; ConnectivityManager cm = (ConnectivityManager) mApplication.getApplicationContext().getSystemService( Context.CONNECTIVITY_SERVICE); return !cm.isActiveNetworkMetered() || shouldPrerenderOnCellularForSession(session); }
Example 12
Source File: SiteSettingsCategory.java From delion with Apache License 2.0 | 5 votes |
/** * Returns whether the current category is managed by the custodian (e.g. parent, not an * enterprise admin) of the account if the account is supervised. */ public boolean isManagedByCustodian() { PrefServiceBridge prefs = PrefServiceBridge.getInstance(); if (showGeolocationSites()) { return prefs.isAllowLocationManagedByCustodian(); } if (showCameraSites()) { return prefs.isCameraManagedByCustodian(); } if (showMicrophoneSites()) { return prefs.isMicManagedByCustodian(); } return false; }
Example 13
Source File: ContextualSearchUma.java From delion with Apache License 2.0 | 5 votes |
/** * @return The code for the Contextual Search preference. */ private static int getPreferenceValue() { PrefServiceBridge preferences = PrefServiceBridge.getInstance(); if (preferences.isContextualSearchUninitialized()) { return PREFERENCE_UNINITIALIZED; } else if (preferences.isContextualSearchDisabled()) { return PREFERENCE_DISABLED; } return PREFERENCE_ENABLED; }
Example 14
Source File: PrivacyPreferences.java From delion with Apache License 2.0 | 4 votes |
/** * Updates the summaries for several preferences. */ public void updateSummaries() { PrefServiceBridge prefServiceBridge = PrefServiceBridge.getInstance(); PrivacyPreferencesManager privacyPrefManager = PrivacyPreferencesManager.getInstance(); CharSequence textOn = getActivity().getResources().getText(R.string.text_on); CharSequence textOff = getActivity().getResources().getText(R.string.text_off); CheckBoxPreference navigationErrorPref = (CheckBoxPreference) findPreference( PREF_NAVIGATION_ERROR); navigationErrorPref.setChecked(prefServiceBridge.isResolveNavigationErrorEnabled()); CheckBoxPreference searchSuggestionsPref = (CheckBoxPreference) findPreference( PREF_SEARCH_SUGGESTIONS); searchSuggestionsPref.setChecked(prefServiceBridge.isSearchSuggestEnabled()); CheckBoxPreference extendedReportingPref = (CheckBoxPreference) findPreference(PREF_SAFE_BROWSING_EXTENDED_REPORTING); extendedReportingPref.setChecked( prefServiceBridge.isSafeBrowsingExtendedReportingEnabled()); CheckBoxPreference safeBrowsingPref = (CheckBoxPreference) findPreference(PREF_SAFE_BROWSING); safeBrowsingPref.setChecked(prefServiceBridge.isSafeBrowsingEnabled()); Preference doNotTrackPref = findPreference(PREF_DO_NOT_TRACK); doNotTrackPref.setSummary(prefServiceBridge.isDoNotTrackEnabled() ? textOn : textOff); Preference contextualPref = findPreference(PREF_CONTEXTUAL_SEARCH); if (contextualPref != null) { boolean isContextualSearchEnabled = !prefServiceBridge.isContextualSearchDisabled(); contextualPref.setSummary(isContextualSearchEnabled ? textOn : textOff); } Preference physicalWebPref = findPreference(PREF_PHYSICAL_WEB); if (physicalWebPref != null) { physicalWebPref.setSummary(privacyPrefManager.isPhysicalWebEnabled() ? textOn : textOff); } if (privacyPrefManager.isCellularExperimentEnabled()) { Preference usageAndCrashPref = findPreference(PREF_USAGE_AND_CRASH_REPORTING); usageAndCrashPref.setSummary(privacyPrefManager.isUsageAndCrashReportingEnabled() ? textOn : textOff); } }
Example 15
Source File: PrivacyPreferences.java From 365browser with Apache License 2.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PrivacyPreferencesManager privacyPrefManager = PrivacyPreferencesManager.getInstance(); privacyPrefManager.migrateNetworkPredictionPreferences(); PreferenceUtils.addPreferencesFromResource(this, R.xml.privacy_preferences); getActivity().setTitle(R.string.prefs_privacy); setHasOptionsMenu(true); PrefServiceBridge prefServiceBridge = PrefServiceBridge.getInstance(); mManagedPreferenceDelegate = createManagedPreferenceDelegate(); ChromeBaseCheckBoxPreference networkPredictionPref = (ChromeBaseCheckBoxPreference) findPreference(PREF_NETWORK_PREDICTIONS); networkPredictionPref.setChecked(prefServiceBridge.getNetworkPredictionEnabled()); networkPredictionPref.setOnPreferenceChangeListener(this); networkPredictionPref.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 (ChromeFeatureList.isEnabled(ChromeFeatureList.CONTENT_SUGGESTIONS_SETTINGS)) { searchSuggestionsPref.setTitle(R.string.search_site_suggestions_title); searchSuggestionsPref.setSummary(R.string.search_site_suggestions_summary); } PreferenceScreen preferenceScreen = getPreferenceScreen(); if (!ContextualSearchFieldTrial.isEnabled()) { preferenceScreen.removePreference(findPreference(PREF_CONTEXTUAL_SEARCH)); } // Listen to changes to both Extended Reporting prefs. ChromeBaseCheckBoxPreference legacyExtendedReportingPref = (ChromeBaseCheckBoxPreference) findPreference( PREF_SAFE_BROWSING_EXTENDED_REPORTING); legacyExtendedReportingPref.setOnPreferenceChangeListener(this); legacyExtendedReportingPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate); ChromeBaseCheckBoxPreference scoutReportingPref = (ChromeBaseCheckBoxPreference) findPreference(PREF_SAFE_BROWSING_SCOUT_REPORTING); scoutReportingPref.setOnPreferenceChangeListener(this); scoutReportingPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate); // Remove the extended reporting preference that is NOT active. String extended_reporting_pref_to_remove = prefServiceBridge.isSafeBrowsingScoutReportingActive() ? PREF_SAFE_BROWSING_EXTENDED_REPORTING : PREF_SAFE_BROWSING_SCOUT_REPORTING; preferenceScreen.removePreference(findPreference(extended_reporting_pref_to_remove)); ChromeBaseCheckBoxPreference safeBrowsingPref = (ChromeBaseCheckBoxPreference) findPreference(PREF_SAFE_BROWSING); safeBrowsingPref.setOnPreferenceChangeListener(this); safeBrowsingPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate); if (!PhysicalWeb.featureIsEnabled()) { preferenceScreen.removePreference(findPreference(PREF_PHYSICAL_WEB)); } if (ClearBrowsingDataTabsFragment.isFeatureEnabled()) { findPreference(PREF_CLEAR_BROWSING_DATA) .setFragment(ClearBrowsingDataTabsFragment.class.getName()); } updateSummaries(); }
Example 16
Source File: AccountManagementFragment.java From 365browser with Apache License 2.0 | 4 votes |
private void configureChildAccountPreferences() { Preference parentAccounts = findPreference(PREF_PARENT_ACCOUNTS); Preference childContent = findPreference(PREF_CHILD_CONTENT); if (mProfile.isChild()) { Resources res = getActivity().getResources(); PrefServiceBridge prefService = PrefServiceBridge.getInstance(); String firstParent = prefService.getSupervisedUserCustodianEmail(); String secondParent = prefService.getSupervisedUserSecondCustodianEmail(); String parentText; if (!secondParent.isEmpty()) { parentText = res.getString(R.string.account_management_two_parent_names, firstParent, secondParent); } else if (!firstParent.isEmpty()) { parentText = res.getString(R.string.account_management_one_parent_name, firstParent); } else { parentText = res.getString(R.string.account_management_no_parental_data); } parentAccounts.setSummary(parentText); parentAccounts.setSelectable(false); ((ChromeBasePreference) parentAccounts).setUseReducedPadding(true); final int childContentSummary; int defaultBehavior = prefService.getDefaultSupervisedUserFilteringBehavior(); if (defaultBehavior == PrefServiceBridge.SUPERVISED_USER_FILTERING_BLOCK) { childContentSummary = R.string.account_management_child_content_approved; } else if (prefService.isSupervisedUserSafeSitesEnabled()) { childContentSummary = R.string.account_management_child_content_filter_mature; } else { childContentSummary = R.string.account_management_child_content_all; } childContent.setSummary(childContentSummary); // TODO(dgn): made selectable to show the dividers. Find a way to avoid this. A side // effect is that it shows a tap ripple on an item that is not interactive. // childContent.setSelectable(false); Drawable newIcon = ApiCompatibilityUtils.getDrawable( getResources(), R.drawable.ic_drive_site_white_24dp); newIcon.mutate().setColorFilter( ApiCompatibilityUtils.getColor(getResources(), R.color.google_grey_600), PorterDuff.Mode.SRC_IN); childContent.setIcon(newIcon); } else { PreferenceScreen prefScreen = getPreferenceScreen(); prefScreen.removePreference(findPreference(PREF_PARENTAL_SETTINGS)); prefScreen.removePreference(parentAccounts); prefScreen.removePreference(childContent); } }
Example 17
Source File: PrivacyPreferences.java From 365browser with Apache License 2.0 | 4 votes |
/** * Updates the summaries for several preferences. */ public void updateSummaries() { PrefServiceBridge prefServiceBridge = PrefServiceBridge.getInstance(); PrivacyPreferencesManager privacyPrefManager = PrivacyPreferencesManager.getInstance(); CharSequence textOn = getActivity().getResources().getText(R.string.text_on); CharSequence textOff = getActivity().getResources().getText(R.string.text_off); CheckBoxPreference navigationErrorPref = (CheckBoxPreference) findPreference( PREF_NAVIGATION_ERROR); if (navigationErrorPref != null) { navigationErrorPref.setChecked( prefServiceBridge.isResolveNavigationErrorEnabled()); } CheckBoxPreference searchSuggestionsPref = (CheckBoxPreference) findPreference( PREF_SEARCH_SUGGESTIONS); if (searchSuggestionsPref != null) { searchSuggestionsPref.setChecked(prefServiceBridge.isSearchSuggestEnabled()); } String extended_reporting_pref = prefServiceBridge.isSafeBrowsingScoutReportingActive() ? PREF_SAFE_BROWSING_SCOUT_REPORTING : PREF_SAFE_BROWSING_EXTENDED_REPORTING; CheckBoxPreference extendedReportingPref = (CheckBoxPreference) findPreference(extended_reporting_pref); if (extendedReportingPref != null) { extendedReportingPref.setChecked( prefServiceBridge.isSafeBrowsingExtendedReportingEnabled()); } CheckBoxPreference safeBrowsingPref = (CheckBoxPreference) findPreference(PREF_SAFE_BROWSING); if (safeBrowsingPref != null) { safeBrowsingPref.setChecked(prefServiceBridge.isSafeBrowsingEnabled()); } Preference doNotTrackPref = findPreference(PREF_DO_NOT_TRACK); if (doNotTrackPref != null) { doNotTrackPref.setSummary(prefServiceBridge.isDoNotTrackEnabled() ? textOn : textOff); } Preference contextualPref = findPreference(PREF_CONTEXTUAL_SEARCH); if (contextualPref != null) { boolean isContextualSearchEnabled = !prefServiceBridge.isContextualSearchDisabled(); contextualPref.setSummary(isContextualSearchEnabled ? textOn : textOff); } Preference physicalWebPref = findPreference(PREF_PHYSICAL_WEB); if (physicalWebPref != null) { physicalWebPref.setSummary(privacyPrefManager.isPhysicalWebEnabled() ? textOn : textOff); } Preference usageAndCrashPref = findPreference(PREF_USAGE_AND_CRASH_REPORTING); if (usageAndCrashPref != null) { usageAndCrashPref.setSummary( privacyPrefManager.isUsageAndCrashReportingPermittedByUser() ? textOn : textOff); } }
Example 18
Source File: PrivacyPreferences.java From AndroidChromium with Apache License 2.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); PrivacyPreferencesManager privacyPrefManager = PrivacyPreferencesManager.getInstance(); privacyPrefManager.migrateNetworkPredictionPreferences(); addPreferencesFromResource(R.xml.privacy_preferences); getActivity().setTitle(R.string.prefs_privacy); setHasOptionsMenu(true); PrefServiceBridge prefServiceBridge = PrefServiceBridge.getInstance(); mManagedPreferenceDelegate = createManagedPreferenceDelegate(); ChromeBaseCheckBoxPreference networkPredictionPref = (ChromeBaseCheckBoxPreference) findPreference(PREF_NETWORK_PREDICTIONS); networkPredictionPref.setChecked(prefServiceBridge.getNetworkPredictionEnabled()); networkPredictionPref.setOnPreferenceChangeListener(this); networkPredictionPref.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); PreferenceScreen preferenceScreen = getPreferenceScreen(); if (!ContextualSearchFieldTrial.isEnabled()) { preferenceScreen.removePreference(findPreference(PREF_CONTEXTUAL_SEARCH)); } // Listen to changes to both Extended Reporting prefs. ChromeBaseCheckBoxPreference legacyExtendedReportingPref = (ChromeBaseCheckBoxPreference) findPreference( PREF_SAFE_BROWSING_EXTENDED_REPORTING); legacyExtendedReportingPref.setOnPreferenceChangeListener(this); legacyExtendedReportingPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate); ChromeBaseCheckBoxPreference scoutReportingPref = (ChromeBaseCheckBoxPreference) findPreference(PREF_SAFE_BROWSING_SCOUT_REPORTING); scoutReportingPref.setOnPreferenceChangeListener(this); scoutReportingPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate); // Remove the extended reporting preference that is NOT active. String extended_reporting_pref_to_remove = prefServiceBridge.isSafeBrowsingScoutReportingActive() ? PREF_SAFE_BROWSING_EXTENDED_REPORTING : PREF_SAFE_BROWSING_SCOUT_REPORTING; preferenceScreen.removePreference(findPreference(extended_reporting_pref_to_remove)); ChromeBaseCheckBoxPreference safeBrowsingPref = (ChromeBaseCheckBoxPreference) findPreference(PREF_SAFE_BROWSING); safeBrowsingPref.setOnPreferenceChangeListener(this); safeBrowsingPref.setManagedPreferenceDelegate(mManagedPreferenceDelegate); if (!PhysicalWeb.featureIsEnabled()) { preferenceScreen.removePreference(findPreference(PREF_PHYSICAL_WEB)); } updateSummaries(); }
Example 19
Source File: PrivacyPreferences.java From AndroidChromium with Apache License 2.0 | 4 votes |
/** * Updates the summaries for several preferences. */ public void updateSummaries() { PrefServiceBridge prefServiceBridge = PrefServiceBridge.getInstance(); PrivacyPreferencesManager privacyPrefManager = PrivacyPreferencesManager.getInstance(); CharSequence textOn = getActivity().getResources().getText(R.string.text_on); CharSequence textOff = getActivity().getResources().getText(R.string.text_off); CheckBoxPreference navigationErrorPref = (CheckBoxPreference) findPreference( PREF_NAVIGATION_ERROR); if (navigationErrorPref != null) { navigationErrorPref.setChecked( prefServiceBridge.isResolveNavigationErrorEnabled()); } CheckBoxPreference searchSuggestionsPref = (CheckBoxPreference) findPreference( PREF_SEARCH_SUGGESTIONS); if (searchSuggestionsPref != null) { searchSuggestionsPref.setChecked(prefServiceBridge.isSearchSuggestEnabled()); } String extended_reporting_pref = prefServiceBridge.isSafeBrowsingScoutReportingActive() ? PREF_SAFE_BROWSING_SCOUT_REPORTING : PREF_SAFE_BROWSING_EXTENDED_REPORTING; CheckBoxPreference extendedReportingPref = (CheckBoxPreference) findPreference(extended_reporting_pref); if (extendedReportingPref != null) { extendedReportingPref.setChecked( prefServiceBridge.isSafeBrowsingExtendedReportingEnabled()); } CheckBoxPreference safeBrowsingPref = (CheckBoxPreference) findPreference(PREF_SAFE_BROWSING); if (safeBrowsingPref != null) { safeBrowsingPref.setChecked(prefServiceBridge.isSafeBrowsingEnabled()); } Preference doNotTrackPref = findPreference(PREF_DO_NOT_TRACK); if (doNotTrackPref != null) { doNotTrackPref.setSummary(prefServiceBridge.isDoNotTrackEnabled() ? textOn : textOff); } Preference contextualPref = findPreference(PREF_CONTEXTUAL_SEARCH); if (contextualPref != null) { boolean isContextualSearchEnabled = !prefServiceBridge.isContextualSearchDisabled(); contextualPref.setSummary(isContextualSearchEnabled ? textOn : textOff); } Preference physicalWebPref = findPreference(PREF_PHYSICAL_WEB); if (physicalWebPref != null) { physicalWebPref.setSummary(privacyPrefManager.isPhysicalWebEnabled() ? textOn : textOff); } Preference usageAndCrashPref = findPreference(PREF_USAGE_AND_CRASH_REPORTING); if (usageAndCrashPref != null) { usageAndCrashPref.setSummary( privacyPrefManager.isUsageAndCrashReportingPermittedByUser() ? textOn : textOff); } }
Example 20
Source File: PrivacyPreferencesManager.java From 365browser with Apache License 2.0 | 4 votes |
/** * Migrate and delete old preferences. Note that migration has to happen in Android-specific * code because we need to access ALLOW_PRERENDER sharedPreference. * TODO(bnc) https://crbug.com/394845. This change is planned for M38. After a year or so, it * would be worth considering removing this migration code (also removing accessors in * PrefServiceBridge and pref_service_bridge), and reverting to default for users * who had set preferences but have not used Chrome for a year. This change would be subject to * privacy review. */ public void migrateNetworkPredictionPreferences() { PrefServiceBridge prefService = PrefServiceBridge.getInstance(); // See if PREF_NETWORK_PREDICTIONS is an old boolean value. boolean predictionOptionIsBoolean = false; try { mSharedPreferences.getString(PREF_NETWORK_PREDICTIONS, ""); } catch (ClassCastException ex) { predictionOptionIsBoolean = true; } // Nothing to do if the user or this migration code has already set the new // preference. if (!predictionOptionIsBoolean && prefService.obsoleteNetworkPredictionOptionsHasUserSetting()) { return; } // Nothing to do if the old preferences are unset. if (!predictionOptionIsBoolean && !mSharedPreferences.contains(PREF_BANDWIDTH_OLD) && !mSharedPreferences.contains(PREF_BANDWIDTH_NO_CELLULAR_OLD)) { return; } // Migrate if the old preferences are at their default values. // (Note that for PREF_BANDWIDTH*, if the setting is default, then there is no way to tell // whether the user has set it.) final String prefBandwidthDefault = BandwidthType.PRERENDER_ON_WIFI.title(); final String prefBandwidth = mSharedPreferences.getString(PREF_BANDWIDTH_OLD, prefBandwidthDefault); boolean prefBandwidthNoCellularDefault = true; boolean prefBandwidthNoCellular = mSharedPreferences.getBoolean( PREF_BANDWIDTH_NO_CELLULAR_OLD, prefBandwidthNoCellularDefault); if (!(prefBandwidthDefault.equals(prefBandwidth)) || (prefBandwidthNoCellular != prefBandwidthNoCellularDefault)) { boolean newValue = true; // Observe PREF_BANDWIDTH on mobile network capable devices. if (isMobileNetworkCapable()) { if (mSharedPreferences.contains(PREF_BANDWIDTH_OLD)) { BandwidthType prefetchBandwidthTypePref = BandwidthType.getBandwidthFromTitle( prefBandwidth); if (BandwidthType.NEVER_PRERENDER.equals(prefetchBandwidthTypePref)) { newValue = false; } else if (BandwidthType.PRERENDER_ON_WIFI.equals(prefetchBandwidthTypePref)) { newValue = true; } else if (BandwidthType.ALWAYS_PRERENDER.equals(prefetchBandwidthTypePref)) { newValue = true; } } // Observe PREF_BANDWIDTH_NO_CELLULAR on devices without mobile network. } else { if (mSharedPreferences.contains(PREF_BANDWIDTH_NO_CELLULAR_OLD)) { if (prefBandwidthNoCellular) { newValue = true; } else { newValue = false; } } } // Save new value in Chrome PrefService. prefService.setNetworkPredictionEnabled(newValue); } // Delete old sharedPreferences. SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit(); // Delete PREF_BANDWIDTH and PREF_BANDWIDTH_NO_CELLULAR: just migrated these options. if (mSharedPreferences.contains(PREF_BANDWIDTH_OLD)) { sharedPreferencesEditor.remove(PREF_BANDWIDTH_OLD); } if (mSharedPreferences.contains(PREF_BANDWIDTH_NO_CELLULAR_OLD)) { sharedPreferencesEditor.remove(PREF_BANDWIDTH_NO_CELLULAR_OLD); } // Also delete ALLOW_PRERENDER, which was updated based on PREF_BANDWIDTH[_NO_CELLULAR] and // network connectivity type, therefore does not carry additional information. if (mSharedPreferences.contains(ALLOW_PRERENDER_OLD)) { sharedPreferencesEditor.remove(ALLOW_PRERENDER_OLD); } // Delete bool PREF_NETWORK_PREDICTIONS so that string values can be stored. Note that this // SharedPreference carries no information, because it used to be overwritten by // kNetworkPredictionEnabled on startup, and now it is overwritten by // kNetworkPredictionOptions on startup. if (mSharedPreferences.contains(PREF_NETWORK_PREDICTIONS)) { sharedPreferencesEditor.remove(PREF_NETWORK_PREDICTIONS); } sharedPreferencesEditor.apply(); }