From 33fbd09bb28555834923050b9fd20ed01dd606e3 Mon Sep 17 00:00:00 2001 From: mattgilbride Date: Mon, 9 Jan 2023 18:43:34 +0000 Subject: Remove stack trace from Binder#getCallingUidOrWtf Rather than Log.wtfStack, use Slog.wtf if Binder#getCallingUidOrThrow would throw. Accept an argument for the caller to provide a message in the resulting log, if generated. This has the following advantages over the previous design: 1. Collecting a stack is expensive, so it wouldn't be possible to use the previous design in hot codepaths. 2. Using Slog instead of Log.wtf means neither app processes nor system_server would crash. We don't necessarily need to crash app processes as this method is for information gathering purposes only. 3. Accepting a message as a parameter allows immediate callers to identify themselves without needing a stack trace. We plan to use this method in code generated by the AIDL compiler for system services. This will inform the decision making process w.r.t. the migration to getCallingUidOrThrow. Bug: 252975769 Test: TH Change-Id: If072c80d380aa9db63e5bf075944980e035bb922 --- core/java/android/os/Binder.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/java/android/os/Binder.java b/core/java/android/os/Binder.java index aa561050c919..0cb7df73f9b7 100644 --- a/core/java/android/os/Binder.java +++ b/core/java/android/os/Binder.java @@ -358,16 +358,16 @@ public class Binder implements IBinder { * Return the Linux UID assigned to the process that sent the transaction * currently being processed. * - * Logs WTF if the current thread is not currently + * Slog.wtf if the current thread is not currently * executing an incoming transaction and the calling identity has not been * explicitly set with {@link #clearCallingIdentity()} * * @hide */ - public static final int getCallingUidOrWtf() { + public static final int getCallingUidOrWtf(String message) { if (!isDirectlyHandlingTransaction() && !hasExplicitIdentity()) { - Log.wtfStack(TAG, - "Thread is not in a binder transaction, " + Slog.wtf(TAG, + message + ": Thread is not in a binder transaction, " + "and the calling identity has not been " + "explicitly set with clearCallingIdentity"); } -- cgit v1.2.3-59-g8ed1b