summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathew Inwood <mathewi@google.com>2011-09-07 03:07:06 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-09-07 03:07:06 -0700
commit950292f77b748c897f66ab665a8d4cada16139ba (patch)
tree08d7830152433291011d0bb5b6b42d277c3f0837
parent9754b4311b58e24899b9c5c09a3a760a0fd9db81 (diff)
parent467813fba07c4dcc4ce350a3d4576f5739c5c940 (diff)
downloadpackages_apps_Browser-950292f77b748c897f66ab665a8d4cada16139ba.zip
packages_apps_Browser-950292f77b748c897f66ab665a8d4cada16139ba.tar.gz
packages_apps_Browser-950292f77b748c897f66ab665a8d4cada16139ba.tar.bz2
Merge "More fine-grained config for 'Search result preloading' setting."
-rw-r--r--res/values/strings.xml17
-rw-r--r--res/xml/bandwidth_preferences.xml9
-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
5 files changed, 85 insertions, 10 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 123e5c8..77e25a3 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -646,8 +646,25 @@
<string name="pref_data_title">Bandwidth Management</string>
<!-- Title for search preloading [CHAR LIMIT=40] -->
<string name="pref_data_preload_title">Search result preloading</string>
+ <!-- Search preloading options [CHAR LIMIT=20] -->
+ <string-array name="pref_data_preload_choices">
+ <item>Never</item>
+ <item>Only on Wi-Fi</item>
+ <item>Always</item>
+ </string-array>
+ <!-- Do not translate -->
+ <string name="pref_data_preload_value_never" translatable="false">NEVER</string>
+ <string name="pref_data_preload_value_wifi_only" translatable="false">WIFI_ONLY</string>
+ <string name="pref_data_preload_value_always" translatable="false">ALWAYS</string>
+ <string-array name="pref_data_preload_values" translatable="false">
+ <item><xliff:g>@string/pref_data_preload_value_never</xliff:g></item>
+ <item><xliff:g>@string/pref_data_preload_value_wifi_only</xliff:g></item>
+ <item><xliff:g>@string/pref_data_preload_value_always</xliff:g></item>
+ </string-array>
<!-- Summary for search preloading [CHAR LIMIT=80] -->
<string name="pref_data_preload_summary">Allow the 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 a dialog displayed when the browser has a data connectivity
problem -->
<string name="browserFrameNetworkErrorLabel">Data connectivity problem</string>
diff --git a/res/xml/bandwidth_preferences.xml b/res/xml/bandwidth_preferences.xml
index 0767ac5..8a31304 100644
--- a/res/xml/bandwidth_preferences.xml
+++ b/res/xml/bandwidth_preferences.xml
@@ -16,11 +16,14 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
- <CheckBoxPreference
- android:key="preload_enabled"
+ <ListPreference
+ android:key="preload_when"
android:title="@string/pref_data_preload_title"
android:summary="@string/pref_data_preload_summary"
- android:defaultValue="false" />
+ android:defaultValue="@string/pref_data_preload_value_wifi_only"
+ android:entries="@array/pref_data_preload_choices"
+ android:entryValues="@array/pref_data_preload_values"
+ android:dialogTitle="@string/pref_data_preload_dialogtitle" />
<CheckBoxPreference
android:key="load_images"
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);