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

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

Add finishTrackingPendingImeVisibilityRequests

This adds a new test API on ImeTrackerService, along the lines
of hasPendingImeVisibilityRequests, to finish tracking any pending
IME requests and reset the state of ImeTrackerService. This should
fix any issues where other test suites finish with outstanding IME
requests, which could break InputMethodStatsTest.

Bug: 328861282
Test: atest InputMethodStatsTest
Change-Id: I6fd4558755a98ffa9148124101a186c21a00d1da
parent 4888f41d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -3943,6 +3943,7 @@ package android.view.inputmethod {

  public final class InputMethodManager {
    method @RequiresPermission(android.Manifest.permission.TEST_INPUT_METHOD) public void addVirtualStylusIdForTestSession();
    method @RequiresPermission(android.Manifest.permission.TEST_INPUT_METHOD) public void finishTrackingPendingImeVisibilityRequests();
    method public int getDisplayId();
    method @FlaggedApi("android.view.inputmethod.imm_userhandle_hostsidetests") @NonNull @RequiresPermission(value=android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional=true) public java.util.List<android.view.inputmethod.InputMethodInfo> getEnabledInputMethodListAsUser(@NonNull android.os.UserHandle);
    method @FlaggedApi("android.view.inputmethod.imm_userhandle_hostsidetests") @NonNull @RequiresPermission(value=android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, conditional=true) public java.util.List<android.view.inputmethod.InputMethodSubtype> getEnabledInputMethodSubtypeListAsUser(@NonNull String, boolean, @NonNull android.os.UserHandle);
+14 −0
Original line number Diff line number Diff line
@@ -769,6 +769,20 @@ final class IInputMethodManagerGlobalInvoker {
        }
    }

    @AnyThread
    @RequiresPermission(Manifest.permission.TEST_INPUT_METHOD)
    static void finishTrackingPendingImeVisibilityRequests() {
        final var service = getImeTrackerService();
        if (service == null) {
            return;
        }
        try {
            service.finishTrackingPendingImeVisibilityRequests();
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }

    @AnyThread
    @Nullable
    private static IImeTracker getImeTrackerService() {
+13 −0
Original line number Diff line number Diff line
@@ -4319,6 +4319,19 @@ public final class InputMethodManager {
        return IInputMethodManagerGlobalInvoker.hasPendingImeVisibilityRequests();
    }

    /**
     * A test API for CTS to finish the tracking of any pending IME visibility requests. This
     * won't stop the actual requests, but allows resetting the state when starting up test runs.
     *
     * @hide
     */
    @SuppressLint("UnflaggedApi") // @TestApi without associated feature.
    @TestApi
    @RequiresPermission(Manifest.permission.TEST_INPUT_METHOD)
    public void finishTrackingPendingImeVisibilityRequests() {
        IInputMethodManagerGlobalInvoker.finishTrackingPendingImeVisibilityRequests();
    }

    /**
     * Show the settings for enabling subtypes of the specified input method.
     *
+9 −0
Original line number Diff line number Diff line
@@ -86,4 +86,13 @@ interface IImeTracker {
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
            + "android.Manifest.permission.TEST_INPUT_METHOD)")
    boolean hasPendingImeVisibilityRequests();

    /**
     * Finishes the tracking of any pending IME visibility requests. This won't stop the actual
     * requests, but allows resetting the state when starting up test runs.
     */
    @EnforcePermission("TEST_INPUT_METHOD")
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(value = "
            + "android.Manifest.permission.TEST_INPUT_METHOD)")
    oneway void finishTrackingPendingImeVisibilityRequests();
}
+9 −0
Original line number Diff line number Diff line
@@ -165,6 +165,15 @@ public final class ImeTrackerService extends IImeTracker.Stub {
        }
    }

    @EnforcePermission(Manifest.permission.TEST_INPUT_METHOD)
    @Override
    public void finishTrackingPendingImeVisibilityRequests() {
        super.finishTrackingPendingImeVisibilityRequests_enforcePermission();
        synchronized (mLock) {
            mHistory.mLiveEntries.clear();
        }
    }

    /**
     * A circular buffer storing the most recent few {@link ImeTracker.Token} entries information.
     */