Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 55fdb310 authored by Adam Bookatz's avatar Adam Bookatz
Browse files

TestApi for UserSystemPackageInstaller

Introduces a TestApi that lists which system packages
will be pre-installed for the given user type, for
use with CTS tests that need to predict which packages
are installed on a new user.

Test: atest com.android.cts.devicepolicy.DeviceOwnerTest#testCreateAndManageUser_LeaveAllSystemApps
Bug: 189873486
Change-Id: I471c5da55f8cf500a07de5773050a997ea391892
parent 1e372e67
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1765,6 +1765,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);
+1 −0
Original line number Diff line number Diff line
@@ -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);
+29 −0
Original line number Diff line number Diff line
@@ -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;
@@ -3199,6 +3201,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
     *
+11 −0
Original line number Diff line number Diff line
@@ -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;