Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HMS activity open #1533

Merged
merged 2 commits into from
Feb 16, 2022
Merged

Fix HMS activity open #1533

merged 2 commits into from
Feb 16, 2022

Conversation

Jeasmine
Copy link
Contributor

@Jeasmine Jeasmine commented Feb 10, 2022

Description

One Line Summary

HMS notification with Message Type Message doesn't open the app.

Details

Motivation

HMS notification with Message Type Message, don't trigger OS logic. It doesn't enter on the activity reverse trampolining logic. Notification open depends on the start activity that was still implemented in the release 4.4.2. Also, the HMS notification trampolining point of entrance is NotificationOpenedActivityHMS configured by the backend.

Since the last EMUI is based on Android 10 and the coming HarmonyOS version doesn't specify activity trampolining requirements, the last logic was pulled back again.

Scope

HMS notification with Message Type Message

Manual testing

Test app opens by notification with data and message, message type, with application in the background and swiped away. On Huawei P20 Lite Android 9

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

This change is Reviewable

@Jeasmine Jeasmine added the WIP Work In Progress label Feb 10, 2022
@Jeasmine Jeasmine changed the title WIP - Fix HMS Activity trampolining Fix HMS Activity trampolining Feb 10, 2022
@Jeasmine Jeasmine changed the title Fix HMS Activity trampolining Fix HMS activity open Feb 10, 2022
@Jeasmine Jeasmine requested a review from a team February 10, 2022 22:09
@Jeasmine
Copy link
Contributor Author

@jkasten2 will love your point of view in this PR 🙏

@Jeasmine Jeasmine removed the WIP Work In Progress label Feb 10, 2022
Copy link
Member

@jkasten2 jkasten2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jeasmine Thanks for diving in and fixing the issue! Just some things to clean up in the PR and we can get it merged in.

Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @Jeasmine)


OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java, line 2339 at r1 (raw file):

    * Method called when opening a notification
    */
   static void handleNotificationOpen(final Activity context, final JSONArray data, final boolean fromHMSMessage, @Nullable final String notificationId) {

Instead of naming this fromHMSMessage we should come up with a boolean name that is more generic, to separate concerns. Something like startLauncherActivity?


OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java, line 2368 at r1 (raw file):

         applicationOpenedByNotification(notificationId);

         // HMS notification with Message Type being Message won't trigger Activity reverse trampolining logic

This comment would be better fit if it was added to notificationPayloadProcessorHMS.java instead.


OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java, line 2372 at r1 (raw file):

         // Last EMUI (12 to the date) is based on Android 10, so no
         // Activity trampolining restriction exist for HMS devices
         if (OSUtils.isHuaweiDeviceType() && fromHMSMessage) {

Checking OSUtils.isHuaweiDeviceType() is redundant, we can remove it.


OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java, line 2381 at r1 (raw file):

   }

   // This opens the app in the same way an Android home screen launcher does.

Let's add a comment that reverse activity traplining is used for most notifications, this method is only used if the push provider does support it.

@Jeasmine Jeasmine requested a review from emawby February 15, 2022 16:21
Copy link
Contributor Author

@Jeasmine Jeasmine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 2 of 4 files reviewed, 4 unresolved discussions (waiting on @emawby and @jkasten2)


OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java, line 2339 at r1 (raw file):

Previously, jkasten2 (Josh Kasten) wrote…

Instead of naming this fromHMSMessage we should come up with a boolean name that is more generic, to separate concerns. Something like startLauncherActivity?

Done.


OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java, line 2368 at r1 (raw file):

Previously, jkasten2 (Josh Kasten) wrote…

This comment would be better fit if it was added to notificationPayloadProcessorHMS.java instead.

Done.


OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java, line 2372 at r1 (raw file):

Previously, jkasten2 (Josh Kasten) wrote…

Checking OSUtils.isHuaweiDeviceType() is redundant, we can remove it.

Done.


OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java, line 2381 at r1 (raw file):

Previously, jkasten2 (Josh Kasten) wrote…

Let's add a comment that reverse activity traplining is used for most notifications, this method is only used if the push provider does support it.

Nice catch

@Jeasmine
Copy link
Contributor Author

@Jeasmine Thanks for diving in and fixing the issue! Just some things to clean up in the PR and we can get it merged in.

Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @Jeasmine)

OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java, line 2339 at r1 (raw file):

    * Method called when opening a notification
    */
   static void handleNotificationOpen(final Activity context, final JSONArray data, final boolean fromHMSMessage, @Nullable final String notificationId) {

Instead of naming this fromHMSMessage we should come up with a boolean name that is more generic, to separate concerns. Something like startLauncherActivity?

OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java, line 2368 at r1 (raw file):

         applicationOpenedByNotification(notificationId);

         // HMS notification with Message Type being Message won't trigger Activity reverse trampolining logic

This comment would be better fit if it was added to notificationPayloadProcessorHMS.java instead.

OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java, line 2372 at r1 (raw file):

         // Last EMUI (12 to the date) is based on Android 10, so no
         // Activity trampolining restriction exist for HMS devices
         if (OSUtils.isHuaweiDeviceType() && fromHMSMessage) {

Checking OSUtils.isHuaweiDeviceType() is redundant, we can remove it.

OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignal.java, line 2381 at r1 (raw file):

   }

   // This opens the app in the same way an Android home screen launcher does.

Let's add a comment that reverse activity traplining is used for most notifications, this method is only used if the push provider does support it.

Thanks for the review!

Base automatically changed from fix/hms-notification to main February 15, 2022 17:21
Copy link
Member

@jkasten2 jkasten2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 2 of 2 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @jkasten2)

* HMS notification with Message type "Message" won't trigger activity trampolining logic
* Start application from NotificationOpenedActivityHMS
@Jeasmine Jeasmine force-pushed the fix/hms-notification-trampolining branch from 9102a12 to 0c7aecf Compare February 16, 2022 20:03
@Jeasmine Jeasmine merged commit 1086758 into main Feb 16, 2022
@Jeasmine Jeasmine deleted the fix/hms-notification-trampolining branch February 16, 2022 20:04
@nan-li nan-li mentioned this pull request Mar 3, 2022
@jkasten2
Copy link
Member

jkasten2 commented Mar 4, 2022

@peter-rosendahl Just wanted to call out to you this should fix the issue in the #1494 (comment) you left when sending HMS notification types (not data type). It is now available in the 4.7.0 release:
https://github.com/OneSignal/OneSignal-Android-SDK/releases/tag/4.7.0

You can manually bump the OneSignal version in your app/build.gradle under your platforms/android folder to get this update now for your Cordova app. Or wait a bit longer until we make a Cordova new release.

@dkoeltringer
Copy link

@jkasten2 I have a similar or the same issue as @peter-rosendahl with the OneSignal SDK for Android. I hoped it is fixed now with the 4.7.0 release, but the issue is still present on my Huawei device. The notification is present, but when clicking on it, the app is not opened.
Can you have a look on this? If you need additional information, I am glad to help!

@jkasten2
Copy link
Member

@dkoeltringer Thanks for reporting. Is the issue happening with "message" and / or "data" Huawei HMS notification types?
By default OneSignal uses HMS "message" type but you can change this via the REST API by adding huawei_msg_type or setting it under the notification settings on the dashboard before seeing:

The different is important as they work much differently from another.

Questions

  1. Does the issue happen with "message" and / or "data" Huawei HMS notification types?
  2. Does the state of your app matter? App backgrounded vs closed swiped away.
  3. What version of EMUI and Android do you see the issue on?
  4. Provide a full system logcat with no filtering so we can see the system events to debug.

@dkoeltringer
Copy link

@jkasten2 Thank you for your quick reply!
One maybe important thing, I have missed in my last post: The issue happens only if there is a launch url added. Without the launch url the app is started without problem, but only the main activity, because the launch url is missing.

Here the answers for your questions:

  1. We used HMS notification type "message". After trying "data" everything worked without problem. So I think this is the fix we have searched for.
  2. Does not matter.
  3. EMUI 10.1.0, Android 10
  4. Do you still need the logcat for analyzing the issue, or is this not needed anymore, because the issue has resolved with the "data" notification type?

Thank you very much for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants