Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0eab112f authored by YK Jeffrey Chao's avatar YK Jeffrey Chao Committed by Matthew Xie
Browse files

Preload timeout and retry mechanism (2/3)

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
parent 63f1cc4e
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -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;
}

+10 −1
Original line number Diff line number Diff line
@@ -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()) {