From 12917c6b8fac65fb1014789cf78b4abcd6936ee0 Mon Sep 17 00:00:00 2001 From: Tony Mak Date: Mon, 15 Jan 2018 15:17:13 +0000 Subject: [PATCH] Workaround a bug that causes multiple activity instances are created If Intent A contains both package and component, while Intent B contains the exact component but without the package, AMS thinks that they are different and not reusing the existing activity. Launcher starts app in current user by using startActivity(intent without package), while CrossProfileAppsService does not. This bug is tracked in b/64108432. And let's workaround it for now. There is no harm to not setting package anyway given that the component is set explicitly. Fix: 71983351 Test: Manual 1. Start app that integrates with CrossProfileApps API in user 0 2. Start the work profile instance by consuming CrossProfileApps APIs 3. Switch back to user 0 by consuming CrossProfileApps APIs 4. Observe that the same activity instance in #1 is brought up. Change-Id: I4da6737ed3df589a0acd86ace1a7add3783d4449 --- .../core/java/com/android/server/pm/LauncherAppsService.java | 1 + .../server/pm/crossprofile/CrossProfileAppsServiceImpl.java | 1 + 2 files changed, 2 insertions(+) diff --git a/services/core/java/com/android/server/pm/LauncherAppsService.java b/services/core/java/com/android/server/pm/LauncherAppsService.java index b06b58385cc31..1717b3d1a5f79 100644 --- a/services/core/java/com/android/server/pm/LauncherAppsService.java +++ b/services/core/java/com/android/server/pm/LauncherAppsService.java @@ -652,6 +652,7 @@ public class LauncherAppsService extends SystemService { activityInfo.name.equals(component.getClassName())) { // Found an activity with category launcher that matches // this component so ok to launch. + launchIntent.setPackage(null); launchIntent.setComponent(component); mContext.startActivityAsUser(launchIntent, opts, user); return; diff --git a/services/core/java/com/android/server/pm/crossprofile/CrossProfileAppsServiceImpl.java b/services/core/java/com/android/server/pm/crossprofile/CrossProfileAppsServiceImpl.java index d6281c51b3faa..a517d6d1a99e6 100644 --- a/services/core/java/com/android/server/pm/crossprofile/CrossProfileAppsServiceImpl.java +++ b/services/core/java/com/android/server/pm/crossprofile/CrossProfileAppsServiceImpl.java @@ -111,6 +111,7 @@ public class CrossProfileAppsServiceImpl extends ICrossProfileApps.Stub { final long ident = mInjector.clearCallingIdentity(); try { + launchIntent.setPackage(null); launchIntent.setComponent(component); mContext.startActivityAsUser(launchIntent, ActivityOptions.makeOpenCrossProfileAppsAnimation().toBundle(), user);