Ensure that a PushProvider is available on a device before using it.
It help to fallback to UnifiedPush (if available) if the PlayServices are not installed on the device.
This commit is contained in:
parent
e2c9389d36
commit
7498c148f1
5 changed files with 45 additions and 1 deletions
|
|
@ -19,6 +19,7 @@ package io.element.android.libraries.pushproviders.unifiedpush
|
|||
import android.content.Context
|
||||
import com.squareup.anvil.annotations.ContributesMultibinding
|
||||
import io.element.android.libraries.androidutils.system.getApplicationLabel
|
||||
import io.element.android.libraries.core.log.logger.LoggerTag
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.libraries.di.ApplicationContext
|
||||
import io.element.android.libraries.matrix.api.MatrixClient
|
||||
|
|
@ -26,8 +27,11 @@ import io.element.android.libraries.pushproviders.api.Distributor
|
|||
import io.element.android.libraries.pushproviders.api.PushProvider
|
||||
import io.element.android.libraries.pushstore.api.clientsecret.PushClientSecret
|
||||
import org.unifiedpush.android.connector.UnifiedPush
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
private val loggerTag = LoggerTag("UnifiedPushProvider", LoggerTag.PushLoggerTag)
|
||||
|
||||
@ContributesMultibinding(AppScope::class)
|
||||
class UnifiedPushProvider @Inject constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
|
|
@ -38,6 +42,17 @@ class UnifiedPushProvider @Inject constructor(
|
|||
override val index = UnifiedPushConfig.INDEX
|
||||
override val name = UnifiedPushConfig.NAME
|
||||
|
||||
override fun isAvailable(): Boolean {
|
||||
val isAvailable = getDistributors().isNotEmpty()
|
||||
return if (isAvailable) {
|
||||
Timber.tag(loggerTag.value).d("UnifiedPush is available")
|
||||
true
|
||||
} else {
|
||||
Timber.tag(loggerTag.value).w("UnifiedPush is not available")
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
override fun getDistributors(): List<Distributor> {
|
||||
val distributors = UnifiedPush.getDistributors(context)
|
||||
return distributors.mapNotNull {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue