Search in sources :

Example 1 with SettingsRequest

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

the class DefaultSettingsSpiCallTest method testWebCall.

public void testWebCall() throws Exception {
    final String instanceId = CommonUtils.createInstanceIdFrom("fake_build_id");
    final SettingsRequest requestData = buildSettingsRequest(instanceId);
    final String url = "http://localhost:3000/spi/v1/platforms/android/apps/com.crashlytics.test/settings";
    final InspectableHttpGetRequest request = new InspectableHttpGetRequest();
    final DefaultSettingsSpiCall call = new DefaultSettingsSpiCall(url, new HttpRequestFactory() {

        @Override
        public HttpGetRequest buildHttpGetRequest(String url, Map<String, String> queryParams) {
            request.setUrl(url);
            request.setQueryParams(queryParams);
            return request;
        }
    });
    assertNotNull(call.invoke(requestData, true));
    assertEquals(url, request.getUrl());
    final Map<?, ?> queryParams = request.getQueryParams();
    assertEquals(BUILD_VERSION, queryParams.get(DefaultSettingsSpiCall.BUILD_VERSION_PARAM));
    assertEquals(DISPLAY_VERSION, queryParams.get(DefaultSettingsSpiCall.DISPLAY_VERSION_PARAM));
    assertEquals(instanceId, queryParams.get(DefaultSettingsSpiCall.INSTANCE_PARAM));
    assertEquals(Integer.toString(SOURCE), queryParams.get(DefaultSettingsSpiCall.SOURCE_PARAM));
    final Map<String, String> headers = request.getHeaders();
    assertEquals(GOOGLE_APP_ID, headers.get(DefaultSettingsSpiCall.HEADER_GOOGLE_APP_ID));
    assertEquals(DefaultSettingsSpiCall.ANDROID_CLIENT_TYPE, headers.get(DefaultSettingsSpiCall.HEADER_CLIENT_TYPE));
    assertEquals(DEVICE_MODEL, headers.get(DefaultSettingsSpiCall.HEADER_DEVICE_MODEL));
    assertEquals(OS_BUILD_VERSION, headers.get(DefaultSettingsSpiCall.HEADER_OS_BUILD_VERSION));
    assertEquals(OS_DISPLAY_VERSION, headers.get(DefaultSettingsSpiCall.HEADER_OS_DISPLAY_VERSION));
    assertEquals(INSTALLATION_ID, headers.get(DefaultSettingsSpiCall.HEADER_INSTALLATION_ID));
    assertEquals(DefaultSettingsSpiCall.ACCEPT_JSON_VALUE, headers.get(DefaultSettingsSpiCall.HEADER_ACCEPT));
}
Also used : HttpRequestFactory(com.google.firebase.crashlytics.internal.network.HttpRequestFactory) SettingsRequest(com.google.firebase.crashlytics.internal.settings.model.SettingsRequest) InspectableHttpGetRequest(com.google.firebase.crashlytics.internal.network.InspectableHttpGetRequest) HttpGetRequest(com.google.firebase.crashlytics.internal.network.HttpGetRequest) InspectableHttpGetRequest(com.google.firebase.crashlytics.internal.network.InspectableHttpGetRequest)

Example 2 with SettingsRequest

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

the class SettingsController method create.

public static SettingsController create(Context context, String googleAppId, IdManager idManager, HttpRequestFactory httpRequestFactory, String versionCode, String versionName, String urlEndpoint, DataCollectionArbiter dataCollectionArbiter) {
    String installerPackageName = idManager.getInstallerPackageName();
    CurrentTimeProvider currentTimeProvider = new SystemCurrentTimeProvider();
    SettingsJsonParser settingsJsonParser = new SettingsJsonParser(currentTimeProvider);
    CachedSettingsIo cachedSettingsIo = new CachedSettingsIo(context);
    String settingsUrl = String.format(Locale.US, SETTINGS_URL_FORMAT, googleAppId);
    SettingsSpiCall settingsSpiCall = new DefaultSettingsSpiCall(urlEndpoint, settingsUrl, httpRequestFactory);
    String deviceModel = idManager.getModelName();
    String osBuildVersion = idManager.getOsBuildVersionString();
    String osDisplayVersion = idManager.getOsDisplayVersionString();
    String instanceId = CommonUtils.createInstanceIdFrom(CommonUtils.getMappingFileId(context), googleAppId, versionName, versionCode);
    int deliveryMechanismId = DeliveryMechanism.determineFrom(installerPackageName).getId();
    SettingsRequest settingsRequest = new SettingsRequest(googleAppId, deviceModel, osBuildVersion, osDisplayVersion, idManager, instanceId, versionName, versionCode, deliveryMechanismId);
    return new SettingsController(context, settingsRequest, currentTimeProvider, settingsJsonParser, cachedSettingsIo, settingsSpiCall, dataCollectionArbiter);
}
Also used : SystemCurrentTimeProvider(com.google.firebase.crashlytics.internal.common.SystemCurrentTimeProvider) CurrentTimeProvider(com.google.firebase.crashlytics.internal.common.CurrentTimeProvider) SystemCurrentTimeProvider(com.google.firebase.crashlytics.internal.common.SystemCurrentTimeProvider) DefaultSettingsSpiCall(com.google.firebase.crashlytics.internal.settings.network.DefaultSettingsSpiCall) SettingsRequest(com.google.firebase.crashlytics.internal.settings.model.SettingsRequest) SettingsSpiCall(com.google.firebase.crashlytics.internal.settings.network.SettingsSpiCall) DefaultSettingsSpiCall(com.google.firebase.crashlytics.internal.settings.network.DefaultSettingsSpiCall)

Example 3 with SettingsRequest

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

the class DefaultSettingsControllerTest method testNoAvailableSettingsLoad.

public void testNoAvailableSettingsLoad() throws Exception {
    when(mockSettingsSpiCall.invoke(any(SettingsRequest.class), eq(true))).thenReturn(null);
    when(mockCachedSettingsIo.readCachedSettings()).thenReturn(null);
    TaskCompletionSource<Void> dataCollectionPermission = new TaskCompletionSource<>();
    when(mockDataCollectionArbiter.waitForDataCollectionPermission(any(Executor.class))).thenReturn(dataCollectionPermission.getTask());
    final SettingsRequest requestData = buildSettingsRequest();
    final SettingsController controller = newSettingsController(requestData, mockCurrentTimeProvider, mockSettingsJsonParser, mockCachedSettingsIo, mockSettingsSpiCall, mockDataCollectionArbiter, false);
    Task<Void> loadFinished = controller.loadSettingsData(networkExecutor);
    assertNotNull(controller.getSettings());
    assertFalse(controller.getAppSettings().isComplete());
    dataCollectionPermission.trySetResult(null);
    await(loadFinished);
    assertNotNull(controller.getSettings());
    assertFalse(controller.getAppSettings().isComplete());
    verify(mockSettingsSpiCall).invoke(any(SettingsRequest.class), eq(true));
    verify(mockCachedSettingsIo, times(2)).readCachedSettings();
    verifyZeroInteractions(mockSettingsJsonParser);
    verify(mockCurrentTimeProvider).getCurrentTimeMillis();
}
Also used : TaskCompletionSource(com.google.android.gms.tasks.TaskCompletionSource) Executor(java.util.concurrent.Executor) SettingsRequest(com.google.firebase.crashlytics.internal.settings.model.SettingsRequest)

Example 4 with SettingsRequest

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

the class DefaultSettingsSpiCallTest method testWebCallNoInstanceId.

public void testWebCallNoInstanceId() throws Exception {
    final SettingsRequest requestData = buildSettingsRequest(null);
    final String url = "http://localhost:3000/spi/v1/platforms/android/apps/com.crashlytics.test/settings";
    final InspectableHttpGetRequest request = new InspectableHttpGetRequest();
    final DefaultSettingsSpiCall call = new DefaultSettingsSpiCall(url, new HttpRequestFactory() {

        @Override
        public HttpGetRequest buildHttpGetRequest(String url, Map<String, String> queryParams) {
            request.setUrl(url);
            request.setQueryParams(queryParams);
            return request;
        }
    });
    assertNotNull(call.invoke(requestData, true));
    assertEquals(url, request.getUrl());
    final Map<?, ?> queryParams = request.getQueryParams();
    assertEquals(BUILD_VERSION, queryParams.get(DefaultSettingsSpiCall.BUILD_VERSION_PARAM));
    assertEquals(DISPLAY_VERSION, queryParams.get(DefaultSettingsSpiCall.DISPLAY_VERSION_PARAM));
    assertFalse(queryParams.containsKey(DefaultSettingsSpiCall.INSTANCE_PARAM));
    assertEquals(Integer.toString(SOURCE), queryParams.get(DefaultSettingsSpiCall.SOURCE_PARAM));
    final Map<String, String> headers = request.getHeaders();
    assertEquals(GOOGLE_APP_ID, headers.get(DefaultSettingsSpiCall.HEADER_GOOGLE_APP_ID));
    assertEquals(DefaultSettingsSpiCall.ANDROID_CLIENT_TYPE, headers.get(DefaultSettingsSpiCall.HEADER_CLIENT_TYPE));
    assertEquals(DEVICE_MODEL, headers.get(DefaultSettingsSpiCall.HEADER_DEVICE_MODEL));
    assertEquals(OS_BUILD_VERSION, headers.get(DefaultSettingsSpiCall.HEADER_OS_BUILD_VERSION));
    assertEquals(OS_DISPLAY_VERSION, headers.get(DefaultSettingsSpiCall.HEADER_OS_DISPLAY_VERSION));
    assertEquals(INSTALLATION_ID, headers.get(DefaultSettingsSpiCall.HEADER_INSTALLATION_ID));
    assertEquals(DefaultSettingsSpiCall.ACCEPT_JSON_VALUE, headers.get(DefaultSettingsSpiCall.HEADER_ACCEPT));
}
Also used : HttpRequestFactory(com.google.firebase.crashlytics.internal.network.HttpRequestFactory) SettingsRequest(com.google.firebase.crashlytics.internal.settings.model.SettingsRequest) InspectableHttpGetRequest(com.google.firebase.crashlytics.internal.network.InspectableHttpGetRequest) HttpGetRequest(com.google.firebase.crashlytics.internal.network.HttpGetRequest) InspectableHttpGetRequest(com.google.firebase.crashlytics.internal.network.InspectableHttpGetRequest)

Aggregations

SettingsRequest (com.google.firebase.crashlytics.internal.settings.model.SettingsRequest)4 HttpGetRequest (com.google.firebase.crashlytics.internal.network.HttpGetRequest)2 HttpRequestFactory (com.google.firebase.crashlytics.internal.network.HttpRequestFactory)2 InspectableHttpGetRequest (com.google.firebase.crashlytics.internal.network.InspectableHttpGetRequest)2 TaskCompletionSource (com.google.android.gms.tasks.TaskCompletionSource)1 CurrentTimeProvider (com.google.firebase.crashlytics.internal.common.CurrentTimeProvider)1 SystemCurrentTimeProvider (com.google.firebase.crashlytics.internal.common.SystemCurrentTimeProvider)1 DefaultSettingsSpiCall (com.google.firebase.crashlytics.internal.settings.network.DefaultSettingsSpiCall)1 SettingsSpiCall (com.google.firebase.crashlytics.internal.settings.network.SettingsSpiCall)1 Executor (java.util.concurrent.Executor)1