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
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user