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

Commit abcab703 authored by Wale Ogunwale's avatar Wale Ogunwale Committed by Android (Google) Code Review
Browse files

Merge "Fixed permission issue with AM.setFocusedStack/Task APIs" into nyc-dev

parents bfed18aa b7521b31
Loading
Loading
Loading
Loading
+22 −14
Original line number Diff line number Diff line
@@ -2851,33 +2851,41 @@ public final class ActivityManagerService extends ActivityManagerNative
    @Override
    public void setFocusedStack(int stackId) {
        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedStack()");
        if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedStack: stackId=" + stackId);
        synchronized (ActivityManagerService.this) {
            ActivityStack stack = mStackSupervisor.getStack(stackId);
            if (stack != null) {
                ActivityRecord r = stack.topRunningActivityLocked();
                if (r != null) {
                    setFocusedActivityLocked(r, "setFocusedStack");
        final long callingId = Binder.clearCallingIdentity();
        try {
            synchronized (this) {
                final ActivityStack stack = mStackSupervisor.getStack(stackId);
                if (stack == null) {
                    return;
                }
                final ActivityRecord r = stack.topRunningActivityLocked();
                if (setFocusedActivityLocked(r, "setFocusedStack")) {
                    mStackSupervisor.resumeFocusedStackTopActivityLocked();
                }
            }
        } finally {
            Binder.restoreCallingIdentity(callingId);
        }
    }
    @Override
    public void setFocusedTask(int taskId) {
        enforceCallingPermission(MANAGE_ACTIVITY_STACKS, "setFocusedTask()");
        if (DEBUG_FOCUS) Slog.d(TAG_FOCUS, "setFocusedTask: taskId=" + taskId);
        long callingId = Binder.clearCallingIdentity();
        final long callingId = Binder.clearCallingIdentity();
        try {
            synchronized (ActivityManagerService.this) {
                TaskRecord task = mStackSupervisor.anyTaskForIdLocked(taskId);
                if (task != null) {
            synchronized (this) {
                final TaskRecord task = mStackSupervisor.anyTaskForIdLocked(taskId);
                if (task == null) {
                    return;
                }
                final ActivityRecord r = task.topRunningActivityLocked();
                if (setFocusedActivityLocked(r, "setFocusedTask")) {
                    mStackSupervisor.resumeFocusedStackTopActivityLocked();
                }
            }
            }
        } finally {
            Binder.restoreCallingIdentity(callingId);
        }