Merged
Conversation
jkasten2
approved these changes
Feb 8, 2022
Member
jkasten2
left a comment
There was a problem hiding this comment.
Code changes look good to me! Made one comment on a test improvement, feel free to make the fix and merge without another approval.
Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @nan-li)
OneSignalSDK/unittest/src/test/java/com/test/onesignal/GenerateNotificationRunner.java, line 1990 at r1 (raw file):
public void testNotificationProcessingAndForegroundHandler_callCompleteWithMutableNotification_displays() throws Exception { // 1. Setup correct notification extension service class startRemoteNotificationReceivedHandlerService("com.test.onesignal.GenerateNotificationRunner$" +
Recommend using a hard reference to this class so if any code refactor is done in the future this will be a compile error instead of a failed test.
startRemoteNotificationReceivedHandlerService(RemoteNotificationReceivedHandler_notificationReceivedCallCompleteWithMutableNotification.getClass().getCanonicalName());When the NSE calls `complete` with `notification.mutableCopy()` rather than the original notification, and the foreground handler is also set, the notification will not display. This test is added to replicate that behavior. We will address the bug in the following commit to get the test to pass.
- `OSNotification(OSNotification notification)` is used as the constructor for `OSMutableNotification` - `ttl` and `sentTime` were missing from this constructor so that these values defaulted to 0, leading to some problems with determining ttl logic later. - Unrelated to what this PR is going to address, but also added `smallIcon` here since that was also missing.
When we check `isNotificationWithinTTL` to determine if we should display it, we should use `currentTimeMillis` (milliseconds since epoch) instead of `currentThreadTimeMillis` to determine the current time that will be used in the logic. The google sent_time is also in milliseconds since epoch. During some testing, `currentThreadTimeMillis` is equivalent to almost 0 seconds due to it being the time a thread has been active. While working on this, I looked at other places that used thread time inaccurately and changed to using `currentTimeMillis` instead.
These two tests now fail after moving away from using thread time. - notShowNotificationPastTTL - shouldSetExpireTimeCorrectlyWhenMissingFromPayload Modify the test code to not use thread time
528a908 to
8dd2cdc
Compare
Merged
1 task
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.
Description
One Line Summary
Add
ttlandsentTime(andsmallIcon) to an OSNotification constructor and change usages ofcurrentThreadTimeMillis(time thread has been active) tocurrentTimeMillis(epoch time) instead.Details
Motivation
This PR is related to some features of #1479.
The
protected OSNotification(OSNotification notification)constructor was missingttlandsentTimeso that when the NSE is used along with the foreground handler, and the NSE passes on amutableCopy(), the notification that is processed by the foreground handler next hasttlandsentTimemissing, and thus defaulted to0, which ends up not displaying due toisNotificationWithinTTL()check returningfalseerroneously.Unrelated, but
smallIconwas also missing so I added it as well.While making the above changes, I noticed that the
currentTimeInSecondsforisNotificationWithinTTL()would be close to zero. When we checkisNotificationWithinTTL()to determine if we should display it, we should usecurrentTimeMillis(milliseconds since epoch) instead ofcurrentThreadTimeMillis(the time a thread has been active) to determine the current time that will be used in the logic. Note that thegoogle.sent_timeis also in milliseconds since epoch.While working on this, I looked at other places that used thread time inaccurately and changed to using
currentTimeMillisinstead.Scope
I think using
currentThreadTimeMilliswas not a problem in the past because it was only the backup value whengoogle.sent_timewas not in the payload.Testing
Unit testing
Added test
testNotificationProcessingAndForegroundHandler_callCompleteWithMutableNotification_displays()and handlerRemoteNotificationReceivedHandler_notificationReceivedCallCompleteWithMutableNotification. The test NSE callscomplete()with amutableCopy()of the notification that is used by the foreground handler later. We test that the notification will display.The two tests
notShowNotificationPastTTLandshouldSetExpireTimeCorrectlyWhenMissingFromPayloadare now failing because they were using thread time. I modified these to use current non-thread time and they now pass.Manual testing
Tested using Android emulator Pixel 5 on API 30 with the demo app in the SDK. Sent notification to the device in the foreground and it didn't display before. Now it displays. Also regularly checked values of
sentTime,ttlandcurrentTimeInSecondsthroughout testing.Affected code checklist
Checklist
Overview
Testing
Final pass
This change is