From f23d750dbbfc3e6753d092e272a2aa7b630d8400 Mon Sep 17 00:00:00 2001 From: Ming-Shin Lu Date: Thu, 25 May 2023 18:49:35 +0000 Subject: [PATCH] Fix next call WIC#show(ime()) failed when the app in multi-window mode In case the app may not be able to control and failed to show IME with calling WIC#show(ime()) in multi-windowing mode because the request visiblity state out-ouf-sync by the IME control being taken by remote target, in WIC#show(), use the IME source visiblity to check whether the IME is valid to show instead of using the requested visiblity state to fix this case. Bug: 283342812 Test: manual with steps: 1. install "Jetpack Compose Demo" app. 2. open Messenges app as a secondary app of the multi window. 3. open "Jetpack Compose Demo" app. 4. enable split splitscreen of "Jetpack Compose Demo" app by long tapping icon in the recent screen. Choose Messages a a secondary app 5. Navigate "Text" -> "Text Input" -> "Basic input fields" 6. Tap "simple editing single line". Confirm the software keyboard is appeared. 7. Tap back button to close the software keyboard. 8. Tap "simple editing multi line". 9. Ensure the IME being shown as expected Change-Id: I933e02c03f496d4f1f8d43e2602cbf1f87d40899 --- core/java/android/view/InsetsController.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java index 7e4e4022f00f3..5019b85ca503e 100644 --- a/core/java/android/view/InsetsController.java +++ b/core/java/android/view/InsetsController.java @@ -1099,21 +1099,25 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation // TODO: Support a ResultReceiver for IME. // TODO(b/123718661): Make show() work for multi-session IME. int typesReady = 0; + final boolean imeVisible = mState.isSourceOrDefaultVisible( + mImeSourceConsumer.getId(), ime()); for (int type = FIRST; type <= LAST; type = type << 1) { if ((types & type) == 0) { continue; } @AnimationType final int animationType = getAnimationType(type); final boolean requestedVisible = (type & mRequestedVisibleTypes) != 0; - final boolean isImeAnimation = type == ime(); - if (requestedVisible && animationType == ANIMATION_TYPE_NONE - || animationType == ANIMATION_TYPE_SHOW) { + final boolean isIme = type == ime(); + var alreadyVisible = requestedVisible && (!isIme || imeVisible) + && animationType == ANIMATION_TYPE_NONE; + var alreadyAnimatingShow = animationType == ANIMATION_TYPE_SHOW; + if (alreadyVisible || alreadyAnimatingShow) { // no-op: already shown or animating in (because window visibility is // applied before starting animation). if (DEBUG) Log.d(TAG, String.format( "show ignored for type: %d animType: %d requestedVisible: %s", type, animationType, requestedVisible)); - if (isImeAnimation) { + if (isIme) { ImeTracker.forLogging().onCancelled(statsToken, ImeTracker.PHASE_CLIENT_APPLY_ANIMATION); } @@ -1121,13 +1125,13 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation } if (fromIme && animationType == ANIMATION_TYPE_USER) { // App is already controlling the IME, don't cancel it. - if (isImeAnimation) { + if (isIme) { ImeTracker.forLogging().onFailed( statsToken, ImeTracker.PHASE_CLIENT_APPLY_ANIMATION); } continue; } - if (isImeAnimation) { + if (isIme) { ImeTracker.forLogging().onProgress( statsToken, ImeTracker.PHASE_CLIENT_APPLY_ANIMATION); }