use of org.chromium.chrome.browser.preferences.PrefServiceBridge in project AndroidChromium by JackyAndroid.
the class PrivacyPreferences method createManagedPreferenceDelegate.
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)) {
return prefs.isSafeBrowsingExtendedReportingManaged();
}
if (PREF_SAFE_BROWSING.equals(key)) {
return prefs.isSafeBrowsingManaged();
}
if (PREF_NETWORK_PREDICTIONS.equals(key)) {
return prefs.isNetworkPredictionManaged();
}
return false;
}
};
}
use of org.chromium.chrome.browser.preferences.PrefServiceBridge in project AndroidChromium by JackyAndroid.
the class PrivacyPreferencesManager method migrateNetworkPredictionPreferences.
/**
* 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;
}
// 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);
}
// network connectivity type, therefore does not carry additional information.
if (mSharedPreferences.contains(ALLOW_PRERENDER_OLD)) {
sharedPreferencesEditor.remove(ALLOW_PRERENDER_OLD);
}
// kNetworkPredictionOptions on startup.
if (mSharedPreferences.contains(PREF_NETWORK_PREDICTIONS)) {
sharedPreferencesEditor.remove(PREF_NETWORK_PREDICTIONS);
}
sharedPreferencesEditor.apply();
}
use of org.chromium.chrome.browser.preferences.PrefServiceBridge in project AndroidChromium by JackyAndroid.
the class SiteSettingsPreferences method updatePreferenceStates.
private void updatePreferenceStates() {
PrefServiceBridge prefServiceBridge = PrefServiceBridge.getInstance();
// Translate preference.
Preference translatePref = findPreference(TRANSLATE_KEY);
if (translatePref != null) {
setTranslateStateSummary(translatePref);
}
// Preferences that navigate to Website Settings.
List<String> websitePrefs = new ArrayList<String>();
if (mMediaSubMenu) {
websitePrefs.add(PROTECTED_CONTENT_KEY);
websitePrefs.add(AUTOPLAY_KEY);
} else {
// When showing the main menu, only one of these two will be visible, at most.
if (mProtectedContentMenuAvailable && !mAutoplayMenuAvailable) {
websitePrefs.add(PROTECTED_CONTENT_KEY);
} else if (mAutoplayMenuAvailable && !mProtectedContentMenuAvailable) {
websitePrefs.add(AUTOPLAY_KEY);
}
websitePrefs.add(BACKGROUND_SYNC_KEY);
websitePrefs.add(CAMERA_KEY);
websitePrefs.add(COOKIES_KEY);
websitePrefs.add(FULLSCREEN_KEY);
websitePrefs.add(JAVASCRIPT_KEY);
websitePrefs.add(LOCATION_KEY);
websitePrefs.add(MICROPHONE_KEY);
websitePrefs.add(NOTIFICATIONS_KEY);
websitePrefs.add(POPUPS_KEY);
}
// associated content settings entry.
for (String prefName : websitePrefs) {
Preference p = findPreference(prefName);
boolean checked = false;
if (AUTOPLAY_KEY.equals(prefName)) {
checked = PrefServiceBridge.getInstance().isAutoplayEnabled();
} else if (BACKGROUND_SYNC_KEY.equals(prefName)) {
checked = PrefServiceBridge.getInstance().isBackgroundSyncAllowed();
} else if (CAMERA_KEY.equals(prefName)) {
checked = PrefServiceBridge.getInstance().isCameraEnabled();
} else if (COOKIES_KEY.equals(prefName)) {
checked = PrefServiceBridge.getInstance().isAcceptCookiesEnabled();
} else if (FULLSCREEN_KEY.equals(prefName)) {
checked = PrefServiceBridge.getInstance().isFullscreenAllowed();
} else if (JAVASCRIPT_KEY.equals(prefName)) {
checked = PrefServiceBridge.getInstance().javaScriptEnabled();
} else if (LOCATION_KEY.equals(prefName)) {
checked = LocationSettings.getInstance().areAllLocationSettingsEnabled();
} else if (MICROPHONE_KEY.equals(prefName)) {
checked = PrefServiceBridge.getInstance().isMicEnabled();
} else if (NOTIFICATIONS_KEY.equals(prefName)) {
checked = PrefServiceBridge.getInstance().isNotificationsEnabled();
} else if (POPUPS_KEY.equals(prefName)) {
checked = PrefServiceBridge.getInstance().popupsEnabled();
} else if (PROTECTED_CONTENT_KEY.equals(prefName)) {
checked = PrefServiceBridge.getInstance().isProtectedMediaIdentifierEnabled();
}
int contentType = keyToContentSettingsType(prefName);
p.setTitle(ContentSettingsResources.getTitle(contentType));
p.setOnPreferenceClickListener(this);
// Disable autoplay preference if Data Saver is ON.
if (AUTOPLAY_KEY.equals(prefName) && DataReductionProxySettings.getInstance().isDataReductionProxyEnabled()) {
p.setSummary(ContentSettingsResources.getAutoplayDisabledByDataSaverSummary());
p.setEnabled(false);
} else if (COOKIES_KEY.equals(prefName) && checked && prefServiceBridge.isBlockThirdPartyCookiesEnabled()) {
p.setSummary(ContentSettingsResources.getCookieAllowedExceptThirdPartySummary());
} else if (LOCATION_KEY.equals(prefName) && checked && prefServiceBridge.isLocationAllowedByPolicy()) {
p.setSummary(ContentSettingsResources.getGeolocationAllowedSummary());
} else {
p.setSummary(ContentSettingsResources.getCategorySummary(contentType, checked));
}
if (p.isEnabled()) {
p.setIcon(ContentSettingsResources.getIcon(contentType));
} else {
p.setIcon(ContentSettingsResources.getDisabledIcon(contentType, getResources()));
}
}
Preference p = findPreference(ALL_SITES_KEY);
if (p != null)
p.setOnPreferenceClickListener(this);
p = findPreference(MEDIA_KEY);
if (p != null)
p.setOnPreferenceClickListener(this);
// TODO(finnur): Re-move this for Storage once it can be moved to the 'Usage' menu.
p = findPreference(STORAGE_KEY);
if (p != null)
p.setOnPreferenceClickListener(this);
p = findPreference(USB_KEY);
if (p != null)
p.setOnPreferenceClickListener(this);
}
use of org.chromium.chrome.browser.preferences.PrefServiceBridge in project AndroidChromium by JackyAndroid.
the class ChromeActivitySessionTracker method updateAcceptLanguages.
/**
* 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();
// ex) en_US, de_DE, zh_CN_#Hans
String localeString = Locale.getDefault().toString();
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);
}
}
use of org.chromium.chrome.browser.preferences.PrefServiceBridge in project AndroidChromium by JackyAndroid.
the class PrivacyPreferences method updateSummaries.
/**
* 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());
}
CheckBoxPreference extendedReportingPref = (CheckBoxPreference) findPreference(PREF_SAFE_BROWSING_EXTENDED_REPORTING);
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.isUsageAndCrashReportingEnabled() ? textOn : textOff);
}
}
Aggregations