Skip to content

Commit 5f40a60

Browse files
authored
Merge pull request #1583 from OneSignal/fix/delayed_activity_trampoline
[Fix] Network Delayed Activity Trampoline
2 parents c208afe + 23cc934 commit 5f40a60

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2395,22 +2395,6 @@ static void fireForegroundHandlers(OSNotificationController notificationControll
23952395
* Method called when opening a notification
23962396
*/
23972397
static void handleNotificationOpen(final Activity context, final JSONArray data, @Nullable final String notificationId) {
2398-
// Delay call until remote params are set
2399-
if (taskRemoteController.shouldQueueTaskForInit(OSTaskRemoteController.HANDLE_NOTIFICATION_OPEN)) {
2400-
logger.error("Waiting for remote params. " +
2401-
"Moving " + OSTaskRemoteController.HANDLE_NOTIFICATION_OPEN + " operation to a pending queue.");
2402-
taskRemoteController.addTaskToQueue(new Runnable() {
2403-
@Override
2404-
public void run() {
2405-
if (appContext != null) {
2406-
logger.debug("Running " + OSTaskRemoteController.HANDLE_NOTIFICATION_OPEN + " operation from pending queue.");
2407-
handleNotificationOpen(context, data, notificationId);
2408-
}
2409-
}
2410-
});
2411-
return;
2412-
}
2413-
24142398
// If applicable, check if the user provided privacy consent
24152399
if (shouldLogUserPrivacyConsentErrorMessageForMethodName(null))
24162400
return;

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,14 @@ public void run() {
139139
sleepTime = MAX_WAIT_BETWEEN_RETRIES;
140140

141141
OneSignal.Log(OneSignal.LOG_LEVEL.INFO, "Failed to get Android parameters, trying again in " + (sleepTime / 1_000) + " seconds.");
142-
OSUtils.sleep(sleepTime);
143-
androidParamsRetries++;
144-
makeAndroidParamsRequest(appId, userId, callback);
142+
try {
143+
Thread.sleep(sleepTime);
144+
androidParamsRetries++;
145+
makeAndroidParamsRequest(appId, userId, callback);
146+
} catch (InterruptedException e) {
147+
// Don't retry if something intentionally wants to stop this action
148+
e.printStackTrace();
149+
}
145150
}
146151
}, "OS_PARAMS_REQUEST").start();
147152
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,25 @@ public void testOpeningLauncherActivity() throws Exception {
10771077
assertNull(shadowOf(blankActivity).getNextStartedActivity());
10781078
}
10791079

1080+
@Test
1081+
public void testOpeningLauncherActivityWhenOffline() throws Exception {
1082+
ShadowOneSignalRestClient.failGetParams = true;
1083+
AddLauncherIntentFilter();
1084+
1085+
OneSignalInit();
1086+
// This removes Activity from the unit test's state
1087+
assertNotNull(shadowOf(blankActivity).getNextStartedActivity());
1088+
1089+
// Background the app
1090+
blankActivityController.pause();
1091+
1092+
// Open a notification
1093+
OneSignal_handleNotificationOpen(blankActivity, new JSONArray("[{ \"alert\": \"Test Msg\", \"custom\": { \"i\": \"UUID\" } }]"), ONESIGNAL_NOTIFICATION_ID);
1094+
1095+
// Ensure the app is foregrounded
1096+
assertNotNull(shadowOf(blankActivity).getNextStartedActivity());
1097+
}
1098+
10801099
@Test
10811100
public void testOpeningLaunchUrl() throws Exception {
10821101
// First init run for appId to be saved

0 commit comments

Comments
 (0)