Wifi: Add support for enabling Wifi while in airplane mode.
If the new system settings value for AIRPLANE_MODE_TOGGLEABLE_RADIOS contains RADIO_WIFI, then the user will be allowed to enable Wifi while in airplane mode. Turning on airplane mode will still disable Wifi, but the user will be free to reenable it in the Settings app. Signed-off-by: Mike Lockwood <lockwood@android.com>
This commit is contained in:
@@ -93,6 +93,9 @@ public class WifiService extends IWifiManager.Stub {
|
||||
private boolean mDeviceIdle;
|
||||
private int mPluggedType;
|
||||
|
||||
// true if the user enabled Wifi while in airplane mode
|
||||
private boolean mAirplaneModeOverwridden;
|
||||
|
||||
private final LockList mLocks = new LockList();
|
||||
// some wifi lock statistics
|
||||
private int mFullLocksAcquired;
|
||||
@@ -219,6 +222,8 @@ public class WifiService extends IWifiManager.Stub {
|
||||
new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
// clear our flag indicating the user has overwridden airplane mode
|
||||
mAirplaneModeOverwridden = false;
|
||||
updateWifiState();
|
||||
}
|
||||
},
|
||||
@@ -292,6 +297,8 @@ public class WifiService extends IWifiManager.Stub {
|
||||
synchronized (mWifiHandler) {
|
||||
sWakeLock.acquire();
|
||||
mLastEnableUid = Binder.getCallingUid();
|
||||
// set a flag if the user is enabling Wifi while in airplane mode
|
||||
mAirplaneModeOverwridden = (enable && isAirplaneModeOn() && isAirplaneToggleable());
|
||||
sendEnableMessage(enable, true, Binder.getCallingUid());
|
||||
}
|
||||
|
||||
@@ -312,7 +319,7 @@ public class WifiService extends IWifiManager.Stub {
|
||||
if (mWifiState == eventualWifiState) {
|
||||
return true;
|
||||
}
|
||||
if (enable && isAirplaneModeOn()) {
|
||||
if (enable && isAirplaneModeOn() && !mAirplaneModeOverwridden) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1495,7 +1502,7 @@ public class WifiService extends IWifiManager.Stub {
|
||||
|
||||
private void updateWifiState() {
|
||||
boolean wifiEnabled = getPersistedWifiEnabled();
|
||||
boolean airplaneMode = isAirplaneModeOn();
|
||||
boolean airplaneMode = isAirplaneModeOn() && !mAirplaneModeOverwridden;
|
||||
boolean lockHeld = mLocks.hasLocks();
|
||||
int strongestLockMode;
|
||||
boolean wifiShouldBeEnabled = wifiEnabled && !airplaneMode;
|
||||
@@ -1559,6 +1566,13 @@ public class WifiService extends IWifiManager.Stub {
|
||||
|| airplaneModeRadios.contains(Settings.System.RADIO_WIFI);
|
||||
}
|
||||
|
||||
private boolean isAirplaneToggleable() {
|
||||
String toggleableRadios = Settings.System.getString(mContext.getContentResolver(),
|
||||
Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
|
||||
return toggleableRadios != null
|
||||
&& toggleableRadios.contains(Settings.System.RADIO_WIFI);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Wi-Fi is sensitive to airplane mode, and airplane mode is
|
||||
* currently on.
|
||||
|
||||
Reference in New Issue
Block a user