Fix broken test

Previously, flag INSTALL_ALL_USERS  would treat this as an update,
and only do it for the users who already have the app installed.
Since the behavior changes, revise the test accordingly.

Fix: 226813445
Test: atest FrameworksServicesTests:PackageManagerServiceTest#\
        testInstallReason_userRemainsUninstalled_keepUnknown
Change-Id: If9a84c401224dad238485d6728efe3eb7cad02e2
This commit is contained in:
Jackal Guo
2022-03-28 11:32:39 +08:00
parent 617b65e4fb
commit 04bff1268d

View File

@@ -523,15 +523,11 @@ public class PackageManagerServiceTest {
userId = um.createUser("Test User", 0 /* flags */).getUserHandle().getIdentifier();
runShellCommand("am start-user -w " + userId);
// Since the test APK isn't installed on the 2nd user, the reason should be unknown.
assertWithMessage("The test APK should not be installed in the 2nd user").that(
mIPackageManager.getPackageInfo(TEST_PKG_NAME, 0 /* flags */, userId)).isNull();
assertWithMessage("The install reason in 2nd user should be unknown.").that(
mIPackageManager.getInstallReason(TEST_PKG_NAME, userId)).isEqualTo(
PackageManager.INSTALL_REASON_UNKNOWN);
// Try to update test APK with different reason INSTALL_REASON_USER
runShellCommand("pm install --install-reason 4 " + testApk);
assertWithMessage("The install reason in 2nd user should keep unknown.").that(
mIPackageManager.getInstallReason(TEST_PKG_NAME, userId)).isEqualTo(
PackageManager.INSTALL_REASON_UNKNOWN);
} finally {
runShellCommand("pm uninstall " + TEST_PKG_NAME);
if (userId != UserHandle.USER_NULL) {