Leanplum / Leanplum-Android-SDK

Leanplum's integrated solution delivers meaningful engagement across messaging and the in-app experience.
https://www.leanplum.com
Apache License 2.0
46 stars 40 forks source link

Support multiple push providers #433

Closed hborisoff closed 3 years ago

hborisoff commented 3 years ago
What Where/Who
JIRA Issue SDK-204
People Involved @hborisoff

Background

Refactoring Push module to allow easier integration of new push providers other than FCM.

Implementation

  1. Removed LeanplumPushServiceFcm and LeanplumPushRegistrationService as they were not necessary and was making the implementation confusing. Compare version 1 and version 2 of the architecture diagram, check what happens in onStart of LeanplumPushService (centered and green colored) in both diagrams. Also removed LeanplumManualProvider as it is not used anywhere.

  2. PushProviderType - enumeration to differentiate the push providers.

  3. IPushProvider - main interface to implement for a push provider. It contains several methods:

    • getType - Returns the type of this push provider
    • getRegistrationId - Returns the registration id saved in shared preferences
    • setRegistrationId - Saves the registration id to shared preferences and calls the backend
    • unregister - Mainly for testing purposes to reset the push token from the push provider's SDK
    • updateRegistrationId - Updates the current registration ID from the cloud messaging's API
  4. LeanplumCloudMessagingProvider - abstract class implementing the IPushProvider. It adds functionality to save the registration id to shared preferences and sends it to the backend. Provides an abstract method getSharedPrefsPropertyName that its decedents need to implement.

  5. PushProviders - container for all IPushProvider instances. Contains several methods:

    • setRegistrationId - Set registration id for a specific provider. When a push provider's SDK generates a registration token for the app, this method will get called. For example FirebaseMessagingService.onNewToken.
    • updateRegistrationIdsAndBackend - called from LeanplumPushService to tell the providers to initiate logic for getting the registration ids. It calls them one by one by using OperationQueue.addParallelOperation.