From 7d1203a2f4fdbafe26d33421c3cdd83f07a5fba8 Mon Sep 17 00:00:00 2001 From: Ram Periathiruvadi Date: Wed, 3 May 2017 19:11:20 -0700 Subject: [PATCH] Fix for Bluetooth not restarting on User Switch The flag that keeps track of the Bluetooth adapter status(mEnable) is not guarded correctly and could go out of sync with the adapter status. This causes User Switch handling to not function correctly since it checks for the status of the mEnable flag before restarting Bluetooth. This fix queries the Bluetooth Adapter for the status instead of using the mEnable flag. Bug: b/37648701 Test: Tested switching users multiple times in both phone and carkit. Also tested pairing and connection for sanity. Change-Id: I17facecf8e1de90df11c11d5b0a184f48a0356e4 --- .../core/java/com/android/server/BluetoothManagerService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/BluetoothManagerService.java b/services/core/java/com/android/server/BluetoothManagerService.java index 5a3c7d0aef31c..ba1befdf81753 100644 --- a/services/core/java/com/android/server/BluetoothManagerService.java +++ b/services/core/java/com/android/server/BluetoothManagerService.java @@ -1699,7 +1699,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub { mHandler.removeMessages(MESSAGE_USER_SWITCHED); /* disable and enable BT when detect a user switch */ - if (mEnable && mBluetooth != null) { + if (mBluetooth != null && isEnabled()) { try { mBluetoothLock.readLock().lock(); if (mBluetooth != null) { @@ -1768,6 +1768,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub { mState = BluetoothAdapter.STATE_OFF; // enable addActiveLog(REASON_USER_SWITCH, true); + // mEnable flag could have been reset on disableBLE. Reenable it. + mEnable = true; handleEnable(mQuietEnable); } else if (mBinding || mBluetooth != null) { Message userMsg = mHandler.obtainMessage(MESSAGE_USER_SWITCHED);