From fc8f9637c8f1b9fbe92a75231741c3ad12d03279 Mon Sep 17 00:00:00 2001 From: Tiger Huang Date: Tue, 16 Aug 2022 16:57:38 +0800 Subject: [PATCH] Always copy sources to outInsetsState before writeToParcel InsetsState#writeToParcel is executed outside of mGlobalLock, so there could be two threads accessing the same object at the same time. This CL copies sources to outInsetsState to prevent the race condition. Fix: 235019713 Fix: 242037615 Test: presubmit Change-Id: I78d9b89f88f75ab673761bbfce86330ff0163adc --- .../com/android/server/wm/WindowManagerService.java | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 1d82bfc3aa889..1d174453dcab3 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -1866,7 +1866,7 @@ public class WindowManagerService extends IWindowManager.Stub displayContent.getInsetsStateController().updateAboveInsetsState( false /* notifyInsetsChanged */); - outInsetsState.set(win.getCompatInsetsState(), win.isClientLocal()); + outInsetsState.set(win.getCompatInsetsState(), true /* copySources */); getInsetsSourceControls(win, outActiveControls); if (win.mLayoutAttached) { @@ -2560,7 +2560,7 @@ public class WindowManagerService extends IWindowManager.Stub } if (outInsetsState != null) { - outInsetsState.set(win.getCompatInsetsState(), win.isClientLocal()); + outInsetsState.set(win.getCompatInsetsState(), true /* copySources */); } ProtoLog.v(WM_DEBUG_FOCUS, "Relayout of %s: focusMayChange=%b", @@ -8877,7 +8877,6 @@ public class WindowManagerService extends IWindowManager.Stub @Override public boolean getWindowInsets(WindowManager.LayoutParams attrs, int displayId, InsetsState outInsetsState) { - final boolean fromLocal = Binder.getCallingPid() == MY_PID; final int uid = Binder.getCallingUid(); final long origId = Binder.clearCallingIdentity(); try { @@ -8891,10 +8890,8 @@ public class WindowManagerService extends IWindowManager.Stub final float overrideScale = mAtmService.mCompatModePackages.getCompatScale( attrs.packageName, uid); final InsetsState state = dc.getInsetsPolicy().getInsetsForWindowMetrics(attrs); - final boolean hasCompatScale = - WindowState.hasCompatScale(attrs, token, overrideScale); - outInsetsState.set(state, hasCompatScale || fromLocal); - if (hasCompatScale) { + outInsetsState.set(state, true /* copySources */); + if (WindowState.hasCompatScale(attrs, token, overrideScale)) { final float compatScale = token != null && token.hasSizeCompatBounds() ? token.getSizeCompatScale() * overrideScale : overrideScale;