Improved user lifecycle tracing messages.
Test: manual verification
Bug: 145689885
Change-Id: I7664db5f35eea26509e0e0baba724916642f7ec6
diff --git a/service/src/com/android/car/user/CarUserService.java b/service/src/com/android/car/user/CarUserService.java
index 95cc200..196bd89 100644
--- a/service/src/com/android/car/user/CarUserService.java
+++ b/service/src/com/android/car/user/CarUserService.java
@@ -62,6 +62,7 @@
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.os.IResultReceiver;
+import com.android.internal.util.FunctionalUtils;
import com.android.internal.util.Preconditions;
import com.android.internal.util.UserIcons;
@@ -852,25 +853,27 @@
private void notifyAppLifecycleListeners(UserLifecycleEvent event) {
int listenersSize = mLifecycleListeners.size();
if (listenersSize == 0) {
- Log.i(TAG_USER, "No app listener to be notified");
+ if (Log.isLoggable(TAG_USER, Log.DEBUG)) {
+ Log.d(TAG_USER, "No app listener to be notified of " + event);
+ }
return;
}
+ int userId = event.getUserId();
new Thread(() -> {
// Must use a different TimingsTraceLog because it's another thread
TimingsTraceLog t = new TimingsTraceLog(TAG_USER, Trace.TRACE_TAG_SYSTEM_SERVER);
- Log.i(TAG_USER, "Notifying " + listenersSize + " app listeners");
- int userId = event.getUserId();
+ if (Log.isLoggable(TAG_USER, Log.DEBUG)) {
+ Log.d(TAG_USER, "Notifying " + listenersSize + " app listeners of " + event);
+ }
+ t.traceBegin("notify-app-listeners-user-" + userId + "-event-" + event.getEventType());
for (int i = 0; i < listenersSize; i++) {
int uid = mLifecycleListeners.keyAt(i);
- IResultReceiver listener = mLifecycleListeners.valueAt(i);
- t.traceBegin("notify-" + event.getEventType() + "-app-listener-" + uid);
+ t.traceBegin("notify-app-listener-" + uid);
Bundle data = new Bundle();
data.putInt(CarUserManager.BUNDLE_PARAM_ACTION, event.getEventType());
// TODO(b/144120654): should pass currentId from CarServiceHelperService so it
// can set BUNDLE_PARAM_PREVIOUS_USER_ID (and unit test it)
- if (Log.isLoggable(TAG_USER, Log.DEBUG)) {
- Log.d(TAG_USER, "Notifying listener for uid " + uid);
- }
+ IResultReceiver listener = mLifecycleListeners.valueAt(i);
try {
listener.send(userId, data);
} catch (RemoteException e) {
@@ -879,23 +882,29 @@
t.traceEnd();
}
}
- }, "SwitchUser-" + event.getUserId() + "-Listeners").start();
+ t.traceEnd();
+ }, "SwitchUser-" + userId + "-AppListeners").start();
}
private void notifyUserLifecycleListeners(UserLifecycleEvent event) {
TimingsTraceLog t = new TimingsTraceLog(TAG_USER, Trace.TRACE_TAG_SYSTEM_SERVER);
if (mUserLifecycleListeners.isEmpty()) {
- Log.i(TAG_USER, "Not notifying internal UserLifecycleListeners");
+ Log.w(TAG_USER, "Not notifying internal UserLifecycleListeners");
return;
+ } else if (Log.isLoggable(TAG_USER, Log.DEBUG)) {
+ Log.d(TAG_USER, "Notifying " + mUserLifecycleListeners.size() + " service listeners of "
+ + event);
}
- t.traceBegin("notifyInternalUserLifecycleListeners");
+
+ t.traceBegin("notify-listeners-" + event.getUserId() + "-event-" + event.getEventType());
for (UserLifecycleListener listener : mUserLifecycleListeners) {
- t.traceBegin("notify-" + event.getEventType() + "-listener-" + listener);
+ String listenerName = FunctionalUtils.getLambdaName(listener);
+ t.traceBegin("notify-listener-" + listenerName);
try {
listener.onEvent(event);
} catch (RuntimeException e) {
Log.e(TAG_USER,
- "Exception raised when invoking onEvent for " + listener, e);
+ "Exception raised when invoking onEvent for " + listenerName, e);
}
t.traceEnd();
}