From e02cf61f2ff410b4accd1481ea1e0b564fb05ee9 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Mon, 8 Aug 2022 16:57:51 +0100 Subject: [PATCH 01/12] decoupling debug receiver from the variants by introducing vector layer interface --- .../app/features/debug/di/DebugModule.kt | 32 ++++++++++++++++ ...ebugReceiver.kt => VectorDebugReceiver.kt} | 12 +++++- .../vector/app/core/platform/DebugReceiver.kt | 24 ++++++++++++ .../app/core/platform/VectorBaseActivity.kt | 21 +++------- .../java/im/vector/app/core/di/DebugModule.kt | 38 +++++++++++++++++++ 5 files changed, 110 insertions(+), 17 deletions(-) create mode 100644 vector/src/debug/java/im/vector/app/features/debug/di/DebugModule.kt rename vector/src/debug/java/im/vector/app/receivers/{DebugReceiver.kt => VectorDebugReceiver.kt} (88%) create mode 100644 vector/src/main/java/im/vector/app/core/platform/DebugReceiver.kt create mode 100644 vector/src/release/java/im/vector/app/core/di/DebugModule.kt 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 new file mode 100644 index 00000000000..d68d6c743f0 --- /dev/null +++ b/vector/src/debug/java/im/vector/app/features/debug/di/DebugModule.kt @@ -0,0 +1,32 @@ +/* + * 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.features.debug.di + +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import im.vector.app.core.platform.DebugReceiver +import im.vector.app.receivers.VectorDebugReceiver + +@InstallIn(SingletonComponent::class) +@Module +abstract class DebugModule { + + @Binds + abstract fun bindsDebugReceiver(receiver: VectorDebugReceiver): DebugReceiver +} diff --git a/vector/src/debug/java/im/vector/app/receivers/DebugReceiver.kt b/vector/src/debug/java/im/vector/app/receivers/VectorDebugReceiver.kt similarity index 88% rename from vector/src/debug/java/im/vector/app/receivers/DebugReceiver.kt rename to vector/src/debug/java/im/vector/app/receivers/VectorDebugReceiver.kt index 9ec475d6d33..9b547a433e5 100644 --- a/vector/src/debug/java/im/vector/app/receivers/DebugReceiver.kt +++ b/vector/src/debug/java/im/vector/app/receivers/VectorDebugReceiver.kt @@ -23,13 +23,23 @@ import android.content.IntentFilter import android.content.SharedPreferences import androidx.core.content.edit import im.vector.app.core.di.DefaultSharedPreferences +import im.vector.app.core.platform.DebugReceiver import im.vector.app.core.utils.lsFiles import timber.log.Timber +import javax.inject.Inject /** * Receiver to handle some command from ADB */ -class DebugReceiver : BroadcastReceiver() { +class VectorDebugReceiver @Inject constructor() : BroadcastReceiver(), DebugReceiver { + + override fun register(context: Context) { + context.registerReceiver(this, getIntentFilter(context)) + } + + override fun unregister(context: Context) { + context.unregisterReceiver(this) + } override fun onReceive(context: Context, intent: Intent) { Timber.v("Received debug action: ${intent.action}") diff --git a/vector/src/main/java/im/vector/app/core/platform/DebugReceiver.kt b/vector/src/main/java/im/vector/app/core/platform/DebugReceiver.kt new file mode 100644 index 00000000000..aeb99f312d7 --- /dev/null +++ b/vector/src/main/java/im/vector/app/core/platform/DebugReceiver.kt @@ -0,0 +1,24 @@ +/* + * 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.platform + +import android.content.Context + +interface DebugReceiver { + fun register(context: Context) + fun unregister(context: Context) +} 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 8a09b6bd46a..e5c7ab92283 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 @@ -91,7 +91,7 @@ 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.DebugReceiver +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,6 +160,8 @@ 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 vectorFeatures: VectorFeatures @@ -176,9 +178,6 @@ abstract class VectorBaseActivity : AppCompatActivity(), Maver private var savedInstanceState: Bundle? = null - // For debug only - private var debugReceiver: DebugReceiver? = null - private val restorables = ArrayList() override fun attachBaseContext(base: Context) { @@ -418,13 +417,7 @@ abstract class VectorBaseActivity : AppCompatActivity(), Maver if (this !is BugReportActivity && vectorPreferences.useRageshake()) { rageShake.start() } - DebugReceiver - .getIntentFilter(this) - .takeIf { buildMeta.isDebug } - ?.let { - debugReceiver = DebugReceiver() - registerReceiver(debugReceiver, it) - } + debugReceiver.register(this) } private val postResumeScheduledActions = mutableListOf<() -> Unit>() @@ -454,11 +447,7 @@ abstract class VectorBaseActivity : AppCompatActivity(), Maver Timber.i("onPause Activity ${javaClass.simpleName}") rageShake.stop() - - debugReceiver?.let { - unregisterReceiver(debugReceiver) - debugReceiver = null - } + debugReceiver.unregister(this) } override fun onWindowFocusChanged(hasFocus: Boolean) { 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 new file mode 100644 index 00000000000..2899b14b7b0 --- /dev/null +++ b/vector/src/release/java/im/vector/app/core/di/DebugModule.kt @@ -0,0 +1,38 @@ +/* + * 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.features.debug.di + +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import im.vector.app.core.platform.DebugReceiver + +@InstallIn(SingletonComponent::class) +@Module +object DebugModule { + @Provides + fun providesDebugReceiver() = object: DebugReceiver { + override fun register(context: Context) { + // no op + } + + override fun unregister(context: Context) { + // no op + } + } +} From 19c8b2a630e0e15d1f828bec0e2a3a69e9b9b2d9 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Mon, 8 Aug 2022 17:02:08 +0100 Subject: [PATCH 02/12] moving debug menu access to only the debug sourceset and providing an injectable interface to decouple from the direct access --- vector/src/debug/AndroidManifest.xml | 1 + .../vector/app/features/debug/di/DebugModule.kt | 15 +++++++++++++++ vector/src/main/AndroidManifest.xml | 1 - .../app/features/navigation/DebugNavigator.kt} | 11 ++++++----- .../app/features/navigation/DefaultNavigator.kt | 7 ++++--- .../java/im/vector/app/core/di/DebugModule.kt | 11 ++++++++++- 6 files changed, 36 insertions(+), 10 deletions(-) rename vector/src/{release/java/im/vector/app/features/debug/DebugMenuActivity.kt => main/java/im/vector/app/features/navigation/DebugNavigator.kt} (74%) diff --git a/vector/src/debug/AndroidManifest.xml b/vector/src/debug/AndroidManifest.xml index 84fa2584b95..4ec47d49208 100644 --- a/vector/src/debug/AndroidManifest.xml +++ b/vector/src/debug/AndroidManifest.xml @@ -9,6 +9,7 @@ + - diff --git a/vector/src/release/java/im/vector/app/features/debug/DebugMenuActivity.kt b/vector/src/main/java/im/vector/app/features/navigation/DebugNavigator.kt similarity index 74% rename from vector/src/release/java/im/vector/app/features/debug/DebugMenuActivity.kt rename to vector/src/main/java/im/vector/app/features/navigation/DebugNavigator.kt index c5db033a18a..26e8a3e5c68 100644 --- a/vector/src/release/java/im/vector/app/features/debug/DebugMenuActivity.kt +++ b/vector/src/main/java/im/vector/app/features/navigation/DebugNavigator.kt @@ -1,5 +1,5 @@ /* - * Copyright 2019 New Vector Ltd + * 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. @@ -14,9 +14,10 @@ * limitations under the License. */ -package im.vector.app.features.debug +package im.vector.app.features.navigation -import androidx.appcompat.app.AppCompatActivity +import android.content.Context -// This activity is not accessible -class DebugMenuActivity : AppCompatActivity() +interface DebugNavigator { + fun openDebugMenu(context: Context) +} diff --git a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt index 38db6422876..e9f1619ed5e 100644 --- a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt +++ b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt @@ -51,7 +51,6 @@ import im.vector.app.features.crypto.recover.BootstrapBottomSheet import im.vector.app.features.crypto.recover.SetupMode import im.vector.app.features.crypto.verification.SupportedVerificationMethodsProvider import im.vector.app.features.crypto.verification.VerificationBottomSheet -import im.vector.app.features.debug.DebugMenuActivity import im.vector.app.features.devtools.RoomDevToolActivity import im.vector.app.features.home.room.detail.RoomDetailActivity import im.vector.app.features.home.room.detail.arguments.TimelineArgs @@ -123,7 +122,8 @@ class DefaultNavigator @Inject constructor( private val spaceStateHandler: SpaceStateHandler, private val supportedVerificationMethodsProvider: SupportedVerificationMethodsProvider, private val features: VectorFeatures, - private val analyticsTracker: AnalyticsTracker + private val analyticsTracker: AnalyticsTracker, + private val debugNavigator: DebugNavigator, ) : Navigator { override fun openLogin(context: Context, loginConfig: LoginConfig?, flags: Int) { @@ -367,7 +367,7 @@ class DefaultNavigator @Inject constructor( } override fun openDebug(context: Context) { - context.startActivity(Intent(context, DebugMenuActivity::class.java)) + debugNavigator.openDebugMenu(context) } override fun openKeysBackupSetup(context: Context, showManualExport: Boolean) { @@ -615,3 +615,4 @@ class DefaultNavigator @Inject constructor( context.startActivity(this) } } + 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 2899b14b7b0..c5af1e06c80 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 @@ -21,12 +21,21 @@ import dagger.Module import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent import im.vector.app.core.platform.DebugReceiver +import im.vector.app.features.navigation.DebugNavigator @InstallIn(SingletonComponent::class) @Module object DebugModule { + + @Provides + fun providesDebugNavigator() = object : DebugNavigator { + override fun openDebugMenu(context: Context) { + // no op + } + } + @Provides - fun providesDebugReceiver() = object: DebugReceiver { + fun providesDebugReceiver() = object : DebugReceiver { override fun register(context: Context) { // no op } From 8156a646a118d951af376286b1836f22ab36901b Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Mon, 8 Aug 2022 17:06:57 +0100 Subject: [PATCH 03/12] moving debug interfaces to debug package --- .../debug/java/im/vector/app/features/debug/di/DebugModule.kt | 4 ++-- .../debug/java/im/vector/app/receivers/VectorDebugReceiver.kt | 2 +- .../app/{features/navigation => core/debug}/DebugNavigator.kt | 2 +- .../im/vector/app/core/{platform => debug}/DebugReceiver.kt | 2 +- .../im/vector/app/features/navigation/DefaultNavigator.kt | 1 + vector/src/release/java/im/vector/app/core/di/DebugModule.kt | 4 ++-- 6 files changed, 8 insertions(+), 7 deletions(-) rename vector/src/main/java/im/vector/app/{features/navigation => core/debug}/DebugNavigator.kt (94%) rename vector/src/main/java/im/vector/app/core/{platform => debug}/DebugReceiver.kt (95%) 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 f5f10bf9c9d..fbac319ee93 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 @@ -23,9 +23,9 @@ import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent -import im.vector.app.core.platform.DebugReceiver +import im.vector.app.core.debug.DebugReceiver import im.vector.app.features.debug.DebugMenuActivity -import im.vector.app.features.navigation.DebugNavigator +import im.vector.app.core.debug.DebugNavigator import im.vector.app.receivers.VectorDebugReceiver @InstallIn(SingletonComponent::class) diff --git a/vector/src/debug/java/im/vector/app/receivers/VectorDebugReceiver.kt b/vector/src/debug/java/im/vector/app/receivers/VectorDebugReceiver.kt index 9b547a433e5..827fc540f72 100644 --- a/vector/src/debug/java/im/vector/app/receivers/VectorDebugReceiver.kt +++ b/vector/src/debug/java/im/vector/app/receivers/VectorDebugReceiver.kt @@ -23,7 +23,7 @@ import android.content.IntentFilter import android.content.SharedPreferences import androidx.core.content.edit import im.vector.app.core.di.DefaultSharedPreferences -import im.vector.app.core.platform.DebugReceiver +import im.vector.app.core.debug.DebugReceiver import im.vector.app.core.utils.lsFiles import timber.log.Timber import javax.inject.Inject diff --git a/vector/src/main/java/im/vector/app/features/navigation/DebugNavigator.kt b/vector/src/main/java/im/vector/app/core/debug/DebugNavigator.kt similarity index 94% rename from vector/src/main/java/im/vector/app/features/navigation/DebugNavigator.kt rename to vector/src/main/java/im/vector/app/core/debug/DebugNavigator.kt index 26e8a3e5c68..16c8dac55cd 100644 --- a/vector/src/main/java/im/vector/app/features/navigation/DebugNavigator.kt +++ b/vector/src/main/java/im/vector/app/core/debug/DebugNavigator.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package im.vector.app.features.navigation +package im.vector.app.core.debug import android.content.Context diff --git a/vector/src/main/java/im/vector/app/core/platform/DebugReceiver.kt b/vector/src/main/java/im/vector/app/core/debug/DebugReceiver.kt similarity index 95% rename from vector/src/main/java/im/vector/app/core/platform/DebugReceiver.kt rename to vector/src/main/java/im/vector/app/core/debug/DebugReceiver.kt index aeb99f312d7..7cccba3d375 100644 --- a/vector/src/main/java/im/vector/app/core/platform/DebugReceiver.kt +++ b/vector/src/main/java/im/vector/app/core/debug/DebugReceiver.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package im.vector.app.core.platform +package im.vector.app.core.debug import android.content.Context diff --git a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt index e9f1619ed5e..872f102a0d8 100644 --- a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt +++ b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt @@ -51,6 +51,7 @@ import im.vector.app.features.crypto.recover.BootstrapBottomSheet import im.vector.app.features.crypto.recover.SetupMode import im.vector.app.features.crypto.verification.SupportedVerificationMethodsProvider import im.vector.app.features.crypto.verification.VerificationBottomSheet +import im.vector.app.core.debug.DebugNavigator import im.vector.app.features.devtools.RoomDevToolActivity import im.vector.app.features.home.room.detail.RoomDetailActivity import im.vector.app.features.home.room.detail.arguments.TimelineArgs 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 c5af1e06c80..c340c36aed1 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 @@ -20,8 +20,8 @@ import dagger.Binds import dagger.Module import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent -import im.vector.app.core.platform.DebugReceiver -import im.vector.app.features.navigation.DebugNavigator +import im.vector.app.core.debug.DebugNavigator +import im.vector.app.core.debug.DebugReceiver @InstallIn(SingletonComponent::class) @Module From 02286b96b05b8d2529848035753b352355c5f762 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Mon, 8 Aug 2022 17:13:43 +0100 Subject: [PATCH 04/12] decoupling the flipper proxy from the vector module --- .../app/features/debug/di/DebugModule.kt | 6 +++++ ...{FlipperProxy.kt => VectorFlipperProxy.kt} | 13 ++++------ .../java/im/vector/app/di/FlavorModule.kt | 8 ++++++ .../java/im/vector/app/di/FlavorModule.kt | 16 +++++++++--- ...ightlyProxy.kt => FirebaseNightlyProxy.kt} | 8 +++--- .../java/im/vector/app/VectorApplication.kt | 2 +- .../im/vector/app/core/debug/FlipperProxy.kt | 25 +++++++++++++++++++ .../im/vector/app/core/di/SingletonModule.kt | 4 +-- .../app/core/platform/VectorBaseActivity.kt | 5 ++-- .../vector/app/features/home/HomeActivity.kt | 1 - .../vector/app/features/home}/NightlyProxy.kt | 8 +++--- .../java/im/vector/app/core/di/DebugModule.kt | 17 +++++++++++-- 12 files changed, 85 insertions(+), 28 deletions(-) rename vector/src/debug/java/im/vector/app/flipper/{FlipperProxy.kt => VectorFlipperProxy.kt} (91%) rename vector/src/gplay/java/im/vector/app/nightly/{NightlyProxy.kt => FirebaseNightlyProxy.kt} (95%) create mode 100644 vector/src/main/java/im/vector/app/core/debug/FlipperProxy.kt rename vector/src/{fdroid/java/im/vector/app/nightly => main/java/im/vector/app/features/home}/NightlyProxy.kt (82%) 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 fbac319ee93..56df9fa0bc5 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 76be7e1b46d..2e4336c9422 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 1a3348f4c6f..fcad54c3d2f 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 901320be4cd..256c908a02b 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 7c6685f5ced..59a1e3eb173 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 b1bd0fc3083..f31b5d915e4 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 00000000000..a05da239f54 --- /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 6959f17586b..a060ebe7317 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 e5c7ab92283..24a65e1071f 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 12cdaecdf91..4dd6f8cfba7 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 eecf3a24f26..b25add2ac93 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 c340c36aed1..bedbe97864d 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 + } } From f605e0c4791318e3f8b103004b7cd4fa1fa4c223 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Mon, 8 Aug 2022 17:51:08 +0100 Subject: [PATCH 05/12] decoupling the notification test factory from the vector module --- .../vector/app/di/NotificationTestModule.kt | 31 +++++++++++++++++++ ...ficationTroubleshootTestManagerFactory.kt} | 7 +++-- .../vector/app/di/NotificationTestModule.kt | 31 +++++++++++++++++++ ...ficationTroubleshootTestManagerFactory.kt} | 7 +++-- ...ificationTroubleshootTestManagerFactory.kt | 24 ++++++++++++++ ...ttingsNotificationsTroubleshootFragment.kt | 2 +- 6 files changed, 95 insertions(+), 7 deletions(-) create mode 100644 vector/src/fdroid/java/im/vector/app/di/NotificationTestModule.kt rename vector/src/fdroid/java/im/vector/app/push/fcm/{NotificationTroubleshootTestManagerFactory.kt => FdroidNotificationTroubleshootTestManagerFactory.kt} (93%) create mode 100644 vector/src/gplay/java/im/vector/app/di/NotificationTestModule.kt rename vector/src/gplay/java/im/vector/app/push/fcm/{NotificationTroubleshootTestManagerFactory.kt => GoogleNotificationTroubleshootTestManagerFactory.kt} (93%) create mode 100644 vector/src/main/java/im/vector/app/features/push/NotificationTroubleshootTestManagerFactory.kt diff --git a/vector/src/fdroid/java/im/vector/app/di/NotificationTestModule.kt b/vector/src/fdroid/java/im/vector/app/di/NotificationTestModule.kt new file mode 100644 index 00000000000..a1711261686 --- /dev/null +++ b/vector/src/fdroid/java/im/vector/app/di/NotificationTestModule.kt @@ -0,0 +1,31 @@ +/* + * 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.di + +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.android.components.ActivityComponent +import im.vector.app.features.push.NotificationTroubleshootTestManagerFactory +import im.vector.app.push.fcm.FdroidNotificationTroubleshootTestManagerFactory + +@InstallIn(ActivityComponent::class) +@Module +abstract class NotificationTestModule { + @Binds + abstract fun bindsNotificationTestFactory(factory: FdroidNotificationTroubleshootTestManagerFactory): NotificationTroubleshootTestManagerFactory +} diff --git a/vector/src/fdroid/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt b/vector/src/fdroid/java/im/vector/app/push/fcm/FdroidNotificationTroubleshootTestManagerFactory.kt similarity index 93% rename from vector/src/fdroid/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt rename to vector/src/fdroid/java/im/vector/app/push/fcm/FdroidNotificationTroubleshootTestManagerFactory.kt index 5873b4308ff..86843f0e6ff 100644 --- a/vector/src/fdroid/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt +++ b/vector/src/fdroid/java/im/vector/app/push/fcm/FdroidNotificationTroubleshootTestManagerFactory.kt @@ -21,6 +21,7 @@ import im.vector.app.fdroid.features.settings.troubleshoot.TestAutoStartBoot import im.vector.app.fdroid.features.settings.troubleshoot.TestBackgroundRestrictions import im.vector.app.fdroid.features.settings.troubleshoot.TestBatteryOptimization import im.vector.app.features.VectorFeatures +import im.vector.app.features.push.NotificationTroubleshootTestManagerFactory import im.vector.app.features.settings.troubleshoot.NotificationTroubleshootTestManager import im.vector.app.features.settings.troubleshoot.TestAccountSettings import im.vector.app.features.settings.troubleshoot.TestAvailableUnifiedPushDistributors @@ -35,7 +36,7 @@ import im.vector.app.features.settings.troubleshoot.TestUnifiedPushEndpoint import im.vector.app.features.settings.troubleshoot.TestUnifiedPushGateway import javax.inject.Inject -class NotificationTroubleshootTestManagerFactory @Inject constructor( +class FdroidNotificationTroubleshootTestManagerFactory @Inject constructor( private val unifiedPushHelper: UnifiedPushHelper, private val testSystemSettings: TestSystemSettings, private val testAccountSettings: TestAccountSettings, @@ -52,9 +53,9 @@ class NotificationTroubleshootTestManagerFactory @Inject constructor( private val testBatteryOptimization: TestBatteryOptimization, private val testNotification: TestNotification, private val vectorFeatures: VectorFeatures, -) { +): NotificationTroubleshootTestManagerFactory { - fun create(fragment: Fragment): NotificationTroubleshootTestManager { + override fun create(fragment: Fragment): NotificationTroubleshootTestManager { val mgr = NotificationTroubleshootTestManager(fragment) mgr.addTest(testSystemSettings) mgr.addTest(testAccountSettings) diff --git a/vector/src/gplay/java/im/vector/app/di/NotificationTestModule.kt b/vector/src/gplay/java/im/vector/app/di/NotificationTestModule.kt new file mode 100644 index 00000000000..f3dfbccfc17 --- /dev/null +++ b/vector/src/gplay/java/im/vector/app/di/NotificationTestModule.kt @@ -0,0 +1,31 @@ +/* + * 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.di + +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.android.components.ActivityComponent +import im.vector.app.features.push.NotificationTroubleshootTestManagerFactory +import im.vector.app.push.fcm.GoogleNotificationTroubleshootTestManagerFactory + +@InstallIn(ActivityComponent::class) +@Module +abstract class NotificationTestModule { + @Binds + abstract fun bindsNotificationTestFactory(factory: GoogleNotificationTroubleshootTestManagerFactory): NotificationTroubleshootTestManagerFactory +} diff --git a/vector/src/gplay/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt b/vector/src/gplay/java/im/vector/app/push/fcm/GoogleNotificationTroubleshootTestManagerFactory.kt similarity index 93% rename from vector/src/gplay/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt rename to vector/src/gplay/java/im/vector/app/push/fcm/GoogleNotificationTroubleshootTestManagerFactory.kt index b3425c778b9..154e127fb62 100644 --- a/vector/src/gplay/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt +++ b/vector/src/gplay/java/im/vector/app/push/fcm/GoogleNotificationTroubleshootTestManagerFactory.kt @@ -18,6 +18,7 @@ package im.vector.app.push.fcm import androidx.fragment.app.Fragment import im.vector.app.core.pushers.UnifiedPushHelper import im.vector.app.features.VectorFeatures +import im.vector.app.features.push.NotificationTroubleshootTestManagerFactory import im.vector.app.features.settings.troubleshoot.NotificationTroubleshootTestManager import im.vector.app.features.settings.troubleshoot.TestAccountSettings import im.vector.app.features.settings.troubleshoot.TestAvailableUnifiedPushDistributors @@ -35,7 +36,7 @@ import im.vector.app.gplay.features.settings.troubleshoot.TestPlayServices import im.vector.app.gplay.features.settings.troubleshoot.TestTokenRegistration import javax.inject.Inject -class NotificationTroubleshootTestManagerFactory @Inject constructor( +class GoogleNotificationTroubleshootTestManagerFactory @Inject constructor( private val unifiedPushHelper: UnifiedPushHelper, private val testSystemSettings: TestSystemSettings, private val testAccountSettings: TestAccountSettings, @@ -52,9 +53,9 @@ class NotificationTroubleshootTestManagerFactory @Inject constructor( private val testPushFromPushGateway: TestPushFromPushGateway, private val testNotification: TestNotification, private val vectorFeatures: VectorFeatures, -) { +) : NotificationTroubleshootTestManagerFactory { - fun create(fragment: Fragment): NotificationTroubleshootTestManager { + override fun create(fragment: Fragment): NotificationTroubleshootTestManager { val mgr = NotificationTroubleshootTestManager(fragment) mgr.addTest(testSystemSettings) mgr.addTest(testAccountSettings) diff --git a/vector/src/main/java/im/vector/app/features/push/NotificationTroubleshootTestManagerFactory.kt b/vector/src/main/java/im/vector/app/features/push/NotificationTroubleshootTestManagerFactory.kt new file mode 100644 index 00000000000..6a3ce04c1a3 --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/push/NotificationTroubleshootTestManagerFactory.kt @@ -0,0 +1,24 @@ +/* + * 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.features.push + +import androidx.fragment.app.Fragment +import im.vector.app.features.settings.troubleshoot.NotificationTroubleshootTestManager + +interface NotificationTroubleshootTestManagerFactory { + fun create(fragment: Fragment): NotificationTroubleshootTestManager +} diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationsTroubleshootFragment.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationsTroubleshootFragment.kt index 8a3407b4284..e75824195e2 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationsTroubleshootFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationsTroubleshootFragment.kt @@ -35,11 +35,11 @@ import im.vector.app.core.extensions.registerStartForActivityResult import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.databinding.FragmentSettingsNotificationsTroubleshootBinding import im.vector.app.features.notifications.NotificationActionIds +import im.vector.app.features.push.NotificationTroubleshootTestManagerFactory import im.vector.app.features.rageshake.BugReporter import im.vector.app.features.settings.VectorSettingsFragmentInteractionListener import im.vector.app.features.settings.troubleshoot.NotificationTroubleshootTestManager import im.vector.app.features.settings.troubleshoot.TroubleshootTest -import im.vector.app.push.fcm.NotificationTroubleshootTestManagerFactory import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.extensions.tryOrNull import javax.inject.Inject From 0c61595ace023f26d22aa85baf6a7fb8c3bdcd78 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Mon, 8 Aug 2022 18:05:04 +0100 Subject: [PATCH 06/12] decoupling the fcm helper from the vector module --- .../java/im/vector/app/di/FlavorModule.kt | 26 ++++++---- .../fcm/{FcmHelper.kt => FdroidFcmHelper.kt} | 17 ++++--- .../java/im/vector/app/di/FlavorModule.kt | 5 ++ .../troubleshoot/TestFirebaseToken.kt | 2 +- .../troubleshoot/TestTokenRegistration.kt | 2 +- .../fcm/{FcmHelper.kt => GoogleFcmHelper.kt} | 17 ++++--- .../java/im/vector/app/VectorApplication.kt | 2 +- .../im/vector/app/core/pushers/FcmHelper.kt | 50 +++++++++++++++++++ .../app/core/pushers/UnifiedPushHelper.kt | 1 - .../vector/app/features/home/HomeActivity.kt | 2 +- .../TestAvailableUnifiedPushDistributors.kt | 2 +- 11 files changed, 95 insertions(+), 31 deletions(-) rename vector/src/fdroid/java/im/vector/app/push/fcm/{FcmHelper.kt => FdroidFcmHelper.kt} (78%) rename vector/src/gplay/java/im/vector/app/push/fcm/{FcmHelper.kt => GoogleFcmHelper.kt} (87%) create mode 100644 vector/src/main/java/im/vector/app/core/pushers/FcmHelper.kt 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 fcad54c3d2f..5a7a527c3fa 100644 --- a/vector/src/fdroid/java/im/vector/app/di/FlavorModule.kt +++ b/vector/src/fdroid/java/im/vector/app/di/FlavorModule.kt @@ -17,28 +17,36 @@ package im.vector.app.di import android.content.Context +import dagger.Binds import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent +import im.vector.app.core.pushers.FcmHelper 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 +import im.vector.app.push.fcm.FdroidFcmHelper @InstallIn(SingletonComponent::class) @Module -object FlavorModule { +abstract class FlavorModule { - @Provides - fun provideGuardServiceStarter(preferences: VectorPreferences, appContext: Context): GuardServiceStarter { - return FDroidGuardServiceStarter(preferences, appContext) - } + companion object { + @Provides + fun provideGuardServiceStarter(preferences: VectorPreferences, appContext: Context): GuardServiceStarter { + return FDroidGuardServiceStarter(preferences, appContext) + } - @Provides - fun provideNightlyProxy() = object : NightlyProxy { - override fun onHomeResumed() { - // no op + @Provides + fun provideNightlyProxy() = object : NightlyProxy { + override fun onHomeResumed() { + // no op + } } } + + @Binds + abstract fun bindsFcmHelper(fcmHelper: FdroidFcmHelper): FcmHelper } diff --git a/vector/src/fdroid/java/im/vector/app/push/fcm/FcmHelper.kt b/vector/src/fdroid/java/im/vector/app/push/fcm/FdroidFcmHelper.kt similarity index 78% rename from vector/src/fdroid/java/im/vector/app/push/fcm/FcmHelper.kt rename to vector/src/fdroid/java/im/vector/app/push/fcm/FdroidFcmHelper.kt index 24ff00a3536..8d41ce1e00a 100755 --- a/vector/src/fdroid/java/im/vector/app/push/fcm/FcmHelper.kt +++ b/vector/src/fdroid/java/im/vector/app/push/fcm/FdroidFcmHelper.kt @@ -20,6 +20,7 @@ package im.vector.app.push.fcm import android.app.Activity import android.content.Context 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.fdroid.BackgroundSyncStarter 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. */ -class FcmHelper @Inject constructor( +class FdroidFcmHelper @Inject constructor( private val context: Context, private val backgroundSyncStarter: BackgroundSyncStarter, -) { +) : FcmHelper { - fun isFirebaseAvailable(): Boolean = false + override fun isFirebaseAvailable(): Boolean = false /** * Retrieves the FCM registration token. * * @return the FCM token or null if not received from FCM */ - fun getFcmToken(): String? { + override fun getFcmToken(): String? { return null } @@ -49,7 +50,7 @@ class FcmHelper @Inject constructor( * * @param token the token to store */ - fun storeFcmToken(token: String?) { + override fun storeFcmToken(token: String?) { // No op } @@ -58,17 +59,17 @@ class FcmHelper @Inject constructor( * * @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 } - fun onEnterForeground(activeSessionHolder: ActiveSessionHolder) { + override fun onEnterForeground(activeSessionHolder: ActiveSessionHolder) { // try to stop all regardless of background mode activeSessionHolder.getSafeActiveSession()?.syncService()?.stopAnyBackgroundSync() AlarmSyncBroadcastReceiver.cancelAlarm(context) } - fun onEnterBackground(activeSessionHolder: ActiveSessionHolder) { + override fun onEnterBackground(activeSessionHolder: ActiveSessionHolder) { backgroundSyncStarter.start(activeSessionHolder) } } 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 256c908a02b..442f5f2eed3 100644 --- a/vector/src/gplay/java/im/vector/app/di/FlavorModule.kt +++ b/vector/src/gplay/java/im/vector/app/di/FlavorModule.kt @@ -21,9 +21,11 @@ import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent +import im.vector.app.core.pushers.FcmHelper import im.vector.app.core.services.GuardServiceStarter import im.vector.app.features.home.NightlyProxy import im.vector.app.nightly.FirebaseNightlyProxy +import im.vector.app.push.fcm.GoogleFcmHelper @InstallIn(SingletonComponent::class) @Module @@ -38,4 +40,7 @@ abstract class FlavorModule { @Binds abstract fun bindsNightlyProxy(nightlyProxy: FirebaseNightlyProxy): NightlyProxy + + @Binds + abstract fun bindsFcmHelper(fcmHelper: GoogleFcmHelper): FcmHelper } diff --git a/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestFirebaseToken.kt b/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestFirebaseToken.kt index e7e3157f6b6..d6180a9fe8a 100644 --- a/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestFirebaseToken.kt +++ b/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestFirebaseToken.kt @@ -20,10 +20,10 @@ import androidx.activity.result.ActivityResultLauncher import androidx.fragment.app.FragmentActivity import com.google.firebase.messaging.FirebaseMessaging import im.vector.app.R +import im.vector.app.core.pushers.FcmHelper import im.vector.app.core.resources.StringProvider import im.vector.app.core.utils.startAddGoogleAccountIntent import im.vector.app.features.settings.troubleshoot.TroubleshootTest -import im.vector.app.push.fcm.FcmHelper import timber.log.Timber import javax.inject.Inject diff --git a/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestTokenRegistration.kt b/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestTokenRegistration.kt index 8c21404d20b..840bde77b1e 100644 --- a/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestTokenRegistration.kt +++ b/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestTokenRegistration.kt @@ -23,10 +23,10 @@ import androidx.work.WorkInfo import androidx.work.WorkManager import im.vector.app.R 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.resources.StringProvider 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 javax.inject.Inject diff --git a/vector/src/gplay/java/im/vector/app/push/fcm/FcmHelper.kt b/vector/src/gplay/java/im/vector/app/push/fcm/GoogleFcmHelper.kt similarity index 87% rename from vector/src/gplay/java/im/vector/app/push/fcm/FcmHelper.kt rename to vector/src/gplay/java/im/vector/app/push/fcm/GoogleFcmHelper.kt index a4eb9efc73f..636f4f3189f 100755 --- a/vector/src/gplay/java/im/vector/app/push/fcm/FcmHelper.kt +++ b/vector/src/gplay/java/im/vector/app/push/fcm/GoogleFcmHelper.kt @@ -25,6 +25,7 @@ import com.google.firebase.messaging.FirebaseMessaging import im.vector.app.R import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.di.DefaultSharedPreferences +import im.vector.app.core.pushers.FcmHelper import im.vector.app.core.pushers.PushersManager import timber.log.Timber 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. * It has an alter ego in the fdroid variant. */ -class FcmHelper @Inject constructor( +class GoogleFcmHelper @Inject constructor( context: Context, -) { +) : FcmHelper { companion object { private const val PREFS_KEY_FCM_TOKEN = "FCM_TOKEN" } private val sharedPrefs = DefaultSharedPreferences.getInstance(context) - fun isFirebaseAvailable(): Boolean = true + override fun isFirebaseAvailable(): Boolean = true /** * Retrieves the FCM registration token. * * @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) } @@ -59,7 +60,7 @@ class FcmHelper @Inject constructor( * * @param token the token to store */ - fun storeFcmToken(token: String?) { + override fun storeFcmToken(token: String?) { sharedPrefs.edit { putString(PREFS_KEY_FCM_TOKEN, token) } @@ -70,7 +71,7 @@ class FcmHelper @Inject constructor( * * @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))) { // 'app should always check the device for a compatible Google Play services APK before accessing Google Play services features' if (checkPlayServices(activity)) { @@ -106,12 +107,12 @@ class FcmHelper @Inject constructor( } @Suppress("UNUSED_PARAMETER") - fun onEnterForeground(activeSessionHolder: ActiveSessionHolder) { + override fun onEnterForeground(activeSessionHolder: ActiveSessionHolder) { // No op } @Suppress("UNUSED_PARAMETER") - fun onEnterBackground(activeSessionHolder: ActiveSessionHolder) { + override fun onEnterBackground(activeSessionHolder: ActiveSessionHolder) { // No op } } diff --git a/vector/src/main/java/im/vector/app/VectorApplication.kt b/vector/src/main/java/im/vector/app/VectorApplication.kt index f31b5d915e4..53222ab9620 100644 --- a/vector/src/main/java/im/vector/app/VectorApplication.kt +++ b/vector/src/main/java/im/vector/app/VectorApplication.kt @@ -43,6 +43,7 @@ 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.pushers.FcmHelper import im.vector.app.core.resources.BuildMeta import im.vector.app.features.analytics.VectorAnalytics 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.themes.ThemeUtils import im.vector.app.features.version.VersionProvider -import im.vector.app.push.fcm.FcmHelper import org.jitsi.meet.sdk.log.JitsiMeetDefaultLogHandler import org.matrix.android.sdk.api.Matrix import org.matrix.android.sdk.api.auth.AuthenticationService diff --git a/vector/src/main/java/im/vector/app/core/pushers/FcmHelper.kt b/vector/src/main/java/im/vector/app/core/pushers/FcmHelper.kt new file mode 100644 index 00000000000..601722a036a --- /dev/null +++ b/vector/src/main/java/im/vector/app/core/pushers/FcmHelper.kt @@ -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) +} diff --git a/vector/src/main/java/im/vector/app/core/pushers/UnifiedPushHelper.kt b/vector/src/main/java/im/vector/app/core/pushers/UnifiedPushHelper.kt index 724d3c7aa67..1f44ab36863 100644 --- a/vector/src/main/java/im/vector/app/core/pushers/UnifiedPushHelper.kt +++ b/vector/src/main/java/im/vector/app/core/pushers/UnifiedPushHelper.kt @@ -28,7 +28,6 @@ import im.vector.app.core.utils.getApplicationLabel import im.vector.app.features.VectorFeatures import im.vector.app.features.settings.BackgroundSyncMode import im.vector.app.features.settings.VectorPreferences -import im.vector.app.push.fcm.FcmHelper import kotlinx.coroutines.launch import org.matrix.android.sdk.api.Matrix import org.matrix.android.sdk.api.cache.CacheStrategy 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 4dd6f8cfba7..fe57b9f735c 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 @@ -44,6 +44,7 @@ import im.vector.app.core.extensions.replaceFragment import im.vector.app.core.extensions.validateBackPressed import im.vector.app.core.platform.VectorBaseActivity 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.UnifiedPushHelper 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.themes.ThemeUtils import im.vector.app.features.workers.signout.ServerBackupStatusViewModel -import im.vector.app.push.fcm.FcmHelper import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch diff --git a/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestAvailableUnifiedPushDistributors.kt b/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestAvailableUnifiedPushDistributors.kt index acc01429243..89e7d8c204b 100644 --- a/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestAvailableUnifiedPushDistributors.kt +++ b/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestAvailableUnifiedPushDistributors.kt @@ -19,9 +19,9 @@ package im.vector.app.features.settings.troubleshoot import android.content.Intent import androidx.activity.result.ActivityResultLauncher import im.vector.app.R +import im.vector.app.core.pushers.FcmHelper import im.vector.app.core.pushers.UnifiedPushHelper import im.vector.app.core.resources.StringProvider -import im.vector.app.push.fcm.FcmHelper import javax.inject.Inject class TestAvailableUnifiedPushDistributors @Inject constructor( From ed3b73a98990dbb6a80a147f90c5a157b0282ebe Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 9 Aug 2022 10:32:43 +0100 Subject: [PATCH 07/12] decouples the flavor code / OSS licenses activity launching --- .../fdroid/java/im/vector/app/di/FlavorModule.kt | 10 ++++++++++ .../app/{FlavorCode.kt => GoogleFlavorLegals.kt} | 14 ++++++++++++-- .../gplay/java/im/vector/app/di/FlavorModule.kt | 6 ++++++ .../app/features/settings/legals/FlavourLegals.kt} | 10 ++++++---- .../features/settings/legals/LegalsController.kt | 5 +++-- .../app/features/settings/legals/LegalsFragment.kt | 7 +++---- 6 files changed, 40 insertions(+), 12 deletions(-) rename vector/src/gplay/java/im/vector/app/{FlavorCode.kt => GoogleFlavorLegals.kt} (60%) rename vector/src/{fdroid/java/im/vector/app/FlavorCode.kt => main/java/im/vector/app/features/settings/legals/FlavourLegals.kt} (74%) 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 5a7a527c3fa..1936fbda8c3 100644 --- a/vector/src/fdroid/java/im/vector/app/di/FlavorModule.kt +++ b/vector/src/fdroid/java/im/vector/app/di/FlavorModule.kt @@ -27,6 +27,7 @@ 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 +import im.vector.app.features.settings.legals.FlavourLegals import im.vector.app.push.fcm.FdroidFcmHelper @InstallIn(SingletonComponent::class) @@ -45,6 +46,15 @@ abstract class FlavorModule { // no op } } + + @Provides + fun providesFlavorLegals() = object : FlavourLegals { + override fun hasThirdPartyNotices() = false + + override fun navigateToThirdPartyNotices(context: Context) { + // no op + } + } } @Binds diff --git a/vector/src/gplay/java/im/vector/app/FlavorCode.kt b/vector/src/gplay/java/im/vector/app/GoogleFlavorLegals.kt similarity index 60% rename from vector/src/gplay/java/im/vector/app/FlavorCode.kt rename to vector/src/gplay/java/im/vector/app/GoogleFlavorLegals.kt index 040296d755b..32849b37410 100644 --- a/vector/src/gplay/java/im/vector/app/FlavorCode.kt +++ b/vector/src/gplay/java/im/vector/app/GoogleFlavorLegals.kt @@ -1,5 +1,5 @@ /* - * Copyright 2020 New Vector Ltd + * 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. @@ -19,5 +19,15 @@ package im.vector.app import android.content.Context import android.content.Intent import com.google.android.gms.oss.licenses.OssLicensesMenuActivity +import im.vector.app.features.settings.legals.FlavourLegals +import javax.inject.Inject -fun openOssLicensesMenuActivity(context: Context) = context.startActivity(Intent(context, OssLicensesMenuActivity::class.java)) +class GoogleFlavorLegals @Inject constructor() : FlavourLegals { + + override fun hasThirdPartyNotices() = true + + override fun navigateToThirdPartyNotices(context: Context) { + // See https://developers.google.com/android/guides/opensource + context.startActivity(Intent(context, OssLicensesMenuActivity::class.java)) + } +} 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 442f5f2eed3..c97d1bff041 100644 --- a/vector/src/gplay/java/im/vector/app/di/FlavorModule.kt +++ b/vector/src/gplay/java/im/vector/app/di/FlavorModule.kt @@ -21,9 +21,11 @@ import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent +import im.vector.app.GoogleFlavorLegals import im.vector.app.core.pushers.FcmHelper import im.vector.app.core.services.GuardServiceStarter import im.vector.app.features.home.NightlyProxy +import im.vector.app.features.settings.legals.FlavourLegals import im.vector.app.nightly.FirebaseNightlyProxy import im.vector.app.push.fcm.GoogleFcmHelper @@ -43,4 +45,8 @@ abstract class FlavorModule { @Binds abstract fun bindsFcmHelper(fcmHelper: GoogleFcmHelper): FcmHelper + + @Binds + abstract fun bindsFlavorLegals(legals: GoogleFlavorLegals): FlavourLegals } + diff --git a/vector/src/fdroid/java/im/vector/app/FlavorCode.kt b/vector/src/main/java/im/vector/app/features/settings/legals/FlavourLegals.kt similarity index 74% rename from vector/src/fdroid/java/im/vector/app/FlavorCode.kt rename to vector/src/main/java/im/vector/app/features/settings/legals/FlavourLegals.kt index 7d8ef22b449..a33ad23f7e2 100644 --- a/vector/src/fdroid/java/im/vector/app/FlavorCode.kt +++ b/vector/src/main/java/im/vector/app/features/settings/legals/FlavourLegals.kt @@ -1,5 +1,5 @@ /* - * Copyright 2020 New Vector Ltd + * 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. @@ -14,9 +14,11 @@ * limitations under the License. */ -package im.vector.app +package im.vector.app.features.settings.legals import android.content.Context -// No op -fun openOssLicensesMenuActivity(@Suppress("UNUSED_PARAMETER") context: Context) = Unit +interface FlavourLegals { + fun hasThirdPartyNotices(): Boolean + fun navigateToThirdPartyNotices(context: Context) +} diff --git a/vector/src/main/java/im/vector/app/features/settings/legals/LegalsController.kt b/vector/src/main/java/im/vector/app/features/settings/legals/LegalsController.kt index f88b73f36c3..c64b2e51d3d 100644 --- a/vector/src/main/java/im/vector/app/features/settings/legals/LegalsController.kt +++ b/vector/src/main/java/im/vector/app/features/settings/legals/LegalsController.kt @@ -38,7 +38,8 @@ class LegalsController @Inject constructor( private val stringProvider: StringProvider, private val resources: Resources, private val elementLegals: ElementLegals, - private val errorFormatter: ErrorFormatter + private val errorFormatter: ErrorFormatter, + private val flavourLegals: FlavourLegals, ) : TypedEpoxyController() { var listener: Listener? = null @@ -134,7 +135,7 @@ class LegalsController @Inject constructor( clickListener { host.listener?.openThirdPartyNotice() } } // Only on Gplay - if (resources.getBoolean(R.bool.isGplay)) { + if (flavourLegals.hasThirdPartyNotices()) { discoveryPolicyItem { id("eltpn2") name(host.stringProvider.getString(R.string.settings_other_third_party_notices)) diff --git a/vector/src/main/java/im/vector/app/features/settings/legals/LegalsFragment.kt b/vector/src/main/java/im/vector/app/features/settings/legals/LegalsFragment.kt index 9a4090ad1b2..7bdcb9b5c96 100644 --- a/vector/src/main/java/im/vector/app/features/settings/legals/LegalsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/legals/LegalsFragment.kt @@ -33,11 +33,11 @@ import im.vector.app.databinding.FragmentGenericRecyclerBinding import im.vector.app.features.analytics.plan.MobileScreen import im.vector.app.features.discovery.ServerPolicy import im.vector.app.features.settings.VectorSettingsUrls -import im.vector.app.openOssLicensesMenuActivity import javax.inject.Inject class LegalsFragment @Inject constructor( - private val controller: LegalsController + private val controller: LegalsController, + private val flavourLegals: FlavourLegals, ) : VectorBaseFragment(), LegalsController.Listener { @@ -100,8 +100,7 @@ class LegalsFragment @Inject constructor( override fun openThirdPartyNoticeGplay() { if (firstThrottler.canHandle() is FirstThrottler.CanHandlerResult.Yes) { - // See https://developers.google.com/android/guides/opensource - openOssLicensesMenuActivity(requireActivity()) + flavourLegals.navigateToThirdPartyNotices(requireContext()) } } } From 045398d06feddff81be334cddf8c834a86383d68 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 9 Aug 2022 10:42:44 +0100 Subject: [PATCH 08/12] fixing import ordering and duplicated documentation --- .../app/features/debug/di/DebugModule.kt | 5 ++--- .../app/receivers/VectorDebugReceiver.kt | 2 +- .../im/vector/app/push/fcm/FdroidFcmHelper.kt | 15 --------------- ...ificationTroubleshootTestManagerFactory.kt | 2 +- .../java/im/vector/app/di/FlavorModule.kt | 1 - .../im/vector/app/push/fcm/GoogleFcmHelper.kt | 19 +------------------ .../im/vector/app/core/pushers/FcmHelper.kt | 13 +++++++------ .../features/navigation/DefaultNavigator.kt | 3 +-- 8 files changed, 13 insertions(+), 47 deletions(-) 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 56df9fa0bc5..b15f6dce62a 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 @@ -23,10 +23,10 @@ import dagger.Module import dagger.Provides import dagger.hilt.InstallIn 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.DebugReceiver import im.vector.app.core.debug.FlipperProxy +import im.vector.app.features.debug.DebugMenuActivity import im.vector.app.flipper.VectorFlipperProxy import im.vector.app.receivers.VectorDebugReceiver @@ -49,5 +49,4 @@ abstract class DebugModule { @Binds abstract fun bindsFlipperProxy(flipperProxy: VectorFlipperProxy): FlipperProxy - } diff --git a/vector/src/debug/java/im/vector/app/receivers/VectorDebugReceiver.kt b/vector/src/debug/java/im/vector/app/receivers/VectorDebugReceiver.kt index 827fc540f72..550dc055d9d 100644 --- a/vector/src/debug/java/im/vector/app/receivers/VectorDebugReceiver.kt +++ b/vector/src/debug/java/im/vector/app/receivers/VectorDebugReceiver.kt @@ -22,8 +22,8 @@ import android.content.Intent import android.content.IntentFilter import android.content.SharedPreferences import androidx.core.content.edit -import im.vector.app.core.di.DefaultSharedPreferences import im.vector.app.core.debug.DebugReceiver +import im.vector.app.core.di.DefaultSharedPreferences import im.vector.app.core.utils.lsFiles import timber.log.Timber import javax.inject.Inject diff --git a/vector/src/fdroid/java/im/vector/app/push/fcm/FdroidFcmHelper.kt b/vector/src/fdroid/java/im/vector/app/push/fcm/FdroidFcmHelper.kt index 8d41ce1e00a..5b83769116a 100755 --- a/vector/src/fdroid/java/im/vector/app/push/fcm/FdroidFcmHelper.kt +++ b/vector/src/fdroid/java/im/vector/app/push/fcm/FdroidFcmHelper.kt @@ -36,29 +36,14 @@ class FdroidFcmHelper @Inject constructor( override fun isFirebaseAvailable(): Boolean = false - /** - * Retrieves the FCM registration token. - * - * @return the FCM token or null if not received from FCM - */ override fun getFcmToken(): String? { return null } - /** - * Store FCM token to the SharedPrefs - * - * @param token the token to store - */ override fun storeFcmToken(token: String?) { // No op } - /** - * onNewToken may not be called on application upgrade, so ensure my shared pref is set - * - * @param activity the first launch Activity - */ override fun ensureFcmTokenIsRetrieved(activity: Activity, pushersManager: PushersManager, registerPusher: Boolean) { // No op } diff --git a/vector/src/fdroid/java/im/vector/app/push/fcm/FdroidNotificationTroubleshootTestManagerFactory.kt b/vector/src/fdroid/java/im/vector/app/push/fcm/FdroidNotificationTroubleshootTestManagerFactory.kt index 86843f0e6ff..d99afa59f7e 100644 --- a/vector/src/fdroid/java/im/vector/app/push/fcm/FdroidNotificationTroubleshootTestManagerFactory.kt +++ b/vector/src/fdroid/java/im/vector/app/push/fcm/FdroidNotificationTroubleshootTestManagerFactory.kt @@ -53,7 +53,7 @@ class FdroidNotificationTroubleshootTestManagerFactory @Inject constructor( private val testBatteryOptimization: TestBatteryOptimization, private val testNotification: TestNotification, private val vectorFeatures: VectorFeatures, -): NotificationTroubleshootTestManagerFactory { +) : NotificationTroubleshootTestManagerFactory { override fun create(fragment: Fragment): NotificationTroubleshootTestManager { val mgr = NotificationTroubleshootTestManager(fragment) 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 c97d1bff041..393ea1e62a6 100644 --- a/vector/src/gplay/java/im/vector/app/di/FlavorModule.kt +++ b/vector/src/gplay/java/im/vector/app/di/FlavorModule.kt @@ -49,4 +49,3 @@ abstract class FlavorModule { @Binds abstract fun bindsFlavorLegals(legals: GoogleFlavorLegals): FlavourLegals } - diff --git a/vector/src/gplay/java/im/vector/app/push/fcm/GoogleFcmHelper.kt b/vector/src/gplay/java/im/vector/app/push/fcm/GoogleFcmHelper.kt index 636f4f3189f..d64847c124f 100755 --- a/vector/src/gplay/java/im/vector/app/push/fcm/GoogleFcmHelper.kt +++ b/vector/src/gplay/java/im/vector/app/push/fcm/GoogleFcmHelper.kt @@ -45,32 +45,17 @@ class GoogleFcmHelper @Inject constructor( override fun isFirebaseAvailable(): Boolean = true - /** - * Retrieves the FCM registration token. - * - * @return the FCM token or null if not received from FCM - */ override fun getFcmToken(): String? { return sharedPrefs.getString(PREFS_KEY_FCM_TOKEN, null) } - /** - * Store FCM token to the SharedPrefs - * TODO Store in realm - * - * @param token the token to store - */ override fun storeFcmToken(token: String?) { + // TODO Store in realm sharedPrefs.edit { putString(PREFS_KEY_FCM_TOKEN, token) } } - /** - * onNewToken may not be called on application upgrade, so ensure my shared pref is set - * - * @param activity the first launch Activity - */ override fun ensureFcmTokenIsRetrieved(activity: Activity, pushersManager: PushersManager, registerPusher: Boolean) { // if (TextUtils.isEmpty(getFcmToken(activity))) { // 'app should always check the device for a compatible Google Play services APK before accessing Google Play services features' @@ -106,12 +91,10 @@ class GoogleFcmHelper @Inject constructor( return resultCode == ConnectionResult.SUCCESS } - @Suppress("UNUSED_PARAMETER") override fun onEnterForeground(activeSessionHolder: ActiveSessionHolder) { // No op } - @Suppress("UNUSED_PARAMETER") override fun onEnterBackground(activeSessionHolder: ActiveSessionHolder) { // No op } diff --git a/vector/src/main/java/im/vector/app/core/pushers/FcmHelper.kt b/vector/src/main/java/im/vector/app/core/pushers/FcmHelper.kt index 601722a036a..7b2c5e39595 100644 --- a/vector/src/main/java/im/vector/app/core/pushers/FcmHelper.kt +++ b/vector/src/main/java/im/vector/app/core/pushers/FcmHelper.kt @@ -25,22 +25,23 @@ interface FcmHelper { /** * 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? /** - * Store FCM token to the SharedPrefs - * TODO Store in realm + * Store FCM token to the SharedPrefs. * - * @param token the token to store + * @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 + * onNewToken may not be called on application upgrade, so ensure my shared pref is set. * - * @param activity the first launch Activity + * @param activity the first launch Activity. + * @param pushersManager the instance to register the pusher on. + * @param registerPusher whether the pusher should be registered. */ fun ensureFcmTokenIsRetrieved(activity: Activity, pushersManager: PushersManager, registerPusher: Boolean) diff --git a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt index 872f102a0d8..e724084501c 100644 --- a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt +++ b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt @@ -34,6 +34,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder import im.vector.app.R import im.vector.app.SpaceStateHandler import im.vector.app.config.OnboardingVariant +import im.vector.app.core.debug.DebugNavigator import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.error.fatalError import im.vector.app.features.VectorFeatures @@ -51,7 +52,6 @@ import im.vector.app.features.crypto.recover.BootstrapBottomSheet import im.vector.app.features.crypto.recover.SetupMode import im.vector.app.features.crypto.verification.SupportedVerificationMethodsProvider import im.vector.app.features.crypto.verification.VerificationBottomSheet -import im.vector.app.core.debug.DebugNavigator import im.vector.app.features.devtools.RoomDevToolActivity import im.vector.app.features.home.room.detail.RoomDetailActivity import im.vector.app.features.home.room.detail.arguments.TimelineArgs @@ -616,4 +616,3 @@ class DefaultNavigator @Inject constructor( context.startActivity(this) } } - From 319ec6fbf492fb47265170331445a98c20dc9b8d Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 9 Aug 2022 11:25:55 +0100 Subject: [PATCH 09/12] removing now unused gplay resource --- vector/build.gradle | 2 -- 1 file changed, 2 deletions(-) diff --git a/vector/build.gradle b/vector/build.gradle index 0edaf5424ee..1244a84bfda 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -307,7 +307,6 @@ android { isDefault = true versionName "${versionMajor}.${versionMinor}.${versionPatch}${getGplayVersionSuffix()}" - resValue "bool", "isGplay", "true" buildConfigField "String", "SHORT_FLAVOR_DESCRIPTION", "\"G\"" buildConfigField "String", "FLAVOR_DESCRIPTION", "\"GooglePlay\"" } @@ -317,7 +316,6 @@ android { versionName "${versionMajor}.${versionMinor}.${versionPatch}${getFdroidVersionSuffix()}" - resValue "bool", "isGplay", "false" buildConfigField "String", "SHORT_FLAVOR_DESCRIPTION", "\"F\"" buildConfigField "String", "FLAVOR_DESCRIPTION", "\"FDroid\"" } From d7949307a41f5cceacdb2e1e6f8190a15d9ae1cd Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Tue, 9 Aug 2022 14:01:00 +0100 Subject: [PATCH 10/12] adding changelog entry --- changelog.d/6783.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/6783.misc diff --git a/changelog.d/6783.misc b/changelog.d/6783.misc new file mode 100644 index 00000000000..d1095c1203a --- /dev/null +++ b/changelog.d/6783.misc @@ -0,0 +1 @@ +Decouples the variant logic from the vector module From 6526cf3c2ebf4101e2c761bbd83a3d56294ba882 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Wed, 10 Aug 2022 14:14:39 +0100 Subject: [PATCH 11/12] removing unused file, the release flipper proxy instance is provided by the debug module --- .../im/vector/app/flipper/FlipperProxy.kt | 31 ------------------- 1 file changed, 31 deletions(-) delete mode 100644 vector/src/release/java/im/vector/app/flipper/FlipperProxy.kt diff --git a/vector/src/release/java/im/vector/app/flipper/FlipperProxy.kt b/vector/src/release/java/im/vector/app/flipper/FlipperProxy.kt deleted file mode 100644 index 03b1977a45b..00000000000 --- a/vector/src/release/java/im/vector/app/flipper/FlipperProxy.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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.flipper - -import okhttp3.Interceptor -import org.matrix.android.sdk.api.Matrix -import javax.inject.Inject - -/** - * No op version. - */ -@Suppress("UNUSED_PARAMETER") -class FlipperProxy @Inject constructor() { - fun init(matrix: Matrix) {} - - fun getNetworkInterceptor(): Interceptor? = null -} From 439224e4dec4ec1314b5f15e315201a996961730 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Thu, 11 Aug 2022 09:32:36 +0100 Subject: [PATCH 12/12] using american english for consistency --- vector/src/fdroid/java/im/vector/app/di/FlavorModule.kt | 4 ++-- vector/src/gplay/java/im/vector/app/GoogleFlavorLegals.kt | 4 ++-- vector/src/gplay/java/im/vector/app/di/FlavorModule.kt | 4 ++-- .../settings/legals/{FlavourLegals.kt => FlavorLegals.kt} | 2 +- .../vector/app/features/settings/legals/LegalsController.kt | 4 ++-- .../im/vector/app/features/settings/legals/LegalsFragment.kt | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-) rename vector/src/main/java/im/vector/app/features/settings/legals/{FlavourLegals.kt => FlavorLegals.kt} (96%) 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 1936fbda8c3..5355aa3cd9c 100644 --- a/vector/src/fdroid/java/im/vector/app/di/FlavorModule.kt +++ b/vector/src/fdroid/java/im/vector/app/di/FlavorModule.kt @@ -27,7 +27,7 @@ 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 -import im.vector.app.features.settings.legals.FlavourLegals +import im.vector.app.features.settings.legals.FlavorLegals import im.vector.app.push.fcm.FdroidFcmHelper @InstallIn(SingletonComponent::class) @@ -48,7 +48,7 @@ abstract class FlavorModule { } @Provides - fun providesFlavorLegals() = object : FlavourLegals { + fun providesFlavorLegals() = object : FlavorLegals { override fun hasThirdPartyNotices() = false override fun navigateToThirdPartyNotices(context: Context) { diff --git a/vector/src/gplay/java/im/vector/app/GoogleFlavorLegals.kt b/vector/src/gplay/java/im/vector/app/GoogleFlavorLegals.kt index 32849b37410..b5f8c8c951b 100644 --- a/vector/src/gplay/java/im/vector/app/GoogleFlavorLegals.kt +++ b/vector/src/gplay/java/im/vector/app/GoogleFlavorLegals.kt @@ -19,10 +19,10 @@ package im.vector.app import android.content.Context import android.content.Intent import com.google.android.gms.oss.licenses.OssLicensesMenuActivity -import im.vector.app.features.settings.legals.FlavourLegals +import im.vector.app.features.settings.legals.FlavorLegals import javax.inject.Inject -class GoogleFlavorLegals @Inject constructor() : FlavourLegals { +class GoogleFlavorLegals @Inject constructor() : FlavorLegals { override fun hasThirdPartyNotices() = true 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 393ea1e62a6..2fe72313ea9 100644 --- a/vector/src/gplay/java/im/vector/app/di/FlavorModule.kt +++ b/vector/src/gplay/java/im/vector/app/di/FlavorModule.kt @@ -25,7 +25,7 @@ import im.vector.app.GoogleFlavorLegals import im.vector.app.core.pushers.FcmHelper import im.vector.app.core.services.GuardServiceStarter import im.vector.app.features.home.NightlyProxy -import im.vector.app.features.settings.legals.FlavourLegals +import im.vector.app.features.settings.legals.FlavorLegals import im.vector.app.nightly.FirebaseNightlyProxy import im.vector.app.push.fcm.GoogleFcmHelper @@ -47,5 +47,5 @@ abstract class FlavorModule { abstract fun bindsFcmHelper(fcmHelper: GoogleFcmHelper): FcmHelper @Binds - abstract fun bindsFlavorLegals(legals: GoogleFlavorLegals): FlavourLegals + abstract fun bindsFlavorLegals(legals: GoogleFlavorLegals): FlavorLegals } diff --git a/vector/src/main/java/im/vector/app/features/settings/legals/FlavourLegals.kt b/vector/src/main/java/im/vector/app/features/settings/legals/FlavorLegals.kt similarity index 96% rename from vector/src/main/java/im/vector/app/features/settings/legals/FlavourLegals.kt rename to vector/src/main/java/im/vector/app/features/settings/legals/FlavorLegals.kt index a33ad23f7e2..9b2a0817001 100644 --- a/vector/src/main/java/im/vector/app/features/settings/legals/FlavourLegals.kt +++ b/vector/src/main/java/im/vector/app/features/settings/legals/FlavorLegals.kt @@ -18,7 +18,7 @@ package im.vector.app.features.settings.legals import android.content.Context -interface FlavourLegals { +interface FlavorLegals { fun hasThirdPartyNotices(): Boolean fun navigateToThirdPartyNotices(context: Context) } diff --git a/vector/src/main/java/im/vector/app/features/settings/legals/LegalsController.kt b/vector/src/main/java/im/vector/app/features/settings/legals/LegalsController.kt index c64b2e51d3d..a1d01024daa 100644 --- a/vector/src/main/java/im/vector/app/features/settings/legals/LegalsController.kt +++ b/vector/src/main/java/im/vector/app/features/settings/legals/LegalsController.kt @@ -39,7 +39,7 @@ class LegalsController @Inject constructor( private val resources: Resources, private val elementLegals: ElementLegals, private val errorFormatter: ErrorFormatter, - private val flavourLegals: FlavourLegals, + private val flavorLegals: FlavorLegals, ) : TypedEpoxyController() { var listener: Listener? = null @@ -135,7 +135,7 @@ class LegalsController @Inject constructor( clickListener { host.listener?.openThirdPartyNotice() } } // Only on Gplay - if (flavourLegals.hasThirdPartyNotices()) { + if (flavorLegals.hasThirdPartyNotices()) { discoveryPolicyItem { id("eltpn2") name(host.stringProvider.getString(R.string.settings_other_third_party_notices)) diff --git a/vector/src/main/java/im/vector/app/features/settings/legals/LegalsFragment.kt b/vector/src/main/java/im/vector/app/features/settings/legals/LegalsFragment.kt index 7bdcb9b5c96..aef1c69baa1 100644 --- a/vector/src/main/java/im/vector/app/features/settings/legals/LegalsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/legals/LegalsFragment.kt @@ -37,7 +37,7 @@ import javax.inject.Inject class LegalsFragment @Inject constructor( private val controller: LegalsController, - private val flavourLegals: FlavourLegals, + private val flavorLegals: FlavorLegals, ) : VectorBaseFragment(), LegalsController.Listener { @@ -100,7 +100,7 @@ class LegalsFragment @Inject constructor( override fun openThirdPartyNoticeGplay() { if (firstThrottler.canHandle() is FirstThrottler.CanHandlerResult.Yes) { - flavourLegals.navigateToThirdPartyNotices(requireContext()) + flavorLegals.navigateToThirdPartyNotices(requireContext()) } } }