Merge "Preserve custom activity intent on relaunch" into pi-dev
am: 1b59867b9f
Change-Id: I7fa71c11e25e08d65b9e0a4e8349b934d6bf9cb1
This commit is contained in:
@@ -2683,7 +2683,7 @@ public final class ActivityThread extends ClientTransactionHandler {
|
|||||||
// TODO(lifecycler): Can't switch to use #handleLaunchActivity() because it will try to
|
// TODO(lifecycler): Can't switch to use #handleLaunchActivity() because it will try to
|
||||||
// call #reportSizeConfigurations(), but the server might not know anything about the
|
// call #reportSizeConfigurations(), but the server might not know anything about the
|
||||||
// activity if it was launched from LocalAcvitivyManager.
|
// activity if it was launched from LocalAcvitivyManager.
|
||||||
return performLaunchActivity(r);
|
return performLaunchActivity(r, null /* customIntent */);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Activity getActivity(IBinder token) {
|
public final Activity getActivity(IBinder token) {
|
||||||
@@ -2768,7 +2768,7 @@ public final class ActivityThread extends ClientTransactionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Core implementation of activity launch. */
|
/** Core implementation of activity launch. */
|
||||||
private Activity performLaunchActivity(ActivityClientRecord r) {
|
private Activity performLaunchActivity(ActivityClientRecord r, Intent customIntent) {
|
||||||
ActivityInfo aInfo = r.activityInfo;
|
ActivityInfo aInfo = r.activityInfo;
|
||||||
if (r.packageInfo == null) {
|
if (r.packageInfo == null) {
|
||||||
r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo,
|
r.packageInfo = getPackageInfo(aInfo.applicationInfo, r.compatInfo,
|
||||||
@@ -2838,6 +2838,9 @@ public final class ActivityThread extends ClientTransactionHandler {
|
|||||||
r.embeddedID, r.lastNonConfigurationInstances, config,
|
r.embeddedID, r.lastNonConfigurationInstances, config,
|
||||||
r.referrer, r.voiceInteractor, window, r.configCallback);
|
r.referrer, r.voiceInteractor, window, r.configCallback);
|
||||||
|
|
||||||
|
if (customIntent != null) {
|
||||||
|
activity.mIntent = customIntent;
|
||||||
|
}
|
||||||
r.lastNonConfigurationInstances = null;
|
r.lastNonConfigurationInstances = null;
|
||||||
checkAndBlockForNetworkAccess();
|
checkAndBlockForNetworkAccess();
|
||||||
activity.mStartedActivity = false;
|
activity.mStartedActivity = false;
|
||||||
@@ -2982,7 +2985,7 @@ public final class ActivityThread extends ClientTransactionHandler {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Activity handleLaunchActivity(ActivityClientRecord r,
|
public Activity handleLaunchActivity(ActivityClientRecord r,
|
||||||
PendingTransactionActions pendingActions) {
|
PendingTransactionActions pendingActions, Intent customIntent) {
|
||||||
// If we are getting ready to gc after going to the background, well
|
// If we are getting ready to gc after going to the background, well
|
||||||
// we are back active so skip it.
|
// we are back active so skip it.
|
||||||
unscheduleGcIdler();
|
unscheduleGcIdler();
|
||||||
@@ -3005,7 +3008,7 @@ public final class ActivityThread extends ClientTransactionHandler {
|
|||||||
}
|
}
|
||||||
WindowManagerGlobal.initialize();
|
WindowManagerGlobal.initialize();
|
||||||
|
|
||||||
final Activity a = performLaunchActivity(r);
|
final Activity a = performLaunchActivity(r, customIntent);
|
||||||
|
|
||||||
if (a != null) {
|
if (a != null) {
|
||||||
r.createdConfig = new Configuration(mConfiguration);
|
r.createdConfig = new Configuration(mConfiguration);
|
||||||
@@ -4699,6 +4702,8 @@ public final class ActivityThread extends ClientTransactionHandler {
|
|||||||
List<ResultInfo> pendingResults, List<ReferrerIntent> pendingIntents,
|
List<ResultInfo> pendingResults, List<ReferrerIntent> pendingIntents,
|
||||||
PendingTransactionActions pendingActions, boolean startsNotResumed,
|
PendingTransactionActions pendingActions, boolean startsNotResumed,
|
||||||
Configuration overrideConfig, String reason) {
|
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.
|
// Need to ensure state is saved.
|
||||||
if (!r.paused) {
|
if (!r.paused) {
|
||||||
performPauseActivity(r, false, reason, null /* pendingActions */);
|
performPauseActivity(r, false, reason, null /* pendingActions */);
|
||||||
@@ -4731,7 +4736,7 @@ public final class ActivityThread extends ClientTransactionHandler {
|
|||||||
r.startsNotResumed = startsNotResumed;
|
r.startsNotResumed = startsNotResumed;
|
||||||
r.overrideConfig = overrideConfig;
|
r.overrideConfig = overrideConfig;
|
||||||
|
|
||||||
handleLaunchActivity(r, pendingActions);
|
handleLaunchActivity(r, pendingActions, customIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package android.app;
|
|||||||
import android.app.servertransaction.ClientTransaction;
|
import android.app.servertransaction.ClientTransaction;
|
||||||
import android.app.servertransaction.PendingTransactionActions;
|
import android.app.servertransaction.PendingTransactionActions;
|
||||||
import android.app.servertransaction.TransactionExecutor;
|
import android.app.servertransaction.TransactionExecutor;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.res.CompatibilityInfo;
|
import android.content.res.CompatibilityInfo;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
@@ -140,7 +141,7 @@ public abstract class ClientTransactionHandler {
|
|||||||
|
|
||||||
/** Perform activity launch. */
|
/** Perform activity launch. */
|
||||||
public abstract Activity handleLaunchActivity(ActivityThread.ActivityClientRecord r,
|
public abstract Activity handleLaunchActivity(ActivityThread.ActivityClientRecord r,
|
||||||
PendingTransactionActions pendingActions);
|
PendingTransactionActions pendingActions, Intent customIntent);
|
||||||
|
|
||||||
/** Perform activity start. */
|
/** Perform activity start. */
|
||||||
public abstract void handleStartActivity(ActivityThread.ActivityClientRecord r,
|
public abstract void handleStartActivity(ActivityThread.ActivityClientRecord r,
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ public class LaunchActivityItem extends ClientTransactionItem {
|
|||||||
mOverrideConfig, mCompatInfo, mReferrer, mVoiceInteractor, mState, mPersistentState,
|
mOverrideConfig, mCompatInfo, mReferrer, mVoiceInteractor, mState, mPersistentState,
|
||||||
mPendingResults, mPendingNewIntents, mIsForward,
|
mPendingResults, mPendingNewIntents, mIsForward,
|
||||||
mProfilerInfo, client);
|
mProfilerInfo, client);
|
||||||
client.handleLaunchActivity(r, pendingActions);
|
client.handleLaunchActivity(r, pendingActions, null /* customIntent */);
|
||||||
Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
|
Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -173,7 +173,8 @@ public class TransactionExecutor {
|
|||||||
log("Transitioning to state: " + state);
|
log("Transitioning to state: " + state);
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case ON_CREATE:
|
case ON_CREATE:
|
||||||
mTransactionHandler.handleLaunchActivity(r, mPendingActions);
|
mTransactionHandler.handleLaunchActivity(r, mPendingActions,
|
||||||
|
null /* customIntent */);
|
||||||
break;
|
break;
|
||||||
case ON_START:
|
case ON_START:
|
||||||
mTransactionHandler.handleStartActivity(r, mPendingActions);
|
mTransactionHandler.handleStartActivity(r, mPendingActions);
|
||||||
|
|||||||
@@ -16,7 +16,11 @@
|
|||||||
|
|
||||||
package android.app.activity;
|
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.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.ActivityThread;
|
import android.app.ActivityThread;
|
||||||
@@ -27,6 +31,7 @@ import android.app.servertransaction.ClientTransactionItem;
|
|||||||
import android.app.servertransaction.ResumeActivityItem;
|
import android.app.servertransaction.ResumeActivityItem;
|
||||||
import android.app.servertransaction.StopActivityItem;
|
import android.app.servertransaction.StopActivityItem;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.IBinder;
|
||||||
import android.support.test.InstrumentationRegistry;
|
import android.support.test.InstrumentationRegistry;
|
||||||
import android.support.test.filters.MediumTest;
|
import android.support.test.filters.MediumTest;
|
||||||
import android.support.test.rule.ActivityTestRule;
|
import android.support.test.rule.ActivityTestRule;
|
||||||
@@ -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) {
|
private static ClientTransaction newRelaunchResumeTransaction(Activity activity) {
|
||||||
final ClientTransactionItem callbackItem = ActivityRelaunchItem.obtain(null,
|
final ClientTransactionItem callbackItem = ActivityRelaunchItem.obtain(null,
|
||||||
null, 0, new MergedConfiguration(), false /* preserveWindow */);
|
null, 0, new MergedConfiguration(), false /* preserveWindow */);
|
||||||
|
|||||||
Reference in New Issue
Block a user