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

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

IMF cleanups, nits and nullability fixes 1/n

This clarifies the nullability of some fields, and removes unnecessary
null checks, related to ClientController, ClientState, ImeBindingState,
SessionState and AccessibilitySessionState.

Additionally explicilty marks the fallbackInputConnection fields. This
also removed checks around the nullability of the
IInputMethodClientInvoker in IMMS, as this is always a non-null value.

Flag: EXEMPT cleanup
Bug: 281029564
Test: atest FrameworksInputMethodSystemServerTests
Change-Id: Ib4de661c1a55eb3b618659b21ab91a20d76ffde6
parent 4fb4149e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -512,6 +512,7 @@ public final class InputMethodManager {
    final H mH;

    // Our generic input connection if the current target does not have its own.
    @NonNull
    private final RemoteInputConnectionImpl mFallbackInputConnection;

    private final int mDisplayId;
+14 −12
Original line number Diff line number Diff line
@@ -43,21 +43,23 @@ final class ClientController {
    @GuardedBy("ImfLock.class")
    private final List<ClientControllerCallback> mCallbacks = new ArrayList<>();

    @NonNull
    private final PackageManagerInternal mPackageManagerInternal;

    interface ClientControllerCallback {

        void onClientRemoved(ClientState client);
        void onClientRemoved(@NonNull ClientState client);
    }

    ClientController(PackageManagerInternal packageManagerInternal) {
    ClientController(@NonNull PackageManagerInternal packageManagerInternal) {
        mPackageManagerInternal = packageManagerInternal;
    }

    @GuardedBy("ImfLock.class")
    ClientState addClient(IInputMethodClientInvoker clientInvoker,
            IRemoteInputConnection inputConnection, int selfReportedDisplayId, int callerUid,
            int callerPid) {
    @NonNull
    ClientState addClient(@NonNull IInputMethodClientInvoker clientInvoker,
            @NonNull IRemoteInputConnection fallbackInputConnection, int selfReportedDisplayId,
            int callerUid, int callerPid) {
        final IBinder.DeathRecipient deathRecipient = () -> {
            // Exceptionally holding ImfLock here since this is a internal lambda expression.
            synchronized (ImfLock.class) {
@@ -90,15 +92,15 @@ final class ClientController {
        // have the client crash.  Thus we do not verify the display ID at all here.  Instead we
        // later check the display ID every time the client needs to interact with the specified
        // display.
        final ClientState cs = new ClientState(clientInvoker, inputConnection,
                callerUid, callerPid, selfReportedDisplayId, deathRecipient);
        final var cs = new ClientState(clientInvoker, fallbackInputConnection, callerUid, callerPid,
                selfReportedDisplayId, deathRecipient);
        mClients.put(clientInvoker.asBinder(), cs);
        return cs;
    }

    @VisibleForTesting
    @GuardedBy("ImfLock.class")
    boolean removeClient(IInputMethodClient client) {
    boolean removeClient(@NonNull IInputMethodClient client) {
        return removeClientAsBinder(client.asBinder());
    }

@@ -116,7 +118,7 @@ final class ClientController {
    }

    @GuardedBy("ImfLock.class")
    void addClientControllerCallback(ClientControllerCallback callback) {
    void addClientControllerCallback(@NonNull ClientControllerCallback callback) {
        mCallbacks.add(callback);
    }

@@ -127,15 +129,15 @@ final class ClientController {
    }

    @GuardedBy("ImfLock.class")
    void forAllClients(Consumer<ClientState> consumer) {
    void forAllClients(@NonNull Consumer<ClientState> consumer) {
        for (int i = 0; i < mClients.size(); i++) {
            consumer.accept(mClients.valueAt(i));
        }
    }

    @GuardedBy("ImfLock.class")
    boolean verifyClientAndPackageMatch(
            @NonNull IInputMethodClient client, @NonNull String packageName) {
    boolean verifyClientAndPackageMatch(@NonNull IInputMethodClient client,
            @NonNull String packageName) {
        final ClientState cs = mClients.get(client.asBinder());
        if (cs == null) {
            throw new IllegalArgumentException("unknown client " + client.asBinder());
+21 −13
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.inputmethod;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.IBinder;
import android.util.SparseArray;
import android.view.inputmethod.InputBinding;
@@ -24,12 +26,17 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.inputmethod.IRemoteInputConnection;

final class ClientState {

    @NonNull
    final IInputMethodClientInvoker mClient;
    @NonNull
    final IRemoteInputConnection mFallbackInputConnection;
    final int mUid;
    final int mPid;
    final int mSelfReportedDisplayId;
    @NonNull
    final InputBinding mBinding;
    @NonNull
    final IBinder.DeathRecipient mClientDeathRecipient;

    @GuardedBy("ImfLock.class")
@@ -39,30 +46,31 @@ final class ClientState {
    boolean mSessionRequestedForAccessibility;

    @GuardedBy("ImfLock.class")
    @Nullable
    InputMethodManagerService.SessionState mCurSession;

    @GuardedBy("ImfLock.class")
    SparseArray<InputMethodManagerService.AccessibilitySessionState> mAccessibilitySessions =
    @NonNull
    final SparseArray<InputMethodManagerService.AccessibilitySessionState> mAccessibilitySessions =
            new SparseArray<>();

    @Override
    public String toString() {
        return "ClientState{" + Integer.toHexString(
                System.identityHashCode(this)) + " mUid=" + mUid
                + " mPid=" + mPid + " mSelfReportedDisplayId=" + mSelfReportedDisplayId + "}";
    }

    ClientState(IInputMethodClientInvoker client,
            IRemoteInputConnection fallbackInputConnection,
            int uid, int pid, int selfReportedDisplayId,
            IBinder.DeathRecipient clientDeathRecipient) {
    ClientState(@NonNull IInputMethodClientInvoker client,
            @NonNull IRemoteInputConnection fallbackInputConnection, int uid, int pid,
            int selfReportedDisplayId, @NonNull IBinder.DeathRecipient clientDeathRecipient) {
        mClient = client;
        mFallbackInputConnection = fallbackInputConnection;
        mUid = uid;
        mPid = pid;
        mSelfReportedDisplayId = selfReportedDisplayId;
        mBinding = new InputBinding(null /*conn*/, mFallbackInputConnection.asBinder(), mUid,
        mBinding = new InputBinding(null /* conn */, fallbackInputConnection.asBinder(), mUid,
                mPid);
        mClientDeathRecipient = clientDeathRecipient;
    }

    @Override
    public String toString() {
        return "ClientState{" + Integer.toHexString(System.identityHashCode(this))
                + " mUid=" + mUid + " mPid=" + mPid
                + " mSelfReportedDisplayId=" + mSelfReportedDisplayId + "}";
    }
}
+5 −11
Original line number Diff line number Diff line
@@ -58,23 +58,17 @@ final class IInputMethodClientInvoker {
    private final Handler mHandler;

    @AnyThread
    @Nullable
    static IInputMethodClientInvoker create(@Nullable IInputMethodClient inputMethodClient,
    @NonNull
    static IInputMethodClientInvoker create(@NonNull IInputMethodClient inputMethodClient,
            @NonNull Handler handler) {
        if (inputMethodClient == null) {
            return null;
        }
        final boolean isProxy = Binder.isProxy(inputMethodClient);
        return new IInputMethodClientInvoker(inputMethodClient, isProxy, isProxy ? null : handler);
    }

    @AnyThread
    @Nullable
    static IInputMethodClientInvoker create$ravenwood(
            @Nullable IInputMethodClient inputMethodClient, @NonNull Handler handler) {
        if (inputMethodClient == null) {
            return null;
        }
    @NonNull
    static IInputMethodClientInvoker create$ravenwood(@NonNull IInputMethodClient inputMethodClient,
            @NonNull Handler handler) {
        return new IInputMethodClientInvoker(inputMethodClient, true, null);
    }

+6 −6
Original line number Diff line number Diff line
@@ -89,8 +89,8 @@ final class IInputMethodManagerImpl extends IInputMethodManager.Stub {

    @BinderThread
    interface Callback {
        void addClient(IInputMethodClient client, IRemoteInputConnection inputConnection,
                int selfReportedDisplayId);
        void addClient(@NonNull IInputMethodClient client,
                @NonNull IRemoteInputConnection inputConnection, int selfReportedDisplayId);

        InputMethodInfo getCurrentInputMethodInfoAsUser(@UserIdInt int userId);

@@ -242,9 +242,9 @@ final class IInputMethodManagerImpl extends IInputMethodManager.Stub {
    }

    @Override
    public void addClient(IInputMethodClient client, IRemoteInputConnection inputmethod,
            int untrustedDisplayId) {
        mCallback.addClient(client, inputmethod, untrustedDisplayId);
    public void addClient(@NonNull IInputMethodClient client,
            @NonNull IRemoteInputConnection fallbackInputConnection, int untrustedDisplayId) {
        mCallback.addClient(client, fallbackInputConnection, untrustedDisplayId);
    }

    @Override
@@ -414,7 +414,7 @@ final class IInputMethodManagerImpl extends IInputMethodManager.Stub {
    }

    @Override
    public void reportPerceptibleAsync(IBinder windowToken, boolean perceptible) {
    public void reportPerceptibleAsync(@NonNull IBinder windowToken, boolean perceptible) {
        mCallback.reportPerceptibleAsync(windowToken, perceptible);
    }

Loading