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

Commit 09d55867 authored by Jian-Yang Liu's avatar Jian-Yang Liu Committed by Android (Google) Code Review
Browse files

Merge "Updated InputMethodService to not inset by navigation bar if requested by automotive."

parents 9af0f119 7eec316f
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -38,6 +38,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;
@@ -451,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.
@@ -1230,6 +1234,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.
@@ -1239,12 +1248,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
@@ -3284,6 +3297,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: