Poll for notification permission changes#2112
Conversation
a175fec to
e8277d7
Compare
e8277d7 to
63e5cbf
Compare
There was a problem hiding this comment.
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.
5c28104 to
54bb02d
Compare
jkasten2
left a comment
There was a problem hiding this comment.
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.
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
jkasten2
left a comment
There was a problem hiding this comment.
After looking through the test I have a concern about the default pollingWaitInterval value, left more details on the line of code.
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
set delay to be 100 ms to fix flakiness
jkasten2
left a comment
There was a problem hiding this comment.
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
_enabledboolean 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