summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorJonathan Scott <scottjonathan@google.com>2020-01-20 16:22:58 +0000
committerJonathan Scott <scottjonathan@google.com>2020-01-21 20:10:36 +0000
commitd72fc8d3db63e6c801ca4b3c379f21059fd8cd8c (patch)
treed6facb9f28936b98d598d92406c7aa6167f7a7a8 /core/java/android
parentb492f4e34713bcc825906250610ca55149ad6130 (diff)
Add CrossProfileApps#startActivity which takes an Intent.
Test: atest com.android.cts.devicepolicy.CrossProfileAppsHostSideTest Bug: 136249261 Change-Id: I2735dc480126daf457cc1fd09bbeae243d4e3db0
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/content/pm/CrossProfileApps.java26
-rw-r--r--core/java/android/content/pm/ICrossProfileApps.aidl2
2 files changed, 28 insertions, 0 deletions
diff --git a/core/java/android/content/pm/CrossProfileApps.java b/core/java/android/content/pm/CrossProfileApps.java
index 5aa9c9bebc2c..48f473018127 100644
--- a/core/java/android/content/pm/CrossProfileApps.java
+++ b/core/java/android/content/pm/CrossProfileApps.java
@@ -94,6 +94,32 @@ public class CrossProfileApps {
}
/**
+ * Starts the specified activity of the caller package in the specified profile.
+ *
+ * <p>The caller must have the {@link android.Manifest.permission#INTERACT_ACROSS_PROFILES}
+ * permission and both the caller and target user profiles must be in the same profile group.
+ *
+ * @param intent The intent to launch. A component in the caller package must be specified.
+ * @param targetUser The {@link UserHandle} of the profile; must be one of the users returned by
+ * {@link #getTargetUserProfiles()} if different to the calling user, otherwise a
+ * {@link SecurityException} will be thrown.
+ */
+ @RequiresPermission(anyOf = {
+ android.Manifest.permission.INTERACT_ACROSS_PROFILES,
+ android.Manifest.permission.INTERACT_ACROSS_USERS})
+ public void startActivity(@NonNull Intent intent, @NonNull UserHandle targetUser) {
+ try {
+ mService.startActivityAsUserByIntent(
+ mContext.getIApplicationThread(),
+ mContext.getPackageName(),
+ intent,
+ targetUser.getIdentifier());
+ } catch (RemoteException ex) {
+ throw ex.rethrowFromSystemServer();
+ }
+ }
+
+ /**
* Starts the specified activity of the caller package in the specified profile. Unlike
* {@link #startMainActivity}, this can start any activity of the caller package, not just
* the main activity.
diff --git a/core/java/android/content/pm/ICrossProfileApps.aidl b/core/java/android/content/pm/ICrossProfileApps.aidl
index 694b1a3c4e73..755950cd5ebe 100644
--- a/core/java/android/content/pm/ICrossProfileApps.aidl
+++ b/core/java/android/content/pm/ICrossProfileApps.aidl
@@ -29,6 +29,8 @@ import android.os.UserHandle;
interface ICrossProfileApps {
void startActivityAsUser(in IApplicationThread caller, in String callingPackage,
in ComponentName component, int userId, boolean launchMainActivity);
+ void startActivityAsUserByIntent(in IApplicationThread caller, in String callingPackage,
+ in Intent intent, int userId);
List<UserHandle> getTargetUserProfiles(in String callingPackage);
boolean canInteractAcrossProfiles(in String callingPackage);
boolean canRequestInteractAcrossProfiles(in String callingPackage);