Skip to content

Commit 4e22ad3

Browse files
author
Zhihai Xu
committed
Settings shows it is connected to A2DP, though the device is not actually connected
the root cause is the A2dp and Pbap service need receive STATE_TURNING_OFF intent to shutdown cleanly. So we need send completely state transition intents in user switch handler. bug7403171 Change-Id: Ic92bc85c2b74ae7c95440b237ea8851771ee9f04
1 parent eb3aa44 commit 4e22ad3

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

services/java/com/android/server/BluetoothManagerService.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -775,8 +775,18 @@ public void handleMessage(Message msg) {
775775

776776
// Send BT state broadcast to update
777777
// the BT icon correctly
778-
bluetoothStateChangeHandler(BluetoothAdapter.STATE_ON,
779-
BluetoothAdapter.STATE_TURNING_OFF);
778+
if ((mState == BluetoothAdapter.STATE_TURNING_ON) ||
779+
(mState == BluetoothAdapter.STATE_ON)) {
780+
bluetoothStateChangeHandler(BluetoothAdapter.STATE_ON,
781+
BluetoothAdapter.STATE_TURNING_OFF);
782+
mState = BluetoothAdapter.STATE_TURNING_OFF;
783+
}
784+
if (mState == BluetoothAdapter.STATE_TURNING_OFF) {
785+
bluetoothStateChangeHandler(BluetoothAdapter.STATE_TURNING_OFF,
786+
BluetoothAdapter.STATE_OFF);
787+
}
788+
789+
mHandler.removeMessages(MESSAGE_BLUETOOTH_STATE_CHANGE);
780790
mState = BluetoothAdapter.STATE_OFF;
781791
}
782792
break;
@@ -820,20 +830,33 @@ public void handleMessage(Message msg) {
820830
}
821831
}
822832
}
823-
mHandler.removeMessages(MESSAGE_BLUETOOTH_STATE_CHANGE);
833+
834+
if (mState == BluetoothAdapter.STATE_TURNING_OFF) {
835+
// MESSAGE_USER_SWITCHED happened right after MESSAGE_ENABLE
836+
bluetoothStateChangeHandler(mState, BluetoothAdapter.STATE_OFF);
837+
mState = BluetoothAdapter.STATE_OFF;
838+
}
839+
if (mState == BluetoothAdapter.STATE_OFF) {
840+
bluetoothStateChangeHandler(mState, BluetoothAdapter.STATE_TURNING_ON);
841+
mState = BluetoothAdapter.STATE_TURNING_ON;
842+
}
824843

825844
waitForOnOff(true, false);
826845

827-
bluetoothStateChangeHandler(mState, BluetoothAdapter.STATE_ON);
846+
if (mState == BluetoothAdapter.STATE_TURNING_ON) {
847+
bluetoothStateChangeHandler(mState, BluetoothAdapter.STATE_ON);
848+
}
828849

829850
// disable
830851
handleDisable(false);
852+
// Pbap service need receive STATE_TURNING_OFF intent to close
853+
bluetoothStateChangeHandler(BluetoothAdapter.STATE_ON,
854+
BluetoothAdapter.STATE_TURNING_OFF);
831855

832856
waitForOnOff(false, true);
833857

834-
bluetoothStateChangeHandler(BluetoothAdapter.STATE_ON,
858+
bluetoothStateChangeHandler(BluetoothAdapter.STATE_TURNING_OFF,
835859
BluetoothAdapter.STATE_OFF);
836-
mState = BluetoothAdapter.STATE_OFF;
837860
sendBluetoothServiceDownCallback();
838861
synchronized (mConnection) {
839862
if (mBluetooth != null) {
@@ -844,6 +867,8 @@ public void handleMessage(Message msg) {
844867
}
845868
SystemClock.sleep(100);
846869

870+
mHandler.removeMessages(MESSAGE_BLUETOOTH_STATE_CHANGE);
871+
mState = BluetoothAdapter.STATE_OFF;
847872
// enable
848873
handleEnable(false, mQuietEnable);
849874
} else if (mBinding || mBluetooth != null) {

0 commit comments

Comments
 (0)