Package org.robolectric.shadows
Class ShadowContextImpl
java.lang.Object
org.robolectric.shadows.ShadowContextImpl
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Reflector interface forContextImpl
's internals. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
bindService
(Intent service, int flags, Executor executor, ServiceConnection conn) protected boolean
bindService
(Intent intent, ServiceConnection serviceConnection, int i) protected boolean
bindServiceAsUser
(Intent intent, ServiceConnection serviceConnection, int i, UserHandle userHandle) Binds to a service but ignores the given UserHandle.protected int
checkCallingOrSelfPermission
(String permission) protected int
checkCallingPermission
(String permission) protected int
checkPermission
(String permission, int pid, int uid) protected ClassLoader
protected ContentResolver
getDatabasePath
(String name) protected File
getExternalFilesDir
(String type) protected File[]
getExternalFilesDirs
(String type) protected SharedPreferences
getSharedPreferences
(String name, int mode) protected Object
getSystemService
(String name) Returns the handle to a system-level service by name.protected int
protected Intent
registerReceiver
(BroadcastReceiver receiver, IntentFilter filter) protected Intent
registerReceiver
(BroadcastReceiver receiver, IntentFilter filter, int flags) protected Intent
registerReceiver
(BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission, Handler scheduler) protected Intent
registerReceiver
(BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission, Handler scheduler, int flags) protected Intent
registerReceiverAsUser
(BroadcastReceiver receiver, UserHandle user, IntentFilter filter, String broadcastPermission, Handler scheduler) void
removeSystemService
(String name) MakesgetSystemService(String)
returnnull
for the given system service name, mimicking a device that doesn't have that system service.static void
reset()
protected void
sendBroadcast
(Intent intent) protected void
sendBroadcast
(Intent intent, String receiverPermission) protected void
sendBroadcast
(Intent intent, String receiverPermission, Bundle options) protected void
sendBroadcastAsUser
(Intent intent, UserHandle user) protected void
sendBroadcastAsUser
(Intent intent, UserHandle user, String receiverPermission) protected void
sendOrderedBroadcast
(Intent intent, String receiverPermission) protected void
sendOrderedBroadcast
(Intent intent, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras) protected void
sendOrderedBroadcastAsUser
(Intent intent, UserHandle userHandle, String receiverPermission, int appOp, Bundle options, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras) protected void
sendOrderedBroadcastAsUser
(Intent intent, UserHandle userHandle, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras) Allows the test to query for the broadcasts for specific users, for everything else behaves assendOrderedBroadcastAsUser(android.content.Intent, android.os.UserHandle, java.lang.String, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle)
.protected void
sendStickyBroadcast
(Intent intent) void
setSystemService
(String key, Object service) void
setUserId
(int userId) Set the user id returned bygetUserId()
.protected void
startActivityAsUser
(Intent intent, Bundle options, UserHandle user) Behaves asContext.startActivity(Intent, Bundle)
.protected ComponentName
startForegroundService
(Intent service) protected void
startIntentSender
(IntentSender intent, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) protected ComponentName
startService
(Intent service) protected boolean
stopService
(Intent name) protected void
unbindService
(ServiceConnection serviceConnection) protected void
unregisterReceiver
(BroadcastReceiver broadcastReceiver) protected void
validateServiceIntent
(Intent service)
-
Field Details
-
CLASS_NAME
- See Also:
-
-
Constructor Details
-
ShadowContextImpl
public ShadowContextImpl()
-
-
Method Details
-
getSystemService
Returns the handle to a system-level service by name. If the service is not available in Roboletric, or it is set to unavailable inShadowServiceManager.setServiceAvailability(java.lang.String, boolean)
,null
will be returned. -
setSystemService
-
removeSystemService
MakesgetSystemService(String)
returnnull
for the given system service name, mimicking a device that doesn't have that system service. -
startIntentSender
@Implementation protected void startIntentSender(IntentSender intent, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options) throws IntentSender.SendIntentException - Throws:
IntentSender.SendIntentException
-
getClassLoader
-
checkCallingPermission
-
checkCallingOrSelfPermission
-
getContentResolver
-
sendBroadcast
-
sendBroadcast
-
sendBroadcast
@Implementation(minSdk=33) protected void sendBroadcast(Intent intent, String receiverPermission, Bundle options) -
sendBroadcastAsUser
-
sendBroadcastAsUser
@Implementation protected void sendBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission) -
sendOrderedBroadcast
-
sendOrderedBroadcast
@Implementation protected void sendOrderedBroadcast(Intent intent, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras) -
sendOrderedBroadcastAsUser
@Implementation protected void sendOrderedBroadcastAsUser(Intent intent, UserHandle userHandle, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras) Allows the test to query for the broadcasts for specific users, for everything else behaves assendOrderedBroadcastAsUser(android.content.Intent, android.os.UserHandle, java.lang.String, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle)
. -
sendOrderedBroadcastAsUser
@Implementation(minSdk=23) protected void sendOrderedBroadcastAsUser(Intent intent, UserHandle userHandle, String receiverPermission, int appOp, Bundle options, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras) Behaves assendOrderedBroadcastAsUser(android.content.Intent, android.os.UserHandle, java.lang.String, android.content.BroadcastReceiver, android.os.Handler, int, java.lang.String, android.os.Bundle)
. Currently ignores appOp and options. -
sendStickyBroadcast
-
checkPermission
-
registerReceiver
-
registerReceiver
@Implementation(minSdk=26) protected Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, int flags) -
registerReceiver
@Implementation protected Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission, Handler scheduler) -
registerReceiver
@Implementation(minSdk=26) protected Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission, Handler scheduler, int flags) -
registerReceiverAsUser
@Implementation protected Intent registerReceiverAsUser(BroadcastReceiver receiver, UserHandle user, IntentFilter filter, String broadcastPermission, Handler scheduler) -
unregisterReceiver
-
startService
-
startForegroundService
-
stopService
-
bindService
@Implementation(minSdk=29) protected boolean bindService(Intent service, int flags, Executor executor, ServiceConnection conn) -
bindService
@Implementation protected boolean bindService(Intent intent, ServiceConnection serviceConnection, int i) -
bindServiceAsUser
@Implementation(minSdk=21) protected boolean bindServiceAsUser(Intent intent, ServiceConnection serviceConnection, int i, UserHandle userHandle) Binds to a service but ignores the given UserHandle. -
unbindService
-
validateServiceIntent
-
startActivityAsUser
@Implementation(minSdk=21) protected void startActivityAsUser(Intent intent, Bundle options, UserHandle user) Behaves asContext.startActivity(Intent, Bundle)
. The user parameter is ignored. -
setUserId
public void setUserId(int userId) Set the user id returned bygetUserId()
. -
getUserId
-
getExternalFilesDir
-
getExternalFilesDirs
-
reset
-
getDatabasePath
-