diff options
author | Irfan Sheriff <isheriff@google.com> | 2011-03-09 09:30:28 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-03-09 09:30:28 -0800 |
commit | 7ad85eb62f9f332cc8002ec996cd359333ba590e (patch) | |
tree | 1e0c037e0317ef0a575c60fb9dff30e42a1cf6cb | |
parent | ea44c7c71431adbce348cf9ef3f22d9561bb7fc1 (diff) | |
parent | 658772f0e6bcf2b0a3e26778c2fc47accbdfeb2e (diff) | |
download | frameworks_base-7ad85eb62f9f332cc8002ec996cd359333ba590e.zip frameworks_base-7ad85eb62f9f332cc8002ec996cd359333ba590e.tar.gz frameworks_base-7ad85eb62f9f332cc8002ec996cd359333ba590e.tar.bz2 |
Merge "Persist wifi override in airplane mode" into honeycomb-mr1
-rw-r--r-- | services/java/com/android/server/WifiService.java | 69 |
1 files changed, 43 insertions, 26 deletions
diff --git a/services/java/com/android/server/WifiService.java b/services/java/com/android/server/WifiService.java index adc49ae..3c6c427 100644 --- a/services/java/com/android/server/WifiService.java +++ b/services/java/com/android/server/WifiService.java @@ -62,6 +62,7 @@ import android.util.Slog; import java.util.ArrayList; import java.util.List; import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicBoolean; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -99,9 +100,6 @@ public class WifiService extends IWifiManager.Stub { /* Chipset supports background scan */ 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(); // some wifi lock statistics private int mFullHighPerfLocksAcquired; @@ -144,6 +142,14 @@ public class WifiService extends IWifiManager.Stub { private static final String 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; @@ -338,11 +344,11 @@ 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.set(false); - // on airplane disable, restore Wifi if the saved state indicates so - if (!isAirplaneModeOn() && testAndClearWifiSavedState()) { - persistWifiEnabled(true); + mAirplaneModeOn.set(isAirplaneModeOn()); + /* On airplane mode disable, restore wifi state if necessary */ + if (!mAirplaneModeOn.get() && (testAndClearWifiSavedState() || + mWifiState.get() == WIFI_ENABLED_AIRPLANE_OVERRIDE)) { + persistWifiEnabled(true); } updateWifiState(); } @@ -402,9 +408,10 @@ public class WifiService extends IWifiManager.Stub { * This function is used only at boot time */ public void checkAndStartWifi() { - /* Start if Wi-Fi is enabled or the saved state indicates Wi-Fi was on */ - boolean wifiEnabled = !isAirplaneModeOn() - && (getPersistedWifiEnabled() || testAndClearWifiSavedState()); + mAirplaneModeOn.set(isAirplaneModeOn()); + mWifiState.set(getPersistedWifiState()); + /* 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 " + (wifiEnabled ? "enabled" : "disabled")); setWifiEnabled(wifiEnabled); @@ -423,21 +430,39 @@ public class WifiService extends IWifiManager.Stub { return (wifiSavedState == 1); } - private boolean getPersistedWifiEnabled() { + private int getPersistedWifiState() { final ContentResolver cr = mContext.getContentResolver(); try { - return Settings.Secure.getInt(cr, Settings.Secure.WIFI_ON) == 1; + return Settings.Secure.getInt(cr, Settings.Secure.WIFI_ON); } catch (Settings.SettingNotFoundException e) { - Settings.Secure.putInt(cr, Settings.Secure.WIFI_ON, 0); - return false; + Settings.Secure.putInt(cr, Settings.Secure.WIFI_ON, WIFI_DISABLED); + 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) { 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()} * @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"); } - // set a flag if the user is enabling Wifi while in airplane mode - if (enable && isAirplaneModeOn() && isAirplaneToggleable()) { - mAirplaneModeOverwridden.set(true); - } - if (enable) { reportStartWorkSource(); } @@ -1037,11 +1057,8 @@ public class WifiService extends IWifiManager.Stub { } private void updateWifiState() { - boolean wifiEnabled = getPersistedWifiEnabled(); - boolean airplaneMode = isAirplaneModeOn() && !mAirplaneModeOverwridden.get(); boolean lockHeld = mLocks.hasLocks(); int strongestLockMode = WifiManager.WIFI_MODE_FULL; - boolean wifiShouldBeEnabled = wifiEnabled && !airplaneMode; boolean wifiShouldBeStarted = !mDeviceIdle || lockHeld; if (lockHeld) { @@ -1053,11 +1070,11 @@ public class WifiService extends IWifiManager.Stub { } /* Disable tethering when airplane mode is enabled */ - if (airplaneMode) { + if (mAirplaneModeOn.get()) { mWifiStateMachine.setWifiApEnabled(null, false); } - if (wifiShouldBeEnabled) { + if (shouldWifiBeEnabled()) { if (wifiShouldBeStarted) { reportStartWorkSource(); mWifiStateMachine.setWifiEnabled(true); |