/**
   * Enable btsnoop logging by changing the BtSnoopLogOutput line in /etc/bluetooth/bt_stack.conf to
   * true.
   */
  private boolean enableBtsnoopLogging() throws DeviceNotAvailableException {
    File confFile = mTestDevice.pullFile(BTSNOOP_CONF_FILE);
    if (confFile == null) {
      return false;
    }

    BufferedReader confReader = null;
    try {
      confReader = new BufferedReader(new FileReader(confFile));
      StringBuilder newConf = new StringBuilder();
      String line;
      while ((line = confReader.readLine()) != null) {
        if (line.startsWith("BtSnoopLogOutput=")) {
          newConf.append("BtSnoopLogOutput=true\n");
        } else {
          newConf.append(line).append("\n");
        }
      }
      mTestDevice.executeAdbCommand("remount");
      return mTestDevice.pushString(newConf.toString(), BTSNOOP_CONF_FILE);
    } catch (IOException e) {
      return false;
    } finally {
      confFile.delete();
      StreamUtil.close(confReader);
    }
  }
Exemplo n.º 2
0
  private boolean runCapture(int themeId, int layoutId, String imageName) throws Exception {
    final StringBuilder sb = new StringBuilder(START_CMD);
    sb.append(String.format(INTENT_INTEGER_EXTRA, EXTRA_THEME, themeId));
    sb.append(String.format(INTENT_INTEGER_EXTRA, EXTRA_LAYOUT, layoutId));
    sb.append(String.format(INTENT_INTEGER_EXTRA, EXTRA_TIMEOUT, CAPTURE_TIMEOUT));
    final String startCommand = sb.toString();
    // Clear logcat
    mDevice.executeAdbCommand("logcat", "-c");
    // Stop any existing instances
    mDevice.executeShellCommand(STOP_CMD);
    // Start activity
    mDevice.executeShellCommand(startCommand);

    boolean success = false;
    boolean waiting = true;
    while (waiting) {
      // Dump logcat.
      final String logs =
          mDevice.executeAdbCommand("logcat", "-v", "brief", "-d", CLASS + ":I", "*:S");
      // Search for string.
      final Scanner in = new Scanner(logs);
      while (in.hasNextLine()) {
        final String line = in.nextLine();
        if (line.startsWith("I/" + CLASS)) {
          final String[] lineSplit = line.split(":");
          final String s = lineSplit[1].trim();
          final String imageNameGenerated = lineSplit[2].trim();
          if (s.equals("OKAY") && imageNameGenerated.equals(imageName)) {
            success = true;
            waiting = false;
          } else if (s.equals("ERROR") && imageNameGenerated.equals(imageName)) {
            success = false;
            waiting = false;
          }
        }
      }
      in.close();
    }

    return success;
  }