File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed
src/main/java/com/google/firebase/remoteconfig/internal Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change 1
1
# Unreleased
2
-
2
+ * [ fixed ] Fixed ` NetworkOnMainThreadException ` on Android versions below 8 by disconnecting HttpURLConnection only on API levels 26 and higher.
3
3
4
4
# 22.1.1
5
- [ fixed] Fixed an issue where the connection to the real-time Remote Config backend could remain
5
+ * [ fixed] Fixed an issue where the connection to the real-time Remote Config backend could remain
6
6
open in the background.
7
7
8
8
Original file line number Diff line number Diff line change 22
22
import android .annotation .SuppressLint ;
23
23
import android .content .Context ;
24
24
import android .content .pm .PackageManager ;
25
+ import android .os .Build ;
25
26
import android .util .Log ;
26
27
import androidx .annotation .GuardedBy ;
27
28
import androidx .annotation .NonNull ;
@@ -409,8 +410,13 @@ public void setIsInBackground(boolean isInBackground) {
409
410
}
410
411
// Close the connection if the app is in the background and there is an active
411
412
// HttpUrlConnection.
412
- if (isInBackground && httpURLConnection != null ) {
413
- httpURLConnection .disconnect ();
413
+ // This is now only done on Android versions >= O (API 26) because
414
+ // on older versions, background detection callbacks run on the main thread, which
415
+ // could lead to a NetworkOnMainThreadException when disconnecting the connection.
416
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
417
+ if (isInBackground && httpURLConnection != null ) {
418
+ httpURLConnection .disconnect ();
419
+ }
414
420
}
415
421
}
416
422
}
You can’t perform that action at this time.
0 commit comments