Keep airplane mode UI & system settings in sync
If mobile radio bring up/down fails, airplane mode UI & system settings go out of sync and this prevents wifi from being brought up on every reboot. Bug: 2887841 Change-Id: Id0f1299e6b4e2c28b72c8fb8d853dad3fcaceaa7
This commit is contained in:
@@ -64,8 +64,6 @@ public class AirplaneModeEnabler implements Preference.OnPreferenceChangeListene
|
|||||||
|
|
||||||
public void resume() {
|
public void resume() {
|
||||||
|
|
||||||
// This is the widget enabled state, not the preference toggled state
|
|
||||||
mCheckBoxPref.setEnabled(true);
|
|
||||||
mCheckBoxPref.setChecked(isAirplaneModeOn(mContext));
|
mCheckBoxPref.setChecked(isAirplaneModeOn(mContext));
|
||||||
|
|
||||||
mPhoneStateReceiver.registerIntent();
|
mPhoneStateReceiver.registerIntent();
|
||||||
@@ -84,13 +82,14 @@ public class AirplaneModeEnabler implements Preference.OnPreferenceChangeListene
|
|||||||
|
|
||||||
private void setAirplaneModeOn(boolean enabling) {
|
private void setAirplaneModeOn(boolean enabling) {
|
||||||
|
|
||||||
mCheckBoxPref.setEnabled(false);
|
|
||||||
mCheckBoxPref.setSummary(enabling ? R.string.airplane_mode_turning_on
|
mCheckBoxPref.setSummary(enabling ? R.string.airplane_mode_turning_on
|
||||||
: R.string.airplane_mode_turning_off);
|
: R.string.airplane_mode_turning_off);
|
||||||
|
|
||||||
// Change the system setting
|
// Change the system setting
|
||||||
Settings.System.putInt(mContext.getContentResolver(), Settings.System.AIRPLANE_MODE_ON,
|
Settings.System.putInt(mContext.getContentResolver(), Settings.System.AIRPLANE_MODE_ON,
|
||||||
enabling ? 1 : 0);
|
enabling ? 1 : 0);
|
||||||
|
// Update the UI to reflect system setting
|
||||||
|
mCheckBoxPref.setChecked(enabling);
|
||||||
|
|
||||||
// Post the intent
|
// Post the intent
|
||||||
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
|
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
|
||||||
@@ -100,14 +99,17 @@ public class AirplaneModeEnabler implements Preference.OnPreferenceChangeListene
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when we've received confirmation that the airplane mode was set.
|
* Called when we've received confirmation that the airplane mode was set.
|
||||||
|
* TODO: We update the checkbox summary when we get notified
|
||||||
|
* that mobile radio is powered up/down. We should not have dependency
|
||||||
|
* on one radio alone. We need to do the following:
|
||||||
|
* - handle the case of wifi/bluetooth failures
|
||||||
|
* - mobile does not send failure notification, fail on timeout.
|
||||||
*/
|
*/
|
||||||
private void onAirplaneModeChanged() {
|
private void onAirplaneModeChanged() {
|
||||||
ServiceState serviceState = mPhoneStateReceiver.getServiceState();
|
ServiceState serviceState = mPhoneStateReceiver.getServiceState();
|
||||||
boolean airplaneModeEnabled = serviceState.getState() == ServiceState.STATE_POWER_OFF;
|
boolean airplaneModeEnabled = serviceState.getState() == ServiceState.STATE_POWER_OFF;
|
||||||
mCheckBoxPref.setChecked(airplaneModeEnabled);
|
|
||||||
mCheckBoxPref.setSummary(airplaneModeEnabled ? null :
|
mCheckBoxPref.setSummary(airplaneModeEnabled ? null :
|
||||||
mContext.getString(R.string.airplane_mode_summary));
|
mContext.getString(R.string.airplane_mode_summary));
|
||||||
mCheckBoxPref.setEnabled(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -128,7 +130,7 @@ public class AirplaneModeEnabler implements Preference.OnPreferenceChangeListene
|
|||||||
// update database based on the current checkbox state
|
// update database based on the current checkbox state
|
||||||
setAirplaneModeOn(isAirplaneModeOn);
|
setAirplaneModeOn(isAirplaneModeOn);
|
||||||
} else {
|
} else {
|
||||||
// update checkbox state based on database value
|
// update summary
|
||||||
onAirplaneModeChanged();
|
onAirplaneModeChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user