Changes PM so apps are not installed for pre-created users.

A pre-created user is not ready for use yet, so when an app is
installed using USER_ALL, it should not be installed on such user.

In particular, doing so can cause multi-user releted CTS tests to
fail when the device has pre-created users. Example:
- Device has pre-created user 42
- Test infra install TestApp on all users (which include 42)
- Test case creates a new user
- Framework converts 42
- Test case calls 'pm install-existing --user 42 --wait TestApp' -
  it will hang

Test: adb shell pm create-user --pre-create-only && \
  atest CtsAppExitTestCases:android.app.cts.ActivityManagerAppExitInfoTest#testSecondaryUser # on automotive and phone

Test: atest CtsCarHostTestCases:android.car.cts.PreCreateUsersHostTest # to make sure it doesn't break anything

Bug: 215653069
Bug: 218724421

Merged-In: If261163c024fbdf4121fbcd0971ed784018a2991
Change-Id: If261163c024fbdf4121fbcd0971ed784018a2991
(cherry picked from commit 1e0920671ac0208bb588f8e7ea1fc42d4d68dfb4)
This commit is contained in:
Felipe Leme
2022-02-09 14:14:32 -08:00
parent c8cebe93e3
commit c6e6c51902

View File

@@ -116,6 +116,7 @@ import com.android.server.pm.permission.LegacyPermissionState.PermissionState;
import com.android.server.pm.verify.domain.DomainVerificationLegacySettings; import com.android.server.pm.verify.domain.DomainVerificationLegacySettings;
import com.android.server.pm.verify.domain.DomainVerificationManagerInternal; import com.android.server.pm.verify.domain.DomainVerificationManagerInternal;
import com.android.server.pm.verify.domain.DomainVerificationPersistence; import com.android.server.pm.verify.domain.DomainVerificationPersistence;
import com.android.server.utils.Slogf;
import com.android.server.utils.Snappable; import com.android.server.utils.Snappable;
import com.android.server.utils.SnapshotCache; import com.android.server.utils.SnapshotCache;
import com.android.server.utils.TimingsTraceAndSlog; import com.android.server.utils.TimingsTraceAndSlog;
@@ -944,7 +945,8 @@ public final class Settings implements Watchable, Snappable {
Slog.i(PackageManagerService.TAG, "Stopping package " + pkgName, e); Slog.i(PackageManagerService.TAG, "Stopping package " + pkgName, e);
} }
List<UserInfo> users = getAllUsers(userManager); List<UserInfo> users = getAllUsers(userManager);
final int installUserId = installUser != null ? installUser.getIdentifier() : 0; int installUserId = installUser != null ? installUser.getIdentifier()
: UserHandle.USER_SYSTEM;
if (users != null && allowInstall) { if (users != null && allowInstall) {
for (UserInfo user : users) { for (UserInfo user : users) {
// By default we consider this app to be installed // By default we consider this app to be installed
@@ -955,8 +957,14 @@ public final class Settings implements Watchable, Snappable {
// user we are installing for. // user we are installing for.
final boolean installed = installUser == null final boolean installed = installUser == null
|| (installUserId == UserHandle.USER_ALL || (installUserId == UserHandle.USER_ALL
&& !isAdbInstallDisallowed(userManager, user.id)) && !isAdbInstallDisallowed(userManager, user.id)
&& !user.preCreated)
|| installUserId == user.id; || installUserId == user.id;
if (DEBUG_MU) {
Slogf.d(TAG, "createNewSetting(pkg=%s, installUserId=%s, user=%s, "
+ "installed=%b)",
pkgName, installUserId, user.toFullString(), installed);
}
pkgSetting.setUserState(user.id, 0, COMPONENT_ENABLED_STATE_DEFAULT, pkgSetting.setUserState(user.id, 0, COMPONENT_ENABLED_STATE_DEFAULT,
installed, installed,
true /*stopped*/, true /*stopped*/,
@@ -1980,11 +1988,14 @@ public final class Settings implements Watchable, Snappable {
serializer.startTag(null, TAG_PACKAGE_RESTRICTIONS); serializer.startTag(null, TAG_PACKAGE_RESTRICTIONS);
if (DEBUG_MU) Log.i(TAG, "Writing " + userPackagesStateFile); if (DEBUG_MU) {
Slogf.i(TAG, "Writing %s (%d packages)", userPackagesStateFile,
mPackages.values().size());
}
for (final PackageSetting pkg : mPackages.values()) { for (final PackageSetting pkg : mPackages.values()) {
final PackageUserState ustate = pkg.readUserState(userId); final PackageUserState ustate = pkg.readUserState(userId);
if (DEBUG_MU) { if (DEBUG_MU) {
Log.i(TAG, " pkg=" + pkg.name + ", installed=" + ustate.installed Log.v(TAG, " pkg=" + pkg.name + ", installed=" + ustate.installed
+ ", state=" + ustate.enabled); + ", state=" + ustate.enabled);
} }