Skip to content

fix: Ignore global proxy settings if system thinks there's none #4744

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

Conversation

ShadowRZ
Copy link
Contributor

Content

Ignore global proxy settings from Settings.Global.getString(context.contentResolver, Settings.Global.HTTP_PROXY) if the system says we have no proxy

Motivation and context

Closes #3447

See #3447 (comment) for technical details.

Screenshots / GIFs

Tests

  • Step 1: In the provisioned device, Run adb shell settings put global http_proxy :0
  • Step 2: Check if Element X Android can select a identity provider without saying We couldn't reach the homeserver

Tested devices

  • Physical
  • Emulator
  • OS version(s): Android 15

Checklist

  • Changes have been tested on an Android device or Android emulator with API 24
  • UI change has been tested on both light and dark themes
  • Accessibility has been taken into account. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#accessibility
  • Pull request is based on the develop branch
  • Pull request title will be used in the release note, it clearly define what will change for the user
  • Pull request includes screenshots or videos if containing UI changes
  • You've made a self review of your PR

@ShadowRZ ShadowRZ requested a review from a team as a code owner May 19, 2025 15:13
@ShadowRZ ShadowRZ requested review from jmartinesp and removed request for a team May 19, 2025 15:13
@CLAassistant
Copy link

CLAassistant commented May 19, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

Thank you for your contribution! Here are a few things to check in the PR to ensure it's reviewed as quickly as possible:

  • Your branch should be based on origin/develop, at least when it was created.
  • The title of the PR will be used for release notes, so it needs to describe the change visible to the user.
  • The test pass locally running ./gradlew test.
  • The code quality check suite pass locally running ./gradlew runQualityChecks.
  • If you modified anything related to the UI, including previews, you'll have to run the Record screenshots GH action in your forked repo: that will generate compatible new screenshots. However, given Github Actions limitations, it will prevent the CI from running temporarily, until you upload a new commit after that one. To do so, just pull the latest changes and push an empty commit.

@github-actions github-actions bot added the Z-Community-PR Issue is solved by a community member's PR label May 19, 2025
@spaetz
Copy link

spaetz commented May 19, 2025

Bit of context: many applications set http_proxy to :0 in order to disable it. Android libraries understand this, rust however considers :0 to be an invalid entry and connections fail.
This is a frequent source of real world support issues by EXA users. Fixing this would be nice, ideally this is fixed in upstream rust, of course

Copy link

codecov bot commented May 19, 2025

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Project coverage is 80.12%. Comparing base (34e88f3) to head (02c8c85).
Report is 27 commits behind head on develop.

Files with missing lines Patch % Lines
...ibraries/matrix/impl/proxy/DefaultProxyProvider.kt 0.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4744      +/-   ##
===========================================
- Coverage    80.13%   80.12%   -0.02%     
===========================================
  Files         2129     2129              
  Lines        56449    56453       +4     
  Branches      7055     7057       +2     
===========================================
- Hits         45236    45233       -3     
- Misses        8795     8799       +4     
- Partials      2418     2421       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Otherwise a :0 proxy would break in Rust SDK.
@ShadowRZ ShadowRZ force-pushed the features/shadowrz/ignore-proxy-if-system-thinks-no-proxy branch from 007e0f5 to 02c8c85 Compare May 20, 2025 08:41
@ShadowRZ
Copy link
Contributor Author

I did some further testing on the emulator:

  • adb shell settings put global http_proxy :1: Direct connection
  • adb shell settings put global http_proxy :65535: Direct connection
  • adb shell settings put global http_proxy 1:65536: Direct connection
  • adb shell settings put global http_proxy 1:65535: A proxy defined at 1:65535

So I think that an invalid http_proxy value in Android means no proxy (direct), and to workaround this in the Rust SDK side we can just introduce a "lossy" proxy configration function where it'll throw away invalid proxy configurations.

@jmartinesp
Copy link
Member

jmartinesp commented May 21, 2025

I gave this a quick try and it seems like your implementation works fine, the defaultProxy value is null if the proxy is not valid.

So I think that an invalid http_proxy value in Android means no proxy (direct), and to workaround this in the Rust SDK side we can just introduce a "lossy" proxy configration function where it'll throw away invalid proxy configurations.

Isn't this what you already did in the PR? Unless I missed some corner case I think we can merge it as is, it's better than the current behaviour.

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update @ShadowRZ , and thanks for the extra test @jmartinesp !

@bmarty bmarty merged commit 630e1d1 into element-hq:develop May 26, 2025
23 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Z-Community-PR Issue is solved by a community member's PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

I can't login to any homeserver at all: "We couldn't reach this homeserver"
5 participants