@@ -24,6 +24,8 @@ namespace Firebase.VertexAI.Internal {
24
24
25
25
// Contains internal helper methods for interacting with other Firebase libraries.
26
26
internal static class FirebaseInterops {
27
+ // The cached fields for FirebaseApp reflection.
28
+ private static PropertyInfo _dataCollectionProperty = null ;
27
29
28
30
// The various App Check types needed to retrieve the token, cached via reflection on startup.
29
31
private static Type _appCheckType ;
@@ -48,6 +50,7 @@ internal static class FirebaseInterops {
48
50
private const string authHeader = "Authorization" ;
49
51
50
52
static FirebaseInterops ( ) {
53
+ InitializeAppReflection ( ) ;
51
54
InitializeAppCheckReflection ( ) ;
52
55
InitializeAuthReflection ( ) ;
53
56
}
@@ -58,6 +61,72 @@ private static void LogError(string message) {
58
61
#endif
59
62
}
60
63
64
+ // Cache the methods needed for FirebaseApp reflection.
65
+ private static void InitializeAppReflection ( ) {
66
+ try {
67
+ _dataCollectionProperty = typeof ( FirebaseApp ) . GetProperty (
68
+ "IsDataCollectionDefaultEnabled" ,
69
+ BindingFlags . Instance | BindingFlags . NonPublic ) ;
70
+ if ( _dataCollectionProperty == null ) {
71
+ LogError ( "Could not find FirebaseApp.IsDataCollectionDefaultEnabled property via reflection." ) ;
72
+ return ;
73
+ }
74
+ if ( _dataCollectionProperty . PropertyType != typeof ( bool ) ) {
75
+ LogError ( "FirebaseApp.IsDataCollectionDefaultEnabled is not a bool, " +
76
+ $ "but is { _dataCollectionProperty . PropertyType } ") ;
77
+ return ;
78
+ }
79
+ } catch ( Exception e ) {
80
+ LogError ( $ "Failed to initialize FirebaseApp reflection: { e } ") ;
81
+ }
82
+ }
83
+
84
+ // Gets the property FirebaseApp.IsDataCollectionDefaultEnabled.
85
+ public static bool GetIsDataCollectionDefaultEnabled ( FirebaseApp firebaseApp ) {
86
+ if ( firebaseApp == null || _dataCollectionProperty == null ) {
87
+ return false ;
88
+ }
89
+
90
+ try {
91
+ return ( bool ) _dataCollectionProperty . GetValue ( firebaseApp ) ;
92
+ } catch ( Exception e ) {
93
+ LogError ( $ "Error accessing 'IsDataCollectionDefaultEnabled': { e } ") ;
94
+ return false ;
95
+ }
96
+ }
97
+
98
+ // SDK version to use if unable to find it.
99
+ private const string _unknownSdkVersion = "unknown" ;
100
+ private static readonly Lazy < string > _sdkVersionFetcher = new ( ( ) => {
101
+ try {
102
+ // Get the type Firebase.VersionInfo from the assembly that defines FirebaseApp.
103
+ Type versionInfoType = typeof ( FirebaseApp ) . Assembly . GetType ( "Firebase.VersionInfo" ) ;
104
+ if ( versionInfoType == null ) {
105
+ LogError ( "Firebase.VersionInfo type not found via reflection" ) ;
106
+ return _unknownSdkVersion ;
107
+ }
108
+
109
+ // Firebase.VersionInfo.SdkVersion
110
+ PropertyInfo sdkVersionProperty = versionInfoType . GetProperty (
111
+ "SdkVersion" ,
112
+ BindingFlags . Static | BindingFlags . NonPublic ) ;
113
+ if ( sdkVersionProperty == null ) {
114
+ LogError ( "Firebase.VersionInfo.SdkVersion property not found via reflection." ) ;
115
+ return _unknownSdkVersion ;
116
+ }
117
+
118
+ return sdkVersionProperty . GetValue ( null ) as string ?? _unknownSdkVersion ;
119
+ } catch ( Exception e ) {
120
+ LogError ( $ "Error accessing SdkVersion via reflection: { e } ") ;
121
+ return _unknownSdkVersion ;
122
+ }
123
+ } ) ;
124
+
125
+ // Gets the internal property Firebase.VersionInfo.SdkVersion
126
+ internal static string GetVersionInfoSdkVersion ( ) {
127
+ return _sdkVersionFetcher . Value ;
128
+ }
129
+
61
130
// Cache the various types and methods needed for AppCheck token retrieval.
62
131
private static void InitializeAppCheckReflection ( ) {
63
132
const string firebaseAppCheckTypeName = "Firebase.AppCheck.FirebaseAppCheck, Firebase.AppCheck" ;
@@ -301,7 +370,6 @@ internal static async Task AddFirebaseTokensAsync(ClientWebSocket socket, Fireba
301
370
socket . Options . SetRequestHeader ( authHeader , $ "Firebase { authToken } ") ;
302
371
}
303
372
}
304
-
305
373
}
306
374
307
375
}
0 commit comments