am ce66556a: Merge "Fix persisting wifi state on setWifiEnabled() call" into jb-dev
* commit 'ce66556a345aacad517f8eb72ddec20160ce9d61': Fix persisting wifi state on setWifiEnabled() call
This commit is contained in:
@@ -376,11 +376,7 @@ public class WifiService extends IWifiManager.Stub {
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
mAirplaneModeOn.set(isAirplaneModeOn());
|
mAirplaneModeOn.set(isAirplaneModeOn());
|
||||||
/* On airplane mode disable, restore wifi state if necessary */
|
handleAirplaneModeToggled();
|
||||||
if (!mAirplaneModeOn.get() && (testAndClearWifiSavedState() ||
|
|
||||||
mPersistWifiState.get() == WIFI_ENABLED_AIRPLANE_OVERRIDE)) {
|
|
||||||
persistWifiState(true);
|
|
||||||
}
|
|
||||||
updateWifiState();
|
updateWifiState();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -447,7 +443,10 @@ public class WifiService extends IWifiManager.Stub {
|
|||||||
boolean wifiEnabled = shouldWifiBeEnabled() || testAndClearWifiSavedState();
|
boolean wifiEnabled = shouldWifiBeEnabled() || testAndClearWifiSavedState();
|
||||||
Slog.i(TAG, "WifiService starting up with Wi-Fi " +
|
Slog.i(TAG, "WifiService starting up with Wi-Fi " +
|
||||||
(wifiEnabled ? "enabled" : "disabled"));
|
(wifiEnabled ? "enabled" : "disabled"));
|
||||||
setWifiEnabled(wifiEnabled);
|
|
||||||
|
// If we are already disabled (could be due to airplane mode), avoid changing persist
|
||||||
|
// state here
|
||||||
|
if (wifiEnabled) setWifiEnabled(wifiEnabled);
|
||||||
|
|
||||||
mWifiWatchdogStateMachine = WifiWatchdogStateMachine.
|
mWifiWatchdogStateMachine = WifiWatchdogStateMachine.
|
||||||
makeWifiWatchdogStateMachine(mContext);
|
makeWifiWatchdogStateMachine(mContext);
|
||||||
@@ -485,26 +484,43 @@ public class WifiService extends IWifiManager.Stub {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void persistWifiState(boolean enabled) {
|
private void handleWifiToggled(boolean enabled) {
|
||||||
final ContentResolver cr = mContext.getContentResolver();
|
|
||||||
boolean airplane = mAirplaneModeOn.get() && isAirplaneToggleable();
|
boolean airplane = mAirplaneModeOn.get() && isAirplaneToggleable();
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
if (airplane) {
|
if (airplane) {
|
||||||
mPersistWifiState.set(WIFI_ENABLED_AIRPLANE_OVERRIDE);
|
persistWifiState(WIFI_ENABLED_AIRPLANE_OVERRIDE);
|
||||||
} else {
|
} else {
|
||||||
mPersistWifiState.set(WIFI_ENABLED);
|
persistWifiState(WIFI_ENABLED);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (airplane) {
|
// When wifi state is disabled, we do not care
|
||||||
mPersistWifiState.set(WIFI_DISABLED_AIRPLANE_ON);
|
// if airplane mode is on or not. The scenario of
|
||||||
} else {
|
// wifi being disabled due to airplane mode being turned on
|
||||||
mPersistWifiState.set(WIFI_DISABLED);
|
// is handled handleAirplaneModeToggled()
|
||||||
}
|
persistWifiState(WIFI_DISABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
Settings.Secure.putInt(cr, Settings.Secure.WIFI_ON, mPersistWifiState.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleAirplaneModeToggled() {
|
||||||
|
if (mAirplaneModeOn.get()) {
|
||||||
|
// Wifi disabled due to airplane on
|
||||||
|
if (mWifiEnabled) {
|
||||||
|
persistWifiState(WIFI_DISABLED_AIRPLANE_ON);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* On airplane mode disable, restore wifi state if necessary */
|
||||||
|
if (testAndClearWifiSavedState() ||
|
||||||
|
mPersistWifiState.get() == WIFI_ENABLED_AIRPLANE_OVERRIDE) {
|
||||||
|
persistWifiState(WIFI_ENABLED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void persistWifiState(int state) {
|
||||||
|
final ContentResolver cr = mContext.getContentResolver();
|
||||||
|
mPersistWifiState.set(state);
|
||||||
|
Settings.Secure.putInt(cr, Settings.Secure.WIFI_ON, state);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* see {@link android.net.wifi.WifiManager#pingSupplicant()}
|
* see {@link android.net.wifi.WifiManager#pingSupplicant()}
|
||||||
@@ -578,12 +594,9 @@ public class WifiService extends IWifiManager.Stub {
|
|||||||
* only CHANGE_WIFI_STATE is enforced
|
* only CHANGE_WIFI_STATE is enforced
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Avoids overriding of airplane state when wifi is already in the expected state */
|
long ident = Binder.clearCallingIdentity();
|
||||||
if (enable != mWifiEnabled) {
|
handleWifiToggled(enable);
|
||||||
long ident = Binder.clearCallingIdentity();
|
Binder.restoreCallingIdentity(ident);
|
||||||
persistWifiState(enable);
|
|
||||||
Binder.restoreCallingIdentity(ident);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
if (!mIsReceiverRegistered) {
|
if (!mIsReceiverRegistered) {
|
||||||
|
|||||||
Reference in New Issue
Block a user