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));
}
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));
}
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);
}
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));
}
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);
}
}
Aggregations