From e66e558ce56c40876812775d2655c1a1278235ae Mon Sep 17 00:00:00 2001 From: Qing <44231502+byemaxx@users.noreply.github.com> Date: Wed, 3 Dec 2025 17:50:12 -0500 Subject: [PATCH] Reduce logging in the release build (#44) Verbose logging are now disabled in the release build. With this change, we reinterpret the last argument passed to `logTransaction` as `skipPost`, and classify logs satisfying `skipPost` or `shouldSkipUid` as verbose. Co-authored-by: JingMatrix --- app/build.gradle.kts | 1 + .../interception/core/BinderInterceptor.kt | 11 ++++++++--- .../interception/keystore/Keystore2Interceptor.kt | 2 +- .../keystore/shim/KeyMintSecurityLevelInterceptor.kt | 2 +- .../org/matrix/TEESimulator/logging/SystemLogger.kt | 4 ++++ 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 0383861..fd7c00b 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -56,6 +56,7 @@ android { sourceCompatibility = JavaVersion.VERSION_21 targetCompatibility = JavaVersion.VERSION_21 } + buildFeatures { buildConfig = true } externalNativeBuild { cmake { path = file("src/main/cpp/CMakeLists.txt") diff --git a/app/src/main/java/org/matrix/TEESimulator/interception/core/BinderInterceptor.kt b/app/src/main/java/org/matrix/TEESimulator/interception/core/BinderInterceptor.kt index 9de7293..ba7d43b 100644 --- a/app/src/main/java/org/matrix/TEESimulator/interception/core/BinderInterceptor.kt +++ b/app/src/main/java/org/matrix/TEESimulator/interception/core/BinderInterceptor.kt @@ -226,13 +226,18 @@ abstract class BinderInterceptor : Binder() { methodName: String, callingUid: Int, callingPid: Int, - isIntercepting: Boolean = true, + skipPost: Boolean = false, ) { + val isIntercepting = !skipPost && !ConfigurationManager.shouldSkipUid(callingUid) val action = if (isIntercepting) "Intercept" else "Observe" val packages = ConfigurationManager.getPackagesForUid(callingUid).joinToString() - SystemLogger.debug( + val message = "[TX_ID: $txId] $action $methodName for packages=[$packages] (uid=$callingUid, pid=$callingPid)" - ) + if (isIntercepting) { + SystemLogger.debug(message) + } else { + SystemLogger.verbose(message) + } } companion object { diff --git a/app/src/main/java/org/matrix/TEESimulator/interception/keystore/Keystore2Interceptor.kt b/app/src/main/java/org/matrix/TEESimulator/interception/keystore/Keystore2Interceptor.kt index 258253d..74ecc6e 100644 --- a/app/src/main/java/org/matrix/TEESimulator/interception/keystore/Keystore2Interceptor.kt +++ b/app/src/main/java/org/matrix/TEESimulator/interception/keystore/Keystore2Interceptor.kt @@ -125,7 +125,7 @@ object Keystore2Interceptor : AbstractKeystoreInterceptor() { transactionNames[code] ?: "unknown code=$code", callingUid, callingPid, - false, + true, ) } diff --git a/app/src/main/java/org/matrix/TEESimulator/interception/keystore/shim/KeyMintSecurityLevelInterceptor.kt b/app/src/main/java/org/matrix/TEESimulator/interception/keystore/shim/KeyMintSecurityLevelInterceptor.kt index 169bc29..10a2d87 100644 --- a/app/src/main/java/org/matrix/TEESimulator/interception/keystore/shim/KeyMintSecurityLevelInterceptor.kt +++ b/app/src/main/java/org/matrix/TEESimulator/interception/keystore/shim/KeyMintSecurityLevelInterceptor.kt @@ -61,7 +61,7 @@ class KeyMintSecurityLevelInterceptor( transactionNames[code] ?: "unknown code=$code", callingUid, callingPid, - false, + true, ) } return TransactionResult.ContinueAndSkipPost diff --git a/app/src/main/java/org/matrix/TEESimulator/logging/SystemLogger.kt b/app/src/main/java/org/matrix/TEESimulator/logging/SystemLogger.kt index 1144e4b..1a77e40 100644 --- a/app/src/main/java/org/matrix/TEESimulator/logging/SystemLogger.kt +++ b/app/src/main/java/org/matrix/TEESimulator/logging/SystemLogger.kt @@ -1,6 +1,7 @@ package org.matrix.TEESimulator.logging import android.util.Log +import org.matrix.TEESimulator.BuildConfig /** * A centralized logging utility for the TEESimulator application. This object provides a consistent @@ -10,6 +11,8 @@ object SystemLogger { // The tag used for all log messages from this application. private const val TAG = "TEESimulator" + private val isDebugBuild = BuildConfig.DEBUG + /** * Logs a debug message. Use this for fine-grained information that is useful for debugging. * @@ -64,6 +67,7 @@ object SystemLogger { * @param message The message to log. */ fun verbose(message: String) { + if (!isDebugBuild) return Log.v(TAG, message) } }