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;
}
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);
}
}
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;
}
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();
}
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);
}
Aggregations