UserSystemPackageInstaller uses user types

UserSystemPackageInstaller was recently introduced and used a subset of
UserInfo flags to specify which package should be installed on which
user.
ag/9507174 introduced the notion of user types to UserManager.

The current cl does the following:

UserSystemPackageInstaller now uses user types instead of UserInfo
flags. This includes both base types (SYSTEM, FULL, PROFILE), as well as
specific user types (like guest, managed profiles, etc.). OEMs can
therefore specify on which type of user each system package should be
installed.

(Installing based on the ephemeral flag is therefore no longer
available, but since it wasn't being used for this purpose, that's
okay.)

Bug: 134605778
Bug: 142151520
Bug: 142482943
Test: atest UserSystemPackageInstallerTest
Change-Id: Ibd6de29e4f4861e91e282edfdd3100dc2d2e2f5f
diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java
index 8ddfad9..8144338 100644
--- a/services/core/java/com/android/server/pm/UserManagerService.java
+++ b/services/core/java/com/android/server/pm/UserManagerService.java
@@ -564,7 +564,7 @@
             readUserListLP();
             sInstance = this;
         }
-        mSystemPackageInstaller = new UserSystemPackageInstaller(this);
+        mSystemPackageInstaller = new UserSystemPackageInstaller(this, mUserTypes);
         mLocalService = new LocalService();
         LocalServices.addService(UserManagerInternal.class, mLocalService);
         mLockPatternUtils = new LockPatternUtils(mContext);
@@ -1205,6 +1205,24 @@
         }
     }
 
+    /** Returns whether the given user type is one of the FULL user types. */
+    boolean isUserTypeSubtypeOfFull(String userType) {
+        UserTypeDetails userTypeDetails = mUserTypes.get(userType);
+        return userTypeDetails != null && userTypeDetails.isFull();
+    }
+
+    /** Returns whether the given user type is one of the PROFILE user types. */
+    boolean isUserTypeSubtypeOfProfile(String userType) {
+        UserTypeDetails userTypeDetails = mUserTypes.get(userType);
+        return userTypeDetails != null && userTypeDetails.isProfile();
+    }
+
+    /** Returns whether the given user type is one of the SYSTEM user types. */
+    boolean isUserTypeSubtypeOfSystem(String userType) {
+        UserTypeDetails userTypeDetails = mUserTypes.get(userType);
+        return userTypeDetails != null && userTypeDetails.isSystem();
+    }
+
     @Override
     public boolean hasBadge(@UserIdInt int userId) {
         checkManageOrInteractPermIfCallerInOtherProfileGroup(userId, "hasBadge");
@@ -3233,8 +3251,8 @@
                     StorageManager.FLAG_STORAGE_DE | StorageManager.FLAG_STORAGE_CE);
             t.traceEnd();
 
-            final Set<String> installablePackages = // TODO(b/142482943): use userType
-                    mSystemPackageInstaller.getInstallablePackagesForUserType(flags);
+            final Set<String> installablePackages =
+                    mSystemPackageInstaller.getInstallablePackagesForUserType(userType);
             t.traceBegin("PM.createNewUser");
             mPm.createNewUser(userId, installablePackages, disallowedPackages);
             t.traceEnd();