Add logs for launcher user cache

Bug: 243688989
Flag: None
Change-Id: I6f6ea3f3326c1814c2a50863e9bfbcb7e4323ae8
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index c20494d..4e066b0 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -21,6 +21,7 @@
 import static com.android.launcher3.LauncherAppState.ACTION_FORCE_ROLOAD;
 import static com.android.launcher3.config.FeatureFlags.IS_STUDIO_BUILD;
 import static com.android.launcher3.testing.shared.TestProtocol.WORK_TAB_MISSING;
+import static com.android.launcher3.testing.shared.TestProtocol.sDebugTracing;
 import static com.android.launcher3.testing.shared.TestProtocol.testLogD;
 import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
 import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
@@ -295,7 +296,7 @@
     }
 
     public void onBroadcastIntent(@NonNull final Intent intent) {
-        if (DEBUG_RECEIVER) Log.d(TAG, "onReceive intent=" + intent);
+        if (DEBUG_RECEIVER || sDebugTracing) Log.d(TAG, "onReceive intent=" + intent);
         final String action = intent.getAction();
         if (Intent.ACTION_LOCALE_CHANGED.equals(action)) {
             // If we have changed locale we need to clear out the labels in all apps/workspace.
diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java
index 1a8cf24..ca356b0 100644
--- a/src/com/android/launcher3/model/LoaderTask.java
+++ b/src/com/android/launcher3/model/LoaderTask.java
@@ -24,6 +24,8 @@
 import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_DISABLED_LOCKED_USER;
 import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_DISABLED_SAFEMODE;
 import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_DISABLED_SUSPENDED;
+import static com.android.launcher3.testing.shared.TestProtocol.WORK_TAB_MISSING;
+import static com.android.launcher3.testing.shared.TestProtocol.testLogD;
 import static com.android.launcher3.util.Executors.MODEL_EXECUTOR;
 import static com.android.launcher3.util.PackageManagerHelper.hasShortcutsPermission;
 import static com.android.launcher3.util.PackageManagerHelper.isSystemApp;
@@ -949,6 +951,7 @@
     }
 
     private List<LauncherActivityInfo> loadAllApps() {
+        testLogD(WORK_TAB_MISSING, "loadingAllApps");
         final List<UserHandle> profiles = mUserCache.getUserProfiles();
         List<LauncherActivityInfo> allActivityList = new ArrayList<>();
         // Clear the list of apps
diff --git a/src/com/android/launcher3/pm/UserCache.java b/src/com/android/launcher3/pm/UserCache.java
index 5aab41a..5ebcf42 100644
--- a/src/com/android/launcher3/pm/UserCache.java
+++ b/src/com/android/launcher3/pm/UserCache.java
@@ -16,6 +16,9 @@
 
 package com.android.launcher3.pm;
 
+import static com.android.launcher3.testing.shared.TestProtocol.WORK_TAB_MISSING;
+import static com.android.launcher3.testing.shared.TestProtocol.testLogD;
+
 import android.content.Context;
 import android.content.Intent;
 import android.os.UserHandle;
@@ -56,6 +59,7 @@
     }
 
     private void onUsersChanged(Intent intent) {
+        testLogD(WORK_TAB_MISSING, "onUsersChanged intent: " + intent);
         enableAndResetCache();
         mUserChangeListeners.forEach(Runnable::run);
     }
@@ -84,6 +88,7 @@
             List<UserHandle> users = mUserManager.getUserProfiles();
             if (users != null) {
                 for (UserHandle user : users) {
+                    testLogD(WORK_TAB_MISSING, "caching user: " + user);
                     long serial = mUserManager.getSerialNumberForUser(user);
                     mUsers.put(serial, user);
                     mUserToSerialMap.put(user, serial);
@@ -134,13 +139,24 @@
      * @see UserManager#getUserProfiles()
      */
     public List<UserHandle> getUserProfiles() {
+        StringBuilder usersToReturn = new StringBuilder();
         synchronized (this) {
             if (mUsers != null) {
+                for (UserHandle u : mUserToSerialMap.keySet()) {
+                    usersToReturn.append(u).append(" && ");
+                }
+                testLogD(WORK_TAB_MISSING, "users from cache: " + usersToReturn);
                 return new ArrayList<>(mUserToSerialMap.keySet());
+            } else {
+                testLogD(WORK_TAB_MISSING, "users from cache null");
             }
         }
 
         List<UserHandle> users = mUserManager.getUserProfiles();
+        for (UserHandle u : users) {
+            usersToReturn.append(u).append(" && ");
+        }
+        testLogD(WORK_TAB_MISSING, "users from userManager: " + usersToReturn);
         return users == null ? Collections.emptyList() : users;
     }
 }
diff --git a/src/com/android/launcher3/util/ItemInfoMatcher.java b/src/com/android/launcher3/util/ItemInfoMatcher.java
index 8a27381..b6af314 100644
--- a/src/com/android/launcher3/util/ItemInfoMatcher.java
+++ b/src/com/android/launcher3/util/ItemInfoMatcher.java
@@ -18,7 +18,6 @@
 
 import android.content.ComponentName;
 import android.os.UserHandle;
-import android.util.Log;
 
 import androidx.annotation.NonNull;
 
@@ -26,7 +25,6 @@
 import com.android.launcher3.model.data.FolderInfo;
 import com.android.launcher3.model.data.ItemInfo;
 import com.android.launcher3.shortcuts.ShortcutKey;
-import com.android.launcher3.testing.shared.TestProtocol;
 
 import java.util.Collection;
 import java.util.HashSet;
@@ -44,14 +42,7 @@
     private static final ComponentName EMPTY_COMPONENT = new ComponentName("", "");
 
     public static Predicate<ItemInfo> ofUser(UserHandle user) {
-        return info -> {
-            if (TestProtocol.sDebugTracing) {
-                Log.d(TestProtocol.WORK_TAB_MISSING, "userHandle: " + user
-                        + ", itemUserHandle: " + info.user
-                        + " package: " + info.getTargetPackage());
-            }
-            return info != null && info.user.equals(user);
-        };
+        return info -> info != null && info.user.equals(user);
     }
 
     public static Predicate<ItemInfo> ofComponents(