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

Commit 069ca5d7 authored by baik.han's avatar baik.han Committed by Piotr Wilczyński
Browse files

Prevent the thread unsafe operation during the user switching

- Prevent accessing a variable that controls brightness
  at the same time through different threads.

Bug: 267255661
Bug: 262663423
Test: Manual
Change-Id: I7ffeb83e664e058a9b3e9f4f8a59d65936c43a6b
(cherry picked from commit 9e345b68)
parent 954f15ac
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -132,6 +132,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    private static final int MSG_UPDATE_RBC = 11;
    private static final int MSG_BRIGHTNESS_RAMP_DONE = 12;
    private static final int MSG_STATSD_HBM_BRIGHTNESS = 13;
    private static final int MSG_SWITCH_USER = 14;

    private static final int PROXIMITY_UNKNOWN = -1;
    private static final int PROXIMITY_NEGATIVE = 0;
@@ -703,6 +704,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    }

    public void onSwitchUser(@UserIdInt int newUserId) {
        Message msg = mHandler.obtainMessage(MSG_SWITCH_USER, newUserId);
        mHandler.sendMessage(msg);
    }

    private void handleOnSwitchUser(@UserIdInt int newUserId) {
        handleSettingsChange(true /* userSwitch */);
        handleBrightnessModeChange();
        if (mBrightnessTracker != null) {
@@ -3167,6 +3173,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                case MSG_STATSD_HBM_BRIGHTNESS:
                    logHbmBrightnessStats(Float.intBitsToFloat(msg.arg1), msg.arg2);
                    break;

                case MSG_SWITCH_USER:
                    handleOnSwitchUser(msg.arg1);
                    break;
            }
        }
    }