Pushwoosh / pushwoosh-react-native-plugin

Other
57 stars 43 forks source link

Huawei integration issue #123

Closed olbesp closed 3 years ago

olbesp commented 3 years ago

I'm not able to receive push notifications on Huawei devices.

Steps I've done:

  1. The agconnect-services.json file is placed under <PROJECT_ROOT>android/app/
  2. Signing Certificate Fingerprint (SHA-256) is generated and inserted in AppGallery Connect project settings (both debug + release)
  3. The "Push Kit" service is enabled in AppGallery Connect
  4. All needed dependencies are added: <PROJECT_ROOT>/android/build.gradle Screenshot 2021-03-30 at 22 34 21

<PROJECT_ROOT>/android/app/build.gradle

Screenshot 2021-03-30 at 22 36 45 Screenshot 2021-03-30 at 22 36 38
  1. Pushwoosh project is configured with App ID + App Secret

    Screenshot 2021-03-30 at 22 43 01
  2. In my JavaScript:

    
    PushwooshSDK.init({ pw_appid: PW_APPID, project_number: FB_SENDER })

PushwooshSDK.enableHuaweiPushNotifications();

PushwooshSDK.register()


### AppGallery Connect Cloud debugging

1. I'm able to start the app and I see `PushwooshSDK.init` success callback
2. I'm able to register push_token and see a new user 
<img width="366" alt="Screenshot 2021-03-30 at 22 46 07" src="https://user-images.githubusercontent.com/29006216/113047256-c2e1a380-91a9-11eb-83c7-78dd8284dd41.png">

But I'm not able to receive any push notification that I trigger manually.

More than that, the app crashes after terminate and relaunch on the device (the AppGallery Connect cloud debugging device)
and I see an error in the logs.

Here is a log filtered by "pushwoosh":

2021-03-30 22:22:13 9512-11303/? D/Pushwoosh: [RequestManager] Try To send: setBadge; baseUrl: https://44AAF-9181A.api.pushwoosh.com/json/1.3/ 2021-03-30 22:22:13 9512-9818/? I/WM-WorkerWrapper: Worker result SUCCESS for Work [ id=b24cf56f-5fe8-49cc-a630-e94e5a56447d, tags={ com.pushwoosh.huawei.internal.registrar.HmsRegistrarWorker } ] 2021-03-30 22:22:13 9512-11303/? I/Pushwoosh: [RequestManager] | Pushwoosh request: | Url: https://44AAF-9181A.api.pushwoosh.com/json/1.3/setBadge 2021-03-30 22:22:13 9512-11303/? D/Pushwoosh: [RequestManager] setBadge response success 2021-03-30 22:22:14 9512-9512/? I/Pushwoosh: [HmsRegistrarWorker] HCM token is AE3MDD8i9LnuiNmZZA95-4A7AHCrMpCx-Zicw0e9dgKDUyjYrJXYnTVC8meGAjIHErwVDtcKZTSqCF-lz4E57VP5-TQ5bxsQ3p86FuXmhoxHIkXahwt3F7phMW2kvmi5xA 2021-03-30 22:22:14 9512-9512/? D/Pushwoosh: [DeviceRegistrar] Registering for pushes... 2021-03-30 22:22:14 9512-9605/? D/Pushwoosh: [RequestManager] Try To send: registerDevice; baseUrl: https://44AAF-9181A.api.pushwoosh.com/json/1.3/ 2021-03-30 22:22:14 9512-9605/? I/Pushwoosh: [RequestManager] | Pushwoosh request: | Url: https://44AAF-9181A.api.pushwoosh.com/json/1.3/registerDevice 2021-03-30 22:22:14 9512-9605/? D/Pushwoosh: [RequestManager] registerDevice response success 2021-03-30 22:22:14 9512-9512/? I/Pushwoosh: [DeviceRegistrar] Registered for push notifications: AE3MDD8i9LnuiNmZZA95-4A7AHCrMpCx-Zicw0e9dgKDUyjYrJXYnTVC8meGAjIHErwVDtcKZTSqCF-lz4E57VP5-TQ5bxsQ3p86FuXmhoxHIkXahwt3F7phMW2kvmi5xA 2021-03-30 22:22:44 14644-14644/? E/Pushwoosh: This is not an Amazon device. The service is not available. 2021-03-30 22:22:44 14644-14684/? D/Pushwoosh: [CrashAnalytics] Looking for exceptions in: /data/user/164/com.koerapp.student/files 2021-03-30 22:22:44 14644-14644/? I/Pushwoosh: Log level: DEBUG 2021-03-30 22:22:44 14644-14644/? I/Pushwoosh: [NotificationManager] Sender ID: HUAWEI_DEVICE 2021-03-30 22:22:44 14644-14644/? I/Pushwoosh: [NotificationManager] Sender ID changed, clearing token java.lang.RuntimeException: Unable to get provider com.pushwoosh.PushwooshInitProvider: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.pushwoosh.huawei.internal.registrar.HuaweiPushRegistrar$b.a()' on a null object reference Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.pushwoosh.huawei.internal.registrar.HuaweiPushRegistrar$b.a()' on a null object reference at com.pushwoosh.huawei.internal.registrar.HuaweiPushRegistrar.registerPW(Unknown Source:2) at com.pushwoosh.notification.PushwooshNotificationManager.b(Unknown Source:90) at com.pushwoosh.notification.PushwooshNotificationManager.e(Unknown Source:52) at com.pushwoosh.d.a(Unknown Source:49) at com.pushwoosh.PushwooshPlatform.l(Unknown Source:2) at com.pushwoosh.PushwooshInitializer.init(Unknown Source:64) at com.pushwoosh.PushwooshInitProvider.onCreate(Unknown Source:18)



Also, I attach the entire log file in case you need it too.
[2021-03-30 22_23_06.log](https://github.com/Pushwoosh/pushwoosh-react-native-plugin/files/6231794/2021-03-30.22_23_06.log)

Thanks in advance.

P.S. I use pushwoosh-react-native-plugin *v6.1.3*
wfhm commented 3 years ago

@olbesp,

According to the Message History of the app 44AAF-9181A, you get the NoPermissionToSend error - this is a response we get from HMS when trying to send a push to a token registered with a different App ID/App Secret. I can see that the app configuration was changed several times, so there is a chance that push tokens in your database are no longer valid. Please make sure that the agconnect-services.json and the HMS credentials in the Control Panel configuration match.

As for the crash, may I ask you to share a reproducer APK so we could test it on our side?

olbesp commented 3 years ago

The crash is reproduced on every version after v6.0.10. I test on my old Huawei P Smart+ device (Android 9) It even doesn't matter if I call Pushwoosh.enableHuaweiPushNotifications() or not. Seems like the Pushwoosh plugin "understands" that I use the Huawei device by itself.

The app starts fine and I'm able to register my token and receive a push notification (unfortunately, only through firebase, Huawei push notifications don't work at all). When I restart the app I see this error again and again and the app crashes:

2021-04-01 16:55:19.144 25622-25622/com.koerapp.student E/koerapp.studen: [qarth_debug:]  get PatchStore::createDisableExceptionQarthFile method fail.
2021-04-01 16:55:19.152 25622-25622/com.koerapp.student E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.koerapp.student, PID: 25622
    java.lang.RuntimeException: Unable to get provider com.pushwoosh.PushwooshInitProvider: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.pushwoosh.huawei.internal.registrar.HuaweiPushRegistrar$b.a()' on a null object reference
        at android.app.ActivityThread.installProvider(ActivityThread.java:7278)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6813)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6699)
        at android.app.ActivityThread.access$2000(ActivityThread.java:273)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2020)
        at android.os.Handler.dispatchMessage(Handler.java:112)
        at android.os.Looper.loop(Looper.java:216)
        at android.app.ActivityThread.main(ActivityThread.java:7625)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.pushwoosh.huawei.internal.registrar.HuaweiPushRegistrar$b.a()' on a null object reference
        at com.pushwoosh.huawei.internal.registrar.HuaweiPushRegistrar.registerPW(Unknown Source:2)
        at com.pushwoosh.notification.PushwooshNotificationManager.b(Unknown Source:90)
        at com.pushwoosh.notification.PushwooshNotificationManager.e(Unknown Source:52)
        at com.pushwoosh.d.a(Unknown Source:51)
        at com.pushwoosh.PushwooshPlatform.l(Unknown Source:2)
        at com.pushwoosh.PushwooshInitializer.init(Unknown Source:64)
        at com.pushwoosh.PushwooshInitProvider.onCreate(Unknown Source:18)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1949)
        at android.content.ContentProvider.attachInfo(ContentProvider.java:1923)
        at android.app.ActivityThread.installProvider(ActivityThread.java:7273)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6813) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6699) 
        at android.app.ActivityThread.access$2000(ActivityThread.java:273) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2020) 
        at android.os.Handler.dispatchMessage(Handler.java:112) 
        at android.os.Looper.loop(Looper.java:216) 
        at android.app.ActivityThread.main(ActivityThread.java:7625) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987) 
2021-04-01 16:55:19.165 25622-25622/? I/Process: Sending signal. PID: 25622 SIG: 9

Unfortunately, I can't share the APK file

wfhm commented 3 years ago

@olbesp,

I've reproduced the crash, the fix is already applied to our native Android SDK, and it will be fixed in the React Native plugin with the next release.

The app starts fine and I'm able to register my token and receive a push notification (unfortunately, only through firebase, Huawei push notifications don't work at all).

This might actually be unrelated to the crash - after successful registration, pushes should be received without running the code that caused this bug. Since you have changed Huawei configuration for your app several times and now I can see NoPermissionToSend error responses in your MessageHistory, there is a chance that the current configuration is incorrect. I would suggest deleting all Huawei devices from your database for the app 44AAF-9181A - after you register your device once again, we will see if the issue is related to the config or not. What do you think?

olbesp commented 3 years ago

@wfhm Thanks! I'll check that.

wfhm commented 3 years ago

@olbesp Just in case, to completely remove a device from our backend, you can use /deleteDevice API:

https://docs.pushwoosh.com/platform-docs/api-reference/device-api#deletedevice