Skip to content

Commit 49ad48c

Browse files
Removing unnecessary code related to ghost pushes
1 parent caf81b0 commit 49ad48c

File tree

5 files changed

+49
-165
lines changed

5 files changed

+49
-165
lines changed

iterableapi/src/main/java/com/iterable/iterableapi/IterableFirebaseMessagingService.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.iterable.iterableapi;
22

33
import android.content.Context;
4-
import android.os.AsyncTask;
54
import android.os.Bundle;
5+
66
import androidx.annotation.NonNull;
77

88
import com.google.android.gms.tasks.Tasks;
@@ -63,7 +63,7 @@ public static boolean handleMessageReceived(@NonNull Context context, @NonNull R
6363
if (!IterableNotificationHelper.isEmptyBody(extras)) {
6464
IterableLogger.d(TAG, "Iterable push received " + messageData);
6565

66-
enqueueNotificationWork(context, extras, false);
66+
enqueueNotificationWork(context, extras);
6767
} else {
6868
IterableLogger.d(TAG, "Iterable OS notification push received");
6969
}
@@ -137,12 +137,11 @@ public static boolean isGhostPush(RemoteMessage remoteMessage) {
137137
}
138138
}
139139

140-
private static void enqueueNotificationWork(@NonNull final Context context, @NonNull final Bundle extras, boolean isGhostPush) {
140+
private static void enqueueNotificationWork(@NonNull final Context context, @NonNull final Bundle extras) {
141141
IterableNotificationWorkScheduler scheduler = new IterableNotificationWorkScheduler(context);
142142

143143
scheduler.scheduleNotificationWork(
144144
extras,
145-
false,
146145
new IterableNotificationWorkScheduler.SchedulerCallback() {
147146
@Override
148147
public void onScheduleSuccess(UUID workId) {
@@ -174,20 +173,3 @@ private static void handleFallbackNotification(@NonNull Context context, @NonNul
174173
}
175174
}
176175
}
177-
178-
/**
179-
* @deprecated This class is no longer used. Notification processing now uses WorkManager
180-
* to comply with Firebase best practices. This class is kept for backwards compatibility only.
181-
*/
182-
@Deprecated
183-
class IterableNotificationManager extends AsyncTask<IterableNotificationBuilder, Void, Void> {
184-
185-
@Override
186-
protected Void doInBackground(IterableNotificationBuilder... params) {
187-
if (params != null && params[0] != null) {
188-
IterableNotificationBuilder notificationBuilder = params[0];
189-
IterableNotificationHelper.postNotificationOnDevice(notificationBuilder.context, notificationBuilder);
190-
}
191-
return null;
192-
}
193-
}

iterableapi/src/main/java/com/iterable/iterableapi/IterableNotificationWorkScheduler.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,13 @@ interface SchedulerCallback {
3434
this.workManager = workManager;
3535
}
3636

37-
public void scheduleNotificationWork(
37+
void scheduleNotificationWork(
3838
@NonNull Bundle notificationData,
39-
boolean isGhostPush,
4039
@Nullable SchedulerCallback callback) {
4140

4241
try {
4342
androidx.work.Data inputData = IterableNotificationWorker.createInputData(
44-
notificationData,
45-
isGhostPush
43+
notificationData
4644
);
4745

4846
OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(IterableNotificationWorker.class)

iterableapi/src/main/java/com/iterable/iterableapi/IterableNotificationWorker.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ internal class IterableNotificationWorker(
2424
private const val FOREGROUND_NOTIFICATION_ID = 10101
2525

2626
const val KEY_NOTIFICATION_DATA_JSON = "notification_data_json"
27-
const val KEY_IS_GHOST_PUSH = "is_ghost_push"
2827

2928
@JvmStatic
30-
fun createInputData(extras: Bundle, isGhostPush: Boolean): Data {
29+
fun createInputData(extras: Bundle): Data {
3130
val jsonObject = JSONObject()
3231
for (key in extras.keySet()) {
3332
val value = extras.getString(key)
@@ -38,7 +37,6 @@ internal class IterableNotificationWorker(
3837

3938
return Data.Builder()
4039
.putString(KEY_NOTIFICATION_DATA_JSON, jsonObject.toString())
41-
.putBoolean(KEY_IS_GHOST_PUSH, isGhostPush)
4240
.build()
4341
}
4442
}
@@ -117,13 +115,6 @@ internal class IterableNotificationWorker(
117115
IterableLogger.d(TAG, "Starting notification processing in Worker")
118116

119117
try {
120-
val isGhostPush = inputData.getBoolean(KEY_IS_GHOST_PUSH, false)
121-
122-
if (isGhostPush) {
123-
IterableLogger.d(TAG, "Ghost push detected, skipping notification display")
124-
return Result.success()
125-
}
126-
127118
val jsonString = inputData.getString(KEY_NOTIFICATION_DATA_JSON)
128119

129120
if (jsonString == null || jsonString.isEmpty()) {

iterableapi/src/test/java/com/iterable/iterableapi/IterableNotificationWorkSchedulerTest.java

Lines changed: 26 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void testScheduleNotificationWorkEnqueuesWithWorkManager() {
7272
Bundle data = new Bundle();
7373
data.putString("key", "value");
7474

75-
scheduler.scheduleNotificationWork(data, false, null);
75+
scheduler.scheduleNotificationWork(data, null);
7676

7777
verify(mockWorkManager).enqueue(any(OneTimeWorkRequest.class));
7878
}
@@ -85,7 +85,7 @@ public void testScheduleNotificationWorkCallsSuccessCallback() {
8585
IterableNotificationWorkScheduler.SchedulerCallback callback =
8686
mock(IterableNotificationWorkScheduler.SchedulerCallback.class);
8787

88-
scheduler.scheduleNotificationWork(data, false, callback);
88+
scheduler.scheduleNotificationWork(data, callback);
8989

9090
verify(callback).onScheduleSuccess(any(UUID.class));
9191
}
@@ -98,7 +98,7 @@ public void testScheduleNotificationWorkPassesWorkIdToCallback() {
9898
IterableNotificationWorkScheduler.SchedulerCallback callback =
9999
mock(IterableNotificationWorkScheduler.SchedulerCallback.class);
100100

101-
scheduler.scheduleNotificationWork(data, false, callback);
101+
scheduler.scheduleNotificationWork(data, callback);
102102

103103
ArgumentCaptor<UUID> uuidCaptor = ArgumentCaptor.forClass(UUID.class);
104104
verify(callback).onScheduleSuccess(uuidCaptor.capture());
@@ -113,7 +113,7 @@ public void testScheduleNotificationWorkSucceedsWithNullCallback() {
113113
data.putString("key", "value");
114114

115115
// Should not throw exception with null callback
116-
scheduler.scheduleNotificationWork(data, false, null);
116+
scheduler.scheduleNotificationWork(data, null);
117117

118118
verify(mockWorkManager).enqueue(any(OneTimeWorkRequest.class));
119119
}
@@ -123,7 +123,7 @@ public void testScheduleNotificationWorkEnqueuesOnlyOnce() {
123123
Bundle data = new Bundle();
124124
data.putString("key", "value");
125125

126-
scheduler.scheduleNotificationWork(data, false, null);
126+
scheduler.scheduleNotificationWork(data, null);
127127

128128
// Verify enqueue called exactly once
129129
verify(mockWorkManager).enqueue(any(OneTimeWorkRequest.class));
@@ -145,7 +145,7 @@ public void testScheduleNotificationWorkCallsFailureCallbackOnException() {
145145
IterableNotificationWorkScheduler.SchedulerCallback callback =
146146
mock(IterableNotificationWorkScheduler.SchedulerCallback.class);
147147

148-
scheduler.scheduleNotificationWork(data, false, callback);
148+
scheduler.scheduleNotificationWork(data, callback);
149149

150150
verify(callback).onScheduleFailure(any(Exception.class), any(Bundle.class));
151151
}
@@ -161,7 +161,7 @@ public void testScheduleNotificationWorkPassesExceptionToFailureCallback() {
161161
IterableNotificationWorkScheduler.SchedulerCallback callback =
162162
mock(IterableNotificationWorkScheduler.SchedulerCallback.class);
163163

164-
scheduler.scheduleNotificationWork(data, false, callback);
164+
scheduler.scheduleNotificationWork(data, callback);
165165

166166
ArgumentCaptor<Exception> exceptionCaptor = ArgumentCaptor.forClass(Exception.class);
167167
verify(callback).onScheduleFailure(exceptionCaptor.capture(), any(Bundle.class));
@@ -180,7 +180,7 @@ public void testScheduleNotificationWorkPassesOriginalDataToFailureCallback() {
180180
IterableNotificationWorkScheduler.SchedulerCallback callback =
181181
mock(IterableNotificationWorkScheduler.SchedulerCallback.class);
182182

183-
scheduler.scheduleNotificationWork(data, false, callback);
183+
scheduler.scheduleNotificationWork(data, callback);
184184

185185
ArgumentCaptor<Bundle> bundleCaptor = ArgumentCaptor.forClass(Bundle.class);
186186
verify(callback).onScheduleFailure(any(Exception.class), bundleCaptor.capture());
@@ -198,7 +198,7 @@ public void testScheduleNotificationWorkHandlesFailureWithNullCallback() {
198198
.when(mockWorkManager).enqueue(any(OneTimeWorkRequest.class));
199199

200200
// Should not throw exception with null callback
201-
scheduler.scheduleNotificationWork(data, false, null);
201+
scheduler.scheduleNotificationWork(data, null);
202202
}
203203

204204
// ========================================================================
@@ -211,7 +211,7 @@ public void testScheduleNotificationWorkPreservesNotificationData() {
211211
data.putString(IterableConstants.ITERABLE_DATA_TITLE, "Test Title");
212212
data.putString(IterableConstants.ITERABLE_DATA_BODY, "Test Body");
213213

214-
scheduler.scheduleNotificationWork(data, false, null);
214+
scheduler.scheduleNotificationWork(data, null);
215215

216216
ArgumentCaptor<OneTimeWorkRequest> requestCaptor =
217217
ArgumentCaptor.forClass(OneTimeWorkRequest.class);
@@ -226,47 +226,11 @@ public void testScheduleNotificationWorkPreservesNotificationData() {
226226
assertTrue("Should contain body", jsonString.contains("Test Body"));
227227
}
228228

229-
@Test
230-
public void testScheduleNotificationWorkHandlesGhostPushFlagTrue() {
231-
Bundle data = new Bundle();
232-
data.putString("key", "value");
233-
234-
scheduler.scheduleNotificationWork(data, true, null);
235-
236-
ArgumentCaptor<OneTimeWorkRequest> requestCaptor =
237-
ArgumentCaptor.forClass(OneTimeWorkRequest.class);
238-
verify(mockWorkManager).enqueue(requestCaptor.capture());
239-
240-
OneTimeWorkRequest capturedRequest = requestCaptor.getValue();
241-
Data workData = capturedRequest.getWorkSpec().input;
242-
243-
boolean isGhostPush = workData.getBoolean(IterableNotificationWorker.KEY_IS_GHOST_PUSH, false);
244-
assertEquals("Ghost push flag should be true", true, isGhostPush);
245-
}
246-
247-
@Test
248-
public void testScheduleNotificationWorkHandlesGhostPushFlagFalse() {
249-
Bundle data = new Bundle();
250-
data.putString("key", "value");
251-
252-
scheduler.scheduleNotificationWork(data, false, null);
253-
254-
ArgumentCaptor<OneTimeWorkRequest> requestCaptor =
255-
ArgumentCaptor.forClass(OneTimeWorkRequest.class);
256-
verify(mockWorkManager).enqueue(requestCaptor.capture());
257-
258-
OneTimeWorkRequest capturedRequest = requestCaptor.getValue();
259-
Data workData = capturedRequest.getWorkSpec().input;
260-
261-
boolean isGhostPush = workData.getBoolean(IterableNotificationWorker.KEY_IS_GHOST_PUSH, true);
262-
assertEquals("Ghost push flag should be false", false, isGhostPush);
263-
}
264-
265229
@Test
266230
public void testScheduleNotificationWorkHandlesEmptyBundle() {
267231
Bundle emptyData = new Bundle();
268232

269-
scheduler.scheduleNotificationWork(emptyData, false, null);
233+
scheduler.scheduleNotificationWork(emptyData, null);
270234

271235
verify(mockWorkManager).enqueue(any(OneTimeWorkRequest.class));
272236
}
@@ -278,7 +242,7 @@ public void testScheduleNotificationWorkPreservesMultipleFields() {
278242
data.putString("field2", "value2");
279243
data.putString("field3", "value3");
280244

281-
scheduler.scheduleNotificationWork(data, false, null);
245+
scheduler.scheduleNotificationWork(data, null);
282246

283247
ArgumentCaptor<OneTimeWorkRequest> requestCaptor =
284248
ArgumentCaptor.forClass(OneTimeWorkRequest.class);
@@ -302,7 +266,7 @@ public void testScheduleNotificationWorkUsesCorrectWorkerClass() {
302266
Bundle data = new Bundle();
303267
data.putString("key", "value");
304268

305-
scheduler.scheduleNotificationWork(data, false, null);
269+
scheduler.scheduleNotificationWork(data, null);
306270

307271
ArgumentCaptor<OneTimeWorkRequest> requestCaptor =
308272
ArgumentCaptor.forClass(OneTimeWorkRequest.class);
@@ -319,7 +283,7 @@ public void testScheduleNotificationWorkCreatesOneTimeRequest() {
319283
Bundle data = new Bundle();
320284
data.putString("key", "value");
321285

322-
scheduler.scheduleNotificationWork(data, false, null);
286+
scheduler.scheduleNotificationWork(data, null);
323287

324288
// Verify a OneTimeWorkRequest was enqueued
325289
verify(mockWorkManager).enqueue(any(OneTimeWorkRequest.class));
@@ -330,7 +294,7 @@ public void testScheduleNotificationWorkSetsInputData() {
330294
Bundle data = new Bundle();
331295
data.putString("key", "value");
332296

333-
scheduler.scheduleNotificationWork(data, false, null);
297+
scheduler.scheduleNotificationWork(data, null);
334298

335299
ArgumentCaptor<OneTimeWorkRequest> requestCaptor =
336300
ArgumentCaptor.forClass(OneTimeWorkRequest.class);
@@ -356,7 +320,7 @@ public void testSuccessCallbackIsCalledExactlyOnce() {
356320
IterableNotificationWorkScheduler.SchedulerCallback callback =
357321
mock(IterableNotificationWorkScheduler.SchedulerCallback.class);
358322

359-
scheduler.scheduleNotificationWork(data, false, callback);
323+
scheduler.scheduleNotificationWork(data, callback);
360324

361325
verify(callback).onScheduleSuccess(any(UUID.class));
362326
verify(callback, never()).onScheduleFailure(any(Exception.class), any(Bundle.class));
@@ -373,7 +337,7 @@ public void testFailureCallbackIsCalledExactlyOnce() {
373337
IterableNotificationWorkScheduler.SchedulerCallback callback =
374338
mock(IterableNotificationWorkScheduler.SchedulerCallback.class);
375339

376-
scheduler.scheduleNotificationWork(data, false, callback);
340+
scheduler.scheduleNotificationWork(data, callback);
377341

378342
verify(callback).onScheduleFailure(any(Exception.class), any(Bundle.class));
379343
verify(callback, never()).onScheduleSuccess(any(UUID.class));
@@ -385,7 +349,7 @@ public void testCallbacksAreOptional() {
385349
data.putString("key", "value");
386350

387351
// Should work without callbacks (null)
388-
scheduler.scheduleNotificationWork(data, false, null);
352+
scheduler.scheduleNotificationWork(data, null);
389353

390354
verify(mockWorkManager).enqueue(any(OneTimeWorkRequest.class));
391355
}
@@ -401,7 +365,7 @@ public void testFailureCallbackReceivesCorrectException() {
401365
IterableNotificationWorkScheduler.SchedulerCallback callback =
402366
mock(IterableNotificationWorkScheduler.SchedulerCallback.class);
403367

404-
scheduler.scheduleNotificationWork(data, false, callback);
368+
scheduler.scheduleNotificationWork(data, callback);
405369

406370
ArgumentCaptor<Exception> exceptionCaptor = ArgumentCaptor.forClass(Exception.class);
407371
verify(callback).onScheduleFailure(exceptionCaptor.capture(), any(Bundle.class));
@@ -420,7 +384,7 @@ public void testFailureCallbackReceivesOriginalNotificationData() {
420384
IterableNotificationWorkScheduler.SchedulerCallback callback =
421385
mock(IterableNotificationWorkScheduler.SchedulerCallback.class);
422386

423-
scheduler.scheduleNotificationWork(data, false, callback);
387+
scheduler.scheduleNotificationWork(data, callback);
424388

425389
ArgumentCaptor<Bundle> bundleCaptor = ArgumentCaptor.forClass(Bundle.class);
426390
verify(callback).onScheduleFailure(any(Exception.class), bundleCaptor.capture());
@@ -474,7 +438,7 @@ public void testScheduleNotificationWorkCreatesValidInputData() {
474438
Bundle data = new Bundle();
475439
data.putString(IterableConstants.ITERABLE_DATA_TITLE, "Title");
476440

477-
scheduler.scheduleNotificationWork(data, false, null);
441+
scheduler.scheduleNotificationWork(data, null);
478442

479443
ArgumentCaptor<OneTimeWorkRequest> requestCaptor =
480444
ArgumentCaptor.forClass(OneTimeWorkRequest.class);
@@ -489,7 +453,7 @@ public void testScheduleNotificationWorkIncludesAllRequiredKeys() {
489453
Bundle data = new Bundle();
490454
data.putString("key", "value");
491455

492-
scheduler.scheduleNotificationWork(data, false, null);
456+
scheduler.scheduleNotificationWork(data, null);
493457

494458
ArgumentCaptor<OneTimeWorkRequest> requestCaptor =
495459
ArgumentCaptor.forClass(OneTimeWorkRequest.class);
@@ -500,11 +464,6 @@ public void testScheduleNotificationWorkIncludesAllRequiredKeys() {
500464
// Verify required keys are present
501465
assertNotNull("Should have notification JSON",
502466
inputData.getString(IterableNotificationWorker.KEY_NOTIFICATION_DATA_JSON));
503-
504-
// Ghost push flag should be present (default false)
505-
boolean hasFlag = inputData.getKeyValueMap()
506-
.containsKey(IterableNotificationWorker.KEY_IS_GHOST_PUSH);
507-
assertTrue("Should have ghost push flag", hasFlag);
508467
}
509468

510469
@Test
@@ -515,7 +474,7 @@ public void testScheduleNotificationWorkWithComplexData() {
515474
data.putString(IterableConstants.ITERABLE_DATA_BODY, "Body");
516475
data.putString("customField", "customValue");
517476

518-
scheduler.scheduleNotificationWork(data, false, null);
477+
scheduler.scheduleNotificationWork(data, null);
519478

520479
verify(mockWorkManager).enqueue(any(OneTimeWorkRequest.class));
521480
}
@@ -529,7 +488,7 @@ public void testScheduleNotificationWorkHandlesSpecialCharactersInData() {
529488
Bundle data = new Bundle();
530489
data.putString("special", "Value with symbols: !@#$% and \"quotes\"");
531490

532-
scheduler.scheduleNotificationWork(data, false, null);
491+
scheduler.scheduleNotificationWork(data, null);
533492

534493
verify(mockWorkManager).enqueue(any(OneTimeWorkRequest.class));
535494
}
@@ -539,7 +498,7 @@ public void testScheduleNotificationWorkHandlesUnicodeInData() {
539498
Bundle data = new Bundle();
540499
data.putString("unicode", "Unicode: 你好 👋 émojis 🎉");
541500

542-
scheduler.scheduleNotificationWork(data, false, null);
501+
scheduler.scheduleNotificationWork(data, null);
543502

544503
verify(mockWorkManager).enqueue(any(OneTimeWorkRequest.class));
545504
}
@@ -551,7 +510,7 @@ public void testScheduleNotificationWorkHandlesLargeBundle() {
551510
data.putString("key" + i, "value" + i);
552511
}
553512

554-
scheduler.scheduleNotificationWork(data, false, null);
513+
scheduler.scheduleNotificationWork(data, null);
555514

556515
verify(mockWorkManager).enqueue(any(OneTimeWorkRequest.class));
557516
}

0 commit comments

Comments
 (0)