Skip to content

Commit 7b72c82

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents b902407 + 39ce055 commit 7b72c82

File tree

72 files changed

+2029
-1744
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2029
-1744
lines changed

firebase-perf/src/main/java/com/google/firebase/perf/FirebasePerfRegistrar.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,14 @@ public List<Component<?>> getComponents() {
5252
.add(Dependency.required(FirebaseInstallationsApi.class))
5353
.add(Dependency.requiredProvider(TransportFactory.class))
5454
.factory(FirebasePerfRegistrar::providesFirebasePerformance)
55-
// Since the SDK is eager(auto starts at app start), we use "lazy" dependency for some
56-
// components that are not required during initialization so as not to force initialize
57-
// them at app startup (refer
58-
// https://github.com/google/guice/wiki/InjectingProviders#providers-for-lazy-loading).
59-
.eagerInDefaultApp()
6055
.build(),
56+
/**
57+
* Fireperf SDK is lazily by {@link FirebasePerformanceInitializer} during {@link
58+
* com.google.firebase.perf.application.AppStateMonitor#onActivityResumed(Activity)}. we use
59+
* "lazy" dependency for some components that are not required during initialization so as
60+
* not to force initialize them at app startup (refer
61+
* https://github.com/google/guice/wiki/InjectingProviders#providers-for-lazy-loading)*
62+
*/
6163
LibraryVersionComponent.create("fire-perf", BuildConfig.VERSION_NAME));
6264
}
6365

firebase-perf/src/main/java/com/google/firebase/perf/FirebasePerformance.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import com.google.firebase.perf.metrics.HttpMetric;
3535
import com.google.firebase.perf.metrics.Trace;
3636
import com.google.firebase.perf.metrics.validator.PerfMetricValidator;
37-
import com.google.firebase.perf.session.GaugeManager;
37+
import com.google.firebase.perf.session.gauges.GaugeManager;
3838
import com.google.firebase.perf.transport.TransportManager;
3939
import com.google.firebase.perf.util.Constants;
4040
import com.google.firebase.perf.util.ImmutableBundle;
@@ -180,15 +180,15 @@ public static FirebasePerformance getInstance() {
180180
TransportManager.getInstance()
181181
.initialize(firebaseApp, firebaseInstallationsApi, transportFactoryProvider);
182182

183-
Context context = firebaseApp.getApplicationContext();
183+
Context appContext = firebaseApp.getApplicationContext();
184184
// TODO(b/110178816): Explore moving off of main thread.
185-
mMetadataBundle = extractMetadata(context);
185+
mMetadataBundle = extractMetadata(appContext);
186186

187187
remoteConfigManager.setFirebaseRemoteConfigProvider(firebaseRemoteConfigProvider);
188188
this.configResolver = configResolver;
189189
this.configResolver.setMetadataBundle(mMetadataBundle);
190-
this.configResolver.setApplicationContext(context);
191-
gaugeManager.setApplicationContext(context);
190+
this.configResolver.setApplicationContext(appContext);
191+
gaugeManager.setApplicationContext(appContext);
192192

193193
mPerformanceCollectionForceEnabledState = configResolver.getIsPerformanceCollectionEnabled();
194194
}
@@ -444,16 +444,16 @@ public HttpMetric newHttpMetric(@NonNull URL url, @NonNull @HttpMethod String ht
444444
/**
445445
* Extracts the metadata bundle from the ApplicationContext.
446446
*
447-
* @param context The ApplicationContext.
447+
* @param appContext The ApplicationContext.
448448
* @return A shallow copy of the bundle containing the metadata extracted from the context.
449449
*/
450-
private static ImmutableBundle extractMetadata(Context context) {
450+
private static ImmutableBundle extractMetadata(Context appContext) {
451451
Bundle bundle = null;
452452
try {
453453
ApplicationInfo ai =
454-
context
454+
appContext
455455
.getPackageManager()
456-
.getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
456+
.getApplicationInfo(appContext.getPackageName(), PackageManager.GET_META_DATA);
457457

458458
bundle = ai.metaData;
459459
} catch (NameNotFoundException | NullPointerException e) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2021 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.perf;
16+
17+
import com.google.firebase.perf.application.AppStateMonitor;
18+
19+
/**
20+
* FirebasePerformanceInitializer to initialize FirebasePerformance during app cold start
21+
*
22+
* @hide
23+
*/
24+
/** @hide */
25+
public final class FirebasePerformanceInitializer implements AppStateMonitor.AppColdStartCallback {
26+
27+
/** @hide */
28+
@Override
29+
public void onAppColdStart() {
30+
// Initialize FirebasePerformance when app cold starts.
31+
FirebasePerformance.getInstance();
32+
}
33+
}

0 commit comments

Comments
 (0)