Fix the race in per display brightness overrides.
RootWindowContainer#performSurfacePlacementNoTrace:
1. Clear the current overrides
2. Set the new overrides
3. Post the overrides on the handler thread
With the per-display handling of brightness overrides, we pass an
object to the handler thread instead of a primitive integer. It's the
same object as the RootWindowContainer field, so it may be cleared
during the next performSurfacePlacement call before the handler thread
had the chance to send it out.
The fix is to simply send a copy of the overrides to the handler thread
Technically this is a pre-existing issue but didn't cause any problems
because only the tag was lost and not the brightness value (as it was
a primitive int and was copied anyway)
Fix: 382323783
Test: manual
Flag: EXEMPT bugfix
(cherry picked from commit 78ad38417b06c0ffac9d17f1985d08561dd9bc6d)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:cf2c5620ce742c99976f4d60f540c5cd1cbc7804)
Merged-In: Ia08a18af9d6921c1421c84d812d21af52a8f6478
Change-Id: Ia08a18af9d6921c1421c84d812d21af52a8f6478
diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java
index 46312af..a83b25e 100644
--- a/services/core/java/com/android/server/wm/RootWindowContainer.java
+++ b/services/core/java/com/android/server/wm/RootWindowContainer.java
@@ -882,7 +882,9 @@
if (!mWmService.mDisplayFrozen) {
// Post these on a handler such that we don't call into power manager service while
// holding the window manager lock to avoid lock contention with power manager lock.
- mHandler.obtainMessage(SET_SCREEN_BRIGHTNESS_OVERRIDE, mDisplayBrightnessOverrides)
+ // Send a copy of the brightness overrides as they may be cleared before being sent out.
+ mHandler.obtainMessage(SET_SCREEN_BRIGHTNESS_OVERRIDE,
+ mDisplayBrightnessOverrides.clone())
.sendToTarget();
mHandler.obtainMessage(SET_USER_ACTIVITY_TIMEOUT, mUserActivityTimeout).sendToTarget();
}