diff options
author | Bookatz <bookatz@google.com> | 2019-08-05 14:07:12 -0700 |
---|---|---|
committer | Bookatz <bookatz@google.com> | 2019-09-24 09:38:58 -0700 |
commit | 04d7ae5c6f87dad68980304c7cdb220a8ce54cf2 (patch) | |
tree | 388fc386b0768dfb06e955ea7f08c98e8da83b07 /apct-tests/perftests/multiuser | |
parent | 679a4248a9c8a34e12809064136ee5f0efab090d (diff) |
Whitelist packages for user types
Creates a new SystemConfig xml entry which allows a device to whitelist
system packages to be installed on users when they are created, based on
the type of user.
System packages will be installed on users when they are created, or
during OTAs, based on this whitelist. The whitelist can be
enabled/disabled via a Config resource.
For any user type, system packages can be whitelisted or blacklisted.
If it is both (for the same user type), the blacklist takes priority.
If it is neither, it won't be installed (since it isn't whitelisted).
If a system package isn't mentioned in the whitelist file at all, for
any user, then its behaviour depends on the Config resource value, which
can optionally implicitly whitelist all such apps on all users.
For now, the list is mostly empty and the default config is set to be
enabled but implicitly whitelist all system packages that are not
mentioned.
Test: atest FrameworksServicesTests:SystemConfigTest
Test: atest com.android.server.pm.UserManagerServicePackageWhitelistTest
Test: manually test user 0 by flashall -w and checking packages
Test: manually test OTA by setting setprop persist.pm.mock-upgrade 1
Bug: 134605778
Change-Id: Ia098c1f597f66a1c946cfcc9b7771c25e8ceabf7
Diffstat (limited to 'apct-tests/perftests/multiuser')
-rw-r--r-- | apct-tests/perftests/multiuser/AndroidManifest.xml | 1 | ||||
-rw-r--r-- | apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java | 77 |
2 files changed, 78 insertions, 0 deletions
diff --git a/apct-tests/perftests/multiuser/AndroidManifest.xml b/apct-tests/perftests/multiuser/AndroidManifest.xml index b2a9524d29c4..893c8ca9328b 100644 --- a/apct-tests/perftests/multiuser/AndroidManifest.xml +++ b/apct-tests/perftests/multiuser/AndroidManifest.xml @@ -22,6 +22,7 @@ <uses-permission android:name="android.permission.INSTALL_PACKAGES" /> <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS" /> <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" /> + <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" /> <application> <uses-library android:name="android.test.runner" /> diff --git a/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java b/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java index 32107b4e789e..e74e4a958eb9 100644 --- a/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java +++ b/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java @@ -38,8 +38,10 @@ import android.os.Bundle; import android.os.IBinder; import android.os.IProgressListener; import android.os.RemoteException; +import android.os.SystemProperties; import android.os.UserHandle; import android.os.UserManager; +import android.perftests.utils.ShellHelper; import android.util.Log; import android.view.WindowManagerGlobal; @@ -85,6 +87,14 @@ public class UserLifecycleTests { private static final String DUMMY_PACKAGE_NAME = "perftests.multiuser.apps.dummyapp"; + // Copy of UserSystemPackageInstaller whitelist mode constants. + private static final String PACKAGE_WHITELIST_MODE_PROP = + "persist.debug.user.package_whitelist_mode"; + private static final int USER_TYPE_PACKAGE_WHITELIST_MODE_DISABLE = 0; + private static final int USER_TYPE_PACKAGE_WHITELIST_MODE_ENFORCE = 0b001; + private static final int USER_TYPE_PACKAGE_WHITELIST_MODE_IMPLICIT_WHITELIST = 0b100; + private static final int USER_TYPE_PACKAGE_WHITELIST_MODE_DEVICE_DEFAULT = -1; + private UserManager mUm; private ActivityManager mAm; private IActivityManager mIam; @@ -442,6 +452,55 @@ public class UserLifecycleTests { } } + // TODO: This is just a POC. Do this properly and add more. + /** Tests starting (unlocking) a newly-created profile using the user-type-pkg-whitelist. */ + @Test + public void managedProfileUnlock_usingWhitelist() throws Exception { + assumeTrue(mHasManagedUserFeature); + final int origMode = getUserTypePackageWhitelistMode(); + setUserTypePackageWhitelistMode(USER_TYPE_PACKAGE_WHITELIST_MODE_ENFORCE + | USER_TYPE_PACKAGE_WHITELIST_MODE_IMPLICIT_WHITELIST); + + try { + while (mRunner.keepRunning()) { + mRunner.pauseTiming(); + final int userId = createManagedProfile(); + mRunner.resumeTiming(); + + startUserInBackground(userId); + + mRunner.pauseTiming(); + removeUser(userId); + mRunner.resumeTiming(); + } + } finally { + setUserTypePackageWhitelistMode(origMode); + } + } + /** Tests starting (unlocking) a newly-created profile NOT using the user-type-pkg-whitelist. */ + @Test + public void managedProfileUnlock_notUsingWhitelist() throws Exception { + assumeTrue(mHasManagedUserFeature); + final int origMode = getUserTypePackageWhitelistMode(); + setUserTypePackageWhitelistMode(USER_TYPE_PACKAGE_WHITELIST_MODE_DISABLE); + + try { + while (mRunner.keepRunning()) { + mRunner.pauseTiming(); + final int userId = createManagedProfile(); + mRunner.resumeTiming(); + + startUserInBackground(userId); + + mRunner.pauseTiming(); + removeUser(userId); + mRunner.resumeTiming(); + } + } finally { + setUserTypePackageWhitelistMode(origMode); + } + } + /** Creates a new user, returning its userId. */ private int createUserNoFlags() { return createUserWithFlags(/* flags= */ 0); @@ -458,6 +517,10 @@ public class UserLifecycleTests { private int createManagedProfile() { final UserInfo userInfo = mUm.createProfileForUser("TestProfile", UserInfo.FLAG_MANAGED_PROFILE, mAm.getCurrentUser()); + if (userInfo == null) { + throw new IllegalStateException("Creating managed profile failed. Most likely there is " + + "already a pre-existing profile on the device."); + } mUsersToRemove.add(userInfo.id); return userInfo.id; } @@ -627,6 +690,20 @@ public class UserLifecycleTests { } } + /** Gets the PACKAGE_WHITELIST_MODE_PROP System Property. */ + private int getUserTypePackageWhitelistMode() { + return SystemProperties.getInt(PACKAGE_WHITELIST_MODE_PROP, + USER_TYPE_PACKAGE_WHITELIST_MODE_DEVICE_DEFAULT); + } + + /** Sets the PACKAGE_WHITELIST_MODE_PROP System Property to the given value. */ + private void setUserTypePackageWhitelistMode(int mode) { + String result = ShellHelper.runShellCommand( + String.format("setprop %s %d", PACKAGE_WHITELIST_MODE_PROP, mode)); + attestFalse("Failed to set sysprop " + PACKAGE_WHITELIST_MODE_PROP + ": " + result, + result != null && result.contains("Failed")); + } + private void removeUser(int userId) { try { mUm.removeUser(userId); |