Package org.robolectric.shadows
Class ShadowContextWrapper
java.lang.Object
org.robolectric.shadows.ShadowContextWrapper
- Direct Known Subclasses:
ShadowApplication
,ShadowContextThemeWrapper
,ShadowService
@Implements(android.content.ContextWrapper.class) public class ShadowContextWrapper extends Object
-
Constructor Summary
Constructors Constructor Description ShadowContextWrapper()
-
Method Summary
Modifier and Type Method Description void
clearBroadcastIntents()
Clears the broadcast intents sent during the tests (for all users).void
clearNextStartedActivities()
Clears allIntent
s started byContextWrapper.startActivity(android.content.Intent)
.void
clearStartedServices()
Clears allIntent
started byContext.startService(android.content.Intent)
.void
denyPermissions(int pid, int uid, String... permissions)
Revoke the given permissions for the given process and user.void
denyPermissions(String... permissionNames)
Revoke the given permissions for the current process and user.List<Intent>
getAllStartedServices()
Returns allIntent
started by#startService(android.content.Intent)
without consuming them.List<Intent>
getBroadcastIntents()
Returns the broadcast intents sent during the tests (for all users).List<Intent>
getBroadcastIntentsForUser(UserHandle userHandle)
Returns the broadcast intents sent to the given user.Bundle
getBroadcastOptions(Intent intent)
Returns the broadcast options when the intent was last sent.Intent
getNextStartedActivity()
Consumes the most recentIntent
started byContextWrapper.startActivity(android.content.Intent)
and returns it.ShadowActivity.IntentForResult
getNextStartedActivityForResult()
Consumes the most recentIntentForResult
started by {@link * ContextWrapper#startActivity(android.content.Intent, android.os.Bundle)} and returns it.Intent
getNextStartedService()
Consumes the most recentIntent
started byContext.startService(android.content.Intent)
and returns it.Intent
getNextStoppedService()
Consumes theIntent
requested to stop a service byContext.stopService(android.content.Intent)
from the bottom of the stack of stop requests.void
grantPermissions(int pid, int uid, String... permissions)
Grant the given permissions for the given process and user.void
grantPermissions(String... permissionNames)
Grant the given permissions for the current process and user.Intent
peekNextStartedActivity()
Returns the most recentIntent
started byContextWrapper.startActivity(android.content.Intent)
without consuming it.ShadowActivity.IntentForResult
peekNextStartedActivityForResult()
Returns the most recentIntentForResult
started byContextWrapper.startActivity(android.content.Intent, android.os.Bundle)
without consuming it.Intent
peekNextStartedService()
Returns the most recentIntent
started byContext.startService(android.content.Intent)
without consuming it.void
removeSystemService(String name)
MakesContext.getSystemService(String)
returnnull
for the given system service name, mimicking a device that doesn't have that system service.
-
Constructor Details
-
ShadowContextWrapper
public ShadowContextWrapper()
-
-
Method Details
-
getBroadcastIntents
Returns the broadcast intents sent during the tests (for all users). -
getBroadcastOptions
Returns the broadcast options when the intent was last sent. -
getBroadcastIntentsForUser
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
Consumes the most recentIntent
started byContextWrapper.startActivity(android.content.Intent)
and returns it.- Returns:
- the most recently started
Intent
-
peekNextStartedActivity
Returns the most recentIntent
started byContextWrapper.startActivity(android.content.Intent)
without consuming it.- Returns:
- the most recently started
Intent
-
clearNextStartedActivities
public void clearNextStartedActivities()Clears allIntent
s started byContextWrapper.startActivity(android.content.Intent)
. -
getNextStartedActivityForResult
Consumes the most recentIntentForResult
started by {@link * ContextWrapper#startActivity(android.content.Intent, android.os.Bundle)} and returns it.- Returns:
- the most recently started
IntentForResult
-
peekNextStartedActivityForResult
Returns the most recentIntentForResult
started byContextWrapper.startActivity(android.content.Intent, android.os.Bundle)
without consuming it.- Returns:
- the most recently started
IntentForResult
-
getNextStartedService
Consumes the most recentIntent
started byContext.startService(android.content.Intent)
and returns it.- Returns:
- the most recently started
Intent
-
peekNextStartedService
Returns the most recentIntent
started byContext.startService(android.content.Intent)
without consuming it.- Returns:
- the most recently started
Intent
-
getAllStartedServices
Returns allIntent
started by#startService(android.content.Intent)
without consuming them.- Returns:
- the list of
Intent
-
clearStartedServices
public void clearStartedServices()Clears allIntent
started byContext.startService(android.content.Intent)
. -
getNextStoppedService
Consumes theIntent
requested to stop a service byContext.stopService(android.content.Intent)
from the bottom of the stack of stop requests. -
grantPermissions
Grant the given permissions for the current process and user. -
grantPermissions
Grant the given permissions for the given process and user. -
denyPermissions
Revoke the given permissions for the current process and user.Has no effect if permissions were not previously granted.
-
denyPermissions
Revoke the given permissions for the given process and user. -
removeSystemService
MakesContext.getSystemService(String)
returnnull
for the given system service name, mimicking a device that doesn't have that system service.
-