Skip to content

Commit

Permalink
Draft of possible api change
Browse files Browse the repository at this point in the history
  • Loading branch information
mrober committed Jul 30, 2024
1 parent 10fe142 commit 5dd4115
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 71 deletions.
57 changes: 29 additions & 28 deletions firebase-crashlytics/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,24 @@ package com.google.firebase.crashlytics {

public class FirebaseCrashlytics {
method @NonNull public com.google.android.gms.tasks.Task<java.lang.Boolean> checkForUnsentReports();
method public void deleteUnsentReports();
method public boolean didCrashOnPreviousExecution();
method @com.google.errorprone.annotations.CanIgnoreReturnValue public com.google.android.gms.tasks.Task<java.lang.Void> deleteUnsentReports();
method @Deprecated @Discouraged(message="May not be current. Use didCrashOnPreviousExecutionTask") public boolean didCrashOnPreviousExecution();
method public com.google.android.gms.tasks.Task<java.lang.Boolean> didCrashOnPreviousExecutionTask();
method @NonNull public static com.google.firebase.crashlytics.FirebaseCrashlytics getInstance();
method public void log(@NonNull String);
method public void recordException(@NonNull Throwable);
method public void sendUnsentReports();
method public boolean isCrashlyticsCollectionEnabled();
method public void setCrashlyticsCollectionEnabled(boolean);
method public void setCrashlyticsCollectionEnabled(@Nullable Boolean);
method public void setCustomKey(@NonNull String, boolean);
method public void setCustomKey(@NonNull String, double);
method public void setCustomKey(@NonNull String, float);
method public void setCustomKey(@NonNull String, int);
method public void setCustomKey(@NonNull String, long);
method public void setCustomKey(@NonNull String, @NonNull String);
method public void setCustomKeys(@NonNull com.google.firebase.crashlytics.CustomKeysAndValues);
method public void setUserId(@NonNull String);
method public com.google.android.gms.tasks.Task<java.lang.Boolean> isCrashlyticsCollectionEnabled();
method @com.google.errorprone.annotations.CanIgnoreReturnValue public com.google.android.gms.tasks.Task<java.lang.Void> log(@NonNull String);
method @com.google.errorprone.annotations.CanIgnoreReturnValue public com.google.android.gms.tasks.Task<java.lang.Void> recordException(@NonNull Throwable);
method @com.google.errorprone.annotations.CanIgnoreReturnValue public com.google.android.gms.tasks.Task<java.lang.Void> sendUnsentReports();
method @com.google.errorprone.annotations.CanIgnoreReturnValue public com.google.android.gms.tasks.Task<java.lang.Void> setCrashlyticsCollectionEnabled(boolean);
method @com.google.errorprone.annotations.CanIgnoreReturnValue public com.google.android.gms.tasks.Task<java.lang.Void> setCrashlyticsCollectionEnabled(@Nullable Boolean);
method @com.google.errorprone.annotations.CanIgnoreReturnValue public com.google.android.gms.tasks.Task<java.lang.Void> setCustomKey(@NonNull String, boolean);
method @com.google.errorprone.annotations.CanIgnoreReturnValue public com.google.android.gms.tasks.Task<java.lang.Void> setCustomKey(@NonNull String, double);
method @com.google.errorprone.annotations.CanIgnoreReturnValue public com.google.android.gms.tasks.Task<java.lang.Void> setCustomKey(@NonNull String, float);
method @com.google.errorprone.annotations.CanIgnoreReturnValue public com.google.android.gms.tasks.Task<java.lang.Void> setCustomKey(@NonNull String, int);
method @com.google.errorprone.annotations.CanIgnoreReturnValue public com.google.android.gms.tasks.Task<java.lang.Void> setCustomKey(@NonNull String, long);
method @com.google.errorprone.annotations.CanIgnoreReturnValue public com.google.android.gms.tasks.Task<java.lang.Void> setCustomKey(@NonNull String, @NonNull String);
method @com.google.errorprone.annotations.CanIgnoreReturnValue public com.google.android.gms.tasks.Task<java.lang.Void> setCustomKeys(@NonNull com.google.firebase.crashlytics.CustomKeysAndValues);
method public com.google.android.gms.tasks.Task<java.lang.Void> setUserId(@NonNull String);
}

public final class FirebaseCrashlyticsKt {
Expand All @@ -43,12 +44,12 @@ package com.google.firebase.crashlytics {

public final class KeyValueBuilder {
ctor public KeyValueBuilder(@NonNull com.google.firebase.crashlytics.FirebaseCrashlytics crashlytics);
method public void key(@NonNull String key, boolean value);
method public void key(@NonNull String key, double value);
method public void key(@NonNull String key, float value);
method public void key(@NonNull String key, int value);
method public void key(@NonNull String key, long value);
method public void key(@NonNull String key, @NonNull String value);
method public com.google.android.gms.tasks.Task<java.lang.Void> key(@NonNull String key, boolean value);
method public com.google.android.gms.tasks.Task<java.lang.Void> key(@NonNull String key, double value);
method public com.google.android.gms.tasks.Task<java.lang.Void> key(@NonNull String key, float value);
method public com.google.android.gms.tasks.Task<java.lang.Void> key(@NonNull String key, int value);
method public com.google.android.gms.tasks.Task<java.lang.Void> key(@NonNull String key, long value);
method public com.google.android.gms.tasks.Task<java.lang.Void> key(@NonNull String key, @NonNull String value);
}

}
Expand All @@ -62,12 +63,12 @@ package com.google.firebase.crashlytics.ktx {

@Deprecated public final class KeyValueBuilder {
ctor @Deprecated public KeyValueBuilder(@NonNull com.google.firebase.crashlytics.FirebaseCrashlytics crashlytics);
method @Deprecated public void key(@NonNull String key, boolean value);
method @Deprecated public void key(@NonNull String key, double value);
method @Deprecated public void key(@NonNull String key, float value);
method @Deprecated public void key(@NonNull String key, int value);
method @Deprecated public void key(@NonNull String key, long value);
method @Deprecated public void key(@NonNull String key, @NonNull String value);
method @Deprecated public com.google.android.gms.tasks.Task<java.lang.Void> key(@NonNull String key, boolean value);
method @Deprecated public com.google.android.gms.tasks.Task<java.lang.Void> key(@NonNull String key, double value);
method @Deprecated public com.google.android.gms.tasks.Task<java.lang.Void> key(@NonNull String key, float value);
method @Deprecated public com.google.android.gms.tasks.Task<java.lang.Void> key(@NonNull String key, int value);
method @Deprecated public com.google.android.gms.tasks.Task<java.lang.Void> key(@NonNull String key, long value);
method @Deprecated public com.google.android.gms.tasks.Task<java.lang.Void> key(@NonNull String key, @NonNull String value);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

import android.content.Context;
import android.content.pm.PackageManager;
import androidx.annotation.Discouraged;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.Tasks;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.firebase.FirebaseApp;
import com.google.firebase.analytics.connector.AnalyticsConnector;
import com.google.firebase.crashlytics.internal.CrashlyticsNativeComponent;
Expand Down Expand Up @@ -202,12 +205,13 @@ public static FirebaseCrashlytics getInstance() {
*
* @param throwable a {@link Throwable} to be recorded as a non-fatal event.
*/
public void recordException(@NonNull Throwable throwable) {
@CanIgnoreReturnValue
public Task<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;
return Tasks.forResult(null);
}
core.logException(throwable);
return core.logException(throwable);
}

/**
Expand All @@ -221,8 +225,9 @@ public void recordException(@NonNull Throwable throwable) {
*
* @param message the message to be logged
*/
public void log(@NonNull String message) {
core.log(message);
@CanIgnoreReturnValue
public Task<Void> log(@NonNull String message) {
return core.log(message);
}

/**
Expand All @@ -235,8 +240,8 @@ public void log(@NonNull String message) {
*
* @param identifier a unique identifier for the current user
*/
public void setUserId(@NonNull String identifier) {
core.setUserId(identifier);
public Task<Void> setUserId(@NonNull String identifier) {
return core.setUserId(identifier);
}

/**
Expand All @@ -257,8 +262,9 @@ public void setUserId(@NonNull String identifier) {
* @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));
@CanIgnoreReturnValue
public Task<Void> setCustomKey(@NonNull String key, boolean value) {
return core.setCustomKey(key, Boolean.toString(value));
}

/**
Expand All @@ -278,8 +284,9 @@ public void setCustomKey(@NonNull String key, boolean value) {
* @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));
@CanIgnoreReturnValue
public Task<Void> setCustomKey(@NonNull String key, double value) {
return core.setCustomKey(key, Double.toString(value));
}

/**
Expand All @@ -300,8 +307,9 @@ public void setCustomKey(@NonNull String key, double value) {
* @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));
@CanIgnoreReturnValue
public Task<Void> setCustomKey(@NonNull String key, float value) {
return core.setCustomKey(key, Float.toString(value));
}

/**
Expand All @@ -322,8 +330,9 @@ public void setCustomKey(@NonNull String key, float value) {
* @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));
@CanIgnoreReturnValue
public Task<Void> setCustomKey(@NonNull String key, int value) {
return core.setCustomKey(key, Integer.toString(value));
}

/**
Expand All @@ -344,8 +353,9 @@ public void setCustomKey(@NonNull String key, int value) {
* @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));
@CanIgnoreReturnValue
public Task<Void> setCustomKey(@NonNull String key, long value) {
return core.setCustomKey(key, Long.toString(value));
}

/**
Expand All @@ -366,8 +376,9 @@ public void setCustomKey(@NonNull String key, long value) {
* @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);
@CanIgnoreReturnValue
public Task<Void> setCustomKey(@NonNull String key, @NonNull String value) {
return core.setCustomKey(key, value);
}

/**
Expand All @@ -390,8 +401,9 @@ public void setCustomKey(@NonNull String key, @NonNull String value) {
*
* @param keysAndValues A dictionary of keys and the values to associate with each key
*/
public void setCustomKeys(@NonNull CustomKeysAndValues keysAndValues) {
core.setCustomKeys(keysAndValues.keysAndValues);
@CanIgnoreReturnValue
public Task<Void> setCustomKeys(@NonNull CustomKeysAndValues keysAndValues) {
return core.setCustomKeys(keysAndValues.keysAndValues);
}

// region Unsent report management.
Expand All @@ -413,16 +425,18 @@ public Task<Boolean> 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();
@CanIgnoreReturnValue
public Task<Void> sendUnsentReports() {
return 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();
@CanIgnoreReturnValue
public Task<Void> deleteUnsentReports() {
return core.deleteUnsentReports();
}

// endregion
Expand All @@ -431,11 +445,24 @@ public void deleteUnsentReports() {
* Checks whether the app crashed on its previous run.
*
* @return true if a crash was recorded during the previous run of the app.
* @deprecated Use didCrashOnPreviousExecutionTask.
*/
@Discouraged(message = "May not be current. Use didCrashOnPreviousExecutionTask")
@Deprecated
public boolean didCrashOnPreviousExecution() {
return core.didCrashOnPreviousExecution();
}

/**
* Checks whether the app crashed on its previous run.
*
* @return A Task that resolves to true if a crash was recorded during the previous run of the app
*/
public Task<Boolean> didCrashOnPreviousExecutionTask() {
// Would didCrashOnPreviousRun be a better name?
return core.didCrashOnPreviousExecutionTask();
}

/**
* Indicates whether or not automatic data collection is enabled
*
Expand All @@ -446,7 +473,8 @@ public boolean didCrashOnPreviousExecution() {
* <p>Otherwise, use the default {@link FirebaseApp#isDataCollectionDefaultEnabled()} in
* FirebaseApp
*/
public boolean isCrashlyticsCollectionEnabled() {
public Task<Boolean> isCrashlyticsCollectionEnabled() {
// This api was not released yet, safe to change return type.
return core.isCrashlyticsCollectionEnabled();
}

Expand All @@ -467,8 +495,10 @@ public boolean isCrashlyticsCollectionEnabled() {
* 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);
@CanIgnoreReturnValue
public Task<Void> setCrashlyticsCollectionEnabled(boolean enabled) {
// Why do we have this method if we have the Boolean boxed version below? Safe to remove this?
return core.setCrashlyticsCollectionEnabled(enabled);
}

/**
Expand All @@ -489,7 +519,8 @@ public void setCrashlyticsCollectionEnabled(boolean enabled) {
* 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);
@CanIgnoreReturnValue
public Task<Void> setCrashlyticsCollectionEnabled(@Nullable Boolean enabled) {
return core.setCrashlyticsCollectionEnabled(enabled);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,14 @@ private Task<Void> doBackgroundInitialization(SettingsProvider settingsProvider)

// endregion

public boolean isCrashlyticsCollectionEnabled() {
return dataCollectionArbiter.isAutomaticDataCollectionEnabled();
public Task<Boolean> isCrashlyticsCollectionEnabled() {
// TODO(mrober): Is this current?
return Tasks.forResult(dataCollectionArbiter.isAutomaticDataCollectionEnabled());
}

public void setCrashlyticsCollectionEnabled(@Nullable Boolean enabled) {
public Task<Void> setCrashlyticsCollectionEnabled(@Nullable Boolean enabled) {
dataCollectionArbiter.setCrashlyticsDataCollectionEnabled(enabled);
return Tasks.forResult(null);
}

// region Unsent report management.
Expand Down Expand Up @@ -322,8 +324,9 @@ public static String getVersion() {
* Throwable was thrown. The Throwable will always be processed on a background thread, so it is
* safe to invoke this method from the main thread.
*/
public void logException(@NonNull Throwable throwable) {
commonWorker.submit(() -> controller.writeNonFatalException(Thread.currentThread(), throwable));
public Task<Void> logException(@NonNull Throwable throwable) {
return commonWorker.submit(
() -> controller.writeNonFatalException(Thread.currentThread(), throwable));
}

/**
Expand All @@ -336,17 +339,17 @@ public void logException(@NonNull Throwable throwable) {
*
* @see #logException(Throwable)
*/
public void log(final String msg) {
public Task<Void> log(final String msg) {
final long timestamp = System.currentTimeMillis() - startTime;
// queuing up on common worker to maintain the order
commonWorker.submit(
return commonWorker.submit(
() -> {
diskWriteWorker.submit(() -> controller.writeToLog(timestamp, msg));
});
}

public void setUserId(String identifier) {
commonWorker.submit(() -> controller.setUserId(identifier));
public Task<Void> setUserId(String identifier) {
return commonWorker.submit(() -> controller.setUserId(identifier));
}

/**
Expand All @@ -358,8 +361,8 @@ public void setUserId(String identifier) {
*
* @throws NullPointerException if key is null.
*/
public void setCustomKey(String key, String value) {
commonWorker.submit(() -> controller.setCustomKey(key, value));
public Task<Void> setCustomKey(String key, String value) {
return commonWorker.submit(() -> controller.setCustomKey(key, value));
}

/**
Expand All @@ -375,8 +378,8 @@ public void setCustomKey(String key, String value) {
*
* @throws NullPointerException if any key in keysAndValues is null.
*/
public void setCustomKeys(Map<String, String> keysAndValues) {
commonWorker.submit(() -> controller.setCustomKeys(keysAndValues));
public Task<Void> setCustomKeys(Map<String, String> keysAndValues) {
return commonWorker.submit(() -> controller.setCustomKeys(keysAndValues));
}

// endregion
Expand Down Expand Up @@ -512,9 +515,14 @@ private void checkForPreviousCrash() {
}

public boolean didCrashOnPreviousExecution() {
// TODO(mrober): Is this boolean always correct?
return didCrashOnPreviousExecution;
}

public Task<Boolean> didCrashOnPreviousExecutionTask() {
return Tasks.forResult(didCrashOnPreviousExecution);
}

// endregion

// region Static utilities
Expand Down

0 comments on commit 5dd4115

Please sign in to comment.