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

Commit 5d3f629a authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Add IMMS#getCurrentImeUserId() to reduce inter-class dependencies

In order to clarify the data dependency between *Controller classes
and InputMethodManagerService, this CL introduces

 InputMethodManagerService#getCurrentImeUserId()

to reduce the direct references to InputMethodUtils from controller
classes.

This is a mechanical refactoring CL. There must be no observable
behavior change.

Bug: 309868254
Test: presubmit
Change-Id: I70b64921f676513be400129b8a79f35a28776d60
parent d2018b52
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ final class AutofillSuggestionsController {
    private static final String TAG = AutofillSuggestionsController.class.getSimpleName();

    @NonNull private final InputMethodManagerService mService;
    @NonNull private final InputMethodUtils.InputMethodSettings mSettings;

    private static final class CreateInlineSuggestionsRequest {
        @NonNull final InlineSuggestionsRequestInfo mRequestInfo;
@@ -76,7 +75,6 @@ final class AutofillSuggestionsController {

    AutofillSuggestionsController(@NonNull InputMethodManagerService service) {
        mService = service;
        mSettings = mService.mSettings;
    }

    @GuardedBy("ImfLock.class")
@@ -88,7 +86,7 @@ final class AutofillSuggestionsController {
        final InputMethodInfo imi = mService.queryInputMethodForCurrentUserLocked(
                mService.getSelectedMethodIdLocked());
        try {
            if (userId == mSettings.getCurrentUserId()
            if (userId == mService.getCurrentImeUserIdLocked()
                    && imi != null && isInlineSuggestionsEnabled(imi, touchExplorationEnabled)) {
                mPendingInlineSuggestionsRequest = new CreateInlineSuggestionsRequest(
                        requestInfo, callback, imi.getPackageName());
+2 −4
Original line number Diff line number Diff line
@@ -63,7 +63,6 @@ final class InputMethodBindingController {

    @NonNull private final InputMethodManagerService mService;
    @NonNull private final Context mContext;
    @NonNull private final InputMethodUtils.InputMethodSettings mSettings;
    @NonNull private final PackageManagerInternal mPackageManagerInternal;
    @NonNull private final WindowManagerInternal mWindowManagerInternal;

@@ -113,7 +112,6 @@ final class InputMethodBindingController {
            int imeConnectionBindFlags, CountDownLatch latchForTesting) {
        mService = service;
        mContext = mService.mContext;
        mSettings = mService.mSettings;
        mPackageManagerInternal = mService.mPackageManagerInternal;
        mWindowManagerInternal = mService.mWindowManagerInternal;
        mImeConnectionBindFlags = imeConnectionBindFlags;
@@ -322,7 +320,7 @@ final class InputMethodBindingController {
        private void updateCurrentMethodUid() {
            final String curMethodPackage = mCurIntent.getComponent().getPackageName();
            final int curMethodUid = mPackageManagerInternal.getPackageUid(
                    curMethodPackage, 0 /* flags */, mSettings.getCurrentUserId());
                    curMethodPackage, 0 /* flags */, mService.getCurrentImeUserIdLocked());
            if (curMethodUid < 0) {
                Slog.e(TAG, "Failed to get UID for package=" + curMethodPackage);
                mCurMethodUid = Process.INVALID_UID;
@@ -478,7 +476,7 @@ final class InputMethodBindingController {
            return false;
        }
        return mContext.bindServiceAsUser(mCurIntent, conn, flags,
                new UserHandle(mSettings.getCurrentUserId()));
                new UserHandle(mService.getCurrentImeUserIdLocked()));
    }

    @GuardedBy("ImfLock.class")
+6 −0
Original line number Diff line number Diff line
@@ -1727,6 +1727,12 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
        registerDeviceListenerAndCheckStylusSupport();
    }

    @GuardedBy("ImfLock.class")
    @UserIdInt
    int getCurrentImeUserIdLocked() {
        return mSettings.getCurrentUserId();
    }

    private final class InkWindowInitializer implements Runnable {
        public void run() {
            synchronized (ImfLock.class) {
+2 −1
Original line number Diff line number Diff line
@@ -79,7 +79,8 @@ final class InputMethodMenuController {

        synchronized (ImfLock.class) {
            final boolean isScreenLocked = mWindowManagerInternal.isKeyguardLocked()
                    && mWindowManagerInternal.isKeyguardSecure(mSettings.getCurrentUserId());
                    && mWindowManagerInternal.isKeyguardSecure(
                            mService.getCurrentImeUserIdLocked());
            final String lastInputMethodId = mSettings.getSelectedInputMethod();
            int lastInputMethodSubtypeId =
                    mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId);