OneSignal / OneSignal-Android-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your native Android or Amazon app with OneSignal. https://onesignal.com
Other
592 stars 368 forks source link

[Bug]: OneSignal subscription list shows "Permission is not granted" even the permission is already granted #2106

Open softsan opened 1 month ago

softsan commented 1 month ago

What happened?

For few of my users in production, can't get subscribed to Onesignal. It shows the record in subscription list but it shows as "Permission is not granted" I double / triple checked with the users and they all have given permission for Notification. They also did cache and data clear, logout, uninstall and fresh install several times but it doesn't make any difference. I am using the very latest version of OneSignal SDK. Here are some screenshots:

subscription_list

When i open that subscription, there is no "Externalid" and i am pretty sure I use that in my code:

details

Steps to reproduce?

In my MainApplication.kt I init OneSignal like this:
OneSignal.initWithContext(applicationContext, oneSignalAppId)

this is how i asked permission:
CoroutineScope(Dispatchers.IO).launch {
                OneSignal.Notifications.requestPermission(true)
            }

And after login, i use this:
 OneSignal.login(userIdx)

and register the tags like this:
 OneSignal.User.addTag(key, value)

and on logout from my app i clear all the tags and also sign out from OneSignal
fun unregisterTag(key: String) {
        OneSignal.User.removeTag(key)
    }

fun removeExternalUserId() {
        OneSignal.logout()
    }

Also i created in-app Push prompt for those users and they received that and they always click on "Allow" button but it never get subscribed or if subscribed it shows as "Permission is not granted"

What did you expect to happen?

It should subscribed to Onesignal and should receive push notifications.

OneSignal Android SDK version

5.1.13

Android version

13, 12, 11

Specific Android models

Android 14 Samsung/ pixel device

Relevant log output

No response

Code of Conduct

jennantilla commented 3 weeks ago

Hello @softsan thanks for reaching out! Are you able to reproduce this on any devices you have? If so, capturing a debug log would be most helpful to see what's going on.

Thank you!

softsan commented 2 weeks ago

@jennantilla No, it doesn't reproduce on our dev environment. It mostly on Production user. I also observed that for some of the production user, it shows as "Permission denied" and "Not subscribed" error on OneSignal dashboard. Unfortunately we don't have any access of their device and it's hard for them as well to get the device logs. Btw, do you have any SDK method to capture OneSignal logs (release logs) / device logs into a flle? if so i can use that method to dump logs into file and upload it to my server.

softsan commented 2 weeks ago

@jennantilla Further on this, we have several other users who are seeing either "Permission not granted" or "Not subscribed" on OneSignal dashboard. We double checked that they logout from app, cleared their cache and data, uninstall and fresh install the app. But it still shows the the same on OneSignal dashboard.

os_ss

socialError commented 2 weeks ago

@jennantilla Hello we have the same issue and we can reproduce it 100%.

Version: 5.1.14

How to reproduce?

  1. clean install the app
  2. use Onesignal.login to login user which already exists in onesignal console (that userId was previously logged in the app)
  3. right after that request permission using OneSignal.getNotifications().requestPermission and accept permission

Based on logs when you accept permission OperationRepo.enqueue(operation: {"name":"update-subscription is enqueued and after that should be executed by SubscriptionOperationExecutor and sent to console.

But problem is that if you manage to make step 3 (accepting permission) before login is executed via LoginUserOperationExecutor than SubscriptionOperationExecutor is not created and executed and subscription is in console shown as Permission Not Granted and stuck in that state. (It seems that restarting the app or changing onesignal tags doesn't help. Only fix is to disable permission and enable it manually again).

When it works correctly?

So there seems to be small window if you accept permission after login before login is actually executed that causes this issue that subscription is shown as Permission not granted. We upgraded onesignal from 4.x to 5x and this causes huge issue for us so please take a look at it

Here is the full log you can examine based on steps to reproduce: https://www.dropbox.com/scl/fi/0zd5j9oszm0s67be6tivh/onesignal_issue.tft.rtf?rlkey=hxs6eeahdek9ykqzqddonqksv&dl=0

jkasten2 commented 1 week ago

@socialError thanks for breaking down the issue and documenting exactly when the issue does and doesn't happen.

The root of the issue is when a LoginUserOperation is being combined with a UpdateSubscriptionOperation. LoginUserOperationExecutor processes these together and makes a single REST API call as follows:

HttpClient: Request
Sent = POST
https://api.onesignal.com/apps/{{APP_ID}}/users - Body: {"identity":{"external_id":"SOME_EXISTING_ID"},"subscriptions":
[{"id":"11111111-2222-3333-444444444444","token":"FCM_PUSH_TOKEN","enabled":true,"notification_types":1}],"properties":
{"timezone_id":"Europe\/Bratislava","language":"en"},"refresh_device_metadata":true
}

The OneSignal REST API should be able to accept the subscription update, however as you noted there is a bug where if the externalId already exists the update on the subscription doesn't happen.

This is something the OneSignal backend is looking into, and we will update you here once it is fixed.