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

Commit 9d0c9eb5 authored by Louis Chang's avatar Louis Chang Committed by android-build-team Robot
Browse files

Detects all activities for whether showing work challenge

Work challenge did not show when a work activity is not on top, but
still visible after screen turns on.

Also show work challenge even if the work activity is behind a top
fullscreen activity of another profile because the user can still
navigate back to the work activity when top activity finishes.

Bug: 177457096
Test: ActivityStackSupervisorTests

Change-Id: I5e09b09be547d04fdfd709cb9cd4bcd4a94bbf21
Merged-In: I5e09b09be547d04fdfd709cb9cd4bcd4a94bbf21
(cherry picked from commit 6820d708)
parent ea1b439c
Loading
Loading
Loading
Loading
+9 −28
Original line number Diff line number Diff line
@@ -852,27 +852,7 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
    }

    /**
     * Detects whether we should show a lock screen in front of this task for a locked user.
     * <p>
     * We'll do this if either of the following holds:
     * <ul>
     *   <li>The top activity explicitly belongs to {@param userId}.</li>
     *   <li>The top activity returns a result to an activity belonging to {@param userId}.</li>
     * </ul>
     *
     * @return {@code true} if the top activity looks like it belongs to {@param userId}.
     */
    private boolean taskTopActivityIsUser(TaskRecord task, @UserIdInt int userId) {
        // To handle the case that work app is in the task but just is not the top one.
        final ActivityRecord activityRecord = task.getTopActivity();
        final ActivityRecord resultTo = (activityRecord != null ? activityRecord.resultTo : null);

        return (activityRecord != null && activityRecord.userId == userId)
                || (resultTo != null && resultTo.userId == userId);
    }

    /**
     * Find all visible task stacks containing {@param userId} and intercept them with an activity
     * Find all task stacks containing {@param userId} and intercept them with an activity
     * to block out the contents and possibly start a credential-confirming intent.
     *
     * @param userId user handle for the locked managed profile.
@@ -885,13 +865,14 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D
                final List<TaskRecord> tasks = stacks.get(stackNdx).getAllTasks();
                for (int taskNdx = tasks.size() - 1; taskNdx >= 0; taskNdx--) {
                    final TaskRecord task = tasks.get(taskNdx);

                    // Check the task for a top activity belonging to userId, or returning a result
                    // to an activity belonging to userId. Example case: a document picker for
                    // personal files, opened by a work app, should still get locked.
                    if (taskTopActivityIsUser(task, userId)) {
                    for (int activityNdx = task.mActivities.size() - 1; activityNdx >= 0;
                            activityNdx--) {
                        final ActivityRecord activity = task.mActivities.get(activityNdx);
                        if (!activity.finishing && activity.userId == userId) {
                            mService.mTaskChangeNotificationController.notifyTaskProfileLocked(
                                    task.taskId, userId);
                            break;
                        }
                    }
                }
            }
+36 −6
Original line number Diff line number Diff line
@@ -18,25 +18,26 @@ package com.android.server.am;

import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
import static android.app.ActivityManager.StackId.PINNED_STACK_ID;

import static com.android.server.am.ActivityStackSupervisor.MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;

import android.content.ComponentName;
import android.graphics.Rect;
import android.os.RemoteException;
import android.os.UserHandle;
import android.platform.test.annotations.Presubmit;
import android.support.test.filters.MediumTest;
import android.support.test.runner.AndroidJUnit4;

import org.junit.runner.RunWith;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static com.android.server.am.ActivityStackSupervisor.MATCH_TASK_IN_STACKS_OR_RECENT_TASKS_AND_RESTORE;

/**
 * Tests for the {@link ActivityStackSupervisor} class.
@@ -135,4 +136,33 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase {

        assertFalse(service.mStackSupervisor.mStoppingActivities.contains(firstActivity));
    }

    @Test
    public void testLockAllProfileTasks() throws Exception {
        // Make an activity visible with the user id set to 1
        final ActivityManagerService service = createActivityManagerService();
        final TaskRecord task = createTask(service, testActivityComponent,
                FULLSCREEN_WORKSPACE_STACK_ID);
        final ActivityRecord activity = createActivity(service, testActivityComponent, task, 1);

        // Create another activity on top and the user id is 2
        final ActivityRecord topActivity = createActivity(service, testActivityComponent, task, 2);

        // Make sure the listeners will be notified for putting the task to locked state
        LocalTaskStackListener listener = new LocalTaskStackListener();
        service.registerTaskStackListener(listener);
        service.mStackSupervisor.lockAllProfileTasks(1);
        assertTrue(listener.mTaskProfileLocked);
        service.unregisterTaskStackListener(listener);
    }

    private class LocalTaskStackListener extends android.app.TaskStackListener {
        boolean mTaskProfileLocked;

        @Override
        public void onTaskProfileLocked(int taskId, int userId) {
            super.onTaskProfileLocked(taskId, userId);
            mTaskProfileLocked = true;
        }
    }
}