Merge "Fix issue with wrong user task being resolved" into qt-dev

This commit is contained in:
Winson Chung
2019-05-19 03:54:23 +00:00
committed by Android (Google) Code Review
2 changed files with 46 additions and 9 deletions

View File

@@ -100,13 +100,15 @@ class RecentsAnimation implements RecentsAnimationCallbacks,
} }
// If the activity is associated with the recents stack, then try and get that first // If the activity is associated with the recents stack, then try and get that first
final int userId = mService.getCurrentUserId();
mTargetActivityType = intent.getComponent() != null mTargetActivityType = intent.getComponent() != null
&& recentsComponent.equals(intent.getComponent()) && recentsComponent.equals(intent.getComponent())
? ACTIVITY_TYPE_RECENTS ? ACTIVITY_TYPE_RECENTS
: ACTIVITY_TYPE_HOME; : ACTIVITY_TYPE_HOME;
ActivityStack targetStack = mDefaultDisplay.getStack(WINDOWING_MODE_UNDEFINED, ActivityStack targetStack = mDefaultDisplay.getStack(WINDOWING_MODE_UNDEFINED,
mTargetActivityType); mTargetActivityType);
ActivityRecord targetActivity = getTargetActivity(targetStack, intent.getComponent()); ActivityRecord targetActivity = getTargetActivity(targetStack, intent.getComponent(),
userId);
final boolean hasExistingActivity = targetActivity != null; final boolean hasExistingActivity = targetActivity != null;
if (hasExistingActivity) { if (hasExistingActivity) {
final ActivityDisplay display = targetActivity.getDisplay(); final ActivityDisplay display = targetActivity.getDisplay();
@@ -156,13 +158,13 @@ class RecentsAnimation implements RecentsAnimationCallbacks,
.setCallingUid(recentsUid) .setCallingUid(recentsUid)
.setCallingPackage(recentsComponent.getPackageName()) .setCallingPackage(recentsComponent.getPackageName())
.setActivityOptions(SafeActivityOptions.fromBundle(options.toBundle())) .setActivityOptions(SafeActivityOptions.fromBundle(options.toBundle()))
.setMayWait(mService.getCurrentUserId()) .setMayWait(userId)
.execute(); .execute();
// Move the recents activity into place for the animation // Move the recents activity into place for the animation
targetActivity = mDefaultDisplay.getStack(WINDOWING_MODE_UNDEFINED, targetStack = mDefaultDisplay.getStack(WINDOWING_MODE_UNDEFINED,
mTargetActivityType).getTopActivity(); mTargetActivityType);
targetStack = targetActivity.getActivityStack(); targetActivity = getTargetActivity(targetStack, intent.getComponent(), userId);
mDefaultDisplay.moveStackBehindBottomMostVisibleStack(targetStack); mDefaultDisplay.moveStackBehindBottomMostVisibleStack(targetStack);
if (DEBUG) { if (DEBUG) {
Slog.d(TAG, "Moved stack=" + targetStack + " behind stack=" Slog.d(TAG, "Moved stack=" + targetStack + " behind stack="
@@ -172,7 +174,6 @@ class RecentsAnimation implements RecentsAnimationCallbacks,
mWindowManager.prepareAppTransition(TRANSIT_NONE, false); mWindowManager.prepareAppTransition(TRANSIT_NONE, false);
mWindowManager.executeAppTransition(); mWindowManager.executeAppTransition();
// TODO: Maybe wait for app to draw in this particular case? // TODO: Maybe wait for app to draw in this particular case?
if (DEBUG) Slog.d(TAG, "Started intent=" + intent); if (DEBUG) Slog.d(TAG, "Started intent=" + intent);
@@ -406,17 +407,18 @@ class RecentsAnimation implements RecentsAnimationCallbacks,
* @return the top activity in the {@param targetStack} matching the {@param component}, or just * @return the top activity in the {@param targetStack} matching the {@param component}, or just
* the top activity of the top task if no task matches the component. * the top activity of the top task if no task matches the component.
*/ */
private ActivityRecord getTargetActivity(ActivityStack targetStack, ComponentName component) { private ActivityRecord getTargetActivity(ActivityStack targetStack, ComponentName component,
int userId) {
if (targetStack == null) { if (targetStack == null) {
return null; return null;
} }
for (int i = targetStack.getChildCount() - 1; i >= 0; i--) { for (int i = targetStack.getChildCount() - 1; i >= 0; i--) {
final TaskRecord task = targetStack.getChildAt(i); final TaskRecord task = targetStack.getChildAt(i);
if (task.getBaseIntent().getComponent().equals(component)) { if (task.userId == userId && task.getBaseIntent().getComponent().equals(component)) {
return task.getTopActivity(); return task.getTopActivity();
} }
} }
return targetStack.getTopActivity(); return null;
} }
} }

View File

@@ -16,9 +16,11 @@
package com.android.server.wm; package com.android.server.wm;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_HOME;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS; import static android.app.WindowConfiguration.ACTIVITY_TYPE_RECENTS;
import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD; import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN; import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.doCallRealMethod; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doCallRealMethod;
@@ -56,6 +58,8 @@ import org.junit.Test;
@Presubmit @Presubmit
public class RecentsAnimationTest extends ActivityTestsBase { public class RecentsAnimationTest extends ActivityTestsBase {
private static final int TEST_USER_ID = 100;
private final ComponentName mRecentsComponent = private final ComponentName mRecentsComponent =
new ComponentName(mContext.getPackageName(), "RecentsActivity"); new ComponentName(mContext.getPackageName(), "RecentsActivity");
private RecentsAnimationController mRecentsAnimationController; private RecentsAnimationController mRecentsAnimationController;
@@ -223,6 +227,37 @@ public class RecentsAnimationTest extends ActivityTestsBase {
verify(mRecentsAnimationController, times(0)).cancelOnNextTransitionStart(); verify(mRecentsAnimationController, times(0)).cancelOnNextTransitionStart();
} }
@Test
public void testMultipleUserHomeActivity_findUserHomeTask() {
ActivityDisplay display = mService.mRootActivityContainer.getDefaultDisplay();
ActivityStack homeStack = display.getStack(WINDOWING_MODE_UNDEFINED, ACTIVITY_TYPE_HOME);
ActivityRecord otherUserHomeActivity = new ActivityBuilder(mService)
.setStack(homeStack)
.setCreateTask(true)
.setComponent(new ComponentName(mContext.getPackageName(), "Home2"))
.build();
otherUserHomeActivity.getTaskRecord().userId = TEST_USER_ID;
ActivityStack fullscreenStack = display.createStack(WINDOWING_MODE_FULLSCREEN,
ACTIVITY_TYPE_STANDARD, true /* onTop */);
new ActivityBuilder(mService)
.setComponent(new ComponentName(mContext.getPackageName(), "App1"))
.setCreateTask(true)
.setStack(fullscreenStack)
.build();
doReturn(TEST_USER_ID).when(mService).getCurrentUserId();
doCallRealMethod().when(mRootActivityContainer).ensureActivitiesVisible(
any() /* starting */, anyInt() /* configChanges */,
anyBoolean() /* preserveWindows */);
startRecentsActivity(otherUserHomeActivity.getTaskRecord().getBaseIntent().getComponent(),
true);
// Ensure we find the task for the right user and it is made visible
assertTrue(otherUserHomeActivity.visible);
}
private void startRecentsActivity() { private void startRecentsActivity() {
startRecentsActivity(mRecentsComponent, false /* getRecentsAnimation */); startRecentsActivity(mRecentsComponent, false /* getRecentsAnimation */);
} }