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

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

Merge "Added WC#showToCurrentUser (83/n)"

parents d10dc73d 9bb1a1ea
Loading
Loading
Loading
Loading
+0 −61
Original line number Diff line number Diff line
@@ -48,34 +48,19 @@ import static android.view.WindowManager.LayoutParams.LAST_SYSTEM_WINDOW;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_IS_ROUNDED_CORNERS_OVERLAY;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR;
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS;
import static android.view.WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_STARTING;
import static android.view.WindowManager.LayoutParams.TYPE_BOOT_PROGRESS;
import static android.view.WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY;
import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
import static android.view.WindowManager.LayoutParams.TYPE_DREAM;
import static android.view.WindowManager.LayoutParams.TYPE_INPUT_CONSUMER;
import static android.view.WindowManager.LayoutParams.TYPE_INPUT_METHOD;
import static android.view.WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG;
import static android.view.WindowManager.LayoutParams.TYPE_MAGNIFICATION_OVERLAY;
import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR;
import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
import static android.view.WindowManager.LayoutParams.TYPE_PHONE;
import static android.view.WindowManager.LayoutParams.TYPE_POINTER;
import static android.view.WindowManager.LayoutParams.TYPE_PRESENTATION;
import static android.view.WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;
import static android.view.WindowManager.LayoutParams.TYPE_PRIVATE_PRESENTATION;
import static android.view.WindowManager.LayoutParams.TYPE_QS_DIALOG;
import static android.view.WindowManager.LayoutParams.TYPE_SEARCH_BAR;
import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL;
import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL;
import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
import static android.view.WindowManager.LayoutParams.TYPE_VOICE_INTERACTION;
import static android.view.WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY;
import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
import static android.view.WindowManager.LayoutParams.isSystemAlertWindowType;
import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN;
@@ -2182,52 +2167,6 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
    }

    @Override
    public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs) {

        // If this switch statement is modified, modify the comment in the declarations of
        // the type in {@link WindowManager.LayoutParams} as well.
        switch (attrs.type) {
            default:
                // These are the windows that by default are shown only to the user that created
                // them. If this needs to be overridden, set
                // {@link WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS} in
                // {@link WindowManager.LayoutParams}. Note that permission
                // {@link android.Manifest.permission.INTERNAL_SYSTEM_WINDOW} is required as well.
                if ((attrs.privateFlags & SYSTEM_FLAG_SHOW_FOR_ALL_USERS) == 0) {
                    return true;
                }
                break;

            // These are the windows that by default are shown to all users. However, to
            // protect against spoofing, check permissions below.
            case TYPE_APPLICATION_STARTING:
            case TYPE_BOOT_PROGRESS:
            case TYPE_DISPLAY_OVERLAY:
            case TYPE_INPUT_CONSUMER:
            case TYPE_KEYGUARD_DIALOG:
            case TYPE_MAGNIFICATION_OVERLAY:
            case TYPE_NAVIGATION_BAR:
            case TYPE_NAVIGATION_BAR_PANEL:
            case TYPE_PHONE:
            case TYPE_POINTER:
            case TYPE_PRIORITY_PHONE:
            case TYPE_SEARCH_BAR:
            case TYPE_STATUS_BAR:
            case TYPE_STATUS_BAR_PANEL:
            case TYPE_STATUS_BAR_SUB_PANEL:
            case TYPE_SYSTEM_DIALOG:
            case TYPE_VOLUME_OVERLAY:
            case TYPE_PRESENTATION:
            case TYPE_PRIVATE_PRESENTATION:
            case TYPE_DOCK_DIVIDER:
                break;
        }

        // Check if third party app has set window to system window type.
        return mContext.checkCallingOrSelfPermission(INTERNAL_SYSTEM_WINDOW) != PERMISSION_GRANTED;
    }

    void readLidState() {
        mDefaultDisplayPolicy.setLidState(mWindowManagerFuncs.getLidState());
    }
+0 −10
Original line number Diff line number Diff line
@@ -701,16 +701,6 @@ public interface WindowManagerPolicy extends WindowManagerPolicyConstants {
     */
    public int checkAddPermission(WindowManager.LayoutParams attrs, int[] outAppOp);

    /**
     * Check permissions when adding a window.
     *
     * @param attrs The window's LayoutParams.
     *
     * @return True if the window may only be shown to the current user, false if the window can
     * be shown on all users' windows.
     */
    public boolean checkShowToOwnerOnly(WindowManager.LayoutParams attrs);

    /**
     * After the window manager has computed the current configuration based
     * on its knowledge of the display and input devices, it gives the policy
+5 −0
Original line number Diff line number Diff line
@@ -7451,6 +7451,11 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        return mTaskOverlay;
    }

    @Override
    boolean showToCurrentUser() {
        return mShowForAllUsers || mWmService.isCurrentProfile(mUserId);
    }

    @Override
    public String toString() {
        if (stringName != null) {
+19 −28
Original line number Diff line number Diff line
@@ -1258,7 +1258,7 @@ class ActivityStack extends WindowContainer<WindowContainer> implements BoundsAn

        super.switchUser(userId);
        forAllTasks((t) -> {
            if (t.mWmService.isCurrentProfileLocked(t.mUserId) || t.showForAllUsers()) {
            if (t.mWmService.isCurrentProfile(t.mUserId) || t.showForAllUsers()) {
                mChildren.remove(t);
                mChildren.add(t);
            }
@@ -3986,11 +3986,19 @@ class ActivityStack extends WindowContainer<WindowContainer> implements BoundsAn
     * @param showForAllUsers Whether to show the task regardless of the current user.
     */
    private void addChild(Task task, int position, boolean showForAllUsers, boolean moveParents) {
        try {
            // Force show for all user so task can be position correctly based on which user is
            // active. We clear the force show below.
            task.setForceShowForAllUsers(showForAllUsers);
            // Add child task.
            addChild(task, null);

            // Move child to a proper position, as some restriction for position might apply.
        positionChildAt(position, task, moveParents /* includingParents */, showForAllUsers);
            positionChildAt(position, task, moveParents /* includingParents */);

        } finally {
            task.setForceShowForAllUsers(false);
        }
    }

    @Override
@@ -4036,18 +4044,7 @@ class ActivityStack extends WindowContainer<WindowContainer> implements BoundsAn
    @Override
    void positionChildAt(int position, WindowContainer child, boolean includingParents) {
        final Task task = (Task) child;
        positionChildAt(position, task, includingParents, task.showForAllUsers());
    }

    /**
     * Overridden version of {@link ActivityStack#positionChildAt(int, WindowContainer, boolean)}.
     * Used in {@link ActivityStack#addChild(Task, int, boolean showForAllUsers, boolean)}, as it
     * can receive showForAllUsers param from {@link ActivityRecord} instead of
     * {@link Task#showForAllUsers()}.
     */
    private int positionChildAt(int position, Task child, boolean includingParents,
            boolean showForAllUsers) {
        final int targetPosition = findPositionForTask(child, position, showForAllUsers);
        final int targetPosition = findPositionForTask(task, position);
        super.positionChildAt(targetPosition, child, includingParents);

        // Log positioning.
@@ -4056,8 +4053,7 @@ class ActivityStack extends WindowContainer<WindowContainer> implements BoundsAn
        }

        final int toTop = targetPosition == mChildren.size() - 1 ? 1 : 0;
        EventLogTags.writeWmTaskMoved(child.mTaskId, toTop, targetPosition);
        return targetPosition;
        EventLogTags.writeWmTaskMoved(task.mTaskId, toTop, targetPosition);
    }

    @Override
@@ -4127,9 +4123,8 @@ class ActivityStack extends WindowContainer<WindowContainer> implements BoundsAn

    // TODO: We should really have users as a window container in the hierarchy so that we don't
    // have to do complicated things like we are doing in this method.
    int findPositionForTask(Task task, int targetPosition, boolean showForAllUsers) {
        final boolean canShowTask =
                showForAllUsers || mWmService.isCurrentProfileLocked(task.mUserId);
    int findPositionForTask(Task task, int targetPosition) {
        final boolean canShowTask = task.showToCurrentUser();

        final int stackSize = mChildren.size();
        int minPosition = 0;
@@ -4161,9 +4156,7 @@ class ActivityStack extends WindowContainer<WindowContainer> implements BoundsAn
    private int computeMinPosition(int minPosition, int size) {
        while (minPosition < size) {
            final Task tmpTask = (Task) mChildren.get(minPosition);
            final boolean canShowTmpTask =
                    tmpTask.showForAllUsers()
                            || mWmService.isCurrentProfileLocked(tmpTask.mUserId);
            final boolean canShowTmpTask = tmpTask.showToCurrentUser();
            if (canShowTmpTask) {
                break;
            }
@@ -4181,9 +4174,7 @@ class ActivityStack extends WindowContainer<WindowContainer> implements BoundsAn
    private int computeMaxPosition(int maxPosition) {
        while (maxPosition > 0) {
            final Task tmpTask = (Task) mChildren.get(maxPosition);
            final boolean canShowTmpTask =
                    tmpTask.showForAllUsers()
                            || mWmService.isCurrentProfileLocked(tmpTask.mUserId);
            final boolean canShowTmpTask = tmpTask.showToCurrentUser();
            if (!canShowTmpTask) {
                break;
            }
+12 −1
Original line number Diff line number Diff line
@@ -385,6 +385,8 @@ class Task extends WindowContainer<WindowContainer> {

    private static Exception sTmpException;

    private boolean mForceShowForAllUsers;

    private final FindRootHelper mFindRootHelper = new FindRootHelper();
    private class FindRootHelper {
        private ActivityRecord mRoot;
@@ -2185,7 +2187,7 @@ class Task extends WindowContainer<WindowContainer> {
                + " from stack=" + getStack());
        EventLogTags.writeWmTaskRemoved(mTaskId, "reParentTask:" + reason);

        position = stack.findPositionForTask(this, position, showForAllUsers());
        position = stack.findPositionForTask(this, position);

        reparent(stack, position);

@@ -2522,6 +2524,15 @@ class Task extends WindowContainer<WindowContainer> {
        return r != null && r.mShowForAllUsers;
    }

    @Override
    boolean showToCurrentUser() {
        return mForceShowForAllUsers || showForAllUsers() || mWmService.isCurrentProfile(mUserId);
    }

    void setForceShowForAllUsers(boolean forceShowForAllUsers) {
        mForceShowForAllUsers = forceShowForAllUsers;
    }

    /**
     * When we are in a floating stack (Freeform, Pinned, ...) we calculate
     * insets differently. However if we are animating to the fullscreen stack
Loading