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

Commit fc5884ba authored by William Escande's avatar William Escande
Browse files

SystemServer: DISABLE_MESSAGE handle in function

Having a separate method allow to be called without using the handler.
This will be used by the messenger

Bug: 288450479
Bug: 321804999
Test: m service-bluetooth | No-op Change
Change-Id: I5b291b5eda16f33ab25b60e9675b4f1e900392f6
parent e26529a5
Loading
Loading
Loading
Loading
+23 −18
Original line number Diff line number Diff line
@@ -1436,11 +1436,11 @@ class BluetoothManagerService {

    private BluetoothServiceConnection mConnection = new BluetoothServiceConnection();
    private int mWaitForEnableRetry;
    private int mWaitForDisableRetry;

    @VisibleForTesting
    class BluetoothHandler extends Handler {
        boolean mGetNameAddressOnly = false;
        private int mWaitForDisableRetry;

        BluetoothHandler(Looper looper) {
            super(looper);
@@ -1498,24 +1498,8 @@ class BluetoothManagerService {

                case MESSAGE_DISABLE:
                    Log.d(TAG, "MESSAGE_DISABLE: mAdapter=" + mAdapter);
                    if (mHandler.hasMessages(MESSAGE_HANDLE_DISABLE_DELAYED)
                            || isBinding()
                            || mHandler.hasMessages(MESSAGE_HANDLE_ENABLE_DELAYED)) {
                        // We are handling enable or disable right now, wait for it.
                        mHandler.sendEmptyMessageDelayed(MESSAGE_DISABLE, ENABLE_DISABLE_DELAY_MS);
                        break;
                    }

                    mHandler.removeMessages(MESSAGE_RESTART_BLUETOOTH_SERVICE);

                    if (mEnable && mAdapter != null) {
                        mWaitForDisableRetry = 0;
                        mHandler.sendEmptyMessageDelayed(
                                MESSAGE_HANDLE_DISABLE_DELAYED, ENABLE_DISABLE_DELAY_MS);
                    } else {
                        mEnable = false;
                        handleDisable();
                    }
                    handleDisableMessage();
                    break;

                case MESSAGE_HANDLE_ENABLE_DELAYED:
@@ -1959,6 +1943,27 @@ class BluetoothManagerService {
        }
    }

    private void handleDisableMessage() {
        if (mHandler.hasMessages(MESSAGE_HANDLE_DISABLE_DELAYED)
                || isBinding()
                || mHandler.hasMessages(MESSAGE_HANDLE_ENABLE_DELAYED)) {
            // We are handling enable or disable right now, wait for it.
            mHandler.sendEmptyMessageDelayed(MESSAGE_DISABLE, ENABLE_DISABLE_DELAY_MS);
            return;
        }

        mHandler.removeMessages(MESSAGE_RESTART_BLUETOOTH_SERVICE);

        if (mEnable && mAdapter != null) {
            mWaitForDisableRetry = 0;
            mHandler.sendEmptyMessageDelayed(
                    MESSAGE_HANDLE_DISABLE_DELAYED, ENABLE_DISABLE_DELAY_MS);
        } else {
            mEnable = false;
            handleDisable();
        }
    }

    @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)
    private void handleEnable(boolean quietMode) {
        mQuietEnable = quietMode;