use of com.google.firebase.crashlytics.internal.settings.Settings in project firebase-android-sdk by firebase.
the class CrashlyticsController method submitAllReports.
Task<Void> submitAllReports(Task<Settings> settingsDataTask) {
if (!reportingCoordinator.hasReportsToSend()) {
// Just notify the user that there are no reports and stop.
Logger.getLogger().v("No crash reports are available to be sent.");
unsentReportsAvailable.trySetResult(false);
return Tasks.forResult(null);
}
Logger.getLogger().v("Crash reports are available to be sent.");
return waitForReportAction().onSuccessTask(new SuccessContinuation<Boolean, Void>() {
@NonNull
@Override
public Task<Void> then(@Nullable Boolean send) throws Exception {
return backgroundWorker.submitTask(new Callable<Task<Void>>() {
@Override
public Task<Void> call() throws Exception {
if (!send) {
Logger.getLogger().v("Deleting cached crash reports...");
deleteFiles(listAppExceptionMarkerFiles());
reportingCoordinator.removeAllReports();
unsentReportsHandled.trySetResult(null);
return Tasks.forResult(null);
}
Logger.getLogger().d("Sending cached crash reports...");
// waitForReportAction guarantees we got user permission.
boolean dataCollectionToken = send;
// Signal to the settings fetch and onboarding that we have explicit
// permission.
dataCollectionArbiter.grantDataCollectionPermission(dataCollectionToken);
Executor executor = backgroundWorker.getExecutor();
return settingsDataTask.onSuccessTask(executor, new SuccessContinuation<Settings, Void>() {
@NonNull
@Override
public Task<Void> then(@Nullable Settings appSettingsData) throws Exception {
if (appSettingsData == null) {
Logger.getLogger().w("Received null app settings at app startup. Cannot send cached reports");
return Tasks.forResult(null);
}
logAnalyticsAppExceptionEvents();
reportingCoordinator.sendReports(executor);
unsentReportsHandled.trySetResult(null);
return Tasks.forResult(null);
}
});
}
});
}
});
}
use of com.google.firebase.crashlytics.internal.settings.Settings in project firebase-android-sdk by firebase.
the class CrashlyticsControllerRobolectricTest method mockSettingsProvider.
private void mockSettingsProvider(boolean collectAnrs) {
Settings settings = new Settings(0, new SessionData(4, 4), new FeatureFlagData(true, collectAnrs), 3, 0, 1.0, 1.0, 1);
when(mockSettingsProvider.getSettingsSync()).thenReturn(settings);
}
use of com.google.firebase.crashlytics.internal.settings.Settings in project firebase-android-sdk by firebase.
the class CrashlyticsCore method doBackgroundInitialization.
/**
* Performs background initialization synchronously on the calling thread.
*/
private Task<Void> doBackgroundInitialization(SettingsProvider settingsProvider) {
// create the marker for this run
markInitializationStarted();
try {
breadcrumbSource.registerBreadcrumbHandler(this::log);
final Settings settingsData = settingsProvider.getSettingsSync();
if (!settingsData.featureFlagData.collectReports) {
Logger.getLogger().d("Collection of crash reports disabled in Crashlytics settings.");
// handle this case.
return Tasks.forException(new RuntimeException("Collection of crash reports disabled in Crashlytics settings."));
}
if (!controller.finalizeSessions(settingsProvider)) {
Logger.getLogger().w("Previous sessions could not be finalized.");
}
// handle that as a separate call.
return controller.submitAllReports(settingsProvider.getSettingsAsync());
} catch (Exception e) {
Logger.getLogger().e("Crashlytics encountered a problem during asynchronous initialization.", e);
return Tasks.forException(e);
} finally {
// The only thing that compels us to leave the marker and start synchronously next time
// is not executing all the way through this method. That would indicate that we perhaps
// didn't get our settings and have a chance to send reports. This situation is usually
// caused by the Main thread crashing shortly after the synchronous portion of our
// start-up completes.
//
// Internal exceptions on start-up or other problems aren't likely to be fixed by
// starting synchronously next time, so don't bother slowing down the host app for that.
markInitializationComplete();
}
}
use of com.google.firebase.crashlytics.internal.settings.Settings in project firebase-android-sdk by firebase.
the class CrashlyticsReportPersistenceTest method testFinalizeReports_whenSettingsChanges_capsReports.
public void testFinalizeReports_whenSettingsChanges_capsReports() throws IOException {
SettingsProvider settingsProvider = mock(SettingsProvider.class);
Settings.SessionData sessionData1 = new Settings.SessionData(VERY_LARGE_UPPER_LIMIT, 4);
Settings.SessionData sessionData2 = new Settings.SessionData(VERY_LARGE_UPPER_LIMIT, 8);
Settings settings1 = new Settings(0, sessionData1, new FeatureFlagData(true, true), 3, 0, 1.0, 1.0, 1);
Settings settings2 = new Settings(0, sessionData2, new FeatureFlagData(true, true), 3, 0, 1.0, 1.0, 1);
when(settingsProvider.getSettingsSync()).thenReturn(settings1);
reportPersistence = new CrashlyticsReportPersistence(fileStore, settingsProvider);
DecimalFormat format = new DecimalFormat("00");
for (int i = 0; i < 16; i++) {
persistReportWithEvent(reportPersistence, "testSession" + format.format(i), true);
}
reportPersistence.finalizeReports("skippedSession", 0L);
List<CrashlyticsReportWithSessionId> finalizedReports = reportPersistence.loadFinalizedReports();
assertEquals(4, finalizedReports.size());
when(settingsProvider.getSettingsSync()).thenReturn(settings2);
for (int i = 16; i < 32; i++) {
persistReportWithEvent(reportPersistence, "testSession" + i, true);
}
reportPersistence.finalizeReports("skippedSession", 0L);
finalizedReports = reportPersistence.loadFinalizedReports();
assertEquals(8, finalizedReports.size());
}
use of com.google.firebase.crashlytics.internal.settings.Settings in project firebase-android-sdk by firebase.
the class CrashlyticsReportPersistenceTest method createSettingsProviderMock.
private static SettingsProvider createSettingsProviderMock(int maxCompleteSessionsCount, int maxCustomExceptionEvents) {
SettingsProvider settingsProvider = mock(SettingsProvider.class);
Settings.SessionData sessionData = new Settings.SessionData(maxCustomExceptionEvents, maxCompleteSessionsCount);
Settings settings = new Settings(0, sessionData, new FeatureFlagData(true, false), 3, 0, 1.0, 1.0, 1);
when(settingsProvider.getSettingsSync()).thenReturn(settings);
return settingsProvider;
}
Aggregations