2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

No issue: Use correct server host and force subscribe for push

This commit is contained in:
Jonathan Almeida 2019-07-19 16:05:17 -04:00 committed by Jonathan Almeida
parent 28eb5c541a
commit 2531e9dd62
2 changed files with 33 additions and 15 deletions

View File

@ -17,6 +17,7 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
import mozilla.components.concept.fetch.Client
import mozilla.components.concept.push.PushProcessor
import mozilla.components.service.fretboard.Fretboard
import mozilla.components.service.fretboard.source.kinto.KintoExperimentSource
import mozilla.components.service.fretboard.storage.flatfile.FlatFileExperimentStorage
@ -69,6 +70,13 @@ open class FenixApplication : Application() {
if (Settings.getInstance(this).isTelemetryEnabled) {
components.analytics.metrics.start()
}
// Sets the PushFeature as the singleton instance for push messages to go to.
// We need the push feature setup here to deliver messages in the case where the service
// starts up the app first.
if (FeatureFlags.sendTabEnabled && components.backgroundServices.pushConfig != null) {
PushProcessor.install(components.backgroundServices.push)
}
}
private fun registerRxExceptionHandling() {

View File

@ -6,6 +6,7 @@ package org.mozilla.fenix.components
import android.content.Context
import android.os.Build
import android.preference.PreferenceManager
import androidx.lifecycle.ProcessLifecycleOwner
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@ -13,7 +14,6 @@ import kotlinx.coroutines.launch
import mozilla.components.browser.storage.sync.PlacesBookmarksStorage
import mozilla.components.browser.storage.sync.PlacesHistoryStorage
import mozilla.components.concept.push.Bus
import mozilla.components.concept.push.PushProcessor
import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.DeviceCapability
import mozilla.components.concept.sync.DeviceEvent
@ -76,7 +76,7 @@ class BackgroundServices(
SyncConfig(setOf("history", "bookmarks"), syncPeriodInMinutes = 240L) // four hours
}
private val pushConfig by lazy {
val pushConfig by lazy {
val projectIdKey = context.getString(R.string.pref_key_push_project_id)
val resId = context.resources.getIdentifier(projectIdKey, "string", context.packageName)
if (resId == 0) {
@ -88,7 +88,7 @@ class BackgroundServices(
val pushService by lazy { FirebasePush() }
private val push by lazy {
val push by lazy {
AutoPushFeature(context = context, service = pushService, config = pushConfig!!).also {
// Notify observers for Services' messages.
it.registerForPushMessages(PushType.Services, object : Bus.Observer<PushType, String> {
@ -101,16 +101,31 @@ class BackgroundServices(
// Notify observers for subscription changes.
it.registerForSubscriptions(object : PushSubscriptionObserver {
override fun onSubscriptionAvailable(subscription: AutoPushSubscription) {
accountManager.authenticatedAccount()?.deviceConstellation()
?.setDevicePushSubscriptionAsync(
DevicePushSubscription(
endpoint = subscription.endpoint,
publicKey = subscription.publicKey,
authKey = subscription.authKey
// Update for only the services subscription.
if (subscription.type == PushType.Services) {
accountManager.authenticatedAccount()?.deviceConstellation()
?.setDevicePushSubscriptionAsync(
DevicePushSubscription(
endpoint = subscription.endpoint,
publicKey = subscription.publicKey,
authKey = subscription.authKey
)
)
)
}
}
}, ProcessLifecycleOwner.get(), false)
// For all the current Fenix users, we need to remove the current push token and
// re-subscribe again on the right push server. We should never do this otherwise!
// Should be removed after majority of our users are correctly subscribed.
// See: https://github.com/mozilla-mobile/fenix/issues/4218
val preferences = PreferenceManager.getDefaultSharedPreferences(context)
val prefResetSubKey = "reset_broken_push_subscription"
if (preferences.getBoolean(prefResetSubKey, true)) {
preferences.edit().putBoolean(prefResetSubKey, false).apply()
it.forceRegistrationRenewal()
}
}
}
@ -118,11 +133,6 @@ class BackgroundServices(
// Make the "history" and "bookmark" stores accessible to workers spawned by the sync manager.
GlobalSyncableStoreProvider.configureStore("history" to historyStorage)
GlobalSyncableStoreProvider.configureStore("bookmarks" to bookmarkStorage)
// Sets the PushFeature as the singleton instance for push messages to go to.
if (FeatureFlags.sendTabEnabled && pushConfig != null) {
PushProcessor.install(push)
}
}
private val deviceEventObserver = object : DeviceEventsObserver {