Detects all activities for whether showing work challenge am: 69b3a3cd04
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14182408 Change-Id: I96c3433ccfb430ce9dae8c8b1459278f814221a3
This commit is contained in:
@@ -2132,13 +2132,14 @@ class RootActivityContainer extends ConfigurationContainer
|
||||
final List<TaskRecord> tasks = stack.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)) {
|
||||
mService.getTaskChangeNotificationController().notifyTaskProfileLocked(
|
||||
task.taskId, userId);
|
||||
for (int activityNdx = task.mActivities.size() - 1; activityNdx >= 0;
|
||||
activityNdx--) {
|
||||
final ActivityRecord activity = task.mActivities.get(activityNdx);
|
||||
if (!activity.finishing && activity.mUserId == userId) {
|
||||
mService.getTaskChangeNotificationController()
|
||||
.notifyTaskProfileLocked(task.taskId, userId);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2148,26 +2149,6 @@ class RootActivityContainer extends ConfigurationContainer
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.mUserId == userId)
|
||||
|| (resultTo != null && resultTo.mUserId == userId);
|
||||
}
|
||||
|
||||
void cancelInitializingActivities() {
|
||||
for (int displayNdx = mActivityDisplays.size() - 1; displayNdx >= 0; --displayNdx) {
|
||||
final ActivityDisplay display = mActivityDisplays.get(displayNdx);
|
||||
|
||||
@@ -60,6 +60,7 @@ import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Rect;
|
||||
import android.os.UserHandle;
|
||||
import android.platform.test.annotations.Presubmit;
|
||||
import android.util.Pair;
|
||||
import android.view.DisplayInfo;
|
||||
@@ -818,6 +819,25 @@ public class RootActivityContainerTests extends ActivityTestsBase {
|
||||
assertEquals(infoFake1.activityInfo.name, resolvedInfo.first.name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLockAllProfileTasks() {
|
||||
// Make an activity visible with the user id set to 1
|
||||
final TaskRecord task = new TaskBuilder(mSupervisor).setStack(mFullscreenStack).build();
|
||||
final ActivityRecord activity = new ActivityBuilder(mService).setTask(task)
|
||||
.setUid(UserHandle.PER_USER_RANGE + 1).build();
|
||||
|
||||
// Create another activity on top and the user id is 2
|
||||
final ActivityRecord topActivity = new ActivityBuilder(mService)
|
||||
.setTask(task).setUid(UserHandle.PER_USER_RANGE + 2).build();
|
||||
|
||||
// Make sure the listeners will be notified for putting the task to locked state
|
||||
TaskChangeNotificationController controller =
|
||||
mService.getTaskChangeNotificationController();
|
||||
spyOn(controller);
|
||||
mService.mRootActivityContainer.lockAllProfileTasks(1);
|
||||
verify(controller).notifyTaskProfileLocked(eq(task.taskId), eq(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that {@link RootActivityContainer#getLaunchStack} with the real caller id will get the
|
||||
* expected stack when requesting the activity launch on the secondary display.
|
||||
|
||||
Reference in New Issue
Block a user