summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/PreloadRequestReceiver.java
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/com/android/browser/PreloadRequestReceiver.java
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/com/android/browser/PreloadRequestReceiver.java')
-rw-r--r--src/com/android/browser/PreloadRequestReceiver.java50
1 files changed, 46 insertions, 4 deletions
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);