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

Commit 350010d2 authored by Vinit Nayak's avatar Vinit Nayak Committed by Arne Coucheron
Browse files

Set gesture exclusion rect for IMEs



Use visible inset values provided by
IMEs to set gesture exclusion rects
for the EdgeBackGestureHandler to ignore
regions where the keyboard is.
If the IME has not overridden
onComputeInsets(), InputMethodService
uses the location of R.id.inputArea
to approximate the location of where
the IME region starts.

Fixes: 141215181
Test: Tested full screen landscape keyboards
(Messenger, Hangouts), non full screen landscape
keyboards (SMS Messages), searching from the top
of the screen in the Toolbar (Google Play Store)

[AdrianDC] Backported from Android 11 to 10 to resolve
           back gesture navigation over the IME surface
           while built with Go's "ro.config.low_ram=true"
           which disables "mSupportsPictureInPicture" in
           WindowManagerService::registerPinnedStackListener

Change-Id: I359d719493fb92d49cd309c2d00371134cd758fe
Signed-off-by: default avatarAdrian DC <radian.dc@gmail.com>
parent 99f92318
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Collections;

/**
 * InputMethodService provides a standard implementation of an InputMethod,
@@ -437,6 +438,7 @@ public class InputMethodService extends AbstractInputMethodService {
    private static final int VOLUME_CURSOR_ON_REVERSE = 2;

    final ViewTreeObserver.OnComputeInternalInsetsListener mInsetsComputer = info -> {
        onComputeInsets(mTmpInsets);
        if (isExtractViewShown()) {
            // In true fullscreen mode, we just say the window isn't covering
            // any content so we don't impact whatever is behind.
@@ -445,12 +447,15 @@ public class InputMethodService extends AbstractInputMethodService {
            info.touchableRegion.setEmpty();
            info.setTouchableInsets(ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_FRAME);
        } else {
            onComputeInsets(mTmpInsets);
            info.contentInsets.top = mTmpInsets.contentTopInsets;
            info.visibleInsets.top = mTmpInsets.visibleTopInsets;
            info.touchableRegion.set(mTmpInsets.touchableRegion);
            info.setTouchableInsets(mTmpInsets.touchableInsets);
        }

        if (mInputFrame != null) {
            setImeExclusionRect(mTmpInsets.visibleTopInsets);
        }
    };

    final View.OnClickListener mActionClickListener = v -> {
@@ -675,6 +680,14 @@ public class InputMethodService extends AbstractInputMethodService {
        mPrivOps.setImeWindowStatus(visibilityFlags, backDisposition);
    }

    /** Set region of the keyboard to be avoided from back gesture */
    private void setImeExclusionRect(int visibleTopInsets) {
        View inputFrameRootView = mInputFrame.getRootView();
        Rect r = new Rect(0, visibleTopInsets, inputFrameRootView.getWidth(),
                inputFrameRootView.getHeight());
        inputFrameRootView.setSystemGestureExclusionRects(Collections.singletonList(r));
    }

    /**
     * Concrete implementation of
     * {@link AbstractInputMethodService.AbstractInputMethodSessionImpl} that provides
+1 −44
Original line number Diff line number Diff line
@@ -61,7 +61,6 @@ import com.android.systemui.R;
import com.android.systemui.bubbles.BubbleController;
import com.android.systemui.recents.OverviewProxyService;
import com.android.systemui.shared.system.QuickStepContract;
import com.android.systemui.shared.system.WindowManagerWrapper;
import com.android.systemui.tuner.TunerService;

import lineageos.providers.LineageSettings;
@@ -84,37 +83,6 @@ public class EdgeBackGestureHandler implements DisplayListener, TunerService.Tun
    private static final String KEY_GESTURE_BACK_EXCLUDE_TOP =
            "lineagesecure:" + LineageSettings.Secure.GESTURE_BACK_EXCLUDE_TOP;

    private final IPinnedStackListener.Stub mImeChangedListener = new IPinnedStackListener.Stub() {
        @Override
        public void onListenerRegistered(IPinnedStackController controller) {
        }

        @Override
        public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) {
            // No need to thread jump, assignments are atomic
            mImeHeight = imeVisible ? imeHeight : 0;
            // TODO: Probably cancel any existing gesture
        }

        @Override
        public void onShelfVisibilityChanged(boolean shelfVisible, int shelfHeight) {
        }

        @Override
        public void onMinimizedStateChanged(boolean isMinimized) {
        }

        @Override
        public void onMovementBoundsChanged(Rect insetBounds, Rect normalBounds,
                Rect animatingBounds, boolean fromImeAdjustment, boolean fromShelfAdjustment,
                int displayRotation) {
        }

        @Override
        public void onActionsChanged(ParceledListSlice actions) {
        }
    };

    private ISystemGestureExclusionListener mGestureExclusionListener =
            new ISystemGestureExclusionListener.Stub() {
                @Override
@@ -164,8 +132,6 @@ public class EdgeBackGestureHandler implements DisplayListener, TunerService.Tun
    private boolean mInRejectedExclusion = false;
    private boolean mIsOnLeftEdge;

    private int mImeHeight = 0;

    private boolean mIsAttached;
    private boolean mIsGesturalModeEnabled;
    private boolean mIsEnabled;
@@ -270,7 +236,6 @@ public class EdgeBackGestureHandler implements DisplayListener, TunerService.Tun
        }

        if (!mIsEnabled) {
            WindowManagerWrapper.getInstance().removePinnedStackListener(mImeChangedListener);
            mContext.getSystemService(DisplayManager.class).unregisterDisplayListener(this);

            try {
@@ -287,7 +252,6 @@ public class EdgeBackGestureHandler implements DisplayListener, TunerService.Tun
                    mContext.getMainThreadHandler());

            try {
                WindowManagerWrapper.getInstance().addPinnedStackListener(mImeChangedListener);
                WindowManagerGlobal.getWindowManagerService()
                        .registerSystemGestureExclusionListener(
                                mGestureExclusionListener, mDisplayId);
@@ -344,14 +308,8 @@ public class EdgeBackGestureHandler implements DisplayListener, TunerService.Tun
    }

    private boolean isWithinTouchRegion(int x, int y) {
        final int baseY = mDisplaySize.y - Math.max(mImeHeight, mNavBarHeight);
        // Disallow if over the IME
        if (y > baseY) {
            return false;
        }

        // Disallow if over user exclusion area
        if (mUserExclude > 0 && y < baseY - mUserExclude) {
        if (mUserExclude > 0 && y < mDisplaySize.y - mNavBarHeight - mUserExclude) {
            return false;
        }

@@ -582,7 +540,6 @@ public class EdgeBackGestureHandler implements DisplayListener, TunerService.Tun
        pw.println("  mInRejectedExclusion" + mInRejectedExclusion);
        pw.println("  mExcludeRegion=" + mExcludeRegion);
        pw.println("  mUnrestrictedExcludeRegion=" + mUnrestrictedExcludeRegion);
        pw.println("  mImeHeight=" + mImeHeight);
        pw.println("  mIsAttached=" + mIsAttached);
        pw.println("  mEdgeWidth=" + mEdgeWidth);
    }