Fields Summary |
---|
private static final String | COMMAND |
private static final String | PARAM |
private static final String | CMD_PREPARE |
private static final String | CMD_SET |
private static final String | CMD_DONE |
private static final String | SERVICE_ACTION |
private static final String | SERVICE_PKG |
private static final String | LOG_TAG |
private com.android.testing.alarmservice.Alarm | mAlarmService |
private android.os.Bundle | mArgs |
private String | mCommand |
private android.content.Intent | mServceIntent |
private android.content.ServiceConnection | mConn |
Methods Summary |
---|
private void | callDone()
try {
mAlarmService.done();
} catch (RemoteException e) {
errorFinish("RemoteExeption in prepare()");
} finally {
getContext().unbindService(mConn);
}
// explicitly stop the service (started in prepare()) so that the service is now free
// to be reclaimed
getContext().stopService(mServceIntent);
|
private void | callPrepare()
try {
mAlarmService.prepare();
} catch (RemoteException e) {
errorFinish("RemoteExeption in prepare()");
} finally {
getContext().unbindService(mConn);
}
|
private void | callSetAndWait(long timeoutMills)
try {
mAlarmService.setAlarmAndWait(timeoutMills);
} catch (RemoteException e) {
errorFinish("RemoteExeption in setAlarmAndWait()");
} finally {
getContext().unbindService(mConn);
}
|
private void | connectToAlarmService()
// start the service with an intent, this ensures the service keeps running after unbind
ComponentName cn = getContext().startService(mServceIntent);
if (cn == null) {
errorFinish("failed to start service");
}
if (!getContext().bindService(mServceIntent, mConn, Context.BIND_AUTO_CREATE)) {
errorFinish("failed to bind service");
}
|
private void | errorFinish(java.lang.String msg)
Bundle ret = new Bundle();
ret.putString("error", msg);
finish(Activity.RESULT_CANCELED, ret);
|
private void | handleCommands()
if (CMD_PREPARE.equals(mCommand)) {
callPrepare();
} else if (CMD_SET.equals(mCommand)) {
String paramString = mArgs.getString(PARAM);
if (paramString == null) {
errorFinish("argument expected for alarm time");
}
long timeout = -1;
try {
timeout = Long.parseLong(paramString);
} catch (NumberFormatException nfe) {
errorFinish("a number argument is expected");
}
callSetAndWait(timeout);
} else if (CMD_DONE.equals(mCommand)) {
callDone();
} else {
errorFinish("Unrecognized command: " + mCommand);
}
finish(Activity.RESULT_OK, new Bundle());
|
public void | onCreate(android.os.Bundle arguments)
super.onCreate(arguments);
mCommand = arguments.getString(COMMAND);
if ("true".equals(arguments.getString("debug"))) {
Debug.waitForDebugger();
}
if (mCommand == null) {
errorFinish("No command specified");
}
mArgs = arguments;
connectToAlarmService();
|