Skip to content

Add DebugNfcTagEmulator in DevPlaygound - #7282

Open
TimoPtr wants to merge 3 commits into
mainfrom
feature/nfc_tag_emulator
Open

Add DebugNfcTagEmulator in DevPlaygound#7282
TimoPtr wants to merge 3 commits into
mainfrom
feature/nfc_tag_emulator

Conversation

@TimoPtr

@TimoPtr TimoPtr commented Jul 31, 2026

Copy link
Copy Markdown
Member

Summary

I wanted to debug some NFC tag issue but I don't have any writable NFC tag so I've asked Claude to do an emulator of tag. This is Claude work using the android.nfc.cardemulation.HostApduService within the DevPlaygound. I tested it on Android 9 and 17 and both managed to make proper tag read by our app.

Checklist

  • New or updated tests have been added to cover the changes following the testing guidelines.
  • The code follows the project's code style and best_practices.
  • The changes have been thoroughly tested, and edge cases have been considered.
  • 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.
  • I have read the Open Home Foundation AI Policy.

Select exactly one option that describes AI usage in this contribution:

  • I have not used AI for this contribution.
  • AI assistance was used for this contribution.
  • AI fully generated the code for this contribution, but I've reviewed and understood it before submitting and will respond without AI during review.

Screenshots

image image

Any other notes

I didn't review in details the service I assumed that since it works the tag used is valid.

Copilot AI review requested due to automatic review settings July 31, 2026 09:40
@TimoPtr
TimoPtr requested a review from jpelgrom July 31, 2026 09:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a debug-only NFC tag emulator inside the Dev Playground, allowing developers to emulate a writable NFC Forum Type 4 tag via Host Card Emulation (HCE) and inspect/modify its NDEF payload for debugging tag handling.

Changes:

  • Introduces a debug HostApduService + in-memory NDEF file state to emulate a writable Type 4 tag.
  • Adds a Dev Playground UI screen to control the emulated tag ID and view raw/decoded NDEF content.
  • Refactors NFC tag writing helpers by extracting NFCUtil.createTagUrl/createTagMessage and adds Robolectric coverage for the emulator APDU behavior.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
app/src/testDebug/kotlin/io/homeassistant/companion/android/developer/nfc/DebugNfcTagEmulatorServiceTest.kt Adds Robolectric tests validating APDU select/read/write flows and summary updates.
app/src/main/kotlin/io/homeassistant/companion/android/nfc/NFCUtil.kt Extracts URL/message builders for HA NFC tags and reuses them for tag writing.
app/src/main/kotlin/io/homeassistant/companion/android/nfc/NfcSetupActivity.kt Switches tag URL construction to NFCUtil.createTagUrl.
app/src/debug/res/xml/debug_nfc_tag_apduservice.xml Declares the HCE AID filter for an NDEF Type 4 Tag application.
app/src/debug/res/values/strings.xml Adds a debug label string for the emulator.
app/src/debug/kotlin/io/homeassistant/companion/android/developer/nfc/DebugNfcTagEmulatorActivity.kt New Dev Playground screen for controlling and inspecting the emulated tag.
app/src/debug/kotlin/io/homeassistant/companion/android/developer/nfc/DebugNfcTagEmulator.kt Implements emulator state + HostApduService APDU handling and logging.
app/src/debug/kotlin/io/homeassistant/companion/android/developer/DevPlaygroundActivity.kt Adds entry point button to launch the emulator screen.
app/src/debug/AndroidManifest.xml Registers the emulator activity and HCE service (disabled by default).

Comment thread app/src/debug/res/values/strings.xml Fixed
Comment thread app/src/debug/res/xml/debug_nfc_tag_apduservice.xml Fixed
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.

3 participants