UnifiedPush / android-connector

Mirror of https://codeberg.org/UnifiedPush/android-connector/
Apache License 2.0
35 stars 8 forks source link

Library gets out of sync if distributor is uninstalled #83

Closed nikclayton closed 3 months ago

nikclayton commented 3 months ago

The library can get out of sync if the push distributor is uninstalled.

This can be reproduced with the sample app. To do so, on a test device or emulator:

  1. Install ntfy
  2. Build and run the mainFlavorDebug variant of the sample app (so it doesn't include the FCM distributor)
  3. Click "Register" in the sample app
  4. Note the endpont that was returned when registering
  5. Uninstall ntfy
  6. Re-run the sample app

Bug 1: You'll see that MainActivity redirects to CheckActivity, and CheckActivity shows the old endpoint. While the endpoint may still exist (I don't know what ntfy does with registered endpoints when the app is uninstalled), no notifications from that endpoint are being delivered to the application.

  1. Re-install ntfy
  2. Re-run the sample app

Bug 2: Although ntfy has been re-installed, the old endpoint is still shown.

Bug 2 can be fixed in the sample app by re-writing onResume from:

    override fun onResume() {
        super.onResume()
        if (store.endpoint != null) {
            goToCheckActivity(this)
            finish()
        } else {
            internalReceiver = registerOnRegistrationUpdate {
                if (store.endpoint != null) {
                    goToCheckActivity(this)
                    finish()
                }
            }
        }
    }

to:

    override fun onResume() {
        super.onResume()
        internalReceiver = registerOnRegistrationUpdate {
            if (store.endpoint != null) {
                goToCheckActivity(this)
                finish()
            }
        }

        if (store.featureByteMessage) {
            registerAppWithDialog(this, features = arrayListOf(FEATURE_BYTES_MESSAGE))
        } else {
            registerAppWithDialog(this, features = arrayListOf())
        }
    }

I'm not sure about bug 1. The cleanest thing I can think of is if registerAppWithDialog either:

  1. Broadcast ACTION_REGISTRATION_FAILED if no distributors are available
  2. Broadcast a different action, and there was an associated new receiver callback to deal with the explicit case where no distributors are available

This would allow the end-user app to easily detect this case and respond to it.

p1gp1g commented 3 months ago

For ease of use, getAckDistributor sends an UNREGISTERED intent when the distributor has been uninstalled: https://codeberg.org/UnifiedPush/android-connector/commit/2a7095029c6695e1b51ca3f29a346287f907dab8

Also, the example didn't check if the distributor was still installed before returning the endpoint: https://codeberg.org/UnifiedPush/android-example/commit/36a3d8d1eb5e6e6477b89649a160fc285089c4b1

I think this closes this issue