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

Commit bec93bc1 authored by Aurélien Pomini's avatar Aurélien Pomini
Browse files

Clear calling identity before invoking contrast listeners

Also make sure to call the listeners outside the lock.

Flag: android.app.fix_contrast_and_force_invert_state_for_multi_user
Bug: 438028125
Test: presubmit
Change-Id: I5608429e970777f61a1f548f45b1667297d30f89
parent 767b9c9a
Loading
Loading
Loading
Loading
+19 −2
Original line number Diff line number Diff line
@@ -574,13 +574,30 @@ public class UiModeManager {

        @Override
        public void notifyContrastChanged(float contrast) {
            final Map<ContrastChangeListener, Executor> listeners;
            synchronized (mGlobalsLock) {
                // if value changed in the settings, update the cached value and notify listeners
                if (Math.abs(mContrast - contrast) < 1e-10) return;
                mContrast = contrast;

                if (!fixContrastAndForceInvertStateForMultiUser()) {
                    mContrastChangeListeners.forEach((listener, executor) -> executor.execute(
                            () -> listener.onContrastChanged(contrast)));
                    return;
                }
                listeners = new ArrayMap<>(mContrastChangeListeners);
            }

            listeners.forEach((listener, executor) -> {
                final long token = Binder.clearCallingIdentity();
                try {
                    executor.execute(() -> listener.onContrastChanged(contrast));
                } finally {
                    Binder.restoreCallingIdentity(token);
                }
            });


        }

        @Override