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

Commit e5094e86 authored by Cosmin Băieș's avatar Cosmin Băieș Committed by Android (Google) Code Review
Browse files

Merge "Remove canImeRenderGesturalNavButtons and sysprop" into main

parents 5d628b1f 5786050d
Loading
Loading
Loading
Loading
+0 −67
Original line number Diff line number Diff line
@@ -60,7 +60,6 @@ import static android.view.inputmethod.Flags.FLAG_VERIFY_KEY_EVENT;
import static android.view.inputmethod.Flags.ctrlShiftShortcut;
import static android.view.inputmethod.Flags.predictiveBackIme;

import android.annotation.AnyThread;
import android.annotation.CallSuper;
import android.annotation.DrawableRes;
import android.annotation.DurationMillisLong;
@@ -99,7 +98,6 @@ import android.os.Process;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.Trace;
import android.provider.Settings;
import android.text.InputType;
@@ -344,26 +342,6 @@ public class InputMethodService extends AbstractInputMethodService {
    static final String TAG = "InputMethodService";
    static final boolean DEBUG = false;

    /**
     * Key for a boolean value that tells whether {@link InputMethodService} is responsible for
     * rendering the back button and the IME switcher button or not when the gestural navigation is
     * enabled.
     *
     * <p>This sysprop is just ignored when the gestural navigation mode is not enabled.</p>
     *
     * <p>
     * To avoid complexity that is not necessary for production, you always need to reboot the
     * device after modifying this flag as follows:
     * <pre>
     * $ adb root
     * $ adb shell setprop persist.sys.ime.can_render_gestural_nav_buttons true
     * $ adb reboot
     * </pre>
     * </p>
     */
    private static final String PROP_CAN_RENDER_GESTURAL_NAV_BUTTONS =
            "persist.sys.ime.can_render_gestural_nav_buttons";

    /**
     * Number of {@link MotionEvent} to buffer if IME is not ready with Ink view.
     * This number may be configured eventually based on device's touch sampling frequency.
@@ -413,32 +391,6 @@ public class InputMethodService extends AbstractInputMethodService {
     */
    private Region mLastHandwritingRegion;

    /**
     * Returns whether {@link InputMethodService} is responsible for rendering the back button and
     * the IME switcher button or not when the gestural navigation is enabled.
     *
     * <p>This method is supposed to be used with an assumption that the same value is returned in
     * other processes. It is developers' responsibility for rebooting the device when the sysprop
     * is modified.</p>
     *
     * @return {@code true} if {@link InputMethodService} is responsible for rendering the back
     * button and the IME switcher button when the gestural navigation is enabled.
     *
     * @hide
     */
    @AnyThread
    public static boolean canImeRenderGesturalNavButtons() {
        if (Flags.disallowDisablingImeNavigationBar()) {
            return true;
        }
        return SystemProperties.getBoolean(PROP_CAN_RENDER_GESTURAL_NAV_BUTTONS, true);
    }

    /**
     * Cached value of {@link #canImeRenderGesturalNavButtons}, as it doesn't change at runtime.
     */
    private final boolean mCanImeRenderGesturalNavButtons = canImeRenderGesturalNavButtons();

    /**
     * Allows the system to optimize the back button affordance based on the presence of software
     * keyboard.
@@ -569,9 +521,6 @@ public class InputMethodService extends AbstractInputMethodService {
    private final NavigationBarController mNavigationBarController =
            new NavigationBarController(this);

    /** Whether a custom IME Switcher button was requested to be visible. */
    private boolean mCustomImeSwitcherButtonRequestedVisible;

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
    int mTheme = 0;

@@ -924,20 +873,6 @@ public class InputMethodService extends AbstractInputMethodService {
        @Override
        public void onNavButtonFlagsChanged(@InputMethodNavButtonFlags int navButtonFlags) {
            mNavigationBarController.onNavButtonFlagsChanged(navButtonFlags);
            if (!mCanImeRenderGesturalNavButtons) {
                final boolean showImeSwitcher = (navButtonFlags
                        & InputMethodNavButtonFlags.SHOW_IME_SWITCHER_WHEN_IME_IS_SHOWN) != 0;
                // The IME cannot draw the IME nav bar, so this will never be visible. In this case
                // the system nav bar hosts the IME buttons.
                // The system nav bar will be hidden when the IME is shown and the config is set.
                final boolean navBarNotVisible = getApplicationContext().getResources()
                        .getBoolean(com.android.internal.R.bool.config_hideNavBarForKeyboard);
                final boolean visible = showImeSwitcher && navBarNotVisible;
                if (visible != mCustomImeSwitcherButtonRequestedVisible) {
                    mCustomImeSwitcherButtonRequestedVisible = visible;
                    onCustomImeSwitcherButtonRequestedVisible(visible);
                }
            }
        }

        /**
@@ -4705,8 +4640,6 @@ public class InputMethodService extends AbstractInputMethodService {
                + " touchableRegion=" + mTmpInsets.touchableRegion);
        p.println("  mSettingsObserver=" + mSettingsObserver);
        p.println("  mNavigationBarController=" + mNavigationBarController.toDebugString());
        p.println("  mCustomImeSwitcherButtonRequestedVisible="
                + mCustomImeSwitcherButtonRequestedVisible);
    }

    private final ImeTracing.ServiceDumper mDumper = new ImeTracing.ServiceDumper() {
+431 −529
Original line number Diff line number Diff line
@@ -52,109 +52,16 @@ import com.android.internal.inputmethod.InputMethodNavButtonFlags;
import java.util.Objects;

/**
 * This class hides details behind {@link InputMethodService#canImeRenderGesturalNavButtons()} from
 * {@link InputMethodService}.
 *
 * <p>All the package-private methods are no-op when
 * {@link InputMethodService#canImeRenderGesturalNavButtons()} returns {@code false}.</p>
 */
final class NavigationBarController {

    private interface Callback {

        default void updateInsets(@NonNull InputMethodService.Insets originalInsets) {
        }

        default void updateTouchableInsets(@NonNull InputMethodService.Insets originalInsets,
                @NonNull ViewTreeObserver.InternalInsetsInfo dest) {
        }

        default void onSoftInputWindowCreated(@NonNull SoftInputWindow softInputWindow) {
        }

        default void onViewInitialized() {
        }

        default void onWindowShown() {
        }

        default void onDestroy() {
        }

        default void onNavButtonFlagsChanged(@InputMethodNavButtonFlags int navButtonFlags) {
        }

        default boolean isShown() {
            return false;
        }

        default String toDebugString() {
            return "No-op implementation";
        }

        Callback NOOP = new Callback() {
        };
    }

    private final Callback mImpl;

    NavigationBarController(@NonNull InputMethodService inputMethodService) {
        mImpl = InputMethodService.canImeRenderGesturalNavButtons()
                ? new Impl(inputMethodService) : Callback.NOOP;
    }

    /**
     * Update the given insets to be at least as big as the IME navigation bar, when visible.
     *
     * @param originalInsets the insets to check and modify to include the IME navigation bar.
     */
    void updateInsets(@NonNull InputMethodService.Insets originalInsets) {
        mImpl.updateInsets(originalInsets);
    }

    void updateTouchableInsets(@NonNull InputMethodService.Insets originalInsets,
            @NonNull ViewTreeObserver.InternalInsetsInfo dest) {
        mImpl.updateTouchableInsets(originalInsets, dest);
    }

    void onSoftInputWindowCreated(@NonNull SoftInputWindow softInputWindow) {
        mImpl.onSoftInputWindowCreated(softInputWindow);
    }

    void onViewInitialized() {
        mImpl.onViewInitialized();
    }

    void onWindowShown() {
        mImpl.onWindowShown();
    }

    void onDestroy() {
        mImpl.onDestroy();
    }

    void onNavButtonFlagsChanged(@InputMethodNavButtonFlags int navButtonFlags) {
        mImpl.onNavButtonFlagsChanged(navButtonFlags);
    }

    /**
     * Returns whether the IME navigation bar is currently shown.
 * The IME navigation bar, used when {@code config_imeDrawsImeNavBar} is set. This does not replace,
 * but rather complements the system navigation bar.
 */
    boolean isShown() {
        return mImpl.isShown();
    }

    String toDebugString() {
        return mImpl.toDebugString();
    }

    private static final class Impl implements Callback, Window.DecorCallback,
final class NavigationBarController implements Window.DecorCallback,
        NavigationBarView.ButtonClickListener {

    private static final int DEFAULT_COLOR_ADAPT_TRANSITION_TIME = 1700;

    // Copied from com.android.systemui.animation.Interpolators#LEGACY_DECELERATE
        private static final Interpolator LEGACY_DECELERATE =
                new PathInterpolator(0f, 0f, 0.2f, 1f);
    private static final Interpolator LEGACY_DECELERATE = new PathInterpolator(0f, 0f, 0.2f, 1f);

    @NonNull
    private final InputMethodService mService;
@@ -166,7 +73,7 @@ final class NavigationBarController {
    @Nullable
    private NavigationBarFrame mNavigationBarFrame;
    @Nullable
        Insets mLastInsets;
    private Insets mLastInsets;

    private boolean mShouldShowImeSwitcherWhenImeIsShown;

@@ -187,7 +94,7 @@ final class NavigationBarController {
    private final Rect mTempRect = new Rect();
    private final int[] mTempPos = new int[2];

        Impl(@NonNull InputMethodService inputMethodService) {
    NavigationBarController(@NonNull InputMethodService inputMethodService) {
        mService = inputMethodService;
    }

@@ -275,9 +182,8 @@ final class NavigationBarController {
                // IME navigation bar.
                boolean visible = insets.isVisible(captionBar());
                mNavigationBarFrame.setVisibility(visible ? View.VISIBLE : View.GONE);
                    checkCustomImeSwitcherButtonRequestedVisible(
                            mShouldShowImeSwitcherWhenImeIsShown, mImeDrawsImeNavBar,
                            !visible /* imeNavBarNotVisible */);
                checkCustomImeSwitcherButtonRequestedVisible(mShouldShowImeSwitcherWhenImeIsShown,
                        mImeDrawsImeNavBar, !visible /* imeNavBarNotVisible */);
            }
            return view.onApplyWindowInsets(insets);
        });
@@ -295,8 +201,12 @@ final class NavigationBarController {
        mNavigationBarFrame = null;
    }

        @Override
        public void updateInsets(@NonNull InputMethodService.Insets originalInsets) {
    /**
     * Update the given insets to be at least as big as the IME navigation bar, when visible.
     *
     * @param originalInsets the insets to check and modify to include the IME navigation bar.
     */
    void updateInsets(@NonNull InputMethodService.Insets originalInsets) {
        if (!mImeDrawsImeNavBar || mNavigationBarFrame == null
                || mNavigationBarFrame.getVisibility() != View.VISIBLE
                || mService.isFullscreenMode()) {
@@ -313,8 +223,7 @@ final class NavigationBarController {
        }
    }

        @Override
        public void updateTouchableInsets(@NonNull InputMethodService.Insets originalInsets,
    void updateTouchableInsets(@NonNull InputMethodService.Insets originalInsets,
            @NonNull ViewTreeObserver.InternalInsetsInfo dest) {
        if (!mImeDrawsImeNavBar || mNavigationBarFrame == null) {
            return;
@@ -433,23 +342,20 @@ final class NavigationBarController {
        });
    }

        @Override
        public void onSoftInputWindowCreated(@NonNull SoftInputWindow softInputWindow) {
    void onSoftInputWindowCreated(@NonNull SoftInputWindow softInputWindow) {
        final Window window = softInputWindow.getWindow();
        mAppearance = window.getSystemBarAppearance();
        window.setDecorCallback(this);
    }

        @Override
        public void onViewInitialized() {
    void onViewInitialized() {
        if (mDestroyed) {
            return;
        }
        installNavigationBarFrameIfNecessary();
    }

        @Override
        public void onDestroy() {
    void onDestroy() {
        if (mDestroyed) {
            return;
        }
@@ -460,8 +366,7 @@ final class NavigationBarController {
        mDestroyed = true;
    }

        @Override
        public void onWindowShown() {
    void onWindowShown() {
        if (mDestroyed || !mImeDrawsImeNavBar || mNavigationBarFrame == null) {
            return;
        }
@@ -487,8 +392,7 @@ final class NavigationBarController {
        }
    }

        @Override
        public void onNavButtonFlagsChanged(@InputMethodNavButtonFlags int navButtonFlags) {
    void onNavButtonFlagsChanged(@InputMethodNavButtonFlags int navButtonFlags) {
        if (mDestroyed) {
            return;
        }
@@ -624,10 +528,11 @@ final class NavigationBarController {
                : 0;
    }

        @Override
        public boolean isShown() {
            return mNavigationBarFrame != null
                    && mNavigationBarFrame.getVisibility() == View.VISIBLE;
    /**
     * Returns whether the IME navigation bar is currently shown.
     */
    boolean isShown() {
        return mNavigationBarFrame != null && mNavigationBarFrame.getVisibility() == View.VISIBLE;
    }

    /**
@@ -657,12 +562,10 @@ final class NavigationBarController {
        }
    }

        @Override
        public String toDebugString() {
    String toDebugString() {
        return "{mImeDrawsImeNavBar=" + mImeDrawsImeNavBar
                + " mNavigationBarFrame=" + mNavigationBarFrame
                    + " mShouldShowImeSwitcherWhenImeIsShown="
                    + mShouldShowImeSwitcherWhenImeIsShown
                + " mShouldShowImeSwitcherWhenImeIsShown=" + mShouldShowImeSwitcherWhenImeIsShown
                + " mCustomImeSwitcherButtonRequestedVisible="
                + mCustomImeSwitcherButtonRequestedVisible
                + " mAppearance=0x" + Integer.toHexString(mAppearance)
@@ -671,4 +574,3 @@ final class NavigationBarController {
                + "}";
    }
}
}
+0 −11
Original line number Diff line number Diff line
@@ -214,17 +214,6 @@ flag {
  }
}

flag {
    name: "disallow_disabling_ime_navigation_bar"
    namespace: "input_method"
    description: "Disallows disabling the IME navigation bar through canImeRenderGesturalNavButtons"
    bug: "402442590"
    is_fixed_read_only: true
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
  name: "disable_ime_restore_on_activity_create"
  namespace: "input_method"
+0 −4
Original line number Diff line number Diff line
@@ -26,10 +26,6 @@ import java.lang.annotation.Retention;
 * A set of flags notified from {@link com.android.server.inputmethod.InputMethodManagerService} to
 * {@link android.inputmethodservice.InputMethodService} regarding how
 * {@link android.inputmethodservice.NavigationBarController} should behave.
 *
 * <p>These flags will take effect when and only when
 * {@link android.inputmethodservice.InputMethodService#canImeRenderGesturalNavButtons} returns
 * {@code true}.</p>
 */
@Retention(SOURCE)
@IntDef(flag = true, value = {
+1 −13
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.systemui.navigationbar.views;
import static android.app.StatusBarManager.NAVBAR_BACK_DISMISS_IME;
import static android.app.StatusBarManager.NAVBAR_IME_SWITCHER_BUTTON_VISIBLE;
import static android.app.StatusBarManager.NAVBAR_IME_VISIBLE;
import static android.inputmethodservice.InputMethodService.canImeRenderGesturalNavButtons;
import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;

import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_HOME_DISABLED;
@@ -170,16 +169,6 @@ public class NavigationBarView extends FrameLayout {
    private ScreenPinningNotify mScreenPinningNotify;
    private boolean mScreenPinningActive = false;

    /**
     * {@code true} if the IME can render the back button and the IME switcher button.
     *
     * <p>The value must be used when and only when
     * {@link com.android.systemui.shared.system.QuickStepContract#isGesturalMode(int)} returns
     * {@code true}</p>
     *
     * <p>Cache the value here for better performance.</p>
     */
    private final boolean mImeCanRenderGesturalNavButtons = canImeRenderGesturalNavButtons();
    private Gefingerpoken mTouchHandler;
    private boolean mLauncherProxyEnabled;
    private boolean mShowSwipeUpUi;
@@ -674,8 +663,7 @@ public class NavigationBarView extends FrameLayout {
     * Returns whether the IME is currently visible and drawing the nav buttons.
     */
    boolean isImeRenderingNavButtons() {
        return mImeDrawsImeNavBar && mImeCanRenderGesturalNavButtons
                && (mNavbarFlags & NAVBAR_IME_VISIBLE) != 0;
        return mImeDrawsImeNavBar && (mNavbarFlags & NAVBAR_IME_VISIBLE) != 0;
    }

    @VisibleForTesting