From f7065dc95213df91e631eb7689e25cc5f4378476 Mon Sep 17 00:00:00 2001 From: Ugo Yu Date: Tue, 26 May 2020 13:28:38 +0800 Subject: [PATCH] Disable Bluetooth if BLE was disabled while enabling * Call onBrEdrDown if BLE app count is 0 when entering BLE_ON state and the Bluetooth ON was triggered via enableBle(). This fixes an issue that Bluetooth automatically turns ON if gms calls enableBle() then disableBle() in a short time. * Fix a deadlock bug that acquires writeLock in a readLock. Bug: 153767389 Bug: 155950370 Test: Manual Change-Id: I4f92581465de81ffe9b45fb042b5cc43e5ab4136 --- .../com/android/server/BluetoothManagerService.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/services/core/java/com/android/server/BluetoothManagerService.java b/services/core/java/com/android/server/BluetoothManagerService.java index 192ea72224b1a..249e376b52557 100644 --- a/services/core/java/com/android/server/BluetoothManagerService.java +++ b/services/core/java/com/android/server/BluetoothManagerService.java @@ -957,7 +957,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub { } /** - * Call IBluetooth.onLeServiceUp() to continue if Bluetooth should be on. + * Call IBluetooth.onLeServiceUp() to continue if Bluetooth should be on, + * call IBluetooth.onBrEdrDown() to disable if Bluetooth should be off. */ private void continueFromBleOnState() { if (DBG) { @@ -969,11 +970,10 @@ class BluetoothManagerService extends IBluetoothManager.Stub { Slog.e(TAG, "onBluetoothServiceUp: mBluetooth is null!"); return; } - if (!mEnableExternal && !isBleAppPresent() && isAirplaneModeOn()) { - // Airplane mode is turned on while enabling BLE only mode, disable - // BLE now. - disableBleScanMode(); - sendBrEdrDownCallback(); + if (!mEnableExternal && !isBleAppPresent()) { + Slog.i(TAG, "Bluetooth was disabled while enabling BLE, disable BLE now"); + mEnable = false; + mBluetooth.onBrEdrDown(); return; } if (isBluetoothPersistedStateOnBluetooth() || !isBleAppPresent()) {