Search in sources :

Example 1 with LogFileManager

use of com.google.firebase.crashlytics.internal.metadata.LogFileManager in project firebase-android-sdk by firebase.

the class CrashlyticsCore method onPreExecute.

// endregion
// region Initialization
public boolean onPreExecute(AppData appData, SettingsDataProvider settingsProvider) {
    // before starting the crash detector make sure that this was built with our build
    // tools.
    // Throw an exception and halt the app if the build ID is required and not present.
    // TODO: This flag is no longer supported and should be removed, as part of a larger refactor
    // now that the buildId is now only used for mapping file association.
    final boolean requiresBuildId = CommonUtils.getBooleanResourceValue(context, CRASHLYTICS_REQUIRE_BUILD_ID, CRASHLYTICS_REQUIRE_BUILD_ID_DEFAULT);
    if (!isBuildIdValid(appData.buildId, requiresBuildId)) {
        throw new IllegalStateException(MISSING_BUILD_ID_MSG);
    }
    final String sessionIdentifier = new CLSUUID(idManager).toString();
    try {
        crashMarker = new CrashlyticsFileMarker(CRASH_MARKER_FILE_NAME, fileStore);
        initializationMarker = new CrashlyticsFileMarker(INITIALIZATION_MARKER_FILE_NAME, fileStore);
        final UserMetadata userMetadata = new UserMetadata(sessionIdentifier, fileStore, backgroundWorker);
        final LogFileManager logFileManager = new LogFileManager(fileStore);
        final StackTraceTrimmingStrategy stackTraceTrimmingStrategy = new MiddleOutFallbackStrategy(MAX_STACK_SIZE, new RemoveRepeatsStrategy(NUM_STACK_REPETITIONS_ALLOWED));
        final SessionReportingCoordinator sessionReportingCoordinator = SessionReportingCoordinator.create(context, idManager, fileStore, appData, logFileManager, userMetadata, stackTraceTrimmingStrategy, settingsProvider);
        controller = new CrashlyticsController(context, backgroundWorker, idManager, dataCollectionArbiter, fileStore, crashMarker, appData, userMetadata, logFileManager, sessionReportingCoordinator, nativeComponent, analyticsEventLogger);
        // If the file is present at this point, then the previous run's initialization
        // did not complete, and we want to perform initialization synchronously this time.
        // We make this check early here because we want to guarantee that the async
        // startup thread we're about to launch doesn't affect the value.
        final boolean initializeSynchronously = didPreviousInitializationFail();
        checkForPreviousCrash();
        controller.enableExceptionHandling(sessionIdentifier, Thread.getDefaultUncaughtExceptionHandler(), settingsProvider);
        if (initializeSynchronously && CommonUtils.canTryConnection(context)) {
            Logger.getLogger().d("Crashlytics did not finish previous background " + "initialization. Initializing synchronously.");
            // finishInitSynchronously blocks the UI thread while it finishes background init.
            finishInitSynchronously(settingsProvider);
            // Returning false here to stop the rest of init from being run in the background thread.
            return false;
        }
    } catch (Exception e) {
        Logger.getLogger().e("Crashlytics was not started due to an exception during initialization", e);
        controller = null;
        return false;
    }
    Logger.getLogger().d("Successfully configured exception handler.");
    return true;
}
Also used : RemoveRepeatsStrategy(com.google.firebase.crashlytics.internal.stacktrace.RemoveRepeatsStrategy) UserMetadata(com.google.firebase.crashlytics.internal.metadata.UserMetadata) LogFileManager(com.google.firebase.crashlytics.internal.metadata.LogFileManager) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) StackTraceTrimmingStrategy(com.google.firebase.crashlytics.internal.stacktrace.StackTraceTrimmingStrategy) MiddleOutFallbackStrategy(com.google.firebase.crashlytics.internal.stacktrace.MiddleOutFallbackStrategy)

Example 2 with LogFileManager

use of com.google.firebase.crashlytics.internal.metadata.LogFileManager in project firebase-android-sdk by firebase.

the class CrashlyticsController method writeApplicationExitInfoEventIfRelevant.

// endregion
// region ApplicationExitInfo
/**
 * If an ApplicationExitInfo exists relevant to the session, writes that event.
 */
private void writeApplicationExitInfoEventIfRelevant(String sessionId) {
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        // Gets all the available app exit infos.
        List<ApplicationExitInfo> applicationExitInfoList = activityManager.getHistoricalProcessExitReasons(null, 0, 0);
        // happened during the session.
        if (applicationExitInfoList.size() != 0) {
            final LogFileManager relevantSessionLogManager = new LogFileManager(fileStore, sessionId);
            final UserMetadata relevantUserMetadata = UserMetadata.loadFromExistingSession(sessionId, fileStore, backgroundWorker);
            reportingCoordinator.persistRelevantAppExitInfoEvent(sessionId, applicationExitInfoList, relevantSessionLogManager, relevantUserMetadata);
        } else {
            Logger.getLogger().v("No ApplicationExitInfo available. Session: " + sessionId);
        }
    } else {
        Logger.getLogger().v("ANR feature enabled, but device is API " + android.os.Build.VERSION.SDK_INT);
    }
}
Also used : ApplicationExitInfo(android.app.ApplicationExitInfo) UserMetadata(com.google.firebase.crashlytics.internal.metadata.UserMetadata) ActivityManager(android.app.ActivityManager) LogFileManager(com.google.firebase.crashlytics.internal.metadata.LogFileManager)

Example 3 with LogFileManager

use of com.google.firebase.crashlytics.internal.metadata.LogFileManager in project firebase-android-sdk by firebase.

the class CrashlyticsCore method onPreExecute.

// endregion
// region Initialization
public boolean onPreExecute(AppData appData, SettingsProvider settingsProvider) {
    // before starting the crash detector make sure that this was built with our build
    // tools.
    // Throw an exception and halt the app if the build ID is required and not present.
    // TODO: This flag is no longer supported and should be removed, as part of a larger refactor
    // now that the buildId is now only used for mapping file association.
    final boolean requiresBuildId = CommonUtils.getBooleanResourceValue(context, CRASHLYTICS_REQUIRE_BUILD_ID, CRASHLYTICS_REQUIRE_BUILD_ID_DEFAULT);
    if (!isBuildIdValid(appData.buildId, requiresBuildId)) {
        throw new IllegalStateException(MISSING_BUILD_ID_MSG);
    }
    final String sessionIdentifier = new CLSUUID(idManager).toString();
    try {
        crashMarker = new CrashlyticsFileMarker(CRASH_MARKER_FILE_NAME, fileStore);
        initializationMarker = new CrashlyticsFileMarker(INITIALIZATION_MARKER_FILE_NAME, fileStore);
        final UserMetadata userMetadata = new UserMetadata(sessionIdentifier, fileStore, backgroundWorker);
        final LogFileManager logFileManager = new LogFileManager(fileStore);
        final StackTraceTrimmingStrategy stackTraceTrimmingStrategy = new MiddleOutFallbackStrategy(MAX_STACK_SIZE, new RemoveRepeatsStrategy(NUM_STACK_REPETITIONS_ALLOWED));
        final SessionReportingCoordinator sessionReportingCoordinator = SessionReportingCoordinator.create(context, idManager, fileStore, appData, logFileManager, userMetadata, stackTraceTrimmingStrategy, settingsProvider, onDemandCounter);
        controller = new CrashlyticsController(context, backgroundWorker, idManager, dataCollectionArbiter, fileStore, crashMarker, appData, userMetadata, logFileManager, sessionReportingCoordinator, nativeComponent, analyticsEventLogger);
        // If the file is present at this point, then the previous run's initialization
        // did not complete, and we want to perform initialization synchronously this time.
        // We make this check early here because we want to guarantee that the async
        // startup thread we're about to launch doesn't affect the value.
        final boolean initializeSynchronously = didPreviousInitializationFail();
        checkForPreviousCrash();
        controller.enableExceptionHandling(sessionIdentifier, Thread.getDefaultUncaughtExceptionHandler(), settingsProvider);
        if (initializeSynchronously && CommonUtils.canTryConnection(context)) {
            Logger.getLogger().d("Crashlytics did not finish previous background " + "initialization. Initializing synchronously.");
            // finishInitSynchronously blocks the UI thread while it finishes background init.
            finishInitSynchronously(settingsProvider);
            // Returning false here to stop the rest of init from being run in the background thread.
            return false;
        }
    } catch (Exception e) {
        Logger.getLogger().e("Crashlytics was not started due to an exception during initialization", e);
        controller = null;
        return false;
    }
    Logger.getLogger().d("Successfully configured exception handler.");
    return true;
}
Also used : RemoveRepeatsStrategy(com.google.firebase.crashlytics.internal.stacktrace.RemoveRepeatsStrategy) UserMetadata(com.google.firebase.crashlytics.internal.metadata.UserMetadata) LogFileManager(com.google.firebase.crashlytics.internal.metadata.LogFileManager) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) StackTraceTrimmingStrategy(com.google.firebase.crashlytics.internal.stacktrace.StackTraceTrimmingStrategy) MiddleOutFallbackStrategy(com.google.firebase.crashlytics.internal.stacktrace.MiddleOutFallbackStrategy)

Example 4 with LogFileManager

use of com.google.firebase.crashlytics.internal.metadata.LogFileManager in project firebase-android-sdk by firebase.

the class CrashlyticsController method finalizePreviousNativeSession.

private void finalizePreviousNativeSession(String previousSessionId) {
    Logger.getLogger().v("Finalizing native report for session " + previousSessionId);
    NativeSessionFileProvider nativeSessionFileProvider = nativeComponent.getSessionFileProvider(previousSessionId);
    File minidumpFile = nativeSessionFileProvider.getMinidumpFile();
    if (minidumpFile == null || !minidumpFile.exists()) {
        Logger.getLogger().w("No minidump data found for session " + previousSessionId);
        return;
    }
    // Because we don't want to read the minidump to get its timestamp, just use file creation time.
    final long eventTime = minidumpFile.lastModified();
    final LogFileManager previousSessionLogManager = new LogFileManager(fileStore, previousSessionId);
    final File nativeSessionDirectory = fileStore.getNativeSessionDir(previousSessionId);
    if (!nativeSessionDirectory.isDirectory()) {
        Logger.getLogger().w("Couldn't create directory to store native session files, aborting.");
        return;
    }
    doWriteAppExceptionMarker(eventTime);
    List<NativeSessionFile> nativeSessionFiles = getNativeSessionFiles(nativeSessionFileProvider, previousSessionId, fileStore, previousSessionLogManager.getBytesForLog());
    NativeSessionFileGzipper.processNativeSessions(nativeSessionDirectory, nativeSessionFiles);
    Logger.getLogger().d("CrashlyticsController#finalizePreviousNativeSession");
    reportingCoordinator.finalizeSessionWithNativeEvent(previousSessionId, nativeSessionFiles);
    previousSessionLogManager.clearLog();
}
Also used : NativeSessionFileProvider(com.google.firebase.crashlytics.internal.NativeSessionFileProvider) File(java.io.File) LogFileManager(com.google.firebase.crashlytics.internal.metadata.LogFileManager)

Example 5 with LogFileManager

use of com.google.firebase.crashlytics.internal.metadata.LogFileManager in project firebase-android-sdk by firebase.

the class CrashlyticsControllerTest method testFatalEvent_sendsAppExceptionEvent.

public void testFatalEvent_sendsAppExceptionEvent() {
    final String sessionId = "sessionId";
    final LogFileManager logFileManager = new LogFileManager(testFileStore);
    final AnalyticsEventLogger mockFirebaseAnalyticsLogger = mock(AnalyticsEventLogger.class);
    final CrashlyticsController controller = builder().setAnalyticsEventLogger(mockFirebaseAnalyticsLogger).setLogFileManager(logFileManager).build();
    when(mockSessionReportingCoordinator.listSortedOpenSessionIds()).thenReturn(new TreeSet<>(Collections.singleton(sessionId)));
    controller.openSession(SESSION_ID);
    controller.handleUncaughtException(testSettingsProvider, Thread.currentThread(), new RuntimeException("Fatal"));
    controller.finalizeSessions(testSettingsProvider);
    assertFirebaseAnalyticsCrashEvent(mockFirebaseAnalyticsLogger);
}
Also used : Mockito.anyString(org.mockito.Mockito.anyString) LogFileManager(com.google.firebase.crashlytics.internal.metadata.LogFileManager) AnalyticsEventLogger(com.google.firebase.crashlytics.internal.analytics.AnalyticsEventLogger)

Aggregations

LogFileManager (com.google.firebase.crashlytics.internal.metadata.LogFileManager)6 UserMetadata (com.google.firebase.crashlytics.internal.metadata.UserMetadata)3 NativeSessionFileProvider (com.google.firebase.crashlytics.internal.NativeSessionFileProvider)2 MiddleOutFallbackStrategy (com.google.firebase.crashlytics.internal.stacktrace.MiddleOutFallbackStrategy)2 RemoveRepeatsStrategy (com.google.firebase.crashlytics.internal.stacktrace.RemoveRepeatsStrategy)2 StackTraceTrimmingStrategy (com.google.firebase.crashlytics.internal.stacktrace.StackTraceTrimmingStrategy)2 File (java.io.File)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 Mockito.anyString (org.mockito.Mockito.anyString)2 ActivityManager (android.app.ActivityManager)1 ApplicationExitInfo (android.app.ApplicationExitInfo)1 CrashlyticsNativeComponent (com.google.firebase.crashlytics.internal.CrashlyticsNativeComponent)1 AnalyticsEventLogger (com.google.firebase.crashlytics.internal.analytics.AnalyticsEventLogger)1 TreeSet (java.util.TreeSet)1