Search in sources :

Example 1 with Settings

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);
                        }
                    });
                }
            });
        }
    });
}
Also used : Task(com.google.android.gms.tasks.Task) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Executor(java.util.concurrent.Executor) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) NonNull(androidx.annotation.NonNull) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) Settings(com.google.firebase.crashlytics.internal.settings.Settings)

Example 2 with Settings

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);
}
Also used : SessionData(com.google.firebase.crashlytics.internal.settings.Settings.SessionData) Settings(com.google.firebase.crashlytics.internal.settings.Settings) FeatureFlagData(com.google.firebase.crashlytics.internal.settings.Settings.FeatureFlagData)

Example 3 with 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();
    }
}
Also used : Settings(com.google.firebase.crashlytics.internal.settings.Settings) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with Settings

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());
}
Also used : SettingsProvider(com.google.firebase.crashlytics.internal.settings.SettingsProvider) DecimalFormat(java.text.DecimalFormat) CrashlyticsReportWithSessionId(com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId) Settings(com.google.firebase.crashlytics.internal.settings.Settings) FeatureFlagData(com.google.firebase.crashlytics.internal.settings.Settings.FeatureFlagData)

Example 5 with Settings

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;
}
Also used : SettingsProvider(com.google.firebase.crashlytics.internal.settings.SettingsProvider) Settings(com.google.firebase.crashlytics.internal.settings.Settings) FeatureFlagData(com.google.firebase.crashlytics.internal.settings.Settings.FeatureFlagData)

Aggregations

Settings (com.google.firebase.crashlytics.internal.settings.Settings)9 FeatureFlagData (com.google.firebase.crashlytics.internal.settings.Settings.FeatureFlagData)4 SettingsProvider (com.google.firebase.crashlytics.internal.settings.SettingsProvider)4 TestSettings (com.google.firebase.crashlytics.internal.settings.TestSettings)3 NonNull (androidx.annotation.NonNull)2 Task (com.google.android.gms.tasks.Task)2 CrashlyticsReportWithSessionId (com.google.firebase.crashlytics.internal.common.CrashlyticsReportWithSessionId)2 FileStore (com.google.firebase.crashlytics.internal.persistence.FileStore)2 SettingsController (com.google.firebase.crashlytics.internal.settings.SettingsController)2 TimeoutException (java.util.concurrent.TimeoutException)2 Resources (android.content.res.Resources)1 FirebaseOptions (com.google.firebase.FirebaseOptions)1 DevelopmentPlatformProvider (com.google.firebase.crashlytics.internal.DevelopmentPlatformProvider)1 CrashlyticsReport (com.google.firebase.crashlytics.internal.model.CrashlyticsReport)1 Session (com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session)1 Event (com.google.firebase.crashlytics.internal.model.CrashlyticsReport.Session.Event)1 SessionData (com.google.firebase.crashlytics.internal.settings.Settings.SessionData)1 FirebaseInstallationsApi (com.google.firebase.installations.FirebaseInstallationsApi)1 IOException (java.io.IOException)1 DecimalFormat (java.text.DecimalFormat)1