From 7318911f69d8038f93eb89d9399fc8418a3197cf Mon Sep 17 00:00:00 2001 From: Ming-Shin Lu Date: Fri, 1 Apr 2022 18:31:27 +0800 Subject: [PATCH] Reset crop after finished transition In case when in landcape mode, starting an activity transition with DefaultTransitionHandler#startSurfaceAnimation to set crop that affected the app surface, and seeing the "cropped" half app surface after rotating to portrait mode, In Transition#buildFinishTransaction, we should reset the crop to the target parent's requested overrided bound after finished transition and re-parented back into the hierarchy to fix this bad state. Also, ensure to not set crop on the display in case seeing the cropped content during the display rotation, and use parent's overrided bound to crop the activity in case we cropped the letterbox area for fixed-orientation activity. Fix: 223396859 Test: manual as steps: Issue case: 1) Launch messages app 2) Tap the editor to show IME and enter the search page 3) Rotate device to landscape mode 4) Press back button on the search bar to close search page 5) Rotate device to portrait mode, expect the app surface should not be cropped Full app/split-screen case: 1) Launch message app (or another app like chrome in split-screen) 2) Rotate device from portrait to landscape mode (or landscape to portrait) 3) Expect no cropped content during animating Fix orientation app in split-screen case: 0) Settings -> "Enable non-resizable in multi window" in developer option 1) Launch camera and message in split-screen mode 2) Rotate device from portrait to landscape mode (or landscape to portrait) 3) Expect no cropped content during animating Change-Id: Idb10df39e6947b7a3f4d67e7ef2826bd83108ab3 --- .../java/com/android/server/wm/Transition.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/services/core/java/com/android/server/wm/Transition.java b/services/core/java/com/android/server/wm/Transition.java index c44f08cbd1ebe..f6f9020555d85 100644 --- a/services/core/java/com/android/server/wm/Transition.java +++ b/services/core/java/com/android/server/wm/Transition.java @@ -426,6 +426,21 @@ class Transition extends Binder implements BLASTSyncEngine.TransactionReadyListe t.setLayer(targetLeash, target.getLastLayer()); target.getRelativePosition(tmpPos); t.setPosition(targetLeash, tmpPos.x, tmpPos.y); + final Rect clipRect; + // No need to clip the display in case seeing the clipped content when during the + // display rotation. + if (target.asDisplayContent() != null) { + clipRect = null; + } else if (target.asActivityRecord() != null) { + // Always use parent bounds of activity because letterbox area (e.g. fixed + // aspect ratio or size compat mode) should be included. + clipRect = target.getParent().getRequestedOverrideBounds(); + clipRect.offset(-tmpPos.x, -tmpPos.y); + } else { + clipRect = target.getRequestedOverrideBounds(); + clipRect.offset(-tmpPos.x, -tmpPos.y); + } + t.setCrop(targetLeash, clipRect); t.setCornerRadius(targetLeash, 0); t.setShadowRadius(targetLeash, 0); t.setMatrix(targetLeash, 1, 0, 0, 1);