Methods Summary |
---|
public static android.os.SystemService$State | getState(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 boolean | isRunning(java.lang.String service)Check if given service is {@link State#RUNNING}.
return State.RUNNING.equals(getState(service));
|
public static boolean | isStopped(java.lang.String service)Check if given service is {@link State#STOPPED}.
return State.STOPPED.equals(getState(service));
|
public static void | restart(java.lang.String name)Request that the init daemon restart a named service.
SystemProperties.set("ctl.restart", name);
|
public static void | start(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 void | stop(java.lang.String name)Request that the init daemon stop a named service.
SystemProperties.set("ctl.stop", name);
|
public static void | waitForAnyStopped(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 void | waitForState(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) {
}
}
}
|