OSDN Git Service

Preload timeout and retry mechanism (2/3)
authorYK Jeffrey Chao <jechao@broadcom.com>
Wed, 24 Apr 2013 18:55:23 +0000 (11:55 -0700)
committerMatthew Xie <mattx@google.com>
Fri, 10 May 2013 07:29:11 +0000 (00:29 -0700)
If the Preload process was stuck due to unknown hardware init failure,
a 8-second ENABLE_TIMEOUT timeout would be eventually expired in Java layer
at AdapterState and attempted to set BT state back to STATE_OFF.
However BluetoothManagerService did not handle this case accordingly and led
to state mis-matching between Java layer and BTIF at the end.

Add the processing logic in AdapterState to handle the case when an explicit
STATE_OFF notification from BTIF was received in the TurningOn Pending state.

bug  7566317

Change-Id: I29c379cd453d05297ed382a5e8f862fa7d0f8881

jni/com_android_bluetooth_btservice_AdapterService.cpp
src/com/android/bluetooth/btservice/AdapterState.java

index 310dcea..11c19fc 100644 (file)
@@ -570,7 +570,11 @@ static jboolean disableNative(JNIEnv* env, jobject obj) {
     if (!sBluetoothInterface) return result;
 
     int ret = sBluetoothInterface->disable();
-    result = (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
+    /* Retrun JNI_FALSE only when BTIF explicitly reports
+       BT_STATUS_FAIL. It is fine for the BT_STATUS_NOT_READY
+       case which indicates that stack had not been enabled.
+    */
+    result = (ret == BT_STATUS_FAIL) ? JNI_FALSE : JNI_TRUE;
     return result;
 }
 
index fbc32a5..108c055 100755 (executable)
@@ -258,7 +258,7 @@ final class AdapterState extends StateMachine {
                      Log.w(TAG,"Timeout will setting scan mode..Continuing with disable...");
                      //Fall through
                 case BEGIN_DISABLE: {
-                    if (DBG) Log.d(TAG,"CURRENT_STATE=PENDING, MESSAGE = BEGIN_DISABLE" + isTurningOn + ", isTurningOff=" + isTurningOff);
+                    if (DBG) Log.d(TAG,"CURRENT_STATE=PENDING, MESSAGE = BEGIN_DISABLE, isTurningOn=" + isTurningOn + ", isTurningOff=" + isTurningOff);
                     removeMessages(SET_SCAN_MODE_TIMEOUT);
                     sendMessageDelayed(DISABLE_TIMEOUT, DISABLE_TIMEOUT_DELAY);
                     boolean ret = mAdapterService.disableNative();
@@ -273,6 +273,15 @@ final class AdapterState extends StateMachine {
                     break;
                 case DISABLED:
                     if (DBG) Log.d(TAG,"CURRENT_STATE=PENDING, MESSAGE = DISABLED, isTurningOn=" + isTurningOn + ", isTurningOff=" + isTurningOff);
+                    if (isTurningOn) {
+                        removeMessages(ENABLE_TIMEOUT);
+                        errorLog("Error enabling Bluetooth - hardware init failed");
+                        mPendingCommandState.setTurningOn(false);
+                        transitionTo(mOffState);
+                        mAdapterService.stopProfileServices();
+                        notifyAdapterStateChange(BluetoothAdapter.STATE_OFF);
+                        break;
+                    }
                     removeMessages(DISABLE_TIMEOUT);
                     sendMessageDelayed(STOP_TIMEOUT, STOP_TIMEOUT_DELAY);
                     if (mAdapterService.stopProfileServices()) {