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

Avoiding direct BuildConfig usage #6517

Merged
merged 23 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
274b1a1
moving analytics config to the config module, it's now up to forks to…
ouchadam Jun 30, 2022
87a8c78
moving the voice message limit to the config module
ouchadam Jun 30, 2022
e795e9d
porting the onboarding variant selection to the config
ouchadam Jun 30, 2022
f14aabc
ports the key sharing strategy to the config
ouchadam Jun 30, 2022
012485b
lifting the live location sharing build flag to the config along with…
ouchadam Jun 30, 2022
56afac2
creating a location sharing config for holding the map tiler key
ouchadam Jun 30, 2022
b6d052e
lifting voip setting to a voip config
ouchadam Jun 30, 2022
cc4aae0
replacing DEBUG build config flag with injectable property
ouchadam Jul 1, 2022
9fe3fc6
extracting the config models to their own files
ouchadam Jul 1, 2022
811b2e8
accessing the notification action ids via a dedicated class which bui…
ouchadam Jul 1, 2022
d42c27b
lifting the low privacy build config to the config
ouchadam Jul 1, 2022
df02f50
moving git versioning to the buildMeta abstraction
ouchadam Jul 1, 2022
18943e3
removing unused buildconfig option
ouchadam Jul 1, 2022
cceac66
moving build flavor information to the build meta
ouchadam Jul 8, 2022
c07296c
adding changelog entry
ouchadam Jul 11, 2022
3d207f9
removing unused imports and fixing missing full stop on docs
ouchadam Jul 11, 2022
fe1019f
using Config strict mode flag directly within the Application as the …
ouchadam Jul 11, 2022
cb59d82
extracting the notification action ids to their own file
ouchadam Jul 11, 2022
8b9d1bb
making use of the existing sdk int provider instead of supplying it v…
ouchadam Jul 11, 2022
9b1def3
updating variable casing as they're no longer const val or file level
ouchadam Jul 11, 2022
3c1e183
using low privacy log from the vector module for code within vector, …
ouchadam Jul 29, 2022
d1a63cc
removing unused import
ouchadam Jul 29, 2022
2ee52f2
fixing import ordering
ouchadam Aug 2, 2022
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/6406.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Modularization] Provides abstraction to avoids direct usages of BuildConfig
48 changes: 48 additions & 0 deletions vector-config/src/main/java/im/vector/app/config/Analytics.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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.config

/**
* The types of analytics Element currently supports.
*/
sealed interface Analytics {

/**
* Disables the analytics integrations.
*/
object Disabled : Analytics

/**
* Analytics integration via PostHog.
*/
data class PostHog(
/**
* The PostHog instance url.
*/
val postHogHost: String,

/**
* The PostHog instance API key.
*/
val postHogApiKey: String,

/**
* A URL to more information about the analytics collection.
*/
val policyLink: String,
) : Analytics
}
53 changes: 53 additions & 0 deletions vector-config/src/main/java/im/vector/app/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,57 @@ object Config {
* - Changing the value from `true` to `false` will force the app to return to the background sync / Firebase Push.
*/
const val ALLOW_EXTERNAL_UNIFIED_PUSH_DISTRIBUTORS = true

const val ENABLE_LOCATION_SHARING = true
const val LOCATION_MAP_TILER_KEY = "fU3vlMsMn4Jb6dnEIFsx"

/**
* The maximum length of voice messages in milliseconds.
*/
const val VOICE_MESSAGE_LIMIT_MS = 120_000L

/**
* The strategy for sharing device keys.
*/
val KEY_SHARING_STRATEGY = KeySharingStrategy.WhenTyping

/**
* The onboarding flow.
*/
val ONBOARDING_VARIANT = OnboardingVariant.FTUE_AUTH

/**
* If set, MSC3086 asserted identity messages sent on VoIP calls will cause the call to appear in the room corresponding to the asserted identity.
* This *must* only be set in trusted environments.
*/
const val HANDLE_CALL_ASSERTED_IDENTITY_EVENTS = false

const val LOW_PRIVACY_LOG_ENABLE = false
const val ENABLE_STRICT_MODE_LOGS = false

/**
* The analytics configuration to use for the Debug build type.
* Can be disabled by providing Analytics.Disabled
*/
val DEBUG_ANALYTICS_CONFIG = Analytics.PostHog(
postHogHost = "https://posthog.element.dev",
postHogApiKey = "phc_VtA1L35nw3aeAtHIx1ayrGdzGkss7k1xINeXcoIQzXN",
policyLink = "https://element.io/cookie-policy",
)

/**
* The analytics configuration to use for the Release build type.
* Can be disabled by providing Analytics.Disabled
*/
val RELEASE_ANALYTICS_CONFIG = Analytics.PostHog(
postHogHost = "https://posthog.hss.element.io",
postHogApiKey = "phc_Jzsm6DTm6V2705zeU5dcNvQDlonOR68XvX2sh1sEOHO",
policyLink = "https://element.io/cookie-policy",
)

/**
* The analytics configuration to use for the Nightly build type.
* Can be disabled by providing Analytics.Disabled
*/
val NIGHTLY_ANALYTICS_CONFIG = RELEASE_ANALYTICS_CONFIG
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 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.
Expand All @@ -16,12 +16,20 @@

package im.vector.app.config

import im.vector.app.BuildConfig
import im.vector.app.features.analytics.AnalyticsConfig
enum class KeySharingStrategy {
/**
* Keys will be sent for the first time when the first message is sent.
* This is handled by the Matrix SDK so there's no need to do it in Vector.
*/
WhenSendingEvent,

val analyticsConfig: AnalyticsConfig = object : AnalyticsConfig {
override val isEnabled = BuildConfig.APPLICATION_ID == "im.vector.app.debug"
override val postHogHost = "https://posthog.element.dev"
override val postHogApiKey = "phc_VtA1L35nw3aeAtHIx1ayrGdzGkss7k1xINeXcoIQzXN"
override val policyLink = "https://element.io/cookie-policy"
/**
* Keys will be sent for the first time when the timeline displayed.
*/
WhenEnteringRoom,

/**
* Keys will be sent for the first time when a typing started.
*/
WhenTyping
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 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.
Expand All @@ -16,17 +16,8 @@

package im.vector.app.config

import im.vector.app.BuildConfig
import im.vector.app.features.analytics.AnalyticsConfig

private val allowedPackageList = listOf(
"im.vector.app",
"im.vector.app.nightly",
)

val analyticsConfig: AnalyticsConfig = object : AnalyticsConfig {
override val isEnabled = BuildConfig.APPLICATION_ID in allowedPackageList
override val postHogHost = "https://posthog.hss.element.io"
override val postHogApiKey = "phc_Jzsm6DTm6V2705zeU5dcNvQDlonOR68XvX2sh1sEOHO"
override val policyLink = "https://element.io/cookie-policy"
enum class OnboardingVariant {
LEGACY,
LOGIN_2,
FTUE_AUTH
}
23 changes: 0 additions & 23 deletions vector/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,6 @@ android {
buildConfigField "String", "GIT_BRANCH_NAME", "\"${gitBranchName()}\""
buildConfigField "String", "BUILD_NUMBER", "\"${buildNumber}\""

buildConfigField "im.vector.app.features.VectorFeatures.OnboardingVariant", "ONBOARDING_VARIANT", "im.vector.app.features.VectorFeatures.OnboardingVariant.FTUE_AUTH"

buildConfigField "im.vector.app.features.crypto.keysrequest.OutboundSessionKeySharingStrategy", "outboundSessionKeySharingStrategy", "im.vector.app.features.crypto.keysrequest.OutboundSessionKeySharingStrategy.WhenTyping"

buildConfigField "Long", "VOICE_MESSAGE_DURATION_LIMIT_MS", "120_000L"

// If set, MSC3086 asserted identity messages sent on VoIP calls will cause the call to appear in the room corresponding to the asserted identity.
// This *must* only be set in trusted environments.
buildConfigField "Boolean", "handleCallAssertedIdentityEvents", "false"

buildConfigField "Boolean", "enableLocationSharing", "true"
buildConfigField "String", "mapTilerKey", "\"fU3vlMsMn4Jb6dnEIFsx\""

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

// Keep abiFilter for the universalApk
Expand Down Expand Up @@ -250,10 +237,6 @@ android {
resValue "string", "app_name", "Element dbg"
resValue "color", "launcher_background", "#0DBD8B"

buildConfigField "boolean", "LOW_PRIVACY_LOG_ENABLE", "false"
// Set to true if you want to enable strict mode in debug
buildConfigField "boolean", "ENABLE_STRICT_MODE_LOGS", "false"

signingConfig signingConfigs.debug

if (project.hasProperty("coverage")) {
Expand All @@ -265,10 +248,6 @@ android {
resValue "string", "app_name", "Element"
resValue "color", "launcher_background", "#0DBD8B"

buildConfigField "boolean", "LOW_PRIVACY_LOG_ENABLE", "false"
buildConfigField "boolean", "ENABLE_STRICT_MODE_LOGS", "false"

// When updating this block, please also update the same block in the `nightly` buildType below
postprocessing {
removeUnusedCode true
removeUnusedResources true
Expand Down Expand Up @@ -329,7 +308,6 @@ android {
versionName "${versionMajor}.${versionMinor}.${versionPatch}${getGplayVersionSuffix()}"

resValue "bool", "isGplay", "true"
buildConfigField "boolean", "ALLOW_FCM_USE", "true"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ALLOW_FCM_USE is not used

buildConfigField "String", "SHORT_FLAVOR_DESCRIPTION", "\"G\""
buildConfigField "String", "FLAVOR_DESCRIPTION", "\"GooglePlay\""
}
Expand All @@ -340,7 +318,6 @@ android {
versionName "${versionMajor}.${versionMinor}.${versionPatch}${getFdroidVersionSuffix()}"

resValue "bool", "isGplay", "false"
buildConfigField "boolean", "ALLOW_FCM_USE", "false"
buildConfigField "String", "SHORT_FLAVOR_DESCRIPTION", "\"F\""
buildConfigField "String", "FLAVOR_DESCRIPTION", "\"FDroid\""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ class DebugFeaturesStateFactory @Inject constructor(
key = DebugFeatureKeys.allowExternalUnifiedPushDistributors,
factory = VectorFeatures::allowExternalUnifiedPushDistributors
),
createBooleanFeature(
label = "Enable Live Location Sharing",
key = DebugFeatureKeys.liveLocationSharing,
factory = VectorFeatures::isLocationSharingEnabled
),
createBooleanFeature(
label = "Force usage of OpusEncoder library",
key = DebugFeatureKeys.forceUsageOfOpusEncoder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import im.vector.app.config.OnboardingVariant
import im.vector.app.features.DefaultVectorFeatures
import im.vector.app.features.VectorFeatures
import kotlinx.coroutines.flow.first
Expand All @@ -39,8 +40,8 @@ class DebugVectorFeatures(

private val dataStore = context.dataStore

override fun onboardingVariant(): VectorFeatures.OnboardingVariant {
return readPreferences().getEnum<VectorFeatures.OnboardingVariant>() ?: vectorFeatures.onboardingVariant()
override fun onboardingVariant(): OnboardingVariant {
return readPreferences().getEnum<OnboardingVariant>() ?: vectorFeatures.onboardingVariant()
}

override fun isOnboardingAlreadyHaveAccountSplashEnabled(): Boolean = read(DebugFeatureKeys.onboardingAlreadyHaveAnAccount)
Expand All @@ -66,6 +67,9 @@ class DebugVectorFeatures(
override fun isScreenSharingEnabled(): Boolean = read(DebugFeatureKeys.screenSharing)
?: vectorFeatures.isScreenSharingEnabled()

override fun isLocationSharingEnabled(): Boolean = read(DebugFeatureKeys.liveLocationSharing)
?: vectorFeatures.isLocationSharingEnabled()

override fun forceUsageOfOpusEncoder(): Boolean = read(DebugFeatureKeys.forceUsageOfOpusEncoder)
?: vectorFeatures.forceUsageOfOpusEncoder()

Expand Down
11 changes: 7 additions & 4 deletions vector/src/main/java/im/vector/app/VectorApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ import com.mapbox.mapboxsdk.Mapbox
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.di.ActiveSessionHolder
import im.vector.app.core.resources.BuildMeta
import im.vector.app.features.analytics.VectorAnalytics
import im.vector.app.features.call.webrtc.WebRtcCallManager
import im.vector.app.features.configuration.VectorConfiguration
Expand Down Expand Up @@ -99,6 +101,7 @@ class VectorApplication :
@Inject lateinit var flipperProxy: FlipperProxy
@Inject lateinit var matrix: Matrix
@Inject lateinit var fcmHelper: FcmHelper
@Inject lateinit var buildMeta: BuildMeta

// font thread handler
private var fontThreadHandler: Handler? = null
Expand Down Expand Up @@ -127,12 +130,12 @@ class VectorApplication :
.filterIsInstance(JitsiMeetDefaultLogHandler::class.java)
.forEach { Timber.uproot(it) }

if (BuildConfig.DEBUG) {
if (buildMeta.isDebug) {
Timber.plant(Timber.DebugTree())
}
Timber.plant(vectorFileLogger)

if (BuildConfig.DEBUG) {
if (buildMeta.isDebug) {
Stetho.initializeWithDefaults(this)
}
logInfo()
Expand All @@ -148,7 +151,7 @@ class VectorApplication :
R.array.com_google_android_gms_fonts_certs
)
FontsContractCompat.requestFont(this, fontRequest, emojiCompatFontProvider, getFontThreadHandler())
VectorLocale.init(this)
VectorLocale.init(this, buildMeta)
ThemeUtils.init(this)
vectorConfiguration.applyToApplicationContext()

Expand Down Expand Up @@ -196,7 +199,7 @@ class VectorApplication :
}

private fun enableStrictModeIfNeeded() {
if (BuildConfig.ENABLE_STRICT_MODE_LOGS) {
if (Config.ENABLE_STRICT_MODE_LOGS) {
StrictMode.setThreadPolicy(
StrictMode.ThreadPolicy.Builder()
.detectAll()
Expand Down
Loading