From 0c7aecf16a14f2014210f9ec3ed8e120695c4f85 Mon Sep 17 00:00:00 2001 From: Jeasmine Nahui Date: Tue, 15 Feb 2022 13:30:21 -0300 Subject: [PATCH] Abstract HMS logic from handleNotificationOpen --- .../onesignal/NotificationPayloadProcessorHMS.java | 4 ++++ .../src/main/java/com/onesignal/OneSignal.java | 12 +++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationPayloadProcessorHMS.java b/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationPayloadProcessorHMS.java index d47289c55..b437553c4 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationPayloadProcessorHMS.java +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationPayloadProcessorHMS.java @@ -73,6 +73,10 @@ private static void handleProcessJsonOpenData(@NonNull Activity activity, @NonNu ); } + // HMS notification with Message Type being Message won't trigger Activity reverse trampolining logic + // for this case OneSignal rely on NotificationOpenedActivityHMS activity + // Last EMUI (12 to the date) is based on Android 10, so no + // Activity trampolining restriction exist for HMS devices public static void processDataMessageReceived(@NonNull final Context context, @Nullable String data) { OneSignal.initWithContext(context); if (data == null) diff --git a/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java b/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java index 32176dbf1..92c476215 100644 --- a/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java +++ b/OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java @@ -2336,7 +2336,7 @@ static void fireForegroundHandlers(OSNotificationController notificationControll /** * Method called when opening a notification */ - static void handleNotificationOpen(final Activity context, final JSONArray data, final boolean fromHMSMessage, @Nullable final String notificationId) { + static void handleNotificationOpen(final Activity context, final JSONArray data, final boolean startLauncherActivity, @Nullable final String notificationId) { // Delay call until remote params are set if (taskRemoteController.shouldQueueTaskForInit(OSTaskRemoteController.HANDLE_NOTIFICATION_OPEN)) { logger.error("Waiting for remote params. " + @@ -2346,7 +2346,7 @@ static void handleNotificationOpen(final Activity context, final JSONArray data, public void run() { if (appContext != null) { logger.debug("Running " + OSTaskRemoteController.HANDLE_NOTIFICATION_OPEN + " operation from pending queue."); - handleNotificationOpen(context, data, fromHMSMessage, notificationId); + handleNotificationOpen(context, data, startLauncherActivity, notificationId); } } }); @@ -2365,11 +2365,7 @@ public void run() { if (shouldInitDirectSessionFromNotificationOpen(context, data)) { applicationOpenedByNotification(notificationId); - // HMS notification with Message Type being Message won't trigger Activity reverse trampolining logic - // for this case OneSignal rely on NotificationOpenedActivityHMS activity - // Last EMUI (12 to the date) is based on Android 10, so no - // Activity trampolining restriction exist for HMS devices - if (OSUtils.isHuaweiDeviceType() && fromHMSMessage) { + if (startLauncherActivity) { // Start activity with an activity trampolining startOrResumeApp(context); } @@ -2378,6 +2374,8 @@ public void run() { runNotificationOpenedCallback(data); } + // Reverse activity trampolining is used for most notifications. + // This method is only used if the push provider does support it. // This opens the app in the same way an Android home screen launcher does. // This means we expect the following behavior: // 1. Starts the Activity defined in the app's AndroidManifest.xml as "android.intent.action.MAIN"