summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Tyler Gunn <tgunn@google.com> 2023-03-16 23:00:04 +0000
committer Tyler Gunn <tgunn@google.com> 2023-03-16 23:00:04 +0000
commit4d54ccae611e5bfc5130b6732c1b0f544ee63151 (patch)
treefeec687c446b7c2d238d571a4535f7597437338d
parent62229367d3013b235e5be409b24b4c3d9c25abc3 (diff)
Add Telecom log tagging for whether logs took place in Telecom lock.
We've seen some bugs lately which root cause to an operation taking place OUTSIDE of the Telecom sync lock when it should happen inside. To help diagnose these types of problem, this change adds an icon to the end of Telecom log messages which indicates if the log message was triggered from within the Telecom lock or not. ❗ indicates the message came from outside the Telecom lock; this is NOT always a problem as some logs purposely take place outside a lock. 🔒 indicates the message came from inside the Telecom lock. This is only enabled in userdebug builds to ensure no extra overhead is incurred to check locks when logging takes place (Thread.holdsLock does appear to be a very efficient API, but still). Test: Build; verify logging indicates whether calls are from in Telecom lock. Bug: 273759792 Change-Id: I3bdf7d444ff81af2df55ff76ec72d8862f72c0f4
-rw-r--r--telecomm/java/android/telecom/Log.java19
1 files changed, 18 insertions, 1 deletions
diff --git a/telecomm/java/android/telecom/Log.java b/telecomm/java/android/telecom/Log.java
index 884dcf2dfbad..a34094ce6452 100644
--- a/telecomm/java/android/telecom/Log.java
+++ b/telecomm/java/android/telecom/Log.java
@@ -69,6 +69,7 @@ public class Log {
private static final Object sSingletonSync = new Object();
private static EventManager sEventManager;
private static SessionManager sSessionManager;
+ private static Object sLock = null;
/**
* Tracks whether user-activated extended logging is enabled.
@@ -388,6 +389,19 @@ public class Log {
}
/**
+ * Sets the main telecom sync lock used within Telecom. This is used when building log messages
+ * so that we can identify places in the code where we are doing something outside of the
+ * Telecom lock.
+ * @param lock The lock.
+ */
+ public static void setLock(Object lock) {
+ // Don't do lock monitoring on user builds.
+ if (!Build.IS_USER) {
+ sLock = lock;
+ }
+ }
+
+ /**
* If user enabled extended logging is enabled and the time limit has passed, disables the
* extended logging.
*/
@@ -512,7 +526,10 @@ public class Log {
args.length);
msg = format + " (An error occurred while formatting the message.)";
}
- return String.format(Locale.US, "%s: %s%s", prefix, msg, sessionPostfix);
+ // If a lock was set, check if this thread holds that lock and output an emoji that lets
+ // the developer know whether a log message came from within the Telecom lock or not.
+ String isLocked = sLock != null ? (Thread.holdsLock(sLock) ? "\uD83D\uDD12" : "❗") : "";
+ return String.format(Locale.US, "%s: %s%s%s", prefix, msg, sessionPostfix, isLocked);
}
/**