Repository navigation
Add no-op Analytics, unsupported Cloud Messaging and in-memory Performance Monitoring for the JVM - #88
Merged
Conversation
…mance Monitoring for the JVM
The Firebase Kotlin SDK has so far filled the gap of the three Firebase products this SDK did not port with JVM-only
code of its own. This moves that code here, so that firebase-kotlin-sdk can treat Analytics, Cloud Messaging and
Performance Monitoring like every other module on the JVM: its com.google.firebase sources become header stubs that
are compiled against this jar, verified against it member by member and stripped.
com.google.firebase.analytics is a no-op, as Google Analytics has no client for the JVM: FirebaseAnalytics accepts
and drops events, user properties, the user ID and consent, and its instance and session IDs are null. It comes with
the Event, Param and UserProperty constants, the ConsentType and ConsentStatus enums and the AnalyticsKt facade
(Firebase.analytics, logEvent { } with ParametersBuilder, setConsent { } with ConsentBuilder) of the Android SDK.
com.google.firebase.messaging has the FirebaseMessaging singleton and the MessagingKt facade, but messages are
received through a device registration the JVM does not have, so every operation but isAutoInitEnabled throws an
UnsupportedOperationException saying so. RemoteMessage, its Builder and Notification are an in-memory data holder
backed by a Bundle and read through the keys the Android SDK uses, SendException carries its error codes and
FirebaseMessagingService is a Service subclass whose callbacks are never invoked.
com.google.firebase.perf keeps traces and HTTP metrics in memory: Trace records its metrics (while running, and
atomically) and attributes, HttpMetric its response code, payload sizes, content type and attributes, and nothing is
reported. FirebasePerformance is a process singleton that FirebasePerfRegistrar also registers as a Firebase
component, so FirebaseApp.get(FirebasePerformance.class) works as on Android, and the PerformanceKt facade
(Firebase.performance, trace { }) is included. Trace and RemoteMessage are Parcelable like the Android classes.
For the Analytics items array, android.os.Bundle becomes Parcelable and stores parcelables and parcelable arrays,
which android.os.Parcel now writes and reads as values. Application.getProcessName() is added, as firebase-common
calls it when it reports that no default app is initialized. The version becomes 0.8.3.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Firebase Kotlin SDK has so far filled the gap of the three Firebase products this SDK did not port with JVM-only code of its own. This PR moves that code here as three new hand-written packages, so that firebase-kotlin-sdk can treat Analytics, Cloud Messaging and Performance Monitoring like every other module on the JVM: its
com.google.firebasesources become header stubs that are compiled against this jar, verified against it member by member and stripped. None of the Android AARs is added: firebase-analytics would drag in play-services-measurement, and firebase-messaging and firebase-perf need Android runtime pieces.com.google.firebase.analyticsis a no-op, as Google Analytics has no client for the JVM.FirebaseAnalytics.getInstance(Context)returns a singleton that accepts and drops events, default parameters, user properties, the user ID, the session timeout and consent;getAppInstanceId()andgetSessionId()complete with null andgetFirebaseInstanceId()is null. TheEvent,ParamandUserPropertyconstants, theConsentTypeandConsentStatusenums, the deprecatedsetCurrentScreen(Activity, ...)and theAnalyticsKtfacade of the Android SDK (Firebase.analytics,logEvent(name) { param(...) }withParametersBuilder,setConsent { }withConsentBuilder) are included.Firebase.analyticsneeds the default app, as on Android. OnlyGoogleAnalyticsServerPreviewActivityand the facade's hiddenANALYTICS/LOCKinternals are left out.com.google.firebase.messaginghas theFirebaseMessagingsingleton and theMessagingKtfacade (Firebase.messaging,remoteMessage(to) { }), but messages are received through a device registration a desktop or server JVM does not have, so every operation other thanisAutoInitEnabled(kept in memory) throws anUnsupportedOperationExceptionsaying so:getToken,deleteToken,subscribeToTopic,unsubscribeFromTopic,send, the delivery metrics and notification delegation setters andregister/unregister.RemoteMessage, itsBuilderandNotificationare a real in-memory data holder: the message is backed by aBundleand read through the keys the Android SDK uses (google.to,google.message_id,google.ttl, thegcm.n.*notification entries, the priorities),getData()leaves out the reserved keys like the Android class does, and the message isParcelable.SendExceptioncarries itsERROR_*codes andFirebaseMessagingServiceis aServicesubclass whose callbacks are never invoked.com.google.firebase.perfkeeps traces and HTTP metrics in memory and reports nothing.Tracerecords its metrics only while running and atomically, as the Android class does, and its attributes at any time;HttpMetricrecords the response code, payload sizes, content type and attributes; both expose theMAX_*constants andTraceisParcelable.FirebasePerformanceis a process singleton withnewTrace, bothnewHttpMetricoverloads,startTrace, the in-memoryisPerformanceCollectionEnabledand theHttpMethodconstants, and aFirebasePerfRegistrarregisters it as a Firebase component so thatapp.get(FirebasePerformance.class), which the Kotlin SDK'sFirebase.performance(app)relies on, works as on Android. ThePerformanceKtfacade (Firebase.performance, the threetrace { }forms) and theAddTraceannotation complete the package.Two Android shims grow for this:
android.os.BundlebecomesParcelable(with aCREATOR) and stores parcelables and parcelable arrays, which the Analyticsitemsparameter is, andandroid.os.Parcelwrites and reads parcelable arrays as values.Application.getProcessName()is added because firebase-common calls it when it reports that no default app is initialized, which surfaced as aNoSuchMethodErrorinstead of theIllegalStateException.The signatures were verified against the Android SDK's
api.txtthrough firebase-kotlin-sdk's header-stub verifier: in a worktree of itsv3.0.0branch pointing at this build published to mavenLocal as 0.8.3, the three modules were switched to ordinary header stubs on the JVM (the Android stubs shared withjvmMain, the JVM-only implementations deleted), andcompileKotlinJvm,jvmTestandapiCheckoffirebase-analytics,firebase-messagingandfirebase-perfpass, every stub member found on this jar with the same JVM signature and static-ness. Here,./gradlew buildpasses with the Firebase emulator running (144 tests, including new tests for the three packages,BundleandParcel), and the README lists the three products and their behaviour. The version becomes 0.8.3.