Skip to content

Commit 120cc3e

Browse files
committed
Avoid continue logic when having foreground handler
* When having foreground handler active, stop processing notification, it will be processed by user or timer complete
1 parent 1eb82bd commit 120cc3e

File tree

4 files changed

+4
-26
lines changed

4 files changed

+4
-26
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,14 @@ static int processJobForDisplay(OSNotificationController notificationController,
140140
if (fromBackgroundLogic && OneSignal.shouldFireForegroundHandlers()) {
141141
notificationController.setFromBackgroundLogic(false);
142142
OneSignal.fireForegroundHandlers(notificationController);
143+
// Notification will be processed by foreground user complete or timer complete
144+
return androidNotificationId;
143145
} else {
144-
notificationController.setForegroundLogicEnded(true);
145146
GenerateNotification.fromJsonPayload(notificationJob);
146147
}
147148
}
148149

149-
if (!notificationJob.isRestoring() && !notificationJob.isIamPreview() && !notificationJob.isProcessed()) {
150-
notificationJob.setProcessed(true);
150+
if (!notificationJob.isRestoring() && !notificationJob.isIamPreview()) {
151151
processNotification(notificationJob, opened);
152152
OneSignal.handleNotificationReceived(notificationJob);
153153
}
@@ -265,7 +265,6 @@ private static void saveNotification(OSNotificationGenerationJob notificationJob
265265
} catch (JSONException e) {
266266
e.printStackTrace();
267267
}
268-
OneSignal.Log(OneSignal.LOG_LEVEL.DEBUG, "Finish saving notification");
269268
}
270269

271270
static void markRestoredNotificationAsDismissed(OSNotificationGenerationJob notifiJob) {

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public class OSNotificationController {
4343
private final OSNotificationGenerationJob notificationJob;
4444
private boolean restoring;
4545
private boolean fromBackgroundLogic;
46-
private boolean foregroundLogicEnded;
4746

4847
OSNotificationController(OSNotificationGenerationJob notificationJob, boolean restoring, boolean fromBackgroundLogic) {
4948
this.restoring = restoring;
@@ -81,7 +80,6 @@ private OSNotificationGenerationJob createNotificationJobFromCurrent(Context con
8180
* @see OSNotificationReceivedEvent#complete(OSNotification)
8281
*/
8382
void processNotification(OSNotification originalNotification, @Nullable OSNotification notification) {
84-
OneSignal.onesignalLog(OneSignal.LOG_LEVEL.DEBUG, "processNotification called from Thread: " + Thread.currentThread().toString());
8583
if (notification != null) {
8684
// Save as processed to prevent possible duplicate calls from canonical ids
8785
boolean display = isStringEmpty(notification.getBody());
@@ -111,7 +109,6 @@ private void notDisplayNotificationLogic(OSNotification originalNotification) {
111109
} else {
112110
// -1 is used to note never displayed
113111
notificationJob.getNotification().setAndroidNotificationId(-1);
114-
notificationJob.setProcessed(true);
115112
NotificationBundleProcessor.processNotification(notificationJob, true);
116113
OneSignal.handleNotificationReceived(notificationJob);
117114
}
@@ -141,14 +138,6 @@ public void setFromBackgroundLogic(boolean fromBackgroundLogic) {
141138
this.fromBackgroundLogic = fromBackgroundLogic;
142139
}
143140

144-
public boolean isForegroundLogicEnded() {
145-
return foregroundLogicEnded;
146-
}
147-
148-
public void setForegroundLogicEnded(boolean foregroundLogicEnded) {
149-
this.foregroundLogicEnded = foregroundLogicEnded;
150-
}
151-
152141
/**
153142
* In addition to using the setters to set all of the handlers you can also create your own implementation
154143
* within a separate class and give your AndroidManifest.xml a special meta data tag

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public class OSNotificationGenerationJob {
4444
private JSONObject jsonPayload;
4545
private boolean restoring;
4646
private boolean iamPreview;
47-
private boolean processed;
4847

4948
private Long shownTimeStamp;
5049

@@ -173,14 +172,6 @@ public void setIamPreview(boolean iamPreview) {
173172
this.iamPreview = iamPreview;
174173
}
175174

176-
public boolean isProcessed() {
177-
return processed;
178-
}
179-
180-
public void setProcessed(boolean processed) {
181-
this.processed = processed;
182-
}
183-
184175
public Long getShownTimeStamp() {
185176
return shownTimeStamp;
186177
}
@@ -243,7 +234,6 @@ public String toString() {
243234
"jsonPayload=" + jsonPayload +
244235
", isRestoring=" + restoring +
245236
", isIamPreview=" + iamPreview +
246-
", isProcessed=" + processed +
247237
", shownTimeStamp=" + shownTimeStamp +
248238
", overriddenBodyFromExtender=" + overriddenBodyFromExtender +
249239
", overriddenTitleFromExtender=" + overriddenTitleFromExtender +

OneSignalSDK/unittest/src/test/java/com/test/onesignal/GenerateNotificationRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,7 @@ public void testNotificationWillShowInForegroundHandler_silentNotificationNotSav
20622062
.pollInterval(new Duration(500, TimeUnit.MILLISECONDS))
20632063
.untilAsserted(() -> {
20642064
// Make sure 1 notification exists in DB
2065-
assertNotificationDbRecords(1, false);
2065+
assertNotificationDbRecords(1, true);
20662066
});
20672067
}
20682068

0 commit comments

Comments
 (0)