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

Commit 5d43e09d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Avoid Bluetooth gets turned on by enableBle" into sc-qpr1-dev am: 2195d444 am: d3c04e2b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15771372

Change-Id: I734d449afaed4a862d189b15dc7341026f81d8ba
parents 4e3a00ab d3c04e2b
Loading
Loading
Loading
Loading
+35 −13
Original line number Diff line number Diff line
@@ -186,8 +186,6 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
    private final ReentrantReadWriteLock mBluetoothLock = new ReentrantReadWriteLock();
    private boolean mBinding;
    private boolean mUnbinding;
    private int mWaitForEnableRetry;
    private int mWaitForDisableRetry;

    private BluetoothModeChangeHelper mBluetoothModeChangeHelper;

@@ -956,14 +954,15 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
        if (mState == BluetoothAdapter.STATE_ON
                || mState == BluetoothAdapter.STATE_BLE_ON
                || mState == BluetoothAdapter.STATE_TURNING_ON
                || mState == BluetoothAdapter.STATE_TURNING_OFF) {
            Log.d(TAG, "enableBLE(): Bluetooth already enabled");
                || mState == BluetoothAdapter.STATE_TURNING_OFF
                || mState == BluetoothAdapter.STATE_BLE_TURNING_ON) {
            Log.d(TAG, "enableBLE(): Bluetooth is already enabled or is turning on");
            return true;
        }
        synchronized (mReceiver) {
            // waive WRITE_SECURE_SETTINGS permission check
            sendEnableMsg(false,
                    BluetoothProtoEnums.ENABLE_DISABLE_REASON_APPLICATION_REQUEST, packageName);
            sendEnableMsg(false, BluetoothProtoEnums.ENABLE_DISABLE_REASON_APPLICATION_REQUEST,
                    packageName, true);
        }
        return true;
    }
@@ -1776,6 +1775,8 @@ class BluetoothManagerService extends IBluetoothManager.Stub {

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

        BluetoothHandler(Looper looper) {
            super(looper);
@@ -1826,11 +1827,12 @@ class BluetoothManagerService extends IBluetoothManager.Stub {

                case MESSAGE_ENABLE:
                    int quietEnable = msg.arg1;
                    int isBle  = msg.arg2;
                    if (mHandler.hasMessages(MESSAGE_HANDLE_DISABLE_DELAYED)
                            || mHandler.hasMessages(MESSAGE_HANDLE_ENABLE_DELAYED)) {
                        // We are handling enable or disable right now, wait for it.
                        mHandler.sendMessageDelayed(mHandler.obtainMessage(MESSAGE_ENABLE,
                                quietEnable, 0), ENABLE_DISABLE_DELAY_MS);
                                quietEnable, isBle), ENABLE_DISABLE_DELAY_MS);
                        break;
                    }

@@ -1845,13 +1847,28 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                    try {
                        mBluetoothLock.readLock().lock();
                        if (mBluetooth != null) {
                            boolean isHandled = true;
                            int state = mBluetooth.getState();
                            if (state == BluetoothAdapter.STATE_BLE_ON) {
                            switch (state) {
                                case BluetoothAdapter.STATE_BLE_ON:
                                    if (isBle == 1) {
                                        Slog.i(TAG, "Already at BLE_ON State");
                                    } else {
                                        Slog.w(TAG, "BT Enable in BLE_ON State, going to ON");
                                        mBluetooth.onLeServiceUp(mContext.getAttributionSource());
                                        persistBluetoothSetting(BLUETOOTH_ON_BLUETOOTH);
                                    }
                                    break;
                                case BluetoothAdapter.STATE_BLE_TURNING_ON:
                                case BluetoothAdapter.STATE_TURNING_ON:
                                case BluetoothAdapter.STATE_ON:
                                    Slog.i(TAG, "MESSAGE_ENABLE: already enabled");
                                    break;
                                default:
                                    isHandled = false;
                                    break;
                            }
                            if (isHandled) break;
                        }
                    } catch (RemoteException e) {
                        Slog.e(TAG, "", e);
@@ -2617,7 +2634,12 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
    }

    private void sendEnableMsg(boolean quietMode, int reason, String packageName) {
        mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_ENABLE, quietMode ? 1 : 0, 0));
        sendEnableMsg(quietMode, reason, packageName, false);
    }

    private void sendEnableMsg(boolean quietMode, int reason, String packageName, boolean isBle) {
        mHandler.sendMessage(mHandler.obtainMessage(MESSAGE_ENABLE, quietMode ? 1 : 0,
                  isBle ? 1 : 0));
        addActiveLog(reason, packageName, true);
        mLastEnabledTime = SystemClock.elapsedRealtime();
    }