Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 227c6659 authored by Tiger Huang's avatar Tiger Huang
Browse files

Make canBeImeTarget be compatible with legacy behavior

And let IME always extend into the status bar area so that the position
of IME can never affected by status bar. This can prevent flicker during
IME animation.

This CL also makes PerDisplay can restart the animation while the insets
source control is changed during animation.

Fix: 151759336
Test: atest WindowStateTests
Change-Id: Ic2a308e6b7ec39b4b8645751e31addd26ddf3735
parent 0a9aff3a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1249,6 +1249,7 @@ public class InputMethodService extends AbstractInputMethodService {
                WindowManager.LayoutParams.TYPE_INPUT_METHOD, Gravity.BOTTOM, false);
        mWindow.getWindow().getAttributes().setFitInsetsTypes(statusBars() | navigationBars());
        mWindow.getWindow().getAttributes().setFitInsetsSides(Side.all() & ~Side.BOTTOM);
        mWindow.getWindow().getAttributes().setFitInsetsIgnoringVisibility(true);

        // IME layout should always be inset by navigation bar, no matter its current visibility,
        // unless automotive requests it, since automotive may hide the navigation bar.
+15 −11
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.content.res.Configuration;
import android.graphics.Point;
import android.os.Handler;
import android.os.RemoteException;
import android.util.Slog;
@@ -97,7 +98,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
        }
        if (mSystemWindows.mDisplayController.getDisplayLayout(displayId).rotation()
                != pd.mRotation && isImeShowing(displayId)) {
            pd.startAnimation(true);
            pd.startAnimation(true, false /* forceRestart */);
        }
    }

@@ -200,7 +201,15 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
                        continue;
                    }
                    if (activeControl.getType() == InsetsState.ITYPE_IME) {
                        mHandler.post(() -> {
                            final Point lastSurfacePosition = mImeSourceControl != null
                                    ? mImeSourceControl.getSurfacePosition() : null;
                            mImeSourceControl = activeControl;
                            if (!activeControl.getSurfacePosition().equals(lastSurfacePosition)
                                    && mAnimation != null) {
                                startAnimation(mImeShowing, true /* forceRestart */);
                            }
                        });
                    }
                }
            }
@@ -212,7 +221,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
                return;
            }
            if (DEBUG) Slog.d(TAG, "Got showInsets for ime");
            startAnimation(true /* show */);
            startAnimation(true /* show */, false /* forceRestart */);
        }

        @Override
@@ -221,7 +230,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
                return;
            }
            if (DEBUG) Slog.d(TAG, "Got hideInsets for ime");
            startAnimation(false /* show */);
            startAnimation(false /* show */, false /* forceRestart */);
        }

        /**
@@ -239,7 +248,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
            return imeSource.getFrame().top + (int) surfaceOffset;
        }

        private void startAnimation(final boolean show) {
        private void startAnimation(final boolean show, final boolean forceRestart) {
            final InsetsSource imeSource = mInsetsState.getSource(InsetsState.ITYPE_IME);
            if (imeSource == null || mImeSourceControl == null) {
                return;
@@ -250,7 +259,7 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
                            + (mAnimationDirection == DIRECTION_SHOW ? "SHOW"
                            : (mAnimationDirection == DIRECTION_HIDE ? "HIDE" : "NONE")));
                }
                if ((mAnimationDirection == DIRECTION_SHOW && show)
                if (!forceRestart && (mAnimationDirection == DIRECTION_SHOW && show)
                        || (mAnimationDirection == DIRECTION_HIDE && !show)) {
                    return;
                }
@@ -270,11 +279,6 @@ public class DisplayImeController implements DisplayController.OnDisplaysChanged
                final float shownY = defaultY;
                final float startY = show ? hiddenY : shownY;
                final float endY = show ? shownY : hiddenY;
                if (mImeShowing && show) {
                    // IME is already showing, so set seek to end
                    seekValue = shownY;
                    seek = true;
                }
                mImeShowing = show;
                mAnimation = ValueAnimator.ofFloat(startY, endY);
                mAnimation.setDuration(
+4 −4
Original line number Diff line number Diff line
@@ -131,6 +131,7 @@ import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_WALLPAPER_LIGHT;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
import static com.android.server.wm.WindowManagerService.H.WINDOW_STATE_BLAST_SYNC_TIMEOUT;
import static com.android.server.wm.WindowManagerService.MAX_ANIMATION_DURATION;
import static com.android.server.wm.WindowManagerService.TYPE_LAYER_MULTIPLIER;
import static com.android.server.wm.WindowManagerService.TYPE_LAYER_OFFSET;
@@ -138,7 +139,6 @@ import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_REMOVING_FOCUS;
import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_TIMEOUT;
import static com.android.server.wm.WindowManagerService.H.WINDOW_STATE_BLAST_SYNC_TIMEOUT;
import static com.android.server.wm.WindowStateAnimator.COMMIT_DRAW_PENDING;
import static com.android.server.wm.WindowStateAnimator.DRAW_PENDING;
import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN;
@@ -2270,9 +2270,9 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
            return false;
        }

        if (PixelFormat.formatHasAlpha(mAttrs.format) && mAttrs.alpha == 0) {
            // Support legacy use cases where completely transparent windows can still be ime target
            // with FLAG_NOT_FOCUSABLE and ALT_FOCUSABLE_IM set.
        if (PixelFormat.formatHasAlpha(mAttrs.format)) {
            // Support legacy use cases where transparent windows can still be ime target with
            // FLAG_NOT_FOCUSABLE and ALT_FOCUSABLE_IM set.
            // Certain apps listen for IME insets using transparent windows and ADJUST_NOTHING to
            // manually synchronize app content to IME animation b/144619551.
            // TODO(b/145812508): remove this once new focus management is complete b/141738570
+0 −2
Original line number Diff line number Diff line
@@ -251,11 +251,9 @@ public class WindowStateTests extends WindowTestsBase {

        // b/145812508: special legacy use-case for transparent/translucent windows.
        appWindow.mAttrs.format = PixelFormat.TRANSPARENT;
        appWindow.mAttrs.alpha = 0;
        assertTrue(appWindow.canBeImeTarget());

        appWindow.mAttrs.format = PixelFormat.OPAQUE;
        appWindow.mAttrs.alpha = 1;
        appWindow.mAttrs.flags &= ~FLAG_ALT_FOCUSABLE_IM;
        assertFalse(appWindow.canBeImeTarget());
        appWindow.mAttrs.flags &= ~FLAG_NOT_FOCUSABLE;