Crashes extends AbstractAppCenterService { @VisibleForTesting @Nullable ErrorReport buildErrorReport(ManagedErrorLog log) { UUID id = log.getId(); if (mErrorReportCache.containsKey(id)) { ErrorReport report = mErrorReportCache.get(id).report; report.setDevice(log.getDevice()); return report; } else { File file = ErrorLogHelper.getStoredThrowableFile(id); if (file != null) { String stackTrace = null; if (file.length() > 0) { stackTrace = FileManager.read(file); } ErrorReport report = ErrorLogHelper.getErrorReportFromErrorLog(log, stackTrace); mErrorReportCache.put(id, new ErrorLogReport(log, report)); return report; } } return null; } private  Crashes(); @NonNull static synchronized Crashes getInstance(); static AppCenterFuture<Boolean> isEnabled(); static AppCenterFuture<Void> setEnabled(boolean enabled); @SuppressWarnings({"SameParameterValue", "WeakerAccess"}) static void trackError(Throwable throwable); static void trackError(Throwable throwable, Map<String, String> properties, Iterable<ErrorAttachmentLog> attachments); static void generateTestCrash(); static void setListener(CrashesListener listener); static AppCenterFuture<String> getMinidumpDirectory(); static void notifyUserConfirmation(@UserConfirmationDef int userConfirmation); static AppCenterFuture<Boolean> hasCrashedInLastSession(); static AppCenterFuture<ErrorReport> getLastSessionCrashReport(); static AppCenterFuture<Boolean> hasReceivedMemoryWarningInLastSession(); @Override synchronized void onStarted(@NonNull Context context, @NonNull Channel channel, String appSecret, String transmissionTargetToken, boolean startedFromApp); @Override Map<String, LogFactory> getLogFactories(); @Override String getServiceName(); static final int SEND; static final int DONT_SEND; static final int ALWAYS_SEND; @VisibleForTesting
    static final String PREF_KEY_ALWAYS_SEND; static final String LOG_TAG; }
@Test public void buildErrorReport() { mErrorLog.setDevice(mock(Device.class)); ErrorReport errorReport = ErrorLogHelper.getErrorReportFromErrorLog(mErrorLog, STACK_TRACE); mockStatic(ErrorLogHelper.class); File throwableFile = mock(File.class); when(throwableFile.length()).thenReturn(1L); when(ErrorLogHelper.getStoredThrowableFile(any(UUID.class))).thenReturn(throwableFile).thenReturn(null); when(ErrorLogHelper.getErrorReportFromErrorLog(mErrorLog, STACK_TRACE)).thenReturn(errorReport); when(FileManager.read(any(File.class))).thenReturn(STACK_TRACE); Crashes crashes = Crashes.getInstance(); ErrorReport report = crashes.buildErrorReport(mErrorLog); assertErrorEquals(mErrorLog, report); verifyStatic(); ErrorLogHelper.getErrorReportFromErrorLog(mErrorLog, STACK_TRACE); assertEquals(report, crashes.buildErrorReport(mErrorLog)); verifyStatic(); ErrorLogHelper.getErrorReportFromErrorLog(mErrorLog, STACK_TRACE); mErrorLog.setId(UUID.randomUUID()); report = crashes.buildErrorReport(mErrorLog); assertNull(report); }