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

Commit 6a350cda authored by Cosmin Băieș's avatar Cosmin Băieș
Browse files

Don't show IME Switcher settings button if locked

While the screen is locked, pressing on the settings button from the IME
Switcher menu has no effect, as we cannot launch the IME settings app in
that state. This removes the button if the screen is locked.

Flag: EXEMPT bugfix
Test: atest InputMethodManagerTest#testInputMethodPickerNoLanguageSettingsWhenScreenLocked
Bug: 397612817
Change-Id: I48816c18986e0202e4be415467a9101caa7469b3
parent 4fb4149e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -4964,8 +4964,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                }
            }

            mMenuControllerNew.show(imList, lastInputMethodId, selectedSubtypeIndex, displayId,
                    userId);
            mMenuControllerNew.show(imList, lastInputMethodId, selectedSubtypeIndex, isScreenLocked,
                    displayId, userId);
        } else {
            mMenuController.showInputMethodMenuLocked(showAuxSubtypes, displayId,
                    lastInputMethodId, lastInputMethodSubtypeIndex, imList, userId);
+13 −10
Original line number Diff line number Diff line
@@ -87,12 +87,14 @@ final class InputMethodMenuControllerNew {
     * @param selectedSubtypeIndex the index of the selected subtype in the input method's array of
     *                             subtypes, or {@link InputMethodUtils#NOT_A_SUBTYPE_INDEX} if no
     *                             subtype is selected.
     * @param isScreenLocked       whether the screen is current locked.
     * @param displayId            the ID of the display where the menu was requested.
     * @param userId               the ID of the user that requested the menu.
     */
    @RequiresPermission(allOf = {INTERACT_ACROSS_USERS, HIDE_OVERLAY_WINDOWS})
    void show(@NonNull List<ImeSubtypeListItem> items, @Nullable String selectedImeId,
            int selectedSubtypeIndex, int displayId, @UserIdInt int userId) {
            int selectedSubtypeIndex, boolean isScreenLocked, int displayId,
            @UserIdInt int userId) {
        // Hide the menu in case it was already showing.
        hide(displayId, userId);

@@ -133,7 +135,7 @@ final class InputMethodMenuControllerNew {
        recyclerView.requestFocus();

        final var selectedItem = selectedIndex > -1 ? menuItems.get(selectedIndex) : null;
        updateLanguageSettingsButton(selectedItem, contentView, displayId, userId);
        updateLanguageSettingsButton(selectedItem, contentView, isScreenLocked, displayId, userId);

        builder.setOnCancelListener(dialog -> hide(displayId, userId));
        mMenuItems = menuItems;
@@ -280,23 +282,24 @@ final class InputMethodMenuControllerNew {

    /**
     * Updates the visibility of the Language Settings button to visible if the currently selected
     * item specifies a (language) settings activity and the device is provisioned. Otherwise,
     * the button won't be shown.
     * item specifies a (language) settings activity, the screen is not locked and the device is
     * provisioned. Otherwise, the button won't be shown.
     *
     * @param selectedItem   the currently selected item, or {@code null} if no item is selected.
     * @param view           the menu dialog view.
     * @param isScreenLocked whether the screen is currently locked.
     * @param displayId      the ID of the display where the menu was requested.
     * @param userId         the ID of the user that requested the menu.
     */
    @RequiresPermission(allOf = {INTERACT_ACROSS_USERS})
    private void updateLanguageSettingsButton(@Nullable MenuItem selectedItem, @NonNull View view,
            int displayId, @UserIdInt int userId) {
            boolean isScreenLocked, int displayId, @UserIdInt int userId) {
        final var settingsIntent = (selectedItem instanceof SubtypeItem selectedSubtypeItem)
                ? selectedSubtypeItem.mImi.createImeLanguageSettingsActivityIntent() : null;
        final boolean isDeviceProvisioned = Settings.Global.getInt(
                view.getContext().getContentResolver(), Settings.Global.DEVICE_PROVISIONED,
                0) != 0;
        final boolean hasButton = settingsIntent != null && isDeviceProvisioned;
        final boolean hasButton = settingsIntent != null && !isScreenLocked && isDeviceProvisioned;
        final View buttonBar = view.requireViewById(com.android.internal.R.id.button_bar);
        final Button button = view.requireViewById(com.android.internal.R.id.button1);
        final RecyclerView recyclerView = view.requireViewById(com.android.internal.R.id.list);