-
Notifications
You must be signed in to change notification settings - Fork 617
Migrate fireperf content provider to component #4242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
f2c4fdb
a495cb7
c2d7476
b4f9ccc
8071823
fd7c0e3
18b98fb
b32aa04
14235e2
f074d74
23b36d4
9e31558
ea9339c
5e10d8f
e7c4f34
7d8062b
66a5f05
1f668dd
b5af211
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2022 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; | ||
|
||
import android.os.SystemClock; | ||
import com.google.auto.value.AutoValue; | ||
|
||
/** | ||
* Represents the time at which Firebase began initialization, both in unix time/epoch milliseconds | ||
* and in milliseconds since boot. The absence of a StartupTime indicates an unreliable or | ||
* misleading time, such as a launch in direct boot mode. Because of this, StartupTime cannot be | ||
* guaranteed to be present, and instead should be optionally depended on, and its absence handled. | ||
*/ | ||
@AutoValue | ||
public abstract class StartupTime { | ||
|
||
/** @return The epoch time that Firebase began initializing, in milliseconds */ | ||
public abstract long getEpochMillis(); | ||
|
||
/** @return The number of milliseconds from boot to when Firebase began initializing */ | ||
public abstract long getElapsedRealtime(); | ||
|
||
/** | ||
* @param epochMillis Time in milliseconds since epoch | ||
* @param elapsedRealtime Time in milliseconds since boot | ||
*/ | ||
public static StartupTime create(long epochMillis, long elapsedRealtime) { | ||
return new AutoValue_StartupTime(epochMillis, elapsedRealtime); | ||
} | ||
|
||
/** @return A StartupTime represented by the current epoch time and JVM nano time */ | ||
public static StartupTime now() { | ||
return create(System.currentTimeMillis(), SystemClock.elapsedRealtime()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2022 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 android.content.Context; | ||
import android.os.Handler; | ||
import android.os.Looper; | ||
import com.google.firebase.FirebaseApp; | ||
import com.google.firebase.StartupTime; | ||
import com.google.firebase.perf.application.AppStateMonitor; | ||
import com.google.firebase.perf.config.ConfigResolver; | ||
import com.google.firebase.perf.metrics.AppStartTrace; | ||
import com.google.firebase.perf.session.SessionManager; | ||
|
||
/** | ||
* The Firebase Performance early initialization. | ||
* | ||
* <p>Responsible for initializing the AppStartTrace, and early initialization of ConfigResolver | ||
*/ | ||
public class FirebasePerfEarly { | ||
private final Handler mainHandler = new Handler(Looper.getMainLooper()); | ||
|
||
public FirebasePerfEarly(FirebaseApp app) { | ||
Context context = app.getApplicationContext(); | ||
|
||
// Initialize ConfigResolver early for accessing device caching layer. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vkryachko I wonder if we could merge the 2-part initialization ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have full context on why the 2-part logic was in place, but my understanding that part of it was to speed up the SDK and delay a lot of work as much as possible(i.e. see #2518). But I trust your judgement to evolve this in a way that makes sense, after this initial migration. Happy to discuss it more. |
||
ConfigResolver configResolver = ConfigResolver.getInstance(); | ||
configResolver.setApplicationContext(context); | ||
|
||
AppStateMonitor appStateMonitor = AppStateMonitor.getInstance(); | ||
appStateMonitor.registerActivityLifecycleCallbacks(context); | ||
appStateMonitor.registerForAppColdStart(new FirebasePerformanceInitializer()); | ||
|
||
if (app.get(StartupTime.class) != null) { | ||
AppStartTrace appStartTrace = AppStartTrace.getInstance(); | ||
appStartTrace.registerActivityLifecycleCallbacks(context); | ||
mainHandler.post(new AppStartTrace.StartFromBackgroundRunnable(appStartTrace)); | ||
} | ||
|
||
// In the case of cold start, we create a session and start collecting gauges as early as | ||
// possible. | ||
// There is code in SessionManager that prevents us from resetting the session twice in case | ||
// of app cold start. | ||
SessionManager.getInstance().initializeGaugeCollection(); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.