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

Commit afc96fda authored by Wale Ogunwale's avatar Wale Ogunwale
Browse files

Changed task focused to be based on focused app vs. window

Task#isFocused and onWindowFocusChanged (renamed to onAppFocusChanged)
where based on the current focused window which is wrong since not all
windows are contained within a task. Changed to use DC#mFocusedApp
instead which tracks focus changes to app windows.

Also,
- Start calling dispatchTaskInfoChangedIfNeeded in
Task#onAppFocusChanged
- Removed DC#mLastFocus that isn't used.

Bug: 180525887
Test: Task focus doesn't change when notification shade is expanded.
Change-Id: I1abf97b5f8d7eedd36bd429835094f6a48361bee
parent 5df7e132
Loading
Loading
Loading
Loading
+7 −32
Original line number Diff line number Diff line
@@ -504,11 +504,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
     */
    WindowState mCurrentFocus = null;

    /**
     * The last focused window that we've notified the client that the focus is changed.
     */
    WindowState mLastFocus = null;

    /**
     * The foreground app of this display. Windows below this app cannot be the focused window. If
     * the user taps on the area outside of the task of the focused app, we will notify AM about the
@@ -1244,12 +1239,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
                // removing from parent.
                token.getParent().removeChild(token);
            }
            if (token.hasChild(prevDc.mLastFocus)) {
                // If the reparent window token contains previous display's last focus window, means
                // it will end up to gain window focus on the target display, so it should not be
                // notified that it lost focus from the previous display.
                prevDc.mLastFocus = null;
            }
        }

        addWindowToken(token.token, token);
@@ -3204,9 +3193,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        pw.print(prefix); pw.print("mLayoutSeq="); pw.println(mLayoutSeq);

        pw.print("  mCurrentFocus="); pw.println(mCurrentFocus);
        if (mLastFocus != mCurrentFocus) {
            pw.print("  mLastFocus="); pw.println(mLastFocus);
        }
        pw.print("  mFocusedApp="); pw.println(mFocusedApp);
        if (mFixedRotationLaunchingApp != null) {
            pw.println("  mFixedRotationLaunchingApp=" + mFixedRotationLaunchingApp);
@@ -3437,8 +3423,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
            }
        }

        onWindowFocusChanged(oldFocus, newFocus);

        int focusChanged = getDisplayPolicy().focusChangedLw(oldFocus, newFocus);

        if (imWindowChanged && oldFocus != mInputMethodWindow) {
@@ -3489,7 +3473,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
                    mWmService.mAccessibilityController));
        }

        mLastFocus = mCurrentFocus;
        return true;
    }

@@ -3497,20 +3480,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        accessibilityController.onWindowFocusChangedNot(getDisplayId());
    }

    private static void onWindowFocusChanged(WindowState oldFocus, WindowState newFocus) {
        final Task focusedTask = newFocus != null ? newFocus.getTask() : null;
        final Task unfocusedTask = oldFocus != null ? oldFocus.getTask() : null;
        if (focusedTask == unfocusedTask) {
            return;
        }
        if (focusedTask != null) {
            focusedTask.onWindowFocusChanged(true /* hasFocus */);
        }
        if (unfocusedTask != null) {
            unfocusedTask.onWindowFocusChanged(false /* hasFocus */);
        }
    }

    /**
     * Set the new focused app to this display.
     *
@@ -3534,7 +3503,14 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        }
        ProtoLog.i(WM_DEBUG_FOCUS_LIGHT, "setFocusedApp %s displayId=%d Callers=%s",
                newFocus, getDisplayId(), Debug.getCallers(4));
        final Task oldTask = mFocusedApp != null ? mFocusedApp.getTask() : null;
        final Task newTask = newFocus != null ? newFocus.getTask() : null;
        mFocusedApp = newFocus;
        if (oldTask != newTask) {
            if (oldTask != null) oldTask.onAppFocusChanged(false);
            if (newTask != null) newTask.onAppFocusChanged(true);
        }

        getInputMonitor().setFocusedAppLw(newFocus);
        updateTouchExcludeRegion();
        return true;
@@ -4230,7 +4206,6 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        if (DEBUG_INPUT_METHOD) {
            Slog.i(TAG_WM, "Desired input method target: " + imFocus);
            Slog.i(TAG_WM, "Current focus: " + mCurrentFocus + " displayId=" + mDisplayId);
            Slog.i(TAG_WM, "Last focus: " + mLastFocus + " displayId=" + mDisplayId);
        }

        if (DEBUG_INPUT_METHOD) {
+4 −5
Original line number Diff line number Diff line
@@ -4314,10 +4314,10 @@ class Task extends TaskFragment {
     * @return true if the task is currently focused.
     */
    private boolean isFocused() {
        if (mDisplayContent == null || mDisplayContent.mCurrentFocus == null) {
        if (mDisplayContent == null || mDisplayContent.mFocusedApp == null) {
            return false;
        }
        return mDisplayContent.mCurrentFocus.getTask() == this;
        return mDisplayContent.mFocusedApp.getTask() == this;
    }

    /**
@@ -4374,10 +4374,9 @@ class Task extends TaskFragment {
     * Called on the task of a window which gained or lost focus.
     * @param hasFocus
     */
    void onWindowFocusChanged(boolean hasFocus) {
    void onAppFocusChanged(boolean hasFocus) {
        updateShadowsRadius(hasFocus, getSyncTransaction());
        // TODO(b/180525887): Un-comment once there is resolution on the bug.
        // dispatchTaskInfoChangedIfNeeded(false /* force */);
        dispatchTaskInfoChangedIfNeeded(false /* force */);
    }

    void onPictureInPictureParamsChanged() {
+0 −13
Original line number Diff line number Diff line
@@ -871,19 +871,6 @@ public class DisplayContentTests extends WindowTestsBase {
                .setDisplayInfoOverrideFromWindowManager(dc.getDisplayId(), null);
    }

    @UseTestDisplay
    @Test
    public void testClearLastFocusWhenReparentingFocusedWindow() {
        final DisplayContent defaultDisplay = mWm.getDefaultDisplayContentLocked();
        final WindowState window = createWindow(null /* parent */, TYPE_BASE_APPLICATION,
                defaultDisplay, "window");
        defaultDisplay.mLastFocus = window;
        mDisplayContent.mCurrentFocus = window;
        mDisplayContent.reParentWindowToken(window.mToken);

        assertNull(defaultDisplay.mLastFocus);
    }

    @Test
    public void testGetPreferredOptionsPanelGravityFromDifferentDisplays() {
        final DisplayContent portraitDisplay = createNewDisplay();