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

Commit 0f439a1c authored by Menghan Li's avatar Menghan Li
Browse files

fix(EDT) Correct caching of ForceInvertState

Root cause: The getForceInvertStateLocked function failed to update
the cache because the underlying "get" function returned 0 when a key
was not found. This 0 value conflicted with valid FORCE_INVERT_TYPE_OFF
state, preventing the cache from recognizing a new value and updating.
This also blocked the indexOfKey initialization, leading to repeated
calls to getForceInvertStateLocked.

Solution: The "get" function's default return value for unfound keys
was changed to a non-zero value.  This allows the cache to correctly
distinguish between a "not found" condition and FORCE_INVERT_TYPE_OFF
state, enabling proper cache updates, completing initialization, and
preventing redundant calls to getForceInvertStateLocked.

Bug: 393829725
Bug: 393843555
Flag: android.view.accessibility.force_invert_color
Test: Tested the forced dark theme by enabling both system and
app-level dark mode, verifying that the view correctly cached and
displayed the forced dark theme. And then disabled dark mode and
repeated the test.
Change-Id: I8535cad0157b0e95ca1dbe79de415d6c22f511de
parent 12f4df91
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -1410,10 +1410,10 @@ final class UiModeManagerService extends SystemService {
    @GuardedBy("mLock")
    @ForceInvertType
    private int getForceInvertStateLocked() {
        if (mForceInvertStates.indexOfKey(mCurrentUser) < 0) {
        if (mForceInvertStates.indexOfKey(mCurrentUser) < 0 && mSystemReady) {
            updateForceInvertStateLocked();
        }
        return mForceInvertStates.get(mCurrentUser);
        return mForceInvertStates.get(mCurrentUser, FORCE_INVERT_TYPE_OFF);
    }

    /**
@@ -1423,7 +1423,7 @@ final class UiModeManagerService extends SystemService {
    @GuardedBy("mLock")
    private boolean updateForceInvertStateLocked() {
        int forceInvertState = getForceInvertStateInternal();
        if (mForceInvertStates.get(mCurrentUser) != forceInvertState) {
        if (mForceInvertStates.get(mCurrentUser, Integer.MIN_VALUE) != forceInvertState) {
            mForceInvertStates.put(mCurrentUser, forceInvertState);
            return true;
        }