FileDocCategorySizeDatePackage
ServiceManager.javaAPI DocAndroid 5.1 API4392Thu Mar 12 22:22:10 GMT 2015android.os

ServiceManager

public final class ServiceManager extends Object
hide

Fields Summary
private static final String
TAG
private static IServiceManager
sServiceManager
private static HashMap
sCache
Constructors Summary
Methods Summary
public static voidaddService(java.lang.String name, IBinder service)
Place a new @a service called @a name into the service manager.

param
name the name of the new service
param
service the service object

        try {
            getIServiceManager().addService(name, service, false);
        } catch (RemoteException e) {
            Log.e(TAG, "error in addService", e);
        }
    
public static voidaddService(java.lang.String name, IBinder service, boolean allowIsolated)
Place a new @a service called @a name into the service manager.

param
name the name of the new service
param
service the service object
param
allowIsolated set to true to allow isolated sandboxed processes to access this service

        try {
            getIServiceManager().addService(name, service, allowIsolated);
        } catch (RemoteException e) {
            Log.e(TAG, "error in addService", e);
        }
    
public static IBindercheckService(java.lang.String name)
Retrieve an existing service called @a name from the service manager. Non-blocking.

        try {
            IBinder service = sCache.get(name);
            if (service != null) {
                return service;
            } else {
                return getIServiceManager().checkService(name);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "error in checkService", e);
            return null;
        }
    
private static IServiceManagergetIServiceManager()


        
        if (sServiceManager != null) {
            return sServiceManager;
        }

        // Find the service manager
        sServiceManager = ServiceManagerNative.asInterface(BinderInternal.getContextObject());
        return sServiceManager;
    
public static IBindergetService(java.lang.String name)
Returns a reference to a service with the given name.

param
name the name of the service to get
return
a reference to the service, or null if the service doesn't exist

        try {
            IBinder service = sCache.get(name);
            if (service != null) {
                return service;
            } else {
                return getIServiceManager().getService(name);
            }
        } catch (RemoteException e) {
            Log.e(TAG, "error in getService", e);
        }
        return null;
    
public static voidinitServiceCache(java.util.Map cache)
This is only intended to be called when the process is first being brought up and bound by the activity manager. There is only one thread in the process at that time, so no locking is done.

param
cache the cache of service references
hide

        if (sCache.size() != 0) {
            throw new IllegalStateException("setServiceCache may only be called once");
        }
        sCache.putAll(cache);
    
public static java.lang.String[]listServices()
Return a list of all currently running services.

        try {
            return getIServiceManager().listServices();
        } catch (RemoteException e) {
            Log.e(TAG, "error in listServices", e);
            return null;
        }