From ac696e19a24c75e2fbecf3f3f8e1398ce38c572f Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Tue, 1 Oct 2019 19:13:48 +0800 Subject: Fix startActivities may put activity in new task unexpectedly Commit 591bf6 misplaced the setResultTo to the creation loop of starters that leads to ActivityStarter#mSourceRecord is always null. Then during startActivities, if an activity has different task affinity from the previous, it will be put in a new task unexpectedly. Also avoid getting the modified component specified flag. Bug: 141525305 Test: atest StartActivityTests#testStartActivitiesInNewAndSameTask Change-Id: I237c9abff6ed9b0afab114e14d57c67692576033 --- .../core/java/com/android/server/wm/ActivityStartController.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityStartController.java b/services/core/java/com/android/server/wm/ActivityStartController.java index 919141c13622..6ee64f348a55 100644 --- a/services/core/java/com/android/server/wm/ActivityStartController.java +++ b/services/core/java/com/android/server/wm/ActivityStartController.java @@ -386,6 +386,8 @@ public class ActivityStartController { throw new IllegalArgumentException("File descriptors passed in Intent"); } + // Get the flag earlier because the intent may be modified in resolveActivity below. + final boolean componentSpecified = intent.getComponent() != null; // Don't modify the client's object! intent = new Intent(intent); @@ -409,7 +411,6 @@ public class ActivityStartController { .setCaller(caller) .setResolvedType(resolvedTypes[i]) .setActivityInfo(aInfo) - .setResultTo(resultTo) .setRequestCode(-1) .setCallingPid(callingPid) .setCallingUid(callingUid) @@ -417,7 +418,7 @@ public class ActivityStartController { .setRealCallingPid(realCallingPid) .setRealCallingUid(realCallingUid) .setActivityOptions(checkedOptions) - .setComponentSpecified(intent.getComponent() != null) + .setComponentSpecified(componentSpecified) // Top activity decides on animation being run, so we allow only for the // top one as otherwise an activity below might consume it. @@ -430,7 +431,8 @@ public class ActivityStartController { // Lock the loop to ensure the activities launched in a sequence. synchronized (mService.mGlobalLock) { for (int i = 0; i < starters.length; i++) { - final int startResult = starters[i].setOutActivity(outActivity).execute(); + final int startResult = starters[i].setResultTo(resultTo) + .setOutActivity(outActivity).execute(); if (startResult < START_SUCCESS) { // Abort by error result and recycle unused starters. for (int j = i + 1; j < starters.length; j++) { -- cgit v1.2.3-59-g8ed1b