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

Commit 6e2d54e0 authored by Antonio Kantek's avatar Antonio Kantek
Browse files

Use lambda when iterating over clients

Suppress warnings to avoid error prone (falsely) alerting when
accessing ImfLock guarded fields.

Fix: 322816970
Test: atest CtsInputMethodTestCases CtsInputMethodInstallTestCases
Change-Id: Ief7b16317f6d8bbd3a6717903efc5fb385d6caeb
parent 4eac1b08
Loading
Loading
Loading
Loading
+27 −53
Original line number Diff line number Diff line
@@ -2882,16 +2882,12 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
    @GuardedBy("ImfLock.class")
    void clearClientSessionsLocked() {
        if (getCurMethodLocked() != null) {
            // TODO(b/322816970): Replace this with lambda.
            mClientController.forAllClients(new Consumer<ClientState>() {

                @GuardedBy("ImfLock.class")
                @Override
                public void accept(ClientState c) {
            // TODO(b/324907325): Remove the suppress warnings once b/324907325 is fixed.
            @SuppressWarnings("GuardedBy") Consumer<ClientState> clearClientSession = c -> {
                clearClientSessionLocked(c);
                clearClientSessionForAccessibilityLocked(c);
                }
            });
            };
            mClientController.forAllClients(clearClientSession);

            finishSessionLocked(mEnabledSession);
            for (int i = 0; i < mEnabledAccessibilitySessions.size(); i++) {
@@ -4567,15 +4563,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
        super.startImeTrace_enforcePermission();
        ImeTracing.getInstance().startTrace(null /* printwriter */);
        synchronized (ImfLock.class) {
            // TODO(b/322816970): Replace this with lambda.
            mClientController.forAllClients(new Consumer<ClientState>() {

                @GuardedBy("ImfLock.class")
                @Override
                public void accept(ClientState c) {
                    c.mClient.setImeTraceEnabled(true /* enabled */);
                }
            });
            mClientController.forAllClients(c -> c.mClient.setImeTraceEnabled(true /* enabled */));
        }
    }

@@ -4587,15 +4575,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub

        ImeTracing.getInstance().stopTrace(null /* printwriter */);
        synchronized (ImfLock.class) {
            // TODO(b/322816970): Replace this with lambda.
            mClientController.forAllClients(new Consumer<ClientState>() {

                @GuardedBy("ImfLock.class")
                @Override
                public void accept(ClientState c) {
                    c.mClient.setImeTraceEnabled(false /* enabled */);
                }
            });
            mClientController.forAllClients(c -> c.mClient.setImeTraceEnabled(false /* enabled */));
        }
    }

@@ -5829,15 +5809,12 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                // We only have sessions when we bound to an input method. Remove this session
                // from all clients.
                if (getCurMethodLocked() != null) {
                    // TODO(b/322816970): Replace this with lambda.
                    mClientController.forAllClients(new Consumer<ClientState>() {
                    // TODO(b/324907325): Remove the suppress warnings once b/324907325 is fixed.
                    @SuppressWarnings("GuardedBy") Consumer<ClientState> clearClientSession =
                            c -> clearClientSessionForAccessibilityLocked(c,
                                    accessibilityConnectionId);
                    mClientController.forAllClients(clearClientSession);

                        @GuardedBy("ImfLock.class")
                        @Override
                        public void accept(ClientState c) {
                            clearClientSessionForAccessibilityLocked(c, accessibilityConnectionId);
                        }
                    });
                    AccessibilitySessionState session = mEnabledAccessibilitySessions.get(
                            accessibilityConnectionId);
                    if (session != null) {
@@ -6023,12 +6000,8 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
            }
            // Dump ClientController#mClients
            p.println("  ClientStates:");
            // TODO(b/322816970): Replace this with lambda.
            mClientController.forAllClients(new Consumer<ClientState>() {

                @GuardedBy("ImfLock.class")
                @Override
                public void accept(ClientState c) {
            // TODO(b/324907325): Remove the suppress warnings once b/324907325 is fixed.
            @SuppressWarnings("GuardedBy") Consumer<ClientState> clientControllerDump = c -> {
                p.println("  " + c + ":");
                p.println("    client=" + c.mClient);
                p.println("    fallbackInputConnection="
@@ -6039,8 +6012,9 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                        "    sessionRequestedForAccessibility="
                                + c.mSessionRequestedForAccessibility);
                p.println("    curSession=" + c.mCurSession);
                }
            });
            };
            mClientController.forAllClients(clientControllerDump);

            p.println("  mCurMethodId=" + getSelectedMethodIdLocked());
            client = mCurClient;
            p.println("  mCurClient=" + client + " mCurSeq=" + getSequenceNumberLocked());