/** * Entry point for the Stetho dumpapp script. * * {@link #initialize} must have been called in the app before running dumpapp. */ @Override public void dump(DumperContext dumpContext) throws DumpException { ensureInitialized(); List<String> args = dumpContext.getArgsAsList(); PrintStream writer = dumpContext.getStdout(); String cmd = args.isEmpty() ? null : args.get(0); List<String> rest = args.isEmpty() ? new ArrayList<String>() : args.subList(1, args.size()); if (cmd != null && cmd.equals("memcache")) { memcache(writer, rest); } else if (cmd != null && cmd.equals("diskcache")) { diskcache(mMainFileCache, "Main", writer, rest); diskcache(mSmallFileCache, "Small", writer, rest); } else { usage(writer); if (TextUtils.isEmpty(cmd)) { throw new DumpUsageException("Missing command"); } else { throw new DumpUsageException("Unknown command: " + cmd); } } }
@Override public void dump(DumperContext dumpContext) throws DumpException { Iterator<String> argsIter = dumpContext.getArgsAsList().iterator(); String command = ArgsHelper.nextOptionalArg(argsIter, null); if ("throw".equals(command)) { doUncaughtException(argsIter); } else if ("kill".equals(command)) { doKill(dumpContext, argsIter); } else if ("exit".equals(command)) { doSystemExit(argsIter); } else { doUsage(dumpContext.getStdout()); if (command != null) { throw new DumpUsageException("Unsupported command: " + command); } } }
private void doKill(DumperContext dumpContext, Iterator<String> argsIter) throws DumpException { String signal = ArgsHelper.nextOptionalArg(argsIter, OPTION_KILL_DEFAULT); try { Process kill = new ProcessBuilder() .command("/system/bin/kill", "-" + signal, String.valueOf(android.os.Process.myPid())) .redirectErrorStream(true) .start(); // Handle kill command output gracefully in the event that the signal delivered didn't // actually take out our process... try { InputStream in = kill.getInputStream(); Util.copy(in, dumpContext.getStdout(), new byte[1024]); } finally { kill.destroy(); } } catch (IOException e) { throw new DumpException("Failed to invoke kill: " + e); } }
@Override public void dump(DumperContext dumpContext) throws DumpException { final PrintStream output = dumpContext.getStdout(); Iterator<String> argsIter = dumpContext.getArgsAsList().iterator(); String outputPath = argsIter.hasNext() ? argsIter.next() : null; if (outputPath == null) { usage(output); } else { if ("-".equals(outputPath)) { handlePipeOutput(output); } else { File outputFile = new File(outputPath); if (!outputFile.isAbsolute()) { outputFile = mContext.getFileStreamPath(outputPath); } writeHprof(outputFile); output.println("Wrote to " + outputFile); } } }
@Override public void dump(DumperContext dumpContext) throws DumpException { Iterator<String> args = dumpContext.getArgsAsList().iterator(); String command = ArgsHelper.nextOptionalArg(args, ""); if ("ls".equals(command)) { doLs(dumpContext.getStdout()); } else if ("tree".equals(command)) { doTree(dumpContext.getStdout()); } else if ("download".equals(command)) { doDownload(dumpContext.getStdout(), args); } else { doUsage(dumpContext.getStdout()); if (!"".equals(command)) { throw new DumpUsageException("Unknown command: " + command); } } }
@Override public void dump(DumperContext dumpContext) throws DumpException { PrintStream writer = dumpContext.getStdout(); Iterator<String> argsIter = dumpContext.getArgsAsList().iterator(); String command = ArgsHelper.nextOptionalArg(argsIter, null); if (CMD_LIST.equalsIgnoreCase(command)) { doList(writer); } else if (CMD_DELETE.equalsIgnoreCase(command)) { doRemove(writer, argsIter); } else if (CMD_CLEAR.equalsIgnoreCase(command)) { doClear(writer); } else if (CMD_REFRESH.equalsIgnoreCase(command)) { doRefresh(writer); } else { usage(writer); if (command != null) { throw new DumpUsageException("Unknown command: " + command); } } }
private void dumpTypeMap(DumperContext dumperContext, InfoDumper dumper) throws DumpException { PrintStream writer = dumperContext.getStdout(); if (mIsAll) { writer.println("[" + dumper.getTitle() + "]"); } LinkedHashMap<String, String> dumps = dumper.getDumpMap(mContext); if (dumps == null) { writer.println(dumper.getErrorMessage()); if (mIsAll) { writer.println(""); } return; } for (Map.Entry<String, String> e : dumps.entrySet()) { writer.println(e.getKey() + ": " + e.getValue()); } if (mIsAll) { writer.println(""); } }
private void dumpTypeList(DumperContext dumperContext, InfoDumper dumper) throws DumpException { PrintStream writer = dumperContext.getStdout(); if (mIsAll) { writer.println("[" + dumper.getTitle() + "]"); } List<String> dumps = dumper.getDumpList(mContext); if (dumps == null) { writer.println(dumper.getErrorMessage()); if (mIsAll) { writer.println(""); } return; } for (String dump : dumps) { writer.println(dump); } if (mIsAll) { writer.println(""); } }
@Override public void dump(DumperContext dumpContext) throws DumpException { Iterator<String> args = dumpContext.getArgsAsList().iterator(); String command = ArgsHelper.nextOptionalArg(args, ""); if ("download".equals(command)) { doDownload(dumpContext.getStdout(), args); } else { doUsage(dumpContext.getStdout()); if (!"".equals(command)) { throw new DumpUsageException("Unknown command: " + command); } } }
@Override public void dump(DumperContext dumpContext) throws DumpException { final PrintStream writer = dumpContext.getStdout(); List<String> args = dumpContext.getArgsAsList(); String commandName = args.isEmpty() ? "" : args.remove(0); switch (commandName) { case "alarms": displayAlarms(writer); break; case "appInfo": displayAppInfo(writer); break; case "bootReceiver": displayBootReceiverState(writer); break; case "currentSession": displayCurrentSessionData(writer); break; case "endpoint": changeEndpoint(writer, args); break; case "notif": displayNotificationReminder(); break; default: doUsage(writer); break; } }
@Override public void dump(DumperContext dumpContext) throws DumpUsageException { PrintStream writer = dumpContext.getStdout(); List<String> args = dumpContext.getArgsAsList(); String commandName = args.isEmpty() ? "" : args.remove(0); if (commandName.equals("print")) { doPrint(writer, args); } else if (commandName.equals("write")) { doWrite(args); } else { doUsage(writer); } }
@Override public void dump(DumperContext dumpContext) throws DumpException { PrintStream writer = dumpContext.getStdout(); Iterator<String> args = dumpContext.getArgsAsList().iterator(); String helloToWhom = ArgsHelper.nextOptionalArg(args, null); if (helloToWhom != null) { doHello(dumpContext.getStdin(), writer, helloToWhom); } else { doUsage(writer); } }
private void usage(DumperContext dumperContext) { PrintStream writer = dumperContext.getStdout(); final String cmdName = "dumpapp " + NAME; final String usagePrefix = "Usage: " + cmdName + " "; writer.println(usagePrefix + "<command>"); writer.print(usagePrefix + CMD_BUILD_CONFIG); writer.println(); writer.print(usagePrefix + CMD_ID); writer.println(); writer.print(usagePrefix + CMD_DPI); writer.println(); writer.print(usagePrefix + CMD_MEMORY); writer.println(); writer.print(usagePrefix + CMD_PERMISSION); writer.println(); writer.print(usagePrefix + CMD_LAST_UPDATE); writer.println(); writer.print(usagePrefix + CMD_APPLICATION_INFO); writer.println(); writer.print(usagePrefix + CMD_OS_BUILD); writer.println(); writer.print(usagePrefix + CMD_NETWORK); writer.println(); writer.print(usagePrefix + CMD_ERROR); writer.println(); writer.print(usagePrefix + CMD_TEL); writer.println(); writer.print(usagePrefix + CMD_ALL); writer.println(); }
@Override public void dump(DumperContext dumperContext) throws DumpException { Iterator<String> argsIterator = dumperContext.getArgsAsList().iterator(); String command = ArgsHelper.nextOptionalArg(argsIterator, null); mIsAll = false; if (CMD_BUILD_CONFIG.equalsIgnoreCase(command)) { dumpBuildConfig(dumperContext); } else if (CMD_PERMISSION.equalsIgnoreCase(command)) { dumpPermission(dumperContext); } else if (CMD_LAST_UPDATE.equalsIgnoreCase(command)) { dumpLastUpdate(dumperContext); } else if (CMD_APPLICATION_INFO.equalsIgnoreCase(command)) { dumpApplicationInfo(dumperContext); } else if (CMD_ID.equalsIgnoreCase(command)) { dumpIds(dumperContext); } else if (CMD_OS_BUILD.equalsIgnoreCase(command)) { dumpOsBuild(dumperContext); } else if (CMD_DPI.equalsIgnoreCase(command)) { dumpDpi(dumperContext); } else if (CMD_MEMORY.equalsIgnoreCase(command)) { dumpMemory(dumperContext); } else if (CMD_ERROR.equalsIgnoreCase(command)) { dumpError(dumperContext); } else if (CMD_NETWORK.equalsIgnoreCase(command)) { dumpNetwork(dumperContext); } else if (CMD_TEL.equalsIgnoreCase(command)) { dumpTel(dumperContext); } else if (CMD_ALL.equalsIgnoreCase(command)) { mIsAll = true; dumpBuildConfig(dumperContext); dumpPermission(dumperContext); dumpLastUpdate(dumperContext); dumpApplicationInfo(dumperContext); dumpIds(dumperContext); dumpOsBuild(dumperContext); dumpDpi(dumperContext); dumpMemory(dumperContext); dumpError(dumperContext); dumpNetwork(dumperContext); dumpTel(dumperContext); } else { usage(dumperContext); if (command != null) { throw new DumpUsageException("Unknown command: " + command); } } }
private void dumpBuildConfig(DumperContext dumperContext) throws DumpException { dumpTypeMap(dumperContext, new BuildConfigDumper()); }
private void dumpPermission(DumperContext dumperContext) throws DumpException { dumpTypeList(dumperContext, new PermissionDumper()); }
private void dumpLastUpdate(DumperContext dumperContext) throws DumpException { dumpTypeList(dumperContext, new LastUpdateDumper()); }
private void dumpApplicationInfo(DumperContext dumperContext) throws DumpException { dumpTypeMap(dumperContext, new ApplicationInfoDumper()); }
private void dumpOsBuild(DumperContext dumperContext) throws DumpException { dumpTypeMap(dumperContext, new OsBuildDumper()); }
private void dumpIds(DumperContext dumperContext) throws DumpException { dumpTypeMap(dumperContext, new IdsDumper()); }
private void dumpDpi(DumperContext dumperContext) throws DumpException { dumpTypeMap(dumperContext, new DpiDumper()); }
private void dumpMemory(DumperContext dumperContext) throws DumpException { dumpTypeMap(dumperContext, new MemoryDumper()); }
private void dumpError(DumperContext dumperContext) throws DumpException { dumpTypeMap(dumperContext, new ErrorDumper()); }
private void dumpNetwork(DumperContext dumperContext) throws DumpException { dumpTypeMap(dumperContext, new NetworkDumper()); }
private void dumpTel(DumperContext dumperContext) throws DumpException { dumpTypeMap(dumperContext, new TelDumper()); }