summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Daniel Sandler <dsandler@android.com> 2014-10-29 00:01:25 -0400
committer Daniel Sandler <dsandler@android.com> 2014-10-29 00:05:56 -0400
commit795893eb6ff0c02c30a5765e06807ce1ee43978f (patch)
tree40742a3bb20209ab5cf499ec3c41a1b729af8a53
parent685720309a582acc513454d674f82368479c5297 (diff)
More flexible intent extra parsing.
Specifically, --ei (int extras) and --eia (int[] extras) now use Integer.decode(), which means they accept negative integers, base-16 integers formatted as #NNN and 0xNNN, and base-8 integers formatted as 0NNN. Additionally, --ez (boolean extras) can now be specified as "true", "false", "t", "f", or an integer (any nonzero treated as true). The previous behavior, based on Boolean.valueOf(), would silently assign false if you managed to get the spelling of "true" wrong. Change-Id: I058254e907308006d403b5b7866c86bcaa03d8d3
-rw-r--r--cmds/am/src/com/android/commands/am/Am.java23
1 files changed, 19 insertions, 4 deletions
diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java
index ba11a815d5f4..bc57030e3da0 100644
--- a/cmds/am/src/com/android/commands/am/Am.java
+++ b/cmds/am/src/com/android/commands/am/Am.java
@@ -417,7 +417,7 @@ public class Am extends BaseCommand {
} else if (opt.equals("--ei")) {
String key = nextArgRequired();
String value = nextArgRequired();
- intent.putExtra(key, Integer.valueOf(value));
+ intent.putExtra(key, Integer.decode(value));
} else if (opt.equals("--eu")) {
String key = nextArgRequired();
String value = nextArgRequired();
@@ -434,7 +434,7 @@ public class Am extends BaseCommand {
String[] strings = value.split(",");
int[] list = new int[strings.length];
for (int i = 0; i < strings.length; i++) {
- list[i] = Integer.valueOf(strings[i]);
+ list[i] = Integer.decode(strings[i]);
}
intent.putExtra(key, list);
} else if (opt.equals("--el")) {
@@ -477,8 +477,23 @@ public class Am extends BaseCommand {
hasIntentInfo = true;
} else if (opt.equals("--ez")) {
String key = nextArgRequired();
- String value = nextArgRequired();
- intent.putExtra(key, Boolean.valueOf(value));
+ String value = nextArgRequired().toLowerCase();
+ // Boolean.valueOf() results in false for anything that is not "true", which is
+ // error-prone in shell commands
+ boolean arg;
+ if ("true".equals(value) || "t".equals(value)) {
+ arg = true;
+ } else if ("false".equals(value) || "f".equals(value)) {
+ arg = false;
+ } else {
+ try {
+ arg = Integer.decode(value) != 0;
+ } catch (NumberFormatException ex) {
+ throw new IllegalArgumentException("Invalid boolean value: " + value);
+ }
+ }
+
+ intent.putExtra(key, arg);
} else if (opt.equals("-n")) {
String str = nextArgRequired();
ComponentName cn = ComponentName.unflattenFromString(str);