Package org.robolectric.shadows
Class ShadowServiceManager
java.lang.Object
org.robolectric.shadows.ShadowServiceManager
@Implements(value=android.os.ServiceManager.class,
isInAndroidSdk=false)
public class ShadowServiceManager
extends Object
Shadow for
ServiceManager
.-
Field Summary
FieldsModifier and TypeFieldDescription -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addBinderService
(String name, Class<? extends IInterface> clazz, IInterface service) protected static void
addBinderService
(Map<String, org.robolectric.shadows.ShadowServiceManager.BinderService> binderServices, String name, Class<? extends IInterface> clazz) protected static void
addService
(String name, IBinder service) protected static IBinder
checkService
(String name) Same asgetService(java.lang.String)
.protected static IBinder
getService
(String name) Returns theIBinder
associated with the given system service.protected static void
initServiceCache
(Map<String, IBinder> cache) protected static boolean
isDeclared
(String name) Returns whether the specified service is declared.protected static String[]
static void
reset()
static void
setServiceAvailability
(String service, boolean available) Sets the availability of the given system service.static void
setServiceDeclaredOrNot
(String name, boolean declared) Sets the declared status of the given system service.protected static IBinder
waitForDeclaredService
(String name) Returns theIBinder
associated with the given declared system service.protected static IBinder
waitForService
(String name) Returns theIBinder
associated with the given system service.
-
Field Details
-
binderServices
-
-
Constructor Details
-
ShadowServiceManager
public ShadowServiceManager()
-
-
Method Details
-
addBinderService
protected static void addBinderService(Map<String, org.robolectric.shadows.ShadowServiceManager.BinderService> binderServices, String name, Class<? extends IInterface> clazz) -
addBinderService
public static void addBinderService(String name, Class<? extends IInterface> clazz, IInterface service) -
getService
Returns theIBinder
associated with the given system service. If the given service is set to unavailable insetServiceAvailability(java.lang.String, boolean)
,null
will be returned. -
addService
-
checkService
Same asgetService(java.lang.String)
.The real implementation of
checkService(java.lang.String)
differs fromgetService(java.lang.String)
in that it is not a blocking call; so it is more likely to returnnull
in cases where the service isn't available (whereasgetService(java.lang.String)
will block until it becomes available, until a timeout or error happens). -
waitForService
@Implementation(minSdk=30) protected static IBinder waitForService(String name) throws InterruptedException Returns theIBinder
associated with the given system service. If the given service is set to unavailable insetServiceAvailability(java.lang.String, boolean)
, the method will block until the service becomes available or the thread is interrupted.- Throws:
InterruptedException
-
waitForDeclaredService
@Implementation(minSdk=30) @Nullable protected static IBinder waitForDeclaredService(String name) throws InterruptedException Returns theIBinder
associated with the given declared system service. If the given service is set to unavailable insetServiceAvailability(java.lang.String, boolean)
, the method will block until the service becomes available or the thread is interrupted.If the given service is not declared,
null
will be returned immediately.- Throws:
InterruptedException
-
isDeclared
Returns whether the specified service is declared. Can usesetServiceDeclaredOrNot(java.lang.String, boolean)
to set the declared status of a service. -
listServices
- Throws:
RemoteException
-
initServiceCache
-
setServiceAvailability
Sets the availability of the given system service. If the service is set as unavailable, subsequent calls toContext.getSystemService(java.lang.String)
for that service will returnnull
. When a service is set as available, any threads waiting for the service caused bywaitForService(String)
will be notified and woken up.A service is considered available by default.
-
setServiceDeclaredOrNot
Sets the declared status of the given system service. If the service is set as not declared, subsequent calls toisDeclared(java.lang.String)
for that service will returnfalse
.A service is considered not declared by default.
-
reset
-