com.facebook.stetho.dumpapp.DumperContext Java Examples

The following examples show how to use com.facebook.stetho.dumpapp.DumperContext. 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: 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 #2
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 6 votes vote down vote up
private void printAvailableCommands(DumperContext dumpContext) {
    log(dumpContext, "Available commands:");
    GattCommand[] commands = GattCommand.values();
    for (GattCommand command : commands) {
        dumpContext.getStdout().print(command.getFullName());
        if (command.getShortName() != null && !command.getShortName().equals("")) {
            dumpContext.getStdout().print(", " + command.getShortName());
        }
        dumpContext.getStdout().print(", " + command.getDescription());
        logNewLine(dumpContext);
        logNewLine(dumpContext);
        dumpContext.getStdout().print("-------------------------------");
        logNewLine(dumpContext);
        logNewLine(dumpContext);
    }
}
 
Example #3
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 6 votes vote down vote up
private void gattServerDisconnect(DumperContext dumpContext, Iterator<String> args) throws InterruptedException {
    if (args.hasNext()) {
        String mac = args.next();
        FitbitBluetoothDevice device = null;
        GattConnection conn = fitbitGatt.getConnectionForBluetoothAddress(context, mac);
        if (conn != null) {
            device = conn.getDevice();
        }
        if (device == null) {
            logError(dumpContext, new IllegalArgumentException("No device for mac address provided"));
            return;
        }
        conn.getDevice().addDevicePropertiesChangedListener(this);
        GattServerDisconnectTransaction disconnectTx = new GattServerDisconnectTransaction(fitbitGatt.getServer(), GattState.DISCONNECTED, device);
        CountDownLatch cdl = new CountDownLatch(1);
        fitbitGatt.getServer().runTx(disconnectTx, result -> {
            logSuccessOrFailure(result, dumpContext, "Successfully Server Disconnected from " + mac, "Failed Server Disconnecting from " + mac);
            cdl.countDown();
            conn.getDevice().removeDevicePropertiesChangedListener(this);
        });
        cdl.await();
    } else {
        logError(dumpContext, new IllegalArgumentException("No mac address provided"));
    }
}
 
Example #4
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 6 votes vote down vote up
private void gattServerConnect(DumperContext dumpContext, Iterator<String> args) throws InterruptedException {
    if (args.hasNext()) {
        String mac = args.next();
        FitbitBluetoothDevice device = null;
        GattConnection conn = fitbitGatt.getConnectionForBluetoothAddress(context, mac);
        if (conn != null) {
            device = conn.getDevice();
        }
        if (device == null) {
            logError(dumpContext, new IllegalArgumentException("No device for mac address provided"));
            return;
        }
        GattServerConnectTransaction serverConnectTx = new GattServerConnectTransaction(fitbitGatt.getServer(), GattState.CONNECTED, device);
        CountDownLatch cdl = new CountDownLatch(1);
        fitbitGatt.getServer().runTx(serverConnectTx, result -> {
            logSuccessOrFailure(result, dumpContext, "Successfully Server Connected to " + mac, "Failed Server Connecting to " + mac);
            cdl.countDown();
        });
        cdl.await();
    } else {
        logError(dumpContext, new IllegalArgumentException("No mac address provided"));
    }
}
 
Example #5
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 6 votes vote down vote up
private void gattClientDisconnect(DumperContext dumpContext, Iterator<String> args) throws InterruptedException {
    if (args.hasNext()) {
        String mac = args.next();
        GattConnection conn = clientConnections.get(mac);
        if (conn == null) {
            logError(dumpContext, new IllegalStateException("No connected client for mac " + mac));
        } else {
            conn.getDevice().addDevicePropertiesChangedListener(this);
            conn.unregisterConnectionEventListener(this);
            GattDisconnectTransaction disconnectTx = new GattDisconnectTransaction(conn, GattState.DISCONNECTED);
            CountDownLatch cdl = new CountDownLatch(1);
            conn.runTx(disconnectTx, result -> {
                logSuccessOrFailure(result, dumpContext, "Successfully Disconnected from " + mac, "Failed Disconnecting from " + mac);
                cdl.countDown();
                conn.getDevice().removeDevicePropertiesChangedListener(this);
            });
            cdl.await();
        }
    } else {
        logError(dumpContext, new IllegalArgumentException("No mac address provided"));
    }
}
 
Example #6
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 6 votes vote down vote up
private void gattClientConnect(DumperContext dumpContext, Iterator<String> args) throws InterruptedException {
    if (args.hasNext()) {
        String mac = args.next();
        GattConnection conn = clientConnections.get(mac);
        if (conn == null) {
            logError(dumpContext, new IllegalStateException("No connected client for mac " + mac));
        } else {
            conn.registerConnectionEventListener(this);
            conn.getDevice().addDevicePropertiesChangedListener(this);
            GattConnectTransaction connectTx = new GattConnectTransaction(conn, GattState.CONNECTED);
            CountDownLatch cdl = new CountDownLatch(1);
            conn.runTx(connectTx, result -> {
                logSuccessOrFailure(result, dumpContext, "Successfully Connected to " + mac, "Failed Connecting to " + mac);
                cdl.countDown();
                conn.getDevice().removeDevicePropertiesChangedListener(this);
            });
            cdl.await();
        }
    } else {
        logError(dumpContext, new IllegalArgumentException("No mac address provided"));
    }
}
 
Example #7
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 6 votes vote down vote up
private void gattClientDiscoverServices(DumperContext dumpContext, Iterator<String> args) throws InterruptedException {
    if (args.hasNext()) {
        String mac = args.next();
        GattConnection conn = clientConnections.get(mac);
        if (conn == null) {
            logError(dumpContext, new IllegalStateException("No connected client for mac " + mac));
        } else {
            conn.getDevice().addDevicePropertiesChangedListener(this);
            GattClientDiscoverServicesTransaction discoverTx = new GattClientDiscoverServicesTransaction(conn, GattState.DISCOVERY_SUCCESS);
            CountDownLatch cdl = new CountDownLatch(1);
            conn.runTx(discoverTx, result -> {
                logSuccessOrFailure(result, dumpContext, "Successfully Discovered Gatt Client Services", "Failed Discovering Gatt Client Services");
                cdl.countDown();
                conn.getDevice().removeDevicePropertiesChangedListener(this);
            });
            cdl.await();
        }
    } else {
        logError(dumpContext, new IllegalArgumentException("No mac address provided"));
    }
}
 
Example #8
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 6 votes vote down vote up
private void setJsonFormat(DumperContext dumperContext, Iterator<String> args) {
    String isJsonString = ArgsHelper.nextOptionalArg(args, null);
    if ("on".equalsIgnoreCase(isJsonString)) {
        isJsonFormat = true;
        Map<String, Object> map = new LinkedHashMap<>();
        map.put(COMMAND_KEY, "set-json-format");
        map.put(STATUS_KEY, PASS_STATUS);
        map.put(RESULT_KEY, "Set JSON on");
        JSONObject jsonObject = makeJsonObject(map);
        log(dumperContext, jsonObject.toString());
    } else if ("off".equalsIgnoreCase(isJsonString)) {
        isJsonFormat = false;
        log(dumperContext, "Set JSON off");
    } else {
        throw new IllegalArgumentException("usage: dumpapp set-json-format on/off");
    }
}
 
Example #9
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 6 votes vote down vote up
private void closeGattClient(DumperContext dumpContext, Iterator<String> args) throws InterruptedException {
    if (args.hasNext()) {
        String mac = args.next();
        GattConnection conn = clientConnections.get(mac);
        if (conn == null) {
            logError(dumpContext, new IllegalStateException("No connected client for mac " + mac));
        } else {
            conn.getDevice().addDevicePropertiesChangedListener(this);
            CloseGattTransaction closeTx = new CloseGattTransaction(conn, GattState.CLOSE_GATT_CLIENT_SUCCESS);
            CountDownLatch cdl = new CountDownLatch(1);
            conn.runTx(closeTx, result -> {
                logSuccessOrFailure(result, dumpContext, "Successfully Closed Gatt Client Interface", "Failed Closing Gatt Client Interface");
                cdl.countDown();
                conn.getDevice().removeDevicePropertiesChangedListener(this);
            });
            cdl.await();
        }
    } else {
        logError(dumpContext, new IllegalArgumentException("No mac address provided"));
    }
}
 
Example #10
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 #11
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 #12
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 #13
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 #14
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 6 votes vote down vote up
private void startGatt(DumperContext dumpContext) {
    String status;
    String error = "";
    try {
        fitbitGatt.startGattClient(context);
        fitbitGatt.startGattServer(context);
        List<ParcelUuid> serviceUuids = new ArrayList<>(1);
        serviceUuids.add(ParcelUuid.fromString("ADABFB00-6E7D-4601-BDA2-BFFAA68956BA"));
        fitbitGatt.setScanServiceUuidFilters(serviceUuids);
        fitbitGatt.startHighPriorityScan(fitbitGatt.getAppContext());
        fitbitGatt.initializeScanner(context);
        status = PASS_STATUS;
    } catch (Exception e) {
        status = FAIL_STATUS;
        error = Arrays.toString(e.getStackTrace());
    }

    logResult("init", status, "Gatt Ready", error, dumpContext);
}
 
Example #15
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 #16
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 6 votes vote down vote up
private void logResult(String command, String status, String result, String error,
                       DumperContext dumpContext) {
    if (isJsonFormat) {
        Map<String, Object> map = new LinkedHashMap<>();
        map.put(COMMAND_KEY, command);
        map.put(STATUS_KEY, status);
        if (PASS_STATUS.equalsIgnoreCase(status)) {
            map.put(RESULT_KEY, result);
        } else {
            map.put(ERROR_KEY, error);
        }
        String resultJson = makeJsonObject(map).toString();
        log(dumpContext, resultJson);
    } else {
        log(dumpContext, result);
    }
}
 
Example #17
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
private void addLocalGattServerService(DumperContext dumpContext, Iterator<String> args) throws InterruptedException {
    if (args.hasNext()) {
        String serviceUuid = args.next();
        BluetoothGattServer server = fitbitGatt.getServer().getServer();
        boolean isDuplicate = false;
        for (BluetoothGattService service : server.getServices()) {
            String currentUuid = service.getUuid().toString();
            if (currentUuid.equals(serviceUuid)) {
                isDuplicate = true;
                break;
            }
        }

        if (!isDuplicate) {
            BluetoothGattService gattService = new BluetoothGattService(UUID.fromString(serviceUuid), BluetoothGattService.SERVICE_TYPE_PRIMARY);
            AddGattServerServiceTransaction tx = new AddGattServerServiceTransaction(fitbitGatt.getServer(), GattState.ADD_SERVICE_SUCCESS, gattService);
            CountDownLatch cdl = new CountDownLatch(1);
            fitbitGatt.getServer().runTx(tx, result -> {
                logSuccessOrFailure(result, dumpContext, "Successfully Added Gatt Server Service", "Failed Adding Gatt Server Service");
                cdl.countDown();
            });
            cdl.await();
        } else {
            logSuccess(dumpContext, "Duplicate service by UUID ");
        }

    } else {
        logError(dumpContext, new IllegalArgumentException("No viable service UUID provided"));
    }
}
 
Example #18
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
private void clearLocalGattServerServices(DumperContext dumpContext) throws InterruptedException {
    ClearServerServicesTransaction clearServices = new ClearServerServicesTransaction(fitbitGatt.getServer(), GattState.CLEAR_GATT_SERVER_SERVICES_SUCCESS);
    CountDownLatch cdl = new CountDownLatch(1);
    fitbitGatt.getServer().runTx(clearServices, result -> {
        logSuccessOrFailure(result, dumpContext, "Successfully Cleared Gatt Server Service", "Failed Clearing Gatt Server Service");
        cdl.countDown();
    });
    cdl.await();
}
 
Example #19
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
private void logJsonResult(DumperContext dumpContext, TransactionResult result, String error, Map<String, Object> resultMap) {
    boolean success = result.getResultStatus().equals(TransactionResult.TransactionResultStatus.SUCCESS);
    String status = success ? PASS_STATUS : FAIL_STATUS;
    Map<String, Object> map = new LinkedHashMap<>();
    map.put(COMMAND_KEY, getCommand(dumpContext));
    map.put(STATUS_KEY, status);
    if (PASS_STATUS.equalsIgnoreCase(status)) {
        map.put(RESULT_KEY, makeJsonObject(resultMap));
    } else {
        map.put(ERROR_KEY, error);
    }
    JSONObject jsonRoot = makeJsonObject(map);
    log(dumpContext, jsonRoot.toString());
}
 
Example #20
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
private void refreshGatt(DumperContext dumperContext, Iterator<String> args) throws InterruptedException {
    int index = 0;
    String mac = null;
    while (args.hasNext()) {
        if (index == 0) {
            mac = args.next();
        }
        index++;
    }
    if (mac == null) {
        logError(dumperContext, new IllegalArgumentException("No remote mac address provided"));
        return;
    }
    GattConnection conn = FitbitGatt.getInstance().getConnectionForBluetoothAddress(FitbitGatt.getInstance().getAppContext(), mac);
    if (conn == null) {
        logError(dumperContext, new IllegalArgumentException("No connection available for provided mac"));
        return;
    }
    if (conn.getGatt() == null) {
        logError(dumperContext, new IllegalStateException("No Gatt client established, you have to at least have connected once"));
        return;
    }
    conn.getDevice().addDevicePropertiesChangedListener(this);
    GattClientRefreshGattTransaction refresh = new GattClientRefreshGattTransaction(conn, GattState.REFRESH_GATT_SUCCESS);
    CountDownLatch cdl = new CountDownLatch(1);
    conn.runTx(refresh, result -> {
        logSuccessOrFailure(result, dumperContext, "Successfully refreshed on " + conn.getDevice(), "Failed refreshing on " + conn.getDevice());
        cdl.countDown();
        conn.getDevice().removeDevicePropertiesChangedListener(this);
    });
    cdl.await();
}
 
Example #21
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
private void logJsonResult(DumperContext dumpContext, String status, String error, JSONArray result) {
    Map<String, Object> map = new LinkedHashMap<>();
    map.put(COMMAND_KEY, getCommand(dumpContext));
    map.put(STATUS_KEY, status);
    if (PASS_STATUS.equalsIgnoreCase(status)) {
        map.put(RESULT_KEY, result);
    } else {
        map.put(ERROR_KEY, error);
    }
    JSONObject jsonRoot = makeJsonObject(map);
    log(dumpContext, jsonRoot.toString());
}
 
Example #22
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
private void readGattLibVersion(DumperContext dumpContext) {
    String glversion = "0.0.0"; // For Irvin: Here replace with the correct API

    if (isJsonFormat) {
        Map<String, Object> map = new LinkedHashMap<>();
        map.put(COMMAND_KEY, "read-gatt-lib-version");
        map.put(STATUS_KEY, PASS_STATUS);
        map.put(RESULT_KEY, glversion);
        JSONObject jsonObject = makeJsonObject(map);
        log(dumpContext, jsonObject.toString());
    } else {
        log(dumpContext, glversion);
    }
}
 
Example #23
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
private void readGattClientRssi(DumperContext dumpContext, Iterator<String> args) throws InterruptedException {
    if (args.hasNext()) {
        String mac = args.next();
        FitbitBluetoothDevice device = null;
        GattConnection conn = fitbitGatt.getConnectionForBluetoothAddress(context, mac);
        if (conn != null) {
            device = conn.getDevice();
        }
        if (device == null) {
            logError(dumpContext, new IllegalArgumentException("No device for mac address provided"));
            return;
        }
        conn.getDevice().addDevicePropertiesChangedListener(this);
        ReadRssiTransaction readRssiTransaction = new ReadRssiTransaction(conn, GattState.READ_RSSI_SUCCESS);
        CountDownLatch cdl = new CountDownLatch(1);
        conn.runTx(readRssiTransaction, result -> {
            if (!isJsonFormat) {
                log(dumpContext, result.toString());
                if (result.getResultStatus().equals(TransactionResult.TransactionResultStatus.SUCCESS)) {
                    format(dumpContext, "%d db for device with mac : %s", result.getRssi(), mac);
                    logSuccess(dumpContext, "Successfully read rssi from " + mac);
                } else {
                    logFailure(dumpContext, "Failed reading rssi from " + mac);
                }
            } else {
                Map<String, Object> resultMap = new LinkedHashMap<>();
                resultMap.put(RESULT_RSSI_KEY, result.getRssi());
                logJsonResult(dumpContext, result, result.toString(), resultMap);
            }
            cdl.countDown();
            conn.getDevice().removeDevicePropertiesChangedListener(this);
        });
        cdl.await();
    } else {
        logError(dumpContext, new IllegalArgumentException("No mac address provided"));
    }
}
 
Example #24
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
private void removeGattServerService(DumperContext dumpContext, Iterator<String> args) throws InterruptedException {
    if (args.hasNext()) {
        String serviceUuid = args.next();
        BluetoothGattService gattService = new BluetoothGattService(UUID.fromString(serviceUuid), BluetoothGattService.SERVICE_TYPE_PRIMARY);
        RemoveGattServerServicesTransaction tx = new RemoveGattServerServicesTransaction(fitbitGatt.getServer(), GattState.ADD_SERVICE_SUCCESS, gattService);
        CountDownLatch cdl = new CountDownLatch(1);
        fitbitGatt.getServer().runTx(tx, result -> {
            logSuccessOrFailure(result, dumpContext, "Successfully Removed Gatt Server Service", "Failed Removing Gatt Server Service");
            cdl.countDown();
        });
        cdl.await();
    } else {
        logError(dumpContext, new IllegalArgumentException("No viable service UUID provided"));
    }
}
 
Example #25
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
private void logSuccessOrFailure(TransactionResult result, DumperContext dumpContext, String successStr, String failureStr) {
    boolean success = result.getResultStatus().equals(TransactionResult.TransactionResultStatus.SUCCESS);
    if (isJsonFormat) {
        logResult(getCommand(dumpContext), success ? PASS_STATUS : FAIL_STATUS, result.toString(), result.toString(), dumpContext);
    } else {
        log(dumpContext, result.toString());
        if (success) {
            logSuccess(dumpContext, successStr);
        } else {
            logFailure(dumpContext, failureStr);
        }
    }
}
 
Example #26
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 #27
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
private void readGattClientPhy(DumperContext dumpContext, Iterator<String> args) throws InterruptedException {
    int index = 0;
    String mac = null;
    while (args.hasNext()) {
        if (index == 0) {
            mac = args.next();
        }
        index++;
    }
    if (mac == null) {
        logError(dumpContext, new IllegalArgumentException("No bluetooth mac provided"));
        return;
    }
    GattConnection conn = fitbitGatt.getConnectionForBluetoothAddress(context, mac);
    if (conn == null) {
        logError(dumpContext, new IllegalArgumentException("No device for mac address provided"));
        return;
    }
    ReadGattClientPhyTransaction readGattClientPhyTransaction = new ReadGattClientPhyTransaction(conn, GattState.READ_CURRENT_PHY_SUCCESS);
    CountDownLatch cdl = new CountDownLatch(1);
    conn.runTx(readGattClientPhyTransaction, result -> {
        logSuccessOrFailure(result, dumpContext, "Successfully read physical layer to tx: " + result.getTxPhy() + ", rx:  " + result.getRxPhy(),
            "Failed in reading physical layer to tx: " + result.getTxPhy() + ", rx: " + result.getRxPhy());
        cdl.countDown();
    });
    cdl.await();
}
 
Example #28
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
private void requestGattClientMtu(DumperContext dumpContext, Iterator<String> args) throws InterruptedException {
    int index = 0;
    String mtu = null;
    String mac = null;
    while (args.hasNext()) {
        if (index == 0) {
            mac = args.next();
        } else if (index == 1) {
            mtu = args.next();
        }
        index++;
    }
    if (mac == null) {
        logError(dumpContext, new IllegalArgumentException("No bluetooth mac provided"));
        return;
    }
    if (mtu == null) {
        logError(dumpContext, new IllegalArgumentException("No mtu"));
    }
    GattConnection conn = fitbitGatt.getConnectionForBluetoothAddress(context, mac);
    if (conn == null) {
        logError(dumpContext, new IllegalArgumentException("No device for mac address provided"));
        return;
    }
    RequestMtuGattTransaction tx = new RequestMtuGattTransaction(conn, GattState.REQUEST_MTU_SUCCESS, Integer.parseInt(mtu));
    CountDownLatch cdl = new CountDownLatch(1);
    conn.runTx(tx, result -> {
        logSuccessOrFailure(result, dumpContext, "Successfully changed mtu to " + result.getMtu() + " on " + conn.getDevice(), "Failed changed mtu to " + result.getMtu() + " on " + conn.getDevice());
        cdl.countDown();
    });
    cdl.await();
}
 
Example #29
Source File: SharedPreferencesDumperPlugin.java    From stetho with MIT License 5 votes vote down vote up
@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);
  }
}
 
Example #30
Source File: GattPlugin.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
protected void logError(DumperContext dumpContext, Throwable t) {
    StringWriter sw = new StringWriter();
    t.printStackTrace(new PrintWriter(sw));
    String exceptionAsString = sw.toString();
    String error = "\u001B[31m " + exceptionAsString + " \u001B[0m";
    if (isJsonFormat) {
        logResult(getCommand(dumpContext), FAIL_STATUS, "", error, dumpContext);
    } else {
        dumpContext.getStderr().println(error);
        dumpContext.getStderr().flush();
    }
}