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:
@@ -22,13 +22,12 @@
|
||||
android:key="toggle_wifi"
|
||||
android:title="@string/wifi_quick_toggle_title"
|
||||
android:summary="@string/wifi_quick_toggle_summary"
|
||||
android:persistent="false"
|
||||
android:dependency="toggle_airplane" />
|
||||
android:persistent="false" />
|
||||
|
||||
<PreferenceScreen
|
||||
android:key="wifi_settings"
|
||||
android:title="@string/wifi_settings"
|
||||
android:summary="@string/wifi_settings_summary"
|
||||
android:dependency="toggle_airplane">
|
||||
android:summary="@string/wifi_settings_summary" >
|
||||
<intent
|
||||
android:action="android.intent.action.MAIN"
|
||||
android:targetPackage="com.android.settings"
|
||||
@@ -53,9 +52,9 @@
|
||||
</PreferenceScreen>
|
||||
|
||||
<PreferenceScreen
|
||||
android:key="vpn_settings"
|
||||
android:title="@string/vpn_settings_title"
|
||||
android:summary="@string/vpn_settings_summary"
|
||||
android:dependency="toggle_airplane">
|
||||
android:summary="@string/vpn_settings_summary" >
|
||||
<intent
|
||||
android:action="android.intent.action.MAIN"
|
||||
android:targetPackage="com.android.settings"
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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));
|
||||
this, (CheckBoxPreference) airplanePreference);
|
||||
mBtEnabler = new BluetoothEnabler(this, (CheckBoxPreference) btPreference);
|
||||
|
||||
mBtEnabler = new BluetoothEnabler(
|
||||
this,
|
||||
(CheckBoxPreference) findPreference(KEY_TOGGLE_BLUETOOTH));
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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,22 +153,21 @@ 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();
|
||||
// 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;
|
||||
}
|
||||
|
||||
private Preference getDependencyPreference() {
|
||||
String depKey = mWifiCheckBoxPref.getDependency();
|
||||
if (TextUtils.isEmpty(depKey)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
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) {
|
||||
|
Reference in New Issue
Block a user