summaryrefslogtreecommitdiff
path: root/core/java/android/os/ShellCommand.java
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2016-08-22 17:00:05 -0700
committerDianne Hackborn <hackbod@google.com>2016-09-29 10:58:44 -0700
commit354736e196ff79962b3ddb52619a674044d773e2 (patch)
tree3a70250f8ba7f69f1961491c55e4b5b48ebe99ef /core/java/android/os/ShellCommand.java
parent015deed8104aae1f306394cdf66088592995f0da (diff)
New infrastructure to switch remaining commands to "cmd" calls.
This introduces a new feature of the IBinder command protocol to allow the shell command implementation to call back into its caller to ask it to open files in the calling context. This is needed so that commands that have arguments specifying files can open those files as the calling shell, not the system (or whatever) process. To test this all out, move the "am start" implementation over to ActivityManagerShellCommand, in particular along with its option to specify a file in which to write profiling data. Test: Manual Change-Id: I0c1e3857defefbd19a2ac29413aafbb34b1e48a3
Diffstat (limited to 'core/java/android/os/ShellCommand.java')
-rw-r--r--core/java/android/os/ShellCommand.java17
1 files changed, 13 insertions, 4 deletions
diff --git a/core/java/android/os/ShellCommand.java b/core/java/android/os/ShellCommand.java
index fc804e592148..831c9b27ac45 100644
--- a/core/java/android/os/ShellCommand.java
+++ b/core/java/android/os/ShellCommand.java
@@ -40,6 +40,7 @@ public abstract class ShellCommand {
private FileDescriptor mOut;
private FileDescriptor mErr;
private String[] mArgs;
+ private ShellCallback mShellCallback;
private ResultReceiver mResultReceiver;
private String mCmd;
@@ -55,12 +56,13 @@ public abstract class ShellCommand {
private InputStream mInputStream;
public void init(Binder target, FileDescriptor in, FileDescriptor out, FileDescriptor err,
- String[] args, int firstArgPos) {
+ String[] args, ShellCallback callback, int firstArgPos) {
mTarget = target;
mIn = in;
mOut = out;
mErr = err;
mArgs = args;
+ mShellCallback = callback;
mResultReceiver = null;
mCmd = null;
mArgPos = firstArgPos;
@@ -74,7 +76,7 @@ public abstract class ShellCommand {
}
public int exec(Binder target, FileDescriptor in, FileDescriptor out, FileDescriptor err,
- String[] args, ResultReceiver resultReceiver) {
+ String[] args, ShellCallback callback, ResultReceiver resultReceiver) {
String cmd;
int start;
if (args != null && args.length > 0) {
@@ -84,7 +86,7 @@ public abstract class ShellCommand {
cmd = null;
start = 0;
}
- init(target, in, out, err, args, start);
+ init(target, in, out, err, args, callback, start);
mCmd = cmd;
mResultReceiver = resultReceiver;
@@ -105,7 +107,7 @@ public abstract class ShellCommand {
// go.
PrintWriter eout = getErrPrintWriter();
eout.println();
- eout.println("Exception occurred while dumping:");
+ eout.println("Exception occurred while executing:");
e.printStackTrace(eout);
} finally {
if (DEBUG) Slog.d(TAG, "Flushing output streams on " + mTarget);
@@ -257,6 +259,13 @@ public abstract class ShellCommand {
return arg;
}
+ /**
+ * Return the {@link ShellCallback} for communicating back with the calling shell.
+ */
+ public ShellCallback getShellCallback() {
+ return mShellCallback;
+ }
+
public int handleDefaultCommands(String cmd) {
if ("dump".equals(cmd)) {
String[] newArgs = new String[mArgs.length-1];