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

Commit 6d61f5e5 authored by shafik's avatar shafik
Browse files

Test Rollback Expiration lifetime

Add a test that checks whether the rollback data is expired after the
lifetime duration expires.
Since the default expiration time is 48 hours, the test first changes
the expiration time to a more reasonable (and testable) amount.

Flow:
	* Change rollback lifetime duration to 30s
	* Install v1 of an app
	* Install v2 of an app (with rollback enabled)
	* Check that package rollback is available
	* Wait for the lifetime duration
	* Check that package is not available for rollback

Test: atest RollbackTest
Test: atest RollbackTest#testRollbackExpiresAfterLifetime
Bug: 124096729
Change-Id: I4c6b3df14ed7b98b72d3c8a49a0dd5b2e864e2b2
parent 0eedd597
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -434,7 +434,10 @@ class RollbackManagerServiceImpl extends IRollbackManager.Stub {
            mAvailableRollbacks = null;
            mRecentlyExecutedRollbacks = null;
        }
        getHandler().post(() -> ensureRollbackDataLoaded());
        getHandler().post(() -> {
            updateRollbackLifetimeDurationInMillis();
            ensureRollbackDataLoaded();
        });
    }

    @Override
+59 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.content.rollback.RollbackInfo;
import android.content.rollback.RollbackManager;
import android.os.Handler;
import android.os.HandlerThread;
import android.provider.DeviceConfig;
import android.support.test.InstrumentationRegistry;
import android.util.Log;

@@ -330,6 +331,64 @@ public class RollbackTest {
        }
    }

    /**
     * Test the scheduling aspect of rollback expiration.
     */
    @Test
    public void testRollbackExpiresAfterLifetime() throws Exception {
        long expirationTime = TimeUnit.SECONDS.toMillis(30);
        long defaultExpirationTime = TimeUnit.HOURS.toMillis(48);
        RollbackManager rm = RollbackTestUtils.getRollbackManager();

        try {
            RollbackTestUtils.adoptShellPermissionIdentity(
                    Manifest.permission.INSTALL_PACKAGES,
                    Manifest.permission.DELETE_PACKAGES,
                    Manifest.permission.MANAGE_ROLLBACKS,
                    Manifest.permission.WRITE_DEVICE_CONFIG);

            DeviceConfig.setProperty(DeviceConfig.Rollback.BOOT_NAMESPACE,
                    DeviceConfig.Rollback.ROLLBACK_LIFETIME_IN_MILLIS,
                    Long.toString(expirationTime), false /* makeDefault*/);

            // Pull the new expiration time from DeviceConfig
            rm.reloadPersistedData();

            // Uninstall TEST_APP_A
            RollbackTestUtils.uninstall(TEST_APP_A);
            assertEquals(-1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));

            // Install v1 of the app (without rollbacks enabled).
            RollbackTestUtils.install("RollbackTestAppAv1.apk", false);
            assertEquals(1, RollbackTestUtils.getInstalledVersion(TEST_APP_A));

            // Upgrade from v1 to v2, with rollbacks enabled.
            RollbackTestUtils.install("RollbackTestAppAv2.apk", true);
            assertEquals(2, RollbackTestUtils.getInstalledVersion(TEST_APP_A));

            // Check that the rollback data has not expired
            Thread.sleep(1000);
            RollbackInfo rollback = getUniqueRollbackInfoForPackage(
                    rm.getAvailableRollbacks(), TEST_APP_A);
            assertRollbackInfoEquals(TEST_APP_A, 2, 1, rollback);

            // Give it a little more time, but still not the long enough to expire
            Thread.sleep(expirationTime / 2);
            rollback = getUniqueRollbackInfoForPackage(
                rm.getAvailableRollbacks(), TEST_APP_A);
            assertRollbackInfoEquals(TEST_APP_A, 2, 1, rollback);

            // Check that the data has expired after the expiration time (with a buffer of 1 second)
            Thread.sleep(expirationTime / 2);
            assertNull(getUniqueRollbackInfoForPackage(rm.getAvailableRollbacks(), TEST_APP_A));
        } finally {
            DeviceConfig.setProperty(DeviceConfig.Rollback.BOOT_NAMESPACE,
                    DeviceConfig.Rollback.ROLLBACK_LIFETIME_IN_MILLIS,
                    Long.toString(defaultExpirationTime), false /* makeDefault*/);
            RollbackTestUtils.dropShellPermissionIdentity();
        }
    }

    /**
     * Test explicit expiration of rollbacks.
     * Does not test the scheduling aspects of rollback expiration.