Skip to content

Fix NetworkOnMainThreadException for API levels below 26 #6940

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

Merged
merged 2 commits into from
May 7, 2025

Conversation

tusharkhandelwal8
Copy link
Contributor

This change addresses a NetworkOnMainThreadException that was observed on Android API levels below 26.
The crash happened during background transitions when disconnecting an HttpURLConnection because background callbacks on these older OS versions could run on the main thread. The fix restricts the disconnect logic to run only on API level 26 (Android 8.0) and higher.

Copy link
Contributor

github-actions bot commented May 6, 2025

📝 PRs merging into main branch

Our main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released.

1 similar comment
Copy link
Contributor

github-actions bot commented May 6, 2025

📝 PRs merging into main branch

Our main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 6, 2025

Coverage Report 1

Affected Products

  • firebase-config

    Overall coverage changed from 84.30% (4c4c7c9) to 84.31% (10b23d3) by +0.01%.

    FilenameBase (4c4c7c9)Merge (10b23d3)Diff
    ConfigRealtimeHttpClient.java73.45%73.57%+0.12%

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/Q0fsD7Uhmc.html

Copy link
Contributor

github-actions bot commented May 6, 2025

Test Results

 42 files   -   2   42 suites   - 2   1m 21s ⏱️ - 4m 50s
324 tests +188  324 ✅ +188  0 💤 ±0  0 ❌ ±0 
660 runs  +368  660 ✅ +368  0 💤 ±0  0 ❌ ±0 

Results for commit 861bd2c. ± Comparison against base commit 4c4c7c9.

This pull request removes 136 and adds 324 tests. Note that renamed tests count towards both.
com.google.firebase.appcheck.debug.testing.DebugAppCheckTestHelperTest ‑ testDebugAppCheckTestHelper_withDebugProviderDefaultApp_installsDebugProvider
com.google.firebase.appcheck.debug.testing.DebugAppCheckTestHelperTest ‑ testDebugAppCheckTestHelper_withDebugProviderNamedApp_installsDebugProvider
com.google.firebase.appcheck.debug.testing.DebugAppCheckTestHelperTest ‑ testDebugAppCheckTestHelper_withDebugProvider_noPreviousProvider_installsDebugProvider
com.google.firebase.appcheck.debug.testing.FirebaseAppCheckDebugTestingRegistrarTest ‑ testGetComponents
com.google.firebase.storage.AdaptiveStreamBufferTest ‑ advanceCachedBytes
com.google.firebase.storage.AdaptiveStreamBufferTest ‑ advanceStreamBytes
com.google.firebase.storage.AdaptiveStreamBufferTest ‑ bufferReachedEnd
com.google.firebase.storage.AdaptiveStreamBufferTest ‑ bufferResize
com.google.firebase.storage.AdaptiveStreamBufferTest ‑ readStream
com.google.firebase.storage.DeleteTest ‑ deleteBlob
…
com.google.firebase.remoteconfig.ConfigTests ‑ Custom Signals builder support multiple types
com.google.firebase.remoteconfig.ConfigTests ‑ Firebase#remoteConfig should delegate to FirebaseRemoteConfig#getInstance()
com.google.firebase.remoteconfig.ConfigTests ‑ Firebase#remoteConfig should delegate to FirebaseRemoteConfig#getInstance(FirebaseApp, region)
com.google.firebase.remoteconfig.ConfigTests ‑ FirebaseRemoteConfigSettings builder works
com.google.firebase.remoteconfig.ConfigTests ‑ Overloaded get() operator returns default value when key doesn't exist
com.google.firebase.remoteconfig.ConfigTests ‑ Overloaded get() operator returns value when key exists
com.google.firebase.remoteconfig.CustomSignalsTest ‑ testCustomSignals_builderPutDouble
com.google.firebase.remoteconfig.CustomSignalsTest ‑ testCustomSignals_builderPutDuplicateKeys
com.google.firebase.remoteconfig.CustomSignalsTest ‑ testCustomSignals_builderPutLong
com.google.firebase.remoteconfig.CustomSignalsTest ‑ testCustomSignals_builderPutMixedTypes
…

♻️ This comment has been updated with latest results.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 6, 2025

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 6, 2025

Startup Time Report 1

Note: Layout is sometimes suboptimal due to limited formatting support on GitHub. Please check this report on GCS.

Notes

Startup Times

  • fire-rc

    DeviceStatisticsDistributions
    oriole-32
    Percentile4c4c7c910b23d3DiffSignificant (?)
    p10340 ±613 μs431 ±659 μs+90.9 μs (+26.8%)NO
    p25359 ±650 μs457 ±688 μs+98.4 μs (+27.4%)NO
    p50387 ±687 μs516 ±746 μs+129 μs (+33.4%)NO
    p75454 ±779 μs610 ±856 μs+156 μs (+34.3%)NO
    p90575 ±930 μs773 ±1075 μs+199 μs (+34.6%)NO

    20 test runs in comparison
    CommitTest Runs
    4c4c7c9
    • 2025-05-06_18:46:20.763872_QzxX
    • 2025-05-06_18:46:20.763915_iLZN
    • 2025-05-06_18:46:20.763925_rDGe
    • 2025-05-06_18:46:20.763933_LKFe
    • 2025-05-06_18:46:20.763940_zHbZ
    • 2025-05-06_18:46:20.763947_CONp
    • 2025-05-06_18:46:20.763966_nLDN
    • 2025-05-06_18:46:20.763973_ugPK
    • 2025-05-06_18:46:20.763979_phBc
    • 2025-05-06_18:46:20.763986_hcfF
    10b23d3
    • 2025-05-06_21:13:25.511563_bZms
    • 2025-05-06_21:13:25.511661_pCVS
    • 2025-05-06_21:13:25.511669_Yhwd
    • 2025-05-06_21:13:25.511674_QXfP
    • 2025-05-06_21:13:25.511679_Fetv
    • 2025-05-06_21:13:25.511683_blER
    • 2025-05-06_21:13:25.511692_loPA
    • 2025-05-06_21:13:25.511696_kCuV
    • 2025-05-06_21:13:25.511699_duYL
    • 2025-05-06_21:13:25.511703_MZMq
    redfin-30
    Percentile4c4c7c910b23d3DiffSignificant (?)
    p10223 ±120 μs458 ±585 μs+235 μs (+105.7%)NO
    p25254 ±149 μs549 ±706 μs+295 μs (+115.8%)NO
    p50337 ±225 μs684 ±835 μs+347 μs (+102.8%)NO
    p75527 ±437 μs861 ±1014 μs+334 μs (+63.4%)NO
    p90663 ±555 μs1.10 ±1 ms+432 μs (+65.1%)NO

    20 test runs in comparison
    CommitTest Runs
    4c4c7c9
    • 2025-05-06_18:46:20.763872_QzxX
    • 2025-05-06_18:46:20.763915_iLZN
    • 2025-05-06_18:46:20.763925_rDGe
    • 2025-05-06_18:46:20.763933_LKFe
    • 2025-05-06_18:46:20.763940_zHbZ
    • 2025-05-06_18:46:20.763947_CONp
    • 2025-05-06_18:46:20.763966_nLDN
    • 2025-05-06_18:46:20.763973_ugPK
    • 2025-05-06_18:46:20.763979_phBc
    • 2025-05-06_18:46:20.763986_hcfF
    10b23d3
    • 2025-05-06_21:13:25.511563_bZms
    • 2025-05-06_21:13:25.511661_pCVS
    • 2025-05-06_21:13:25.511669_Yhwd
    • 2025-05-06_21:13:25.511674_QXfP
    • 2025-05-06_21:13:25.511679_Fetv
    • 2025-05-06_21:13:25.511683_blER
    • 2025-05-06_21:13:25.511692_loPA
    • 2025-05-06_21:13:25.511696_kCuV
    • 2025-05-06_21:13:25.511699_duYL
    • 2025-05-06_21:13:25.511703_MZMq
  • timeToInitialDisplay

    DeviceStatisticsDistributions
    oriole-32
    Percentile4c4c7c910b23d3DiffSignificant (?)
    p10196 ±4 ms200 ±3 ms+4.18 ms (+2.1%)NO
    p25202 ±5 ms206 ±3 ms+3.63 ms (+1.8%)NO
    p50210 ±6 ms213 ±3 ms+3.14 ms (+1.5%)NO
    p75218 ±7 ms221 ±4 ms+3.59 ms (+1.7%)NO
    p90224 ±7 ms230 ±6 ms+5.56 ms (+2.5%)NO

    20 test runs in comparison
    CommitTest Runs
    4c4c7c9
    • 2025-05-06_18:46:20.763872_QzxX
    • 2025-05-06_18:46:20.763915_iLZN
    • 2025-05-06_18:46:20.763925_rDGe
    • 2025-05-06_18:46:20.763933_LKFe
    • 2025-05-06_18:46:20.763940_zHbZ
    • 2025-05-06_18:46:20.763947_CONp
    • 2025-05-06_18:46:20.763966_nLDN
    • 2025-05-06_18:46:20.763973_ugPK
    • 2025-05-06_18:46:20.763979_phBc
    • 2025-05-06_18:46:20.763986_hcfF
    10b23d3
    • 2025-05-06_21:13:25.511563_bZms
    • 2025-05-06_21:13:25.511661_pCVS
    • 2025-05-06_21:13:25.511669_Yhwd
    • 2025-05-06_21:13:25.511674_QXfP
    • 2025-05-06_21:13:25.511679_Fetv
    • 2025-05-06_21:13:25.511683_blER
    • 2025-05-06_21:13:25.511692_loPA
    • 2025-05-06_21:13:25.511696_kCuV
    • 2025-05-06_21:13:25.511699_duYL
    • 2025-05-06_21:13:25.511703_MZMq
    redfin-30
    Percentile4c4c7c910b23d3DiffSignificant (?)
    p10225 ±5 ms249 ±5 ms+24.2 ms (+10.8%)MAYBE
    p25232 ±5 ms255 ±4 ms+22.8 ms (+9.8%)MAYBE
    p50239 ±5 ms263 ±4 ms+24.1 ms (+10.1%)YES
    p75248 ±5 ms274 ±6 ms+26.1 ms (+10.5%)MAYBE
    p90256 ±6 ms291 ±12 ms+35.7 ms (+14.0%)MAYBE

    20 test runs in comparison
    CommitTest Runs
    4c4c7c9
    • 2025-05-06_18:46:20.763872_QzxX
    • 2025-05-06_18:46:20.763915_iLZN
    • 2025-05-06_18:46:20.763925_rDGe
    • 2025-05-06_18:46:20.763933_LKFe
    • 2025-05-06_18:46:20.763940_zHbZ
    • 2025-05-06_18:46:20.763947_CONp
    • 2025-05-06_18:46:20.763966_nLDN
    • 2025-05-06_18:46:20.763973_ugPK
    • 2025-05-06_18:46:20.763979_phBc
    • 2025-05-06_18:46:20.763986_hcfF
    10b23d3
    • 2025-05-06_21:13:25.511563_bZms
    • 2025-05-06_21:13:25.511661_pCVS
    • 2025-05-06_21:13:25.511669_Yhwd
    • 2025-05-06_21:13:25.511674_QXfP
    • 2025-05-06_21:13:25.511679_Fetv
    • 2025-05-06_21:13:25.511683_blER
    • 2025-05-06_21:13:25.511692_loPA
    • 2025-05-06_21:13:25.511696_kCuV
    • 2025-05-06_21:13:25.511699_duYL
    • 2025-05-06_21:13:25.511703_MZMq

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/gZm05zaOkX/index.html

@tusharkhandelwal8 tusharkhandelwal8 merged commit 548dc28 into main May 7, 2025
90 of 92 checks passed
@tusharkhandelwal8 tusharkhandelwal8 deleted the fix-background-disconnect branch May 7, 2025 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants