Improved dump on services that implement isSupported(UserInfo).

Test: adb shell dumpsys voiceinteraction
Test: adb shell dumpsys autofill

Bug: 146349941

Change-Id: Ibc3001515081ba0efc72b3651f900a4e4f630faa
diff --git a/services/core/java/com/android/server/SystemService.java b/services/core/java/com/android/server/SystemService.java
index 5e659b6..c5409f85 100644
--- a/services/core/java/com/android/server/SystemService.java
+++ b/services/core/java/com/android/server/SystemService.java
@@ -29,6 +29,10 @@
 
 import com.android.server.pm.UserManagerService;
 
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * The base class for services running in the system process. Override and implement
  * the lifecycle event callback methods as needed.
@@ -164,6 +168,25 @@
     }
 
     /**
+     * Helper method used to dump which users are {@link #onStartUser(UserInfo) supported}.
+     */
+    protected void dumpSupportedUsers(@NonNull PrintWriter pw, @NonNull String prefix) {
+        final List<UserInfo> allUsers = UserManager.get(mContext).getUsers();
+        final List<Integer> supportedUsers = new ArrayList<>(allUsers.size());
+        for (UserInfo user : allUsers) {
+            supportedUsers.add(user.id);
+        }
+        if (allUsers.isEmpty()) {
+            pw.print(prefix); pw.println("No supported users");
+        } else {
+            final int size = supportedUsers.size();
+            pw.print(prefix); pw.print(size); pw.print(" supported user");
+            if (size > 1) pw.print("s");
+            pw.print(": "); pw.println(supportedUsers);
+        }
+    }
+
+    /**
      * @deprecated subclasses should extend {@link #onStartUser(UserInfo)} instead (which by default
      * calls this method).
      */
diff --git a/services/core/java/com/android/server/infra/AbstractMasterSystemService.java b/services/core/java/com/android/server/infra/AbstractMasterSystemService.java
index d71ffb7..58f6ba2 100644
--- a/services/core/java/com/android/server/infra/AbstractMasterSystemService.java
+++ b/services/core/java/com/android/server/infra/AbstractMasterSystemService.java
@@ -762,6 +762,7 @@
             if (mUpdatingPackageNames != null) {
                 pw.print("Packages being updated: "); pw.println(mUpdatingPackageNames);
             }
+            dumpSupportedUsers(pw, prefix);
             if (mServiceNameResolver != null) {
                 pw.print(prefix); pw.print("Name resolver: ");
                 mServiceNameResolver.dumpShort(pw); pw.println();
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
index 6132cc2..404346f 100644
--- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
@@ -1291,6 +1291,7 @@
                 pw.println("  mCurUser: " + mCurUser);
                 pw.println("  mCurUserUnlocked: " + mCurUserUnlocked);
                 pw.println("  mCurUserSupported: " + mCurUserSupported);
+                dumpSupportedUsers(pw, "  ");
                 if (mImpl == null) {
                     pw.println("  (No active implementation)");
                     return;