From c2b062263402c7ada36fe84ee1ed9b5bb1bbefbd Mon Sep 17 00:00:00 2001 From: Martin Brabham Date: Mon, 27 Feb 2017 16:55:07 -0800 Subject: [PATCH] BluetoothManagerService: continue teardown when BLE apps registered When the adapter is toggled off; when there are BLE apps registered, a request is sent to unregister all of the BLE apps. Upon unregister each app will call through to this function via a callback. When this gets called if the ble app count is 0, we can disable everything. I am keeping track of the flag so that we know explicitly where we are coming from. Bug: 34707848 Test: Compile Change-Id: I9a8322a6fa918e7b410770894c257ec9f7d8d1f5 --- .../server/BluetoothManagerService.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/BluetoothManagerService.java b/services/core/java/com/android/server/BluetoothManagerService.java index aff98edf58617..5e9cf7481822e 100644 --- a/services/core/java/com/android/server/BluetoothManagerService.java +++ b/services/core/java/com/android/server/BluetoothManagerService.java @@ -638,6 +638,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub { if (appCount == 0 && mEnable) { disableBleScanMode(); } + if (appCount == 0 && !mEnableExternal) { + sendBrEdrDownCallback(); + } return appCount; } @@ -693,7 +696,14 @@ class BluetoothManagerService extends IBluetoothManager.Stub { return; } - if (isBleAppPresent() == false) { + if (isBleAppPresent()) { + // Need to stay at BLE ON. Disconnect all Gatt connections + try { + mBluetoothGatt.unregAll(); + } catch (RemoteException e) { + Slog.e(TAG, "Unable to disconnect all apps.", e); + } + } else { try { mBluetoothLock.readLock().lock(); if (mBluetooth != null) mBluetooth.onBrEdrDown(); @@ -702,14 +712,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub { } finally { mBluetoothLock.readLock().unlock(); } - } else { - // Need to stay at BLE ON. Disconnect all Gatt connections - try { - mBluetoothGatt.unregAll(); - } catch (RemoteException e) { - Slog.e(TAG, "Unable to disconnect all apps.", e); - } } + } public boolean enableNoAutoConnect(String packageName)