34
34
import com .google .firebase .perf .config .RemoteConfigManager ;
35
35
import com .google .firebase .perf .logging .AndroidLogger ;
36
36
import com .google .firebase .perf .logging .ConsoleUrlGenerator ;
37
+ import com .google .firebase .perf .logging .FirebaseSessionsEnforcementCheck ;
37
38
import com .google .firebase .perf .metrics .HttpMetric ;
38
39
import com .google .firebase .perf .metrics .Trace ;
40
+ import com .google .firebase .perf .session .FirebasePerformanceSessionSubscriber ;
39
41
import com .google .firebase .perf .session .SessionManager ;
40
42
import com .google .firebase .perf .transport .TransportManager ;
41
43
import com .google .firebase .perf .util .Constants ;
42
44
import com .google .firebase .perf .util .ImmutableBundle ;
43
45
import com .google .firebase .perf .util .Timer ;
44
46
import com .google .firebase .remoteconfig .RemoteConfigComponent ;
47
+ import com .google .firebase .sessions .api .FirebaseSessionsDependencies ;
48
+ import com .google .firebase .sessions .api .SessionSubscriber ;
45
49
import java .lang .annotation .Retention ;
46
50
import java .lang .annotation .RetentionPolicy ;
47
51
import java .net .URL ;
@@ -92,6 +96,8 @@ public class FirebasePerformance implements FirebasePerformanceAttributable {
92
96
// once during initialization and cache it.
93
97
private final ImmutableBundle mMetadataBundle ;
94
98
99
+ private final SessionSubscriber sessionSubscriber ;
100
+
95
101
/** Valid HttpMethods for manual network APIs */
96
102
@ StringDef ({
97
103
HttpMethod .GET ,
@@ -136,11 +142,6 @@ public static FirebasePerformance getInstance() {
136
142
// to false if it's been force disabled or it is set to null if neither.
137
143
@ Nullable private Boolean mPerformanceCollectionForceEnabledState = null ;
138
144
139
- private final FirebaseApp firebaseApp ;
140
- private final Provider <RemoteConfigComponent > firebaseRemoteConfigProvider ;
141
- private final FirebaseInstallationsApi firebaseInstallationsApi ;
142
- private final Provider <TransportFactory > transportFactoryProvider ;
143
-
144
145
/**
145
146
* Constructs the FirebasePerformance class and allows injecting dependencies.
146
147
*
@@ -166,23 +167,19 @@ public static FirebasePerformance getInstance() {
166
167
ConfigResolver configResolver ,
167
168
SessionManager sessionManager ) {
168
169
169
- this .firebaseApp = firebaseApp ;
170
- this .firebaseRemoteConfigProvider = firebaseRemoteConfigProvider ;
171
- this .firebaseInstallationsApi = firebaseInstallationsApi ;
172
- this .transportFactoryProvider = transportFactoryProvider ;
173
-
174
170
if (firebaseApp == null ) {
175
171
this .mPerformanceCollectionForceEnabledState = false ;
176
172
this .configResolver = configResolver ;
177
173
this .mMetadataBundle = new ImmutableBundle (new Bundle ());
174
+ this .sessionSubscriber = new FirebasePerformanceSessionSubscriber (false );
178
175
return ;
179
176
}
177
+ FirebaseSessionsEnforcementCheck .setEnforcement (BuildConfig .ENFORCE_LEGACY_SESSIONS );
180
178
181
179
TransportManager .getInstance ()
182
180
.initialize (firebaseApp , firebaseInstallationsApi , transportFactoryProvider );
183
181
184
182
Context appContext = firebaseApp .getApplicationContext ();
185
- // TODO(b/110178816): Explore moving off of main thread.
186
183
mMetadataBundle = extractMetadata (appContext );
187
184
188
185
remoteConfigManager .setFirebaseRemoteConfigProvider (firebaseRemoteConfigProvider );
@@ -192,6 +189,9 @@ public static FirebasePerformance getInstance() {
192
189
sessionManager .setApplicationContext (appContext );
193
190
194
191
mPerformanceCollectionForceEnabledState = configResolver .getIsPerformanceCollectionEnabled ();
192
+ sessionSubscriber = new FirebasePerformanceSessionSubscriber (isPerformanceCollectionEnabled ());
193
+ FirebaseSessionsDependencies .register (sessionSubscriber );
194
+
195
195
if (logger .isLogcatEnabled () && isPerformanceCollectionEnabled ()) {
196
196
logger .info (
197
197
String .format (
@@ -282,7 +282,7 @@ public synchronized void setPerformanceCollectionEnabled(@Nullable Boolean enabl
282
282
return ;
283
283
}
284
284
285
- if (configResolver .getIsPerformanceCollectionDeactivated ()) {
285
+ if (Boolean . TRUE . equals ( configResolver .getIsPerformanceCollectionDeactivated () )) {
286
286
logger .info ("Firebase Performance is permanently disabled" );
287
287
return ;
288
288
}
@@ -466,4 +466,9 @@ private static ImmutableBundle extractMetadata(Context appContext) {
466
466
Boolean getPerformanceCollectionForceEnabledState () {
467
467
return mPerformanceCollectionForceEnabledState ;
468
468
}
469
+
470
+ @ VisibleForTesting
471
+ SessionSubscriber getSessionSubscriber () {
472
+ return sessionSubscriber ;
473
+ }
469
474
}
0 commit comments