Search in sources :

Example 1 with AppSettingsData

use of com.google.firebase.crashlytics.internal.settings.model.AppSettingsData in project GreenHouse by utsanjan.

the class CrashlyticsController method defaultReportUploader.

private ReportUploader.Provider defaultReportUploader() {
    return new // from class: com.google.firebase.crashlytics.internal.common.CrashlyticsController.9
    ReportUploader.Provider() {

        // com.google.firebase.crashlytics.internal.report.ReportUploader.Provider
        @Override
        public ReportUploader createReportUploader(AppSettingsData appSettingsData) {
            String reportsUrl = appSettingsData.reportsUrl;
            String ndkReportsUrl = appSettingsData.ndkReportsUrl;
            String organizationId = appSettingsData.organizationId;
            CreateReportSpiCall call = CrashlyticsController.this.getCreateReportSpiCall(reportsUrl, ndkReportsUrl);
            return new ReportUploader(organizationId, CrashlyticsController.this.appData.googleAppId, DataTransportState.getState(appSettingsData), CrashlyticsController.this.reportManager, call, CrashlyticsController.this.handlingExceptionCheck);
        }
    };
}
Also used : AppSettingsData(com.google.firebase.crashlytics.internal.settings.model.AppSettingsData) ReportUploader(com.google.firebase.crashlytics.internal.report.ReportUploader) CompositeCreateReportSpiCall(com.google.firebase.crashlytics.internal.report.network.CompositeCreateReportSpiCall) DefaultCreateReportSpiCall(com.google.firebase.crashlytics.internal.report.network.DefaultCreateReportSpiCall) NativeCreateReportSpiCall(com.google.firebase.crashlytics.internal.report.network.NativeCreateReportSpiCall) CreateReportSpiCall(com.google.firebase.crashlytics.internal.report.network.CreateReportSpiCall) SettingsDataProvider(com.google.firebase.crashlytics.internal.settings.SettingsDataProvider) NativeSessionFileProvider(com.google.firebase.crashlytics.internal.NativeSessionFileProvider) UnityVersionProvider(com.google.firebase.crashlytics.internal.unity.UnityVersionProvider)

Example 2 with AppSettingsData

use of com.google.firebase.crashlytics.internal.settings.model.AppSettingsData in project GreenHouse by utsanjan.

the class CrashlyticsController method handleUncaughtException.

synchronized void handleUncaughtException(final SettingsDataProvider settingsDataProvider, final Thread thread, final Throwable ex) {
    Logger logger = Logger.getLogger();
    logger.d("Crashlytics is handling uncaught exception \"" + ex + "\" from thread " + thread.getName());
    final Date time = new Date();
    final Task<Void> recordFatalFirebaseEventTask = recordFatalFirebaseEvent(time.getTime());
    Task<Void> handleUncaughtExceptionTask = this.backgroundWorker.submitTask(new // from class: com.google.firebase.crashlytics.internal.common.CrashlyticsController.6
    Callable<Task<Void>>() {

        /* JADX WARN: Can't rename method to resolve collision */
        // java.util.concurrent.Callable
        @Override
        public Task<Void> call() throws Exception {
            CrashlyticsController.this.crashMarker.create();
            long timestampSeconds = CrashlyticsController.getTimestampSeconds(time);
            CrashlyticsController.this.reportingCoordinator.persistFatalEvent(ex, thread, timestampSeconds);
            CrashlyticsController.this.writeFatal(thread, ex, timestampSeconds);
            Settings settings = settingsDataProvider.getSettings();
            int maxCustomExceptionEvents = settings.getSessionData().maxCustomExceptionEvents;
            int maxCompleteSessionsCount = settings.getSessionData().maxCompleteSessionsCount;
            CrashlyticsController.this.doCloseSessions(maxCustomExceptionEvents);
            CrashlyticsController.this.doOpenSession();
            CrashlyticsController.this.trimSessionFiles(maxCompleteSessionsCount);
            if (!CrashlyticsController.this.dataCollectionArbiter.isAutomaticDataCollectionEnabled()) {
                return Tasks.forResult(null);
            }
            final Executor executor = CrashlyticsController.this.backgroundWorker.getExecutor();
            return settingsDataProvider.getAppSettings().onSuccessTask(executor, new // from class: com.google.firebase.crashlytics.internal.common.CrashlyticsController.6.1
            SuccessContinuation<AppSettingsData, Void>() {

                public Task<Void> then(AppSettingsData appSettingsData) throws Exception {
                    if (appSettingsData == null) {
                        Logger.getLogger().w("Received null app settings, cannot send reports at crash time.");
                        return Tasks.forResult(null);
                    }
                    CrashlyticsController.this.sendSessionReports(appSettingsData, true);
                    return Tasks.whenAll(CrashlyticsController.this.reportingCoordinator.sendReports(executor, DataTransportState.getState(appSettingsData)), recordFatalFirebaseEventTask);
                }
            });
        }
    });
    try {
        Utils.awaitEvenIfOnMainThread(handleUncaughtExceptionTask);
    } catch (Exception e) {
    }
}
Also used : AppSettingsData(com.google.firebase.crashlytics.internal.settings.model.AppSettingsData) Task(com.google.android.gms.tasks.Task) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Executor(java.util.concurrent.Executor) Logger(com.google.firebase.crashlytics.internal.Logger) SuccessContinuation(com.google.android.gms.tasks.SuccessContinuation) Date(java.util.Date) IOException(java.io.IOException) Settings(com.google.firebase.crashlytics.internal.settings.model.Settings)

Example 3 with AppSettingsData

use of com.google.firebase.crashlytics.internal.settings.model.AppSettingsData in project firebase-android-sdk by firebase.

the class CrashlyticsController method submitAllReports.

Task<Void> submitAllReports(Task<AppSettingsData> appSettingsDataTask) {
    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 appSettingsDataTask.onSuccessTask(executor, new SuccessContinuation<AppSettingsData, Void>() {

                        @NonNull
                        @Override
                        public Task<Void> then(@Nullable AppSettingsData 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 : AppSettingsData(com.google.firebase.crashlytics.internal.settings.model.AppSettingsData) 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) IOException(java.io.IOException) Callable(java.util.concurrent.Callable)

Example 4 with AppSettingsData

use of com.google.firebase.crashlytics.internal.settings.model.AppSettingsData in project firebase-android-sdk by firebase.

the class DefaultSettingsJsonTransform method defaultSettings.

/**
 * Creates a new Settings with reasonable default values.
 */
static Settings defaultSettings(CurrentTimeProvider currentTimeProvider) {
    final int settingsVersion = SettingsJsonConstants.SETTINGS_VERSION_DEFAULT;
    final int cacheDuration = SettingsJsonConstants.SETTINGS_CACHE_DURATION_DEFAULT;
    JSONObject empty = new JSONObject();
    final AppSettingsData appData = null;
    final SessionSettingsData settingsData = buildSessionDataFrom(empty);
    final FeaturesSettingsData featureData = buildFeaturesSessionDataFrom(empty);
    final long expiresAtMillis = getExpiresAtFrom(currentTimeProvider, cacheDuration, empty);
    return new SettingsData(expiresAtMillis, appData, settingsData, featureData, settingsVersion, cacheDuration);
}
Also used : AppSettingsData(com.google.firebase.crashlytics.internal.settings.model.AppSettingsData) AppSettingsData(com.google.firebase.crashlytics.internal.settings.model.AppSettingsData) SessionSettingsData(com.google.firebase.crashlytics.internal.settings.model.SessionSettingsData) FeaturesSettingsData(com.google.firebase.crashlytics.internal.settings.model.FeaturesSettingsData) SettingsData(com.google.firebase.crashlytics.internal.settings.model.SettingsData) JSONObject(org.json.JSONObject) SessionSettingsData(com.google.firebase.crashlytics.internal.settings.model.SessionSettingsData) FeaturesSettingsData(com.google.firebase.crashlytics.internal.settings.model.FeaturesSettingsData)

Example 5 with AppSettingsData

use of com.google.firebase.crashlytics.internal.settings.model.AppSettingsData in project firebase-android-sdk by firebase.

the class SettingsController method loadSettingsData.

/**
 * Kicks off loading settings either from the cache or the network.
 *
 * @return a task that is resolved when loading is completely finished.
 */
public Task<Void> loadSettingsData(SettingsCacheBehavior cacheBehavior, Executor executor) {
    // backend will know about it.
    if (!buildInstanceIdentifierChanged()) {
        final SettingsData cachedSettings = getCachedSettingsData(cacheBehavior);
        if (cachedSettings != null) {
            settings.set(cachedSettings);
            appSettingsData.get().trySetResult(cachedSettings.getAppSettingsData());
            return Tasks.forResult(null);
        }
    }
    // SKIP_CACHE doesn't actually skip the cache completely; it just skips the first lookup, since
    // we are doing the cache lookup again here with IGNORE_CACHE_EXPIRATION.
    // This has been true in production for some time, though, so no rush to "fix" it.
    // The cached settings are too old, so if there are expired settings, use those for now.
    final SettingsData expiredSettings = getCachedSettingsData(SettingsCacheBehavior.IGNORE_CACHE_EXPIRATION);
    if (expiredSettings != null) {
        settings.set(expiredSettings);
        appSettingsData.get().trySetResult(expiredSettings.getAppSettingsData());
    }
    // Kick off fetching fresh settings.
    return dataCollectionArbiter.waitForDataCollectionPermission(executor).onSuccessTask(executor, new SuccessContinuation<Void, Void>() {

        @NonNull
        @Override
        public Task<Void> then(@Nullable Void aVoid) throws Exception {
            // Waited for data collection permission, so this is safe.
            final boolean dataCollectionToken = true;
            final JSONObject settingsJson = settingsSpiCall.invoke(settingsRequest, dataCollectionToken);
            if (settingsJson != null) {
                final SettingsData fetchedSettings = settingsJsonParser.parseSettingsJson(settingsJson);
                cachedSettingsIo.writeCachedSettings(fetchedSettings.getExpiresAtMillis(), settingsJson);
                logSettings(settingsJson, "Loaded settings: ");
                setStoredBuildInstanceIdentifier(settingsRequest.instanceId);
                // Update the regular settings.
                settings.set(fetchedSettings);
                // Signal the app settings on any Tasks that already exist, and then replace the
                // task so
                // that any new callers get the new app settings instead of any old ones.
                appSettingsData.get().trySetResult(fetchedSettings.getAppSettingsData());
                TaskCompletionSource<AppSettingsData> fetchedAppSettings = new TaskCompletionSource<>();
                fetchedAppSettings.trySetResult(fetchedSettings.getAppSettingsData());
                appSettingsData.set(fetchedAppSettings);
            }
            return Tasks.forResult(null);
        }
    });
}
Also used : AppSettingsData(com.google.firebase.crashlytics.internal.settings.model.AppSettingsData) SettingsData(com.google.firebase.crashlytics.internal.settings.model.SettingsData) TaskCompletionSource(com.google.android.gms.tasks.TaskCompletionSource) Task(com.google.android.gms.tasks.Task) JSONObject(org.json.JSONObject) NonNull(androidx.annotation.NonNull) JSONException(org.json.JSONException)

Aggregations

AppSettingsData (com.google.firebase.crashlytics.internal.settings.model.AppSettingsData)10 SettingsData (com.google.firebase.crashlytics.internal.settings.model.SettingsData)7 FeaturesSettingsData (com.google.firebase.crashlytics.internal.settings.model.FeaturesSettingsData)5 SessionSettingsData (com.google.firebase.crashlytics.internal.settings.model.SessionSettingsData)5 Task (com.google.android.gms.tasks.Task)4 JSONObject (org.json.JSONObject)3 NonNull (androidx.annotation.NonNull)2 TaskCompletionSource (com.google.android.gms.tasks.TaskCompletionSource)2 IOException (java.io.IOException)2 Executor (java.util.concurrent.Executor)2 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 JSONException (org.json.JSONException)2 SuccessContinuation (com.google.android.gms.tasks.SuccessContinuation)1 Logger (com.google.firebase.crashlytics.internal.Logger)1 NativeSessionFileProvider (com.google.firebase.crashlytics.internal.NativeSessionFileProvider)1 ReportUploader (com.google.firebase.crashlytics.internal.report.ReportUploader)1 CompositeCreateReportSpiCall (com.google.firebase.crashlytics.internal.report.network.CompositeCreateReportSpiCall)1 CreateReportSpiCall (com.google.firebase.crashlytics.internal.report.network.CreateReportSpiCall)1 DefaultCreateReportSpiCall (com.google.firebase.crashlytics.internal.report.network.DefaultCreateReportSpiCall)1