Allow bluetooth in airplane mode when in "toggleable" list.

Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS is a list of
radios that can be toggled while in airplane mode.  This CL
changes BluetoothEnabler to respect this.

It parallels the logic in WifiEnabler, which enables OEMs
to allow Wifi changes when in airplane mode.

Most existing devices don't include "bluetooth" in the
toggleable list, which means bluetooth will continue to be
disabled when in airplane mode for those devices.

Fixes http://b/2297314
This commit is contained in:
Jeff Sharkey
2009-12-01 17:08:20 -08:00
parent fc34079510
commit 1c4e96864f
4 changed files with 44 additions and 28 deletions

View File

@@ -44,14 +44,12 @@
android:key="toggle_bluetooth"
android:title="@string/bluetooth_quick_toggle_title"
android:summary="@string/bluetooth_quick_toggle_summary"
android:persistent="false"
android:dependency="toggle_airplane" />
android:persistent="false" />
<PreferenceScreen
android:key="bt_settings"
android:title="@string/bluetooth_settings_title"
android:summary="@string/bluetooth_settings_summary"
android:dependency="toggle_airplane">
android:summary="@string/bluetooth_settings_summary">
<intent
android:action="android.intent.action.MAIN"
android:targetPackage="com.android.settings"

View File

@@ -107,12 +107,12 @@ public class WirelessSettings extends PreferenceActivity {
Preference wifiPreference = findPreference(KEY_TOGGLE_WIFI);
Preference btPreference = findPreference(KEY_TOGGLE_BLUETOOTH);
Preference wifiSettings = findPreference(KEY_WIFI_SETTINGS);
Preference btSettings = findPreference(KEY_BT_SETTINGS);
Preference vpnSettings = findPreference(KEY_VPN_SETTINGS);
IBinder b = ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE);
if (b == null) {
// Disable BT Settings if BT service is not available.
Preference btSettings = findPreference(KEY_BT_SETTINGS);
btSettings.setEnabled(false);
}
@@ -131,6 +131,13 @@ public class WirelessSettings extends PreferenceActivity {
wifiSettings.setDependency(airplanePreference.getKey());
vpnSettings.setDependency(airplanePreference.getKey());
}
// Manually set dependencies for Bluetooth when not toggleable.
if (toggleableRadios == null ||
!toggleableRadios.contains(Settings.System.RADIO_BLUETOOTH)) {
btPreference.setDependency(airplanePreference.getKey());
btSettings.setDependency(airplanePreference.getKey());
}
}
@Override

View File

@@ -16,6 +16,7 @@
package com.android.settings.bluetooth;
import com.android.settings.AirplaneModeEnabler;
import com.android.settings.R;
import android.bluetooth.BluetoothAdapter;
@@ -25,6 +26,7 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.preference.Preference;
import android.preference.CheckBoxPreference;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Config;
@@ -116,14 +118,15 @@ public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
mOriginalSummary :
null);
/*
* Don't ever disable the preference. Only enable here. Disablement
* is taken care of by the dependency code. If this is disabled
* here, it may not be re-enabled from the framework when dependency
* is met. http://b/issue?id=2053751
*/
if (isEnabledByDependency()) {
final boolean hasDependency = !TextUtils.isEmpty(mCheckBoxPreference.getDependency());
final boolean bluetoothAllowed = isBluetoothAllowed(mContext);
// Avoid disabling when dependencies have been manually set,
// workaround for framework bug http://b/2053751
if (bluetoothAllowed) {
mCheckBoxPreference.setEnabled(true);
} else if (!hasDependency) {
mCheckBoxPreference.setEnabled(false);
}
} else if (state == BluetoothAdapter.STATE_TURNING_ON ||
@@ -139,22 +142,21 @@ public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
}
}
private boolean isEnabledByDependency() {
Preference dep = getDependencyPreference();
if (dep == null) {
private static boolean isBluetoothAllowed(Context context) {
// allowed if we are not in airplane mode
if (!AirplaneModeEnabler.isAirplaneModeOn(context)) {
return true;
}
return !dep.shouldDisableDependents();
// allowed if bluetooth 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_BLUETOOTH)) {
return true;
}
private Preference getDependencyPreference() {
String depKey = mCheckBoxPreference.getDependency();
if (TextUtils.isEmpty(depKey)) {
return null;
}
return mCheckBoxPreference.getPreferenceManager().findPreference(depKey);
// allowed if bluetooth 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_BLUETOOTH));
}
}

View File

@@ -123,7 +123,16 @@ public class WifiEnabler implements Preference.OnPreferenceChangeListener {
mWifiCheckBoxPref
.setSummary(wifiState == WIFI_STATE_DISABLED ? mOriginalSummary : null);
mWifiCheckBoxPref.setEnabled(isWifiAllowed(mContext));
final boolean hasDependency = !TextUtils.isEmpty(mWifiCheckBoxPref.getDependency());
final boolean wifiAllowed = isWifiAllowed(mContext);
// Avoid disabling when dependencies have been manually set,
// workaround for framework bug http://b/2053751
if (wifiAllowed) {
mWifiCheckBoxPref.setEnabled(true);
} else if (!hasDependency) {
mWifiCheckBoxPref.setEnabled(false);
}
} else if (wifiState == WIFI_STATE_DISABLING || wifiState == WIFI_STATE_ENABLING) {
mWifiCheckBoxPref.setSummary(wifiState == WIFI_STATE_ENABLING ? R.string.wifi_starting