Merge "TestApi for UserSystemPackageInstaller" into sc-dev

This commit is contained in:
Adam Bookatz
2021-06-18 19:05:49 +00:00
committed by Android (Google) Code Review
4 changed files with 42 additions and 0 deletions

View File

@@ -1769,6 +1769,7 @@ package android.os {
method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public android.content.pm.UserInfo createProfileForUser(@Nullable String, @NonNull String, int, int, @Nullable String[]);
method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public android.content.pm.UserInfo createRestrictedProfile(@Nullable String);
method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public android.content.pm.UserInfo createUser(@Nullable String, @NonNull String, int);
method @Nullable @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public java.util.Set<java.lang.String> getPreInstallableSystemPackages(@NonNull String);
method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public String getUserType();
method @NonNull @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public java.util.List<android.content.pm.UserInfo> getUsers(boolean, boolean, boolean);
method @RequiresPermission(anyOf={android.Manifest.permission.MANAGE_USERS, android.Manifest.permission.CREATE_USERS}) public boolean hasBaseUserRestriction(@NonNull String, @NonNull android.os.UserHandle);

View File

@@ -46,6 +46,7 @@ interface IUserManager {
UserInfo createProfileForUserWithThrow(in String name, in String userType, int flags, int userId,
in String[] disallowedPackages);
UserInfo createRestrictedProfileWithThrow(String name, int parentUserHandle);
String[] getPreInstallableSystemPackages(in String userType);
void setUserEnabled(int userId);
void setUserAdmin(int userId);
void evictCredentialEncryptionKey(int userId);

View File

@@ -26,6 +26,7 @@ import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.StringDef;
import android.annotation.SuppressAutoDoc;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.annotation.TestApi;
@@ -53,6 +54,7 @@ import android.location.LocationManager;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.AndroidException;
import android.util.ArraySet;
import android.view.WindowManager.LayoutParams;
import com.android.internal.R;
@@ -3220,6 +3222,33 @@ public class UserManager {
return intent;
}
/**
* Returns the list of the system packages that would be installed on this type of user upon
* its creation.
*
* Returns {@code null} if all system packages would be installed.
*
* @hide
*/
@TestApi
@SuppressLint("NullableCollection")
@RequiresPermission(anyOf = {
android.Manifest.permission.MANAGE_USERS,
android.Manifest.permission.CREATE_USERS
})
public @Nullable Set<String> getPreInstallableSystemPackages(@NonNull String userType) {
try {
final String[] installableSystemPackages
= mService.getPreInstallableSystemPackages(userType);
if (installableSystemPackages == null) {
return null;
}
return new ArraySet<>(installableSystemPackages);
} catch (RemoteException re) {
throw re.rethrowFromSystemServer();
}
}
/**
* @hide
*

View File

@@ -3902,6 +3902,17 @@ public class UserManagerService extends IUserManager.Stub {
isFirstBoot, isUpgrade, existingPackages);
}
@Override
public String[] getPreInstallableSystemPackages(@NonNull String userType) {
checkManageOrCreateUsersPermission("getPreInstallableSystemPackages");
final Set<String> installableSystemPackages =
mSystemPackageInstaller.getInstallablePackagesForUserType(userType);
if (installableSystemPackages == null) {
return null;
}
return installableSystemPackages.toArray(new String[installableSystemPackages.size()]);
}
private long getCreationTime() {
final long now = System.currentTimeMillis();
return (now > EPOCH_PLUS_30_YEARS) ? now : 0;