Skip to content

onUnregistered message is not always sent by unregisterApp #82

@nikclayton

Description

@nikclayton

My expectation, from the docs, was that calling unregisterApp() should always result in the receiver's onUnregistered method being called.

It's not, and I think that could be a problem.

Suppose I use onUnregistered to make an API call to my remote server to disable push messages. So something like:

@AndroidEntryPoint
class UnifiedPushBroadcastReceiver : MessagingReceiver() {
    @Inject
    lateinit var api: RemoteApi

    // ...

    override fun onUnregistered(context: Context, instance: String) {
        api.unsubscribePush(instance)  // HTTP DELETE /api/v1/push/:instance
    }
}

Elsewhere in my code I allow the user to log out from their account, and as part of the log out logic I have this:

suspend fun logout(context: Context, account: Account) {
    // ...
   
    UnifiedPush.unregisterApp(context, account.unifiedPushInstance)

    // ...
}

My expectation is the call to unregisterApp() will send the broadcast message, onUnregistered will be called, and an RPC to the server to unsubscribe from push messages will be sent.

However...

unregisterApp() may return early, without sending the broadcast message. If I'm reading the code correctly this can happen if the user deletes the app they're using as the push distributor.

For example, suppose:

  1. The user installs my app
  2. My app tells them to install a push distributor
  3. They decide to install ntfy
  4. After trying my app they decide they don't want to use it any more
  5. They uninstall ntfy
  6. They log out of my app, then uninstall it

Because they uninstalled ntfy before logging out of my app onUnregistered is not called, and the push subscription is never deleted from the server.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions