Skip to content

Android externalAppV2#51446

Merged
bramkragten merged 5 commits intohome-assistant:devfrom
TimoPtr:externalAppV2
Apr 9, 2026
Merged

Android externalAppV2#51446
bramkragten merged 5 commits intohome-assistant:devfrom
TimoPtr:externalAppV2

Conversation

@TimoPtr
Copy link
Copy Markdown
Member

@TimoPtr TimoPtr commented Apr 7, 2026

Proposed change

Introduce externalAppV2 to support home-assistant/android#6680, we need a new name since the Android API is a bit different and uses the postMessage function. I didn't replicate the iOS API since if we want that we would need another feature available DOCUMENT_START_SCRIPT on the WebView (to create the structure) that might lead to more devices not supporting it.

This PR also introduce EMAndroidInternalMessage that are not listed in EMOutgoingMessageWithoutAnswer so that we cannot use it in fireMessage and 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

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

To help with the load of incoming pull requests:

@TimoPtr TimoPtr changed the title External app v2 Android externalAppV2 Apr 7, 2026
@TimoPtr TimoPtr marked this pull request as ready for review April 7, 2026 11:49
@TimoPtr TimoPtr requested a review from bgoncal as a code owner April 7, 2026 11:49
@bgoncal bgoncal requested review from bramkragten and Copilot April 7, 2026 11:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 externalAppV2 support to external auth and external messaging send paths (using postMessage with a typed envelope).
  • Introduce EMAndroidInternalMessage to reserve internal Android message types from being used via fireMessage().
  • Update blob URL revocation behavior to treat externalAppV2 as 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.

Comment thread src/data/external.ts
window.externalApp ||
window.webkit?.messageHandlers?.getExternalAuth ||
location.search.includes("external_auth=1");
export const isExternalAndroid = window.externalApp || window.externalAppV2;
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
export const isExternalAndroid = window.externalApp || window.externalAppV2;
export const isExternalAndroid = (): boolean =>
Boolean(window.externalApp || window.externalAppV2);

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The Android app has to inject this before the frontend even loads.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, so it doesnt make sense, isExternal works the same 🙃

Comment thread src/util/file_download.ts Outdated
Comment thread src/util/file_download.ts
Comment thread test/util/file_download.test.ts Outdated
Comment thread src/external_app/external_auth.ts Outdated
@jpelgrom
Copy link
Copy Markdown
Member

jpelgrom commented Apr 7, 2026

Don't forget to also update documentation mentioning window.externalApp: https://developers.home-assistant.io/docs/frontend/external-authentication, https://developers.home-assistant.io/docs/frontend/external-bus.

Comment thread src/data/external.ts Outdated
Comment thread src/external_app/external_messaging.ts Outdated
@bramkragten bramkragten added this to the 2026.4 milestone Apr 8, 2026
@TimoPtr TimoPtr requested a review from bramkragten April 8, 2026 13:32
@bramkragten bramkragten merged commit 63c9b85 into home-assistant:dev Apr 9, 2026
12 checks passed
bramkragten pushed a commit that referenced this pull request Apr 10, 2026
marcinbauer-ohf pushed a commit to marcinbauer-ohf/frontend that referenced this pull request Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants