diff options
author | Mike Lockwood <lockwood@android.com> | 2009-07-29 23:25:10 -0700 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2009-07-29 23:53:44 -0700 |
commit | 83bcc98af19597a213a8d174e8f1b47453d513ce (patch) | |
tree | c1898d10bcaf0720ea5e2566365128e641faca18 /src/com/android | |
parent | f0484951fbff3f34407584b73b45f7f75cb4c989 (diff) | |
download | packages_apps_settings-83bcc98af19597a213a8d174e8f1b47453d513ce.zip packages_apps_settings-83bcc98af19597a213a8d174e8f1b47453d513ce.tar.gz packages_apps_settings-83bcc98af19597a213a8d174e8f1b47453d513ce.tar.bz2 |
Allow enabling Wifi when 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.
We also allow access to the VPN settings under the same circumstances.
Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/settings/AirplaneModeEnabler.java | 2 | ||||
-rw-r--r-- | src/com/android/settings/WirelessSettings.java | 37 | ||||
-rw-r--r-- | src/com/android/settings/wifi/WifiEnabler.java | 31 |
3 files changed, 42 insertions, 28 deletions
diff --git a/src/com/android/settings/AirplaneModeEnabler.java b/src/com/android/settings/AirplaneModeEnabler.java index f105712..45411b2 100644 --- a/src/com/android/settings/AirplaneModeEnabler.java +++ b/src/com/android/settings/AirplaneModeEnabler.java @@ -74,7 +74,7 @@ public class AirplaneModeEnabler implements Preference.OnPreferenceChangeListene mCheckBoxPref.setOnPreferenceChangeListener(null); } - static boolean isAirplaneModeOn(Context context) { + public static boolean isAirplaneModeOn(Context context) { return Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0; } diff --git a/src/com/android/settings/WirelessSettings.java b/src/com/android/settings/WirelessSettings.java index d112915..f160bac 100644 --- a/src/com/android/settings/WirelessSettings.java +++ b/src/com/android/settings/WirelessSettings.java @@ -21,14 +21,18 @@ import com.android.settings.wifi.WifiEnabler; import android.net.wifi.WifiManager; import android.os.Bundle; -import android.preference.PreferenceActivity; import android.preference.CheckBoxPreference; +import android.preference.Preference; +import android.preference.PreferenceActivity; +import android.provider.Settings; public class WirelessSettings extends PreferenceActivity { private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane"; private static final String KEY_TOGGLE_BLUETOOTH = "toggle_bluetooth"; private static final String KEY_TOGGLE_WIFI = "toggle_wifi"; + private static final String KEY_WIFI_SETTINGS = "wifi_settings"; + private static final String KEY_VPN_SETTINGS = "vpn_settings"; private WifiEnabler mWifiEnabler; private AirplaneModeEnabler mAirplaneModeEnabler; @@ -63,18 +67,27 @@ public class WirelessSettings extends PreferenceActivity { private void initToggles() { + Preference airplanePreference = findPreference(KEY_TOGGLE_AIRPLANE); + Preference wifiPreference = findPreference(KEY_TOGGLE_WIFI); + Preference btPreference = findPreference(KEY_TOGGLE_BLUETOOTH); + Preference wifiSettings = findPreference(KEY_WIFI_SETTINGS); + Preference vpnSettings = findPreference(KEY_VPN_SETTINGS); + mWifiEnabler = new WifiEnabler( - this, - (WifiManager) getSystemService(WIFI_SERVICE), - (CheckBoxPreference) findPreference(KEY_TOGGLE_WIFI)); - + this, (WifiManager) getSystemService(WIFI_SERVICE), + (CheckBoxPreference) wifiPreference); mAirplaneModeEnabler = new AirplaneModeEnabler( - this, - (CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE)); - - mBtEnabler = new BluetoothEnabler( - this, - (CheckBoxPreference) findPreference(KEY_TOGGLE_BLUETOOTH)); + this, (CheckBoxPreference) airplanePreference); + mBtEnabler = new BluetoothEnabler(this, (CheckBoxPreference) btPreference); + + // manually set up dependencies for Wifi if its radio is not toggleable in airplane mode + String toggleableRadios = Settings.System.getString(getContentResolver(), + Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS); + if (toggleableRadios == null || !toggleableRadios.contains(Settings.System.RADIO_WIFI)) { + wifiPreference.setDependency(airplanePreference.getKey()); + wifiSettings.setDependency(airplanePreference.getKey()); + vpnSettings.setDependency(airplanePreference.getKey()); + } } - + } diff --git a/src/com/android/settings/wifi/WifiEnabler.java b/src/com/android/settings/wifi/WifiEnabler.java index 88cfe06..10a672b 100644 --- a/src/com/android/settings/wifi/WifiEnabler.java +++ b/src/com/android/settings/wifi/WifiEnabler.java @@ -23,6 +23,7 @@ import static android.net.wifi.WifiManager.WIFI_STATE_ENABLING; import static android.net.wifi.WifiManager.WIFI_STATE_UNKNOWN; import com.android.settings.R; +import com.android.settings.AirplaneModeEnabler; import android.content.BroadcastReceiver; import android.content.Context; @@ -32,6 +33,7 @@ import android.net.NetworkInfo; import android.net.wifi.WifiManager; import android.preference.Preference; import android.preference.CheckBoxPreference; +import android.provider.Settings; import android.text.TextUtils; import android.util.Config; import android.util.Log; @@ -121,7 +123,7 @@ public class WifiEnabler implements Preference.OnPreferenceChangeListener { mWifiCheckBoxPref .setSummary(wifiState == WIFI_STATE_DISABLED ? mOriginalSummary : null); - mWifiCheckBoxPref.setEnabled(isEnabledByDependency()); + mWifiCheckBoxPref.setEnabled(isWifiAllowed(mContext)); } else if (wifiState == WIFI_STATE_DISABLING || wifiState == WIFI_STATE_ENABLING) { mWifiCheckBoxPref.setSummary(wifiState == WIFI_STATE_ENABLING ? R.string.wifi_starting @@ -151,24 +153,23 @@ public class WifiEnabler implements Preference.OnPreferenceChangeListener { } } - private boolean isEnabledByDependency() { - Preference dep = getDependencyPreference(); - if (dep == null) { + private static boolean isWifiAllowed(Context context) { + // allowed if we are not in airplane mode + if (!AirplaneModeEnabler.isAirplaneModeOn(context)) { return true; } - - return !dep.shouldDisableDependents(); - } - - private Preference getDependencyPreference() { - String depKey = mWifiCheckBoxPref.getDependency(); - if (TextUtils.isEmpty(depKey)) { - return null; + // allowed if wifi is not in AIRPLANE_MODE_RADIOS + String radios = Settings.System.getString(context.getContentResolver(), + Settings.System.AIRPLANE_MODE_RADIOS); + if (radios == null || !radios.contains(Settings.System.RADIO_WIFI)) { + return true; } - - return mWifiCheckBoxPref.getPreferenceManager().findPreference(depKey); + // allowed if wifi is in AIRPLANE_MODE_TOGGLEABLE_RADIOS + radios = Settings.System.getString(context.getContentResolver(), + Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS); + return (radios != null && radios.contains(Settings.System.RADIO_WIFI)); } - + private static String getHumanReadableWifiState(int wifiState) { switch (wifiState) { case WIFI_STATE_DISABLED: |