forked from firebase/firebase-android-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirebasePerfRegistrar.java
More file actions
119 lines (112 loc) · 5.38 KB
/
FirebasePerfRegistrar.java
File metadata and controls
119 lines (112 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
//
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.firebase.perf;
import androidx.annotation.Keep;
import com.google.android.datatransport.TransportFactory;
import com.google.firebase.FirebaseApp;
import com.google.firebase.StartupTime;
import com.google.firebase.annotations.concurrent.UiThread;
import com.google.firebase.components.Component;
import com.google.firebase.components.ComponentContainer;
import com.google.firebase.components.ComponentRegistrar;
import com.google.firebase.components.Dependency;
import com.google.firebase.components.Qualified;
import com.google.firebase.installations.FirebaseInstallationsApi;
import com.google.firebase.perf.injection.components.DaggerFirebasePerformanceComponent;
import com.google.firebase.perf.injection.components.FirebasePerformanceComponent;
import com.google.firebase.perf.injection.modules.FirebasePerformanceModule;
import com.google.firebase.perf.session.PerfSession;
import com.google.firebase.perf.session.SessionManager;
import com.google.firebase.perf.session.gauges.GaugeManager;
import com.google.firebase.platforminfo.LibraryVersionComponent;
import com.google.firebase.remoteconfig.RemoteConfigComponent;
import com.google.firebase.sessions.api.FirebaseSessionsDependencies;
import com.google.firebase.sessions.api.SessionSubscriber;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Executor;
/**
* {@link com.google.firebase.components.ComponentRegistrar} for the Firebase Performance SDK.
*
* <p>See go/firebase-android-components and go/firebase-components-android-integration-guide for
* more details.
*
* @hide
*/
@Keep
public class FirebasePerfRegistrar implements ComponentRegistrar {
private static final String LIBRARY_NAME = "fire-perf";
private static final String EARLY_LIBRARY_NAME = "fire-perf-early";
static {
// Add Firebase Performance as a dependency of Sessions when this class is loaded into memory.
FirebaseSessionsDependencies.addDependency(SessionSubscriber.Name.PERFORMANCE);
}
@Override
@Keep
public List<Component<?>> getComponents() {
Qualified<Executor> uiExecutor = Qualified.qualified(UiThread.class, Executor.class);
return Arrays.asList(
Component.builder(FirebasePerformance.class)
.name(LIBRARY_NAME)
.add(Dependency.required(FirebaseApp.class))
.add(Dependency.requiredProvider(RemoteConfigComponent.class))
.add(Dependency.required(FirebaseInstallationsApi.class))
.add(Dependency.requiredProvider(TransportFactory.class))
.add(Dependency.required(FirebasePerfEarly.class))
.add(Dependency.required(SessionManager.class))
.factory(FirebasePerfRegistrar::providesFirebasePerformance)
.build(),
Component.builder(FirebasePerfEarly.class)
.name(EARLY_LIBRARY_NAME)
.add(Dependency.required(FirebaseApp.class))
.add(Dependency.optionalProvider(StartupTime.class))
.add(Dependency.required(uiExecutor))
.add(Dependency.required(SessionManager.class))
.eagerInDefaultApp()
.factory(
container ->
new FirebasePerfEarly(
container.get(FirebaseApp.class),
container.getProvider(StartupTime.class).get(),
container.get(uiExecutor),
container.get(SessionManager.class)))
.build(),
Component.builder(SessionManager.class)
.factory(container -> SessionManager.getInstance())
.build(),
/**
* Fireperf SDK is lazily by {@link FirebasePerformanceInitializer} during {@link
* com.google.firebase.perf.application.AppStateMonitor#onActivityResumed(Activity)}. we use
* "lazy" dependency for some components that are not required during initialization so as
* not to force initialize them at app startup (refer
* https://github.com/google/guice/wiki/InjectingProviders#providers-for-lazy-loading)*
*/
LibraryVersionComponent.create(LIBRARY_NAME, BuildConfig.VERSION_NAME));
}
private static FirebasePerformance providesFirebasePerformance(ComponentContainer container) {
// Ensure FirebasePerfEarly was initialized
container.get(FirebasePerfEarly.class);
FirebasePerformanceComponent component =
DaggerFirebasePerformanceComponent.builder()
.firebasePerformanceModule(
new FirebasePerformanceModule(
container.get(FirebaseApp.class),
container.get(FirebaseInstallationsApi.class),
container.getProvider(RemoteConfigComponent.class),
container.getProvider(TransportFactory.class),
container.get(SessionManager.class)))
.build();
return component.getFirebasePerformance();
}
}