Bluetooth: prevent enabling BLE in airplane mode

Enabling BLE in airplane mode puts BluetoothManagerService in an
unexpected state which causes Bluetooth to be on when airplane mode
is disabled.

Also fixes a bug where a crash of a BLE client would trigger a restart
into ON mode.

Test: SL4A BleBackgroundScanTest:test_airplane_mode_disables_ble

Bug: 32140251
Bug: 32140271
Bug: 32369494

Change-Id: Ie65157e65c3a1ca914f567a7a0c631175d1e5835
(cherry picked from commit bd93b7b3dc6141cef6236cf0ca7dcc5acf5bfeed)
This commit is contained in:
Marie Janssen
2016-10-25 10:47:51 -07:00
parent e9db00e39f
commit a80d745c65
2 changed files with 13 additions and 13 deletions

View File

@@ -765,19 +765,13 @@ public final class BluetoothAdapter {
public boolean enableBLE() { public boolean enableBLE() {
if (!isBleScanAlwaysAvailable()) return false; if (!isBleScanAlwaysAvailable()) return false;
if (isLeEnabled() == true) {
if (DBG) Log.d(TAG, "enableBLE(): BT is already enabled..!");
try { try {
mManagerService.updateBleAppCount(mToken, true); mManagerService.updateBleAppCount(mToken, true);
} catch (RemoteException e) { if (isLeEnabled()) {
Log.e(TAG, "", e); if (DBG) Log.d(TAG, "enableBLE(): Bluetooth already enabled");
}
return true; return true;
} }
if (DBG) Log.d(TAG, "enableBLE(): Calling enable");
try {
if (DBG) Log.d(TAG, "Calling enableBLE");
mManagerService.updateBleAppCount(mToken, true);
return mManagerService.enable(); return mManagerService.enable();
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(TAG, "", e); Log.e(TAG, "", e);

View File

@@ -217,6 +217,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
mBluetoothLock.readLock().lock(); mBluetoothLock.readLock().lock();
if (mBluetooth != null) { if (mBluetooth != null) {
mBluetooth.onBrEdrDown(); mBluetooth.onBrEdrDown();
mEnable = false;
mEnableExternal = false; mEnableExternal = false;
} }
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -456,7 +457,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
if (DBG) Slog.d(TAG, "Disabling LE only mode after application crash"); if (DBG) Slog.d(TAG, "Disabling LE only mode after application crash");
try { try {
mBluetoothLock.readLock().lock(); mBluetoothLock.readLock().lock();
if (mBluetooth != null) { if (mBluetooth != null &&
mBluetooth.getState() == BluetoothAdapter.STATE_BLE_ON) {
mEnable = false;
mBluetooth.onBrEdrDown(); mBluetooth.onBrEdrDown();
} }
} catch (RemoteException e) { } catch (RemoteException e) {
@@ -473,6 +476,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
@Override @Override
public boolean isBleScanAlwaysAvailable() { public boolean isBleScanAlwaysAvailable() {
if (isAirplaneModeOn() && !mEnable) {
return false;
}
try { try {
return (Settings.Global.getInt(mContentResolver, return (Settings.Global.getInt(mContentResolver,
Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE)) != 0; Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE)) != 0;