From 4f06c9d39bf339c94260ded7d584dbfd4d72e9a6 Mon Sep 17 00:00:00 2001 From: jrothfeder Date: Thu, 19 Oct 2023 16:21:44 -0400 Subject: [PATCH] Formatting --- .../crashlytics/FirebaseCrashlytics.java | 863 +++++++++--------- .../firebase/perf/FirebasePerfEarly.java | 4 +- 2 files changed, 430 insertions(+), 437 deletions(-) diff --git a/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/FirebaseCrashlytics.java b/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/FirebaseCrashlytics.java index 2ba74ac6c9b..2dde4a3a6cf 100644 --- a/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/FirebaseCrashlytics.java +++ b/firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/FirebaseCrashlytics.java @@ -42,7 +42,6 @@ import com.google.firebase.inject.Deferred; import com.google.firebase.installations.FirebaseInstallationsApi; import com.google.firebase.sessions.api.FirebaseSessionsDependencies; - import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; @@ -58,443 +57,439 @@ */ public class FirebaseCrashlytics { - static final String FIREBASE_CRASHLYTICS_ANALYTICS_ORIGIN = "clx"; - static final String LEGACY_CRASH_ANALYTICS_ORIGIN = "crash"; - static final int APP_EXCEPTION_CALLBACK_TIMEOUT_MS = 500; - - static @Nullable FirebaseCrashlytics init( - @NonNull FirebaseApp app, - @NonNull FirebaseInstallationsApi firebaseInstallationsApi, - @NonNull Deferred nativeComponent, - @NonNull Deferred 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"); - - CrashlyticsAppQualitySessionsSubscriber sessionsSubscriber = - new CrashlyticsAppQualitySessionsSubscriber(arbiter, fileStore); - FirebaseSessionsDependencies.register(sessionsSubscriber); - - final CrashlyticsCore core = - new CrashlyticsCore( - app, - idManager, - deferredNativeComponent, - arbiter, - analyticsDeferredProxy.getDeferredBreadcrumbSource(), - analyticsDeferredProxy.getAnalyticsEventLogger(), - fileStore, - crashHandlerExecutor, - sessionsSubscriber); - - final String googleAppId = app.getOptions().getApplicationId(); - final String mappingFileId = CommonUtils.getMappingFileId(context); - final List buildIdInfoList = CommonUtils.getBuildIdInfo(context); - - Logger.getLogger().d("Mapping file ID is: " + mappingFileId); - - for (BuildIdInfo buildIdInfo : buildIdInfoList) { - Logger.getLogger() - .d( - String.format( - "Build id for %s on %s: %s", - buildIdInfo.getLibraryName(), - buildIdInfo.getArch(), - buildIdInfo.getBuildId())); - } - - final DevelopmentPlatformProvider developmentPlatformProvider = - new DevelopmentPlatformProvider(context); - - AppData appData; - try { - appData = - AppData.create( - context, - idManager, - googleAppId, - mappingFileId, - buildIdInfoList, - 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() { - @Override - public Object then(@NonNull Task 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() { - @Override - public Void call() throws Exception { - if (finishCoreInBackground) { - core.doBackgroundInitializationAsync(settingsController); - } - return null; - } - }); - - return new FirebaseCrashlytics(core); - } - - @VisibleForTesting // accessible for smoke tests - final CrashlyticsCore core; - - private FirebaseCrashlytics(@NonNull CrashlyticsCore core) { - this.core = core; - } - - /** - * Gets the singleton {@link FirebaseCrashlytics} instance. - * - *

The default {@link FirebaseApp} instance must be initialized before this function is - * called. See - * FirebaseApp for more information. - */ - @NonNull - public static FirebaseCrashlytics getInstance() { - final FirebaseApp app = FirebaseApp.getInstance(); - final FirebaseCrashlytics instance = app.get(FirebaseCrashlytics.class); - if (instance == null) { - throw new NullPointerException("FirebaseCrashlytics component is not present."); - } - return instance; - } - - /** - * Records a non-fatal report to send to Crashlytics. - * - * @param throwable a {@link Throwable} to be recorded as a non-fatal event. - */ - public void recordException(@NonNull Throwable throwable) { - if (throwable == null) { // Users could call this with null despite the annotation. - Logger.getLogger().w("A null value was passed to recordException. Ignoring."); - return; - } - core.logException(throwable); - } - - /** - * Logs a message that's included in the next fatal, non-fatal, or ANR report. - * - *

Logs are visible in the session view on the Firebase Crashlytics console. - * - *

Newline characters are stripped and extremely long messages are truncated. The maximum log - * size is 64k. If exceeded, the log rolls such that messages are removed, starting from the - * oldest. - * - * @param message the message to be logged - */ - public void log(@NonNull String message) { - core.log(message); - } - - /** - * Records a user ID (identifier) that's associated with subsequent fatal, non-fatal, and ANR - * reports. - * - *

The user ID is visible in the session view on the Firebase Crashlytics console. - * - *

Identifiers longer than 1024 characters will be truncated. - * - * @param identifier a unique identifier for the current user - */ - public void setUserId(@NonNull String identifier) { - core.setUserId(identifier); - } - - /** - * Sets a custom key and value that are associated with subsequent fatal, non-fatal, and ANR - * reports. - * - *

Multiple calls to this method with the same key update the value for that key. - * - *

The value of any key at the time of a fatal, non-fatal, or ANR event is associated with - * that event. - * - *

Keys and associated values are visible in the session view on the Firebase Crashlytics - * console. - * - *

Accepts a maximum of 64 key/value pairs. New keys beyond that limit are ignored. Keys or - * values that exceed 1024 characters are truncated. - * - * @param key A unique key - * @param value A value to be associated with the given key - */ - public void setCustomKey(@NonNull String key, boolean value) { - core.setCustomKey(key, Boolean.toString(value)); - } - - /** - * Sets a custom key and value that are associated with subsequent fatal and non-fatal reports. - * - *

Multiple calls to this method with the same key update the value for that key. - * - *

The value of any key at the time of a fatal or non-fatal event is associated with that - * event. - * - *

Keys and associated values are visible in the session view on the Firebase Crashlytics - * console. - * - *

Accepts a maximum of 64 key/value pairs. New keys beyond that limit are ignored. Keys or - * values that exceed 1024 characters are truncated. - * - * @param key A unique key - * @param value A value to be associated with the given key - */ - public void setCustomKey(@NonNull String key, double value) { - core.setCustomKey(key, Double.toString(value)); - } - - /** - * Sets a custom key and value that are associated with subsequent fatal, non-fatal, and ANR - * reports. - * - *

Multiple calls to this method with the same key update the value for that key. - * - *

The value of any key at the time of a fatal, non-fatal, or ANR event is associated with - * that event. - * - *

Keys and associated values are visible in the session view on the Firebase Crashlytics - * console. - * - *

Accepts a maximum of 64 key/value pairs. New keys beyond that limit are ignored. Keys or - * values that exceed 1024 characters are truncated. - * - * @param key A unique key - * @param value A value to be associated with the given key - */ - public void setCustomKey(@NonNull String key, float value) { - core.setCustomKey(key, Float.toString(value)); - } - - /** - * Sets a custom key and value that are associated with subsequent fatal, non-fatal, and ANR - * reports. - * - *

Multiple calls to this method with the same key update the value for that key. - * - *

The value of any key at the time of a fatal, non-fatal, or ANR event is associated with - * that event. - * - *

Keys and associated values are visible in the session view on the Firebase Crashlytics - * console. - * - *

Accepts a maximum of 64 key/value pairs. New keys beyond that limit are ignored. Keys or - * values that exceed 1024 characters are truncated. - * - * @param key A unique key - * @param value A value to be associated with the given key - */ - public void setCustomKey(@NonNull String key, int value) { - core.setCustomKey(key, Integer.toString(value)); - } - - /** - * Records a custom key and value to be associated with subsequent fatal, non-fatal, and ANR - * reports. - * - *

Multiple calls to this method with the same key will update the value for that key. - * - *

The value of any key at the time of a fatal, non-fatal, or ANR event will be associated - * with that event. - * - *

Keys and associated values are visible in the session view on the Firebase Crashlytics - * console. - * - *

A maximum of 64 key/value pairs can be written, and new keys added beyond that limit will - * be ignored. Keys or values that exceed 1024 characters will be truncated. - * - * @param key A unique key - * @param value A value to be associated with the given key - */ - public void setCustomKey(@NonNull String key, long value) { - core.setCustomKey(key, Long.toString(value)); - } - - /** - * Sets a custom key and value that are associated with subsequent fatal, non-fatal, and ANR - * reports. - * - *

Multiple calls to this method with the same key update the value for that key. - * - *

The value of any key at the time of a fatal, non-fatal, or ANR event is associated with - * that event. - * - *

Keys and associated values are visible in the session view on the Firebase Crashlytics - * console. - * - *

Accepts a maximum of 64 key/value pairs. New keys beyond that limit are ignored. Keys or - * values that exceed 1024 characters are truncated. - * - * @param key A unique key - * @param value A value to be associated with the given key - */ - public void setCustomKey(@NonNull String key, @NonNull String value) { - core.setCustomKey(key, value); - } - - /** - * Sets multiple custom keys and values that are associated with subsequent fatal, non-fatal, - * and ANR reports. This method is intended as an alternative to {@code setCustomKey} in order - * to reduce the computational load of writing out multiple key/value pairs at the same time. - * - *

Multiple calls to this method with the same key update the value for that key. - * - *

The value of any key at the time of a fatal, non-fatal, or ANR event is associated with - * that event. - * - *

Keys and associated values are visible in the session view on the Firebase Crashlytics - * console. - * - *

Accepts a maximum of 64 key/value pairs. If calling this method results in the number of - * custom keys exceeding this limit, only some of the keys will be logged (however many are - * needed to get to 64). Which keys are logged versus dropped is unpredictable as there is no - * intrinsic sorting of keys. Keys or values that exceed 1024 characters are truncated. - * - * @param keysAndValues A dictionary of keys and the values to associate with each key - */ - public void setCustomKeys(@NonNull CustomKeysAndValues keysAndValues) { - core.setCustomKeys(keysAndValues.keysAndValues); + static final String FIREBASE_CRASHLYTICS_ANALYTICS_ORIGIN = "clx"; + static final String LEGACY_CRASH_ANALYTICS_ORIGIN = "crash"; + static final int APP_EXCEPTION_CALLBACK_TIMEOUT_MS = 500; + + static @Nullable FirebaseCrashlytics init( + @NonNull FirebaseApp app, + @NonNull FirebaseInstallationsApi firebaseInstallationsApi, + @NonNull Deferred nativeComponent, + @NonNull Deferred 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"); + + CrashlyticsAppQualitySessionsSubscriber sessionsSubscriber = + new CrashlyticsAppQualitySessionsSubscriber(arbiter, fileStore); + FirebaseSessionsDependencies.register(sessionsSubscriber); + + final CrashlyticsCore core = + new CrashlyticsCore( + app, + idManager, + deferredNativeComponent, + arbiter, + analyticsDeferredProxy.getDeferredBreadcrumbSource(), + analyticsDeferredProxy.getAnalyticsEventLogger(), + fileStore, + crashHandlerExecutor, + sessionsSubscriber); + + final String googleAppId = app.getOptions().getApplicationId(); + final String mappingFileId = CommonUtils.getMappingFileId(context); + final List buildIdInfoList = CommonUtils.getBuildIdInfo(context); + + Logger.getLogger().d("Mapping file ID is: " + mappingFileId); + + for (BuildIdInfo buildIdInfo : buildIdInfoList) { + Logger.getLogger() + .d( + String.format( + "Build id for %s on %s: %s", + buildIdInfo.getLibraryName(), buildIdInfo.getArch(), buildIdInfo.getBuildId())); } - // region Unsent report management. - - /** - * Checks a device for any fatal crash, non-fatal error, or ANR reports that haven't yet been - * sent to Crashlytics. If automatic data collection is enabled, then reports are uploaded - * automatically and this always returns false. If automatic data collection is disabled, this - * method can be used to check whether the user opts-in to send crash reports from their device. - * - * @return a Task that is resolved with the result. - */ - @NonNull - public Task checkForUnsentReports() { - return core.checkForUnsentReports(); + final DevelopmentPlatformProvider developmentPlatformProvider = + new DevelopmentPlatformProvider(context); + + AppData appData; + try { + appData = + AppData.create( + context, + idManager, + googleAppId, + mappingFileId, + buildIdInfoList, + developmentPlatformProvider); + } catch (PackageManager.NameNotFoundException e) { + Logger.getLogger().e("Error retrieving app package info.", e); + return null; } - /** - * If automatic data collection is disabled, this method queues up all the reports on a device - * to send to Crashlytics. Otherwise, this method is a no-op. - */ - public void sendUnsentReports() { - core.sendUnsentReports(); - } - - /** - * If automatic data collection is disabled, this method queues up all the reports on a device - * for deletion. Otherwise, this method is a no-op. - */ - public void deleteUnsentReports() { - core.deleteUnsentReports(); - } - - // endregion - - /** - * Checks whether the app crashed on its previous run. - * - * @return true if a crash was recorded during the previous run of the app. - */ - public boolean didCrashOnPreviousExecution() { - return core.didCrashOnPreviousExecution(); - } - - /** - * Enables or disables the automatic data collection configuration for Crashlytics. - * - *

If this is set, it overrides any automatic data collection settings configured in the - * AndroidManifest.xml as well as any Firebase-wide settings. - * - *

If automatic data collection is disabled for Crashlytics, crash reports are stored on the - * device. To check for reports, use the {@link #checkForUnsentReports()} method. Use {@link - * #sendUnsentReports()} to upload existing reports even when automatic data collection is - * disabled. Use {@link #deleteUnsentReports()} to delete any reports stored on the device - * without sending them to Crashlytics. - * - * @param enabled whether to enable automatic data collection. When set to {@code false}, the - * new value does not apply until the next run of the app. To disable data collection by - * default for all app runs, add the {@code firebase_crashlytics_collection_enabled} flag to - * your app's AndroidManifest.xml. - */ - public void setCrashlyticsCollectionEnabled(boolean enabled) { - core.setCrashlyticsCollectionEnabled(enabled); + 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() { + @Override + public Object then(@NonNull Task 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() { + @Override + public Void call() throws Exception { + if (finishCoreInBackground) { + core.doBackgroundInitializationAsync(settingsController); + } + return null; + } + }); + + return new FirebaseCrashlytics(core); + } + + @VisibleForTesting // accessible for smoke tests + final CrashlyticsCore core; + + private FirebaseCrashlytics(@NonNull CrashlyticsCore core) { + this.core = core; + } + + /** + * Gets the singleton {@link FirebaseCrashlytics} instance. + * + *

The default {@link FirebaseApp} instance must be initialized before this function is called. + * See + * FirebaseApp for more information. + */ + @NonNull + public static FirebaseCrashlytics getInstance() { + final FirebaseApp app = FirebaseApp.getInstance(); + final FirebaseCrashlytics instance = app.get(FirebaseCrashlytics.class); + if (instance == null) { + throw new NullPointerException("FirebaseCrashlytics component is not present."); } - - /** - * Enables or disables the automatic data collection configuration for Crashlytics. - * - *

If this is set, it overrides any automatic data collection settings configured in the - * AndroidManifest.xml as well as any Firebase-wide settings. If set to {@code null}, the - * override is cleared. - * - *

If automatic data collection is disabled for Crashlytics, crash reports are stored on the - * device. To check for reports, use the {@link #checkForUnsentReports()} method. Use {@link - * #sendUnsentReports()} to upload existing reports even when automatic data collection is - * disabled. Use {@link #deleteUnsentReports()} to delete any reports stored on the device - * without sending them to Crashlytics. - * - * @param enabled whether to enable or disable automatic data collection. When set to {@code - * false}, the new value does not apply until the next run of the app. When set to {@code - * null}, the override is cleared and automatic data collection settings are determined by - * the configuration in your AndroidManifest.xml or other Firebase-wide settings. - */ - public void setCrashlyticsCollectionEnabled(@Nullable Boolean enabled) { - core.setCrashlyticsCollectionEnabled(enabled); + return instance; + } + + /** + * Records a non-fatal report to send to Crashlytics. + * + * @param throwable a {@link Throwable} to be recorded as a non-fatal event. + */ + public void recordException(@NonNull Throwable throwable) { + if (throwable == null) { // Users could call this with null despite the annotation. + Logger.getLogger().w("A null value was passed to recordException. Ignoring."); + return; } + core.logException(throwable); + } + + /** + * Logs a message that's included in the next fatal, non-fatal, or ANR report. + * + *

Logs are visible in the session view on the Firebase Crashlytics console. + * + *

Newline characters are stripped and extremely long messages are truncated. The maximum log + * size is 64k. If exceeded, the log rolls such that messages are removed, starting from the + * oldest. + * + * @param message the message to be logged + */ + public void log(@NonNull String message) { + core.log(message); + } + + /** + * Records a user ID (identifier) that's associated with subsequent fatal, non-fatal, and ANR + * reports. + * + *

The user ID is visible in the session view on the Firebase Crashlytics console. + * + *

Identifiers longer than 1024 characters will be truncated. + * + * @param identifier a unique identifier for the current user + */ + public void setUserId(@NonNull String identifier) { + core.setUserId(identifier); + } + + /** + * Sets a custom key and value that are associated with subsequent fatal, non-fatal, and ANR + * reports. + * + *

Multiple calls to this method with the same key update the value for that key. + * + *

The value of any key at the time of a fatal, non-fatal, or ANR event is associated with that + * event. + * + *

Keys and associated values are visible in the session view on the Firebase Crashlytics + * console. + * + *

Accepts a maximum of 64 key/value pairs. New keys beyond that limit are ignored. Keys or + * values that exceed 1024 characters are truncated. + * + * @param key A unique key + * @param value A value to be associated with the given key + */ + public void setCustomKey(@NonNull String key, boolean value) { + core.setCustomKey(key, Boolean.toString(value)); + } + + /** + * Sets a custom key and value that are associated with subsequent fatal and non-fatal reports. + * + *

Multiple calls to this method with the same key update the value for that key. + * + *

The value of any key at the time of a fatal or non-fatal event is associated with that + * event. + * + *

Keys and associated values are visible in the session view on the Firebase Crashlytics + * console. + * + *

Accepts a maximum of 64 key/value pairs. New keys beyond that limit are ignored. Keys or + * values that exceed 1024 characters are truncated. + * + * @param key A unique key + * @param value A value to be associated with the given key + */ + public void setCustomKey(@NonNull String key, double value) { + core.setCustomKey(key, Double.toString(value)); + } + + /** + * Sets a custom key and value that are associated with subsequent fatal, non-fatal, and ANR + * reports. + * + *

Multiple calls to this method with the same key update the value for that key. + * + *

The value of any key at the time of a fatal, non-fatal, or ANR event is associated with that + * event. + * + *

Keys and associated values are visible in the session view on the Firebase Crashlytics + * console. + * + *

Accepts a maximum of 64 key/value pairs. New keys beyond that limit are ignored. Keys or + * values that exceed 1024 characters are truncated. + * + * @param key A unique key + * @param value A value to be associated with the given key + */ + public void setCustomKey(@NonNull String key, float value) { + core.setCustomKey(key, Float.toString(value)); + } + + /** + * Sets a custom key and value that are associated with subsequent fatal, non-fatal, and ANR + * reports. + * + *

Multiple calls to this method with the same key update the value for that key. + * + *

The value of any key at the time of a fatal, non-fatal, or ANR event is associated with that + * event. + * + *

Keys and associated values are visible in the session view on the Firebase Crashlytics + * console. + * + *

Accepts a maximum of 64 key/value pairs. New keys beyond that limit are ignored. Keys or + * values that exceed 1024 characters are truncated. + * + * @param key A unique key + * @param value A value to be associated with the given key + */ + public void setCustomKey(@NonNull String key, int value) { + core.setCustomKey(key, Integer.toString(value)); + } + + /** + * Records a custom key and value to be associated with subsequent fatal, non-fatal, and ANR + * reports. + * + *

Multiple calls to this method with the same key will update the value for that key. + * + *

The value of any key at the time of a fatal, non-fatal, or ANR event will be associated with + * that event. + * + *

Keys and associated values are visible in the session view on the Firebase Crashlytics + * console. + * + *

A maximum of 64 key/value pairs can be written, and new keys added beyond that limit will be + * ignored. Keys or values that exceed 1024 characters will be truncated. + * + * @param key A unique key + * @param value A value to be associated with the given key + */ + public void setCustomKey(@NonNull String key, long value) { + core.setCustomKey(key, Long.toString(value)); + } + + /** + * Sets a custom key and value that are associated with subsequent fatal, non-fatal, and ANR + * reports. + * + *

Multiple calls to this method with the same key update the value for that key. + * + *

The value of any key at the time of a fatal, non-fatal, or ANR event is associated with that + * event. + * + *

Keys and associated values are visible in the session view on the Firebase Crashlytics + * console. + * + *

Accepts a maximum of 64 key/value pairs. New keys beyond that limit are ignored. Keys or + * values that exceed 1024 characters are truncated. + * + * @param key A unique key + * @param value A value to be associated with the given key + */ + public void setCustomKey(@NonNull String key, @NonNull String value) { + core.setCustomKey(key, value); + } + + /** + * Sets multiple custom keys and values that are associated with subsequent fatal, non-fatal, and + * ANR reports. This method is intended as an alternative to {@code setCustomKey} in order to + * reduce the computational load of writing out multiple key/value pairs at the same time. + * + *

Multiple calls to this method with the same key update the value for that key. + * + *

The value of any key at the time of a fatal, non-fatal, or ANR event is associated with that + * event. + * + *

Keys and associated values are visible in the session view on the Firebase Crashlytics + * console. + * + *

Accepts a maximum of 64 key/value pairs. If calling this method results in the number of + * custom keys exceeding this limit, only some of the keys will be logged (however many are needed + * to get to 64). Which keys are logged versus dropped is unpredictable as there is no intrinsic + * sorting of keys. Keys or values that exceed 1024 characters are truncated. + * + * @param keysAndValues A dictionary of keys and the values to associate with each key + */ + public void setCustomKeys(@NonNull CustomKeysAndValues keysAndValues) { + core.setCustomKeys(keysAndValues.keysAndValues); + } + + // region Unsent report management. + + /** + * Checks a device for any fatal crash, non-fatal error, or ANR reports that haven't yet been sent + * to Crashlytics. If automatic data collection is enabled, then reports are uploaded + * automatically and this always returns false. If automatic data collection is disabled, this + * method can be used to check whether the user opts-in to send crash reports from their device. + * + * @return a Task that is resolved with the result. + */ + @NonNull + public Task checkForUnsentReports() { + return core.checkForUnsentReports(); + } + + /** + * If automatic data collection is disabled, this method queues up all the reports on a device to + * send to Crashlytics. Otherwise, this method is a no-op. + */ + public void sendUnsentReports() { + core.sendUnsentReports(); + } + + /** + * If automatic data collection is disabled, this method queues up all the reports on a device for + * deletion. Otherwise, this method is a no-op. + */ + public void deleteUnsentReports() { + core.deleteUnsentReports(); + } + + // endregion + + /** + * Checks whether the app crashed on its previous run. + * + * @return true if a crash was recorded during the previous run of the app. + */ + public boolean didCrashOnPreviousExecution() { + return core.didCrashOnPreviousExecution(); + } + + /** + * Enables or disables the automatic data collection configuration for Crashlytics. + * + *

If this is set, it overrides any automatic data collection settings configured in the + * AndroidManifest.xml as well as any Firebase-wide settings. + * + *

If automatic data collection is disabled for Crashlytics, crash reports are stored on the + * device. To check for reports, use the {@link #checkForUnsentReports()} method. Use {@link + * #sendUnsentReports()} to upload existing reports even when automatic data collection is + * disabled. Use {@link #deleteUnsentReports()} to delete any reports stored on the device without + * sending them to Crashlytics. + * + * @param enabled whether to enable automatic data collection. When set to {@code false}, the new + * value does not apply until the next run of the app. To disable data collection by default + * for all app runs, add the {@code firebase_crashlytics_collection_enabled} flag to your + * app's AndroidManifest.xml. + */ + public void setCrashlyticsCollectionEnabled(boolean enabled) { + core.setCrashlyticsCollectionEnabled(enabled); + } + + /** + * Enables or disables the automatic data collection configuration for Crashlytics. + * + *

If this is set, it overrides any automatic data collection settings configured in the + * AndroidManifest.xml as well as any Firebase-wide settings. If set to {@code null}, the override + * is cleared. + * + *

If automatic data collection is disabled for Crashlytics, crash reports are stored on the + * device. To check for reports, use the {@link #checkForUnsentReports()} method. Use {@link + * #sendUnsentReports()} to upload existing reports even when automatic data collection is + * disabled. Use {@link #deleteUnsentReports()} to delete any reports stored on the device without + * sending them to Crashlytics. + * + * @param enabled whether to enable or disable automatic data collection. When set to {@code + * false}, the new value does not apply until the next run of the app. When set to {@code + * null}, the override is cleared and automatic data collection settings are determined by the + * configuration in your AndroidManifest.xml or other Firebase-wide settings. + */ + public void setCrashlyticsCollectionEnabled(@Nullable Boolean enabled) { + core.setCrashlyticsCollectionEnabled(enabled); + } } diff --git a/firebase-perf/src/main/java/com/google/firebase/perf/FirebasePerfEarly.java b/firebase-perf/src/main/java/com/google/firebase/perf/FirebasePerfEarly.java index ecc1ce637a2..5e5d05ee7a4 100644 --- a/firebase-perf/src/main/java/com/google/firebase/perf/FirebasePerfEarly.java +++ b/firebase-perf/src/main/java/com/google/firebase/perf/FirebasePerfEarly.java @@ -38,9 +38,7 @@ public class FirebasePerfEarly { public FirebasePerfEarly( - FirebaseApp app, - @Nullable StartupTime startupTime, - Executor uiExecutor) { + FirebaseApp app, @Nullable StartupTime startupTime, Executor uiExecutor) { Context context = app.getApplicationContext(); // Initialize ConfigResolver early for accessing device caching layer.