Skip to content

Commit 2e4efe7

Browse files
Louis Changandroid-build-team Robot
authored andcommitted
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: RootWindowContainerTests Change-Id: I5e09b09be547d04fdfd709cb9cd4bcd4a94bbf21 Merged-In: I5e09b09be547d04fdfd709cb9cd4bcd4a94bbf21 (cherry picked from commit 87fa64ebe46f1b3273e1e42c99ef2a09f19145a8)
1 parent 1dcac12 commit 2e4efe7

2 files changed

Lines changed: 41 additions & 32 deletions

File tree

services/core/java/com/android/server/wm/RootWindowContainer.java

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3372,50 +3372,26 @@ boolean allPausedActivitiesComplete() {
33723372
}
33733373

33743374
/**
3375-
* Find all visible task stacks containing {@param userId} and intercept them with an activity
3375+
* Find all task stacks containing {@param userId} and intercept them with an activity
33763376
* to block out the contents and possibly start a credential-confirming intent.
33773377
*
33783378
* @param userId user handle for the locked managed profile.
33793379
*/
33803380
void lockAllProfileTasks(@UserIdInt int userId) {
33813381
mService.deferWindowLayout();
33823382
try {
3383-
final PooledConsumer c = PooledLambda.obtainConsumer(
3384-
RootWindowContainer::taskTopActivityIsUser, this, PooledLambda.__(Task.class),
3385-
userId);
3386-
forAllLeafTasks(c, true /* traverseTopToBottom */);
3387-
c.recycle();
3383+
forAllLeafTasks(task -> {
3384+
if (task.getActivity(activity -> !activity.finishing && activity.mUserId == userId)
3385+
!= null) {
3386+
mService.getTaskChangeNotificationController().notifyTaskProfileLocked(
3387+
task.mTaskId, userId);
3388+
}
3389+
}, true /* traverseTopToBottom */);
33883390
} finally {
33893391
mService.continueWindowLayout();
33903392
}
33913393
}
33923394

3393-
/**
3394-
* Detects whether we should show a lock screen in front of this task for a locked user.
3395-
* <p>
3396-
* We'll do this if either of the following holds:
3397-
* <ul>
3398-
* <li>The top activity explicitly belongs to {@param userId}.</li>
3399-
* <li>The top activity returns a result to an activity belonging to {@param userId}.</li>
3400-
* </ul>
3401-
*
3402-
* @return {@code true} if the top activity looks like it belongs to {@param userId}.
3403-
*/
3404-
private void taskTopActivityIsUser(Task task, @UserIdInt int userId) {
3405-
// To handle the case that work app is in the task but just is not the top one.
3406-
final ActivityRecord activityRecord = task.getTopNonFinishingActivity();
3407-
final ActivityRecord resultTo = (activityRecord != null ? activityRecord.resultTo : null);
3408-
3409-
// Check the task for a top activity belonging to userId, or returning a
3410-
// result to an activity belonging to userId. Example case: a document
3411-
// picker for personal files, opened by a work app, should still get locked.
3412-
if ((activityRecord != null && activityRecord.mUserId == userId)
3413-
|| (resultTo != null && resultTo.mUserId == userId)) {
3414-
mService.getTaskChangeNotificationController().notifyTaskProfileLocked(
3415-
task.mTaskId, userId);
3416-
}
3417-
}
3418-
34193395
void cancelInitializingActivities() {
34203396
for (int displayNdx = getChildCount() - 1; displayNdx >= 0; --displayNdx) {
34213397
final DisplayContent display = getChildAt(displayNdx);

services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
2626
import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
2727

28+
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
2829
import static com.android.server.wm.ActivityStack.ActivityState.FINISHING;
2930
import static com.android.server.wm.ActivityStack.ActivityState.PAUSED;
3031
import static com.android.server.wm.ActivityStack.ActivityState.PAUSING;
@@ -36,10 +37,13 @@
3637
import static org.junit.Assert.assertEquals;
3738
import static org.junit.Assert.assertFalse;
3839
import static org.junit.Assert.assertTrue;
40+
import static org.mockito.ArgumentMatchers.eq;
41+
import static org.mockito.Mockito.verify;
3942

4043
import android.app.WindowConfiguration;
4144
import android.content.ComponentName;
4245
import android.content.pm.ActivityInfo;
46+
import android.os.UserHandle;
4347
import android.platform.test.annotations.Presubmit;
4448

4549
import androidx.test.filters.SmallTest;
@@ -169,5 +173,34 @@ public void testAllPausedActivitiesComplete() {
169173
activity.setState(FINISHING, "test FINISHING");
170174
assertThat(mWm.mRoot.allPausedActivitiesComplete()).isTrue();
171175
}
176+
177+
@Test
178+
public void testLockAllProfileTasks() {
179+
// Make an activity visible with the user id set to 0
180+
DisplayContent displayContent = mWm.mRoot.getDisplayContent(DEFAULT_DISPLAY);
181+
TaskDisplayArea taskDisplayArea = displayContent.getTaskDisplayAreaAt(0);
182+
final ActivityStack stack = createTaskStackOnDisplay(WINDOWING_MODE_FULLSCREEN,
183+
ACTIVITY_TYPE_STANDARD, displayContent);
184+
final ActivityRecord activity = new ActivityTestsBase.ActivityBuilder(stack.mAtmService)
185+
.setStack(stack)
186+
.setUid(0)
187+
.setCreateTask(true)
188+
.build();
189+
190+
// Create another activity on top and the user id is 1
191+
Task task = activity.getTask();
192+
final ActivityRecord topActivity = new ActivityTestsBase.ActivityBuilder(mWm.mAtmService)
193+
.setStack(stack)
194+
.setUid(UserHandle.PER_USER_RANGE + 1)
195+
.setTask(task)
196+
.build();
197+
198+
// Make sure the listeners will be notified for putting the task to locked state
199+
TaskChangeNotificationController controller =
200+
mWm.mAtmService.getTaskChangeNotificationController();
201+
spyOn(controller);
202+
mWm.mRoot.lockAllProfileTasks(0);
203+
verify(controller).notifyTaskProfileLocked(eq(task.mTaskId), eq(0));
204+
}
172205
}
173206

0 commit comments

Comments
 (0)