FileDocCategorySizeDatePackage
SystemService.javaAPI DocAndroid 5.1 API4310Thu Mar 12 22:22:10 GMT 2015android.os

SystemService

public class SystemService extends Object
Controls and utilities for low-level {@code init} services.
hide

Fields Summary
private static HashMap
sStates
private static Object
sPropertyLock
Constructors Summary
Methods Summary
public static android.os.SystemService$StategetState(java.lang.String service)
Return current state of given service.

        final String rawState = SystemProperties.get("init.svc." + service);
        final State state = sStates.get(rawState);
        if (state != null) {
            return state;
        } else {
            return State.STOPPED;
        }
    
public static booleanisRunning(java.lang.String service)
Check if given service is {@link State#RUNNING}.

        return State.RUNNING.equals(getState(service));
    
public static booleanisStopped(java.lang.String service)
Check if given service is {@link State#STOPPED}.

        return State.STOPPED.equals(getState(service));
    
public static voidrestart(java.lang.String name)
Request that the init daemon restart a named service.

        SystemProperties.set("ctl.restart", name);
    
public static voidstart(java.lang.String name)
Request that the init daemon start a named service.


     
        SystemProperties.addChangeCallback(new Runnable() {
            @Override
            public void run() {
                synchronized (sPropertyLock) {
                    sPropertyLock.notifyAll();
                }
            }
        });
    
        SystemProperties.set("ctl.start", name);
    
public static voidstop(java.lang.String name)
Request that the init daemon stop a named service.

        SystemProperties.set("ctl.stop", name);
    
public static voidwaitForAnyStopped(java.lang.String services)
Wait until any of given services enters {@link State#STOPPED}.

        while (true) {
            synchronized (sPropertyLock) {
                for (String service : services) {
                    if (State.STOPPED.equals(getState(service))) {
                        return;
                    }
                }

                try {
                    sPropertyLock.wait();
                } catch (InterruptedException e) {
                }
            }
        }
    
public static voidwaitForState(java.lang.String service, android.os.SystemService$State state, long timeoutMillis)
Wait until given service has entered specific state.

        final long endMillis = SystemClock.elapsedRealtime() + timeoutMillis;
        while (true) {
            synchronized (sPropertyLock) {
                final State currentState = getState(service);
                if (state.equals(currentState)) {
                    return;
                }

                if (SystemClock.elapsedRealtime() >= endMillis) {
                    throw new TimeoutException("Service " + service + " currently " + currentState
                            + "; waited " + timeoutMillis + "ms for " + state);
                }

                try {
                    sPropertyLock.wait(timeoutMillis);
                } catch (InterruptedException e) {
                }
            }
        }