Merge "Using EventLog for user switching events" into rvc-dev
diff --git a/services/core/java/com/android/server/am/EventLogTags.logtags b/services/core/java/com/android/server/am/EventLogTags.logtags
index cc5df40..17f4187 100644
--- a/services/core/java/com/android/server/am/EventLogTags.logtags
+++ b/services/core/java/com/android/server/am/EventLogTags.logtags
@@ -93,3 +93,16 @@
 
 # The task is being unfrozen
 30069 am_unfreeze (Pid|1|5),(Process Name|3)
+
+# User switch events
+30070 uc_finish_user_unlocking (UID|1|5)
+30071 uc_finish_user_unlocked (UID|1|5)
+30072 uc_finish_user_unlocked_completed (UID|1|5)
+30073 uc_finish_user_stopping (UID|1|5)
+30074 uc_finish_user_stopped (UID|1|5)
+30075 uc_switch_user (UID|1|5)
+30076 uc_start_user_internal (UID|1|5)
+30077 uc_unlock_user (UID|1|5)
+30078 uc_finish_user_boot (UID|1|5)
+30079 uc_dispatch_user_switch (oldUID|1|5) (newUID|1|5)
+30080 uc_continue_user_switch (oldUID|1|5) (newUID|1|5)
diff --git a/services/core/java/com/android/server/am/UserController.java b/services/core/java/com/android/server/am/UserController.java
index 343b4ba..636a0e9 100644
--- a/services/core/java/com/android/server/am/UserController.java
+++ b/services/core/java/com/android/server/am/UserController.java
@@ -83,6 +83,7 @@
 import android.os.storage.StorageManager;
 import android.text.format.DateUtils;
 import android.util.ArraySet;
+import android.util.EventLog;
 import android.util.IntArray;
 import android.util.Pair;
 import android.util.Slog;
@@ -382,8 +383,8 @@
 
     private void finishUserBoot(UserState uss, IIntentReceiver resultTo) {
         final int userId = uss.mHandle.getIdentifier();
+        EventLog.writeEvent(EventLogTags.UC_FINISH_USER_BOOT, userId);
 
-        Slog.d(TAG, "Finishing user boot " + userId);
         synchronized (mLock) {
             // Bail if we ended up with a stale user
             if (mStartedUsers.get(userId) != uss) {
@@ -451,7 +452,7 @@
      */
     private boolean finishUserUnlocking(final UserState uss) {
         final int userId = uss.mHandle.getIdentifier();
-        Slog.d(TAG, "UserController event: finishUserUnlocking(" + userId + ")");
+        EventLog.writeEvent(EventLogTags.UC_FINISH_USER_UNLOCKING, userId);
         // Only keep marching forward if user is actually unlocked
         if (!StorageManager.isUserKeyUnlocked(userId)) return false;
         synchronized (mLock) {
@@ -496,7 +497,7 @@
      */
     void finishUserUnlocked(final UserState uss) {
         final int userId = uss.mHandle.getIdentifier();
-        Slog.d(TAG, "UserController event: finishUserUnlocked(" + userId + ")");
+        EventLog.writeEvent(EventLogTags.UC_FINISH_USER_UNLOCKED, userId);
         // Only keep marching forward if user is actually unlocked
         if (!StorageManager.isUserKeyUnlocked(userId)) return;
         synchronized (mLock) {
@@ -567,7 +568,7 @@
 
     private void finishUserUnlockedCompleted(UserState uss) {
         final int userId = uss.mHandle.getIdentifier();
-        Slog.d(TAG, "UserController event: finishUserUnlockedCompleted(" + userId + ")");
+        EventLog.writeEvent(EventLogTags.UC_FINISH_USER_UNLOCKED_COMPLETED, userId);
         synchronized (mLock) {
             // Bail if we ended up with a stale user
             if (mStartedUsers.get(uss.mHandle.getIdentifier()) != uss) return;
@@ -830,7 +831,7 @@
 
     void finishUserStopping(final int userId, final UserState uss,
             final boolean allowDelayedLocking) {
-        Slog.d(TAG, "UserController event: finishUserStopping(" + userId + ")");
+        EventLog.writeEvent(EventLogTags.UC_FINISH_USER_STOPPING, userId);
         // On to the next.
         final Intent shutdownIntent = new Intent(Intent.ACTION_SHUTDOWN);
         // This is the result receiver for the final shutdown broadcast.
@@ -870,7 +871,7 @@
 
     void finishUserStopped(UserState uss, boolean allowDelayedLocking) {
         final int userId = uss.mHandle.getIdentifier();
-        Slog.d(TAG, "UserController event: finishUserStopped(" + userId + ")");
+        EventLog.writeEvent(EventLogTags.UC_FINISH_USER_STOPPED, userId);
         final boolean stopped;
         boolean lockUser = true;
         final ArrayList<IStopUserCallback> stopCallbacks;
@@ -1147,7 +1148,7 @@
 
     private boolean startUserInternal(@UserIdInt int userId, boolean foreground,
             @Nullable IProgressListener unlockListener, @NonNull TimingsTraceAndSlog t) {
-        Slog.i(TAG, "Starting userid:" + userId + " fg:" + foreground);
+        EventLog.writeEvent(EventLogTags.UC_START_USER_INTERNAL, userId);
 
         final int callingUid = Binder.getCallingUid();
         final int callingPid = Binder.getCallingPid();
@@ -1396,7 +1397,7 @@
     boolean unlockUser(final @UserIdInt int userId, byte[] token, byte[] secret,
             IProgressListener listener) {
         checkCallingPermission(INTERACT_ACROSS_USERS_FULL, "unlockUser");
-        Slog.i(TAG, "unlocking user " + userId);
+        EventLog.writeEvent(EventLogTags.UC_UNLOCK_USER, userId);
         final long binderToken = Binder.clearCallingIdentity();
         try {
             return unlockUserCleared(userId, token, secret, listener);
@@ -1481,7 +1482,7 @@
 
     boolean switchUser(final int targetUserId) {
         enforceShellRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES, targetUserId);
-        Slog.i(TAG, "switching to user " + targetUserId);
+        EventLog.writeEvent(EventLogTags.UC_SWITCH_USER, targetUserId);
         int currentUserId = getCurrentUserId();
         UserInfo targetUserInfo = getUserInfo(targetUserId);
         if (targetUserId == currentUserId) {
@@ -1604,7 +1605,8 @@
     }
 
     void dispatchUserSwitch(final UserState uss, final int oldUserId, final int newUserId) {
-        Slog.d(TAG, "Dispatch onUserSwitching oldUser #" + oldUserId + " newUser #" + newUserId);
+        EventLog.writeEvent(EventLogTags.UC_DISPATCH_USER_SWITCH, oldUserId, newUserId);
+
         final int observerCount = mUserSwitchObservers.beginBroadcast();
         if (observerCount > 0) {
             final ArraySet<String> curWaitingUserSwitchCallbacks = new ArraySet<>();
@@ -1666,7 +1668,8 @@
     }
 
     void continueUserSwitch(UserState uss, int oldUserId, int newUserId) {
-        Slog.d(TAG, "Continue user switch oldUser #" + oldUserId + ", newUser #" + newUserId);
+        EventLog.writeEvent(EventLogTags.UC_CONTINUE_USER_SWITCH, oldUserId, newUserId);
+
         if (isUserSwitchUiEnabled()) {
             mInjector.getWindowManager().stopFreezingScreen();
         }