Merge "Add createRequestInteractAcrossProfilesIntent API."
diff --git a/api/current.txt b/api/current.txt
index 737bcb6..b0d5fbf 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -11364,6 +11364,7 @@
public class CrossProfileApps {
method public boolean canInteractAcrossProfiles();
method public boolean canRequestInteractAcrossProfiles();
+ method @Nullable public android.content.Intent createRequestInteractAcrossProfilesIntent();
method @NonNull public android.graphics.drawable.Drawable getProfileSwitchingIconDrawable(@NonNull android.os.UserHandle);
method @NonNull public CharSequence getProfileSwitchingLabel(@NonNull android.os.UserHandle);
method @NonNull public java.util.List<android.os.UserHandle> getTargetUserProfiles();
diff --git a/core/java/android/content/pm/CrossProfileApps.java b/core/java/android/content/pm/CrossProfileApps.java
index abf32c5e..9d57514 100644
--- a/core/java/android/content/pm/CrossProfileApps.java
+++ b/core/java/android/content/pm/CrossProfileApps.java
@@ -16,15 +16,19 @@
package android.content.pm;
import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.content.ComponentName;
import android.content.Context;
+import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
+import android.net.Uri;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
+import android.provider.Settings;
import com.android.internal.R;
import com.android.internal.util.UserIcons;
@@ -226,6 +230,30 @@
}
}
+ /**
+ * Returns an {@link Intent} to open the settings page that allows the user to decide whether
+ * the calling app can interact across profiles. The current state is given by
+ * {@link #canInteractAcrossProfiles()}.
+ *
+ * <p>Returns {@code null} if {@link #canRequestInteractAcrossProfiles()} is {@code false}.
+ *
+ * @return an {@link Intent} to open the settings page that allows the user to decide whether
+ * the app can interact across profiles
+ *
+ * @throws SecurityException if {@code mContext.getPackageName()} does not belong to the
+ * calling UID.
+ */
+ public @Nullable Intent createRequestInteractAcrossProfilesIntent() {
+ if (!canRequestInteractAcrossProfiles()) {
+ return null;
+ }
+ final Intent settingsIntent = new Intent();
+ settingsIntent.setAction(Settings.ACTION_MANAGE_CROSS_PROFILE_ACCESS);
+ final Uri packageUri = Uri.parse("package:" + mContext.getPackageName());
+ settingsIntent.setData(packageUri);
+ return settingsIntent;
+ }
+
private void verifyCanAccessUser(UserHandle userHandle) {
if (!getTargetUserProfiles().contains(userHandle)) {
throw new SecurityException("Not allowed to access " + userHandle);
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 0680523..a31c3d1 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -389,6 +389,21 @@
"android.settings.MANAGE_UNKNOWN_APP_SOURCES";
/**
+ * Activity Action: Show settings to allow configuration of cross-profile access for apps
+ *
+ * Input: Optionally, the Intent's data URI can specify the application package name to
+ * directly invoke the management GUI specific to the package name. For example
+ * "package:com.my.app".
+ * <p>
+ * Output: Nothing.
+ *
+ * @hide
+ */
+ @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
+ public static final String ACTION_MANAGE_CROSS_PROFILE_ACCESS =
+ "android.settings.MANAGE_CROSS_PROFILE_ACCESS";
+
+ /**
* Activity Action: Show the "Open by Default" page in a particular application's details page.
* <p>
* In some cases, a matching Activity may not exist, so ensure you safeguard against this.