From 257f8fe85e626e8741ae626228214c2c34390aea Mon Sep 17 00:00:00 2001 From: Marie Janssen Date: Tue, 25 Oct 2016 10:47:51 -0700 Subject: 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 --- .../com/android/server/bluetooth/BluetoothManagerService.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'service/java/com/android/server/bluetooth/BluetoothManagerService.java') diff --git a/service/java/com/android/server/bluetooth/BluetoothManagerService.java b/service/java/com/android/server/bluetooth/BluetoothManagerService.java index 7875cb86ee..2a5b1946b9 100644 --- a/service/java/com/android/server/bluetooth/BluetoothManagerService.java +++ b/service/java/com/android/server/bluetooth/BluetoothManagerService.java @@ -221,6 +221,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { mBluetoothLock.readLock().lock(); if (mBluetooth != null) { mBluetooth.onBrEdrDown(); + mEnable = false; mEnableExternal = false; } } catch (RemoteException e) { @@ -436,14 +437,16 @@ class BluetoothManagerService extends IBluetoothManager.Stub { class ClientDeathRecipient implements IBinder.DeathRecipient { public void binderDied() { - if (DBG) Slog.d(TAG, "Binder is dead - unregister Ble App"); + if (DBG) Slog.d(TAG, "Binder is dead - unregister Ble App"); if (mBleAppCount > 0) --mBleAppCount; if (mBleAppCount == 0) { if (DBG) Slog.d(TAG, "Disabling LE only mode after application crash"); try { mBluetoothLock.readLock().lock(); - if (mBluetooth != null) { + if (mBluetooth != null && + mBluetooth.getState() == BluetoothAdapter.STATE_BLE_ON) { + mEnable = false; mBluetooth.onBrEdrDown(); } } catch (RemoteException e) { @@ -460,6 +463,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub { @Override public boolean isBleScanAlwaysAvailable() { + if (isAirplaneModeOn() && !mEnable) { + return false; + } try { return (Settings.Global.getInt(mContentResolver, Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE)) != 0; -- cgit v1.2.3