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

Commit 2cbdbc42 authored by Cosmin Băieș's avatar Cosmin Băieș
Browse files

Modify getShouldShowImeWithHardKeyboard return val

This modifies getShouldShowImeWithHardKeyboardForTesting to return a
nullable type, instead of the primitive boolean. The method is called
during a test teardown, before the IME process is actually stopped.
However, with config_preventImeStartupUnlessTextEditor set, the IME
process receives the onDestroy call as soon as the IME client is
removed. This would lead to a null pointer exception when calling this
getter method, as mSettingsObserver would already be null.

Flag: EXEMPT testfix
Bug: 406501026
Test: manually enable config_preventImeStartupUnlessTextEditor  and run
  atest InputMethodServiceTest#testImeSwitcherMenu_noLanguageSettingsWhenScreenLocked
Change-Id: I8a624268edf34c885627a094a06dbfaee5cd166b
parent 5e4edde8
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -1659,13 +1659,14 @@ public class InputMethodService extends AbstractInputMethodService {

    /**
     * Checks whether the IME should be shown when a hardware keyboard is connected, as configured
     * through {@link Settings.Secure#SHOW_IME_WITH_HARD_KEYBOARD}, for testing purposes only.
     * through {@link Settings.Secure#SHOW_IME_WITH_HARD_KEYBOARD}, for testing purposes only. If
     * {@link #mSettingsObserver} is {@code null}, this will also return {@code null}.
     *
     * @hide
     */
    @VisibleForTesting
    public final boolean getShouldShowImeWithHardKeyboardForTesting() {
        return mSettingsObserver.shouldShowImeWithHardKeyboard();
    public final Boolean getShouldShowImeWithHardKeyboardForTesting() {
        return mSettingsObserver != null ? mSettingsObserver.shouldShowImeWithHardKeyboard() : null;
    }

    /**
+11 −4
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ import android.view.inputmethod.Flags;
import android.view.inputmethod.InputMethodManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.MediumTest;
import androidx.test.platform.app.InstrumentationRegistry;
@@ -162,7 +163,8 @@ public class InputMethodServiceTest {
    private TestActivity mActivity;
    private InputMethodServiceWrapper mInputMethodService;
    private boolean mOriginalVerboseImeTrackerLoggingEnabled;
    private boolean mOriginalShowImeWithHardKeyboardEnabled;
    @Nullable
    private Boolean mOriginalShowImeWithHardKeyboardEnabled;

    @Before
    public void setUp() throws Exception {
@@ -212,7 +214,9 @@ public class InputMethodServiceTest {
            setVerboseImeTrackerLogging(false);
        }
        // Change back the original value of show_ime_with_hard_keyboard in Settings.
        if (mOriginalShowImeWithHardKeyboardEnabled != null) {
            setShowImeWithHardKeyboard(mOriginalShowImeWithHardKeyboardEnabled);
        }
        executeShellCommand("ime disable " + mInputMethodId);
    }

@@ -1393,9 +1397,12 @@ public class InputMethodServiceTest {
            return;
        }

        final boolean currentEnabled =
        final Boolean currentEnabled =
                mInputMethodService.getShouldShowImeWithHardKeyboardForTesting();
        if (currentEnabled != enable) {
        if (currentEnabled == null) {
            // IME is being destroyed, reset the system property without checking the set value.
            executeShellCommand(SET_SHOW_IME_WITH_HARD_KEYBOARD_CMD + " " + (enable ? "1" : "0"));
        } else if (currentEnabled != enable) {
            executeShellCommand(SET_SHOW_IME_WITH_HARD_KEYBOARD_CMD + " " + (enable ? "1" : "0"));
            eventually(() -> assertWithMessage("showImeWithHardKeyboard updated")
                    .that(mInputMethodService.getShouldShowImeWithHardKeyboardForTesting())