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 <jingmatrix@gmail.com>
This commit is contained in:
Qing
2025-12-03 23:50:12 +01:00
committed by GitHub
co-authored by JingMatrix
parent eeefdc48eb
commit 31a0906c02
5 changed files with 15 additions and 5 deletions
+1
View File
@@ -56,6 +56,7 @@ android {
sourceCompatibility = JavaVersion.VERSION_21 sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21 targetCompatibility = JavaVersion.VERSION_21
} }
buildFeatures { buildConfig = true }
externalNativeBuild { externalNativeBuild {
cmake { cmake {
path = file("src/main/cpp/CMakeLists.txt") path = file("src/main/cpp/CMakeLists.txt")
@@ -226,13 +226,18 @@ abstract class BinderInterceptor : Binder() {
methodName: String, methodName: String,
callingUid: Int, callingUid: Int,
callingPid: Int, callingPid: Int,
isIntercepting: Boolean = true, skipPost: Boolean = false,
) { ) {
val isIntercepting = !skipPost && !ConfigurationManager.shouldSkipUid(callingUid)
val action = if (isIntercepting) "Intercept" else "Observe" val action = if (isIntercepting) "Intercept" else "Observe"
val packages = ConfigurationManager.getPackagesForUid(callingUid).joinToString() val packages = ConfigurationManager.getPackagesForUid(callingUid).joinToString()
SystemLogger.debug( val message =
"[TX_ID: $txId] $action $methodName for packages=[$packages] (uid=$callingUid, pid=$callingPid)" "[TX_ID: $txId] $action $methodName for packages=[$packages] (uid=$callingUid, pid=$callingPid)"
) if (isIntercepting) {
SystemLogger.debug(message)
} else {
SystemLogger.verbose(message)
}
} }
companion object { companion object {
@@ -125,7 +125,7 @@ object Keystore2Interceptor : AbstractKeystoreInterceptor() {
transactionNames[code] ?: "unknown code=$code", transactionNames[code] ?: "unknown code=$code",
callingUid, callingUid,
callingPid, callingPid,
false, true,
) )
} }
@@ -61,7 +61,7 @@ class KeyMintSecurityLevelInterceptor(
transactionNames[code] ?: "unknown code=$code", transactionNames[code] ?: "unknown code=$code",
callingUid, callingUid,
callingPid, callingPid,
false, true,
) )
} }
return TransactionResult.ContinueAndSkipPost return TransactionResult.ContinueAndSkipPost
@@ -1,6 +1,7 @@
package org.matrix.TEESimulator.logging package org.matrix.TEESimulator.logging
import android.util.Log import android.util.Log
import org.matrix.TEESimulator.BuildConfig
/** /**
* A centralized logging utility for the TEESimulator application. This object provides a consistent * 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. // The tag used for all log messages from this application.
private const val TAG = "TEESimulator" 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. * 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. * @param message The message to log.
*/ */
fun verbose(message: String) { fun verbose(message: String) {
if (!isDebugBuild) return
Log.v(TAG, message) Log.v(TAG, message)
} }
} }