18
18
import android .content .Context ;
19
19
import androidx .annotation .Keep ;
20
20
import androidx .annotation .VisibleForTesting ;
21
- import com .google .firebase .perf .application .AppStateMonitor ;
22
21
import com .google .firebase .perf .logging .FirebaseSessionsEnforcementCheck ;
23
22
import com .google .firebase .perf .session .gauges .GaugeManager ;
24
- import com .google .firebase .perf .v1 .ApplicationProcessState ;
25
23
import com .google .firebase .perf .v1 .GaugeMetadata ;
26
24
import com .google .firebase .perf .v1 .GaugeMetric ;
27
25
import java .lang .ref .WeakReference ;
@@ -37,7 +35,6 @@ public class SessionManager {
37
35
private static final SessionManager instance = new SessionManager ();
38
36
39
37
private final GaugeManager gaugeManager ;
40
- private final AppStateMonitor appStateMonitor ;
41
38
private final Set <WeakReference <SessionAwareObject >> clients = new HashSet <>();
42
39
43
40
private PerfSession perfSession ;
@@ -49,23 +46,20 @@ public static SessionManager getInstance() {
49
46
50
47
/** Returns the currently active PerfSession. */
51
48
public final PerfSession perfSession () {
52
- FirebaseSessionsEnforcementCheck .checkSession (
53
- perfSession , "Access perf session from manger without aqs ready" );
49
+ FirebaseSessionsEnforcementCheck .checkSession (perfSession , "PerfSession.perfSession()" );
54
50
55
51
return perfSession ;
56
52
}
57
53
58
54
private SessionManager () {
59
55
// session should quickly updated by session subscriber.
60
- this (GaugeManager .getInstance (), PerfSession .createWithId (null ), AppStateMonitor . getInstance () );
56
+ this (GaugeManager .getInstance (), PerfSession .createWithId (null ));
61
57
}
62
58
63
59
@ VisibleForTesting
64
- public SessionManager (
65
- GaugeManager gaugeManager , PerfSession perfSession , AppStateMonitor appStateMonitor ) {
60
+ public SessionManager (GaugeManager gaugeManager , PerfSession perfSession ) {
66
61
this .gaugeManager = gaugeManager ;
67
62
this .perfSession = perfSession ;
68
- this .appStateMonitor = appStateMonitor ;
69
63
}
70
64
71
65
/**
@@ -83,8 +77,7 @@ public void setApplicationContext(final Context appContext) {
83
77
*/
84
78
public void stopGaugeCollectionIfSessionRunningTooLong () {
85
79
FirebaseSessionsEnforcementCheck .checkSession (
86
- perfSession ,
87
- "Session is not ready while trying to stopGaugeCollectionIfSessionRunningTooLong" );
80
+ perfSession , "SessionManager.stopGaugeCollectionIfSessionRunningTooLong" );
88
81
89
82
if (perfSession .isSessionRunningTooLong ()) {
90
83
gaugeManager .stopCollectingGauges ();
@@ -123,7 +116,7 @@ public void updatePerfSession(PerfSession perfSession) {
123
116
}
124
117
125
118
// Start of stop the gauge data collection.
126
- startOrStopCollectingGauges (appStateMonitor . getAppState () );
119
+ startOrStopCollectingGauges ();
127
120
}
128
121
129
122
/**
@@ -133,7 +126,7 @@ public void updatePerfSession(PerfSession perfSession) {
133
126
* this does not reset the perfSession.
134
127
*/
135
128
public void initializeGaugeCollection () {
136
- startOrStopCollectingGauges (ApplicationProcessState . FOREGROUND );
129
+ startOrStopCollectingGauges ();
137
130
}
138
131
139
132
/**
@@ -160,12 +153,11 @@ public void unregisterForSessionUpdates(WeakReference<SessionAwareObject> client
160
153
}
161
154
}
162
155
163
- private void startOrStopCollectingGauges (ApplicationProcessState appState ) {
164
- FirebaseSessionsEnforcementCheck .checkSession (
165
- perfSession , "Session is not ready while trying to startOrStopCollectingGauges" );
156
+ private void startOrStopCollectingGauges () {
157
+ FirebaseSessionsEnforcementCheck .checkSession (perfSession , "startOrStopCollectingGauges" );
166
158
167
- if (perfSession .isGaugeAndEventCollectionEnabled ()) {
168
- gaugeManager .startCollectingGauges (perfSession , appState );
159
+ if (perfSession .isVerbose ()) {
160
+ gaugeManager .startCollectingGauges (perfSession );
169
161
} else {
170
162
gaugeManager .stopCollectingGauges ();
171
163
}
0 commit comments