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

Commit 7eec316f authored by JianYang Liu's avatar JianYang Liu
Browse files

Updated InputMethodService to not inset by navigation bar if requested

by automotive.

Bug: 147155538
Test: Manual
Change-Id: I4faf82bdd7536bd2d049ded04034a9635d8ca0d3
parent c8e17b66
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.app.Dialog;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
@@ -52,7 +53,6 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Process;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.SystemClock;
@@ -452,6 +452,9 @@ public class InputMethodService extends AbstractInputMethodService {
    @Nullable
    private InlineSuggestionsRequestInfo mInlineSuggestionsRequestInfo = null;

    private boolean mAutomotiveHideNavBarForKeyboard;
    private boolean mIsAutomotive;

    /**
     * An opaque {@link Binder} token of window requesting {@link InputMethodImpl#showSoftInput}
     * The original app window token is passed from client app window.
@@ -1233,6 +1236,11 @@ public class InputMethodService extends AbstractInputMethodService {
        super.onCreate();
        mImm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
        mSettingsObserver = SettingsObserver.createAndRegister(this);

        mIsAutomotive = isAutomotive();
        mAutomotiveHideNavBarForKeyboard = getApplicationContext().getResources().getBoolean(
                com.android.internal.R.bool.config_automotiveHideNavBarForKeyboard);

        // TODO(b/111364446) Need to address context lifecycle issue if need to re-create
        // for update resources & configuration correctly when show soft input
        // in non-default display.
@@ -1242,12 +1250,16 @@ public class InputMethodService extends AbstractInputMethodService {
                WindowManager.LayoutParams.TYPE_INPUT_METHOD, Gravity.BOTTOM, false);
        mWindow.getWindow().getAttributes().setFitInsetsTypes(WindowInsets.Type.statusBars());

        // IME layout should always be inset by navigation bar, no matter it's current visibility.
        // 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.
        mWindow.getWindow().getDecorView().setOnApplyWindowInsetsListener(
                (v, insets) -> v.onApplyWindowInsets(
                        new WindowInsets.Builder(insets).setInsets(
                                navigationBars(),
                                insets.getInsetsIgnoringVisibility(navigationBars()))
                                mIsAutomotive && mAutomotiveHideNavBarForKeyboard
                                        ? android.graphics.Insets.NONE
                                        : insets.getInsetsIgnoringVisibility(navigationBars())
                                )
                                .build()));

        // For ColorView in DecorView to work, FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS needs to be set
@@ -3286,6 +3298,11 @@ public class InputMethodService extends AbstractInputMethodService {
                        : IME_VISIBLE) : 0);
    }

    private boolean isAutomotive() {
        return getApplicationContext().getPackageManager().hasSystemFeature(
                PackageManager.FEATURE_AUTOMOTIVE);
    }

    /**
     * Performs a dump of the InputMethodService's internal state.  Override
     * to add your own information to the dump.
+0 −13
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static java.lang.annotation.RetentionPolicy.SOURCE;
import android.annotation.IntDef;
import android.app.Dialog;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Rect;
import android.os.Debug;
import android.os.IBinder;
@@ -51,7 +50,6 @@ public class SoftInputWindow extends Dialog {
    final int mWindowType;
    final int mGravity;
    final boolean mTakesFocus;
    final boolean mAutomotiveHideNavBarForKeyboard;
    private final Rect mBounds = new Rect();

    @Retention(SOURCE)
@@ -136,8 +134,6 @@ public class SoftInputWindow extends Dialog {
        mWindowType = windowType;
        mGravity = gravity;
        mTakesFocus = takesFocus;
        mAutomotiveHideNavBarForKeyboard = context.getResources().getBoolean(
                com.android.internal.R.bool.config_automotiveHideNavBarForKeyboard);
        initDockWindow();
    }

@@ -251,11 +247,6 @@ public class SoftInputWindow extends Dialog {
            windowModFlags |= WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
        }

        if (isAutomotive() && mAutomotiveHideNavBarForKeyboard) {
            windowSetFlags |= WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
            windowModFlags |= WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
        }

        getWindow().setFlags(windowSetFlags, windowModFlags);
    }

@@ -347,10 +338,6 @@ public class SoftInputWindow extends Dialog {
        mWindowState = newState;
    }

    private boolean isAutomotive() {
        return getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE);
    }

    private static String stateToString(@SoftInputWindowState int state) {
        switch (state) {
            case SoftInputWindowState.TOKEN_PENDING: