Search in sources :

Example 6 with SettingsData

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

the class DefaultSettingsJsonTransformTest method testCachedJsonTransform.

public void testCachedJsonTransform() throws Exception {
    final JSONObject testJson = getTestJSON("cached_settings.json");
    final SettingsData settingsData = transform.buildFromJson(mockCurrentTimeProvider, testJson);
    assertEquals(1234567890, settingsData.expiresAtMillis);
    assertEquals(3600, settingsData.cacheDuration);
    assertAppData(settingsData.appData);
    assertSettingsData(settingsData.sessionData);
    assertFeaturesData(settingsData.featuresData);
    verifyZeroInteractions(mockCurrentTimeProvider);
}
Also used : SessionSettingsData(com.google.firebase.crashlytics.internal.settings.model.SessionSettingsData) AppSettingsData(com.google.firebase.crashlytics.internal.settings.model.AppSettingsData) FeaturesSettingsData(com.google.firebase.crashlytics.internal.settings.model.FeaturesSettingsData) SettingsData(com.google.firebase.crashlytics.internal.settings.model.SettingsData) JSONObject(org.json.JSONObject)

Example 7 with SettingsData

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

the class SettingsV3JsonTransformTest method testToJsonAndBackSurvival.

public void testToJsonAndBackSurvival() throws IOException, JSONException {
    final JSONObject testJson = getTestJSON("firebase_settings.json");
    final SettingsData settingsData = transform.buildFromJson(mockCurrentTimeProvider, testJson);
    final SettingsData roundtrippedSettingsData = transform.buildFromJson(mockCurrentTimeProvider, transform.toJson(settingsData));
    verifySettingsDataObject(mockCurrentTimeProvider, roundtrippedSettingsData);
}
Also used : SessionSettingsData(com.google.firebase.crashlytics.internal.settings.model.SessionSettingsData) AppSettingsData(com.google.firebase.crashlytics.internal.settings.model.AppSettingsData) FeaturesSettingsData(com.google.firebase.crashlytics.internal.settings.model.FeaturesSettingsData) SettingsData(com.google.firebase.crashlytics.internal.settings.model.SettingsData) JSONObject(org.json.JSONObject)

Example 8 with SettingsData

use of com.google.firebase.crashlytics.internal.settings.model.SettingsData 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 9 with SettingsData

use of com.google.firebase.crashlytics.internal.settings.model.SettingsData 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)

Example 10 with SettingsData

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

the class SettingsV3JsonTransform method buildFromJson.

@Override
public SettingsData buildFromJson(CurrentTimeProvider currentTimeProvider, JSONObject json) throws JSONException {
    final int settingsVersion = json.optInt(SettingsJsonConstants.SETTINGS_VERSION, SettingsJsonConstants.SETTINGS_VERSION_DEFAULT);
    final int cacheDuration = json.optInt(SettingsJsonConstants.CACHE_DURATION_KEY, SettingsJsonConstants.SETTINGS_CACHE_DURATION_DEFAULT);
    final AppSettingsData appData = buildAppDataFrom(json.getJSONObject(SettingsJsonConstants.FABRIC_KEY), json.getJSONObject(SettingsJsonConstants.APP_KEY));
    final SessionSettingsData sessionData = defaultSessionData();
    final FeaturesSettingsData featureData = buildFeaturesSessionDataFrom(json.getJSONObject(SettingsJsonConstants.FEATURES_KEY));
    final long expiresAtMillis = getExpiresAtFrom(currentTimeProvider, cacheDuration, json);
    return new SettingsData(expiresAtMillis, appData, sessionData, 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) SessionSettingsData(com.google.firebase.crashlytics.internal.settings.model.SessionSettingsData) FeaturesSettingsData(com.google.firebase.crashlytics.internal.settings.model.FeaturesSettingsData)

Aggregations

SettingsData (com.google.firebase.crashlytics.internal.settings.model.SettingsData)19 AppSettingsData (com.google.firebase.crashlytics.internal.settings.model.AppSettingsData)18 FeaturesSettingsData (com.google.firebase.crashlytics.internal.settings.model.FeaturesSettingsData)15 SessionSettingsData (com.google.firebase.crashlytics.internal.settings.model.SessionSettingsData)15 JSONObject (org.json.JSONObject)15 JSONException (org.json.JSONException)3 Task (com.google.android.gms.tasks.Task)2 TaskCompletionSource (com.google.android.gms.tasks.TaskCompletionSource)2 NonNull (androidx.annotation.NonNull)1