com.facebook.stetho.dumpapp.DumpException Java Examples

The following examples show how to use com.facebook.stetho.dumpapp.DumpException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CrashDumperPlugin.java    From stetho with MIT License 6 votes vote down vote up
@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);
    }
  }
}
 
Example #2
Source File: CrashDumperPlugin.java    From stetho with MIT License 6 votes vote down vote up
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);
  }
}
 
Example #3
Source File: HprofDumperPlugin.java    From stetho with MIT License 6 votes vote down vote up
@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);
    }
  }
}
 
Example #4
Source File: HprofDumperPlugin.java    From stetho with MIT License 6 votes vote down vote up
private void handlePipeOutput(OutputStream output) throws DumpException {
  File hprofFile = mContext.getFileStreamPath("hprof-dump.hprof");
  try {
    writeHprof(hprofFile);
    try {
      InputStream input = new FileInputStream(hprofFile);
      try {
        Util.copy(input, output, new byte[2048]);
      } finally {
        input.close();
      }
    } catch (IOException e) {
      throw new DumpException("Failure copying " + hprofFile + " to dumper output");
    }
  } finally {
    if (hprofFile.exists()) {
      hprofFile.delete();
    }
  }
}
 
Example #5
Source File: FilesDumperPlugin.java    From stetho with MIT License 6 votes vote down vote up
@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);
    }
  }
}
 
Example #6
Source File: APODDumperPlugin.java    From stetho with MIT License 6 votes vote down vote up
@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);
    }
  }
}
 
Example #7
Source File: BaseFrescoStethoPlugin.java    From fresco with MIT License 6 votes vote down vote up
/**
 * Entry point for the Stetho dumpapp script.
 *
 * <p>{@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 if (cmd != null && cmd.equals("clear")) {
    mImagePipeline.clearCaches();
  } else {
    usage(writer);
    if (TextUtils.isEmpty(cmd)) {
      throw new DumpUsageException("Missing command");
    } else {
      throw new DumpUsageException("Unknown command: " + cmd);
    }
  }
}
 
Example #8
Source File: BaseFrescoStethoPlugin.java    From fresco with MIT License 6 votes vote down vote up
private void diskcache(FileCache cache, String title, PrintStream writer, List<String> args)
    throws DumpException {
  DiskStorage.DiskDumpInfo intDiskDumpInfo;
  try {
    intDiskDumpInfo = cache.getDumpInfo();
  } catch (IOException e) {
    throw new DumpException(e.getMessage());
  }
  if (!args.isEmpty() && args.get(0).equals("-s")) {
    writeDiskDumpInfoScriptReadable(writer, intDiskDumpInfo);
  } else {
    writer.println();
    writer.println(title + " disk cache contents:");
    writeDiskDumpInfo(writer, intDiskDumpInfo);
  }
}
 
Example #9
Source File: AppDumperPlugin.java    From droidconat-2016 with Apache License 2.0 5 votes vote down vote up
@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;
    }
}
 
Example #10
Source File: HprofDumperPlugin.java    From stetho with MIT License 5 votes vote down vote up
private void writeHprof(File outputPath) throws DumpException {
  try {
    // Test that we can write here.  dumpHprofData appears to hang if it cannot write
    // to the target location on ART.
    truncateAndDeleteFile(outputPath);
    Debug.dumpHprofData(outputPath.getAbsolutePath());
  } catch (IOException e) {
    throw new DumpException("Failure writing to " + outputPath + ": " + e.getMessage());
  }
}
 
Example #11
Source File: HelloWorldDumperPlugin.java    From stetho with MIT License 5 votes vote down vote up
@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);
  }
}
 
Example #12
Source File: HelloWorldDumperPlugin.java    From stetho with MIT License 5 votes vote down vote up
private void doHello(InputStream in, PrintStream writer, String name) throws DumpException {
  if (TextUtils.isEmpty(name)) {
    // This will print an error to the dumpapp user and cause a non-zero exit of the
    // script.
    throw new DumpUsageException("Name is empty");
  } else if ("-".equals(name)) {
    try {
      name = new BufferedReader(new InputStreamReader(in)).readLine();
    } catch (IOException e) {
      throw new DumpException(e.toString());
    }
  }

  writer.println("Hello " + name + "!");
}
 
Example #13
Source File: BaseFrescoStethoPlugin.java    From fresco with MIT License 5 votes vote down vote up
private void getFiles(
    PrintStream writer, CountingMemoryCacheInspector.DumpInfo<CacheKey, CloseableImage> dumpInfo)
    throws DumpException, IOException {
  writer.println("\nStoring all images in the memory cache into /sdcard/imagedumperfiles/ ...");

  File dir = new File(Environment.getExternalStorageDirectory().getPath() + "/imagedumperfiles/");
  if (dir.exists() && dir.isDirectory()) {
    File[] files = dir.listFiles();
    if (files != null) {
      for (File file : files) {
        file.delete();
      }
    }
    if (!dir.delete()) {
      throw new DumpException("Failed to clear existing /sdcard/imagedumperfiles directory");
    }
  }
  if (!dir.mkdirs()) {
    throw new DumpException("Failed to create /sdcard/imagedumperfiles directory");
  }
  if (!dumpInfo.lruEntries.isEmpty()) {
    writer.println("LRU Entries:");
    storeEntries(dumpInfo.lruEntries, 1, writer, dir);
  }
  if (!dumpInfo.sharedEntries.isEmpty()) {
    writer.println("Shared Entries:");
    storeEntries(dumpInfo.sharedEntries, dumpInfo.lruEntries.size() + 1, writer, dir);
  }

  writer.println("Done!");
}
 
Example #14
Source File: BaseFrescoStethoPlugin.java    From fresco with MIT License votes vote down vote up
protected abstract void ensureInitialized() throws DumpException;