Fix settings handling of wifi events
When wifi events come out, settings has to change the switch state. Changing switch state causes settings to also enable/disable wifi which gets into a loop when there is a driver hung event. Fix to only send framework calls when a user has changed the switch settings Bug: 5271322 Change-Id: I0a7d03a3fe0f28622de05981e5f72a9a8814b2d2
This commit is contained in:
@@ -40,6 +40,7 @@ public class WifiEnabler implements CompoundButton.OnCheckedChangeListener {
|
|||||||
private AtomicBoolean mConnected = new AtomicBoolean(false);
|
private AtomicBoolean mConnected = new AtomicBoolean(false);
|
||||||
|
|
||||||
private final WifiManager mWifiManager;
|
private final WifiManager mWifiManager;
|
||||||
|
private boolean mStateMachineEvent;
|
||||||
private final IntentFilter mIntentFilter;
|
private final IntentFilter mIntentFilter;
|
||||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
@@ -98,6 +99,10 @@ public class WifiEnabler implements CompoundButton.OnCheckedChangeListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
//Do nothing if called as a result of a state machine event
|
||||||
|
if (mStateMachineEvent) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Show toast message if Wi-Fi is not allowed in airplane mode
|
// Show toast message if Wi-Fi is not allowed in airplane mode
|
||||||
if (isChecked && !WirelessSettings.isRadioAllowed(mContext, Settings.System.RADIO_WIFI)) {
|
if (isChecked && !WirelessSettings.isRadioAllowed(mContext, Settings.System.RADIO_WIFI)) {
|
||||||
Toast.makeText(mContext, R.string.wifi_in_airplane_mode, Toast.LENGTH_SHORT).show();
|
Toast.makeText(mContext, R.string.wifi_in_airplane_mode, Toast.LENGTH_SHORT).show();
|
||||||
@@ -127,19 +132,28 @@ public class WifiEnabler implements CompoundButton.OnCheckedChangeListener {
|
|||||||
mSwitch.setEnabled(false);
|
mSwitch.setEnabled(false);
|
||||||
break;
|
break;
|
||||||
case WifiManager.WIFI_STATE_ENABLED:
|
case WifiManager.WIFI_STATE_ENABLED:
|
||||||
mSwitch.setChecked(true);
|
setSwitchChecked(true);
|
||||||
mSwitch.setEnabled(true);
|
mSwitch.setEnabled(true);
|
||||||
break;
|
break;
|
||||||
case WifiManager.WIFI_STATE_DISABLING:
|
case WifiManager.WIFI_STATE_DISABLING:
|
||||||
mSwitch.setEnabled(false);
|
mSwitch.setEnabled(false);
|
||||||
break;
|
break;
|
||||||
case WifiManager.WIFI_STATE_DISABLED:
|
case WifiManager.WIFI_STATE_DISABLED:
|
||||||
mSwitch.setChecked(false);
|
setSwitchChecked(false);
|
||||||
mSwitch.setEnabled(true);
|
mSwitch.setEnabled(true);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
mSwitch.setChecked(false);
|
setSwitchChecked(false);
|
||||||
mSwitch.setEnabled(true);
|
mSwitch.setEnabled(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setSwitchChecked(boolean checked) {
|
||||||
|
if (checked != mSwitch.isChecked()) {
|
||||||
|
mStateMachineEvent = true;
|
||||||
|
mSwitch.setChecked(checked);
|
||||||
|
mStateMachineEvent = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user