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

Commit 257f8fe8 authored by Marie Janssen's avatar Marie Janssen
Browse files

Bluetooth: prevent enabling BLE in airplane mode

Enabling BLE in airplane mode puts BluetoothManagerService in an
unexpected state which causes Bluetooth to be on when airplane mode
is disabled.

Also fixes a bug where a crash of a BLE client would trigger a restart
into ON mode.

Test: SL4A BleBackgroundScanTest:test_airplane_mode_disables_ble

Bug: 32140251
Bug: 32140271
Bug: 32369494

Change-Id: Ie65157e65c3a1ca914f567a7a0c631175d1e5835
parent a0f9afe1
Loading
Loading
Loading
Loading
+5 −11
Original line number Diff line number Diff line
@@ -786,19 +786,13 @@ public final class BluetoothAdapter {
    public boolean enableBLE() {
        if (!isBleScanAlwaysAvailable()) return false;

        if (isLeEnabled() == true) {
            if (DBG) Log.d(TAG, "enableBLE(): BT is already enabled..!");
        try {
            mManagerService.updateBleAppCount(mToken, true);
            } catch (RemoteException e) {
                Log.e(TAG, "", e);
            }
            if (isLeEnabled()) {
                if (DBG) Log.d(TAG, "enableBLE(): Bluetooth already enabled");
                return true;
            }

        try {
            if (DBG) Log.d(TAG, "Calling enableBLE");
            mManagerService.updateBleAppCount(mToken, true);
            if (DBG) Log.d(TAG, "enableBLE(): Calling enable");
            return mManagerService.enable(ActivityThread.currentPackageName());
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
+8 −2
Original line number Diff line number Diff line
@@ -221,6 +221,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                                mBluetoothLock.readLock().lock();
                                if (mBluetooth != null) {
                                    mBluetooth.onBrEdrDown();
                                    mEnable = false;
                                    mEnableExternal = false;
                                }
                            } catch (RemoteException e) {
@@ -443,7 +444,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                if (DBG) Slog.d(TAG, "Disabling LE only mode after application crash");
                try {
                    mBluetoothLock.readLock().lock();
                    if (mBluetooth != null) {
                    if (mBluetooth != null &&
                        mBluetooth.getState() == BluetoothAdapter.STATE_BLE_ON) {
                        mEnable = false;
                        mBluetooth.onBrEdrDown();
                    }
                } catch (RemoteException e) {
@@ -460,6 +463,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub {

    @Override
    public boolean isBleScanAlwaysAvailable() {
        if (isAirplaneModeOn() && !mEnable) {
            return false;
        }
        try {
            return (Settings.Global.getInt(mContentResolver,
                    Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE)) != 0;