android icon indicating copy to clipboard operation
android copied to clipboard

Fix legacy WebView same-origin URL routing

Open himu-gupta opened this issue 5 months ago • 3 comments

Summary

Potentially addresses part of #7027.

The legacy WebViewActivity URL override path used a substring check against the current WebView URL to decide whether a URL should open externally. That can incorrectly classify same-origin Home Assistant URLs with a different path as external.

This updates the legacy override path to compare origins instead. Same-origin Home Assistant URLs stay in the app, different origins still open externally, and non-HTTP(S)/hostless URLs continue to be handed to Android without calling the origin helper.

Checklist

  • [x] New or updated tests have been added to cover the changes following the testing guidelines.
  • [x] The code follows the project's code style and best_practices.
  • [x] The changes have been thoroughly tested, and edge cases have been considered.
  • [x] Changes are backward compatible whenever feasible. Any breaking changes are documented in the changelog for users and/or in the code for developers depending on the relevance.

Screenshots

Not applicable; this changes URL routing behavior only.

Any other notes

Verification performed:

  • git diff --check
  • ./gradlew --no-daemon --console=plain :app:testFullDebugUnitTest --tests io.homeassistant.companion.android.webview.WebViewUrlOverrideTest
  • ./gradlew --no-daemon --console=plain :app:ktlintCheck

himu-gupta avatar Jun 17 '26 19:06 himu-gupta

Potentially addresses https://github.com/home-assistant/android/issues/7027.

This doesn't explain why navigation would happen on closing the app, and linked to the last update. The line you're referring to hasn't changed in months.

jpelgrom avatar Jun 17 '26 20:06 jpelgrom

Thanks, agreed. I checked the attached issue log and it shows the WebView renderer going away first, followed by Launching browser shortly after, so this PR does not explain the renderer crash or prove the app-update timing by itself.

I narrowed the PR wording to "potentially addresses part of #7027" and kept the code scoped to one legacy routing issue: same-origin URLs with a different path no longer get treated as external. I also addressed the review findings by parsing the target URL once, guarding non-HTTP(S)/hostless targets before hasSameOrigin, adding mailto:, tel:, and relative URL tests, and configuring the Robolectric test with HiltTestApplication.

himu-gupta avatar Jun 18 '26 09:06 himu-gupta

Could you describe how to reproduce the initial issue? I never managed to end up into this situation.

TimoPtr avatar Jun 18 '26 09:06 TimoPtr