Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove passthrough register method from FirebaseSessions since `F… #5452

Merged
merged 6 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ private FirebaseCrashlytics buildCrashlytics(ComponentContainer container) {
FirebaseSessions firebaseSessions = container.get(FirebaseSessions.class);

return FirebaseCrashlytics.init(
app, firebaseInstallations, firebaseSessions, nativeComponent, analyticsConnector);
app, firebaseInstallations, nativeComponent, analyticsConnector);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import com.google.firebase.crashlytics.internal.settings.SettingsController;
import com.google.firebase.inject.Deferred;
import com.google.firebase.installations.FirebaseInstallationsApi;
import com.google.firebase.sessions.FirebaseSessions;
import com.google.firebase.sessions.api.FirebaseSessionsDependencies;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
Expand All @@ -64,7 +64,6 @@ public class FirebaseCrashlytics {
static @Nullable FirebaseCrashlytics init(
@NonNull FirebaseApp app,
@NonNull FirebaseInstallationsApi firebaseInstallationsApi,
@NonNull FirebaseSessions firebaseSessions,
@NonNull Deferred<CrashlyticsNativeComponent> nativeComponent,
@NonNull Deferred<AnalyticsConnector> analyticsConnector) {

Expand Down Expand Up @@ -93,7 +92,7 @@ public class FirebaseCrashlytics {

CrashlyticsAppQualitySessionsSubscriber sessionsSubscriber =
new CrashlyticsAppQualitySessionsSubscriber(arbiter, fileStore);
firebaseSessions.register(sessionsSubscriber);
FirebaseSessionsDependencies.register(sessionsSubscriber);

final CrashlyticsCore core =
new CrashlyticsCore(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.google.firebase.perf.metrics.AppStartTrace;
import com.google.firebase.perf.session.PerfSession;
import com.google.firebase.perf.session.SessionManager;
import com.google.firebase.sessions.FirebaseSessions;
import com.google.firebase.sessions.api.FirebaseSessionsDependencies;
import com.google.firebase.sessions.api.SessionSubscriber;
import java.util.concurrent.Executor;

Expand All @@ -38,10 +38,7 @@
public class FirebasePerfEarly {

public FirebasePerfEarly(
FirebaseApp app,
FirebaseSessions firebaseSessions,
@Nullable StartupTime startupTime,
Executor uiExecutor) {
FirebaseApp app, @Nullable StartupTime startupTime, Executor uiExecutor) {
Context context = app.getApplicationContext();

// Initialize ConfigResolver early for accessing device caching layer.
Expand All @@ -59,7 +56,7 @@ public FirebasePerfEarly(
}

// Register with Firebase sessions to receive updates about session changes.
firebaseSessions.register(
FirebaseSessionsDependencies.register(
new SessionSubscriber() {
@Override
public void onSessionChanged(@NonNull SessionDetails sessionDetails) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public List<Component<?>> getComponents() {
container ->
new FirebasePerfEarly(
container.get(FirebaseApp.class),
container.get(FirebaseSessions.class),
container.getProvider(StartupTime.class).get(),
container.get(uiExecutor)))
.build(),
Expand Down
39 changes: 28 additions & 11 deletions firebase-sessions/api.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
// Signature format: 2.0
package com.google.firebase.sessions {
package com.google.firebase.sessions.api {

public final class FirebaseSessions {
method @NonNull public static com.google.firebase.sessions.FirebaseSessions getInstance();
method @NonNull public static com.google.firebase.sessions.FirebaseSessions getInstance(@NonNull com.google.firebase.FirebaseApp app);
method public void register(@NonNull com.google.firebase.sessions.api.SessionSubscriber subscriber);
property @NonNull public static final com.google.firebase.sessions.FirebaseSessions instance;
field @NonNull public static final com.google.firebase.sessions.FirebaseSessions.Companion Companion;
public final class FirebaseSessionsDependencies {
method public void addDependency(@NonNull com.google.firebase.sessions.api.SessionSubscriber.Name subscriberName);
method public static void register(@NonNull com.google.firebase.sessions.api.SessionSubscriber subscriber);
field @NonNull public static final com.google.firebase.sessions.api.FirebaseSessionsDependencies INSTANCE;
}

public static final class FirebaseSessions.Companion {
method @NonNull public com.google.firebase.sessions.FirebaseSessions getInstance();
method @NonNull public com.google.firebase.sessions.FirebaseSessions getInstance(@NonNull com.google.firebase.FirebaseApp app);
property @NonNull public final com.google.firebase.sessions.FirebaseSessions instance;
public interface SessionSubscriber {
method @NonNull public com.google.firebase.sessions.api.SessionSubscriber.Name getSessionSubscriberName();
method public boolean isDataCollectionEnabled();
method public void onSessionChanged(@NonNull com.google.firebase.sessions.api.SessionSubscriber.SessionDetails sessionDetails);
property public abstract boolean isDataCollectionEnabled;
property @NonNull public abstract com.google.firebase.sessions.api.SessionSubscriber.Name sessionSubscriberName;
}

public enum SessionSubscriber.Name {
method @NonNull public static com.google.firebase.sessions.api.SessionSubscriber.Name valueOf(@NonNull String name) throws java.lang.IllegalArgumentException;
method @NonNull public static com.google.firebase.sessions.api.SessionSubscriber.Name[] values();
enum_constant public static final com.google.firebase.sessions.api.SessionSubscriber.Name CRASHLYTICS;
enum_constant @Discouraged(message="This is for testing purposes only.") public static final com.google.firebase.sessions.api.SessionSubscriber.Name MATT_SAYS_HI;
enum_constant public static final com.google.firebase.sessions.api.SessionSubscriber.Name PERFORMANCE;
}

public static final class SessionSubscriber.SessionDetails {
ctor public SessionSubscriber.SessionDetails(@NonNull String sessionId);
method @NonNull public String component1();
method @NonNull public com.google.firebase.sessions.api.SessionSubscriber.SessionDetails copy(@NonNull String sessionId);
method @NonNull public String getSessionId();
property @NonNull public final String sessionId;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ import android.util.Log
import com.google.firebase.Firebase
import com.google.firebase.FirebaseApp
import com.google.firebase.app
import com.google.firebase.sessions.api.FirebaseSessionsDependencies
import com.google.firebase.sessions.api.SessionSubscriber
import com.google.firebase.sessions.settings.SessionsSettings
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

/** The [FirebaseSessions] API provides methods to register a [SessionSubscriber]. */
class FirebaseSessions
internal constructor(
/** Responsible for initializing AQS */
internal class FirebaseSessions(
private val firebaseApp: FirebaseApp,
private val settings: SessionsSettings,
backgroundDispatcher: CoroutineContext,
Expand Down Expand Up @@ -63,23 +61,6 @@ internal constructor(
}
}

/** Register the [subscriber]. This must be called for every dependency. */
fun register(subscriber: SessionSubscriber) {
if (!settings.sessionsEnabled) {
Log.d(TAG, "Sessions SDK disabled. Ignoring dependency registration.")
return
}

FirebaseSessionsDependencies.register(subscriber)

Log.d(
TAG,
"Registering Sessions SDK subscriber with name: ${subscriber.sessionSubscriberName}, " +
"data collection enabled: ${subscriber.isDataCollectionEnabled}"
)
}

/** Calculate whether we should sample events using [sessionSettings] data. */
companion object {
private const val TAG = "FirebaseSessions"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ object FirebaseSessionsDependencies {
* Register and unlock the subscriber. This must be called before [getRegisteredSubscribers] can
* return.
*/
internal fun register(subscriber: SessionSubscriber) {
@JvmStatic
fun register(subscriber: SessionSubscriber) {
val subscriberName = subscriber.sessionSubscriberName
val dependency = getDependency(subscriberName)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class FirebaseSessionsTest {

// Add a fake dependency and register it, otherwise sessions will never send.
val fakeSessionSubscriber = FakeSessionSubscriber()
FirebaseSessions.instance.register(fakeSessionSubscriber)
FirebaseSessionsDependencies.register(fakeSessionSubscriber)

// Wait for the session start event to send.
Thread.sleep(TIME_TO_LOG_SESSION)
Expand Down
Loading