Avoid crashing when Shortcuts are using reserved string - #7273
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
approved these changes
Jul 30, 2026
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
Fix #7270.
Opening the shortcuts settings screen crashed with
IndexOutOfBoundsExceptionwhen 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, andcreateShortcuttreated 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
Select exactly one option that describes AI usage in this contribution: