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

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

Fix some issues in FrameworkInputMethodSystemServerTests

- Fix wrong src path in InputMethodSystemServerTests/Android.bp by CL[1]
- In IMMS, Make ImeTrackerService by CL[2] can inject a test looper, in
  case InputMethodManagerServiceTestBase#setUp got exception by null
  looper queue.
- Remove unused test method IMMS#getVisibilityStateComputer().
- Add ImfLock block in IMMS#getVisibilityApplier for fixing linter
  check.
- Fix a potential NPE when calling mImeTrackerService.onImmsUpdate that
  the statsToken may null during testing.
- Remove duplicate calls in testApplyImeVisibility_throwForInvalidState.
- Add missed showFlag parameters in testPerformShowIme.
- Fix verifyShowSoftInput logic when no need to verify showFlags cases
- Add a regression unit test In ImeVisibilityStateComputerTest for
  Bug 265439883:
  testComputeState_lastImeRequestedVisible_preserved_When_StateUnChanged

 [1]: I84f1a1b25eef4a757d8da27807285e08417458b4
 [2]: I432bab2de58a9df2c421bb00946ab211de445660

Bug: 246309664
Bug: 240359838
Test: atest FrameworkInputMethodSystemServerTests all passed
Change-Id: I0890641868f9200c613af0d6ee7014e4c7b1e7ed
parent 5975f9dc
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -59,13 +59,16 @@ public final class ImeTrackerService extends IImeTracker.Stub {
    private static final long TIMEOUT_MS = 10_000;

    /** Handler for registering timeouts for live entries. */
    private final Handler mHandler =
            new Handler(Looper.myLooper(), null /* callback */, true /* async */);
    private final Handler mHandler;

    /** Singleton instance of the History. */
    @GuardedBy("ImeTrackerService.this")
    private final History mHistory = new History();

    ImeTrackerService(@NonNull Looper looper) {
        mHandler = new Handler(looper, null /* callback */, true /* async */);
    }

    @NonNull
    @Override
    public synchronized IBinder onRequestShow(int uid, @ImeTracker.Origin int origin,
+10 −8
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ import android.os.Debug;
import android.os.Handler;
import android.os.IBinder;
import android.os.LocaleList;
import android.os.Looper;
import android.os.Message;
import android.os.Parcel;
import android.os.Process;
@@ -1105,7 +1106,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            new SoftInputShowHideHistory();

    @NonNull
    private final ImeTrackerService mImeTrackerService = new ImeTrackerService();
    private final ImeTrackerService mImeTrackerService;

    class SettingsObserver extends ContentObserver {
        int mUserId;
@@ -1662,6 +1663,8 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                                true /* allowIo */);
        thread.start();
        mHandler = Handler.createAsync(thread.getLooper(), this);
        mImeTrackerService = new ImeTrackerService(serviceThreadForTesting != null
                ? serviceThreadForTesting.getLooper() : Looper.getMainLooper());
        // Note: SettingsObserver doesn't register observers in its constructor.
        mSettingsObserver = new SettingsObserver(mHandler);
        mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
@@ -4612,8 +4615,10 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                info.requestWindowName, info.imeControlTargetName, info.imeLayerTargetName,
                info.imeSurfaceParentName));

        if (statsToken != null) {
            mImeTrackerService.onImmsUpdate(statsToken.mBinder, info.requestWindowName);
        }
    }

    @BinderThread
    private void hideMySoftInput(@NonNull IBinder token, int flags,
@@ -4653,15 +4658,12 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
        Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
    }

    @VisibleForTesting
    ImeVisibilityStateComputer getVisibilityStateComputer() {
        return mVisibilityStateComputer;
    }

    @VisibleForTesting
    ImeVisibilityApplier getVisibilityApplier() {
        synchronized (ImfLock.class) {
            return mVisibilityApplier;
        }
    }

    @GuardedBy("ImfLock.class")
    void setEnabledSessionLocked(SessionState session) {
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ android_test {
    ],

    srcs: [
        "src/server/**/*.java",
        "src/com/android/server/inputmethod/**/*.java",
    ],

    static_libs: [
+8 −3
Original line number Diff line number Diff line
@@ -65,19 +65,24 @@ public class DefaultImeVisibilityApplierTest extends InputMethodManagerServiceTe

    @Test
    public void testPerformShowIme() throws Exception {
        mVisibilityApplier.performShowIme(mWindowToken, null, null, SHOW_SOFT_INPUT);
        synchronized (ImfLock.class) {
            mVisibilityApplier.performShowIme(mWindowToken, null /* statsToken */,
                    InputMethodManager.SHOW_IMPLICIT, null, SHOW_SOFT_INPUT);
        }
        verifyShowSoftInput(false, true, InputMethodManager.SHOW_IMPLICIT);
    }

    @Test
    public void testPerformHideIme() throws Exception {
        mVisibilityApplier.performHideIme(mWindowToken, null, null, HIDE_SOFT_INPUT);
        synchronized (ImfLock.class) {
            mVisibilityApplier.performHideIme(mWindowToken, null /* statsToken */, null,
                    HIDE_SOFT_INPUT);
        }
        verifyHideSoftInput(false, true);
    }

    @Test
    public void testApplyImeVisibility_throwForInvalidState() {
        mVisibilityApplier.applyImeVisibility(mWindowToken, null, STATE_INVALID);
        assertThrows(IllegalArgumentException.class,
                () -> mVisibilityApplier.applyImeVisibility(mWindowToken, null, STATE_INVALID));
    }
+21 −1
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import static com.android.server.inputmethod.InputMethodManagerService.ImeDispla

import static com.google.common.truth.Truth.assertThat;

import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;
import android.view.inputmethod.InputMethodManager;
@@ -177,9 +178,28 @@ public class ImeVisibilityStateComputerTest extends InputMethodManagerServiceTes
        assertThat(state.getImeDisplayId()).isEqualTo(FALLBACK_DISPLAY_ID);
    }

    private void initImeTargetWindowState(IBinder windowToken) {
    @Test
    public void testComputeState_lastImeRequestedVisible_preserved_When_StateUnChanged() {
        // Assume the last IME targeted window has requested IME visible
        final IBinder lastImeTargetWindowToken = new Binder();
        mInputMethodManagerService.mLastImeTargetWindow = lastImeTargetWindowToken;
        mComputer.requestImeVisibility(lastImeTargetWindowToken, true);
        final ImeTargetWindowState lastState = mComputer.getWindowStateOrNull(
                lastImeTargetWindowToken);
        assertThat(lastState.isRequestedImeVisible()).isTrue();

        // Verify when focusing the next window with STATE_UNCHANGED flag, the last IME
        // visibility state will be preserved to the current window state.
        final ImeTargetWindowState stateWithUnChangedFlag = initImeTargetWindowState(mWindowToken);
        mComputer.computeState(stateWithUnChangedFlag, true /* allowVisible */);
        assertThat(stateWithUnChangedFlag.isRequestedImeVisible()).isEqualTo(
                lastState.isRequestedImeVisible());
    }

    private ImeTargetWindowState initImeTargetWindowState(IBinder windowToken) {
        final ImeTargetWindowState state = new ImeTargetWindowState(SOFT_INPUT_STATE_UNCHANGED,
                0, true, true, true);
        mComputer.setWindowState(windowToken, state);
        return state;
    }
}
Loading