Class ShadowCrossProfileApps
CrossProfileApps.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classContainer object to hold parameters passed tostartMainActivity(ComponentName, UserHandle)orstartActivity(ComponentName, UserHandle),startActivity(Intent, UserHandle, Activity),startActivity(Intent, UserHandle, Activity, Bundle).static classDeprecated. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void__constructor__(Context context, ICrossProfileApps service) voidaddTargetUserProfile(UserHandle userHandle) AddsuserHandleto the list of accessible handles.protected booleancanConfigureInteractAcrossProfiles(String packageName) Unlike the real system, we will assume a package can always configure its own cross profile interaction.protected booleanChecks if the current application can interact across profile.protected booleanReturns whether the calling package can request to navigate the user to the relevant settings page to request user consent to interact across profiles.voidvoidClears the list of accessible handles.protected IntentReturns an intent with the same action as the one returned by system when requesting the same.Consumes the most recentComponentName,UserHandlepair started byCrossProfileApps.startMainActivity(ComponentName, UserHandle)orCrossProfileApps.startActivity(ComponentName, UserHandle),startActivity(Intent, UserHandle, Activity),startActivity(Intent, UserHandle, Activity, Bundle), and returns it wrapped inShadowCrossProfileApps.StartedActivity.protected DrawablegetProfileSwitchingIconDrawable(UserHandle userHandle) Returns aDrawablethat can be shown for profile switching, which is guaranteed to always be the same for a particular user and to be distinct between users.protected CharSequencegetProfileSwitchingLabel(UserHandle userHandle) Returns aCharSequencethat can be shown as a label for profile switching, which is guaranteed to always be the same for a particular user and to be distinct between users.protected List<UserHandle>Returns a list ofUserHandles currently accessible.booleanChecks whether the given intent will redirect toward the screen allowing the user to change the interact across profiles AppOps.Returns the most recentComponentName,UserHandlepair started byCrossProfileApps.startMainActivity(ComponentName, UserHandle)orCrossProfileApps.startActivity(ComponentName, UserHandle),startActivity(Intent, UserHandle, Activity),startActivity(Intent, UserHandle, Activity, Bundle), wrapped inShadowCrossProfileApps.StartedActivity.Deprecated.UsepeekNextStartedActivity()instead.voidremoveTargetUserProfile(UserHandle userHandle) RemovesuserHandlefrom the list of accessible handles, if present.voidsetHasRequestedInteractAcrossProfiles(boolean value) Sets whether or not the current application has requested the interact across profile permission in its manifest.voidsetInteractAcrossProfilesAppOp(int newMode) Forces the {code interact_across_profile} AppOps for the current package.protected voidsetInteractAcrossProfilesAppOp(String packageName, int newMode) Checks permission and changes the AppOps value stored inShadowCrossProfileApps.protected voidstartActivity(ComponentName componentName, UserHandle targetUser) Simulates starting the activity specified in the specified profile, performing the same security checks done by the realCrossProfileApps.protected voidstartActivity(Intent intent, UserHandle targetUser, Activity activity) Simulates starting the activity specified in the specified profile, performing the same security checks done by the realCrossProfileApps.protected voidstartActivity(Intent intent, UserHandle targetUser, Activity activity, Bundle options) Simulates starting the activity specified in the specified profile, performing the same security checks done by the realCrossProfileApps.protected voidstartMainActivity(ComponentName componentName, UserHandle targetUser) Simulates starting the main activity specified in the specified profile, performing the same security checks done by the realCrossProfileApps.protected voidverifyCanAccessUser(UserHandle userHandle) protected voidEnsure the current package has the permission to interact across profiles.
-
Constructor Details
-
ShadowCrossProfileApps
public ShadowCrossProfileApps()
-
-
Method Details
-
__constructor__
-
getTargetUserProfiles
Returns a list ofUserHandles currently accessible. This list is populated from calls toaddTargetUserProfile(UserHandle). -
getProfileSwitchingIconDrawable
Returns aDrawablethat can be shown for profile switching, which is guaranteed to always be the same for a particular user and to be distinct between users. -
getProfileSwitchingLabel
Returns aCharSequencethat can be shown as a label for profile switching, which is guaranteed to always be the same for a particular user and to be distinct between users. -
startMainActivity
@Implementation protected void startMainActivity(ComponentName componentName, UserHandle targetUser) Simulates starting the main activity specified in the specified profile, performing the same security checks done by the realCrossProfileApps.The most recent main activity started can be queried by
peekNextStartedActivity(). -
startActivity
@Implementation(minSdk=29) protected void startActivity(ComponentName componentName, UserHandle targetUser) Simulates starting the activity specified in the specified profile, performing the same security checks done by the realCrossProfileApps.The most recent main activity started can be queried by
peekNextStartedActivity(). -
startActivity
@Implementation(minSdk=30) protected void startActivity(Intent intent, UserHandle targetUser, @Nullable Activity activity) Simulates starting the activity specified in the specified profile, performing the same security checks done by the realCrossProfileApps.The most recent main activity started can be queried by
peekNextStartedActivity(). -
startActivity
@Implementation(minSdk=30) protected void startActivity(Intent intent, UserHandle targetUser, @Nullable Activity activity, @Nullable Bundle options) Simulates starting the activity specified in the specified profile, performing the same security checks done by the realCrossProfileApps.The most recent main activity started can be queried by
peekNextStartedActivity(). -
addTargetUserProfile
AddsuserHandleto the list of accessible handles. -
removeTargetUserProfile
RemovesuserHandlefrom the list of accessible handles, if present. -
clearTargetUserProfiles
public void clearTargetUserProfiles()Clears the list of accessible handles. -
peekNextStartedMainActivity
@Nullable @Deprecated public ShadowCrossProfileApps.StartedMainActivity peekNextStartedMainActivity()Deprecated.UsepeekNextStartedActivity()instead.Returns the most recentComponentName,UserHandlepair started byCrossProfileApps.startMainActivity(ComponentName, UserHandle), wrapped inShadowCrossProfileApps.StartedMainActivity. -
peekNextStartedActivity
Returns the most recentComponentName,UserHandlepair started byCrossProfileApps.startMainActivity(ComponentName, UserHandle)orCrossProfileApps.startActivity(ComponentName, UserHandle),startActivity(Intent, UserHandle, Activity),startActivity(Intent, UserHandle, Activity, Bundle), wrapped inShadowCrossProfileApps.StartedActivity. -
getNextStartedActivity
Consumes the most recentComponentName,UserHandlepair started byCrossProfileApps.startMainActivity(ComponentName, UserHandle)orCrossProfileApps.startActivity(ComponentName, UserHandle),startActivity(Intent, UserHandle, Activity),startActivity(Intent, UserHandle, Activity, Bundle), and returns it wrapped inShadowCrossProfileApps.StartedActivity. -
clearNextStartedActivities
public void clearNextStartedActivities() -
verifyCanAccessUser
-
verifyHasInteractAcrossProfilesPermission
protected void verifyHasInteractAcrossProfilesPermission()Ensure the current package has the permission to interact across profiles. -
canInteractAcrossProfiles
Checks if the current application can interact across profile.This checks for the existence of a target user profile, and if the app has INTERACT_ACROSS_USERS, INTERACT_ACROSS_USERS_FULL or INTERACT_ACROSS_PROFILES permission. Importantly, the
interact_across_profilesAppOps is only checked through the value set bysetInteractAcrossProfilesAppOp(int)or bysetInteractAcrossProfilesAppOp(String, int), if the application has the needed permissions. -
canRequestInteractAcrossProfiles
Returns whether the calling package can request to navigate the user to the relevant settings page to request user consent to interact across profiles.This checks for the existence of a target user profile, and if the app has requested the INTERACT_ACROSS_PROFILES permission in its manifest. As Robolectric doesn't interpret the permissions in the manifest, whether or not the app has requested this is defined by
setHasRequestedInteractAcrossProfiles(boolean).If the test uses
setInteractAcrossProfilesAppOp(int), it implies the app has requested the AppOps.In short, compared to
canInteractAcrossProfiles(), it doesn't check if the user has the AppOps or not. -
setHasRequestedInteractAcrossProfiles
public void setHasRequestedInteractAcrossProfiles(boolean value) Sets whether or not the current application has requested the interact across profile permission in its manifest. -
createRequestInteractAcrossProfilesIntent
Returns an intent with the same action as the one returned by system when requesting the same.Note: Currently, the system will also set the package name as a URI, but as this is not specified in the main doc, we shouldn't rely on it. The purpose is only to make an intent can that be recognised in a test.
- Throws:
SecurityException- if this is called whileCrossProfileApps.canRequestInteractAcrossProfiles()returns false.
-
isRequestInteractAcrossProfilesIntent
Checks whether the given intent will redirect toward the screen allowing the user to change the interact across profiles AppOps. -
setInteractAcrossProfilesAppOp
public void setInteractAcrossProfilesAppOp(int newMode) Forces the {code interact_across_profile} AppOps for the current package.If the value changes, this also sends the
CrossProfileApps.ACTION_CAN_INTERACT_ACROSS_PROFILES_CHANGEDbroadcast. -
setInteractAcrossProfilesAppOp
@Implementation(minSdk=30) protected void setInteractAcrossProfilesAppOp(String packageName, int newMode) Checks permission and changes the AppOps value stored inShadowCrossProfileApps.In the real implementation, if there is no target profile, the AppOps is not changed, as it will be set during the profile's initialization. The real implementation also really changes the AppOps for all profiles the package is installed in.
-
canConfigureInteractAcrossProfiles
Unlike the real system, we will assume a package can always configure its own cross profile interaction.
-
peekNextStartedActivity()andShadowCrossProfileApps.StartedActivityinstead.