From 2d006b8a24d6ac043ece40c4dcff0cf3ab61323c Mon Sep 17 00:00:00 2001 From: jonerlin Date: Thu, 9 Aug 2018 16:39:43 +0800 Subject: AdapterService: Only bind HeadsetService in ON state. * there will be an endless loop to call doBind and cause many connectionRecords of HeadsetService while binding HeadsetService in BLE_ON state. * allow to bind HeadsetService only when BT state is ON Bug: 111730478 Test: Keep device in BLE_ON state -> kill com.android.phone process -> As time goes on, adb shell dumpsys activity services to check the connectionRecords of HeadsetService will not become more and more Change-Id: I5f66d015b8aa3c94c7e887ef033213af74235b4a --- .../server/bluetooth/BluetoothManagerService.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (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 aa426d3cd3..99e0056254 100644 --- a/service/java/com/android/server/bluetooth/BluetoothManagerService.java +++ b/service/java/com/android/server/bluetooth/BluetoothManagerService.java @@ -1161,6 +1161,26 @@ class BluetoothManagerService extends IBluetoothManager.Stub { } private boolean bindService() { + int state = BluetoothAdapter.STATE_OFF; + try { + mBluetoothLock.readLock().lock(); + if (mBluetooth != null) { + state = mBluetooth.getState(); + } + } catch (RemoteException e) { + Slog.e(TAG, "Unable to call getState", e); + return false; + } finally { + mBluetoothLock.readLock().unlock(); + } + + if (!mEnable || state != BluetoothAdapter.STATE_ON) { + if (DBG) { + Slog.d(TAG, "Unable to bindService while Bluetooth is disabled"); + } + return false; + } + if (mIntent != null && mService == null && doBind(mIntent, this, 0, UserHandle.CURRENT_OR_SELF)) { Message msg = mHandler.obtainMessage(MESSAGE_BIND_PROFILE_SERVICE); -- cgit v1.2.3