Exemple #1
0
  public void kill(boolean force) {
    int trycount = 4;

    if (workingProcess != null && running) {

      Log.writeByLevel(LogLevel.CORE, "Trying to stop logcat process");

      consume = false;

      while (consumeWorker.getState() != Thread.State.TERMINATED) {

        if (force) {
          internalStop();
          return;
        }

        Log.writeByLevel(LogLevel.CORE, "Waiting worker thread to finish #%d", trycount);

        try {
          workerLock.waitForLock(100);
        } catch (TimedOutException e) {
          if (trycount <= 0) {
            Log.writeByLevel(LogLevel.CORE, "Thread finish wait threshold limit exceeded.");
            internalStop();
            return;
          }

          trycount--;
        }
      }

      internalStop();
    }
  }
Exemple #2
0
  public boolean start() {
    workerLock.lock();
    processStartWaitLock.lock();

    Log.writeByLevel(LogLevel.CORE, "Starting adb process worker thread");

    consumeWorker = new Thread(this);
    consumeWorker.start();

    Log.writeByLevel(LogLevel.CORE, "Waiting process to be ready");

    try {
      processStartWaitLock.waitForLock(10 * 1000);
    } catch (TimedOutException e) {
      Log.writeByLevel(LogLevel.CORE, "process start wait timed out!");
      return false;
    }

    Log.writeByLevel(LogLevel.CORE, "It seems ok");

    return isRunning();
  }
Exemple #3
0
  @Override
  public void run() {
    BufferedReader streamReader;
    String bufferLine;
    boolean deviceNotConnected = true;

    if (!internalStart()) {
      processStartWaitLock.release();
      return;
    }

    running = true;
    processStartWaitLock.release();

    streamReader = new BufferedReader(new InputStreamReader(workingProcess.getInputStream()));

    while (consume) {
      try {
        bufferLine = streamReader.readLine();

        if (bufferLine == null) {
          try {
            if (workingProcess != null) {
              workingProcess.exitValue();
              Log.writeByLevel(LogLevel.CORE, "Process terminated");
              consume = false;
              raiseEvent("ADBTERM");
            }
          } catch (IllegalThreadStateException e) {
          }

          continue;
        }

        if (StringHelper.isEmpty(bufferLine)) continue;

        if (bufferLine.startsWith("-") || bufferLine.startsWith("*")) {
          continue;
        }

        if (deviceNotConnected) {
          deviceNotConnected = false;

          raiseEvent("DEVCON");
        }
      } catch (IOException e) {
        Log.writeByLevel(LogLevel.CORE, "AN IO EXCEPTION OCCURRED IN CONSUME LOOP.");
        consume = false;
        break;
      }

      if (bufferLine != null) {
        raiseEvent(bufferLine);
      }
    }

    Log.writeByLevel(LogLevel.CORE, "Exited consume loop. Releasing workerBlock");

    try {
      streamReader.close();
    } catch (IOException e) {
    }

    workerLock.release();
  }