From 3e3f4964a6ffa169196e3bf23da6c3ec1dd05149 Mon Sep 17 00:00:00 2001 From: Alex Kershaw Date: Thu, 13 Feb 2020 22:17:29 +0000 Subject: [PATCH] Enforce the cross-profile intent check. DocumentsUI currently hard-codes the IntentForwarderActivity class name. It uses this to determine whether to show a 'switch to personal profile' button. Essentially, it wants to know if the intent it received is a cross-profile intent, so it asks package manager which intents can resolve it and checks whether one of them is IntentForwarderActivity. This is not CTS-enforced, so this CL ensures that it is. OEMs can remove or rename IntentForwarderActivity as long as they update this API and keep the corresponding CTS test passing. Bug: 149568382 Bug: 136249261 Test: atest CtsDevicePolicyManagerTestCases:com.android.cts.devicepolicy.ManagedProfileCrossProfileTest#testCrossProfileIntentFilters Change-Id: I51916c13320420068987925ac979e59bef3b660d --- api/current.txt | 1 + core/java/android/content/pm/ResolveInfo.java | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/api/current.txt b/api/current.txt index ac42e66d54f57..69dd1807a0221 100644 --- a/api/current.txt +++ b/api/current.txt @@ -12327,6 +12327,7 @@ package android.content.pm { method public int describeContents(); method public void dump(android.util.Printer, String); method public final int getIconResource(); + method public boolean isCrossProfileIntentForwarderActivity(); method public android.graphics.drawable.Drawable loadIcon(android.content.pm.PackageManager); method public CharSequence loadLabel(android.content.pm.PackageManager); method public void writeToParcel(android.os.Parcel, int); diff --git a/core/java/android/content/pm/ResolveInfo.java b/core/java/android/content/pm/ResolveInfo.java index 55846adf2f1f5..82b07f24a9063 100644 --- a/core/java/android/content/pm/ResolveInfo.java +++ b/core/java/android/content/pm/ResolveInfo.java @@ -39,6 +39,8 @@ import java.util.Comparator; */ public class ResolveInfo implements Parcelable { private static final String TAG = "ResolveInfo"; + private static final String INTENT_FORWARDER_ACTIVITY = + "com.android.internal.app.IntentForwarderActivity"; /** * The activity or broadcast receiver that corresponds to this resolution @@ -351,6 +353,16 @@ public class ResolveInfo implements Parcelable { } } + /** + * Returns whether this resolution represents the intent forwarder activity. + * + * @return whether this resolution represents the intent forwarder activity + */ + public boolean isCrossProfileIntentForwarderActivity() { + return activityInfo != null + && INTENT_FORWARDER_ACTIVITY.equals(activityInfo.targetActivity); + } + public ResolveInfo() { targetUserId = UserHandle.USER_CURRENT; }