Backed out changeset 1aca15a8d20d (bug 1205237) for mulet 3 test failures on a CLOSED TREE

This commit is contained in:
Carsten "Tomcat" Book 2015-10-21 11:15:31 +02:00
Родитель f7cf52bdc6
Коммит 4dfc4e00c8
1 изменённых файлов: 11 добавлений и 47 удалений

Просмотреть файл

@ -17,10 +17,8 @@ import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.DhcpInfo;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;
import android.text.format.Formatter;
import android.util.Log;
/*
@ -70,15 +68,11 @@ public class GeckoNetworkManager extends BroadcastReceiver implements NativeEven
}
private GeckoNetworkManager() {
EventDispatcher.getInstance().registerGeckoThreadListener(this,
"Wifi:Enable",
"Wifi:GetIPAddress");
EventDispatcher.getInstance().registerGeckoThreadListener(this, "Wifi:Enable");
}
private void onDestroy() {
EventDispatcher.getInstance().unregisterGeckoThreadListener(this,
"Wifi:Enable",
"Wifi:GetIPAddress");
EventDispatcher.getInstance().unregisterGeckoThreadListener(this, "Wifi:Enable");
}
private volatile ConnectionType mConnectionType = ConnectionType.NONE;
@ -155,50 +149,20 @@ public class GeckoNetworkManager extends BroadcastReceiver implements NativeEven
@Override
public void handleMessage(final String event, final NativeJSObject message,
final EventCallback callback) {
switch (event) {
case "Wifi:Enable": {
final WifiManager mgr = (WifiManager) mApplicationContext.getSystemService(Context.WIFI_SERVICE);
if (event.equals("Wifi:Enable")) {
final WifiManager mgr = (WifiManager) mApplicationContext.getSystemService(Context.WIFI_SERVICE);
if (!mgr.isWifiEnabled()) {
mgr.setWifiEnabled(true);
} else {
// If Wifi is enabled, maybe you need to select a network
Intent intent = new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mApplicationContext.startActivity(intent);
}
break;
}
case "Wifi:GetIPAddress": {
getWifiIPAddress(callback);
break;
if (!mgr.isWifiEnabled()) {
mgr.setWifiEnabled(true);
} else {
// If Wifi is enabled, maybe you need to select a network
Intent intent = new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mApplicationContext.startActivity(intent);
}
}
}
// This function only works for IPv4
private void getWifiIPAddress(final EventCallback callback) {
final WifiManager mgr = (WifiManager) mApplicationContext.getSystemService(Context.WIFI_SERVICE);
if (mgr == null) {
callback.sendError("Cannot get WifiManager");
return;
}
final WifiInfo info = mgr.getConnectionInfo();
if (info == null) {
callback.sendError("Cannot get connection info");
return;
}
int ip = info.getIpAddress();
if (ip == 0) {
callback.sendError("Cannot get IPv4 address");
return;
}
callback.sendSuccess(Formatter.formatIpAddress(ip));
}
private void stopListening() {
if (null == mApplicationContext) {
return;