Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple :vector variants/build types #6783

Merged
merged 12 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/6783.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Decouples the variant logic from the vector module
2 changes: 0 additions & 2 deletions vector/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
}
Expand All @@ -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\""
}
Expand Down
1 change: 1 addition & 0 deletions vector/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<activity android:name=".features.debug.settings.DebugPrivateSettingsActivity" />
<activity android:name=".features.debug.sas.DebugSasEmojiActivity" />
<activity android:name=".features.debug.features.DebugFeaturesSettingsActivity" />
<activity android:name=".features.debug.DebugMenuActivity" />

<activity
android:name="com.facebook.flipper.android.diagnostics.FlipperDiagnosticActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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 android.content.Context
import android.content.Intent
import dagger.Binds
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 im.vector.app.features.debug.DebugMenuActivity
import im.vector.app.flipper.VectorFlipperProxy
import im.vector.app.receivers.VectorDebugReceiver

@InstallIn(SingletonComponent::class)
@Module
abstract class DebugModule {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of relying on file overrides with the variants we can provide variant unique modules to the dagger graph and provide different implementations

the variant logic could also be extracted to their own modules in the future if wanted


companion object {

@Provides
fun providesDebugNavigator() = object : DebugNavigator {
override fun openDebugMenu(context: Context) {
context.startActivity(Intent(context, DebugMenuActivity::class.java))
}
}
}

@Binds
abstract fun bindsDebugReceiver(receiver: VectorDebugReceiver): DebugReceiver

@Binds
abstract fun bindsFlipperProxy(flipperProxy: VectorFlipperProxy): FlipperProxy
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -65,8 +65,5 @@ class FlipperProxy @Inject constructor(
}
}

@Suppress("RedundantNullableReturnType")
fun getNetworkInterceptor(): Interceptor? {
return FlipperOkhttpInterceptor(networkFlipperPlugin)
}
override fun networkInterceptor() = FlipperOkhttpInterceptor(networkFlipperPlugin)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,24 @@ import android.content.Intent
import android.content.IntentFilter
import android.content.SharedPreferences
import androidx.core.content.edit
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

/**
* 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}")
Expand Down
34 changes: 30 additions & 4 deletions vector/src/fdroid/java/im/vector/app/di/FlavorModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,46 @@
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.features.settings.legals.FlavourLegals
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it is a detail but could we rename the provide methods using the prefix provides all the time to keep consistency in all modules?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good to me!

return FDroidGuardServiceStarter(preferences, appContext)
}

@Provides
fun provideNightlyProxy() = object : NightlyProxy {
override fun onHomeResumed() {
// no op
}
}

@Provides
fun providesFlavorLegals() = object : FlavourLegals {
override fun hasThirdPartyNotices() = false

override fun navigateToThirdPartyNotices(context: Context) {
// no op
}
}
}

@Binds
abstract fun bindsFcmHelper(fcmHelper: FdroidFcmHelper): FcmHelper
}
31 changes: 31 additions & 0 deletions vector/src/fdroid/java/im/vector/app/di/NotificationTestModule.kt
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,47 +29,32 @@ 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
}

/**
* Store FCM token to the SharedPrefs
*
* @param token the token to store
*/
fun storeFcmToken(token: String?) {
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
*/
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)
Expand Down
33 changes: 33 additions & 0 deletions vector/src/gplay/java/im/vector/app/GoogleFlavorLegals.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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

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

class GoogleFlavorLegals @Inject constructor() : FlavourLegals {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we rename FlavourLegals to FlavorLegals to be consistent in naming?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


override fun hasThirdPartyNotices() = true

override fun navigateToThirdPartyNotices(context: Context) {
// See https://developers.google.com/android/guides/opensource
context.startActivity(Intent(context, OssLicensesMenuActivity::class.java))
}
}
26 changes: 22 additions & 4 deletions vector/src/gplay/java/im/vector/app/di/FlavorModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,36 @@

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.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

@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

@Binds
abstract fun bindsFcmHelper(fcmHelper: GoogleFcmHelper): FcmHelper

@Binds
abstract fun bindsFlavorLegals(legals: GoogleFlavorLegals): FlavourLegals
}
Loading