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

Commit 1a279f97 authored by William Escande's avatar William Escande
Browse files

Remove un-necessary post

Airplane and satellite handler are running on the correct looper. post
is not necessary
For userSwitch posting delayed with a 0 delay isn't giving value.

finally, remove the synchronized in the airplane handler as this is not
called by multiples thread

Bug: 328842491
Flag: Exempt, no-op
Test: atest ServiceBluetoothTests
Change-Id: I4d2e8d7bf6e25ca36157aa2d9ac9dc4ee8fd36f0
parent 41e77e90
Loading
Loading
Loading
Loading
+30 −38
Original line number Diff line number Diff line
@@ -399,39 +399,30 @@ class BluetoothManagerService {
    private static final Object ON_SWITCH_USER_TOKEN = new Object();

    Unit onAirplaneModeChanged(boolean isAirplaneModeOn) {
        mHandler.postDelayed(
                () ->
        delayModeChangedIfNeeded(
                ON_AIRPLANE_MODE_CHANGED_TOKEN,
                () -> handleAirplaneModeChanged(isAirplaneModeOn),
                                "onAirplaneModeChanged"),
                ON_AIRPLANE_MODE_CHANGED_TOKEN,
                0);
                "onAirplaneModeChanged");
        return Unit.INSTANCE;
    }

    // TODO(b/289584302): Update to private once use_new_satellite_mode is enabled
    Unit onSatelliteModeChanged(boolean isSatelliteModeOn) {
        mHandler.postDelayed(
                () ->
        delayModeChangedIfNeeded(
                ON_SATELLITE_MODE_CHANGED_TOKEN,
                () -> handleSatelliteModeChanged(isSatelliteModeOn),
                                "onSatelliteModeChanged"),
                ON_SATELLITE_MODE_CHANGED_TOKEN,
                0);
                "onSatelliteModeChanged");
        return Unit.INSTANCE;
    }

    // Call is coming from the systemServer main thread and need to be post to avoid race
    void onSwitchUser(UserHandle userHandle) {
        mHandler.postDelayed(
        mHandler.post(
                () ->
                        delayModeChangedIfNeeded(
                                ON_SWITCH_USER_TOKEN,
                                () -> handleSwitchUser(userHandle),
                                "onSwitchUser"),
                ON_SWITCH_USER_TOKEN,
                0);
                                "onSwitchUser"));
    }

    private void forceToOffFromModeChange(int currentState, int reason) {
@@ -458,8 +449,8 @@ class BluetoothManagerService {
    }

    private void handleAirplaneModeChanged(boolean isAirplaneModeOn) {
        synchronized (this) {
            if (isBluetoothPersistedStateOn()) {
        boolean isPersistStateOn = isBluetoothPersistedStateOn();
        if (isPersistStateOn) {
            if (isAirplaneModeOn) {
                setBluetoothPersistedState(BLUETOOTH_ON_AIRPLANE);
            } else {
@@ -472,6 +463,8 @@ class BluetoothManagerService {
        Log.d(
                TAG,
                ("handleAirplaneModeChanged(" + isAirplaneModeOn + "):")
                        + (" mEnableExternal=" + mEnableExternal)
                        + (" isPersistStateOn=" + isPersistStateOn)
                        + (" currentState=" + nameForState(currentState)));

        if (isAirplaneModeOn) {
@@ -482,7 +475,6 @@ class BluetoothManagerService {
            autoOnSetupTimer();
        }
    }
    }

    private void handleSatelliteModeChanged(boolean isSatelliteModeOn) {
        final int currentState = mState.get();