Merge "Dynamically update connectivity and IP address."
This commit is contained in:
@@ -47,6 +47,7 @@ import com.android.internal.telephony.Phone;
|
||||
import com.android.internal.telephony.PhoneConstants;
|
||||
import com.android.internal.telephony.PhoneFactory;
|
||||
import com.android.internal.telephony.PhoneStateIntentReceiver;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
|
||||
@@ -117,11 +118,21 @@ public class Status extends PreferenceActivity {
|
||||
static final String CB_AREA_INFO_SENDER_PERMISSION =
|
||||
"android.permission.RECEIVE_EMERGENCY_BROADCAST";
|
||||
|
||||
// Broadcasts to listen to for connectivity changes.
|
||||
private static final String[] CONNECTIVITY_INTENTS = {
|
||||
BluetoothAdapter.ACTION_STATE_CHANGED,
|
||||
ConnectivityManager.CONNECTIVITY_ACTION_IMMEDIATE,
|
||||
WifiManager.LINK_CONFIGURATION_CHANGED_ACTION,
|
||||
WifiManager.NETWORK_STATE_CHANGED_ACTION,
|
||||
};
|
||||
|
||||
private static final int EVENT_SIGNAL_STRENGTH_CHANGED = 200;
|
||||
private static final int EVENT_SERVICE_STATE_CHANGED = 300;
|
||||
|
||||
private static final int EVENT_UPDATE_STATS = 500;
|
||||
|
||||
private static final int EVENT_UPDATE_CONNECTIVITY = 600;
|
||||
|
||||
private ConnectivityManager mCM;
|
||||
private TelephonyManager mTelephonyManager;
|
||||
private WifiManager mWifiManager;
|
||||
@@ -173,6 +184,10 @@ public class Status extends PreferenceActivity {
|
||||
status.updateTimes();
|
||||
sendEmptyMessageDelayed(EVENT_UPDATE_STATS, 1000);
|
||||
break;
|
||||
|
||||
case EVENT_UPDATE_CONNECTIVITY:
|
||||
status.updateConnectivity();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -215,6 +230,17 @@ public class Status extends PreferenceActivity {
|
||||
}
|
||||
};
|
||||
|
||||
private IntentFilter mConnectivityIntentFilter;
|
||||
private final BroadcastReceiver mConnectivityReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (ArrayUtils.contains(CONNECTIVITY_INTENTS, action)) {
|
||||
mHandler.sendEmptyMessage(EVENT_UPDATE_CONNECTIVITY);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private boolean hasBluetooth() {
|
||||
return BluetoothAdapter.getDefaultAdapter() != null;
|
||||
}
|
||||
@@ -325,6 +351,11 @@ public class Status extends PreferenceActivity {
|
||||
mWimaxMacAddress = null;
|
||||
}
|
||||
|
||||
mConnectivityIntentFilter = new IntentFilter();
|
||||
for (String intent: CONNECTIVITY_INTENTS) {
|
||||
mConnectivityIntentFilter.addAction(intent);
|
||||
}
|
||||
|
||||
updateConnectivity();
|
||||
|
||||
String serial = Build.SERIAL;
|
||||
@@ -356,6 +387,8 @@ public class Status extends PreferenceActivity {
|
||||
CB_AREA_INFO_SENDER_PERMISSION);
|
||||
}
|
||||
}
|
||||
registerReceiver(mConnectivityReceiver, mConnectivityIntentFilter,
|
||||
android.Manifest.permission.CHANGE_NETWORK_STATE, null);
|
||||
registerReceiver(mBatteryInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
|
||||
mHandler.sendEmptyMessage(EVENT_UPDATE_STATS);
|
||||
}
|
||||
@@ -372,6 +405,7 @@ public class Status extends PreferenceActivity {
|
||||
unregisterReceiver(mAreaInfoReceiver);
|
||||
}
|
||||
unregisterReceiver(mBatteryInfoReceiver);
|
||||
unregisterReceiver(mConnectivityReceiver);
|
||||
mHandler.removeMessages(EVENT_UPDATE_STATS);
|
||||
}
|
||||
|
||||
|
@@ -16,8 +16,10 @@
|
||||
|
||||
package com.android.settings.wifi;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.net.wifi.WifiWatchdogStateMachine;
|
||||
@@ -53,6 +55,18 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment
|
||||
|
||||
private WifiManager mWifiManager;
|
||||
|
||||
private IntentFilter mFilter;
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (action.equals(WifiManager.LINK_CONFIGURATION_CHANGED_ACTION) ||
|
||||
action.equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {
|
||||
refreshWifiInfo();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -63,15 +77,26 @@ public class AdvancedWifiSettings extends SettingsPreferenceFragment
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
|
||||
mFilter = new IntentFilter();
|
||||
mFilter.addAction(WifiManager.LINK_CONFIGURATION_CHANGED_ACTION);
|
||||
mFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
initPreferences();
|
||||
getActivity().registerReceiver(mReceiver, mFilter,
|
||||
android.Manifest.permission.CHANGE_NETWORK_STATE, null);
|
||||
refreshWifiInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
getActivity().unregisterReceiver(mReceiver);
|
||||
}
|
||||
|
||||
private void initPreferences() {
|
||||
CheckBoxPreference notifyOpenNetworks =
|
||||
(CheckBoxPreference) findPreference(KEY_NOTIFY_OPEN_NETWORKS);
|
||||
|
Reference in New Issue
Block a user