Esempio n. 1
0
  private void checkAndSendReports() {
    TLog.d(TCrash.TAG, "#checkAndSendReports - start");
    CrashReportFinder reportFinder = new CrashReportFinder();
    String[] reportFiles = reportFinder.getCrashReportFiles();
    Arrays.sort(reportFiles);

    int reportsSentCount = 0;

    for (String curFileName : reportFiles)
      if (reportsSentCount > 1) {
        deleteFile(curFileName);
      } else {
        TLog.i(TCrash.TAG, "Sending file " + curFileName);
        try {
          TCrashReportPersister persister = new TCrashReportPersister();
          CrashReportData previousCrashReport = persister.load(curFileName);
          sendCrashReport(previousCrashReport);
          deleteFile(curFileName);
        } catch (RuntimeException e) {
          TLog.e(TCrash.TAG, "Failed to send crash reports for " + curFileName + e.getMessage());
          deleteFile(curFileName);
          break;
        } catch (IOException e) {
          TLog.e(TCrash.TAG, "Failed to load crash report for " + curFileName + e.getMessage());
          deleteFile(curFileName);
          break;
        } catch (ReportSenderException e) {
          TLog.e(TCrash.TAG, "Failed to send crash report for " + curFileName + e.getMessage());
          break;
        }

        reportsSentCount++;
      }
    TLog.d(TCrash.TAG, "#checkAndSendReports - finish");
  }
Esempio n. 2
0
  public int copy(InputStream input, RandomAccessFile out, TTask.Task task)
      throws Exception, IOException {
    this.mBuffer = new byte[8192];
    BufferedInputStream in = new BufferedInputStream(input, 8192);
    TLog.v(this.TAG, "length" + out.length());
    out.seek(out.length());

    int count = 0;
    int byteCount = 0;
    long errorBlockTimePreviousTime = -1L;
    long expireTime = 0L;
    try {
      while (!task.isCancel()) {
        byteCount = in.read(this.mBuffer, 0, 8192);
        if (byteCount == -1) {
          break;
        }
        out.write(this.mBuffer, 0, byteCount);
        count += byteCount;

        if (!TMDownloadManager.getInstance().isOnline()) {
          task.stopTask();
          setErrorCode(2);
          break;
        }

        if (this.mSpeed == 0L) {
          if (errorBlockTimePreviousTime > 0L) {
            expireTime = System.currentTimeMillis() - errorBlockTimePreviousTime;
            if (expireTime > 30000L) {
              setErrorCode(2);
              task.stopTask();
            }
          } else {
            errorBlockTimePreviousTime = System.currentTimeMillis();
          }
        } else {
          expireTime = 0L;
          errorBlockTimePreviousTime = -1L;
        }
      }
    } finally {
      try {
        out.close();
      } catch (IOException e) {
        setErrorCode(3);
        TLog.e(this.TAG, e.getMessage());
      }
      try {
        in.close();
      } catch (IOException e) {
        setErrorCode(3);
        TLog.e(this.TAG, e.getMessage());
      }
    }

    this.mBuffer = null;
    return count;
  }
Esempio n. 3
0
  private void approvePendingReports() {
    TLog.d(TCrash.TAG, "Mark all pending reports as approved.");

    CrashReportFinder reportFinder = new CrashReportFinder();
    String[] reportFileNames = reportFinder.getCrashReportFiles();

    for (String reportFileName : reportFileNames)
      if (!this.fileNameParser.isApproved(reportFileName)) {
        File reportFile = new File(TCrash.getInstance().getFilePath(), reportFileName);

        String newName = reportFileName.replace(".stacktrace", "-approved.stacktrace");

        File newFile = new File(TCrash.getInstance().getFilePath(), newName);
        if (!reportFile.renameTo(newFile))
          TLog.e(
              TCrash.TAG, "Could not rename approved report from " + reportFile + " to " + newFile);
      }
  }