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

Commit 9a5fa11e authored by William Escande's avatar William Escande
Browse files

SystemServer: Extract airplane turn off logic

Bug: 333097218
Test: m .
Flag: Exempt, no logical change
Change-Id: I285734be6e6a0e78ea1c8e0a62662d398ec218cd
parent ef814a2b
Loading
Loading
Loading
Loading
+29 −25
Original line number Diff line number Diff line
@@ -461,25 +461,7 @@ class BluetoothManagerService {
                0);
    }

    @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
    private void handleAirplaneModeChanged(boolean isAirplaneModeOn) {
        synchronized (this) {
            if (isBluetoothPersistedStateOn()) {
                if (isAirplaneModeOn) {
                    setBluetoothPersistedState(BLUETOOTH_ON_AIRPLANE);
                } else {
                    setBluetoothPersistedState(BLUETOOTH_ON_BLUETOOTH);
                }
            }

            int currentState = mState.get();

            Log.d(
                    TAG,
                    ("handleAirplaneModeChanged(" + isAirplaneModeOn + "):")
                            + (" currentState=" + BluetoothAdapter.nameForState(currentState)));

            if (isAirplaneModeOn) {
    private void forceToOffFromModeChange(int currentState, int reason) {
        // Clear registered LE apps to force shut-off
        clearBleApps();

@@ -487,12 +469,12 @@ class BluetoothManagerService {
            AutoOnFeature.pause();
        }

                // If state is BLE_ON make sure we trigger stopBle
        // If currentState is BLE_ON make sure we trigger stopBle
        if (currentState == STATE_BLE_ON) {
            mAdapterLock.readLock().lock();
            try {
                if (mAdapter != null) {
                            addActiveLog(ENABLE_DISABLE_REASON_AIRPLANE_MODE, false);
                    addActiveLog(reason, false);
                    mAdapter.stopBle(mContext.getAttributionSource());
                    mEnable = false;
                    mEnableExternal = false;
@@ -503,8 +485,30 @@ class BluetoothManagerService {
                mAdapterLock.readLock().unlock();
            }
        } else if (currentState == STATE_ON) {
                    sendDisableMsg(ENABLE_DISABLE_REASON_AIRPLANE_MODE);
            sendDisableMsg(reason);
        }
    }

    @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
    private void handleAirplaneModeChanged(boolean isAirplaneModeOn) {
        synchronized (this) {
            if (isBluetoothPersistedStateOn()) {
                if (isAirplaneModeOn) {
                    setBluetoothPersistedState(BLUETOOTH_ON_AIRPLANE);
                } else {
                    setBluetoothPersistedState(BLUETOOTH_ON_BLUETOOTH);
                }
            }

            int currentState = mState.get();

            Log.d(
                    TAG,
                    ("handleAirplaneModeChanged(" + isAirplaneModeOn + "):")
                            + (" currentState=" + BluetoothAdapter.nameForState(currentState)));

            if (isAirplaneModeOn) {
                forceToOffFromModeChange(currentState, ENABLE_DISABLE_REASON_AIRPLANE_MODE);
            } else if (mEnableExternal) {
                sendEnableMsg(mQuietEnableExternal, ENABLE_DISABLE_REASON_AIRPLANE_MODE);
            } else if (currentState != STATE_ON) {