Package org.robolectric.shadows
Class ShadowContextImpl
- java.lang.Object
-
- org.robolectric.shadows.ShadowContextImpl
-
@Implements(className="android.app.ContextImpl") public class ShadowContextImpl extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceShadowContextImpl._ContextImpl_Reflector interface forContextImpl's internals.
-
Field Summary
Fields Modifier and Type Field Description static StringCLASS_NAME
-
Constructor Summary
Constructors Constructor Description ShadowContextImpl()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanbindService(Intent service, int flags, Executor executor, ServiceConnection conn)protected booleanbindService(Intent intent, ServiceConnection serviceConnection, int i)protected booleanbindServiceAsUser(Intent intent, ServiceConnection serviceConnection, int i, UserHandle userHandle)Binds to a service but ignores the given UserHandle.protected intcheckCallingOrSelfPermission(String permission)protected intcheckCallingPermission(String permission)protected intcheckPermission(String permission, int pid, int uid)protected ClassLoadergetClassLoader()protected ContentResolvergetContentResolver()FilegetDatabasePath(String name)protected FilegetExternalFilesDir(String type)protected File[]getExternalFilesDirs(String type)protected SharedPreferencesgetSharedPreferences(String name, int mode)protected ObjectgetSystemService(String name)Returns the handle to a system-level service by name.protected intgetUserId()protected IntentregisterReceiver(BroadcastReceiver receiver, IntentFilter filter)protected IntentregisterReceiver(BroadcastReceiver receiver, IntentFilter filter, int flags)protected IntentregisterReceiver(BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission, Handler scheduler)protected IntentregisterReceiver(BroadcastReceiver receiver, IntentFilter filter, String broadcastPermission, Handler scheduler, int flags)protected IntentregisterReceiverAsUser(BroadcastReceiver receiver, UserHandle user, IntentFilter filter, String broadcastPermission, Handler scheduler)voidremoveSystemService(String name)MakesgetSystemService(String)returnnullfor the given system service name, mimicking a device that doesn't have that system service.static voidreset()protected voidsendBroadcast(Intent intent)protected voidsendBroadcast(Intent intent, String receiverPermission)protected voidsendBroadcastAsUser(Intent intent, UserHandle user)protected voidsendBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission)protected voidsendOrderedBroadcast(Intent intent, String receiverPermission)protected voidsendOrderedBroadcast(Intent intent, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)protected voidsendOrderedBroadcastAsUser(Intent intent, UserHandle userHandle, String receiverPermission, int appOp, Bundle options, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)protected voidsendOrderedBroadcastAsUser(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 voidsendStickyBroadcast(Intent intent)voidsetSystemService(String key, Object service)voidsetUserId(int userId)protected voidstartActivityAsUser(Intent intent, Bundle options, UserHandle user)Behaves asContext.startActivity(Intent, Bundle).protected ComponentNamestartForegroundService(Intent service)protected voidstartIntentSender(IntentSender intent, Intent fillInIntent, int flagsMask, int flagsValues, int extraFlags, Bundle options)protected ComponentNamestartService(Intent service)protected booleanstopService(Intent name)protected voidunbindService(ServiceConnection serviceConnection)protected voidunregisterReceiver(BroadcastReceiver broadcastReceiver)protected voidvalidateServiceIntent(Intent service)
-
-
-
Field Detail
-
CLASS_NAME
public static final String CLASS_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
getSystemService
@Implementation protected Object getSystemService(String name)
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),nullwill be returned.
-
removeSystemService
public void removeSystemService(String name)
MakesgetSystemService(String)returnnullfor 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
@Implementation protected ClassLoader getClassLoader()
-
checkCallingPermission
@Implementation protected int checkCallingPermission(String permission)
-
checkCallingOrSelfPermission
@Implementation protected int checkCallingOrSelfPermission(String permission)
-
getContentResolver
@Implementation protected ContentResolver getContentResolver()
-
sendBroadcast
@Implementation protected void sendBroadcast(Intent intent)
-
sendBroadcast
@Implementation protected void sendBroadcast(Intent intent, String receiverPermission)
-
sendBroadcastAsUser
@Implementation(minSdk=17) protected void sendBroadcastAsUser(Intent intent, UserHandle user)
-
sendBroadcastAsUser
@Implementation(minSdk=17) protected void sendBroadcastAsUser(Intent intent, UserHandle user, String receiverPermission)
-
sendOrderedBroadcast
@Implementation protected void sendOrderedBroadcast(Intent intent, String receiverPermission)
-
sendOrderedBroadcast
@Implementation protected void sendOrderedBroadcast(Intent intent, String receiverPermission, BroadcastReceiver resultReceiver, Handler scheduler, int initialCode, String initialData, Bundle initialExtras)
-
sendOrderedBroadcastAsUser
@Implementation(minSdk=17) 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
@Implementation protected void sendStickyBroadcast(Intent intent)
-
checkPermission
@Implementation protected int checkPermission(String permission, int pid, int uid)
-
registerReceiver
@Implementation protected Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter)
-
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(minSdk=17) protected Intent registerReceiverAsUser(BroadcastReceiver receiver, UserHandle user, IntentFilter filter, String broadcastPermission, Handler scheduler)
-
unregisterReceiver
@Implementation protected void unregisterReceiver(BroadcastReceiver broadcastReceiver)
-
startService
@Implementation protected ComponentName startService(Intent service)
-
startForegroundService
@Implementation(minSdk=26) protected ComponentName startForegroundService(Intent service)
-
stopService
@Implementation protected boolean stopService(Intent name)
-
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
@Implementation protected void unbindService(ServiceConnection serviceConnection)
-
validateServiceIntent
@Implementation(minSdk=19) protected void validateServiceIntent(Intent service)
-
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)
-
getUserId
@Implementation(minSdk=18) protected int getUserId()
-
getExternalFilesDir
@Implementation(maxSdk=18) protected File getExternalFilesDir(String type)
-
getExternalFilesDirs
@Implementation(minSdk=19) protected File[] getExternalFilesDirs(String type)
-
reset
@Resetter public static void reset()
-
getDatabasePath
@Implementation public File getDatabasePath(String name)
-
getSharedPreferences
@Implementation protected SharedPreferences getSharedPreferences(String name, int mode)
-
-