summaryrefslogtreecommitdiffstats
path: root/cmds/am
diff options
context:
space:
mode:
authorMarco Nelissen <marcone@google.com>2013-07-11 09:30:26 -0700
committerMarco Nelissen <marcone@google.com>2013-07-11 09:32:30 -0700
commitf2ca6e271758e6f2b476ca909821e63e30c1c09b (patch)
treebb769f9afc10e6c82475646307d6ecf6d170c358 /cmds/am
parent4a9095007ddf2ec763ad7133e9ac8c62c3f53a4e (diff)
downloadframeworks_base-f2ca6e271758e6f2b476ca909821e63e30c1c09b.zip
frameworks_base-f2ca6e271758e6f2b476ca909821e63e30c1c09b.tar.gz
frameworks_base-f2ca6e271758e6f2b476ca909821e63e30c1c09b.tar.bz2
Add stopservice command to am
Change-Id: I639ad418750c0e1825b330b3bd56e5628926e7f1
Diffstat (limited to 'cmds/am')
-rw-r--r--cmds/am/src/com/android/commands/am/Am.java24
1 files changed, 24 insertions, 0 deletions
diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java
index 87ea4fd..d945216 100644
--- a/cmds/am/src/com/android/commands/am/Am.java
+++ b/cmds/am/src/com/android/commands/am/Am.java
@@ -84,6 +84,7 @@ public class Am extends BaseCommand {
" [--R COUNT] [-S] [--opengl-trace]\n" +
" [--user <USER_ID> | current] <INTENT>\n" +
" am startservice [--user <USER_ID> | current] <INTENT>\n" +
+ " am stopservice [--user <USER_ID> | current] <INTENT>\n" +
" am force-stop [--user <USER_ID> | all | current] <PACKAGE>\n" +
" am kill [--user <USER_ID> | all | current] <PACKAGE>\n" +
" am kill-all\n" +
@@ -125,6 +126,10 @@ public class Am extends BaseCommand {
" --user <USER_ID> | current: Specify which user to run as; if not\n" +
" specified then run as the current user.\n" +
"\n" +
+ "am stopservice: stop a Service. Options are:\n" +
+ " --user <USER_ID> | current: Specify which user to run as; if not\n" +
+ " specified then run as the current user.\n" +
+ "\n" +
"am force-stop: force stop everything associated with <PACKAGE>.\n" +
" --user <USER_ID> | all | current: Specify user to force stop;\n" +
" all users if not specified.\n" +
@@ -259,6 +264,8 @@ public class Am extends BaseCommand {
runStart();
} else if (op.equals("startservice")) {
runStartService();
+ } else if (op.equals("stopservice")) {
+ runStopService();
} else if (op.equals("force-stop")) {
runForceStop();
} else if (op.equals("kill")) {
@@ -574,6 +581,23 @@ public class Am extends BaseCommand {
}
}
+ private void runStopService() throws Exception {
+ Intent intent = makeIntent(UserHandle.USER_CURRENT);
+ if (mUserId == UserHandle.USER_ALL) {
+ System.err.println("Error: Can't stop activity with user 'all'");
+ return;
+ }
+ System.out.println("Stopping service: " + intent);
+ int result = mAm.stopService(null, intent, intent.getType(), mUserId);
+ if (result == 0) {
+ System.err.println("Service not stopped: was not running.");
+ } else if (result == 1) {
+ System.err.println("Service stopped");
+ } else if (result == -1) {
+ System.err.println("Error stopping service");
+ }
+ }
+
private void runStart() throws Exception {
Intent intent = makeIntent(UserHandle.USER_CURRENT);