Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.os; |
| 18 | |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 19 | import android.annotation.UnsupportedAppUsage; |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 20 | import android.util.Slog; |
Dianne Hackborn | c81983a | 2017-10-20 16:16:32 -0700 | [diff] [blame] | 21 | |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 22 | import com.android.internal.util.FastPrintWriter; |
| 23 | |
Todd Kennedy | 72cfcd0 | 2015-11-03 17:08:55 -0800 | [diff] [blame] | 24 | import java.io.BufferedInputStream; |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 25 | import java.io.FileDescriptor; |
Todd Kennedy | 72cfcd0 | 2015-11-03 17:08:55 -0800 | [diff] [blame] | 26 | import java.io.FileInputStream; |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 27 | import java.io.FileOutputStream; |
Todd Kennedy | 72cfcd0 | 2015-11-03 17:08:55 -0800 | [diff] [blame] | 28 | import java.io.InputStream; |
Dianne Hackborn | 2e931f5 | 2016-01-28 12:21:17 -0800 | [diff] [blame] | 29 | import java.io.OutputStream; |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 30 | import java.io.PrintWriter; |
| 31 | |
| 32 | /** |
Dianne Hackborn | 2e931f5 | 2016-01-28 12:21:17 -0800 | [diff] [blame] | 33 | * Helper for implementing {@link Binder#onShellCommand Binder.onShellCommand}. |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 34 | * @hide |
| 35 | */ |
| 36 | public abstract class ShellCommand { |
| 37 | static final String TAG = "ShellCommand"; |
| 38 | static final boolean DEBUG = false; |
| 39 | |
| 40 | private Binder mTarget; |
| 41 | private FileDescriptor mIn; |
| 42 | private FileDescriptor mOut; |
| 43 | private FileDescriptor mErr; |
| 44 | private String[] mArgs; |
Dianne Hackborn | 354736e | 2016-08-22 17:00:05 -0700 | [diff] [blame] | 45 | private ShellCallback mShellCallback; |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 46 | private ResultReceiver mResultReceiver; |
| 47 | |
| 48 | private String mCmd; |
| 49 | private int mArgPos; |
| 50 | private String mCurArgData; |
| 51 | |
Dianne Hackborn | 2e931f5 | 2016-01-28 12:21:17 -0800 | [diff] [blame] | 52 | private FileInputStream mFileIn; |
| 53 | private FileOutputStream mFileOut; |
| 54 | private FileOutputStream mFileErr; |
| 55 | |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 56 | private FastPrintWriter mOutPrintWriter; |
| 57 | private FastPrintWriter mErrPrintWriter; |
Todd Kennedy | 72cfcd0 | 2015-11-03 17:08:55 -0800 | [diff] [blame] | 58 | private InputStream mInputStream; |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 59 | |
Dianne Hackborn | 3cdb56e | 2015-11-11 12:45:44 -0800 | [diff] [blame] | 60 | public void init(Binder target, FileDescriptor in, FileDescriptor out, FileDescriptor err, |
Dianne Hackborn | 354736e | 2016-08-22 17:00:05 -0700 | [diff] [blame] | 61 | String[] args, ShellCallback callback, int firstArgPos) { |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 62 | mTarget = target; |
| 63 | mIn = in; |
| 64 | mOut = out; |
| 65 | mErr = err; |
| 66 | mArgs = args; |
Dianne Hackborn | 354736e | 2016-08-22 17:00:05 -0700 | [diff] [blame] | 67 | mShellCallback = callback; |
Dianne Hackborn | 3cdb56e | 2015-11-11 12:45:44 -0800 | [diff] [blame] | 68 | mResultReceiver = null; |
| 69 | mCmd = null; |
| 70 | mArgPos = firstArgPos; |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 71 | mCurArgData = null; |
Dianne Hackborn | 2e931f5 | 2016-01-28 12:21:17 -0800 | [diff] [blame] | 72 | mFileIn = null; |
| 73 | mFileOut = null; |
| 74 | mFileErr = null; |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 75 | mOutPrintWriter = null; |
| 76 | mErrPrintWriter = null; |
Dianne Hackborn | 2e931f5 | 2016-01-28 12:21:17 -0800 | [diff] [blame] | 77 | mInputStream = null; |
Dianne Hackborn | 3cdb56e | 2015-11-11 12:45:44 -0800 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | public int exec(Binder target, FileDescriptor in, FileDescriptor out, FileDescriptor err, |
Dianne Hackborn | 354736e | 2016-08-22 17:00:05 -0700 | [diff] [blame] | 81 | String[] args, ShellCallback callback, ResultReceiver resultReceiver) { |
Dianne Hackborn | 3cdb56e | 2015-11-11 12:45:44 -0800 | [diff] [blame] | 82 | String cmd; |
| 83 | int start; |
| 84 | if (args != null && args.length > 0) { |
| 85 | cmd = args[0]; |
| 86 | start = 1; |
| 87 | } else { |
| 88 | cmd = null; |
| 89 | start = 0; |
| 90 | } |
Dianne Hackborn | 354736e | 2016-08-22 17:00:05 -0700 | [diff] [blame] | 91 | init(target, in, out, err, args, callback, start); |
Dianne Hackborn | 3cdb56e | 2015-11-11 12:45:44 -0800 | [diff] [blame] | 92 | mCmd = cmd; |
| 93 | mResultReceiver = resultReceiver; |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 94 | |
Dianne Hackborn | 1704e3c | 2017-10-31 19:55:42 +0000 | [diff] [blame] | 95 | if (DEBUG) { |
| 96 | RuntimeException here = new RuntimeException("here"); |
| 97 | here.fillInStackTrace(); |
| 98 | Slog.d(TAG, "Starting command " + mCmd + " on " + mTarget, here); |
| 99 | Slog.d(TAG, "Calling uid=" + Binder.getCallingUid() |
| 100 | + " pid=" + Binder.getCallingPid() + " ShellCallback=" + getShellCallback()); |
| 101 | } |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 102 | int res = -1; |
| 103 | try { |
| 104 | res = onCommand(mCmd); |
| 105 | if (DEBUG) Slog.d(TAG, "Executed command " + mCmd + " on " + mTarget); |
| 106 | } catch (SecurityException e) { |
| 107 | PrintWriter eout = getErrPrintWriter(); |
| 108 | eout.println("Security exception: " + e.getMessage()); |
| 109 | eout.println(); |
| 110 | e.printStackTrace(eout); |
| 111 | } catch (Throwable e) { |
| 112 | // Unlike usual calls, in this case if an exception gets thrown |
| 113 | // back to us we want to print it back in to the dump data, since |
| 114 | // that is where the caller expects all interesting information to |
| 115 | // go. |
| 116 | PrintWriter eout = getErrPrintWriter(); |
| 117 | eout.println(); |
Dianne Hackborn | 354736e | 2016-08-22 17:00:05 -0700 | [diff] [blame] | 118 | eout.println("Exception occurred while executing:"); |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 119 | e.printStackTrace(eout); |
| 120 | } finally { |
| 121 | if (DEBUG) Slog.d(TAG, "Flushing output streams on " + mTarget); |
| 122 | if (mOutPrintWriter != null) { |
| 123 | mOutPrintWriter.flush(); |
| 124 | } |
| 125 | if (mErrPrintWriter != null) { |
| 126 | mErrPrintWriter.flush(); |
| 127 | } |
| 128 | if (DEBUG) Slog.d(TAG, "Sending command result on " + mTarget); |
Dianne Hackborn | c81983a | 2017-10-20 16:16:32 -0700 | [diff] [blame] | 129 | if (mResultReceiver != null) { |
| 130 | mResultReceiver.send(res, null); |
| 131 | } |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 132 | } |
| 133 | if (DEBUG) Slog.d(TAG, "Finished command " + mCmd + " on " + mTarget); |
Dianne Hackborn | 2e44107 | 2015-10-28 18:00:57 -0700 | [diff] [blame] | 134 | return res; |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Dianne Hackborn | 2e931f5 | 2016-01-28 12:21:17 -0800 | [diff] [blame] | 137 | /** |
Dianne Hackborn | c81983a | 2017-10-20 16:16:32 -0700 | [diff] [blame] | 138 | * Adopt the ResultReceiver that was given to this shell command from it, taking |
| 139 | * it over. Primarily used to dispatch to another shell command. Once called, |
| 140 | * this shell command will no longer return its own result when done. |
| 141 | */ |
| 142 | public ResultReceiver adoptResultReceiver() { |
| 143 | ResultReceiver rr = mResultReceiver; |
| 144 | mResultReceiver = null; |
| 145 | return rr; |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Return the raw FileDescriptor for the output stream. |
| 150 | */ |
| 151 | public FileDescriptor getOutFileDescriptor() { |
| 152 | return mOut; |
| 153 | } |
| 154 | |
| 155 | /** |
Dianne Hackborn | 2e931f5 | 2016-01-28 12:21:17 -0800 | [diff] [blame] | 156 | * Return direct raw access (not buffered) to the command's output data stream. |
| 157 | */ |
| 158 | public OutputStream getRawOutputStream() { |
| 159 | if (mFileOut == null) { |
| 160 | mFileOut = new FileOutputStream(mOut); |
| 161 | } |
| 162 | return mFileOut; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Return a PrintWriter for formatting output to {@link #getRawOutputStream()}. |
| 167 | */ |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 168 | public PrintWriter getOutPrintWriter() { |
| 169 | if (mOutPrintWriter == null) { |
Dianne Hackborn | 2e931f5 | 2016-01-28 12:21:17 -0800 | [diff] [blame] | 170 | mOutPrintWriter = new FastPrintWriter(getRawOutputStream()); |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 171 | } |
| 172 | return mOutPrintWriter; |
| 173 | } |
| 174 | |
Dianne Hackborn | 2e931f5 | 2016-01-28 12:21:17 -0800 | [diff] [blame] | 175 | /** |
Dianne Hackborn | c81983a | 2017-10-20 16:16:32 -0700 | [diff] [blame] | 176 | * Return the raw FileDescriptor for the error stream. |
| 177 | */ |
| 178 | public FileDescriptor getErrFileDescriptor() { |
| 179 | return mErr; |
| 180 | } |
| 181 | |
| 182 | /** |
Dianne Hackborn | 2e931f5 | 2016-01-28 12:21:17 -0800 | [diff] [blame] | 183 | * Return direct raw access (not buffered) to the command's error output data stream. |
| 184 | */ |
| 185 | public OutputStream getRawErrorStream() { |
| 186 | if (mFileErr == null) { |
| 187 | mFileErr = new FileOutputStream(mErr); |
| 188 | } |
| 189 | return mFileErr; |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Return a PrintWriter for formatting output to {@link #getRawErrorStream()}. |
| 194 | */ |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 195 | public PrintWriter getErrPrintWriter() { |
| 196 | if (mErr == null) { |
| 197 | return getOutPrintWriter(); |
| 198 | } |
| 199 | if (mErrPrintWriter == null) { |
Dianne Hackborn | 2e931f5 | 2016-01-28 12:21:17 -0800 | [diff] [blame] | 200 | mErrPrintWriter = new FastPrintWriter(getRawErrorStream()); |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 201 | } |
| 202 | return mErrPrintWriter; |
| 203 | } |
| 204 | |
Dianne Hackborn | 2e931f5 | 2016-01-28 12:21:17 -0800 | [diff] [blame] | 205 | /** |
Dianne Hackborn | c81983a | 2017-10-20 16:16:32 -0700 | [diff] [blame] | 206 | * Return the raw FileDescriptor for the input stream. |
| 207 | */ |
| 208 | public FileDescriptor getInFileDescriptor() { |
| 209 | return mIn; |
| 210 | } |
| 211 | |
| 212 | /** |
Dianne Hackborn | 2e931f5 | 2016-01-28 12:21:17 -0800 | [diff] [blame] | 213 | * Return direct raw access (not buffered) to the command's input data stream. |
| 214 | */ |
| 215 | public InputStream getRawInputStream() { |
| 216 | if (mFileIn == null) { |
| 217 | mFileIn = new FileInputStream(mIn); |
| 218 | } |
| 219 | return mFileIn; |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Return buffered access to the command's {@link #getRawInputStream()}. |
| 224 | */ |
| 225 | public InputStream getBufferedInputStream() { |
Todd Kennedy | 72cfcd0 | 2015-11-03 17:08:55 -0800 | [diff] [blame] | 226 | if (mInputStream == null) { |
Dianne Hackborn | 2e931f5 | 2016-01-28 12:21:17 -0800 | [diff] [blame] | 227 | mInputStream = new BufferedInputStream(getRawInputStream()); |
Todd Kennedy | 72cfcd0 | 2015-11-03 17:08:55 -0800 | [diff] [blame] | 228 | } |
| 229 | return mInputStream; |
| 230 | } |
| 231 | |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 232 | /** |
Dianne Hackborn | 331084d | 2016-10-07 17:57:00 -0700 | [diff] [blame] | 233 | * Helper for just system services to ask the shell to open an output file. |
| 234 | * @hide |
| 235 | */ |
Dianne Hackborn | ca3872c | 2017-10-30 14:19:32 -0700 | [diff] [blame] | 236 | public ParcelFileDescriptor openFileForSystem(String path, String mode) { |
Dianne Hackborn | 1704e3c | 2017-10-31 19:55:42 +0000 | [diff] [blame] | 237 | if (DEBUG) Slog.d(TAG, "openFileForSystem: " + path + " mode=" + mode); |
Dianne Hackborn | 331084d | 2016-10-07 17:57:00 -0700 | [diff] [blame] | 238 | try { |
Dianne Hackborn | ca3872c | 2017-10-30 14:19:32 -0700 | [diff] [blame] | 239 | ParcelFileDescriptor pfd = getShellCallback().openFile(path, |
| 240 | "u:r:system_server:s0", mode); |
Dianne Hackborn | 331084d | 2016-10-07 17:57:00 -0700 | [diff] [blame] | 241 | if (pfd != null) { |
Dianne Hackborn | 1704e3c | 2017-10-31 19:55:42 +0000 | [diff] [blame] | 242 | if (DEBUG) Slog.d(TAG, "Got file: " + pfd); |
Dianne Hackborn | 331084d | 2016-10-07 17:57:00 -0700 | [diff] [blame] | 243 | return pfd; |
| 244 | } |
| 245 | } catch (RuntimeException e) { |
Dianne Hackborn | 1704e3c | 2017-10-31 19:55:42 +0000 | [diff] [blame] | 246 | if (DEBUG) Slog.d(TAG, "Failure opening file: " + e.getMessage()); |
Dianne Hackborn | 331084d | 2016-10-07 17:57:00 -0700 | [diff] [blame] | 247 | getErrPrintWriter().println("Failure opening file: " + e.getMessage()); |
| 248 | } |
Dianne Hackborn | 1704e3c | 2017-10-31 19:55:42 +0000 | [diff] [blame] | 249 | if (DEBUG) Slog.d(TAG, "Error: Unable to open file: " + path); |
Dianne Hackborn | 331084d | 2016-10-07 17:57:00 -0700 | [diff] [blame] | 250 | getErrPrintWriter().println("Error: Unable to open file: " + path); |
Robin Lee | 56be27c | 2017-09-14 14:28:26 +0200 | [diff] [blame] | 251 | |
| 252 | String suggestedPath = "/data/local/tmp/"; |
| 253 | if (path == null || !path.startsWith(suggestedPath)) { |
| 254 | getErrPrintWriter().println("Consider using a file under " + suggestedPath); |
| 255 | } |
Dianne Hackborn | 331084d | 2016-10-07 17:57:00 -0700 | [diff] [blame] | 256 | return null; |
| 257 | } |
| 258 | |
| 259 | /** |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 260 | * Return the next option on the command line -- that is an argument that |
| 261 | * starts with '-'. If the next argument is not an option, null is returned. |
| 262 | */ |
| 263 | public String getNextOption() { |
| 264 | if (mCurArgData != null) { |
| 265 | String prev = mArgs[mArgPos - 1]; |
| 266 | throw new IllegalArgumentException("No argument expected after \"" + prev + "\""); |
| 267 | } |
| 268 | if (mArgPos >= mArgs.length) { |
| 269 | return null; |
| 270 | } |
| 271 | String arg = mArgs[mArgPos]; |
| 272 | if (!arg.startsWith("-")) { |
| 273 | return null; |
| 274 | } |
| 275 | mArgPos++; |
| 276 | if (arg.equals("--")) { |
| 277 | return null; |
| 278 | } |
| 279 | if (arg.length() > 1 && arg.charAt(1) != '-') { |
| 280 | if (arg.length() > 2) { |
| 281 | mCurArgData = arg.substring(2); |
| 282 | return arg.substring(0, 2); |
| 283 | } else { |
| 284 | mCurArgData = null; |
| 285 | return arg; |
| 286 | } |
| 287 | } |
| 288 | mCurArgData = null; |
| 289 | return arg; |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Return the next argument on the command line, whatever it is; if there are |
| 294 | * no arguments left, return null. |
| 295 | */ |
| 296 | public String getNextArg() { |
| 297 | if (mCurArgData != null) { |
| 298 | String arg = mCurArgData; |
| 299 | mCurArgData = null; |
| 300 | return arg; |
| 301 | } else if (mArgPos < mArgs.length) { |
| 302 | return mArgs[mArgPos++]; |
| 303 | } else { |
| 304 | return null; |
| 305 | } |
| 306 | } |
| 307 | |
Andrei Onea | 24ec321 | 2019-03-15 17:35:05 +0000 | [diff] [blame] | 308 | @UnsupportedAppUsage |
Filip Gruszczynski | c17d8b7 | 2016-02-03 16:52:59 -0800 | [diff] [blame] | 309 | public String peekNextArg() { |
| 310 | if (mCurArgData != null) { |
| 311 | return mCurArgData; |
| 312 | } else if (mArgPos < mArgs.length) { |
| 313 | return mArgs[mArgPos]; |
| 314 | } else { |
| 315 | return null; |
| 316 | } |
| 317 | } |
| 318 | |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 319 | /** |
| 320 | * Return the next argument on the command line, whatever it is; if there are |
| 321 | * no arguments left, throws an IllegalArgumentException to report this to the user. |
| 322 | */ |
| 323 | public String getNextArgRequired() { |
| 324 | String arg = getNextArg(); |
| 325 | if (arg == null) { |
| 326 | String prev = mArgs[mArgPos - 1]; |
| 327 | throw new IllegalArgumentException("Argument expected after \"" + prev + "\""); |
| 328 | } |
| 329 | return arg; |
| 330 | } |
| 331 | |
Dianne Hackborn | 354736e | 2016-08-22 17:00:05 -0700 | [diff] [blame] | 332 | /** |
| 333 | * Return the {@link ShellCallback} for communicating back with the calling shell. |
| 334 | */ |
| 335 | public ShellCallback getShellCallback() { |
| 336 | return mShellCallback; |
| 337 | } |
| 338 | |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 339 | public int handleDefaultCommands(String cmd) { |
| 340 | if ("dump".equals(cmd)) { |
| 341 | String[] newArgs = new String[mArgs.length-1]; |
| 342 | System.arraycopy(mArgs, 1, newArgs, 0, mArgs.length-1); |
| 343 | mTarget.doDump(mOut, getOutPrintWriter(), newArgs); |
| 344 | return 0; |
| 345 | } else if (cmd == null || "help".equals(cmd) || "-h".equals(cmd)) { |
| 346 | onHelp(); |
| 347 | } else { |
| 348 | getOutPrintWriter().println("Unknown command: " + cmd); |
| 349 | } |
| 350 | return -1; |
| 351 | } |
| 352 | |
Dianne Hackborn | 2e931f5 | 2016-01-28 12:21:17 -0800 | [diff] [blame] | 353 | /** |
| 354 | * Implement parsing and execution of a command. If it isn't a command you understand, |
| 355 | * call {@link #handleDefaultCommands(String)} and return its result as a last resort. |
Leonard Mosescu | f3409ce | 2016-10-06 17:32:05 -0700 | [diff] [blame] | 356 | * Use {@link #getNextOption()}, {@link #getNextArg()}, and {@link #getNextArgRequired()} |
Dianne Hackborn | 2e931f5 | 2016-01-28 12:21:17 -0800 | [diff] [blame] | 357 | * to process additional command line arguments. Command output can be written to |
| 358 | * {@link #getOutPrintWriter()} and errors to {@link #getErrPrintWriter()}. |
| 359 | * |
| 360 | * <p class="caution">Note that no permission checking has been done before entering this function, |
| 361 | * so you need to be sure to do your own security verification for any commands you |
| 362 | * are executing. The easiest way to do this is to have the ShellCommand contain |
| 363 | * only a reference to your service's aidl interface, and do all of your command |
| 364 | * implementations on top of that -- that way you can rely entirely on your executing security |
| 365 | * code behind that interface.</p> |
| 366 | * |
| 367 | * @param cmd The first command line argument representing the name of the command to execute. |
| 368 | * @return Return the command result; generally 0 or positive indicates success and |
| 369 | * negative values indicate error. |
| 370 | */ |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 371 | public abstract int onCommand(String cmd); |
| 372 | |
Dianne Hackborn | 2e931f5 | 2016-01-28 12:21:17 -0800 | [diff] [blame] | 373 | /** |
| 374 | * Implement this to print help text about your command to {@link #getOutPrintWriter()}. |
| 375 | */ |
Dianne Hackborn | 9461b6f | 2015-10-07 17:33:16 -0700 | [diff] [blame] | 376 | public abstract void onHelp(); |
| 377 | } |