From b3b43130db1c02493ca881ad95adf27ec0cbe8ad Mon Sep 17 00:00:00 2001 From: Todd Kennedy Date: Mon, 20 Mar 2017 16:05:48 -0700 Subject: [PATCH] Send launch token to activity manager When an instant app is installed, control passes from the platform to the instant app installer. However, when the instant app is launched, the original launch token needs to be associated with that launch. Do this by sending the launch token along with the original launch intent Change-Id: I5741be343862d4e5c8bfb6b4a81d0bac8e53ea9c Fixes: 35445667 Test: Build and manully inspect the event logs to ensure the launch token is sent on instant app launch --- core/java/android/content/Intent.java | 13 +++++++++++++ .../java/com/android/server/am/ActivityMetricsLogger.java | 1 + .../java/com/android/server/am/ActivityStackSupervisor.java | 4 ++++ .../core/java/com/android/server/pm/InstantAppResolver.java | 2 ++ 4 files changed, 20 insertions(+) diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java index bd31b03d7cff..e7d306dc63cc 100644 --- a/core/java/android/content/Intent.java +++ b/core/java/android/content/Intent.java @@ -5123,6 +5123,8 @@ public class Intent implements Parcelable, Cloneable { private Intent mSelector; private ClipData mClipData; private int mContentUserHint = UserHandle.USER_CURRENT; + /** Token to track instant app launches. Local only; do not copy cross-process. */ + private String mLaunchToken; // --------------------------------------------------------------------- @@ -5143,6 +5145,7 @@ public class Intent implements Parcelable, Cloneable { this.mComponent = o.mComponent; this.mFlags = o.mFlags; this.mContentUserHint = o.mContentUserHint; + this.mLaunchToken = o.mLaunchToken; if (o.mCategories != null) { this.mCategories = new ArraySet(o.mCategories); } @@ -6379,6 +6382,16 @@ public class Intent implements Parcelable, Cloneable { return mContentUserHint; } + /** @hide */ + public String getLaunchToken() { + return mLaunchToken; + } + + /** @hide */ + public void setLaunchToken(String launchToken) { + mLaunchToken = launchToken; + } + /** * Sets the ClassLoader that will be used when unmarshalling * any Parcelable values from the extras of this Intent. diff --git a/services/core/java/com/android/server/am/ActivityMetricsLogger.java b/services/core/java/com/android/server/am/ActivityMetricsLogger.java index dd8c05ea9b87..04a09fe4305e 100644 --- a/services/core/java/com/android/server/am/ActivityMetricsLogger.java +++ b/services/core/java/com/android/server/am/ActivityMetricsLogger.java @@ -321,6 +321,7 @@ class ActivityMetricsLogger { if (info.launchedActivity.info.launchToken != null) { builder.addTaggedData(FIELD_INSTANT_APP_LAUNCH_TOKEN, info.launchedActivity.info.launchToken); + info.launchedActivity.info.launchToken = null; } builder.addTaggedData(APP_TRANSITION_IS_EPHEMERAL, info.launchedActivity.info.applicationInfo.isInstantApp() ? 1 : 0); diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index 217515b936dd..bb93174735d4 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -1226,6 +1226,10 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D mService.setProfileApp(aInfo.applicationInfo, aInfo.processName, profilerInfo); } } + final String intentLaunchToken = intent.getLaunchToken(); + if (aInfo.launchToken == null && intentLaunchToken != null) { + aInfo.launchToken = intentLaunchToken; + } } return aInfo; } diff --git a/services/core/java/com/android/server/pm/InstantAppResolver.java b/services/core/java/com/android/server/pm/InstantAppResolver.java index 86124a823810..59f8a2d0da20 100644 --- a/services/core/java/com/android/server/pm/InstantAppResolver.java +++ b/services/core/java/com/android/server/pm/InstantAppResolver.java @@ -200,6 +200,7 @@ public abstract class InstantAppResolver { // Intent that is launched if the package couldn't be installed for any reason. final Intent failureIntent = new Intent(origIntent); failureIntent.setFlags(failureIntent.getFlags() | Intent.FLAG_IGNORE_EPHEMERAL); + failureIntent.setLaunchToken(token); try { final IIntentSender failureIntentTarget = ActivityManager.getService() .getIntentSender( @@ -216,6 +217,7 @@ public abstract class InstantAppResolver { // Intent that is launched if the package was installed successfully. final Intent successIntent = new Intent(origIntent); + successIntent.setLaunchToken(token); try { final IIntentSender successIntentTarget = ActivityManager.getService() .getIntentSender( -- 2.11.0