diff --git a/vector/src/debug/java/im/vector/app/features/debug/di/DebugModule.kt b/vector/src/debug/java/im/vector/app/features/debug/di/DebugModule.kt index fbac319ee9..56df9fa0bc 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/di/DebugModule.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/di/DebugModule.kt @@ -26,6 +26,8 @@ import dagger.hilt.components.SingletonComponent import im.vector.app.core.debug.DebugReceiver import im.vector.app.features.debug.DebugMenuActivity import im.vector.app.core.debug.DebugNavigator +import im.vector.app.core.debug.FlipperProxy +import im.vector.app.flipper.VectorFlipperProxy import im.vector.app.receivers.VectorDebugReceiver @InstallIn(SingletonComponent::class) @@ -44,4 +46,8 @@ abstract class DebugModule { @Binds abstract fun bindsDebugReceiver(receiver: VectorDebugReceiver): DebugReceiver + + @Binds + abstract fun bindsFlipperProxy(flipperProxy: VectorFlipperProxy): FlipperProxy + } diff --git a/vector/src/debug/java/im/vector/app/flipper/FlipperProxy.kt b/vector/src/debug/java/im/vector/app/flipper/VectorFlipperProxy.kt similarity index 91% rename from vector/src/debug/java/im/vector/app/flipper/FlipperProxy.kt rename to vector/src/debug/java/im/vector/app/flipper/VectorFlipperProxy.kt index 76be7e1b46..2e4336c942 100644 --- a/vector/src/debug/java/im/vector/app/flipper/FlipperProxy.kt +++ b/vector/src/debug/java/im/vector/app/flipper/VectorFlipperProxy.kt @@ -29,19 +29,19 @@ import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPl import com.facebook.soloader.SoLoader import com.kgurgul.flipper.RealmDatabaseDriver import com.kgurgul.flipper.RealmDatabaseProvider +import im.vector.app.core.debug.FlipperProxy import io.realm.RealmConfiguration -import okhttp3.Interceptor import org.matrix.android.sdk.api.Matrix import javax.inject.Inject import javax.inject.Singleton @Singleton -class FlipperProxy @Inject constructor( +class VectorFlipperProxy @Inject constructor( private val context: Context, -) { +) : FlipperProxy { private val networkFlipperPlugin = NetworkFlipperPlugin() - fun init(matrix: Matrix) { + override fun init(matrix: Matrix) { SoLoader.init(context, false) if (FlipperUtils.shouldEnableFlipper(context)) { @@ -65,8 +65,5 @@ class FlipperProxy @Inject constructor( } } - @Suppress("RedundantNullableReturnType") - fun getNetworkInterceptor(): Interceptor? { - return FlipperOkhttpInterceptor(networkFlipperPlugin) - } + override fun networkInterceptor() = FlipperOkhttpInterceptor(networkFlipperPlugin) } diff --git a/vector/src/fdroid/java/im/vector/app/di/FlavorModule.kt b/vector/src/fdroid/java/im/vector/app/di/FlavorModule.kt index 1a3348f4c6..fcad54c3d2 100644 --- a/vector/src/fdroid/java/im/vector/app/di/FlavorModule.kt +++ b/vector/src/fdroid/java/im/vector/app/di/FlavorModule.kt @@ -23,6 +23,7 @@ import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import im.vector.app.core.services.GuardServiceStarter import im.vector.app.fdroid.service.FDroidGuardServiceStarter +import im.vector.app.features.home.NightlyProxy import im.vector.app.features.settings.VectorPreferences @InstallIn(SingletonComponent::class) @@ -33,4 +34,11 @@ object FlavorModule { fun provideGuardServiceStarter(preferences: VectorPreferences, appContext: Context): GuardServiceStarter { return FDroidGuardServiceStarter(preferences, appContext) } + + @Provides + fun provideNightlyProxy() = object : NightlyProxy { + override fun onHomeResumed() { + // no op + } + } } diff --git a/vector/src/gplay/java/im/vector/app/di/FlavorModule.kt b/vector/src/gplay/java/im/vector/app/di/FlavorModule.kt index 901320be4c..256c908a02 100644 --- a/vector/src/gplay/java/im/vector/app/di/FlavorModule.kt +++ b/vector/src/gplay/java/im/vector/app/di/FlavorModule.kt @@ -16,18 +16,26 @@ package im.vector.app.di +import dagger.Binds import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import im.vector.app.core.services.GuardServiceStarter +import im.vector.app.features.home.NightlyProxy +import im.vector.app.nightly.FirebaseNightlyProxy @InstallIn(SingletonComponent::class) @Module -object FlavorModule { +abstract class FlavorModule { - @Provides - fun provideGuardServiceStarter(): GuardServiceStarter { - return object : GuardServiceStarter {} + companion object { + @Provides + fun provideGuardServiceStarter(): GuardServiceStarter { + return object : GuardServiceStarter {} + } } + + @Binds + abstract fun bindsNightlyProxy(nightlyProxy: FirebaseNightlyProxy): NightlyProxy } diff --git a/vector/src/gplay/java/im/vector/app/nightly/NightlyProxy.kt b/vector/src/gplay/java/im/vector/app/nightly/FirebaseNightlyProxy.kt similarity index 95% rename from vector/src/gplay/java/im/vector/app/nightly/NightlyProxy.kt rename to vector/src/gplay/java/im/vector/app/nightly/FirebaseNightlyProxy.kt index 7c6685f5ce..59a1e3eb17 100644 --- a/vector/src/gplay/java/im/vector/app/nightly/NightlyProxy.kt +++ b/vector/src/gplay/java/im/vector/app/nightly/FirebaseNightlyProxy.kt @@ -23,15 +23,17 @@ import com.google.firebase.appdistribution.FirebaseAppDistributionException import im.vector.app.BuildConfig import im.vector.app.core.di.DefaultPreferences import im.vector.app.core.time.Clock +import im.vector.app.features.home.NightlyProxy import timber.log.Timber import javax.inject.Inject -class NightlyProxy @Inject constructor( +class FirebaseNightlyProxy @Inject constructor( private val clock: Clock, @DefaultPreferences private val sharedPreferences: SharedPreferences, -) { - fun onHomeResumed() { +) : NightlyProxy { + + override fun onHomeResumed() { if (!canDisplayPopup()) return val firebaseAppDistribution = FirebaseAppDistribution.getInstance() firebaseAppDistribution.updateIfNewReleaseAvailable() diff --git a/vector/src/main/java/im/vector/app/VectorApplication.kt b/vector/src/main/java/im/vector/app/VectorApplication.kt index b1bd0fc308..f31b5d915e 100644 --- a/vector/src/main/java/im/vector/app/VectorApplication.kt +++ b/vector/src/main/java/im/vector/app/VectorApplication.kt @@ -41,6 +41,7 @@ import com.vanniktech.emoji.EmojiManager import com.vanniktech.emoji.google.GoogleEmojiProvider import dagger.hilt.android.HiltAndroidApp import im.vector.app.config.Config +import im.vector.app.core.debug.FlipperProxy import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.resources.BuildMeta import im.vector.app.features.analytics.VectorAnalytics @@ -59,7 +60,6 @@ import im.vector.app.features.settings.VectorLocale import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.themes.ThemeUtils import im.vector.app.features.version.VersionProvider -import im.vector.app.flipper.FlipperProxy import im.vector.app.push.fcm.FcmHelper import org.jitsi.meet.sdk.log.JitsiMeetDefaultLogHandler import org.matrix.android.sdk.api.Matrix diff --git a/vector/src/main/java/im/vector/app/core/debug/FlipperProxy.kt b/vector/src/main/java/im/vector/app/core/debug/FlipperProxy.kt new file mode 100644 index 0000000000..a05da239f5 --- /dev/null +++ b/vector/src/main/java/im/vector/app/core/debug/FlipperProxy.kt @@ -0,0 +1,25 @@ +/* + * 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.debug + +import okhttp3.Interceptor +import org.matrix.android.sdk.api.Matrix + +interface FlipperProxy { + fun init(matrix: Matrix) + fun networkInterceptor(): Interceptor? +} diff --git a/vector/src/main/java/im/vector/app/core/di/SingletonModule.kt b/vector/src/main/java/im/vector/app/core/di/SingletonModule.kt index 6959f17586..a060ebe731 100644 --- a/vector/src/main/java/im/vector/app/core/di/SingletonModule.kt +++ b/vector/src/main/java/im/vector/app/core/di/SingletonModule.kt @@ -34,6 +34,7 @@ import im.vector.app.EmojiSpanify import im.vector.app.SpaceStateHandler import im.vector.app.SpaceStateHandlerImpl import im.vector.app.config.Config +import im.vector.app.core.debug.FlipperProxy import im.vector.app.core.dispatchers.CoroutineDispatchers import im.vector.app.core.error.DefaultErrorFormatter import im.vector.app.core.error.ErrorFormatter @@ -57,7 +58,6 @@ import im.vector.app.features.settings.FontScalePreferencesImpl import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.ui.SharedPreferencesUiStateRepository import im.vector.app.features.ui.UiStateRepository -import im.vector.app.flipper.FlipperProxy import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.Dispatchers @@ -144,7 +144,7 @@ object VectorStaticModule { roomDisplayNameFallbackProvider = vectorRoomDisplayNameFallbackProvider, threadMessagesEnabledDefault = vectorPreferences.areThreadMessagesEnabled(), networkInterceptors = listOfNotNull( - flipperProxy.getNetworkInterceptor(), + flipperProxy.networkInterceptor(), ) ) } diff --git a/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt b/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt index e5c7ab9228..24a65e1071 100644 --- a/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt +++ b/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt @@ -55,6 +55,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.snackbar.Snackbar import dagger.hilt.android.EntryPointAccessors import im.vector.app.R +import im.vector.app.core.debug.DebugReceiver import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.di.ActivityEntryPoint import im.vector.app.core.dialogs.DialogLocker @@ -91,7 +92,6 @@ import im.vector.app.features.settings.FontScalePreferencesImpl import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.themes.ActivityOtherThemes import im.vector.app.features.themes.ThemeUtils -import im.vector.app.receivers.VectorDebugReceiver import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import org.matrix.android.sdk.api.extensions.orFalse @@ -160,8 +160,9 @@ abstract class VectorBaseActivity : AppCompatActivity(), Maver @Inject lateinit var rageShake: RageShake @Inject lateinit var buildMeta: BuildMeta @Inject lateinit var fontScalePreferences: FontScalePreferences + // For debug only - @Inject lateinit var debugReceiver: VectorDebugReceiver + @Inject lateinit var debugReceiver: DebugReceiver @Inject lateinit var vectorFeatures: VectorFeatures diff --git a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt index 12cdaecdf9..4dd6f8cfba 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt @@ -79,7 +79,6 @@ import im.vector.app.features.spaces.invite.SpaceInviteBottomSheet import im.vector.app.features.spaces.share.ShareSpaceBottomSheet import im.vector.app.features.themes.ThemeUtils import im.vector.app.features.workers.signout.ServerBackupStatusViewModel -import im.vector.app.nightly.NightlyProxy import im.vector.app.push.fcm.FcmHelper import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach diff --git a/vector/src/fdroid/java/im/vector/app/nightly/NightlyProxy.kt b/vector/src/main/java/im/vector/app/features/home/NightlyProxy.kt similarity index 82% rename from vector/src/fdroid/java/im/vector/app/nightly/NightlyProxy.kt rename to vector/src/main/java/im/vector/app/features/home/NightlyProxy.kt index eecf3a24f2..b25add2ac9 100644 --- a/vector/src/fdroid/java/im/vector/app/nightly/NightlyProxy.kt +++ b/vector/src/main/java/im/vector/app/features/home/NightlyProxy.kt @@ -14,10 +14,8 @@ * limitations under the License. */ -package im.vector.app.nightly +package im.vector.app.features.home -import javax.inject.Inject - -class NightlyProxy @Inject constructor() { - fun onHomeResumed() = Unit +interface NightlyProxy { + fun onHomeResumed() } diff --git a/vector/src/release/java/im/vector/app/core/di/DebugModule.kt b/vector/src/release/java/im/vector/app/core/di/DebugModule.kt index c340c36aed..bedbe97864 100644 --- a/vector/src/release/java/im/vector/app/core/di/DebugModule.kt +++ b/vector/src/release/java/im/vector/app/core/di/DebugModule.kt @@ -14,14 +14,18 @@ * limitations under the License. */ -package im.vector.app.features.debug.di +package im.vector.app.core.di -import dagger.Binds +import android.content.Context import dagger.Module +import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import im.vector.app.core.debug.DebugNavigator import im.vector.app.core.debug.DebugReceiver +import im.vector.app.core.debug.FlipperProxy +import okhttp3.Interceptor +import org.matrix.android.sdk.api.Matrix @InstallIn(SingletonComponent::class) @Module @@ -44,4 +48,13 @@ object DebugModule { // no op } } + + @Provides + fun providesFlipperProxy() = object : FlipperProxy { + override fun init(matrix: Matrix) { + // no op + } + + override fun networkInterceptor(): Interceptor? = null + } }