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:
@@ -44,14 +44,12 @@
|
|||||||
android:key="toggle_bluetooth"
|
android:key="toggle_bluetooth"
|
||||||
android:title="@string/bluetooth_quick_toggle_title"
|
android:title="@string/bluetooth_quick_toggle_title"
|
||||||
android:summary="@string/bluetooth_quick_toggle_summary"
|
android:summary="@string/bluetooth_quick_toggle_summary"
|
||||||
android:persistent="false"
|
android:persistent="false" />
|
||||||
android:dependency="toggle_airplane" />
|
|
||||||
|
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
android:key="bt_settings"
|
android:key="bt_settings"
|
||||||
android:title="@string/bluetooth_settings_title"
|
android:title="@string/bluetooth_settings_title"
|
||||||
android:summary="@string/bluetooth_settings_summary"
|
android:summary="@string/bluetooth_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"
|
||||||
|
@@ -107,12 +107,12 @@ public class WirelessSettings extends PreferenceActivity {
|
|||||||
Preference wifiPreference = findPreference(KEY_TOGGLE_WIFI);
|
Preference wifiPreference = findPreference(KEY_TOGGLE_WIFI);
|
||||||
Preference btPreference = findPreference(KEY_TOGGLE_BLUETOOTH);
|
Preference btPreference = findPreference(KEY_TOGGLE_BLUETOOTH);
|
||||||
Preference wifiSettings = findPreference(KEY_WIFI_SETTINGS);
|
Preference wifiSettings = findPreference(KEY_WIFI_SETTINGS);
|
||||||
|
Preference btSettings = findPreference(KEY_BT_SETTINGS);
|
||||||
Preference vpnSettings = findPreference(KEY_VPN_SETTINGS);
|
Preference vpnSettings = findPreference(KEY_VPN_SETTINGS);
|
||||||
|
|
||||||
IBinder b = ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE);
|
IBinder b = ServiceManager.getService(BluetoothAdapter.BLUETOOTH_SERVICE);
|
||||||
if (b == null) {
|
if (b == null) {
|
||||||
// Disable BT Settings if BT service is not available.
|
// Disable BT Settings if BT service is not available.
|
||||||
Preference btSettings = findPreference(KEY_BT_SETTINGS);
|
|
||||||
btSettings.setEnabled(false);
|
btSettings.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,6 +131,13 @@ public class WirelessSettings extends PreferenceActivity {
|
|||||||
wifiSettings.setDependency(airplanePreference.getKey());
|
wifiSettings.setDependency(airplanePreference.getKey());
|
||||||
vpnSettings.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
|
@Override
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.bluetooth;
|
package com.android.settings.bluetooth;
|
||||||
|
|
||||||
|
import com.android.settings.AirplaneModeEnabler;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
@@ -25,6 +26,7 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
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;
|
||||||
|
|
||||||
@@ -116,14 +118,15 @@ public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
|
|||||||
mOriginalSummary :
|
mOriginalSummary :
|
||||||
null);
|
null);
|
||||||
|
|
||||||
/*
|
final boolean hasDependency = !TextUtils.isEmpty(mCheckBoxPreference.getDependency());
|
||||||
* Don't ever disable the preference. Only enable here. Disablement
|
final boolean bluetoothAllowed = isBluetoothAllowed(mContext);
|
||||||
* is taken care of by the dependency code. If this is disabled
|
|
||||||
* here, it may not be re-enabled from the framework when dependency
|
// Avoid disabling when dependencies have been manually set,
|
||||||
* is met. http://b/issue?id=2053751
|
// workaround for framework bug http://b/2053751
|
||||||
*/
|
if (bluetoothAllowed) {
|
||||||
if (isEnabledByDependency()) {
|
|
||||||
mCheckBoxPreference.setEnabled(true);
|
mCheckBoxPreference.setEnabled(true);
|
||||||
|
} else if (!hasDependency) {
|
||||||
|
mCheckBoxPreference.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (state == BluetoothAdapter.STATE_TURNING_ON ||
|
} else if (state == BluetoothAdapter.STATE_TURNING_ON ||
|
||||||
@@ -139,22 +142,21 @@ public class BluetoothEnabler implements Preference.OnPreferenceChangeListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isEnabledByDependency() {
|
private static boolean isBluetoothAllowed(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 bluetooth 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_BLUETOOTH)) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
// allowed if bluetooth is in AIRPLANE_MODE_TOGGLEABLE_RADIOS
|
||||||
private Preference getDependencyPreference() {
|
radios = Settings.System.getString(context.getContentResolver(),
|
||||||
String depKey = mCheckBoxPreference.getDependency();
|
Settings.System.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
|
||||||
if (TextUtils.isEmpty(depKey)) {
|
return (radios != null && radios.contains(Settings.System.RADIO_BLUETOOTH));
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return mCheckBoxPreference.getPreferenceManager().findPreference(depKey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -123,7 +123,16 @@ public class WifiEnabler implements Preference.OnPreferenceChangeListener {
|
|||||||
mWifiCheckBoxPref
|
mWifiCheckBoxPref
|
||||||
.setSummary(wifiState == WIFI_STATE_DISABLED ? mOriginalSummary : null);
|
.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) {
|
} 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
|
||||||
|
Reference in New Issue
Block a user