Consolidate clearing mImeInsetsFrozenUntilStartInput

As CL[1] that IMMS only invoke updateInputMethodTargetWindow when the
IME input target window changed, that caused somehow we can't clear
mImeInsetsFrozenUntilStartInput in ActivityRecord to make the activity
can receive IME insets correctly like when turning the screen off/on
and then unlocking the non-secure keyguard to back to the same app,
since the IME input target didn't changed.

Making sure IMMS side always invoke updateInputMethodTargetWindow to WM
to clear IME insets frozen state.

[1]: Id8a56c68a06a774ef12ba444fd9a368148ea4539

Fix: 205783849
Test: atest ActivityRecordTests#\
        testImeInsetsFrozenFlag_resetWhenReportedToBeImeInputTarget

Change-Id: I796754992911b917a49fcd18f22019c1eecad908
This commit is contained in:
Ming-Shin Lu
2021-12-01 15:46:19 +08:00
parent 642ead3a05
commit 97a4225843
4 changed files with 44 additions and 4 deletions

View File

@@ -2830,7 +2830,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
return; return;
} }
final IBinder targetWindow = mImeTargetWindowMap.get(startInputToken); final IBinder targetWindow = mImeTargetWindowMap.get(startInputToken);
if (targetWindow != null && mLastImeTargetWindow != targetWindow) { if (targetWindow != null) {
mWindowManagerInternal.updateInputMethodTargetWindow(token, targetWindow); mWindowManagerInternal.updateInputMethodTargetWindow(token, targetWindow);
} }
mLastImeTargetWindow = targetWindow; mLastImeTargetWindow = targetWindow;

View File

@@ -1057,6 +1057,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
pw.print(" forceNewConfig="); pw.println(forceNewConfig); pw.print(" forceNewConfig="); pw.println(forceNewConfig);
pw.print(prefix); pw.print("mActivityType="); pw.print(prefix); pw.print("mActivityType=");
pw.println(activityTypeToString(getActivityType())); pw.println(activityTypeToString(getActivityType()));
pw.print(prefix); pw.print("mImeInsetsFrozenUntilStartInput=");
pw.println(mImeInsetsFrozenUntilStartInput);
if (requestedVrComponent != null) { if (requestedVrComponent != null) {
pw.print(prefix); pw.print(prefix);
pw.print("requestedVrComponent="); pw.print("requestedVrComponent=");

View File

@@ -4130,11 +4130,11 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
* which controls the visibility and animation of the input method window. * which controls the visibility and animation of the input method window.
*/ */
void updateImeInputAndControlTarget(WindowState target) { void updateImeInputAndControlTarget(WindowState target) {
if (mImeInputTarget != target) {
ProtoLog.i(WM_DEBUG_IME, "setInputMethodInputTarget %s", target);
if (target != null && target.mActivityRecord != null) { if (target != null && target.mActivityRecord != null) {
target.mActivityRecord.mImeInsetsFrozenUntilStartInput = false; target.mActivityRecord.mImeInsetsFrozenUntilStartInput = false;
} }
if (mImeInputTarget != target) {
ProtoLog.i(WM_DEBUG_IME, "setInputMethodInputTarget %s", target);
setImeInputTarget(target); setImeInputTarget(target);
mInsetsStateController.updateAboveInsetsState(mInputMethodWindow, mInsetsStateController mInsetsStateController.updateAboveInsetsState(mInputMethodWindow, mInsetsStateController
.getRawInsetsState().getSourceOrDefaultVisibility(ITYPE_IME)); .getRawInsetsState().getSourceOrDefaultVisibility(ITYPE_IME));

View File

@@ -39,6 +39,7 @@ import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT; import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static android.os.Process.NOBODY_UID; import static android.os.Process.NOBODY_UID;
import static android.view.Display.DEFAULT_DISPLAY; import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.InsetsState.ITYPE_IME;
import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW; import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW; import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM; import static android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
@@ -128,6 +129,8 @@ import android.view.IRemoteAnimationFinishedCallback;
import android.view.IRemoteAnimationRunner.Stub; import android.view.IRemoteAnimationRunner.Stub;
import android.view.IWindowManager; import android.view.IWindowManager;
import android.view.IWindowSession; import android.view.IWindowSession;
import android.view.InsetsSource;
import android.view.InsetsState;
import android.view.RemoteAnimationAdapter; import android.view.RemoteAnimationAdapter;
import android.view.RemoteAnimationTarget; import android.view.RemoteAnimationTarget;
import android.view.Surface; import android.view.Surface;
@@ -3038,6 +3041,41 @@ public class ActivityRecordTests extends WindowTestsBase {
assertFalse(app.mActivityRecord.mImeInsetsFrozenUntilStartInput); assertFalse(app.mActivityRecord.mImeInsetsFrozenUntilStartInput);
} }
@UseTestDisplay(addWindows = W_INPUT_METHOD)
@Test
public void testImeInsetsFrozenFlag_resetWhenReportedToBeImeInputTarget() {
final WindowState app = createWindow(null, TYPE_APPLICATION, "app");
InsetsSource imeSource = new InsetsSource(ITYPE_IME);
app.getInsetsState().addSource(imeSource);
mDisplayContent.setImeLayeringTarget(app);
mDisplayContent.updateImeInputAndControlTarget(app);
InsetsState state = mDisplayContent.getInsetsPolicy().getInsetsForWindow(app);
assertFalse(state.getSource(ITYPE_IME).isVisible());
assertTrue(state.getSource(ITYPE_IME).getFrame().isEmpty());
// Simulate app is closing and expect IME insets is frozen.
mDisplayContent.mOpeningApps.clear();
app.mActivityRecord.commitVisibility(false, false);
app.mActivityRecord.onWindowsGone();
assertTrue(app.mActivityRecord.mImeInsetsFrozenUntilStartInput);
// Simulate app re-start input or turning screen off/on then unlocked by un-secure
// keyguard to back to the app, expect IME insets is not frozen
imeSource.setFrame(new Rect(100, 400, 500, 500));
app.getInsetsState().addSource(imeSource);
app.getInsetsState().setSourceVisible(ITYPE_IME, true);
mDisplayContent.updateImeInputAndControlTarget(app);
assertFalse(app.mActivityRecord.mImeInsetsFrozenUntilStartInput);
// Verify when IME is visible and the app can receive the right IME insets from policy.
makeWindowVisibleAndDrawn(app, mImeWindow);
state = mDisplayContent.getInsetsPolicy().getInsetsForWindow(app);
assertTrue(state.getSource(ITYPE_IME).isVisible());
assertEquals(state.getSource(ITYPE_IME).getFrame(), imeSource.getFrame());
}
@Test @Test
public void testInClosingAnimation_doNotHideSurface() { public void testInClosingAnimation_doNotHideSurface() {
final WindowState app = createWindow(null, TYPE_APPLICATION, "app"); final WindowState app = createWindow(null, TYPE_APPLICATION, "app");