From 97c1b4a34b35c53f71d95a18985c287b75e905e6 Mon Sep 17 00:00:00 2001 From: Tiger Huang Date: Thu, 2 Jul 2020 01:44:39 +0800 Subject: [PATCH] Apply the requested insets sources if possible If the client doesn't change the insets, we use the dispatched source. In this way, the task snapshot can have the same insets as the client. Fix: 152931762 Test: atest TaskSnapshotControllerTest Change-Id: Ib0315ce0a8ab32e1c653eeed725fecccb54b3aa8 --- .../android/server/wm/TaskSnapshotController.java | 14 +++++++++++++- .../com/android/server/wm/TaskSnapshotSurface.java | 5 ++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/wm/TaskSnapshotController.java b/services/core/java/com/android/server/wm/TaskSnapshotController.java index 51cf858715b4d..c2021303c11c2 100644 --- a/services/core/java/com/android/server/wm/TaskSnapshotController.java +++ b/services/core/java/com/android/server/wm/TaskSnapshotController.java @@ -40,6 +40,7 @@ import android.util.ArraySet; import android.util.Slog; import android.view.InsetsSource; import android.view.InsetsState; +import android.view.InsetsState.InternalInsetsType; import android.view.SurfaceControl; import android.view.ThreadedRenderer; import android.view.WindowInsets; @@ -480,7 +481,9 @@ class TaskSnapshotController { task.getTaskDescription().getBackgroundColor(), 255); final LayoutParams attrs = mainWindow.getAttrs(); final InsetsPolicy insetsPolicy = mainWindow.getDisplayContent().getInsetsPolicy(); - final InsetsState insetsState = insetsPolicy.getInsetsForDispatch(mainWindow); + final InsetsState insetsState = + new InsetsState(insetsPolicy.getInsetsForDispatch(mainWindow)); + mergeInsetsSources(insetsState, mainWindow.getRequestedInsetsState()); final Rect systemBarInsets = getSystemBarInsets(mainWindow.getFrameLw(), insetsState); final SystemBarBackgroundPainter decorPainter = new SystemBarBackgroundPainter(attrs.flags, attrs.privateFlags, attrs.systemUiVisibility, task.getTaskDescription(), @@ -600,6 +603,15 @@ class TaskSnapshotController { return 0; } + static void mergeInsetsSources(InsetsState base, InsetsState other) { + for (@InternalInsetsType int type = 0; type < InsetsState.SIZE; type++) { + final InsetsSource source = other.peekSource(type); + if (source != null) { + base.addSource(source); + } + } + } + static Rect getSystemBarInsets(Rect frame, InsetsState state) { return state.calculateInsets(frame, null /* ignoringVisibilityState */, false /* isScreenRound */, false /* alwaysConsumeSystemBars */, diff --git a/services/core/java/com/android/server/wm/TaskSnapshotSurface.java b/services/core/java/com/android/server/wm/TaskSnapshotSurface.java index 3fc09c93550cf..448b4aae7a88b 100644 --- a/services/core/java/com/android/server/wm/TaskSnapshotSurface.java +++ b/services/core/java/com/android/server/wm/TaskSnapshotSurface.java @@ -42,6 +42,7 @@ import static com.android.internal.policy.DecorView.STATUS_BAR_COLOR_VIEW_ATTRIB import static com.android.internal.policy.DecorView.getNavigationBarRect; import static com.android.server.wm.ProtoLogGroup.WM_DEBUG_STARTING_WINDOW; import static com.android.server.wm.TaskSnapshotController.getSystemBarInsets; +import static com.android.server.wm.TaskSnapshotController.mergeInsetsSources; import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME; import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; @@ -243,7 +244,9 @@ class TaskSnapshotSurface implements StartingSurface { final InsetsPolicy insetsPolicy = topFullscreenOpaqueWindow.getDisplayContent() .getInsetsPolicy(); - insetsState = insetsPolicy.getInsetsForDispatch(topFullscreenOpaqueWindow); + insetsState = + new InsetsState(insetsPolicy.getInsetsForDispatch(topFullscreenOpaqueWindow)); + mergeInsetsSources(insetsState, topFullscreenOpaqueWindow.getRequestedInsetsState()); } try { final int res = session.addToDisplay(window, window.mSeq, layoutParams,