Class ShadowCrossProfileApps


  • @Implements(value=android.content.pm.CrossProfileApps.class,
                minSdk=28)
    public class ShadowCrossProfileApps
    extends java.lang.Object
    Robolectric implementation of CrossProfileApps.
    • Constructor Detail

      • ShadowCrossProfileApps

        public ShadowCrossProfileApps()
    • Method Detail

      • __constructor__

        @Implementation
        protected void __constructor__​(android.content.Context context,
                                       android.content.pm.ICrossProfileApps service)
      • getTargetUserProfiles

        @Implementation
        protected java.util.List<android.os.UserHandle> getTargetUserProfiles()
        Returns a list of UserHandles currently accessible. This list is populated from calls to addTargetUserProfile(UserHandle).
      • getProfileSwitchingIconDrawable

        @Implementation
        protected android.graphics.drawable.Drawable getProfileSwitchingIconDrawable​(android.os.UserHandle userHandle)
        Returns a Drawable that 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

        @Implementation
        protected java.lang.CharSequence getProfileSwitchingLabel​(android.os.UserHandle userHandle)
        Returns a CharSequence that 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​(android.content.ComponentName componentName,
                                         android.os.UserHandle targetUser)
        Simulates starting the main activity specified in the specified profile, performing the same security checks done by the real CrossProfileApps.

        The most recent main activity started can be queried by peekNextStartedActivity() ()}.

      • startActivity

        @Implementation(minSdk=29)
        protected void startActivity​(android.content.ComponentName componentName,
                                     android.os.UserHandle targetUser)
        Simulates starting the activity specified in the specified profile, performing the same security checks done by the real CrossProfileApps.

        The most recent main activity started can be queried by peekNextStartedActivity() ()}.

      • addTargetUserProfile

        public void addTargetUserProfile​(android.os.UserHandle userHandle)
        Adds userHandle to the list of accessible handles.
      • removeTargetUserProfile

        public void removeTargetUserProfile​(android.os.UserHandle userHandle)
        Removes userHandle from the list of accessible handles, if present.
      • clearTargetUserProfiles

        public void clearTargetUserProfiles()
        Clears the list of accessible handles.
      • clearNextStartedActivities

        public void clearNextStartedActivities()
        Clears all records of ShadowCrossProfileApps.StartedActivitys from calls to CrossProfileApps.startActivity(ComponentName, UserHandle) or CrossProfileApps.startMainActivity(ComponentName, UserHandle).
      • verifyHasInteractAcrossProfilesPermission

        protected void verifyHasInteractAcrossProfilesPermission()
        Ensure the current package has the permission to interact across profiles.