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>
This commit is contained in:
Mike Lockwood
2009-07-29 23:25:10 -07:00
parent f0484951fb
commit 83bcc98af1
4 changed files with 47 additions and 34 deletions

View File

@@ -22,13 +22,12 @@
android:key="toggle_wifi" android:key="toggle_wifi"
android:title="@string/wifi_quick_toggle_title" android:title="@string/wifi_quick_toggle_title"
android:summary="@string/wifi_quick_toggle_summary" android:summary="@string/wifi_quick_toggle_summary"
android:persistent="false" android:persistent="false" />
android:dependency="toggle_airplane" />
<PreferenceScreen <PreferenceScreen
android:key="wifi_settings"
android:title="@string/wifi_settings" android:title="@string/wifi_settings"
android:summary="@string/wifi_settings_summary" android:summary="@string/wifi_settings_summary" >
android:dependency="toggle_airplane">
<intent <intent
android:action="android.intent.action.MAIN" android:action="android.intent.action.MAIN"
android:targetPackage="com.android.settings" android:targetPackage="com.android.settings"
@@ -53,9 +52,9 @@
</PreferenceScreen> </PreferenceScreen>
<PreferenceScreen <PreferenceScreen
android:key="vpn_settings"
android:title="@string/vpn_settings_title" android:title="@string/vpn_settings_title"
android:summary="@string/vpn_settings_summary" android:summary="@string/vpn_settings_summary" >
android:dependency="toggle_airplane">
<intent <intent
android:action="android.intent.action.MAIN" android:action="android.intent.action.MAIN"
android:targetPackage="com.android.settings" android:targetPackage="com.android.settings"

View File

@@ -74,7 +74,7 @@ public class AirplaneModeEnabler implements Preference.OnPreferenceChangeListene
mCheckBoxPref.setOnPreferenceChangeListener(null); mCheckBoxPref.setOnPreferenceChangeListener(null);
} }
static boolean isAirplaneModeOn(Context context) { public static boolean isAirplaneModeOn(Context context) {
return Settings.System.getInt(context.getContentResolver(), return Settings.System.getInt(context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0) != 0; Settings.System.AIRPLANE_MODE_ON, 0) != 0;
} }

View File

@@ -21,14 +21,18 @@ import com.android.settings.wifi.WifiEnabler;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.CheckBoxPreference; import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.provider.Settings;
public class WirelessSettings extends PreferenceActivity { public class WirelessSettings extends PreferenceActivity {
private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane"; private static final String KEY_TOGGLE_AIRPLANE = "toggle_airplane";
private static final String KEY_TOGGLE_BLUETOOTH = "toggle_bluetooth"; private static final String KEY_TOGGLE_BLUETOOTH = "toggle_bluetooth";
private static final String KEY_TOGGLE_WIFI = "toggle_wifi"; 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 WifiEnabler mWifiEnabler;
private AirplaneModeEnabler mAirplaneModeEnabler; private AirplaneModeEnabler mAirplaneModeEnabler;
@@ -63,18 +67,27 @@ public class WirelessSettings extends PreferenceActivity {
private void initToggles() { 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( mWifiEnabler = new WifiEnabler(
this, this, (WifiManager) getSystemService(WIFI_SERVICE),
(WifiManager) getSystemService(WIFI_SERVICE), (CheckBoxPreference) wifiPreference);
(CheckBoxPreference) findPreference(KEY_TOGGLE_WIFI));
mAirplaneModeEnabler = new AirplaneModeEnabler( mAirplaneModeEnabler = new AirplaneModeEnabler(
this, this, (CheckBoxPreference) airplanePreference);
(CheckBoxPreference) findPreference(KEY_TOGGLE_AIRPLANE)); mBtEnabler = new BluetoothEnabler(this, (CheckBoxPreference) btPreference);
mBtEnabler = new BluetoothEnabler( // manually set up dependencies for Wifi if its radio is not toggleable in airplane mode
this, String toggleableRadios = Settings.System.getString(getContentResolver(),
(CheckBoxPreference) findPreference(KEY_TOGGLE_BLUETOOTH)); 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());
}
} }
} }

View File

@@ -23,6 +23,7 @@ import static android.net.wifi.WifiManager.WIFI_STATE_ENABLING;
import static android.net.wifi.WifiManager.WIFI_STATE_UNKNOWN; import static android.net.wifi.WifiManager.WIFI_STATE_UNKNOWN;
import com.android.settings.R; import com.android.settings.R;
import com.android.settings.AirplaneModeEnabler;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
@@ -32,6 +33,7 @@ import android.net.NetworkInfo;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.preference.Preference; import android.preference.Preference;
import android.preference.CheckBoxPreference; import android.preference.CheckBoxPreference;
import android.provider.Settings;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Config; import android.util.Config;
import android.util.Log; import android.util.Log;
@@ -121,7 +123,7 @@ public class WifiEnabler implements Preference.OnPreferenceChangeListener {
mWifiCheckBoxPref mWifiCheckBoxPref
.setSummary(wifiState == WIFI_STATE_DISABLED ? mOriginalSummary : null); .setSummary(wifiState == WIFI_STATE_DISABLED ? mOriginalSummary : null);
mWifiCheckBoxPref.setEnabled(isEnabledByDependency()); mWifiCheckBoxPref.setEnabled(isWifiAllowed(mContext));
} else if (wifiState == WIFI_STATE_DISABLING || wifiState == WIFI_STATE_ENABLING) { } else if (wifiState == WIFI_STATE_DISABLING || wifiState == WIFI_STATE_ENABLING) {
mWifiCheckBoxPref.setSummary(wifiState == WIFI_STATE_ENABLING ? R.string.wifi_starting mWifiCheckBoxPref.setSummary(wifiState == WIFI_STATE_ENABLING ? R.string.wifi_starting
@@ -151,22 +153,21 @@ public class WifiEnabler implements Preference.OnPreferenceChangeListener {
} }
} }
private boolean isEnabledByDependency() { private static boolean isWifiAllowed(Context context) {
Preference dep = getDependencyPreference(); // allowed if we are not in airplane mode
if (dep == null) { if (!AirplaneModeEnabler.isAirplaneModeOn(context)) {
return true; return true;
} }
// allowed if wifi is not in AIRPLANE_MODE_RADIOS
return !dep.shouldDisableDependents(); String radios = Settings.System.getString(context.getContentResolver(),
} Settings.System.AIRPLANE_MODE_RADIOS);
if (radios == null || !radios.contains(Settings.System.RADIO_WIFI)) {
private Preference getDependencyPreference() { return true;
String depKey = mWifiCheckBoxPref.getDependency();
if (TextUtils.isEmpty(depKey)) {
return null;
} }
// allowed if wifi is in AIRPLANE_MODE_TOGGLEABLE_RADIOS
return mWifiCheckBoxPref.getPreferenceManager().findPreference(depKey); 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) { private static String getHumanReadableWifiState(int wifiState) {