From e39e9b2f6964f644fc19ec9d7065e9e39b9cab2f Mon Sep 17 00:00:00 2001 From: kholoud mohamed Date: Wed, 18 Mar 2020 18:18:42 +0000 Subject: [PATCH] Change createRequestInteractAcrossProfilesIntent to throw Exception Change to the API to throw a security exception if the app can't request to interact rather than returning null, this is to address an API review feedback. Fixes: 151157516 Test: atest CrossProfileAppsPermissionHostSideTest Change-Id: Icdc9798a8a315cdffbe35b118c988fb60bb285af --- api/current.txt | 2 +- core/java/android/content/pm/CrossProfileApps.java | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/api/current.txt b/api/current.txt index 3327167e460de..4c08541c8159d 100644 --- a/api/current.txt +++ b/api/current.txt @@ -11570,7 +11570,7 @@ package android.content.pm { public class CrossProfileApps { method public boolean canInteractAcrossProfiles(); method public boolean canRequestInteractAcrossProfiles(); - method @Nullable public android.content.Intent createRequestInteractAcrossProfilesIntent(); + method @NonNull 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 getTargetUserProfiles(); diff --git a/core/java/android/content/pm/CrossProfileApps.java b/core/java/android/content/pm/CrossProfileApps.java index dc3a029764162..179fc5c661a5f 100644 --- a/core/java/android/content/pm/CrossProfileApps.java +++ b/core/java/android/content/pm/CrossProfileApps.java @@ -334,7 +334,7 @@ public class CrossProfileApps { * Returns an {@link Intent} to open the settings page that allows the user to decide whether * the calling app can interact across profiles. * - *

Returns {@code null} if {@link #canRequestInteractAcrossProfiles()} is {@code false}. + *

The method {@link #canRequestInteractAcrossProfiles()} must be returning {@code true}. * *

Note that the user may already have given consent and the app may already be able to * interact across profiles, even if {@link #canRequestInteractAcrossProfiles()} is {@code @@ -345,11 +345,12 @@ public class CrossProfileApps { * the app can interact across profiles * * @throws SecurityException if {@code mContext.getPackageName()} does not belong to the - * calling UID. + * calling UID, or {@link #canRequestInteractAcrossProfiles()} is {@code false}. */ - public @Nullable Intent createRequestInteractAcrossProfilesIntent() { + public @NonNull Intent createRequestInteractAcrossProfilesIntent() { if (!canRequestInteractAcrossProfiles()) { - return null; + throw new SecurityException( + "The calling package can not request to interact across profiles."); } final Intent settingsIntent = new Intent(); settingsIntent.setAction(Settings.ACTION_MANAGE_CROSS_PROFILE_ACCESS);