mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 10:25:35 +03:00
decoupling the fcm helper from the vector module
This commit is contained in:
parent
f605e0c479
commit
0c61595ace
11 changed files with 95 additions and 31 deletions
|
@ -17,28 +17,36 @@
|
||||||
package im.vector.app.di
|
package im.vector.app.di
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import dagger.Binds
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
import dagger.hilt.components.SingletonComponent
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import im.vector.app.core.pushers.FcmHelper
|
||||||
import im.vector.app.core.services.GuardServiceStarter
|
import im.vector.app.core.services.GuardServiceStarter
|
||||||
import im.vector.app.fdroid.service.FDroidGuardServiceStarter
|
import im.vector.app.fdroid.service.FDroidGuardServiceStarter
|
||||||
import im.vector.app.features.home.NightlyProxy
|
import im.vector.app.features.home.NightlyProxy
|
||||||
import im.vector.app.features.settings.VectorPreferences
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
|
import im.vector.app.push.fcm.FdroidFcmHelper
|
||||||
|
|
||||||
@InstallIn(SingletonComponent::class)
|
@InstallIn(SingletonComponent::class)
|
||||||
@Module
|
@Module
|
||||||
object FlavorModule {
|
abstract class FlavorModule {
|
||||||
|
|
||||||
@Provides
|
companion object {
|
||||||
fun provideGuardServiceStarter(preferences: VectorPreferences, appContext: Context): GuardServiceStarter {
|
@Provides
|
||||||
return FDroidGuardServiceStarter(preferences, appContext)
|
fun provideGuardServiceStarter(preferences: VectorPreferences, appContext: Context): GuardServiceStarter {
|
||||||
}
|
return FDroidGuardServiceStarter(preferences, appContext)
|
||||||
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
fun provideNightlyProxy() = object : NightlyProxy {
|
fun provideNightlyProxy() = object : NightlyProxy {
|
||||||
override fun onHomeResumed() {
|
override fun onHomeResumed() {
|
||||||
// no op
|
// no op
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
abstract fun bindsFcmHelper(fcmHelper: FdroidFcmHelper): FcmHelper
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ package im.vector.app.push.fcm
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
|
import im.vector.app.core.pushers.FcmHelper
|
||||||
import im.vector.app.core.pushers.PushersManager
|
import im.vector.app.core.pushers.PushersManager
|
||||||
import im.vector.app.fdroid.BackgroundSyncStarter
|
import im.vector.app.fdroid.BackgroundSyncStarter
|
||||||
import im.vector.app.fdroid.receiver.AlarmSyncBroadcastReceiver
|
import im.vector.app.fdroid.receiver.AlarmSyncBroadcastReceiver
|
||||||
|
@ -28,19 +29,19 @@ import javax.inject.Inject
|
||||||
/**
|
/**
|
||||||
* This class has an alter ego in the gplay variant.
|
* This class has an alter ego in the gplay variant.
|
||||||
*/
|
*/
|
||||||
class FcmHelper @Inject constructor(
|
class FdroidFcmHelper @Inject constructor(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val backgroundSyncStarter: BackgroundSyncStarter,
|
private val backgroundSyncStarter: BackgroundSyncStarter,
|
||||||
) {
|
) : FcmHelper {
|
||||||
|
|
||||||
fun isFirebaseAvailable(): Boolean = false
|
override fun isFirebaseAvailable(): Boolean = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the FCM registration token.
|
* Retrieves the FCM registration token.
|
||||||
*
|
*
|
||||||
* @return the FCM token or null if not received from FCM
|
* @return the FCM token or null if not received from FCM
|
||||||
*/
|
*/
|
||||||
fun getFcmToken(): String? {
|
override fun getFcmToken(): String? {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ class FcmHelper @Inject constructor(
|
||||||
*
|
*
|
||||||
* @param token the token to store
|
* @param token the token to store
|
||||||
*/
|
*/
|
||||||
fun storeFcmToken(token: String?) {
|
override fun storeFcmToken(token: String?) {
|
||||||
// No op
|
// No op
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,17 +59,17 @@ class FcmHelper @Inject constructor(
|
||||||
*
|
*
|
||||||
* @param activity the first launch Activity
|
* @param activity the first launch Activity
|
||||||
*/
|
*/
|
||||||
fun ensureFcmTokenIsRetrieved(activity: Activity, pushersManager: PushersManager, registerPusher: Boolean) {
|
override fun ensureFcmTokenIsRetrieved(activity: Activity, pushersManager: PushersManager, registerPusher: Boolean) {
|
||||||
// No op
|
// No op
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onEnterForeground(activeSessionHolder: ActiveSessionHolder) {
|
override fun onEnterForeground(activeSessionHolder: ActiveSessionHolder) {
|
||||||
// try to stop all regardless of background mode
|
// try to stop all regardless of background mode
|
||||||
activeSessionHolder.getSafeActiveSession()?.syncService()?.stopAnyBackgroundSync()
|
activeSessionHolder.getSafeActiveSession()?.syncService()?.stopAnyBackgroundSync()
|
||||||
AlarmSyncBroadcastReceiver.cancelAlarm(context)
|
AlarmSyncBroadcastReceiver.cancelAlarm(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onEnterBackground(activeSessionHolder: ActiveSessionHolder) {
|
override fun onEnterBackground(activeSessionHolder: ActiveSessionHolder) {
|
||||||
backgroundSyncStarter.start(activeSessionHolder)
|
backgroundSyncStarter.start(activeSessionHolder)
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,9 +21,11 @@ import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import dagger.hilt.InstallIn
|
import dagger.hilt.InstallIn
|
||||||
import dagger.hilt.components.SingletonComponent
|
import dagger.hilt.components.SingletonComponent
|
||||||
|
import im.vector.app.core.pushers.FcmHelper
|
||||||
import im.vector.app.core.services.GuardServiceStarter
|
import im.vector.app.core.services.GuardServiceStarter
|
||||||
import im.vector.app.features.home.NightlyProxy
|
import im.vector.app.features.home.NightlyProxy
|
||||||
import im.vector.app.nightly.FirebaseNightlyProxy
|
import im.vector.app.nightly.FirebaseNightlyProxy
|
||||||
|
import im.vector.app.push.fcm.GoogleFcmHelper
|
||||||
|
|
||||||
@InstallIn(SingletonComponent::class)
|
@InstallIn(SingletonComponent::class)
|
||||||
@Module
|
@Module
|
||||||
|
@ -38,4 +40,7 @@ abstract class FlavorModule {
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
abstract fun bindsNightlyProxy(nightlyProxy: FirebaseNightlyProxy): NightlyProxy
|
abstract fun bindsNightlyProxy(nightlyProxy: FirebaseNightlyProxy): NightlyProxy
|
||||||
|
|
||||||
|
@Binds
|
||||||
|
abstract fun bindsFcmHelper(fcmHelper: GoogleFcmHelper): FcmHelper
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,10 @@ import androidx.activity.result.ActivityResultLauncher
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import com.google.firebase.messaging.FirebaseMessaging
|
import com.google.firebase.messaging.FirebaseMessaging
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
|
import im.vector.app.core.pushers.FcmHelper
|
||||||
import im.vector.app.core.resources.StringProvider
|
import im.vector.app.core.resources.StringProvider
|
||||||
import im.vector.app.core.utils.startAddGoogleAccountIntent
|
import im.vector.app.core.utils.startAddGoogleAccountIntent
|
||||||
import im.vector.app.features.settings.troubleshoot.TroubleshootTest
|
import im.vector.app.features.settings.troubleshoot.TroubleshootTest
|
||||||
import im.vector.app.push.fcm.FcmHelper
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,10 @@ import androidx.work.WorkInfo
|
||||||
import androidx.work.WorkManager
|
import androidx.work.WorkManager
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
|
import im.vector.app.core.pushers.FcmHelper
|
||||||
import im.vector.app.core.pushers.PushersManager
|
import im.vector.app.core.pushers.PushersManager
|
||||||
import im.vector.app.core.resources.StringProvider
|
import im.vector.app.core.resources.StringProvider
|
||||||
import im.vector.app.features.settings.troubleshoot.TroubleshootTest
|
import im.vector.app.features.settings.troubleshoot.TroubleshootTest
|
||||||
import im.vector.app.push.fcm.FcmHelper
|
|
||||||
import org.matrix.android.sdk.api.session.pushers.PusherState
|
import org.matrix.android.sdk.api.session.pushers.PusherState
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import com.google.firebase.messaging.FirebaseMessaging
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
import im.vector.app.core.di.DefaultSharedPreferences
|
import im.vector.app.core.di.DefaultSharedPreferences
|
||||||
|
import im.vector.app.core.pushers.FcmHelper
|
||||||
import im.vector.app.core.pushers.PushersManager
|
import im.vector.app.core.pushers.PushersManager
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -33,23 +34,23 @@ import javax.inject.Inject
|
||||||
* This class store the FCM token in SharedPrefs and ensure this token is retrieved.
|
* This class store the FCM token in SharedPrefs and ensure this token is retrieved.
|
||||||
* It has an alter ego in the fdroid variant.
|
* It has an alter ego in the fdroid variant.
|
||||||
*/
|
*/
|
||||||
class FcmHelper @Inject constructor(
|
class GoogleFcmHelper @Inject constructor(
|
||||||
context: Context,
|
context: Context,
|
||||||
) {
|
) : FcmHelper {
|
||||||
companion object {
|
companion object {
|
||||||
private const val PREFS_KEY_FCM_TOKEN = "FCM_TOKEN"
|
private const val PREFS_KEY_FCM_TOKEN = "FCM_TOKEN"
|
||||||
}
|
}
|
||||||
|
|
||||||
private val sharedPrefs = DefaultSharedPreferences.getInstance(context)
|
private val sharedPrefs = DefaultSharedPreferences.getInstance(context)
|
||||||
|
|
||||||
fun isFirebaseAvailable(): Boolean = true
|
override fun isFirebaseAvailable(): Boolean = true
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the FCM registration token.
|
* Retrieves the FCM registration token.
|
||||||
*
|
*
|
||||||
* @return the FCM token or null if not received from FCM
|
* @return the FCM token or null if not received from FCM
|
||||||
*/
|
*/
|
||||||
fun getFcmToken(): String? {
|
override fun getFcmToken(): String? {
|
||||||
return sharedPrefs.getString(PREFS_KEY_FCM_TOKEN, null)
|
return sharedPrefs.getString(PREFS_KEY_FCM_TOKEN, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +60,7 @@ class FcmHelper @Inject constructor(
|
||||||
*
|
*
|
||||||
* @param token the token to store
|
* @param token the token to store
|
||||||
*/
|
*/
|
||||||
fun storeFcmToken(token: String?) {
|
override fun storeFcmToken(token: String?) {
|
||||||
sharedPrefs.edit {
|
sharedPrefs.edit {
|
||||||
putString(PREFS_KEY_FCM_TOKEN, token)
|
putString(PREFS_KEY_FCM_TOKEN, token)
|
||||||
}
|
}
|
||||||
|
@ -70,7 +71,7 @@ class FcmHelper @Inject constructor(
|
||||||
*
|
*
|
||||||
* @param activity the first launch Activity
|
* @param activity the first launch Activity
|
||||||
*/
|
*/
|
||||||
fun ensureFcmTokenIsRetrieved(activity: Activity, pushersManager: PushersManager, registerPusher: Boolean) {
|
override fun ensureFcmTokenIsRetrieved(activity: Activity, pushersManager: PushersManager, registerPusher: Boolean) {
|
||||||
// if (TextUtils.isEmpty(getFcmToken(activity))) {
|
// if (TextUtils.isEmpty(getFcmToken(activity))) {
|
||||||
// 'app should always check the device for a compatible Google Play services APK before accessing Google Play services features'
|
// 'app should always check the device for a compatible Google Play services APK before accessing Google Play services features'
|
||||||
if (checkPlayServices(activity)) {
|
if (checkPlayServices(activity)) {
|
||||||
|
@ -106,12 +107,12 @@ class FcmHelper @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNUSED_PARAMETER")
|
@Suppress("UNUSED_PARAMETER")
|
||||||
fun onEnterForeground(activeSessionHolder: ActiveSessionHolder) {
|
override fun onEnterForeground(activeSessionHolder: ActiveSessionHolder) {
|
||||||
// No op
|
// No op
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNUSED_PARAMETER")
|
@Suppress("UNUSED_PARAMETER")
|
||||||
fun onEnterBackground(activeSessionHolder: ActiveSessionHolder) {
|
override fun onEnterBackground(activeSessionHolder: ActiveSessionHolder) {
|
||||||
// No op
|
// No op
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -43,6 +43,7 @@ import dagger.hilt.android.HiltAndroidApp
|
||||||
import im.vector.app.config.Config
|
import im.vector.app.config.Config
|
||||||
import im.vector.app.core.debug.FlipperProxy
|
import im.vector.app.core.debug.FlipperProxy
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
|
import im.vector.app.core.pushers.FcmHelper
|
||||||
import im.vector.app.core.resources.BuildMeta
|
import im.vector.app.core.resources.BuildMeta
|
||||||
import im.vector.app.features.analytics.VectorAnalytics
|
import im.vector.app.features.analytics.VectorAnalytics
|
||||||
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
import im.vector.app.features.call.webrtc.WebRtcCallManager
|
||||||
|
@ -60,7 +61,6 @@ import im.vector.app.features.settings.VectorLocale
|
||||||
import im.vector.app.features.settings.VectorPreferences
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
import im.vector.app.features.themes.ThemeUtils
|
import im.vector.app.features.themes.ThemeUtils
|
||||||
import im.vector.app.features.version.VersionProvider
|
import im.vector.app.features.version.VersionProvider
|
||||||
import im.vector.app.push.fcm.FcmHelper
|
|
||||||
import org.jitsi.meet.sdk.log.JitsiMeetDefaultLogHandler
|
import org.jitsi.meet.sdk.log.JitsiMeetDefaultLogHandler
|
||||||
import org.matrix.android.sdk.api.Matrix
|
import org.matrix.android.sdk.api.Matrix
|
||||||
import org.matrix.android.sdk.api.auth.AuthenticationService
|
import org.matrix.android.sdk.api.auth.AuthenticationService
|
||||||
|
|
50
vector/src/main/java/im/vector/app/core/pushers/FcmHelper.kt
Normal file
50
vector/src/main/java/im/vector/app/core/pushers/FcmHelper.kt
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package im.vector.app.core.pushers
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
|
|
||||||
|
interface FcmHelper {
|
||||||
|
fun isFirebaseAvailable(): Boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the FCM registration token.
|
||||||
|
*
|
||||||
|
* @return the FCM token or null if not received from FCM
|
||||||
|
*/
|
||||||
|
fun getFcmToken(): String?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store FCM token to the SharedPrefs
|
||||||
|
* TODO Store in realm
|
||||||
|
*
|
||||||
|
* @param token the token to store
|
||||||
|
*/
|
||||||
|
fun storeFcmToken(token: String?)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* onNewToken may not be called on application upgrade, so ensure my shared pref is set
|
||||||
|
*
|
||||||
|
* @param activity the first launch Activity
|
||||||
|
*/
|
||||||
|
fun ensureFcmTokenIsRetrieved(activity: Activity, pushersManager: PushersManager, registerPusher: Boolean)
|
||||||
|
|
||||||
|
fun onEnterForeground(activeSessionHolder: ActiveSessionHolder)
|
||||||
|
|
||||||
|
fun onEnterBackground(activeSessionHolder: ActiveSessionHolder)
|
||||||
|
}
|
|
@ -28,7 +28,6 @@ import im.vector.app.core.utils.getApplicationLabel
|
||||||
import im.vector.app.features.VectorFeatures
|
import im.vector.app.features.VectorFeatures
|
||||||
import im.vector.app.features.settings.BackgroundSyncMode
|
import im.vector.app.features.settings.BackgroundSyncMode
|
||||||
import im.vector.app.features.settings.VectorPreferences
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
import im.vector.app.push.fcm.FcmHelper
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.matrix.android.sdk.api.Matrix
|
import org.matrix.android.sdk.api.Matrix
|
||||||
import org.matrix.android.sdk.api.cache.CacheStrategy
|
import org.matrix.android.sdk.api.cache.CacheStrategy
|
||||||
|
|
|
@ -44,6 +44,7 @@ import im.vector.app.core.extensions.replaceFragment
|
||||||
import im.vector.app.core.extensions.validateBackPressed
|
import im.vector.app.core.extensions.validateBackPressed
|
||||||
import im.vector.app.core.platform.VectorBaseActivity
|
import im.vector.app.core.platform.VectorBaseActivity
|
||||||
import im.vector.app.core.platform.VectorMenuProvider
|
import im.vector.app.core.platform.VectorMenuProvider
|
||||||
|
import im.vector.app.core.pushers.FcmHelper
|
||||||
import im.vector.app.core.pushers.PushersManager
|
import im.vector.app.core.pushers.PushersManager
|
||||||
import im.vector.app.core.pushers.UnifiedPushHelper
|
import im.vector.app.core.pushers.UnifiedPushHelper
|
||||||
import im.vector.app.core.utils.startSharePlainTextIntent
|
import im.vector.app.core.utils.startSharePlainTextIntent
|
||||||
|
@ -79,7 +80,6 @@ import im.vector.app.features.spaces.invite.SpaceInviteBottomSheet
|
||||||
import im.vector.app.features.spaces.share.ShareSpaceBottomSheet
|
import im.vector.app.features.spaces.share.ShareSpaceBottomSheet
|
||||||
import im.vector.app.features.themes.ThemeUtils
|
import im.vector.app.features.themes.ThemeUtils
|
||||||
import im.vector.app.features.workers.signout.ServerBackupStatusViewModel
|
import im.vector.app.features.workers.signout.ServerBackupStatusViewModel
|
||||||
import im.vector.app.push.fcm.FcmHelper
|
|
||||||
import kotlinx.coroutines.flow.launchIn
|
import kotlinx.coroutines.flow.launchIn
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
|
@ -19,9 +19,9 @@ package im.vector.app.features.settings.troubleshoot
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import androidx.activity.result.ActivityResultLauncher
|
import androidx.activity.result.ActivityResultLauncher
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
|
import im.vector.app.core.pushers.FcmHelper
|
||||||
import im.vector.app.core.pushers.UnifiedPushHelper
|
import im.vector.app.core.pushers.UnifiedPushHelper
|
||||||
import im.vector.app.core.resources.StringProvider
|
import im.vector.app.core.resources.StringProvider
|
||||||
import im.vector.app.push.fcm.FcmHelper
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class TestAvailableUnifiedPushDistributors @Inject constructor(
|
class TestAvailableUnifiedPushDistributors @Inject constructor(
|
||||||
|
|
Loading…
Reference in a new issue