Adjust NFC writing AAR records to better fit tag size - #7285
Open
jpelgrom wants to merge 4 commits into
Open
Conversation
- Improves fallback handling to add the current package instead of all or none, to make the best use of available space
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request refines NFC tag writing in the Android companion app by improving how NDEF messages are sized: it now attempts progressively smaller payloads (all AARs → current app AAR → URL only) to better fit different tag capacities, and applies the same fallback behavior when formatting NDEF-formatable tags.
Changes:
- Add a multi-step fallback strategy for AAR (Android Application Record) inclusion based on tag capacity.
- Update NDEF-formatable tag handling to retry formatting with smaller messages instead of failing immediately.
- Add Robolectric tests covering expected record counts and failure modes across representative tag sizes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| app/src/main/kotlin/io/homeassistant/companion/android/nfc/NFCUtil.kt | Implements message-size fallback logic for NDEF and NDEF-formatable tag writing. |
| app/src/test/kotlin/io/homeassistant/companion/android/nfc/NFCUtilTest.kt | Adds Robolectric tests validating the fallback behavior for various tag sizes and error cases. |
Comment on lines
+49
to
+50
| @RunWith(RobolectricTestRunner::class) | ||
| class NFCUtilTest { |
Member
Author
There was a problem hiding this comment.
I don't believe it's needed as we're not interacting with any application classes or Hilt here, running as a unit test similar to UriExtensionsTest.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When writing NFC tags, the app tries to include Android Application Records (AAR) for
io.homeassistant.companion.androidandio.homeassistant.companion.android.minimalalongside the URL. If those don't fit on the tag, it falls back to no AARs to reduce the message size. This PR:This might help with later comments in #7095 as some users reported manually writing one application record to the tag as a workaround/fix.
For the functions that were touched documentation (KDoc) and tests were added.
Checklist
Select exactly one option that describes AI usage in this contribution:
Screenshots
n/a
Link to pull request in documentation repositories
n/a, technical implementation detail
Any other notes
Note that when testing the application ID contains the
.debugsuffix. With the previous implementation that suffix would never be written to NFC tags, as it either had the production IDs hardcoded or none. With these changes, in the situation with 1 AAR you get the current application ID which will contain.debugif using a debug variant.* Related: the iOS companion app implementation always writes one AAR for
io.homeassistant.companion.android.