Merge "Persist wifi override in airplane mode" into honeycomb-mr1
This commit is contained in:
committed by
Android (Google) Code Review
commit
7ad85eb62f
@ -62,6 +62,7 @@ import android.util.Slog;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
@ -99,9 +100,6 @@ public class WifiService extends IWifiManager.Stub {
|
|||||||
/* Chipset supports background scan */
|
/* Chipset supports background scan */
|
||||||
private final boolean mBackgroundScanSupported;
|
private final boolean mBackgroundScanSupported;
|
||||||
|
|
||||||
// true if the user enabled Wifi while in airplane mode
|
|
||||||
private AtomicBoolean mAirplaneModeOverwridden = new AtomicBoolean(false);
|
|
||||||
|
|
||||||
private final LockList mLocks = new LockList();
|
private final LockList mLocks = new LockList();
|
||||||
// some wifi lock statistics
|
// some wifi lock statistics
|
||||||
private int mFullHighPerfLocksAcquired;
|
private int mFullHighPerfLocksAcquired;
|
||||||
@ -144,6 +142,14 @@ public class WifiService extends IWifiManager.Stub {
|
|||||||
private static final String ACTION_DEVICE_IDLE =
|
private static final String ACTION_DEVICE_IDLE =
|
||||||
"com.android.server.WifiManager.action.DEVICE_IDLE";
|
"com.android.server.WifiManager.action.DEVICE_IDLE";
|
||||||
|
|
||||||
|
private static final int WIFI_DISABLED = 0;
|
||||||
|
private static final int WIFI_ENABLED = 1;
|
||||||
|
/* Wifi enabled while in airplane mode */
|
||||||
|
private static final int WIFI_ENABLED_AIRPLANE_OVERRIDE = 2;
|
||||||
|
|
||||||
|
private AtomicInteger mWifiState = new AtomicInteger(WIFI_DISABLED);
|
||||||
|
private AtomicBoolean mAirplaneModeOn = new AtomicBoolean(false);
|
||||||
|
|
||||||
private boolean mIsReceiverRegistered = false;
|
private boolean mIsReceiverRegistered = false;
|
||||||
|
|
||||||
|
|
||||||
@ -338,11 +344,11 @@ public class WifiService extends IWifiManager.Stub {
|
|||||||
new BroadcastReceiver() {
|
new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
// clear our flag indicating the user has overwridden airplane mode
|
mAirplaneModeOn.set(isAirplaneModeOn());
|
||||||
mAirplaneModeOverwridden.set(false);
|
/* On airplane mode disable, restore wifi state if necessary */
|
||||||
// on airplane disable, restore Wifi if the saved state indicates so
|
if (!mAirplaneModeOn.get() && (testAndClearWifiSavedState() ||
|
||||||
if (!isAirplaneModeOn() && testAndClearWifiSavedState()) {
|
mWifiState.get() == WIFI_ENABLED_AIRPLANE_OVERRIDE)) {
|
||||||
persistWifiEnabled(true);
|
persistWifiEnabled(true);
|
||||||
}
|
}
|
||||||
updateWifiState();
|
updateWifiState();
|
||||||
}
|
}
|
||||||
@ -402,9 +408,10 @@ public class WifiService extends IWifiManager.Stub {
|
|||||||
* This function is used only at boot time
|
* This function is used only at boot time
|
||||||
*/
|
*/
|
||||||
public void checkAndStartWifi() {
|
public void checkAndStartWifi() {
|
||||||
/* Start if Wi-Fi is enabled or the saved state indicates Wi-Fi was on */
|
mAirplaneModeOn.set(isAirplaneModeOn());
|
||||||
boolean wifiEnabled = !isAirplaneModeOn()
|
mWifiState.set(getPersistedWifiState());
|
||||||
&& (getPersistedWifiEnabled() || testAndClearWifiSavedState());
|
/* Start if Wi-Fi should be enabled or the saved state indicates Wi-Fi was on */
|
||||||
|
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);
|
setWifiEnabled(wifiEnabled);
|
||||||
@ -423,21 +430,39 @@ public class WifiService extends IWifiManager.Stub {
|
|||||||
return (wifiSavedState == 1);
|
return (wifiSavedState == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean getPersistedWifiEnabled() {
|
private int getPersistedWifiState() {
|
||||||
final ContentResolver cr = mContext.getContentResolver();
|
final ContentResolver cr = mContext.getContentResolver();
|
||||||
try {
|
try {
|
||||||
return Settings.Secure.getInt(cr, Settings.Secure.WIFI_ON) == 1;
|
return Settings.Secure.getInt(cr, Settings.Secure.WIFI_ON);
|
||||||
} catch (Settings.SettingNotFoundException e) {
|
} catch (Settings.SettingNotFoundException e) {
|
||||||
Settings.Secure.putInt(cr, Settings.Secure.WIFI_ON, 0);
|
Settings.Secure.putInt(cr, Settings.Secure.WIFI_ON, WIFI_DISABLED);
|
||||||
return false;
|
return WIFI_DISABLED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean shouldWifiBeEnabled() {
|
||||||
|
if (mAirplaneModeOn.get()) {
|
||||||
|
return mWifiState.get() == WIFI_ENABLED_AIRPLANE_OVERRIDE;
|
||||||
|
} else {
|
||||||
|
return mWifiState.get() != WIFI_DISABLED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void persistWifiEnabled(boolean enabled) {
|
private void persistWifiEnabled(boolean enabled) {
|
||||||
final ContentResolver cr = mContext.getContentResolver();
|
final ContentResolver cr = mContext.getContentResolver();
|
||||||
Settings.Secure.putInt(cr, Settings.Secure.WIFI_ON, enabled ? 1 : 0);
|
if (enabled) {
|
||||||
|
if (isAirplaneModeOn() && isAirplaneToggleable()) {
|
||||||
|
mWifiState.set(WIFI_ENABLED_AIRPLANE_OVERRIDE);
|
||||||
|
} else {
|
||||||
|
mWifiState.set(WIFI_ENABLED);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mWifiState.set(WIFI_DISABLED);
|
||||||
|
}
|
||||||
|
Settings.Secure.putInt(cr, Settings.Secure.WIFI_ON, mWifiState.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* see {@link android.net.wifi.WifiManager#pingSupplicant()}
|
* see {@link android.net.wifi.WifiManager#pingSupplicant()}
|
||||||
* @return {@code true} if the operation succeeds, {@code false} otherwise
|
* @return {@code true} if the operation succeeds, {@code false} otherwise
|
||||||
@ -490,11 +515,6 @@ public class WifiService extends IWifiManager.Stub {
|
|||||||
Slog.e(TAG, "Invoking mWifiStateMachine.setWifiEnabled\n");
|
Slog.e(TAG, "Invoking mWifiStateMachine.setWifiEnabled\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// set a flag if the user is enabling Wifi while in airplane mode
|
|
||||||
if (enable && isAirplaneModeOn() && isAirplaneToggleable()) {
|
|
||||||
mAirplaneModeOverwridden.set(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
reportStartWorkSource();
|
reportStartWorkSource();
|
||||||
}
|
}
|
||||||
@ -1037,11 +1057,8 @@ public class WifiService extends IWifiManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateWifiState() {
|
private void updateWifiState() {
|
||||||
boolean wifiEnabled = getPersistedWifiEnabled();
|
|
||||||
boolean airplaneMode = isAirplaneModeOn() && !mAirplaneModeOverwridden.get();
|
|
||||||
boolean lockHeld = mLocks.hasLocks();
|
boolean lockHeld = mLocks.hasLocks();
|
||||||
int strongestLockMode = WifiManager.WIFI_MODE_FULL;
|
int strongestLockMode = WifiManager.WIFI_MODE_FULL;
|
||||||
boolean wifiShouldBeEnabled = wifiEnabled && !airplaneMode;
|
|
||||||
boolean wifiShouldBeStarted = !mDeviceIdle || lockHeld;
|
boolean wifiShouldBeStarted = !mDeviceIdle || lockHeld;
|
||||||
|
|
||||||
if (lockHeld) {
|
if (lockHeld) {
|
||||||
@ -1053,11 +1070,11 @@ public class WifiService extends IWifiManager.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Disable tethering when airplane mode is enabled */
|
/* Disable tethering when airplane mode is enabled */
|
||||||
if (airplaneMode) {
|
if (mAirplaneModeOn.get()) {
|
||||||
mWifiStateMachine.setWifiApEnabled(null, false);
|
mWifiStateMachine.setWifiApEnabled(null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wifiShouldBeEnabled) {
|
if (shouldWifiBeEnabled()) {
|
||||||
if (wifiShouldBeStarted) {
|
if (wifiShouldBeStarted) {
|
||||||
reportStartWorkSource();
|
reportStartWorkSource();
|
||||||
mWifiStateMachine.setWifiEnabled(true);
|
mWifiStateMachine.setWifiEnabled(true);
|
||||||
|
Reference in New Issue
Block a user