Class ShadowContextWrapper

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clearBroadcastIntents()
      Clears the broadcast intents sent during the tests (for all users).
      void clearNextStartedActivities()
      Clears all Intents started by ContextWrapper.startActivity(android.content.Intent).
      void clearStartedServices()
      Clears all Intent started by Context.startService(android.content.Intent).
      void denyPermissions​(int pid, int uid, java.lang.String... permissions)
      Revoke the given permissions for the given process and user.
      void denyPermissions​(java.lang.String... permissionNames)
      Revoke the given permissions for the current process and user.
      java.util.List<android.content.Intent> getBroadcastIntents()
      Returns the broadcast intents sent during the tests (for all users).
      java.util.List<android.content.Intent> getBroadcastIntentsForUser​(android.os.UserHandle userHandle)
      Returns the broadcast intents sent to the given user.
      android.content.Intent getNextStartedActivity()
      Consumes the most recent Intent started by ContextWrapper.startActivity(android.content.Intent) and returns it.
      ShadowActivity.IntentForResult getNextStartedActivityForResult()
      Consumes the most recent IntentForResult started by {@link * ContextWrapper#startActivity(android.content.Intent, android.os.Bundle)} and returns it.
      android.content.Intent getNextStartedService()
      Consumes the most recent Intent started by Context.startService(android.content.Intent) and returns it.
      android.content.Intent getNextStoppedService()
      Consumes the Intent requested to stop a service by Context.stopService(android.content.Intent) from the bottom of the stack of stop requests.
      void grantPermissions​(int pid, int uid, java.lang.String... permissions)
      Grant the given permissions for the given process and user.
      void grantPermissions​(java.lang.String... permissionNames)
      Grant the given permissions for the current process and user.
      android.content.Intent peekNextStartedActivity()
      Returns the most recent Intent started by ContextWrapper.startActivity(android.content.Intent) without consuming it.
      ShadowActivity.IntentForResult peekNextStartedActivityForResult()
      Returns the most recent IntentForResult started by ContextWrapper.startActivity(android.content.Intent, android.os.Bundle) without consuming it.
      android.content.Intent peekNextStartedService()
      Returns the most recent Intent started by Context.startService(android.content.Intent) without consuming it.
      void removeSystemService​(java.lang.String name)
      Makes Context.getSystemService(String) return null for the given system service name, mimicking a device that doesn't have that system service.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ShadowContextWrapper

        public ShadowContextWrapper()
    • Method Detail

      • getBroadcastIntents

        public java.util.List<android.content.Intent> getBroadcastIntents()
        Returns the broadcast intents sent during the tests (for all users).
      • getBroadcastIntentsForUser

        public java.util.List<android.content.Intent> getBroadcastIntentsForUser​(android.os.UserHandle userHandle)
        Returns the broadcast intents sent to the given user.
      • clearBroadcastIntents

        public void clearBroadcastIntents()
        Clears the broadcast intents sent during the tests (for all users).
      • getNextStartedActivity

        public android.content.Intent getNextStartedActivity()
        Consumes the most recent Intent started by ContextWrapper.startActivity(android.content.Intent) and returns it.
        Returns:
        the most recently started Intent
      • peekNextStartedActivity

        public android.content.Intent peekNextStartedActivity()
        Returns the most recent Intent started by ContextWrapper.startActivity(android.content.Intent) without consuming it.
        Returns:
        the most recently started Intent
      • clearNextStartedActivities

        public void clearNextStartedActivities()
        Clears all Intents started by ContextWrapper.startActivity(android.content.Intent).
      • getNextStartedActivityForResult

        public ShadowActivity.IntentForResult getNextStartedActivityForResult()
        Consumes the most recent IntentForResult started by {@link * ContextWrapper#startActivity(android.content.Intent, android.os.Bundle)} and returns it.
        Returns:
        the most recently started IntentForResult
      • peekNextStartedActivityForResult

        public ShadowActivity.IntentForResult peekNextStartedActivityForResult()
        Returns the most recent IntentForResult started by ContextWrapper.startActivity(android.content.Intent, android.os.Bundle) without consuming it.
        Returns:
        the most recently started IntentForResult
      • getNextStartedService

        public android.content.Intent getNextStartedService()
        Consumes the most recent Intent started by Context.startService(android.content.Intent) and returns it.
        Returns:
        the most recently started Intent
      • peekNextStartedService

        public android.content.Intent peekNextStartedService()
        Returns the most recent Intent started by Context.startService(android.content.Intent) without consuming it.
        Returns:
        the most recently started Intent
      • clearStartedServices

        public void clearStartedServices()
        Clears all Intent started by Context.startService(android.content.Intent).
      • getNextStoppedService

        public android.content.Intent getNextStoppedService()
        Consumes the Intent requested to stop a service by Context.stopService(android.content.Intent) from the bottom of the stack of stop requests.
      • grantPermissions

        public void grantPermissions​(java.lang.String... permissionNames)
        Grant the given permissions for the current process and user.
      • grantPermissions

        public void grantPermissions​(int pid,
                                     int uid,
                                     java.lang.String... permissions)
        Grant the given permissions for the given process and user.
      • denyPermissions

        public void denyPermissions​(java.lang.String... permissionNames)
        Revoke the given permissions for the current process and user. Has no effect if permissions were not previously granted.
      • denyPermissions

        public void denyPermissions​(int pid,
                                    int uid,
                                    java.lang.String... permissions)
        Revoke the given permissions for the given process and user.
      • removeSystemService

        public void removeSystemService​(java.lang.String name)
        Makes Context.getSystemService(String) return null for the given system service name, mimicking a device that doesn't have that system service.