From d42c27bfe0a13699e9b8ea6de107dff1c322ff1c Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 1 Jul 2022 15:00:39 +0100 Subject: [PATCH] lifting the low privacy build config to the config --- .../src/main/java/im/vector/app/config/Config.kt | 2 ++ vector/build.gradle | 2 -- .../main/java/im/vector/app/core/di/SingletonModule.kt | 4 +--- .../vector/app/core/pushers/VectorMessagingReceiver.kt | 6 ++++-- .../java/im/vector/app/core/resources/BuildMeta.kt | 1 + .../im/vector/app/features/location/LocationTracker.kt | 10 ++++++---- .../features/notifications/NotifiableEventResolver.kt | 4 +++- .../notifications/NotificationDrawerManager.kt | 6 ++++-- .../app/features/location/LocationTrackerTest.kt | 3 ++- .../im/vector/app/test/fixtures/BuildMetaFixture.kt | 7 ++++++- 10 files changed, 29 insertions(+), 16 deletions(-) diff --git a/vector-config/src/main/java/im/vector/app/config/Config.kt b/vector-config/src/main/java/im/vector/app/config/Config.kt index ef9b6a7b8d..61b371939b 100644 --- a/vector-config/src/main/java/im/vector/app/config/Config.kt +++ b/vector-config/src/main/java/im/vector/app/config/Config.kt @@ -61,6 +61,8 @@ object Config { */ const val HANDLE_CALL_ASSERTED_IDENTITY_EVENTS = false + const val LOW_PRIVACY_LOG_ENABLE = false + /** * The analytics configuration to use for the Debug build type. * Can be disabled by providing Analytics.Disabled diff --git a/vector/build.gradle b/vector/build.gradle index 0aaf46a6b2..4b1942069c 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -237,7 +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" @@ -252,7 +251,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 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 0b7e3b347d..2807fd9c5c 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 @@ -32,7 +32,6 @@ import dagger.hilt.components.SingletonComponent import im.vector.app.BuildConfig import im.vector.app.EmojiCompatWrapper import im.vector.app.EmojiSpanify -import im.vector.app.config.Analytics import im.vector.app.config.Config import im.vector.app.SpaceStateHandler import im.vector.app.SpaceStateHandlerImpl @@ -44,11 +43,9 @@ import im.vector.app.core.time.Clock import im.vector.app.core.time.DefaultClock import im.vector.app.core.utils.AndroidSystemSettingsProvider import im.vector.app.core.utils.SystemSettingsProvider -import im.vector.app.features.analytics.AnalyticsConfig import im.vector.app.features.analytics.AnalyticsTracker import im.vector.app.features.analytics.VectorAnalytics import im.vector.app.features.analytics.impl.DefaultVectorAnalytics -import im.vector.app.features.home.room.detail.composer.voice.VoiceMessageConfig import im.vector.app.features.invite.AutoAcceptInvites import im.vector.app.features.invite.CompileTimeAutoAcceptInvites import im.vector.app.features.navigation.DefaultNavigator @@ -217,6 +214,7 @@ object VectorStaticModule { isDebug = BuildConfig.DEBUG, sdkInt = Build.VERSION.SDK_INT, applicationId = BuildConfig.APPLICATION_ID, + lowPrivacyLoggingEnabled = Config.LOW_PRIVACY_LOG_ENABLE, ) @Provides diff --git a/vector/src/main/java/im/vector/app/core/pushers/VectorMessagingReceiver.kt b/vector/src/main/java/im/vector/app/core/pushers/VectorMessagingReceiver.kt index 9764347ec1..6df08b89f4 100644 --- a/vector/src/main/java/im/vector/app/core/pushers/VectorMessagingReceiver.kt +++ b/vector/src/main/java/im/vector/app/core/pushers/VectorMessagingReceiver.kt @@ -29,6 +29,7 @@ import im.vector.app.BuildConfig import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.network.WifiDetector import im.vector.app.core.pushers.model.PushData +import im.vector.app.core.resources.BuildMeta import im.vector.app.core.services.GuardServiceStarter import im.vector.app.features.notifications.NotifiableEventResolver import im.vector.app.features.notifications.NotificationActionIds @@ -70,6 +71,7 @@ class VectorMessagingReceiver : MessagingReceiver() { @Inject lateinit var unifiedPushStore: UnifiedPushStore @Inject lateinit var pushParser: PushParser @Inject lateinit var actionIds: NotificationActionIds + @Inject lateinit var buildMeta: BuildMeta private val coroutineScope = CoroutineScope(SupervisorJob()) @@ -89,7 +91,7 @@ class VectorMessagingReceiver : MessagingReceiver() { Timber.tag(loggerTag.value).d("## onMessage() received") val sMessage = String(message) - if (BuildConfig.LOW_PRIVACY_LOG_ENABLE) { + if (buildMeta.lowPrivacyLoggingEnabled) { Timber.tag(loggerTag.value).d("## onMessage() $sMessage") } @@ -173,7 +175,7 @@ class VectorMessagingReceiver : MessagingReceiver() { */ private suspend fun onMessageReceivedInternal(pushData: PushData) { try { - if (BuildConfig.LOW_PRIVACY_LOG_ENABLE) { + if (buildMeta.lowPrivacyLoggingEnabled) { Timber.tag(loggerTag.value).d("## onMessageReceivedInternal() : $pushData") } else { Timber.tag(loggerTag.value).d("## onMessageReceivedInternal()") diff --git a/vector/src/main/java/im/vector/app/core/resources/BuildMeta.kt b/vector/src/main/java/im/vector/app/core/resources/BuildMeta.kt index beed091b58..8571eae9f2 100644 --- a/vector/src/main/java/im/vector/app/core/resources/BuildMeta.kt +++ b/vector/src/main/java/im/vector/app/core/resources/BuildMeta.kt @@ -20,4 +20,5 @@ data class BuildMeta( val isDebug: Boolean, val sdkInt: Int, val applicationId: String, + val lowPrivacyLoggingEnabled: Boolean, ) diff --git a/vector/src/main/java/im/vector/app/features/location/LocationTracker.kt b/vector/src/main/java/im/vector/app/features/location/LocationTracker.kt index aa05fe764b..0103fe3a94 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationTracker.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationTracker.kt @@ -26,6 +26,7 @@ import androidx.core.content.getSystemService import androidx.core.location.LocationListenerCompat import im.vector.app.BuildConfig import im.vector.app.core.di.ActiveSessionHolder +import im.vector.app.core.resources.BuildMeta import im.vector.app.features.session.coroutineScope import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.asSharedFlow @@ -40,7 +41,8 @@ import javax.inject.Singleton @Singleton class LocationTracker @Inject constructor( context: Context, - private val activeSessionHolder: ActiveSessionHolder + private val activeSessionHolder: ActiveSessionHolder, + private val buildMeta: BuildMeta, ) : LocationListenerCompat { private val locationManager = context.getSystemService() @@ -104,7 +106,7 @@ class LocationTracker @Inject constructor( } .maxByOrNull { location -> location.time } ?.let { latestKnownLocation -> - if (BuildConfig.LOW_PRIVACY_LOG_ENABLE) { + if (buildMeta.lowPrivacyLoggingEnabled) { Timber.d("lastKnownLocation: $latestKnownLocation") } else { Timber.d("lastKnownLocation: ${latestKnownLocation.provider}") @@ -162,7 +164,7 @@ class LocationTracker @Inject constructor( } override fun onLocationChanged(location: Location) { - if (BuildConfig.LOW_PRIVACY_LOG_ENABLE) { + if (buildMeta.lowPrivacyLoggingEnabled) { Timber.d("onLocationChanged: $location") } else { Timber.d("onLocationChanged: ${location.provider}") @@ -196,7 +198,7 @@ class LocationTracker @Inject constructor( private fun notifyLocation(location: Location) { activeSessionHolder.getSafeActiveSession()?.coroutineScope?.launch { - if (BuildConfig.LOW_PRIVACY_LOG_ENABLE) { + if (buildMeta.lowPrivacyLoggingEnabled) { Timber.d("notify location: $location") } else { Timber.d("notify location: ${location.provider}") diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventResolver.kt b/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventResolver.kt index 1ca72b8399..77cb749513 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventResolver.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotifiableEventResolver.kt @@ -19,6 +19,7 @@ import android.net.Uri import im.vector.app.BuildConfig import im.vector.app.R import im.vector.app.core.extensions.takeAs +import im.vector.app.core.resources.BuildMeta import im.vector.app.core.resources.StringProvider import im.vector.app.core.time.Clock import im.vector.app.features.displayname.getBestName @@ -62,6 +63,7 @@ class NotifiableEventResolver @Inject constructor( private val noticeEventFormatter: NoticeEventFormatter, private val displayableEventFormatter: DisplayableEventFormatter, private val clock: Clock, + private val buildMeta: BuildMeta, ) { // private val eventDisplay = RiotEventDisplay(context) @@ -264,7 +266,7 @@ class NotifiableEventResolver @Inject constructor( ) } else { Timber.e("## unsupported notifiable event for eventId [${event.eventId}]") - if (BuildConfig.LOW_PRIVACY_LOG_ENABLE) { + if (buildMeta.lowPrivacyLoggingEnabled) { Timber.e("## unsupported notifiable event for event [$event]") } // TODO generic handling? diff --git a/vector/src/main/java/im/vector/app/features/notifications/NotificationDrawerManager.kt b/vector/src/main/java/im/vector/app/features/notifications/NotificationDrawerManager.kt index 686ed324dc..8bf427c031 100644 --- a/vector/src/main/java/im/vector/app/features/notifications/NotificationDrawerManager.kt +++ b/vector/src/main/java/im/vector/app/features/notifications/NotificationDrawerManager.kt @@ -22,6 +22,7 @@ import androidx.annotation.WorkerThread import im.vector.app.ActiveSessionDataSource import im.vector.app.BuildConfig import im.vector.app.R +import im.vector.app.core.resources.BuildMeta import im.vector.app.core.utils.FirstThrottler import im.vector.app.features.displayname.getBestName import im.vector.app.features.settings.VectorPreferences @@ -46,7 +47,8 @@ class NotificationDrawerManager @Inject constructor( private val activeSessionDataSource: ActiveSessionDataSource, private val notifiableEventProcessor: NotifiableEventProcessor, private val notificationRenderer: NotificationRenderer, - private val notificationEventPersistence: NotificationEventPersistence + private val notificationEventPersistence: NotificationEventPersistence, + private val buildMeta: BuildMeta, ) { private val handlerThread: HandlerThread = HandlerThread("NotificationDrawerManager", Thread.MIN_PRIORITY) @@ -92,7 +94,7 @@ class NotificationDrawerManager @Inject constructor( } // If we support multi session, event list should be per userId // Currently only manage single session - if (BuildConfig.LOW_PRIVACY_LOG_ENABLE) { + if (buildMeta.lowPrivacyLoggingEnabled) { Timber.d("onNotifiableEventReceived(): $notifiableEvent") } else { Timber.d("onNotifiableEventReceived(): is push: ${notifiableEvent.canBeReplaced}") diff --git a/vector/src/test/java/im/vector/app/features/location/LocationTrackerTest.kt b/vector/src/test/java/im/vector/app/features/location/LocationTrackerTest.kt index 454a73cd70..54f7412238 100644 --- a/vector/src/test/java/im/vector/app/features/location/LocationTrackerTest.kt +++ b/vector/src/test/java/im/vector/app/features/location/LocationTrackerTest.kt @@ -23,6 +23,7 @@ import im.vector.app.features.session.coroutineScope import im.vector.app.test.fakes.FakeActiveSessionHolder import im.vector.app.test.fakes.FakeContext import im.vector.app.test.fakes.FakeLocationManager +import im.vector.app.test.fixtures.aBuildMeta import im.vector.app.test.test import io.mockk.every import io.mockk.just @@ -56,7 +57,7 @@ class LocationTrackerTest { @Before fun setUp() { mockkStatic("im.vector.app.features.session.SessionCoroutineScopesKt") - locationTracker = LocationTracker(fakeContext.instance, fakeActiveSessionHolder.instance) + locationTracker = LocationTracker(fakeContext.instance, fakeActiveSessionHolder.instance, aBuildMeta()) fakeLocationManager.givenRemoveUpdates(locationTracker) } diff --git a/vector/src/test/java/im/vector/app/test/fixtures/BuildMetaFixture.kt b/vector/src/test/java/im/vector/app/test/fixtures/BuildMetaFixture.kt index b0e6b1dd51..347b49400e 100644 --- a/vector/src/test/java/im/vector/app/test/fixtures/BuildMetaFixture.kt +++ b/vector/src/test/java/im/vector/app/test/fixtures/BuildMetaFixture.kt @@ -19,4 +19,9 @@ package im.vector.app.test.fixtures import android.os.Build import im.vector.app.core.resources.BuildMeta -fun aBuildMeta() = BuildMeta(Build.VERSION_CODES.O) +fun aBuildMeta() = BuildMeta( + isDebug = false, + sdkInt = Build.VERSION_CODES.O, + applicationId = "im.vector", + lowPrivacyLoggingEnabled = false, +)