Merge "Skip forwarding launcher intents"
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index d11698c..720315d 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -198,6 +198,12 @@
public static final int MATCH_DEFAULT_ONLY = 0x00010000;
/**
+ * Resolution and querying flag: do not resolve intents cross-profile.
+ * @hide
+ */
+ public static final int NO_CROSS_PROFILE = 0x00020000;
+
+ /**
* Flag for {@link addCrossProfileIntentFilter}: if the cross-profile intent has been set by the
* profile owner.
* @hide
@@ -2310,6 +2316,7 @@
* @see #MATCH_DEFAULT_ONLY
* @see #GET_INTENT_FILTERS
* @see #GET_RESOLVED_FILTER
+ * @see #NO_CROSS_PROFILE
* @hide
*/
public abstract List<ResolveInfo> queryIntentActivitiesAsUser(Intent intent,
diff --git a/services/core/java/com/android/server/pm/LauncherAppsService.java b/services/core/java/com/android/server/pm/LauncherAppsService.java
index 25ebfc0..65cb6c9 100644
--- a/services/core/java/com/android/server/pm/LauncherAppsService.java
+++ b/services/core/java/com/android/server/pm/LauncherAppsService.java
@@ -197,7 +197,8 @@
mainIntent.setPackage(packageName);
long ident = Binder.clearCallingIdentity();
try {
- List<ResolveInfo> apps = mPm.queryIntentActivitiesAsUser(mainIntent, 0,
+ List<ResolveInfo> apps = mPm.queryIntentActivitiesAsUser(mainIntent,
+ PackageManager.NO_CROSS_PROFILE, // We only want the apps for this user
user.getIdentifier());
return apps;
} finally {
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 7fc7d0d..179b6e9 100755
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -3425,31 +3425,35 @@
// reader
synchronized (mPackages) {
final String pkgName = intent.getPackage();
+ boolean queryCrossProfile = (flags & PackageManager.NO_CROSS_PROFILE) == 0;
if (pkgName == null) {
- //Check if the intent needs to be forwarded to another user for this package
- ArrayList<ResolveInfo> crossProfileResult =
- queryIntentActivitiesCrossProfilePackage(
- intent, resolvedType, flags, userId);
- if (!crossProfileResult.isEmpty()) {
- // Skip the current profile
- return crossProfileResult;
- }
- List<ResolveInfo> result;
- List<CrossProfileIntentFilter> matchingFilters =
- getMatchingCrossProfileIntentFilters(intent, resolvedType, userId);
- // Check for results that need to skip the current profile.
- ResolveInfo resolveInfo = querySkipCurrentProfileIntents(matchingFilters, intent,
- resolvedType, flags, userId);
- if (resolveInfo != null) {
- result = new ArrayList<ResolveInfo>(1);
- result.add(resolveInfo);
- return result;
+ ResolveInfo resolveInfo;
+ if (queryCrossProfile) {
+ // Check if the intent needs to be forwarded to another user for this package
+ ArrayList<ResolveInfo> crossProfileResult =
+ queryIntentActivitiesCrossProfilePackage(
+ intent, resolvedType, flags, userId);
+ if (!crossProfileResult.isEmpty()) {
+ // Skip the current profile
+ return crossProfileResult;
+ }
+ List<CrossProfileIntentFilter> matchingFilters =
+ getMatchingCrossProfileIntentFilters(intent, resolvedType, userId);
+ // Check for results that need to skip the current profile.
+ resolveInfo = querySkipCurrentProfileIntents(matchingFilters, intent,
+ resolvedType, flags, userId);
+ if (resolveInfo != null) {
+ List<ResolveInfo> result = new ArrayList<ResolveInfo>(1);
+ result.add(resolveInfo);
+ return result;
+ }
+ // Check for cross profile results.
+ resolveInfo = queryCrossProfileIntents(
+ matchingFilters, intent, resolvedType, flags, userId);
}
// Check for results in the current profile.
- result = mActivities.queryIntent(intent, resolvedType, flags, userId);
- // Check for cross profile results.
- resolveInfo = queryCrossProfileIntents(
- matchingFilters, intent, resolvedType, flags, userId);
+ List<ResolveInfo> result = mActivities.queryIntent(
+ intent, resolvedType, flags, userId);
if (resolveInfo != null) {
result.add(resolveInfo);
}
@@ -3457,12 +3461,14 @@
}
final PackageParser.Package pkg = mPackages.get(pkgName);
if (pkg != null) {
- ArrayList<ResolveInfo> crossProfileResult =
- queryIntentActivitiesCrossProfilePackage(
- intent, resolvedType, flags, userId, pkg, pkgName);
- if (!crossProfileResult.isEmpty()) {
- // Skip the current profile
- return crossProfileResult;
+ if (queryCrossProfile) {
+ ArrayList<ResolveInfo> crossProfileResult =
+ queryIntentActivitiesCrossProfilePackage(
+ intent, resolvedType, flags, userId, pkg, pkgName);
+ if (!crossProfileResult.isEmpty()) {
+ // Skip the current profile
+ return crossProfileResult;
+ }
}
return mActivities.queryIntentForPackage(intent, resolvedType, flags,
pkg.activities, userId);