summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMathew Inwood <mathewi@google.com>2011-09-02 15:43:17 +0100
committerMathew Inwood <mathewi@google.com>2011-09-05 13:38:54 +0100
commit467813fba07c4dcc4ce350a3d4576f5739c5c940 (patch)
treed54953b7dd04dd058feaba6265139076d58ddf17 /src
parent012dcd474cd3980aa206e4b7a31fa67114f56d54 (diff)
downloadpackages_apps_Browser-467813fba07c4dcc4ce350a3d4576f5739c5c940.zip
packages_apps_Browser-467813fba07c4dcc4ce350a3d4576f5739c5c940.tar.gz
packages_apps_Browser-467813fba07c4dcc4ce350a3d4576f5739c5c940.tar.bz2
More fine-grained config for 'Search result preloading' setting.
Instead of a checkbox, it's now a setting always/wifi only/never. Bug: 5086576 Change-Id: I265a22968eafee547571dc86c10c5d5421a305e8
Diffstat (limited to 'src')
-rw-r--r--src/com/android/browser/BrowserSettings.java17
-rw-r--r--src/com/android/browser/PreferenceKeys.java2
-rw-r--r--src/com/android/browser/PreloadRequestReceiver.java50
3 files changed, 62 insertions, 7 deletions
diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java
index 11316ff..ce8a9c1 100644
--- a/src/com/android/browser/BrowserSettings.java
+++ b/src/com/android/browser/BrowserSettings.java
@@ -780,7 +780,20 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener,
// getter/setters for bandwidth_preferences.xml
// -----------------------------
- public boolean isPreloadEnabled() {
- return mPrefs.getBoolean(PREF_DATA_PRELOAD, false);
+ public static String getPreloadOnWifiOnlyPreferenceString(Context context) {
+ return context.getResources().getString(R.string.pref_data_preload_value_wifi_only);
}
+
+ public static String getPreloadAlwaysPreferenceString(Context context) {
+ return context.getResources().getString(R.string.pref_data_preload_value_always);
+ }
+
+ private String getDefaultPreloadSetting() {
+ return getPreloadOnWifiOnlyPreferenceString(mContext);
+ }
+
+ public String getPreloadEnabled() {
+ return mPrefs.getString(PREF_DATA_PRELOAD, getDefaultPreloadSetting());
+ }
+
}
diff --git a/src/com/android/browser/PreferenceKeys.java b/src/com/android/browser/PreferenceKeys.java
index 1bfe389..f3da937 100644
--- a/src/com/android/browser/PreferenceKeys.java
+++ b/src/com/android/browser/PreferenceKeys.java
@@ -100,7 +100,7 @@ public interface PreferenceKeys {
// ----------------------
// Keys for bandwidth_preferences.xml
// ----------------------
- static final String PREF_DATA_PRELOAD = "preload_enabled";
+ static final String PREF_DATA_PRELOAD = "preload_when";
static final String PREF_LOAD_IMAGES = "load_images";
}
diff --git a/src/com/android/browser/PreloadRequestReceiver.java b/src/com/android/browser/PreloadRequestReceiver.java
index ff3c8e3..c654037 100644
--- a/src/com/android/browser/PreloadRequestReceiver.java
+++ b/src/com/android/browser/PreloadRequestReceiver.java
@@ -18,9 +18,9 @@ package com.android.browser;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
-import android.content.SharedPreferences;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
import android.os.Bundle;
-import android.preference.PreferenceManager;
import android.provider.Browser;
import android.util.Log;
@@ -42,15 +42,57 @@ public class PreloadRequestReceiver extends BroadcastReceiver {
static final String EXTRA_SEARCHBOX_CANCEL = "searchbox_cancel";
static final String EXTRA_SEARCHBOX_SETQUERY = "searchbox_query";
+ private ConnectivityManager mConnectivityManager;
+
@Override
public void onReceive(Context context, Intent intent) {
if (LOGD_ENABLED) Log.d(LOGTAG, "received intent " + intent);
- if (BrowserSettings.getInstance().isPreloadEnabled()
- && intent.getAction().equals(ACTION_PRELOAD)) {
+ if (isPreloadEnabledOnCurrentNetwork(context) &&
+ intent.getAction().equals(ACTION_PRELOAD)) {
handlePreload(context, intent);
}
}
+ private boolean isPreloadEnabledOnCurrentNetwork(Context context) {
+ String preload = BrowserSettings.getInstance().getPreloadEnabled();
+ if (LOGD_ENABLED) Log.d(LOGTAG, "Preload setting: " + preload);
+ if (BrowserSettings.getPreloadAlwaysPreferenceString(context).equals(preload)) {
+ return true;
+ } else if (BrowserSettings.getPreloadOnWifiOnlyPreferenceString(context).equals(preload)) {
+ boolean onWifi = isOnWifi(context);
+ if (LOGD_ENABLED) Log.d(LOGTAG, "on wifi:" + onWifi);
+ return onWifi;
+ } else {
+ return false;
+ }
+ }
+
+ private boolean isOnWifi(Context context) {
+ if (mConnectivityManager == null) {
+ mConnectivityManager = (ConnectivityManager)
+ context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ }
+ NetworkInfo ni = mConnectivityManager.getActiveNetworkInfo();
+ if (ni == null) {
+ return false;
+ }
+ switch (ni.getType()) {
+ case ConnectivityManager.TYPE_MOBILE:
+ case ConnectivityManager.TYPE_MOBILE_DUN:
+ case ConnectivityManager.TYPE_MOBILE_MMS:
+ case ConnectivityManager.TYPE_MOBILE_SUPL:
+ case ConnectivityManager.TYPE_MOBILE_HIPRI:
+ case ConnectivityManager.TYPE_WIMAX: // separate case for this?
+ return false;
+ case ConnectivityManager.TYPE_WIFI:
+ case ConnectivityManager.TYPE_ETHERNET:
+ case ConnectivityManager.TYPE_BLUETOOTH:
+ return true;
+ default:
+ return false;
+ }
+ }
+
private void handlePreload(Context context, Intent i) {
String url = UrlUtils.smartUrlFilter(i.getData());
String id = i.getStringExtra(EXTRA_PRELOAD_ID);