Search in sources :

Example 1 with HttpRequestFactory

use of com.google.firebase.crashlytics.internal.network.HttpRequestFactory 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 HttpRequestFactory

use of com.google.firebase.crashlytics.internal.network.HttpRequestFactory 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) 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 3 with HttpRequestFactory

use of com.google.firebase.crashlytics.internal.network.HttpRequestFactory in project firebase-android-sdk by firebase.

the class FirebaseCrashlytics method init.

@Nullable
static FirebaseCrashlytics init(@NonNull FirebaseApp app, @NonNull FirebaseInstallationsApi firebaseInstallationsApi, @NonNull Deferred<CrashlyticsNativeComponent> nativeComponent, @NonNull Deferred<AnalyticsConnector> analyticsConnector) {
    Context context = app.getApplicationContext();
    final String appIdentifier = context.getPackageName();
    Logger.getLogger().i("Initializing Firebase Crashlytics " + CrashlyticsCore.getVersion() + " for " + appIdentifier);
    FileStore fileStore = new FileStore(context);
    final DataCollectionArbiter arbiter = new DataCollectionArbiter(app);
    final IdManager idManager = new IdManager(context, appIdentifier, firebaseInstallationsApi, arbiter);
    final CrashlyticsNativeComponentDeferredProxy deferredNativeComponent = new CrashlyticsNativeComponentDeferredProxy(nativeComponent);
    // Integration with Firebase Analytics
    final AnalyticsDeferredProxy analyticsDeferredProxy = new AnalyticsDeferredProxy(analyticsConnector);
    final ExecutorService crashHandlerExecutor = ExecutorUtils.buildSingleThreadExecutorService("Crashlytics Exception Handler");
    final CrashlyticsCore core = new CrashlyticsCore(app, idManager, deferredNativeComponent, arbiter, analyticsDeferredProxy.getDeferredBreadcrumbSource(), analyticsDeferredProxy.getAnalyticsEventLogger(), fileStore, crashHandlerExecutor);
    final String googleAppId = app.getOptions().getApplicationId();
    final String mappingFileId = CommonUtils.getMappingFileId(context);
    Logger.getLogger().d("Mapping file ID is: " + mappingFileId);
    final DevelopmentPlatformProvider developmentPlatformProvider = new DevelopmentPlatformProvider(context);
    AppData appData;
    try {
        appData = AppData.create(context, idManager, googleAppId, mappingFileId, developmentPlatformProvider);
    } catch (PackageManager.NameNotFoundException e) {
        Logger.getLogger().e("Error retrieving app package info.", e);
        return null;
    }
    Logger.getLogger().v("Installer package name is: " + appData.installerPackageName);
    final ExecutorService threadPoolExecutor = ExecutorUtils.buildSingleThreadExecutorService("com.google.firebase.crashlytics.startup");
    final SettingsController settingsController = SettingsController.create(context, googleAppId, idManager, new HttpRequestFactory(), appData.versionCode, appData.versionName, fileStore, arbiter);
    // Kick off actually fetching the settings.
    settingsController.loadSettingsData(threadPoolExecutor).continueWith(threadPoolExecutor, new Continuation<Void, Object>() {

        @Override
        public Object then(@NonNull Task<Void> task) throws Exception {
            if (!task.isSuccessful()) {
                Logger.getLogger().e("Error fetching settings.", task.getException());
            }
            return null;
        }
    });
    final boolean finishCoreInBackground = core.onPreExecute(appData, settingsController);
    Tasks.call(threadPoolExecutor, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            if (finishCoreInBackground) {
                core.doBackgroundInitializationAsync(settingsController);
            }
            return null;
        }
    });
    return new FirebaseCrashlytics(core);
}
Also used : Context(android.content.Context) CrashlyticsCore(com.google.firebase.crashlytics.internal.common.CrashlyticsCore) HttpRequestFactory(com.google.firebase.crashlytics.internal.network.HttpRequestFactory) DevelopmentPlatformProvider(com.google.firebase.crashlytics.internal.DevelopmentPlatformProvider) IdManager(com.google.firebase.crashlytics.internal.common.IdManager) DataCollectionArbiter(com.google.firebase.crashlytics.internal.common.DataCollectionArbiter) FileStore(com.google.firebase.crashlytics.internal.persistence.FileStore) PackageManager(android.content.pm.PackageManager) AppData(com.google.firebase.crashlytics.internal.common.AppData) CrashlyticsNativeComponentDeferredProxy(com.google.firebase.crashlytics.internal.CrashlyticsNativeComponentDeferredProxy) ExecutorService(java.util.concurrent.ExecutorService) SettingsController(com.google.firebase.crashlytics.internal.settings.SettingsController) Nullable(androidx.annotation.Nullable)

Example 4 with HttpRequestFactory

use of com.google.firebase.crashlytics.internal.network.HttpRequestFactory 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) 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 5 with HttpRequestFactory

use of com.google.firebase.crashlytics.internal.network.HttpRequestFactory in project GreenHouse by utsanjan.

the class CrashlyticsCore method onPreExecute.

public boolean onPreExecute(SettingsDataProvider settingsProvider) {
    Exception e;
    boolean initializeSynchronously;
    String mappingFileId = CommonUtils.getMappingFileId(this.context);
    Logger logger = Logger.getLogger();
    logger.d("Mapping file ID is: " + mappingFileId);
    boolean requiresBuildId = CommonUtils.getBooleanResourceValue(this.context, CRASHLYTICS_REQUIRE_BUILD_ID, CRASHLYTICS_REQUIRE_BUILD_ID_DEFAULT);
    if (isBuildIdValid(mappingFileId, requiresBuildId)) {
        String googleAppId = this.app.getOptions().getApplicationId();
        try {
            Logger logger2 = Logger.getLogger();
            logger2.i("Initializing Crashlytics " + getVersion());
            FileStore fileStore = new FileStoreImpl(this.context);
            this.crashMarker = new CrashlyticsFileMarker(CRASH_MARKER_FILE_NAME, fileStore);
            this.initializationMarker = new CrashlyticsFileMarker(INITIALIZATION_MARKER_FILE_NAME, fileStore);
            HttpRequestFactory httpRequestFactory = new HttpRequestFactory();
            AppData appData = AppData.create(this.context, this.idManager, googleAppId, mappingFileId);
            UnityVersionProvider unityVersionProvider = new ResourceUnityVersionProvider(this.context);
            AnalyticsReceiver analyticsReceiver = new AnalyticsConnectorReceiver(this.analyticsConnector, new // from class: com.google.firebase.crashlytics.internal.common.CrashlyticsCore.1
            AnalyticsConnectorReceiver.BreadcrumbHandler() {

                // com.google.firebase.crashlytics.internal.analytics.AnalyticsConnectorReceiver.BreadcrumbHandler
                @Override
                public void dropBreadcrumb(String breadcrumb) {
                    CrashlyticsCore.this.log(breadcrumb);
                }
            });
            Logger logger3 = Logger.getLogger();
            logger3.d("Installer package name is: " + appData.installerPackageName);
            this.controller = new CrashlyticsController(this.context, this.backgroundWorker, httpRequestFactory, this.idManager, this.dataCollectionArbiter, fileStore, this.crashMarker, appData, null, null, this.nativeComponent, unityVersionProvider, analyticsReceiver, this.analyticsConnector, settingsProvider);
            initializeSynchronously = didPreviousInitializationFail();
            checkForPreviousCrash();
        } catch (Exception e2) {
            e = e2;
        }
        try {
            this.controller.enableExceptionHandling(Thread.getDefaultUncaughtExceptionHandler(), settingsProvider);
            if (!initializeSynchronously || !CommonUtils.canTryConnection(this.context)) {
                Logger.getLogger().d("Exception handling initialization successful");
                return CRASHLYTICS_REQUIRE_BUILD_ID_DEFAULT;
            }
            Logger.getLogger().d("Crashlytics did not finish previous background initialization. Initializing synchronously.");
            finishInitSynchronously(settingsProvider);
            return false;
        } catch (Exception e3) {
            e = e3;
            Logger.getLogger().e("Crashlytics was not started due to an exception during initialization", e);
            this.controller = null;
            return false;
        }
    } else {
        throw new IllegalStateException(MISSING_BUILD_ID_MSG);
    }
}
Also used : HttpRequestFactory(com.google.firebase.crashlytics.internal.network.HttpRequestFactory) FileStoreImpl(com.google.firebase.crashlytics.internal.persistence.FileStoreImpl) Logger(com.google.firebase.crashlytics.internal.Logger) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException) ResourceUnityVersionProvider(com.google.firebase.crashlytics.internal.unity.ResourceUnityVersionProvider) UnityVersionProvider(com.google.firebase.crashlytics.internal.unity.UnityVersionProvider) FileStore(com.google.firebase.crashlytics.internal.persistence.FileStore) ResourceUnityVersionProvider(com.google.firebase.crashlytics.internal.unity.ResourceUnityVersionProvider) AnalyticsConnectorReceiver(com.google.firebase.crashlytics.internal.analytics.AnalyticsConnectorReceiver) AnalyticsReceiver(com.google.firebase.crashlytics.internal.analytics.AnalyticsReceiver)

Aggregations

HttpRequestFactory (com.google.firebase.crashlytics.internal.network.HttpRequestFactory)6 HttpGetRequest (com.google.firebase.crashlytics.internal.network.HttpGetRequest)4 InspectableHttpGetRequest (com.google.firebase.crashlytics.internal.network.InspectableHttpGetRequest)4 FileStore (com.google.firebase.crashlytics.internal.persistence.FileStore)2 SettingsRequest (com.google.firebase.crashlytics.internal.settings.model.SettingsRequest)2 Context (android.content.Context)1 PackageManager (android.content.pm.PackageManager)1 Nullable (androidx.annotation.Nullable)1 CrashlyticsNativeComponentDeferredProxy (com.google.firebase.crashlytics.internal.CrashlyticsNativeComponentDeferredProxy)1 DevelopmentPlatformProvider (com.google.firebase.crashlytics.internal.DevelopmentPlatformProvider)1 Logger (com.google.firebase.crashlytics.internal.Logger)1 AnalyticsConnectorReceiver (com.google.firebase.crashlytics.internal.analytics.AnalyticsConnectorReceiver)1 AnalyticsReceiver (com.google.firebase.crashlytics.internal.analytics.AnalyticsReceiver)1 AppData (com.google.firebase.crashlytics.internal.common.AppData)1 CrashlyticsCore (com.google.firebase.crashlytics.internal.common.CrashlyticsCore)1 DataCollectionArbiter (com.google.firebase.crashlytics.internal.common.DataCollectionArbiter)1 IdManager (com.google.firebase.crashlytics.internal.common.IdManager)1 FileStoreImpl (com.google.firebase.crashlytics.internal.persistence.FileStoreImpl)1 SettingsController (com.google.firebase.crashlytics.internal.settings.SettingsController)1 ResourceUnityVersionProvider (com.google.firebase.crashlytics.internal.unity.ResourceUnityVersionProvider)1