summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/BrowserSettings.java
diff options
context:
space:
mode:
authorVictoria Lease <violets@google.com>2012-03-23 14:19:56 -0700
committerVictoria Lease <violets@google.com>2012-03-30 11:36:09 -0700
commit96497838babbaeb143b0fbc7d0de9c695e56e9f7 (patch)
tree62cab1448ea8b043fb82afab5e9086d0bafe5900 /src/com/android/browser/BrowserSettings.java
parent018c4c2e28e147fe505375601bd6432a19474ab8 (diff)
downloadpackages_apps_Browser-96497838babbaeb143b0fbc7d0de9c695e56e9f7.zip
packages_apps_Browser-96497838babbaeb143b0fbc7d0de9c695e56e9f7.tar.gz
packages_apps_Browser-96497838babbaeb143b0fbc7d0de9c695e56e9f7.tar.bz2
pref for html5 prefetch bandwidth management
Bug: 5218987 Change-Id: Ifeb9a1b3d71ac83b8ad94a8f31ed324ebd5d0fe7
Diffstat (limited to 'src/com/android/browser/BrowserSettings.java')
-rw-r--r--src/com/android/browser/BrowserSettings.java67
1 files changed, 65 insertions, 2 deletions
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java
index 4fe93d6..415e72d 100644
--- a/src/com/android/browser/BrowserSettings.java
+++ b/src/com/android/browser/BrowserSettings.java
@@ -22,6 +22,8 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
import android.os.Build;
import android.os.Message;
import android.preference.PreferenceManager;
@@ -115,6 +117,9 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
private boolean mNeedsSharedSync = true;
private float mFontSizeMult = 1.0f;
+ // Current state of network-dependent settings
+ private boolean mLinkPrefetchAllowed = true;
+
// Cached values
private int mPageCacheCapacity = 1;
private String mAppCachePath;
@@ -290,6 +295,8 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
settings.setProperty(WebViewProperties.gfxEnableCpuUploadPath,
enableCpuUploadPath() ? "true" : "false");
}
+
+ settings.setLinkPrefetchEnabled(mLinkPrefetchAllowed);
}
/**
@@ -361,8 +368,7 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
syncManagedSettings();
if (PREF_SEARCH_ENGINE.equals(key)) {
updateSearchEngine(false);
- }
- if (PREF_FULLSCREEN.equals(key)) {
+ } else if (PREF_FULLSCREEN.equals(key)) {
if (mController.getUi() != null) {
mController.getUi().setFullscreen(useFullscreen());
}
@@ -370,6 +376,8 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
if (mController.getUi() != null) {
mController.getUi().setUseQuickControls(sharedPreferences.getBoolean(key, false));
}
+ } else if (PREF_LINK_PREFETCH.equals(key)) {
+ updateConnectionType();
}
}
@@ -576,6 +584,37 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
return mPrefs;
}
+ // update connectivity-dependent options
+ public void updateConnectionType() {
+ ConnectivityManager cm = (ConnectivityManager)
+ mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
+ String linkPrefetchPreference = getLinkPrefetchEnabled();
+ boolean linkPrefetchAllowed = linkPrefetchPreference.
+ equals(getLinkPrefetchAlwaysPreferenceString(mContext));
+ NetworkInfo ni = cm.getActiveNetworkInfo();
+ if (ni != null) {
+ switch (ni.getType()) {
+ case ConnectivityManager.TYPE_WIFI:
+ case ConnectivityManager.TYPE_ETHERNET:
+ case ConnectivityManager.TYPE_BLUETOOTH:
+ linkPrefetchAllowed |= linkPrefetchPreference.
+ equals(getLinkPrefetchOnWifiOnlyPreferenceString(mContext));
+ break;
+ case ConnectivityManager.TYPE_MOBILE:
+ case ConnectivityManager.TYPE_MOBILE_DUN:
+ case ConnectivityManager.TYPE_MOBILE_MMS:
+ case ConnectivityManager.TYPE_MOBILE_SUPL:
+ case ConnectivityManager.TYPE_WIMAX:
+ default:
+ break;
+ }
+ }
+ if (mLinkPrefetchAllowed != linkPrefetchAllowed) {
+ mLinkPrefetchAllowed = linkPrefetchAllowed;
+ syncManagedSettings();
+ }
+ }
+
// -----------------------------
// getter/setters for accessibility_preferences.xml
// -----------------------------
@@ -858,6 +897,30 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
return mPrefs.getString(PREF_DATA_PRELOAD, getDefaultPreloadSetting());
}
+ public static String getLinkPrefetchOnWifiOnlyPreferenceString(Context context) {
+ return context.getResources().getString(R.string.pref_link_prefetch_value_wifi_only);
+ }
+
+ public static String getLinkPrefetchAlwaysPreferenceString(Context context) {
+ return context.getResources().getString(R.string.pref_link_prefetch_value_always);
+ }
+
+ private static final String DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY =
+ "browser_default_link_prefetch_setting";
+
+ public String getDefaultLinkPrefetchSetting() {
+ String preload = Settings.Secure.getString(mContext.getContentResolver(),
+ DEFAULT_LINK_PREFETCH_SECURE_SETTING_KEY);
+ if (preload == null) {
+ preload = mContext.getResources().getString(R.string.pref_link_prefetch_default_value);
+ }
+ return preload;
+ }
+
+ public String getLinkPrefetchEnabled() {
+ return mPrefs.getString(PREF_LINK_PREFETCH, getDefaultLinkPrefetchSetting());
+ }
+
// -----------------------------
// getter/setters for browser recovery
// -----------------------------