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

Commit 7516ff90 authored by Craig Mautner's avatar Craig Mautner
Browse files

Keep app focus and input focus current

Change ag/422870 mistakenly set app focus to null in the
InputDispatcher. This change restores setting app focus correctly.

In addition, there were a few places where window focus
(i.e. mCurrentFocus) could be modified without notifying the
InputDispatcher. This change fixes those locations.

Should fix 14564396.

Change-Id: Ie24f3410fdd1f5f1eefbce02759fef4149e59620
parent 414222c2
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -2429,7 +2429,7 @@ public class WindowManagerService extends IWindowManager.Stub
            // relayout to be displayed, so we'll do it there.

            if (focusChanged) {
                finishUpdateFocusedWindowAfterAssignLayersLocked(false /*updateInputWindows*/);
                mInputMonitor.setInputFocusLw(mCurrentFocus, false /*updateInputWindows*/);
            }
            mInputMonitor.updateInputWindowsLw(false /*force*/);

@@ -2546,12 +2546,15 @@ public class WindowManagerService extends IWindowManager.Stub
                if (displayContent != null) {
                    displayContent.layoutNeeded = true;
                }
                updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
                        false /*updateInputWindows*/);
                final boolean focusChanged = updateFocusedWindowLocked(
                        UPDATE_FOCUS_WILL_PLACE_SURFACES, false /*updateInputWindows*/);
                performLayoutAndPlaceSurfacesLocked();
                if (win.mAppToken != null) {
                    win.mAppToken.updateReportedVisibilityLocked();
                }
                if (focusChanged) {
                    mInputMonitor.updateInputWindowsLw(false /*force*/);
                }
                //dump();
                Binder.restoreCallingIdentity(origId);
                return;
@@ -3910,7 +3913,7 @@ public class WindowManagerService extends IWindowManager.Stub
            final boolean changed = mFocusedApp != newFocus;
            if (changed) {
                mFocusedApp = newFocus;
                mInputMonitor.setFocusedAppLw(null);
                mInputMonitor.setFocusedAppLw(newFocus);
            }

            if (moveFocusNow && changed) {
@@ -8917,7 +8920,7 @@ public class WindowManagerService extends IWindowManager.Stub
                    && !moveInputMethodWindowsIfNeededLocked(true)) {
                assignLayersLocked(windows);
            }
            updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, false /*updateInputWindows*/);
            updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES, true /*updateInputWindows*/);
            mFocusMayChange = false;
        }

@@ -9152,10 +9155,11 @@ public class WindowManagerService extends IWindowManager.Stub
        final long currentTime = SystemClock.uptimeMillis();

        int i;
        boolean updateInputWindowsNeeded = false;

        if (mFocusMayChange) {
            mFocusMayChange = false;
            updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
            updateInputWindowsNeeded = updateFocusedWindowLocked(UPDATE_FOCUS_WILL_PLACE_SURFACES,
                    false /*updateInputWindows*/);
        }

@@ -9517,6 +9521,7 @@ public class WindowManagerService extends IWindowManager.Stub
            mFocusMayChange = false;
            if (updateFocusedWindowLocked(UPDATE_FOCUS_PLACING_SURFACES,
                    false /*updateInputWindows*/)) {
                updateInputWindowsNeeded = true;
                defaultDisplay.pendingLayoutChanges |= WindowManagerPolicy.FINISH_LAYOUT_REDO_ANIM;
            }
        }
@@ -9697,6 +9702,9 @@ public class WindowManagerService extends IWindowManager.Stub
            mDisplayContents.valueAt(displayNdx).checkForDeferredActions();
        }

        if (updateInputWindowsNeeded) {
            mInputMonitor.updateInputWindowsLw(false /*force*/);
        }
        setFocusedStackFrame();

        // Check to see if we are now in a state where the screen should
@@ -10012,7 +10020,7 @@ public class WindowManagerService extends IWindowManager.Stub
            if (mode != UPDATE_FOCUS_WILL_ASSIGN_LAYERS) {
                // If we defer assigning layers, then the caller is responsible for
                // doing this part.
                finishUpdateFocusedWindowAfterAssignLayersLocked(updateInputWindows);
                mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows);
            }

            Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
@@ -10021,10 +10029,6 @@ public class WindowManagerService extends IWindowManager.Stub
        return false;
    }

    private void finishUpdateFocusedWindowAfterAssignLayersLocked(boolean updateInputWindows) {
        mInputMonitor.setInputFocusLw(mCurrentFocus, updateInputWindows);
    }

    private WindowState computeFocusedWindowLocked() {
        if (mAnimator.mUniverseBackground != null
                && mAnimator.mUniverseBackground.mWin.canReceiveKeys()) {