Skip to content

Avoid crashing when Shortcuts are using reserved string - #7273

Merged
jpelgrom merged 2 commits into
mainfrom
fix/shortcut_crash
Jul 30, 2026
Merged

Avoid crashing when Shortcuts are using reserved string#7273
jpelgrom merged 2 commits into
mainfrom
fix/shortcut_crash

Conversation

@TimoPtr

@TimoPtr TimoPtr commented Jul 29, 2026

Copy link
Copy Markdown
Member

Summary

Fix #7270.

Opening the shortcuts settings screen crashed with IndexOutOfBoundsException when the system reported more dynamic shortcuts than the 5 slots the screen manages. The ViewModel mapped the system's dynamic shortcut list positionally into a fixed 6-slot list, and createShortcut treated any ID starting with "shortcut" as dynamic, so a pinned shortcut with a user-typed ID like "shortcutA" was silently registered as an extra dynamic shortcut. Two of those and the screen crashed on every open.

To avoid future problem we forbid the usage of shortcut_x in the ID of pinned shortcut. It comes with a downside that if a dynamic shortcut is moved to a pinned shortcut from the launcher it is going to appear in the list of pinned shortcut to edit but we block it from the UI, the edition is still from the dynamic section.

Step to reproduce the crash, set all the dynamic shortcut and then add a pinned shortcut with an ID that starts with shortcut. This PR is going to avoid the crashes on existing install.

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.

Copilot AI review requested due to automatic review settings July 29, 2026 15:53
@TimoPtr
TimoPtr requested a review from jpelgrom July 29, 2026 15:54

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

Fixes a crash in the legacy “Manage Shortcuts” settings screen by making dynamic shortcut handling slot-aware (by ID) instead of position-based, and by preventing pinned shortcuts from using IDs reserved for dynamic slots.

Changes:

  • Map dynamic shortcuts into fixed UI slots using the shortcut ID (shortcut_1..shortcut_5) and ignore extras.
  • Add UI validation for pinned shortcut IDs that collide with reserved dynamic IDs.
  • Add Robolectric tests covering slot overflow, reserved IDs, and dynamic vs pinned classification.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
common/src/main/res/values/strings.xml Adds an error message string for reserved pinned shortcut IDs.
app/src/main/kotlin/io/homeassistant/companion/android/settings/shortcuts/legacy/ManageShortcutsViewModel.kt Reworks dynamic shortcut slot mapping and reserved-ID detection logic.
app/src/main/kotlin/io/homeassistant/companion/android/settings/shortcuts/legacy/views/ManageShortcutsView.kt Shows/blocks reserved pinned shortcut IDs in the UI.
app/src/test/kotlin/io/homeassistant/companion/android/settings/shortcuts/legacy/ManageShortcutsViewModelTest.kt Adds Robolectric coverage for the crash scenario and ID classification.

@jpelgrom
jpelgrom merged commit 85283fb into main Jul 30, 2026
52 of 54 checks passed
@jpelgrom
jpelgrom deleted the fix/shortcut_crash branch July 30, 2026 20:51
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.

Crash When Opening Companion Shortcuts Menu

3 participants