Allow to show IME snapshot on home when turning off screen
Change [1] adds IME snapshot for keeping IME on apps when switching
tasks. Home task was excluded from the target to attach IME snapshot
because home doesn't have the navigation cases as regular task.
Change [2] assumes if IME snapshot should show, then the real IME
should be hidden. The current caller is from
ImeVisibilityStateComputer#onInteractiveChanged with !interactive.
If IME is hidden immediately without showing the snapshot, it will
look flickering.
[1]: I6bef36c779a28777408576f57e5d1c67d5d48e3f
[2]: I2e1e4bc106fc14aa65825ee82dc09390422951c5
Bug: 330713465
Test: Press search bar on home. Turn off screen.
IME won't be flickering.
Change-Id: I1132a78ba1154e777a9751ac70659cd6377fcb39
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index fe280cb..15fb40e 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -4562,7 +4562,12 @@
}
}
- void attachAndShow(Transaction t) {
+ /**
+ * Attaches the snapshot of IME (a snapshot will be taken if there wasn't one) to the IME
+ * target task and shows it. If the given {@param anyTargetTask} is true, the snapshot won't
+ * be skipped by the activity type of IME target task.
+ */
+ void attachAndShow(Transaction t, boolean anyTargetTask) {
final DisplayContent dc = mImeTarget.getDisplayContent();
// Prepare IME screenshot for the target if it allows to attach into.
final Task task = mImeTarget.getTask();
@@ -4570,7 +4575,9 @@
final boolean renewImeSurface = mImeSurface == null
|| mImeSurface.getWidth() != dc.mInputMethodWindow.getFrame().width()
|| mImeSurface.getHeight() != dc.mInputMethodWindow.getFrame().height();
- if (task != null && !task.isActivityTypeHomeOrRecents()) {
+ // The exclusion of home/recents is an optimization for regular task switch because
+ // home/recents won't appear in recents task.
+ if (task != null && (anyTargetTask || !task.isActivityTypeHomeOrRecents())) {
ScreenCapture.ScreenshotHardwareBuffer imeBuffer = renewImeSurface
? dc.mWmService.mTaskSnapshotController.snapshotImeFromAttachedTask(task)
: null;
@@ -4638,7 +4645,9 @@
removeImeSurfaceImmediately();
mImeScreenshot = new ImeScreenshot(
mWmService.mSurfaceControlFactory.apply(null), imeTarget);
- mImeScreenshot.attachAndShow(t);
+ // If the caller requests to hide IME, then allow to show IME snapshot for any target task.
+ // So IME won't look like suddenly disappeared. It usually happens when turning off screen.
+ mImeScreenshot.attachAndShow(t, hideImeWindow /* anyTargetTask */);
if (mInputMethodWindow != null && hideImeWindow) {
// Hide the IME window when deciding to show IME snapshot on demand.
// InsetsController will make IME visible again before animating it.