Terminate PBAP service cleanly during BT off
PBAP service runs in a loop of 10 trials to create the RFCOMM listener
thread; this loop is not getting interrupted during BT off, due to which
we end up delaying PBAP stop by 3 seconds (10 * 300ms). The fix is to
check for BT state after RFCOMM listener failure and break out of the
loop if BT is being turned off.
bug 7134544
Change-Id: I35db2221be30980bec973253cdd888e0ce8cc36b
diff --git a/src/com/android/bluetooth/pbap/BluetoothPbapService.java b/src/com/android/bluetooth/pbap/BluetoothPbapService.java
index 80cd8ee..21714c8 100755
--- a/src/com/android/bluetooth/pbap/BluetoothPbapService.java
+++ b/src/com/android/bluetooth/pbap/BluetoothPbapService.java
@@ -347,6 +347,14 @@
initSocketOK = false;
}
if (!initSocketOK) {
+ // Need to break out of this loop if BT is being turned off.
+ if (mAdapter == null) break;
+ int state = mAdapter.getState();
+ if ((mAdapter.getState() != BluetoothAdapter.STATE_TURNING_ON) &&
+ (mAdapter.getState() != BluetoothAdapter.STATE_ON)) {
+ Log.w(TAG, "initServerSocket failed as BT is (being) turned off");
+ break;
+ }
synchronized (this) {
try {
if (VERBOSE) Log.v(TAG, "wait 300 ms");