summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--res/values/strings.xml22
-rw-r--r--res/xml/bandwidth_preferences.xml8
-rw-r--r--src/com/android/browser/BrowserSettings.java67
-rw-r--r--src/com/android/browser/NetworkStateHandler.java5
-rw-r--r--src/com/android/browser/PreferenceKeys.java1
-rw-r--r--src/com/android/browser/preferences/BandwidthPreferencesFragment.java17
6 files changed, 114 insertions, 6 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2de5e58..6afe4d5 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -664,6 +664,28 @@
<string name="pref_data_preload_summary">Allow browser to preload high confidence search results in the background</string>
<!-- Title of dialog for search preloading [CHAR LIMIT=40] -->
<string name="pref_data_preload_dialogtitle">Search result preloading</string>
+ <!-- Title for link prefetching [CHAR LIMIT=40] -->
+ <string name="pref_link_prefetch_title">Web page preloading</string>
+ <!-- Link prefetching options [CHAR LIMIT=20] -->
+ <string-array name="pref_link_prefetch_choices">
+ <item>Never</item>
+ <item>Only on Wi-Fi</item>
+ <item>Always</item>
+ </string-array>
+ <!-- Do not translate -->
+ <string name="pref_link_prefetch_value_never" translatable="false">NEVER</string>
+ <string name="pref_link_prefetch_value_wifi_only" translatable="false">WIFI_ONLY</string>
+ <string name="pref_link_prefetch_value_always" translatable="false">ALWAYS</string>
+ <string name="pref_link_prefetch_default_value" translatable="false">@string/pref_link_prefetch_value_wifi_only</string>
+ <string-array name="pref_link_prefetch_values" translatable="false">
+ <item><xliff:g>@string/pref_link_prefetch_value_never</xliff:g></item>
+ <item><xliff:g>@string/pref_link_prefetch_value_wifi_only</xliff:g></item>
+ <item><xliff:g>@string/pref_link_prefetch_value_always</xliff:g></item>
+ </string-array>
+ <!-- Summary for link prefetching [CHAR LIMIT=80] -->
+ <string name="pref_link_prefetch_summary">Allow browser to preload linked web pages in the background</string>
+ <!-- Title of dialog for link prefetching [CHAR LIMIT=40] -->
+ <string name="pref_link_prefetch_dialogtitle">Web page preloading</string>
<!-- Title for a dialog displayed when the browser has a data connectivity
problem -->
<string name="browserFrameNetworkErrorLabel">Connection problem</string>
diff --git a/res/xml/bandwidth_preferences.xml b/res/xml/bandwidth_preferences.xml
index bb1688e..9946b48 100644
--- a/res/xml/bandwidth_preferences.xml
+++ b/res/xml/bandwidth_preferences.xml
@@ -24,6 +24,14 @@
android:entryValues="@array/pref_data_preload_values"
android:dialogTitle="@string/pref_data_preload_dialogtitle" />
+ <ListPreference
+ android:key="link_prefetch_when"
+ android:title="@string/pref_link_prefetch_title"
+ android:summary="@string/pref_link_prefetch_summary"
+ android:entries="@array/pref_link_prefetch_choices"
+ android:entryValues="@array/pref_link_prefetch_values"
+ android:dialogTitle="@string/pref_link_prefetch_dialogtitle" />
+
<CheckBoxPreference
android:key="load_images"
android:defaultValue="true"
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
// -----------------------------
diff --git a/src/com/android/browser/NetworkStateHandler.java b/src/com/android/browser/NetworkStateHandler.java
index 4ae91ba..4480664 100644
--- a/src/com/android/browser/NetworkStateHandler.java
+++ b/src/com/android/browser/NetworkStateHandler.java
@@ -26,6 +26,8 @@ import android.net.NetworkInfo;
import android.webkit.WebView;
import android.webkit.WebViewClassic;
+import com.android.browser.BrowserSettings;
+
/**
* Handle network state changes
*/
@@ -68,6 +70,7 @@ public class NetworkStateHandler {
String subtypeName = info.getSubtypeName();
sendNetworkType(typeName.toLowerCase(),
(subtypeName != null ? subtypeName.toLowerCase() : ""));
+ BrowserSettings.getInstance().updateConnectionType();
boolean noConnection = intent.getBooleanExtra(
ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
@@ -87,6 +90,7 @@ public class NetworkStateHandler {
void onResume() {
mActivity.registerReceiver(mNetworkStateIntentReceiver,
mNetworkStateChangedFilter);
+ BrowserSettings.getInstance().updateConnectionType();
}
/**
@@ -114,5 +118,4 @@ public class NetworkStateHandler {
WebViewClassic.fromWebView(w).setNetworkType(type, subtype);
}
}
-
}
diff --git a/src/com/android/browser/PreferenceKeys.java b/src/com/android/browser/PreferenceKeys.java
index 1a20495..ff42aaf 100644
--- a/src/com/android/browser/PreferenceKeys.java
+++ b/src/com/android/browser/PreferenceKeys.java
@@ -102,6 +102,7 @@ public interface PreferenceKeys {
// Keys for bandwidth_preferences.xml
// ----------------------
static final String PREF_DATA_PRELOAD = "preload_when";
+ static final String PREF_LINK_PREFETCH = "link_prefetch_when";
static final String PREF_LOAD_IMAGES = "load_images";
// ----------------------
diff --git a/src/com/android/browser/preferences/BandwidthPreferencesFragment.java b/src/com/android/browser/preferences/BandwidthPreferencesFragment.java
index 2c147cc..0cb064a 100644
--- a/src/com/android/browser/preferences/BandwidthPreferencesFragment.java
+++ b/src/com/android/browser/preferences/BandwidthPreferencesFragment.java
@@ -16,9 +16,11 @@
package com.android.browser.preferences;
+import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.PreferenceFragment;
+import android.preference.PreferenceScreen;
import com.android.browser.BrowserSettings;
import com.android.browser.PreferenceKeys;
@@ -38,15 +40,24 @@ public class BandwidthPreferencesFragment extends PreferenceFragment {
@Override
public void onResume() {
super.onResume();
- if (!getPreferenceScreen().getSharedPreferences()
- .contains(PreferenceKeys.PREF_DATA_PRELOAD)) {
+ PreferenceScreen prefScreen = getPreferenceScreen();
+ SharedPreferences sharedPrefs = prefScreen.getSharedPreferences();
+ if (!sharedPrefs.contains(PreferenceKeys.PREF_DATA_PRELOAD)) {
// set default value for preload setting
- ListPreference preload = (ListPreference) getPreferenceScreen().findPreference(
+ ListPreference preload = (ListPreference) prefScreen.findPreference(
PreferenceKeys.PREF_DATA_PRELOAD);
if (preload != null) {
preload.setValue(BrowserSettings.getInstance().getDefaultPreloadSetting());
}
}
+ if (!sharedPrefs.contains(PreferenceKeys.PREF_LINK_PREFETCH)) {
+ // set default value for link prefetch setting
+ ListPreference prefetch = (ListPreference) prefScreen.findPreference(
+ PreferenceKeys.PREF_LINK_PREFETCH);
+ if (prefetch != null) {
+ prefetch.setValue(BrowserSettings.getInstance().getDefaultLinkPrefetchSetting());
+ }
+ }
}
}