Detect if the current network is wifi or not and update webkit.

This info is passed to youtube.com via navigator.networkType

Fixes Bug: 2368650
This commit is contained in:
Andrei Popescu
2010-01-12 22:42:41 +00:00
parent 843e89757a
commit f5dba888c6
3 changed files with 24 additions and 0 deletions

View File

@@ -247,4 +247,5 @@ final class JWebCoreJavaBridge extends Handler {
private native void nativeUpdatePluginDirectories(String[] directories,
boolean reload);
public native void setNetworkOnLine(boolean online);
public native void setNetworkType(String type, String subtype);
}

View File

@@ -80,6 +80,7 @@ import java.io.IOException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import junit.framework.Assert;
@@ -1131,6 +1132,16 @@ public class WebView extends AbsoluteLayout
networkUp ? 1 : 0, 0);
}
/**
* Inform WebView about the current network type.
* {@hide}
*/
public void setNetworkType(String type, String subtype) {
Map<String, String> map = new HashMap<String, String>();
map.put("type", type);
map.put("subtype", subtype);
mWebViewCore.sendMessage(EventHub.SET_NETWORK_TYPE, map);
}
/**
* Save the state of this WebView used in
* {@link android.app.Activity#onSaveInstanceState}. Please note that this

View File

@@ -878,6 +878,8 @@ final class WebViewCore {
static final int HIDE_FULLSCREEN = 182;
static final int SET_NETWORK_TYPE = 183;
// private message ids
private static final int DESTROY = 200;
@@ -1110,6 +1112,16 @@ final class WebViewCore {
.setNetworkOnLine(msg.arg1 == 1);
break;
case SET_NETWORK_TYPE:
if (BrowserFrame.sJavaBridge == null) {
throw new IllegalStateException("No WebView " +
"has been created in this process!");
}
Map<String, String> map = (Map<String, String>) msg.obj;
BrowserFrame.sJavaBridge
.setNetworkType(map.get("type"), map.get("subtype"));
break;
case CLEAR_CACHE:
clearCache(msg.arg1 == 1);
break;