require authentication for notification action when flag is set#6907
require authentication for notification action when flag is set#6907dkarv wants to merge 6 commits into
Conversation
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Extends notification action handling to propagate an authenticationRequired flag from websocket-received action payloads into built notification actions.
Changes:
- Flatten additional action fields (
uri,behavior,authenticationRequired) when processing websocket data. - Read
authenticationRequiredfrom notification action data and apply it viaNotificationCompat.Action.Builder#setAuthenticationRequired.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| app/src/main/kotlin/io/homeassistant/companion/android/websocket/WebsocketManager.kt | Includes authenticationRequired (and consolidates flattening logic) when serializing action fields into a flattened map. |
| app/src/main/kotlin/io/homeassistant/companion/android/notifications/MessagingManager.kt | Reads the flattened authenticationRequired flag and sets it on built notification actions. |
|
Thanks for the suggestion. However, this doesn't map cleanly on the same pattern as iOS where it is a simple yes/no; the builder specifies
... so you won't be required to authenticate when the device is unlocked, even if you send
... so you might still end up needing to authenticate if Android decides so, even when you send |
|
Thanks for your thoughts. I had another look to compare the behavior on both platforms:
This is the same behavior I saw on iOS. When the device is already unlocked, no further authentication is needed and the action is performed directly. According to the Apple documentation this is expected, it states The action can be performed only on an unlocked device.
I could not find any remark and never experienced this. So I checked in the AOSP code and it seems it just relies on that boolean we can pass: it is queried and passed down here and evaluated here Even if future Android version change it and require another authentication (e.g. when a device is unlocked for too long) I think this is only helping the goal of this flag and further improves security. Happy to hear if I got something wrong. But in conclusion, I would argue the small potential difference in the future does not justify a separate flag for Android and iOS. It would need to be documented, users would need to put two flags into each notification definition in HA, and more. I also checked again the backwards compatibility. If authenticationRequired is not given in the notification data, nothing changes for existing users. |
In that case I think the companion app documentation should also be updated to reflect that, right now it suggests otherwise. |
Makes sense, I changed the documentation in the linked PR: | |
|
Thanks for updating the documentation. In that case as behavior matches I see no objections.
You need to add the key to the list of keys that are passed to Android like here: https://github.com/home-assistant/mobile-apps-fcm-push/blob/main/functions/android.js#L27-L29. If you submit a PR we'll merge it alongside all the other ones and it will immediately start working with FCM. |
|
Could you also add a short line for this change to the in-app changelog like "Added support for ..."? |
Created the PR: home-assistant/mobile-apps-fcm-push#306
Also done, hope I added it the correct way. Thanks overall for your suggestions and help to bring this to live, appreciate it. |
Summary
Add the authenticationRequired flag for notification actions. It is already supported on iOS.
When enabled, the phone has to be unlocked to trigger a notification action. Useful e.g. for opening the door after the bell was ringed or other sensitive actions.
community request
Checklist
Link to pull request in documentation repositories
User Documentation: home-assistant/companion.home-assistant#1331
Any other notes