Skip to content

Commit

Permalink
Merge pull request #1583 from OneSignal/fix/delayed_activity_trampoline
Browse files Browse the repository at this point in the history
[Fix] Network Delayed Activity Trampoline
  • Loading branch information
jkasten2 authored May 14, 2022
2 parents c208afe + 23cc934 commit 5f40a60
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
16 changes: 0 additions & 16 deletions OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java
Original file line number Diff line number Diff line change
Expand Up @@ -2395,22 +2395,6 @@ static void fireForegroundHandlers(OSNotificationController notificationControll
* Method called when opening a notification
*/
static void handleNotificationOpen(final Activity context, final JSONArray data, @Nullable final String notificationId) {
// Delay call until remote params are set
if (taskRemoteController.shouldQueueTaskForInit(OSTaskRemoteController.HANDLE_NOTIFICATION_OPEN)) {
logger.error("Waiting for remote params. " +
"Moving " + OSTaskRemoteController.HANDLE_NOTIFICATION_OPEN + " operation to a pending queue.");
taskRemoteController.addTaskToQueue(new Runnable() {
@Override
public void run() {
if (appContext != null) {
logger.debug("Running " + OSTaskRemoteController.HANDLE_NOTIFICATION_OPEN + " operation from pending queue.");
handleNotificationOpen(context, data, notificationId);
}
}
});
return;
}

// If applicable, check if the user provided privacy consent
if (shouldLogUserPrivacyConsentErrorMessageForMethodName(null))
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,14 @@ public void run() {
sleepTime = MAX_WAIT_BETWEEN_RETRIES;

OneSignal.Log(OneSignal.LOG_LEVEL.INFO, "Failed to get Android parameters, trying again in " + (sleepTime / 1_000) + " seconds.");
OSUtils.sleep(sleepTime);
androidParamsRetries++;
makeAndroidParamsRequest(appId, userId, callback);
try {
Thread.sleep(sleepTime);
androidParamsRetries++;
makeAndroidParamsRequest(appId, userId, callback);
} catch (InterruptedException e) {
// Don't retry if something intentionally wants to stop this action
e.printStackTrace();
}
}
}, "OS_PARAMS_REQUEST").start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,25 @@ public void testOpeningLauncherActivity() throws Exception {
assertNull(shadowOf(blankActivity).getNextStartedActivity());
}

@Test
public void testOpeningLauncherActivityWhenOffline() throws Exception {
ShadowOneSignalRestClient.failGetParams = true;
AddLauncherIntentFilter();

OneSignalInit();
// This removes Activity from the unit test's state
assertNotNull(shadowOf(blankActivity).getNextStartedActivity());

// Background the app
blankActivityController.pause();

// Open a notification
OneSignal_handleNotificationOpen(blankActivity, new JSONArray("[{ \"alert\": \"Test Msg\", \"custom\": { \"i\": \"UUID\" } }]"), ONESIGNAL_NOTIFICATION_ID);

// Ensure the app is foregrounded
assertNotNull(shadowOf(blankActivity).getNextStartedActivity());
}

@Test
public void testOpeningLaunchUrl() throws Exception {
// First init run for appId to be saved
Expand Down

0 comments on commit 5f40a60

Please sign in to comment.