OSDN Git Service

Terminate PBAP service cleanly during BT off
authorKausik Sinnaswamy <kausik@broadcom.com>
Mon, 10 Sep 2012 11:41:14 +0000 (17:11 +0530)
committerMatthew Xie <mattx@google.com>
Mon, 10 Sep 2012 19:17:06 +0000 (12:17 -0700)
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

src/com/android/bluetooth/pbap/BluetoothPbapService.java

index 80cd8ee..21714c8 100755 (executable)
@@ -347,6 +347,14 @@ public class BluetoothPbapService extends Service {
                 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");