Skip to content

Handle local network permission - Android 17#7165

Open
ganfra wants to merge 8 commits into
developfrom
feature/fga/local_network_permission
Open

Handle local network permission - Android 17#7165
ganfra wants to merge 8 commits into
developfrom
feature/fga/local_network_permission

Conversation

@ganfra

@ganfra ganfra commented Jul 7, 2026

Copy link
Copy Markdown
Member

Content

Android 17 introduces a new runtime permission for reaching local-network addresses. Without it, TCP connections to local IPs silently time out.

How it works

  • New LocalNetworkAddressClassifier classifies a URL as LocalIp / PublicIp / Unresolvable via InetAddress + .local mDNS heuristics.
  • LocalNetworkPermissionAdvisor combines the classifier + SDK version + current permission state into a single "should we prompt?" decision.
  • LocalNetworkPermissionGate is a shared Composable state machine that renders a rationale dialog (or "Open settings" variant for permanently-denied cases) before the OS prompt.
  • Consumed at three call sites:
    • LoggedInPresenter : existing sessions upgraded to Android 17.
    • New LoginModePresenter (extracted from the deleted LoginHelper) sign-in flow, shared by the four account-provider screens (onboarding, confirm, choose, classic).
    • ChangeServerPresenter when switching homeserver from settings.

Also

  • New PermissionsEvent.ForceRequestPermissions bypasses the existing soft-denial intercept in DefaultPermissionsPresenter, needed because we render our own rationale/settings
    variants instead of the built-in PermissionsView.
  • MatrixClient.homeserverUrl exposed so consumers can consult the advisor.

Motivation and context

Closes #7073

Screenshots / GIFs

Tests

  • Sign in from Onboarding / Confirm / Choose / Classic screens with a local homeserver → rationale dialog appears before OS prompt.
  • Existing session on Android 17 with a local homeserver → rationale dialog on home screen; dismiss persists per-session.
  • Change server to a local URL → same rationale flow.
  • Sign in with a public homeserver → no prompt.

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

  • I am aware of the etiquette.
  • This PR was made with the help of AI:
    • Yes. In this case, please request a review by Copilot.
    • No.
  • 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 defines 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

@ganfra ganfra added Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. PR-Misc For other changes labels Jul 7, 2026
@github-actions github-actions Bot removed the Record-Screenshots Runs the 'Record Screenshots' CI job and adds a commit with any new screenshots found. label Jul 7, 2026
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/acFJyb

@bmarty

bmarty commented Jul 8, 2026

Copy link
Copy Markdown
Member
image

The popup show "Settings" instead of "Allow access". Also the "Settings" button can be no-op

@ganfra ganfra force-pushed the feature/fga/local_network_permission branch from a9b7b6f to f25ca5b Compare July 8, 2026 15:16
@ganfra

ganfra commented Jul 8, 2026

Copy link
Copy Markdown
Member Author
image The popup show "Settings" instead of "Allow access". Also the "Settings" button can be no-op

Ok, should be fixed now, but one of the issue doesn't exist on real device, only emulator...

@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

@ganfra ganfra marked this pull request as ready for review July 8, 2026 15:33
@ganfra ganfra requested a review from a team as a code owner July 8, 2026 15:33
@ganfra ganfra requested review from bmarty and removed request for a team July 8, 2026 15:33
permissionsPresenterFactory: PermissionsPresenter.Factory,
) : Presenter<LoggedInState> {
private val localNetworkPermissionsPresenter: PermissionsPresenter =
permissionsPresenterFactory.create(Manifest.permission.ACCESS_LOCAL_NETWORK)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • ⚠️ Field requires API level 37 (current min is 33): android.Manifest.permission#ACCESS_LOCAL_NETWORK

permissionsPresenterFactory: PermissionsPresenter.Factory,
) {
private val permissionsPresenter: PermissionsPresenter =
permissionsPresenterFactory.create(Manifest.permission.ACCESS_LOCAL_NETWORK)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  • ⚠️ Field requires API level 37 (current min is 33): android.Manifest.permission#ACCESS_LOCAL_NETWORK

@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.22388% with 83 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.51%. Comparing base (7c3d1e2) to head (f25ca5b).
⚠️ Report is 25 commits behind head on develop.

Files with missing lines Patch % Lines
...ement/android/appnav/loggedin/LoggedInPresenter.kt 42.10% 9 Missing and 2 partials ⚠️
...l/localnetwork/LocalNetworkPermissionDialogView.kt 50.00% 8 Missing and 2 partials ⚠️
...id/features/login/impl/login/LoginModePresenter.kt 79.16% 4 Missing and 6 partials ⚠️
...io/element/android/appnav/loggedin/LoggedInView.kt 59.09% 4 Missing and 5 partials ⚠️
...in/impl/localnetwork/LocalNetworkPermissionGate.kt 82.35% 4 Missing and 2 partials ⚠️
...features/login/impl/resolver/HomeserverResolver.kt 20.00% 3 Missing and 1 partial ⚠️
...chooseaccountprovider/ChooseAccountProviderView.kt 55.55% 2 Missing and 2 partials ⚠️
...nfirmaccountprovider/ConfirmAccountProviderView.kt 55.55% 2 Missing and 2 partials ⚠️
...s/login/impl/changeserver/ChangeServerPresenter.kt 62.50% 1 Missing and 2 partials ⚠️
...roid/libraries/androidutils/network/DnsResolver.kt 0.00% 3 Missing ⚠️
... and 12 more
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7165      +/-   ##
===========================================
- Coverage    80.53%   80.51%   -0.03%     
===========================================
  Files         2705     2714       +9     
  Lines        78030    78270     +240     
  Branches     10532    10582      +50     
===========================================
+ Hits         62843    63016     +173     
- Misses       11128    11174      +46     
- Partials      4059     4080      +21     

☔ View full report in Codecov by Harness.
📢 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR-Misc For other changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't login to personal server anymore (on Android 17?)

3 participants