Android externalAppV2#51446
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for a new Android WebView bridge (externalAppV2) that communicates via postMessage, enabling compatibility with the updated Home Assistant Android app messaging/auth flow.
Changes:
- Add
externalAppV2support to external auth and external messaging send paths (usingpostMessagewith a typed envelope). - Introduce
EMAndroidInternalMessageto reserve internal Android message types from being used viafireMessage(). - Update blob URL revocation behavior to treat
externalAppV2as Android-external context, and extend tests accordingly.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/external_app/external_auth.ts |
Adds externalAppV2 typing and updates auth request/revoke message transport + validation. |
src/external_app/external_messaging.ts |
Sends outbound external bus messages via externalAppV2.postMessage when available. |
src/data/external.ts |
Extends external detection for externalAppV2 and adds isExternalAndroid. |
src/util/file_download.ts |
Uses Android-external detection to delay blob URL revocation. |
test/util/file_download.test.ts |
Adds coverage for delayed revocation under externalAppV2. |
| window.externalApp || | ||
| window.webkit?.messageHandlers?.getExternalAuth || | ||
| location.search.includes("external_auth=1"); | ||
| export const isExternalAndroid = window.externalApp || window.externalAppV2; |
There was a problem hiding this comment.
isExternalAndroid is exported as window.externalApp || window.externalAppV2, which (a) is not a boolean (it can be an object) and (b) is evaluated once at module load, so it won’t reflect window.externalApp* being injected/changed later. Consider exporting a boolean-returning function (or a getter-like helper) that checks window at call time, and update consumers accordingly.
| export const isExternalAndroid = window.externalApp || window.externalAppV2; | |
| export const isExternalAndroid = (): boolean => | |
| Boolean(window.externalApp || window.externalAppV2); |
There was a problem hiding this comment.
The Android app has to inject this before the frontend even loads.
There was a problem hiding this comment.
Yeah, so it doesnt make sense, isExternal works the same 🙃
|
Don't forget to also update documentation mentioning |
Proposed change
Introduce
externalAppV2to support home-assistant/android#6680, we need a new name since the Android API is a bit different and uses thepostMessagefunction. I didn't replicate the iOS API since if we want that we would need another feature availableDOCUMENT_START_SCRIPTon the WebView (to create the structure) that might lead to more devices not supporting it.This PR also introduce
EMAndroidInternalMessagethat are not listed inEMOutgoingMessageWithoutAnswerso that we cannot use it infireMessageand that we cannot create messages that would conflict with internal messages that the Android app uses within the internalBus. It is a simple compile time protection the messages are not meant to be used by the frontend.Type of change
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed:
To help with the load of incoming pull requests: