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

Commit dbe72a03 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Use DisplayContext to obtain InputMethodManager in ViewRootImpl"

parents e727d74d bf25f9ed
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -239,6 +239,12 @@ public final class ViewRootImpl implements ViewParent,
    final ArrayList<WindowCallbacks> mWindowCallbacks = new ArrayList<>();
    @UnsupportedAppUsage
    final Context mContext;
    /**
     * TODO(b/116349163): Check if we can merge this into {@link #mContext}.
     */
    @NonNull
    private Context mDisplayContext;

    @UnsupportedAppUsage
    final IWindowSession mWindowSession;
    @NonNull Display mDisplay;
@@ -532,6 +538,7 @@ public final class ViewRootImpl implements ViewParent,

    public ViewRootImpl(Context context, Display display) {
        mContext = context;
        mDisplayContext = context.createDisplayContext(display);
        mWindowSession = WindowManagerGlobal.getWindowSession();
        mDisplay = display;
        mBasePackageName = context.getBasePackageName();
@@ -1249,6 +1256,7 @@ public final class ViewRootImpl implements ViewParent,
        } else {
            mDisplay = preferredDisplay;
        }
        mDisplayContext = mContext.createDisplayContext(mDisplay);
    }

    void pokeDrawLockIfNeeded() {
@@ -2579,7 +2587,7 @@ public final class ViewRootImpl implements ViewParent,
                    .mayUseInputMethod(mWindowAttributes.flags);
            if (imTarget != mLastWasImTarget) {
                mLastWasImTarget = imTarget;
                InputMethodManager imm = mContext.getSystemService(InputMethodManager.class);
                InputMethodManager imm = mDisplayContext.getSystemService(InputMethodManager.class);
                if (imm != null && imTarget) {
                    imm.onPreWindowFocus(mView, hasWindowFocus);
                    imm.onPostWindowFocus(mView, mView.findFocus(),
@@ -2695,7 +2703,7 @@ public final class ViewRootImpl implements ViewParent,
            mLastWasImTarget = WindowManager.LayoutParams
                    .mayUseInputMethod(mWindowAttributes.flags);

            InputMethodManager imm = mContext.getSystemService(InputMethodManager.class);
            InputMethodManager imm = mDisplayContext.getSystemService(InputMethodManager.class);
            if (imm != null && mLastWasImTarget && !isInLocalFocusMode()) {
                imm.onPreWindowFocus(mView, hasWindowFocus);
            }
@@ -4329,7 +4337,8 @@ public final class ViewRootImpl implements ViewParent,
                    enqueueInputEvent(event, null, 0, true);
                } break;
                case MSG_CHECK_FOCUS: {
                    InputMethodManager imm = mContext.getSystemService(InputMethodManager.class);
                    InputMethodManager imm =
                            mDisplayContext.getSystemService(InputMethodManager.class);
                    if (imm != null) {
                        imm.checkFocus();
                    }
@@ -4871,7 +4880,7 @@ public final class ViewRootImpl implements ViewParent,
        @Override
        protected int onProcess(QueuedInputEvent q) {
            if (mLastWasImTarget && !isInLocalFocusMode()) {
                InputMethodManager imm = mContext.getSystemService(InputMethodManager.class);
                InputMethodManager imm = mDisplayContext.getSystemService(InputMethodManager.class);
                if (imm != null) {
                    final InputEvent event = q.mEvent;
                    if (DEBUG_IMF) Log.v(mTag, "Sending input event to IME: " + event);