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

Commit fa744dbe authored by Jackal Guo's avatar Jackal Guo
Browse files

Revise install reason in the tests

INSTALL_REASON_POLICY may be replaced under certian circumstances.
This results in the tests are flaky. Using another reason instead
for the tests.

Fix: 207726724
Test: atest PackageManagerServiceTest
Change-Id: I7ebae8af0ffb5897c108c09a474750c1ad4d5261
parent 68572f33
Loading
Loading
Loading
Loading
+16 −12
Original line number Diff line number Diff line
@@ -627,17 +627,19 @@ public class PackageManagerServiceTest {
    public void testInstallReason_afterUpdate_keepUnchanged() throws Exception {
        final File testApk = new File(TEST_DATA_PATH, TEST_APP_APK);
        try {
            // Try to install test APK with reason INSTALL_REASON_POLICY
            runShellCommand("pm install --install-reason 1 " + testApk);
            // Try to install test APK with reason INSTALL_REASON_DEVICE_SETUP
            runShellCommand("pm install --install-reason 3 " + testApk);
            assertWithMessage("The install reason of test APK is incorrect.").that(
                    mIPackageManager.getInstallReason(TEST_PKG_NAME,
                            UserHandle.myUserId())).isEqualTo(PackageManager.INSTALL_REASON_POLICY);
                            UserHandle.myUserId())).isEqualTo(
                    PackageManager.INSTALL_REASON_DEVICE_SETUP);

            // Try to update test APK with different reason INSTALL_REASON_USER
            runShellCommand("pm install --install-reason 4 " + testApk);
            assertWithMessage("The install reason should keep unchanged after update.").that(
                    mIPackageManager.getInstallReason(TEST_PKG_NAME,
                            UserHandle.myUserId())).isEqualTo(PackageManager.INSTALL_REASON_POLICY);
                            UserHandle.myUserId())).isEqualTo(
                    PackageManager.INSTALL_REASON_DEVICE_SETUP);
        } finally {
            runShellCommand("pm uninstall " + TEST_PKG_NAME);
        }
@@ -651,11 +653,12 @@ public class PackageManagerServiceTest {
        final File testApk = new File(TEST_DATA_PATH, TEST_APP_APK);
        int userId = UserHandle.USER_NULL;
        try {
            // Try to install test APK with reason INSTALL_REASON_POLICY
            runShellCommand("pm install --install-reason 1 " + testApk);
            // Try to install test APK with reason INSTALL_REASON_DEVICE_SETUP
            runShellCommand("pm install --install-reason 3 " + testApk);
            assertWithMessage("The install reason of test APK is incorrect.").that(
                    mIPackageManager.getInstallReason(TEST_PKG_NAME,
                            UserHandle.myUserId())).isEqualTo(PackageManager.INSTALL_REASON_POLICY);
                            UserHandle.myUserId())).isEqualTo(
                    PackageManager.INSTALL_REASON_DEVICE_SETUP);

            // Create and start the 2nd user.
            userId = um.createUser("Test User", 0 /* flags */).getUserHandle().getIdentifier();
@@ -690,8 +693,8 @@ public class PackageManagerServiceTest {
            userId = um.createUser("Test User", 0 /* flags */).getUserHandle().getIdentifier();
            runShellCommand("am start-user -w " + userId);

            // Try to install test APK to all users with reason INSTALL_REASON_POLICY
            runShellCommand("pm install --install-reason 1 " + testApk);
            // Try to install test APK to all users with reason INSTALL_REASON_DEVICE_SETUP
            runShellCommand("pm install --install-reason 3 " + testApk);
            assertWithMessage("The install reason is inconsistent across users.").that(
                    mIPackageManager.getInstallReason(TEST_PKG_NAME,
                            UserHandle.myUserId())).isEqualTo(
@@ -716,11 +719,12 @@ public class PackageManagerServiceTest {
            userId = um.createUser("Test User", 0 /* flags */).getUserHandle().getIdentifier();
            runShellCommand("am start-user -w " + userId);

            // Try to install test APK on the current user with reason INSTALL_REASON_POLICY
            runShellCommand("pm install --user cur --install-reason 1 " + testApk);
            // Try to install test APK on the current user with reason INSTALL_REASON_DEVICE_SETUP
            runShellCommand("pm install --user cur --install-reason 3 " + testApk);
            assertWithMessage("The install reason on the current user is incorrect.").that(
                    mIPackageManager.getInstallReason(TEST_PKG_NAME,
                            UserHandle.myUserId())).isEqualTo(PackageManager.INSTALL_REASON_POLICY);
                            UserHandle.myUserId())).isEqualTo(
                    PackageManager.INSTALL_REASON_DEVICE_SETUP);

            // Try to install test APK on the 2nd user with reason INSTALL_REASON_USER
            runShellCommand("pm install --user " + userId + " --install-reason 4 " + testApk);