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

Commit 9224679d authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge changes I939444e4,Ie4b0b6f8,I285734be,Ic049d4d1 into main

* changes:
  SystemServer: Satellite mode disable even BLE_ON
  SystemServer: move smaller if branch first
  SystemServer: Extract airplane turn off logic
  SystemServer: change variable name
parents adc4fb44 4e6e7fc2
Loading
Loading
Loading
Loading
+41 −36
Original line number Diff line number Diff line
@@ -462,40 +462,24 @@ 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 st = mState.get();

            Log.d(
                    TAG,
                    "handleAirplaneModeChanged(isAirplaneModeOn="
                            + isAirplaneModeOn
                            + ") | current state="
                            + BluetoothAdapter.nameForState(st));

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

                if (!AirplaneModeListener.hasUserToggledApm(mCurrentUserContext)) {
        if (reason == ENABLE_DISABLE_REASON_SATELLITE_MODE
                || !AirplaneModeListener.hasUserToggledApm(mCurrentUserContext)) {
            // AirplaneMode can have a state where it does not impact the AutoOnFeature
            AutoOnFeature.pause();
        }

                // If state is BLE_ON make sure we trigger stopBle
                if (st == STATE_BLE_ON) {
        if (currentState == STATE_ON) {
            sendDisableMsg(reason);
        } else if (currentState == STATE_BLE_ON) {
            // If currentState is BLE_ON make sure we trigger stopBle
            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;
@@ -505,26 +489,47 @@ class BluetoothManagerService {
            } finally {
                mAdapterLock.readLock().unlock();
            }
                } else if (st == STATE_ON) {
                    sendDisableMsg(ENABLE_DISABLE_REASON_AIRPLANE_MODE);
        }
    }

    @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 (st != STATE_ON) {
            } else if (currentState != STATE_ON) {
                autoOnSetupTimer();
            }
        }
    }

    private void handleSatelliteModeChanged(boolean isSatelliteModeOn) {
        if (shouldBluetoothBeOn(isSatelliteModeOn) && getState() != STATE_ON) {
        final int currentState = mState.get();

        if (shouldBluetoothBeOn(isSatelliteModeOn) && currentState != STATE_ON) {
            sendEnableMsg(mQuietEnableExternal, ENABLE_DISABLE_REASON_SATELLITE_MODE);
        } else if (!shouldBluetoothBeOn(isSatelliteModeOn) && getState() != STATE_OFF) {
            AutoOnFeature.pause();
            sendDisableMsg(ENABLE_DISABLE_REASON_SATELLITE_MODE);
        } else if (!shouldBluetoothBeOn(isSatelliteModeOn) && currentState != STATE_OFF) {
            forceToOffFromModeChange(currentState, ENABLE_DISABLE_REASON_SATELLITE_MODE);
        } else if (!isSatelliteModeOn
                && !shouldBluetoothBeOn(isSatelliteModeOn)
                && getState() != STATE_ON) {
                && currentState != STATE_ON) {
            autoOnSetupTimer();
        }
    }