Skip to content

Commit ad2227c

Browse files
committed
Use currentTime instead of currentThreadTime
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.
1 parent fa5b17c commit ad2227c

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationBundleProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ private static void saveNotification(OSNotificationGenerationJob notificationJob
236236
values.put(NotificationTable.COLUMN_NAME_MESSAGE, notificationJob.getBody().toString());
237237

238238
// Set expire_time
239-
long sentTime = jsonPayload.optLong(OSNotificationController.GOOGLE_SENT_TIME_KEY, OneSignal.getTime().getCurrentThreadTimeMillis()) / 1_000L;
239+
long sentTime = jsonPayload.optLong(OSNotificationController.GOOGLE_SENT_TIME_KEY, OneSignal.getTime().getCurrentTimeMillis()) / 1_000L;
240240
int ttl = jsonPayload.optInt(OSNotificationController.GOOGLE_TTL_KEY, OSNotificationRestoreWorkManager.DEFAULT_TTL_IF_NOT_IN_PAYLOAD);
241241
long expireTime = sentTime + ttl;
242242
values.put(NotificationTable.COLUMN_NAME_EXPIRE_TIME, expireTime);

OneSignalSDK/onesignal/src/main/java/com/onesignal/OSNotification.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private void initPayloadData(JSONObject currentJsonPayload) {
146146
return;
147147
}
148148

149-
long currentTime = OneSignal.getTime().getCurrentThreadTimeMillis();
149+
long currentTime = OneSignal.getTime().getCurrentTimeMillis();
150150
if (currentJsonPayload.has(GOOGLE_TTL_KEY)) {
151151
sentTime = currentJsonPayload.optLong(GOOGLE_SENT_TIME_KEY, currentTime) / 1_000;
152152
ttl = currentJsonPayload.optInt(GOOGLE_TTL_KEY, OSNotificationRestoreWorkManager.DEFAULT_TTL_IF_NOT_IN_PAYLOAD);

OneSignalSDK/onesignal/src/main/java/com/onesignal/OSNotificationController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public boolean isNotificationWithinTTL() {
125125
if (!useTtl)
126126
return true;
127127

128-
long currentTimeInSeconds = OneSignal.getTime().getCurrentThreadTimeMillis() / 1_000;
128+
long currentTimeInSeconds = OneSignal.getTime().getCurrentTimeMillis() / 1_000;
129129
long sentTime = notificationJob.getNotification().getSentTime();
130130
// If available TTL times comes in seconds, by default is 3 days in seconds
131131
int ttl = notificationJob.getNotification().getTtl();

0 commit comments

Comments
 (0)