Skip to content

Commit 8f2d30e

Browse files
authored
openStream should not be intercepted if Firebase Perf is not initialized (#5885)
Proposed fix for #5584: ### Issue Crash happens if a URL connection is opened e.g. `url.openStream()` when `TransportManager` has not been initialized. If developer wants to programmatically enable Firebase using FirebaseOptions, but have included the Firebase Perf plugin, the app will crash after doing a network call. ### Steps to reproduce 1. Add Firebase perf plugin - Module `build.gradle` ``` plugins { alias(libs.plugins.android.application) apply false alias(libs.plugins.jetbrains.kotlin.android) apply false id("com.google.gms.google-services") version "4.4.1" apply false id("com.google.firebase.firebase-perf") version "1.4.2" apply false } ``` - App `build.gradle` ``` plugins { alias(libs.plugins.android.application) alias(libs.plugins.jetbrains.kotlin.android) id("com.google.gms.google-services") id("com.google.firebase.firebase-perf") } ``` 2. Disable Firebase ```xml <provider android:name="com.google.firebase.provider.FirebaseInitProvider" android:authorities="${applicationId}.firebaseinitprovider" tools:node="remove" /> ``` 3. Do a network call ``` val url = URL("https", "www.amazon.com", 443, "") val inputStream = url.openStream() ``` ### Investigation 1. `openStream` in `FirebasePerfUrlConnection` intercepts all urls that opens connections. 5. `openStream` requires `TransportManager` to be initialized 6. `TransportManager` is only initialized after `FirebasePerformance` has been initialized ### Solution If `TransportManager` is not initialized, we should simply return the URL openStream and not intercept the connection.
1 parent bb0823f commit 8f2d30e

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

firebase-perf/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Unreleased
2-
2+
[fixed] Fixed an `ExceptionInInitializerError` where the `url.openStream()` causes a crash if
3+
FirebasePerf is not yet initialized.
34

45
# 20.5.2
56
* [changed] Bump internal dependencies.

firebase-perf/src/main/java/com/google/firebase/perf/network/FirebasePerfUrlConnection.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public static InputStream openStream(final URL url) throws IOException {
5858
*/
5959
static InputStream openStream(URLWrapper wrapper, TransportManager transportManager, Timer timer)
6060
throws IOException {
61+
if (!TransportManager.getInstance().isInitialized()) {
62+
return wrapper.openConnection().getInputStream();
63+
}
6164
timer.reset();
6265
long startTime = timer.getMicros();
6366
NetworkRequestMetricBuilder builder = NetworkRequestMetricBuilder.builder(transportManager);

0 commit comments

Comments
 (0)