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

Commit a201f212 authored by Ming-Shin Lu's avatar Ming-Shin Lu
Browse files

Hide soft-keyboard when no editor is focused

In case seeing the unexpected fallback keyboard layout when focusing to
the window without an editor from the app has shown the IME.

Note that this behaviour change affects when the IME focus switching to
the next window with following configurations from an IME shown window:
  1) SOFT_INPUT_STATE_UNCHANGED state without an editor
  2) SOFT_INPUT_STATE_VISIBLE state without an editor
  3) SOFT_INPUT_STATE_ALWAYS_VISIBLE state without an editor

Also, we guarded this platform behavior with DeviceConfig platform flag
in input method manager namespace.

Fix: 240701729
Bug: 243897178
Test: manual as issue steps
  1) In Launcher, swiping up to enter all apps page.
  2) Tap the search bar to show IME
  3) Type "Keep" to show Keeps app's shortcut
  4) Tap Keeps app's shortcut
  5) Verify IME won't be shown on top of Keeps app's activity
     (As the app set SOFT_INPUT_STATE_UNCHANGED without focusing an
      editor by default)
Test: atest KeyboardVisbilityControltest#\
         ImeInvisible_softInputAdjustNothingFromImeShownApp
Change-Id: I0c502bec5c5e21dabde08d610a9a1969c1229b08
parent 4a8abca2
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -2160,10 +2160,15 @@ package android.provider {
    field public static final String NAMESPACE_APP_COMPAT_OVERRIDES = "app_compat_overrides";
    field public static final String NAMESPACE_CONSTRAIN_DISPLAY_APIS = "constrain_display_apis";
    field public static final String NAMESPACE_DEVICE_IDLE = "device_idle";
    field public static final String NAMESPACE_INPUT_METHOD_MANAGER = "input_method_manager";
    field public static final String NAMESPACE_JOB_SCHEDULER = "jobscheduler";
    field public static final String NAMESPACE_SELECTION_TOOLBAR = "selection_toolbar";
  }

  public interface InputMethodManagerDeviceConfig {
    field public static final String KEY_HIDE_IME_WHEN_NO_EDITOR_FOCUS = "hide_ime_when_no_editor_focus";
  }

  public final class Settings {
    field public static final int RESET_MODE_PACKAGE_DEFAULTS = 1; // 0x1
  }
+8 −0
Original line number Diff line number Diff line
@@ -775,6 +775,14 @@ public final class DeviceConfig {
     */
    public static final String NAMESPACE_WEAR = "wear";

    /**
     * Namespace for the input method manager platform features.
     *
     * @hide
     */
    @TestApi
    public static final String NAMESPACE_INPUT_METHOD_MANAGER = "input_method_manager";

    private static final Object sLock = new Object();
    @GuardedBy("sLock")
    private static ArrayMap<OnPropertiesChangedListener, Pair<String, Executor>> sListeners =
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.provider;

import android.annotation.TestApi;

/**
 * Interface for accessing keys belonging to {@link DeviceConfig#NAMESPACE_INPUT_METHOD_MANAGER}.
 * @hide
 */
@TestApi
public interface InputMethodManagerDeviceConfig {
    /**
     * Whether the IME should be hidden when the window gained focus without an editor focused.
     */
    String KEY_HIDE_IME_WHEN_NO_EDITOR_FOCUS = "hide_ime_when_no_editor_focus";
}
+2 −0
Original line number Diff line number Diff line
@@ -254,6 +254,8 @@ public final class InputMethodDebug {
                return "HIDE_SOFT_INPUT_EXTRACT_INPUT_CHANGED";
            case SoftInputShowHideReason.HIDE_SOFT_INPUT_IMM_DEPRECATION:
                return "HIDE_SOFT_INPUT_IMM_DEPRECATION";
            case SoftInputShowHideReason.HIDE_WINDOW_GAINED_FOCUS_WITHOUT_EDITOR:
                return "HIDE_WINDOW_GAINED_FOCUS_WITHOUT_EDITOR";
            default:
                return "Unknown=" + reason;
        }
+7 −1
Original line number Diff line number Diff line
@@ -63,7 +63,8 @@ import java.lang.annotation.Retention;
        SoftInputShowHideReason.HIDE_SOFT_INPUT_BY_BACK_KEY,
        SoftInputShowHideReason.HIDE_SOFT_INPUT_IME_TOGGLE_SOFT_INPUT,
        SoftInputShowHideReason.HIDE_SOFT_INPUT_EXTRACT_INPUT_CHANGED,
        SoftInputShowHideReason.HIDE_SOFT_INPUT_IMM_DEPRECATION})
        SoftInputShowHideReason.HIDE_SOFT_INPUT_IMM_DEPRECATION,
        SoftInputShowHideReason.HIDE_WINDOW_GAINED_FOCUS_WITHOUT_EDITOR})
public @interface SoftInputShowHideReason {
    /** Show soft input by {@link android.view.inputmethod.InputMethodManager#showSoftInput}. */
    int SHOW_SOFT_INPUT = 0;
@@ -247,4 +248,9 @@ public @interface SoftInputShowHideReason {
     * {@link InputMethodManager#hideSoftInputFromInputMethod(IBinder, int)}.
     */
    int HIDE_SOFT_INPUT_IMM_DEPRECATION = 31;

    /**
     * Hide soft input when the window gained focus without an editor from the IME shown window.
     */
    int HIDE_WINDOW_GAINED_FOCUS_WITHOUT_EDITOR = 32;
}
Loading