diff options
-rw-r--r-- | src/com/android/settings/deviceinfo/Status.java | 34 | ||||
-rw-r--r-- | src/com/android/settings/wifi/AdvancedWifiSettings.java | 25 |
2 files changed, 59 insertions, 0 deletions
diff --git a/src/com/android/settings/deviceinfo/Status.java b/src/com/android/settings/deviceinfo/Status.java index 3795c9f2a..a448daedb 100644 --- a/src/com/android/settings/deviceinfo/Status.java +++ b/src/com/android/settings/deviceinfo/Status.java @@ -54,6 +54,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; @@ -124,11 +125,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; @@ -180,6 +191,10 @@ public class Status extends PreferenceActivity { status.updateTimes(); sendEmptyMessageDelayed(EVENT_UPDATE_STATS, 1000); break; + + case EVENT_UPDATE_CONNECTIVITY: + status.updateConnectivity(); + break; } } } @@ -222,6 +237,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; } @@ -332,6 +358,11 @@ public class Status extends PreferenceActivity { mWimaxMacAddress = null; } + mConnectivityIntentFilter = new IntentFilter(); + for (String intent: CONNECTIVITY_INTENTS) { + mConnectivityIntentFilter.addAction(intent); + } + updateConnectivity(); String serial = Build.SERIAL; @@ -384,6 +415,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); } @@ -400,6 +433,7 @@ public class Status extends PreferenceActivity { unregisterReceiver(mAreaInfoReceiver); } unregisterReceiver(mBatteryInfoReceiver); + unregisterReceiver(mConnectivityReceiver); mHandler.removeMessages(EVENT_UPDATE_STATS); } diff --git a/src/com/android/settings/wifi/AdvancedWifiSettings.java b/src/com/android/settings/wifi/AdvancedWifiSettings.java index 766305876..bbcd50d5a 100644 --- a/src/com/android/settings/wifi/AdvancedWifiSettings.java +++ b/src/com/android/settings/wifi/AdvancedWifiSettings.java @@ -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); |