public abstract class ShellCommand extends Object
Binder.onShellCommand
.Constructor and Description |
---|
ShellCommand() |
Modifier and Type | Method and Description |
---|---|
int |
exec(Binder target,
FileDescriptor in,
FileDescriptor out,
FileDescriptor err,
String[] args,
ResultReceiver resultReceiver) |
InputStream |
getBufferedInputStream()
Return buffered access to the command's
getRawInputStream() . |
PrintWriter |
getErrPrintWriter()
Return a PrintWriter for formatting output to
getRawErrorStream() . |
String |
getNextArg()
Return the next argument on the command line, whatever it is; if there are
no arguments left, return null.
|
String |
getNextArgRequired()
Return the next argument on the command line, whatever it is; if there are
no arguments left, throws an IllegalArgumentException to report this to the user.
|
String |
getNextOption()
Return the next option on the command line -- that is an argument that
starts with '-'.
|
PrintWriter |
getOutPrintWriter()
Return a PrintWriter for formatting output to
getRawOutputStream() . |
OutputStream |
getRawErrorStream()
Return direct raw access (not buffered) to the command's error output data stream.
|
InputStream |
getRawInputStream()
Return direct raw access (not buffered) to the command's input data stream.
|
OutputStream |
getRawOutputStream()
Return direct raw access (not buffered) to the command's output data stream.
|
int |
handleDefaultCommands(String cmd) |
void |
init(Binder target,
FileDescriptor in,
FileDescriptor out,
FileDescriptor err,
String[] args,
int firstArgPos) |
abstract int |
onCommand(String cmd)
Implement parsing and execution of a command.
|
abstract void |
onHelp()
Implement this to print help text about your command to
getOutPrintWriter() . |
String |
peekNextArg() |
public void init(Binder target, FileDescriptor in, FileDescriptor out, FileDescriptor err, String[] args, int firstArgPos)
public int exec(Binder target, FileDescriptor in, FileDescriptor out, FileDescriptor err, String[] args, ResultReceiver resultReceiver)
public OutputStream getRawOutputStream()
public PrintWriter getOutPrintWriter()
getRawOutputStream()
.public OutputStream getRawErrorStream()
public PrintWriter getErrPrintWriter()
getRawErrorStream()
.public InputStream getRawInputStream()
public InputStream getBufferedInputStream()
getRawInputStream()
.public String getNextOption()
public String getNextArg()
public String peekNextArg()
public String getNextArgRequired()
public int handleDefaultCommands(String cmd)
public abstract int onCommand(String cmd)
handleDefaultCommands(String)
and return its result as a last resort.
User getNextOption()
, getNextArg()
, and getNextArgRequired()
to process additional command line arguments. Command output can be written to
getOutPrintWriter()
and errors to getErrPrintWriter()
.
Note that no permission checking has been done before entering this function, so you need to be sure to do your own security verification for any commands you are executing. The easiest way to do this is to have the ShellCommand contain only a reference to your service's aidl interface, and do all of your command implementations on top of that -- that way you can rely entirely on your executing security code behind that interface.
cmd
- The first command line argument representing the name of the command to execute.public abstract void onHelp()
getOutPrintWriter()
.