diff --git a/app/src/main/kotlin/io/element/android/x/di/AppModule.kt b/app/src/main/kotlin/io/element/android/x/di/AppModule.kt index d12d139a73..729603c4d7 100644 --- a/app/src/main/kotlin/io/element/android/x/di/AppModule.kt +++ b/app/src/main/kotlin/io/element/android/x/di/AppModule.kt @@ -25,6 +25,7 @@ import dagger.Module import dagger.Provides import io.element.android.libraries.core.coroutine.CoroutineDispatchers import io.element.android.libraries.core.meta.BuildMeta +import io.element.android.libraries.core.meta.BuildType import io.element.android.libraries.designsystem.utils.SnackbarDispatcher import io.element.android.libraries.di.AppScope import io.element.android.libraries.di.ApplicationContext @@ -38,7 +39,6 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.MainScope import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.plus -import okhttp3.logging.HttpLoggingInterceptor import java.io.File import java.util.concurrent.Executors @@ -64,8 +64,15 @@ object AppModule { @Provides @SingleIn(AppScope::class) - fun providesBuildMeta(@ApplicationContext context: Context) = BuildMeta( - isDebug = BuildConfig.DEBUG, + fun providesBuildType(): BuildType { + return BuildType.valueOf(BuildConfig.BUILD_TYPE.uppercase()) + } + + @Provides + @SingleIn(AppScope::class) + fun providesBuildMeta(@ApplicationContext context: Context, buildType: BuildType) = BuildMeta( + isDebuggable = BuildConfig.DEBUG, + buildType = buildType, applicationName = context.getString(R.string.app_name), applicationId = BuildConfig.APPLICATION_ID, lowPrivacyLoggingEnabled = false, // TODO EAx Config.LOW_PRIVACY_LOG_ENABLE, @@ -75,7 +82,6 @@ object AppModule { gitBranchName = "TODO", // BuildConfig.GIT_BRANCH_NAME, flavorDescription = "TODO", // BuildConfig.FLAVOR_DESCRIPTION, flavorShortDescription = "TODO", // BuildConfig.SHORT_FLAVOR_DESCRIPTION, - okHttpLoggingLevel = if (BuildConfig.DEBUG) HttpLoggingInterceptor.Level.BODY else HttpLoggingInterceptor.Level.BASIC, ) @Provides diff --git a/libraries/core/build.gradle.kts b/libraries/core/build.gradle.kts index dad8f844cc..de9d9735d5 100644 --- a/libraries/core/build.gradle.kts +++ b/libraries/core/build.gradle.kts @@ -29,9 +29,6 @@ java { dependencies { implementation(libs.coroutines.core) - implementation(platform(libs.network.okhttp.bom)) - implementation("com.squareup.okhttp3:logging-interceptor") - testImplementation(libs.test.junit) testImplementation(libs.test.truth) } diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/meta/BuildMeta.kt b/libraries/core/src/main/kotlin/io/element/android/libraries/core/meta/BuildMeta.kt index 8fefe19919..f816f13a39 100644 --- a/libraries/core/src/main/kotlin/io/element/android/libraries/core/meta/BuildMeta.kt +++ b/libraries/core/src/main/kotlin/io/element/android/libraries/core/meta/BuildMeta.kt @@ -16,10 +16,9 @@ package io.element.android.libraries.core.meta -import okhttp3.logging.HttpLoggingInterceptor - data class BuildMeta( - val isDebug: Boolean, + val buildType: BuildType, + val isDebuggable: Boolean, val applicationName: String, val applicationId: String, val lowPrivacyLoggingEnabled: Boolean, @@ -29,5 +28,4 @@ data class BuildMeta( val gitBranchName: String, val flavorDescription: String, val flavorShortDescription: String, - val okHttpLoggingLevel: HttpLoggingInterceptor.Level, ) diff --git a/libraries/core/src/main/kotlin/io/element/android/libraries/core/meta/BuildType.kt b/libraries/core/src/main/kotlin/io/element/android/libraries/core/meta/BuildType.kt new file mode 100644 index 0000000000..085fea8e0f --- /dev/null +++ b/libraries/core/src/main/kotlin/io/element/android/libraries/core/meta/BuildType.kt @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2023 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 io.element.android.libraries.core.meta + +enum class BuildType { + RELEASE, + NIGHTLY, + DEBUG +} diff --git a/libraries/network/src/main/kotlin/io/element/android/libraries/network/NetworkModule.kt b/libraries/network/src/main/kotlin/io/element/android/libraries/network/NetworkModule.kt index 69c1d78369..07a039e248 100644 --- a/libraries/network/src/main/kotlin/io/element/android/libraries/network/NetworkModule.kt +++ b/libraries/network/src/main/kotlin/io/element/android/libraries/network/NetworkModule.kt @@ -22,11 +22,11 @@ import dagger.Provides import io.element.android.libraries.core.meta.BuildMeta import io.element.android.libraries.di.AppScope import io.element.android.libraries.di.SingleIn +import io.element.android.libraries.network.interceptors.FormattedJsonHttpLogger import okhttp3.OkHttpClient import okhttp3.Protocol -import io.element.android.libraries.network.interceptors.FormattedJsonHttpLogger -import java.util.concurrent.TimeUnit import okhttp3.logging.HttpLoggingInterceptor +import java.util.concurrent.TimeUnit @Module @ContributesTo(AppScope::class) @@ -35,9 +35,14 @@ object NetworkModule { @Provides @JvmStatic fun providesHttpLoggingInterceptor(buildMeta: BuildMeta): HttpLoggingInterceptor { - val logger = FormattedJsonHttpLogger(buildMeta.okHttpLoggingLevel) + val loggingLevel = if (buildMeta.isDebuggable) { + HttpLoggingInterceptor.Level.BODY + } else { + HttpLoggingInterceptor.Level.BASIC + } + val logger = FormattedJsonHttpLogger(loggingLevel) val interceptor = HttpLoggingInterceptor(logger) - interceptor.level = buildMeta.okHttpLoggingLevel + interceptor.level = loggingLevel return interceptor }