Loading core/java/android/app/ActivityThread.java +10 −5 Original line number Diff line number Diff line Loading @@ -2683,7 +2683,7 @@ public final class ActivityThread extends ClientTransactionHandler { // TODO(lifecycler): Can't switch to use #handleLaunchActivity() because it will try to // call #reportSizeConfigurations(), but the server might not know anything about the // activity if it was launched from LocalAcvitivyManager. return performLaunchActivity(r); return performLaunchActivity(r, null /* customIntent */); } public final Activity getActivity(IBinder token) { Loading Loading @@ -2768,7 +2768,7 @@ public final class ActivityThread extends ClientTransactionHandler { } /** Core implementation of activity launch. */ private Activity performLaunchActivity(ActivityClientRecord r) { private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) { ActivityInfo aInfo = r.activityInfo; if (r.packageInfo == null) { r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo, Loading Loading @@ -2838,6 +2838,9 @@ public final class ActivityThread extends ClientTransactionHandler { r.embeddedID, r.lastNonConfigurationInstances, config, r.referrer, r.voiceInteractor, window, r.configCallback); if (customIntent != null) { activity.mIntent = customIntent; } r.lastNonConfigurationInstances = null; checkAndBlockForNetworkAccess(); activity.mStartedActivity = false; Loading Loading @@ -2982,7 +2985,7 @@ public final class ActivityThread extends ClientTransactionHandler { */ @Override public Activity handleLaunchActivity(ActivityClientRecord r, PendingTransactionActions pendingActions) { PendingTransactionActions pendingActions, Intent customIntent) { // If we are getting ready to gc after going to the background, well // we are back active so skip it. unscheduleGcIdler(); Loading @@ -3005,7 +3008,7 @@ public final class ActivityThread extends ClientTransactionHandler { } WindowManagerGlobal.initialize(); final Activity a = performLaunchActivity(r); final Activity a = performLaunchActivity(r, customIntent); if (a != null) { r.createdConfig = new Configuration(mConfiguration); Loading Loading @@ -4699,6 +4702,8 @@ public final class ActivityThread extends ClientTransactionHandler { List<ResultInfo> pendingResults, List<ReferrerIntent> pendingIntents, PendingTransactionActions pendingActions, boolean startsNotResumed, Configuration overrideConfig, String reason) { // Preserve last used intent, it may be set from Activity#setIntent(). final Intent customIntent = r.activity.mIntent; // Need to ensure state is saved. if (!r.paused) { performPauseActivity(r, false, reason, null /* pendingActions */); Loading Loading @@ -4731,7 +4736,7 @@ public final class ActivityThread extends ClientTransactionHandler { r.startsNotResumed = startsNotResumed; r.overrideConfig = overrideConfig; handleLaunchActivity(r, pendingActions); handleLaunchActivity(r, pendingActions, customIntent); } @Override Loading core/java/android/app/ClientTransactionHandler.java +2 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.app; import android.app.servertransaction.ClientTransaction; import android.app.servertransaction.PendingTransactionActions; import android.app.servertransaction.TransactionExecutor; import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.res.CompatibilityInfo; import android.content.res.Configuration; Loading Loading @@ -140,7 +141,7 @@ public abstract class ClientTransactionHandler { /** Perform activity launch. */ public abstract Activity handleLaunchActivity(ActivityThread.ActivityClientRecord r, PendingTransactionActions pendingActions); PendingTransactionActions pendingActions, Intent customIntent); /** Perform activity start. */ public abstract void handleStartActivity(ActivityThread.ActivityClientRecord r, Loading core/java/android/app/servertransaction/LaunchActivityItem.java +1 −1 Original line number Diff line number Diff line Loading @@ -75,7 +75,7 @@ public class LaunchActivityItem extends ClientTransactionItem { mOverrideConfig, mCompatInfo, mReferrer, mVoiceInteractor, mState, mPersistentState, mPendingResults, mPendingNewIntents, mIsForward, mProfilerInfo, client); client.handleLaunchActivity(r, pendingActions); client.handleLaunchActivity(r, pendingActions, null /* customIntent */); Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); } Loading core/java/android/app/servertransaction/TransactionExecutor.java +2 −1 Original line number Diff line number Diff line Loading @@ -173,7 +173,8 @@ public class TransactionExecutor { log("Transitioning to state: " + state); switch (state) { case ON_CREATE: mTransactionHandler.handleLaunchActivity(r, mPendingActions); mTransactionHandler.handleLaunchActivity(r, mPendingActions, null /* customIntent */); break; case ON_START: mTransactionHandler.handleStartActivity(r, mPendingActions); Loading core/tests/coretests/src/android/app/activity/ActivityThreadTest.java +35 −0 Original line number Diff line number Diff line Loading @@ -16,7 +16,11 @@ package android.app.activity; import static android.content.Intent.ACTION_EDIT; import static android.content.Intent.ACTION_VIEW; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import android.app.Activity; import android.app.ActivityThread; Loading @@ -27,6 +31,7 @@ import android.app.servertransaction.ClientTransactionItem; import android.app.servertransaction.ResumeActivityItem; import android.app.servertransaction.StopActivityItem; import android.content.Intent; import android.os.IBinder; import android.support.test.InstrumentationRegistry; import android.support.test.filters.MediumTest; import android.support.test.rule.ActivityTestRule; Loading Loading @@ -94,6 +99,36 @@ public class ActivityThreadTest { }); } /** Verify that custom intent set via Activity#setIntent() is preserved on relaunch. */ @Test public void testCustomIntentPreservedOnRelaunch() throws Exception { final Intent initIntent = new Intent(); initIntent.setAction(ACTION_VIEW); final Activity activity = mActivityTestRule.launchActivity(initIntent); IBinder token = activity.getActivityToken(); final ActivityThread activityThread = activity.getActivityThread(); InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { // Recreate and check that intent is still the same. activity.recreate(); final Activity newActivity = activityThread.getActivity(token); assertTrue("Original intent must be preserved after recreate", initIntent.filterEquals(newActivity.getIntent())); // Set custom intent, recreate and check if it is preserved. final Intent customIntent = new Intent(); customIntent.setAction(ACTION_EDIT); newActivity.setIntent(customIntent); activity.recreate(); final Activity lastActivity = activityThread.getActivity(token); assertTrue("Custom intent must be preserved after recreate", customIntent.filterEquals(lastActivity.getIntent())); }); } private static ClientTransaction newRelaunchResumeTransaction(Activity activity) { final ClientTransactionItem callbackItem = ActivityRelaunchItem.obtain(null, null, 0, new MergedConfiguration(), false /* preserveWindow */); Loading Loading
core/java/android/app/ActivityThread.java +10 −5 Original line number Diff line number Diff line Loading @@ -2683,7 +2683,7 @@ public final class ActivityThread extends ClientTransactionHandler { // TODO(lifecycler): Can't switch to use #handleLaunchActivity() because it will try to // call #reportSizeConfigurations(), but the server might not know anything about the // activity if it was launched from LocalAcvitivyManager. return performLaunchActivity(r); return performLaunchActivity(r, null /* customIntent */); } public final Activity getActivity(IBinder token) { Loading Loading @@ -2768,7 +2768,7 @@ public final class ActivityThread extends ClientTransactionHandler { } /** Core implementation of activity launch. */ private Activity performLaunchActivity(ActivityClientRecord r) { private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) { ActivityInfo aInfo = r.activityInfo; if (r.packageInfo == null) { r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo, Loading Loading @@ -2838,6 +2838,9 @@ public final class ActivityThread extends ClientTransactionHandler { r.embeddedID, r.lastNonConfigurationInstances, config, r.referrer, r.voiceInteractor, window, r.configCallback); if (customIntent != null) { activity.mIntent = customIntent; } r.lastNonConfigurationInstances = null; checkAndBlockForNetworkAccess(); activity.mStartedActivity = false; Loading Loading @@ -2982,7 +2985,7 @@ public final class ActivityThread extends ClientTransactionHandler { */ @Override public Activity handleLaunchActivity(ActivityClientRecord r, PendingTransactionActions pendingActions) { PendingTransactionActions pendingActions, Intent customIntent) { // If we are getting ready to gc after going to the background, well // we are back active so skip it. unscheduleGcIdler(); Loading @@ -3005,7 +3008,7 @@ public final class ActivityThread extends ClientTransactionHandler { } WindowManagerGlobal.initialize(); final Activity a = performLaunchActivity(r); final Activity a = performLaunchActivity(r, customIntent); if (a != null) { r.createdConfig = new Configuration(mConfiguration); Loading Loading @@ -4699,6 +4702,8 @@ public final class ActivityThread extends ClientTransactionHandler { List<ResultInfo> pendingResults, List<ReferrerIntent> pendingIntents, PendingTransactionActions pendingActions, boolean startsNotResumed, Configuration overrideConfig, String reason) { // Preserve last used intent, it may be set from Activity#setIntent(). final Intent customIntent = r.activity.mIntent; // Need to ensure state is saved. if (!r.paused) { performPauseActivity(r, false, reason, null /* pendingActions */); Loading Loading @@ -4731,7 +4736,7 @@ public final class ActivityThread extends ClientTransactionHandler { r.startsNotResumed = startsNotResumed; r.overrideConfig = overrideConfig; handleLaunchActivity(r, pendingActions); handleLaunchActivity(r, pendingActions, customIntent); } @Override Loading
core/java/android/app/ClientTransactionHandler.java +2 −1 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package android.app; import android.app.servertransaction.ClientTransaction; import android.app.servertransaction.PendingTransactionActions; import android.app.servertransaction.TransactionExecutor; import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.res.CompatibilityInfo; import android.content.res.Configuration; Loading Loading @@ -140,7 +141,7 @@ public abstract class ClientTransactionHandler { /** Perform activity launch. */ public abstract Activity handleLaunchActivity(ActivityThread.ActivityClientRecord r, PendingTransactionActions pendingActions); PendingTransactionActions pendingActions, Intent customIntent); /** Perform activity start. */ public abstract void handleStartActivity(ActivityThread.ActivityClientRecord r, Loading
core/java/android/app/servertransaction/LaunchActivityItem.java +1 −1 Original line number Diff line number Diff line Loading @@ -75,7 +75,7 @@ public class LaunchActivityItem extends ClientTransactionItem { mOverrideConfig, mCompatInfo, mReferrer, mVoiceInteractor, mState, mPersistentState, mPendingResults, mPendingNewIntents, mIsForward, mProfilerInfo, client); client.handleLaunchActivity(r, pendingActions); client.handleLaunchActivity(r, pendingActions, null /* customIntent */); Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER); } Loading
core/java/android/app/servertransaction/TransactionExecutor.java +2 −1 Original line number Diff line number Diff line Loading @@ -173,7 +173,8 @@ public class TransactionExecutor { log("Transitioning to state: " + state); switch (state) { case ON_CREATE: mTransactionHandler.handleLaunchActivity(r, mPendingActions); mTransactionHandler.handleLaunchActivity(r, mPendingActions, null /* customIntent */); break; case ON_START: mTransactionHandler.handleStartActivity(r, mPendingActions); Loading
core/tests/coretests/src/android/app/activity/ActivityThreadTest.java +35 −0 Original line number Diff line number Diff line Loading @@ -16,7 +16,11 @@ package android.app.activity; import static android.content.Intent.ACTION_EDIT; import static android.content.Intent.ACTION_VIEW; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import android.app.Activity; import android.app.ActivityThread; Loading @@ -27,6 +31,7 @@ import android.app.servertransaction.ClientTransactionItem; import android.app.servertransaction.ResumeActivityItem; import android.app.servertransaction.StopActivityItem; import android.content.Intent; import android.os.IBinder; import android.support.test.InstrumentationRegistry; import android.support.test.filters.MediumTest; import android.support.test.rule.ActivityTestRule; Loading Loading @@ -94,6 +99,36 @@ public class ActivityThreadTest { }); } /** Verify that custom intent set via Activity#setIntent() is preserved on relaunch. */ @Test public void testCustomIntentPreservedOnRelaunch() throws Exception { final Intent initIntent = new Intent(); initIntent.setAction(ACTION_VIEW); final Activity activity = mActivityTestRule.launchActivity(initIntent); IBinder token = activity.getActivityToken(); final ActivityThread activityThread = activity.getActivityThread(); InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> { // Recreate and check that intent is still the same. activity.recreate(); final Activity newActivity = activityThread.getActivity(token); assertTrue("Original intent must be preserved after recreate", initIntent.filterEquals(newActivity.getIntent())); // Set custom intent, recreate and check if it is preserved. final Intent customIntent = new Intent(); customIntent.setAction(ACTION_EDIT); newActivity.setIntent(customIntent); activity.recreate(); final Activity lastActivity = activityThread.getActivity(token); assertTrue("Custom intent must be preserved after recreate", customIntent.filterEquals(lastActivity.getIntent())); }); } private static ClientTransaction newRelaunchResumeTransaction(Activity activity) { final ClientTransactionItem callbackItem = ActivityRelaunchItem.obtain(null, null, 0, new MergedConfiguration(), false /* preserveWindow */); Loading