Merge "Add a sysprop to disable SysUI's nav buttons when IME is shown"

This commit is contained in:
TreeHugger Robot
2022-01-13 05:17:48 +00:00
committed by Android (Google) Code Review
2 changed files with 61 additions and 3 deletions

View File

@@ -54,6 +54,7 @@ import static android.view.WindowInsets.Type.statusBars;
import static java.lang.annotation.RetentionPolicy.SOURCE;
import android.annotation.AnyThread;
import android.annotation.CallSuper;
import android.annotation.DrawableRes;
import android.annotation.IntDef;
@@ -83,6 +84,7 @@ import android.os.Handler;
import android.os.IBinder;
import android.os.ResultReceiver;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.Trace;
import android.provider.Settings;
import android.text.InputType;
@@ -301,6 +303,44 @@ 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";
/**
* 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() {
return SystemProperties.getBoolean(PROP_CAN_RENDER_GESTURAL_NAV_BUTTONS, false);
}
/**
* Allows the system to optimize the back button affordance based on the presence of software
* keyboard.

View File

@@ -16,6 +16,7 @@
package com.android.systemui.navigationbar;
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;
@@ -185,6 +186,17 @@ public class NavigationBarView extends FrameLayout implements
@Nullable
private Rect mOrientedHandleSamplingRegion;
/**
* {@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 class NavTransitionListener implements TransitionListener {
private boolean mBackTransitioning;
private boolean mHomeAppearing;
@@ -760,9 +772,14 @@ public class NavigationBarView extends FrameLayout implements
updateRecentsIcon();
boolean isImeRenderingNavButtons = isGesturalMode(mNavBarMode)
&& mImeCanRenderGesturalNavButtons;
// Update IME button visibility, a11y and rotate button always overrides the appearance
mContextualButtonGroup.setButtonVisibility(R.id.ime_switcher,
(mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_IME_SHOWN) != 0);
boolean disableImeSwitcher =
(mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_IME_SHOWN) == 0
|| isImeRenderingNavButtons;
mContextualButtonGroup.setButtonVisibility(R.id.ime_switcher, !disableImeSwitcher);
mBarTransitions.reapplyDarkIntensity();
@@ -777,7 +794,8 @@ public class NavigationBarView extends FrameLayout implements
&& ((mDisabledFlags & View.STATUS_BAR_DISABLE_HOME) != 0);
boolean disableBack = !useAltBack && (mEdgeBackGestureHandler.isHandlingGestures()
|| ((mDisabledFlags & View.STATUS_BAR_DISABLE_BACK) != 0));
|| ((mDisabledFlags & View.STATUS_BAR_DISABLE_BACK) != 0))
|| isImeRenderingNavButtons;
// When screen pinning, don't hide back and home when connected service or back and
// recents buttons when disconnected from launcher service in screen pinning mode,