51
51
52
52
#if defined(__ANDROID__)
53
53
#include " app/src/google_play_services/availability_android.h"
54
+ #include " app/src/app_android.h"
54
55
#endif // defined(__ANDROID__)
55
56
56
57
namespace firebase {
@@ -167,6 +168,35 @@ static void LogHeartbeatForDesktop(App* app) {
167
168
#endif // FIREBASE_PLATFORM_DESKTOP
168
169
}
169
170
171
+ static void RegisterLibrariesHelper (
172
+ const std::map<std::string, std::string>& libraries) {
173
+ #if FIREBASE_PLATFORM_ANDROID
174
+ JNIEnv* jni_env;
175
+ jobject activity_local_ref = UnityGetActivity (&jni_env);
176
+ firebase::CallAfterEnsureMethodsCached (
177
+ jni_env, activity_local_ref, [&libraries, &jni_env](){
178
+ for (std::map<std::string, std::string>::const_iterator it =
179
+ libraries.begin (); it != libraries.end (); ++it) {
180
+ const std::string& library = it->first ;
181
+ const std::string& version = it->second ;
182
+ firebase::App::RegisterLibrary (library.c_str (),
183
+ version.c_str (),
184
+ jni_env);
185
+ }
186
+ });
187
+ jni_env->DeleteLocalRef (activity_local_ref);
188
+ #else
189
+ for (std::map<std::string, std::string>::const_iterator it =
190
+ libraries.begin (); it != libraries.end (); ++it) {
191
+ const std::string& library = it->first ;
192
+ const std::string& version = it->second ;
193
+ firebase::App::RegisterLibrary (library.c_str (),
194
+ version.c_str (),
195
+ nullptr );
196
+ }
197
+ #endif
198
+ }
199
+
170
200
// Decrease the reference count for the app. When the reference count reaches
171
201
// 0, the App will be deleted.
172
202
static void AppReleaseReference (App* app) {
@@ -821,6 +851,8 @@ static firebase::AppOptions* AppOptionsLoadFromJsonConfig(const char* config) {
821
851
// Whether Crashlytics initialization has been attempted.
822
852
private static bool crashlyticsInitializationAttempted = false ;
823
853
854
+ private static bool userAgentRegistered = false ;
855
+
824
856
// Instantiates a C++ App and returns a reference to the C# proxy.
825
857
// existingProxy is required here to prevent the finalizer being executed
826
858
// while we're creating a new FirebaseApp proxy.
@@ -832,7 +864,28 @@ static firebase::AppOptions* AppOptionsLoadFromJsonConfig(const char* config) {
832
864
Firebase.Platform .FirebaseHandler .Create (
833
865
Firebase.Platform .FirebaseAppUtils .Instance );
834
866
FirebaseApp newProxy;
867
+
835
868
lock (nameToProxy) {
869
+ // If this is the first App, register library information.
870
+ if (!userAgentRegistered) {
871
+ userAgentRegistered = true ;
872
+ var userAgentMap = new StringStringMap ();
873
+
874
+ // fire-(unity|mono)/<sdk_version>
875
+ var libraryPrefix = " fire-" +
876
+ Firebase.Platform .PlatformInformation .RuntimeName ;
877
+ userAgentMap[libraryPrefix] =
878
+ Firebase.VersionInfo .SdkVersion ;
879
+ // fire-(unity|mono)-ver/<unity|mono_version>
880
+ userAgentMap[libraryPrefix + " -ver" ] =
881
+ Firebase.Platform .PlatformInformation .RuntimeVersion ;
882
+ // fire-(unity|mono)/<github-action-built|custom_built>
883
+ userAgentMap[libraryPrefix + " -buildsrc" ] =
884
+ Firebase.VersionInfo .BuildSource ;
885
+
886
+ RegisterLibrariesInternal (userAgentMap);
887
+ }
888
+
836
889
InitializeAppUtilCallbacks ();
837
890
var cPtrHandleRef = new System.Runtime .InteropServices .HandleRef (
838
891
null, System.IntPtr .Zero );
@@ -903,22 +956,10 @@ static firebase::AppOptions* AppOptionsLoadFromJsonConfig(const char* config) {
903
956
return existingProxyForNewApp;
904
957
}
905
958
}
906
- // If this is the first App, register library information.
907
- if (cPtrToProxy.Count == 0 ) {
908
- // fire-(unity|mono)/<sdk_version>
909
- var libraryPrefix = " fire-" +
910
- Firebase.Platform .PlatformInformation .RuntimeName ;
911
- RegisterLibraryInternal (libraryPrefix, Firebase.VersionInfo .SdkVersion );
912
- // fire-(unity|mono)-ver/<unity|mono_version>
913
- RegisterLibraryInternal (
914
- libraryPrefix + " -ver" ,
915
- Firebase.Platform .PlatformInformation .RuntimeVersion );
916
- // fire-(unity|mono)/<github-action-built|custom_built>
917
- RegisterLibraryInternal (
918
- libraryPrefix + " -buildsrc" , Firebase.VersionInfo .BuildSource );
919
- // Log a heartbeat after all Unity user agents have been registered.
920
- LogHeartbeatInternal (newProxy);
921
- }
959
+
960
+ // Log a heartbeat after all Unity user agents have been registered.
961
+ LogHeartbeatInternal (newProxy);
962
+
922
963
// Cache the name so that it can be accessed after the app is disposed.
923
964
newProxy.name = newProxy.NameInternal ;
924
965
// By default the newly created proxy doesn't own the C++ app, take
@@ -1320,9 +1361,9 @@ namespace callback {
1320
1361
return firebase::GetLogLevel ();
1321
1362
}
1322
1363
1323
- %csmethodmodifiers RegisterLibraryInternal () " internal" ;
1324
- static void RegisterLibraryInternal ( const char * library, const char * version ) {
1325
- firebase::App::RegisterLibrary (library, version );
1364
+ %csmethodmodifiers RegisterLibrariesInternal () " internal" ;
1365
+ static void RegisterLibrariesInternal (std::map<std::string, std::string> libraries ) {
1366
+ firebase::RegisterLibrariesHelper (libraries );
1326
1367
}
1327
1368
1328
1369
%csmethodmodifiers LogHeartbeatInternal (App* app) " internal" ;
0 commit comments