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

Commit 8dc058d8 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Annotate lock-free method in InputMethodManagerInternal

This is a follow up CL to my previous CL [1], which attempted to
clarify what InputMethodManagerInternal method take lock internally.

To make code reading easier, this CL makes it clear about what method
internally acquire ImfLock and what method are always thread-safe in
terms of ImfLock.class.

Basically this is a mechanical code refactoring.  There should be no
observable behavior change.

 [1]: I98958e6c149582b0a24997c9ca814e355f8b2a2b
      0fee8d10

Bug: 343601565
Test: presubmit
Change-Id: I8b981d113d4b2664f830ccfaeaf5fe3a5fc5e61c
parent d7d0fd5f
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.inputmethod;

import static java.lang.annotation.RetentionPolicy.SOURCE;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
@@ -30,6 +32,9 @@ import com.android.internal.inputmethod.InlineSuggestionsRequestInfo;
import com.android.internal.inputmethod.SoftInputShowHideReason;
import com.android.server.LocalServices;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.util.Collections;
import java.util.List;

@@ -37,6 +42,16 @@ import java.util.List;
 * Input method manager local system service interface.
 */
public abstract class InputMethodManagerInternal {
    /**
     * Indicates that the method is guaranteed to not require {@link ImfLock}.
     *
     * <p>You can call this method without worrying about system_server lock layering.</p>
     */
    @Retention(SOURCE)
    @Target({ElementType.METHOD})
    public @interface ImfLockFree {
    }

    /**
     * Listener for input method list changed events.
     */
@@ -53,6 +68,7 @@ public abstract class InputMethodManagerInternal {
     *
     * @param interactive the interactive mode parameter
     */
    @ImfLockFree
    public abstract void setInteractive(boolean interactive);

    /**
@@ -61,6 +77,7 @@ public abstract class InputMethodManagerInternal {
     * @param reason               the reason for hiding the current input method
     * @param originatingDisplayId the display ID the request is originated
     */
    @ImfLockFree
    public abstract void hideAllInputMethods(@SoftInputShowHideReason int reason,
            int originatingDisplayId);

@@ -143,6 +160,7 @@ public abstract class InputMethodManagerInternal {
     *
     * @param listener the listener to add
     */
    @ImfLockFree
    public abstract void registerInputMethodListListener(InputMethodListListener listener);

    /**
@@ -178,6 +196,7 @@ public abstract class InputMethodManagerInternal {
     *
     * @param displayId the display hosting the IME window
     */
    @ImfLockFree
    public abstract void removeImeSurface(int displayId);

    /**
@@ -188,12 +207,14 @@ public abstract class InputMethodManagerInternal {
     * @param disableImeIcon indicates whether IME icon should be enabled or not
     * @param displayId      the display for which to update the IME window status
     */
    @ImfLockFree
    public abstract void updateImeWindowStatus(boolean disableImeIcon, int displayId);

    /**
     * Finish stylus handwriting by calling {@link InputMethodService#finishStylusHandwriting()} if
     * there is an ongoing handwriting session.
     */
    @ImfLockFree
    public abstract void maybeFinishStylusHandwriting();

    /**
@@ -240,10 +261,12 @@ public abstract class InputMethodManagerInternal {
     */
    private static final InputMethodManagerInternal NOP =
            new InputMethodManagerInternal() {
                @ImfLockFree
                @Override
                public void setInteractive(boolean interactive) {
                }

                @ImfLockFree
                @Override
                public void hideAllInputMethods(@SoftInputShowHideReason int reason,
                        int originatingDisplayId) {
@@ -282,6 +305,7 @@ public abstract class InputMethodManagerInternal {
                        int deviceId, @Nullable String imeId) {
                }

                @ImfLockFree
                @Override
                public void registerInputMethodListListener(InputMethodListListener listener) {
                }
@@ -300,10 +324,12 @@ public abstract class InputMethodManagerInternal {
                public void onImeParentChanged(int displayId) {
                }

                @ImfLockFree
                @Override
                public void removeImeSurface(int displayId) {
                }

                @ImfLockFree
                @Override
                public void updateImeWindowStatus(boolean disableImeIcon, int displayId) {
                }
@@ -318,6 +344,7 @@ public abstract class InputMethodManagerInternal {
                        @UserIdInt int userId) {
                }

                @ImfLockFree
                @Override
                public void maybeFinishStylusHandwriting() {
                }
+6 −0
Original line number Diff line number Diff line
@@ -5475,12 +5475,14 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.

    private final class LocalServiceImpl extends InputMethodManagerInternal {

        @ImfLockFree
        @Override
        public void setInteractive(boolean interactive) {
            // Do everything in handler so as not to block the caller.
            mHandler.obtainMessage(MSG_SET_INTERACTIVE, interactive ? 1 : 0, 0).sendToTarget();
        }

        @ImfLockFree
        @Override
        public void hideAllInputMethods(@SoftInputShowHideReason int reason,
                int originatingDisplayId) {
@@ -5566,6 +5568,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            }
        }

        @ImfLockFree
        @Override
        public void registerInputMethodListListener(InputMethodListListener listener) {
            mInputMethodListListeners.addIfAbsent(listener);
@@ -5613,11 +5616,13 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            }
        }

        @ImfLockFree
        @Override
        public void removeImeSurface(int displayId) {
            mHandler.obtainMessage(MSG_REMOVE_IME_SURFACE).sendToTarget();
        }

        @ImfLockFree
        @Override
        public void updateImeWindowStatus(boolean disableImeIcon, int displayId) {
            mHandler.obtainMessage(MSG_UPDATE_IME_WINDOW_STATUS, disableImeIcon ? 1 : 0, 0)
@@ -5695,6 +5700,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            }
        }

        @ImfLockFree
        @Override
        public void maybeFinishStylusHandwriting() {
            mHandler.removeMessages(MSG_FINISH_HANDWRITING);