tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

README.md (7565B)


[Android Components](../../../README.md) > Feature > Push

A component that implements push notifications with a supported push service.

Usage

Add a supported push service for providing the encrypted messages (for example, Firebase Cloud Messaging via lib-push-firebase):

class FirebasePush : AbstractFirebasePushService()

Create a push configuration with the project info and also place the required service's API keys in the project directory:

PushConfig(
  senderId = "push-test-f408f",
  serverHost = "updates.push.services.mozilla.com",
  serviceType = ServiceType.FCM,
  protocol = Protocol.HTTPS
)

We can then start the AutoPushFeature to get the subscription info and decrypted push message:

val service = FirebasePush()

val feature = AutoPushFeature(
  context = context,
  service = pushService,
  config = pushConfig
)

// To start the feature and the service.
feature.initialize()

// To stop the feature and the service.
feature.shutdown()

// To receive the subscription info for all the subscription changes.
feature.register(object : AutoPushFeature.Observer {
  override fun onSubscriptionChanged(scope: PushScope) {
    // Handle subscription info here.
  }
})

// Subscribe for a unique scope (identifier).
feature.subscribe("push_subscription_scope_id")

// To receive messages:
feature.register(object : AutoPushFeature.Observer {
  override fun onMessageReceived(scope: String, message: ByteArray?) {
    // Handle decrypted message here.
  }
})

Setting up the dependency

Use Gradle to download the library from maven.mozilla.org (Setup repository):

implementation "org.mozilla.components:feature-push:{latest-version}"

Implementation Notes

The features of WebPush/AutoPush are to:

  1. android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK
  2. android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK
  3. android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK

Key actors & processes

Below is a sequence diagram for the four main processes that take place for push messaging:

  1. android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK
  2. android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK
  3. android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK
  4. android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK

generated sequence diagram

<details>

<summary>Sequence diagram source code</summary>

<!-- Github Markdown has support for rendering mermaid graphs; use mermaid.js.org to generate output for the diagram alternatively -->

sequenceDiagram
    participant Device as Client App
    participant AutoPush
    participant Provider as Push Provider (FCM/APN)
    participant Server as Server App
    rect rgb(191, 223, 255)
    Note over Device,Server: Initialization
    Note right of Device: Generate pub-priv keys
    Device->>Provider: Request device registration token
    Provider-->>Device: Receive device registration token
    Device->>AutoPush: Send token
    end
    rect rgb(191, 223, 255)
    Note over Device,Server: Creating a push subscription
    Device->>AutoPush: Request subscription endpoint
    AutoPush-->>Device: Receive subscription
    Device->>Server: Send subscription endpoint + public key
    end
    rect rgb(191, 223, 255)
    Note over Device,Server: Sending WebPush message
    Note left of Server: Encrypt message
    Server->>AutoPush: Send encrypted message
    AutoPush->>Provider: Forward encrypted message
    Provider->>Device: Deliver encrypted message
    Note right of Device: Decrypt message
    end
    rect rgb(191, 223, 255)
    Note over Device,Server: Un-subscribing (e.g. account log-out)
    Device->>AutoPush: Unsubscribe
    Device->>Server: Unsubscribe (notify server that the subscription is dead)
    end

</details>

Miscellaneous

Q. Why do we need to verify connections, and what happens when we do?

Q. Where do we find more details about AutoPush?

[0]: https://autopush.readthedocs.io/en/latest/architecture.html

License

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/

[0]: https://github.com/mozilla-services/autopush