Skip to content

Commit

Permalink
Abstract HMS logic from handleNotificationOpen
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeasmine committed Feb 16, 2022
1 parent e1bf7fd commit 0c7aecf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. " +
Expand All @@ -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);
}
}
});
Expand All @@ -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);
}
Expand All @@ -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"
Expand Down

0 comments on commit 0c7aecf

Please sign in to comment.