diff options
Diffstat (limited to 'java/com/android/dialer/commandline/CommandLineReceiver.java')
-rw-r--r-- | java/com/android/dialer/commandline/CommandLineReceiver.java | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/java/com/android/dialer/commandline/CommandLineReceiver.java b/java/com/android/dialer/commandline/CommandLineReceiver.java index baaadf054..e5e78c46a 100644 --- a/java/com/android/dialer/commandline/CommandLineReceiver.java +++ b/java/com/android/dialer/commandline/CommandLineReceiver.java @@ -21,8 +21,8 @@ import android.content.Context; import android.content.Intent; import android.text.TextUtils; import com.android.dialer.buildtype.BuildType; +import com.android.dialer.commandline.Command.IllegalCommandLineArgumentException; import com.android.dialer.common.LogUtil; -import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.MoreExecutors; @@ -53,17 +53,18 @@ public class CommandLineReceiver extends BroadcastReceiver { .commandSupplier() .get() .get(intent.getStringExtra(COMMAND)); - if (command == null) { - LogUtil.i(outputTag, "unknown command " + intent.getStringExtra(COMMAND)); - return; - } + try { + if (command == null) { + LogUtil.i(outputTag, "unknown command " + intent.getStringExtra(COMMAND)); + return; + } - ImmutableList<String> args = - intent.hasExtra(ARGS) - ? ImmutableList.copyOf(intent.getStringArrayExtra(ARGS)) - : ImmutableList.of(); + Arguments args = Arguments.parse(intent.getStringArrayExtra(ARGS)); - try { + if (args.getBoolean("help", false)) { + LogUtil.i(outputTag, "usage:\n" + command.getUsage()); + return; + } Futures.addCallback( command.run(args), new FutureCallback<String>() { @@ -78,12 +79,15 @@ public class CommandLineReceiver extends BroadcastReceiver { @Override public void onFailure(Throwable throwable) { - // LogUtil.e(tag, message, e) prints 2 entries where only the first one can be - // intercepted by the script. Compose the string instead. + if (throwable instanceof IllegalCommandLineArgumentException) { + LogUtil.e(outputTag, throwable.getMessage() + "\n\nusage:\n" + command.getUsage()); + } LogUtil.e(outputTag, "error running command future", throwable); } }, MoreExecutors.directExecutor()); + } catch (IllegalCommandLineArgumentException e) { + LogUtil.e(outputTag, e.getMessage() + "\n\nusage:\n" + command.getUsage()); } catch (Throwable throwable) { LogUtil.e(outputTag, "error running command", throwable); } |