-
Notifications
You must be signed in to change notification settings - Fork 368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Poll for notification permission changes #2112
Conversation
a175fec
to
e8277d7
Compare
...va/com/onesignal/notifications/internal/permissions/impl/NotificationPermissionController.kt
Outdated
Show resolved
Hide resolved
...va/com/onesignal/notifications/internal/permissions/impl/NotificationPermissionController.kt
Outdated
Show resolved
Hide resolved
e8277d7
to
63e5cbf
Compare
...va/com/onesignal/notifications/internal/permissions/impl/NotificationPermissionController.kt
Show resolved
Hide resolved
...va/com/onesignal/notifications/internal/permissions/impl/NotificationPermissionController.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments are for if we keep this change the polling rate for the background to a value so high it essentially stops polling.
Still for up for stopping the polling loop and starting a new one when foregrounding if you want to go that route though, as the intent in the code would be more clear.
...va/com/onesignal/notifications/internal/permissions/impl/NotificationPermissionController.kt
Outdated
Show resolved
Hide resolved
OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/internal/config/ConfigModel.kt
Outdated
Show resolved
Hide resolved
OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/internal/config/ConfigModel.kt
Show resolved
Hide resolved
5c28104
to
54bb02d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation itself looks good to me now.
This PR is still noted as WiP, so I'll wait to approve until it's considered complete.
Examples/OneSignalDemo/app/src/main/java/com/onesignal/sdktest/model/MainActivityViewModel.java
Outdated
Show resolved
Hide resolved
5d8d226
to
5b159f7
Compare
We will track the permission state as enabled and fire the handler when the state changes Use a constant from the ConfigModel to control the permission polling interval
Use a waiter instead of waiterWithValue
Adding an initial test for the polling behavior Adding mocking for setting notifications as enabled/disabled in ShadowRoboNotificationManager Adding foregroundFetchNotificationPermissionInterval to the MockHelper configModel with a value of 1 ms
5b159f7
to
8feeda8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking through the test I have a concern about the default pollingWaitInterval
value, left more details on the line of code.
...va/com/onesignal/notifications/internal/permissions/impl/NotificationPermissionController.kt
Outdated
Show resolved
Hide resolved
This protects init in the background onFocus is called immediately if the app is in focus and wakes so we start polling correctly update unit test to account for this
7104d3a
to
4cb7cb1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New "NotificationPermissionController permission polling fires permission changed event" test is failing on CI from the last commit. I believe the test needs to be updated to account for the new polling rate default.
set delay to be 100 ms to fix flakiness
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test passes locally now for me, so it's most likely good now, but let's wait until CI finishes before merging to be sure.
* This code was originally created in #2112 * When making the 5.1.15 release, 2 errors showed up for the `onFocus` method. * Odd that our PR CI build and unit testing succeeded
* This code was originally created in #2112 * A parallel PR made a change to the method signature of `onFocus`
Description
One Line Summary
This PR adds polling for notification permission changes so that we can detect changes that happen from outside of the SDK in the current session.
Details
Spawn a new thread where we check notification permission every second. If the permission has changed we fire the permission observer.
This means that we need to track the permission value to know if it has changed.
This is done using an
_enabled
boolean that gets set when using OneSignal's prompting or when the polling detects a change.When the app loses focus we change the polling interval to 1 day to have the thread sleep until the app is brought into focus.
Motivation
Currently if an app prompts for permissions without using OneSignal or if the user changes permissions without closing the app (notification center long press on notification), we don't detect those permission changes until the next session begins.
Scope
notification permission prompting
Testing
Unit testing
Added a unit testing file for the PermissionController. Currently has 3 tests around the new polling behavior.
Manual testing
Tested by prompting directly through Android native APIs to test that the SDK detects the change.
Tested that backgrounding that properly sleeps the thread to ensure we aren't polling while the app is not in focus.
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is