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

Commit ee9e2770 authored by David Stevens's avatar David Stevens
Browse files

Handle focused tasks on multiple displays

When the focused task changes displays, make sure to mark the whole
previous display as not part of a focused task.

This change also adds an adb am command to change the task focus.

Test: android.server.cts.ActivityManagerDisplayTests
Test: #testStackFocusSwitchOnTouchEvent
Bug: 35214007
Change-Id: I9cb7372c21a0b592abb6f6d910077ff5097dd6cf
parent ef4d6f37
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -2031,6 +2031,8 @@ final class ActivityManagerShellCommand extends ShellCommand {
            return runTaskDragTaskTest(pw);
        } else if (op.equals("size-task-test")) {
            return runTaskSizeTaskTest(pw);
        } else if (op.equals("focus")) {
            return runTaskFocus(pw);
        } else {
            getErrPrintWriter().println("Error: unknown command '" + op + "'");
            return -1;
@@ -2322,6 +2324,13 @@ final class ActivityManagerShellCommand extends ShellCommand {
        return 0;
    }

    int runTaskFocus(PrintWriter pw) throws RemoteException {
        final int taskId = Integer.parseInt(getNextArgRequired());
        pw.println("Setting focus to task " + taskId);
        mInterface.setFocusedTask(taskId);
        return 0;
    }

    int runWrite(PrintWriter pw) {
        mInternal.enforceCallingPermission(android.Manifest.permission.SET_ACTIVITY_WATCHER,
                "registerUidObserver()");
+19 −13
Original line number Diff line number Diff line
@@ -1072,6 +1072,11 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
    }

    void setTouchExcludeRegion(Task focusedTask) {
        // The provided task is the task on this display with focus, so if WindowManagerService's
        // focused app is not on this display, focusedTask will be null.
        if (focusedTask == null) {
            mTouchExcludeRegion.setEmpty();
        } else {
            mTouchExcludeRegion.set(mBaseDisplayRect);
            final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
            mTmpRect2.setEmpty();
@@ -1086,6 +1091,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
            if (!mTmpRect2.isEmpty()) {
                mTouchExcludeRegion.op(mTmpRect2, Region.Op.UNION);
            }
        }
        final WindowState inputMethod = mService.mInputMethodWindow;
        if (inputMethod != null && inputMethod.isVisibleLw()) {
            // If the input method is visible and the user is typing, we don't want these touch
+1 −1
Original line number Diff line number Diff line
@@ -784,7 +784,7 @@ class RootWindowContainer extends WindowContainer<DisplayContent> {
        if (updateInputWindowsNeeded) {
            mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
        }
        mService.setFocusTaskRegionLocked();
        mService.setFocusTaskRegionLocked(null);

        // Check to see if we are now in a state where the screen should
        // be enabled, because the window obscured flags have changed.
+14 −8
Original line number Diff line number Diff line
@@ -2574,13 +2574,18 @@ public class WindowManagerService extends IWindowManager.Stub
        }
    }

    void setFocusTaskRegionLocked() {
    void setFocusTaskRegionLocked(AppWindowToken previousFocus) {
        final Task focusedTask = mFocusedApp != null ? mFocusedApp.mTask : null;
        if (focusedTask != null) {
            final DisplayContent displayContent = focusedTask.getDisplayContent();
            if (displayContent != null) {
                displayContent.setTouchExcludeRegion(focusedTask);
        final Task previousTask = previousFocus != null ? previousFocus.mTask : null;
        final DisplayContent focusedDisplayContent =
                focusedTask != null ? focusedTask.getDisplayContent() : null;
        final DisplayContent previousDisplayContent =
                previousTask != null ? previousTask.getDisplayContent() : null;
        if (previousDisplayContent != null && previousDisplayContent != focusedDisplayContent) {
            previousDisplayContent.setTouchExcludeRegion(null);
        }
        if (focusedDisplayContent != null) {
            focusedDisplayContent.setTouchExcludeRegion(focusedTask);
        }
    }

@@ -2606,9 +2611,10 @@ public class WindowManagerService extends IWindowManager.Stub

            final boolean changed = mFocusedApp != newFocus;
            if (changed) {
                AppWindowToken prev = mFocusedApp;
                mFocusedApp = newFocus;
                mInputMonitor.setFocusedAppLw(newFocus);
                setFocusTaskRegionLocked();
                setFocusTaskRegionLocked(prev);
            }

            if (moveFocusNow && changed) {
@@ -7439,7 +7445,7 @@ public class WindowManagerService extends IWindowManager.Stub
        synchronized (mWindowMap) {
            getDefaultDisplayContentLocked().getDockedDividerController()
                    .setTouchRegion(touchRegion);
            setFocusTaskRegionLocked();
            setFocusTaskRegionLocked(null);
        }
    }