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

Commit f8efe982 authored by Service qcabuildsw's avatar Service qcabuildsw Committed by Gerrit - the friendly Code Review server
Browse files

Merge "BT: Rectifying recovery functionality in case of timeout scenarios"...

Merge "BT: Rectifying recovery functionality in case of timeout scenarios" into android-framework.lnx.2.0.c1-dev
parents 49a4d2a4 074ae480
Loading
Loading
Loading
Loading
+2 −38
Original line number Diff line number Diff line
@@ -143,7 +143,6 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
    private int mErrorRecoveryRetryCounter;
    private final int mSystemUiUid;
    private boolean mIntentPending = false;
    private int mIBluetoothConnectedMsgQueued = 0;

    private void registerForAirplaneMode(IntentFilter filter) {
        final ContentResolver resolver = mContext.getContentResolver();
@@ -887,9 +886,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                return;
            }
            msg.obj = service;
            boolean sent = mHandler.sendMessage(msg);
            if (sent && (msg.arg1 == SERVICE_IBLUETOOTH))
                mIBluetoothConnectedMsgQueued++;
            mHandler.sendMessage(msg);
        }

        public void onServiceDisconnected(ComponentName className) {
@@ -1063,8 +1060,6 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                            break;
                        } // else must be SERVICE_IBLUETOOTH

                        mIBluetoothConnectedMsgQueued--;

                        //Remove timeout
                        mHandler.removeMessages(MESSAGE_TIMEOUT_BIND);

@@ -1199,7 +1194,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                        mBluetoothLock.writeLock().unlock();
                    }

                    if (mEnable && (mIBluetoothConnectedMsgQueued == 0)) {
                    if (mEnable) {
                        mEnable = false;
                        // Send a Bluetooth Restart message
                        Message restartMsg = mHandler.obtainMessage(
@@ -1642,41 +1637,10 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
            mBluetoothLock.readLock().unlock();
        }

        SystemClock.sleep(500);

        // disable
        handleDisable();

        waitForOnOff(false, true);

        // If there is a MESSAGE_BLUETOOTH_SERVICE_CONNECTED in mHandler queue, we should not
        // unbindService as below. Otherwise, after unbind, com.android.bluetooth will die, but
        // later mBluetooth will be assigned to adapterService in handleMessage of
        // MESSAGE_BLUETOOTH_SERVICE_CONNECTED. From then on, mBluetooth is not null,
        // and com.android.bluetooth is dead, but doBind will not be triggered again.
        if (mIBluetoothConnectedMsgQueued > 0) {
            Slog.e(TAG, "recoverBluetoothServiceFromError: "
                    + "MESSAGE_BLUETOOTH_SERVICE_CONNECTED exists in mHandler queue, "
                    + "should not unbindService, return directly.");
            mHandler.removeMessages(MESSAGE_BLUETOOTH_STATE_CHANGE);
            mState = BluetoothAdapter.STATE_OFF;
            return;
        }

        sendBluetoothServiceDownCallback();

        try {
            mBluetoothLock.writeLock().lock();
            if (mBluetooth != null) {
                mBluetooth = null;
                // Unbind
                mContext.unbindService(mConnection);
            }
            mBluetoothGatt = null;
        } finally {
            mBluetoothLock.writeLock().unlock();
        }

        mHandler.removeMessages(MESSAGE_BLUETOOTH_STATE_CHANGE);
        mState = BluetoothAdapter.STATE_OFF;