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

Commit 99ba7e9c authored by Gavin Corkery's avatar Gavin Corkery
Browse files

Add test for rollback of userdata with multiple rollbacks

This test ensures that if a staged install is abandoned, and then
staged again, the userdata snapshot will match the correct rollback.
Since there will be multiple rollbacks in the ENABLING state for the
same package, it is important to ensure that the userdata for the
abandoned rollback is not used.

Test: atest StagedRollbackTest
Bug: 134035054
Change-Id: Icae7226dfb393c5ffc31dd0116f61141e84f5a42
parent 855b4506
Loading
Loading
Loading
Loading
+39 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInstaller;
import android.content.rollback.RollbackInfo;
import android.content.rollback.RollbackManager;

@@ -33,6 +34,7 @@ import androidx.test.InstrumentationRegistry;

import com.android.cts.install.lib.Install;
import com.android.cts.install.lib.InstallUtils;
import com.android.cts.install.lib.LocalIntentSender;
import com.android.cts.install.lib.TestApp;
import com.android.cts.install.lib.Uninstall;
import com.android.cts.rollback.lib.Rollback;
@@ -207,4 +209,40 @@ public class StagedRollbackTest {
                InstrumentationRegistry.getContext().getPackageManager(), 0);
        return comp.getPackageName();
    }

    @Test
    public void testPreviouslyAbandonedRollbacksEnableRollback() throws Exception {
        Uninstall.packages(TestApp.A);
        Install.single(TestApp.A1).commit();
        assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);

        int sessionId = Install.single(TestApp.A2).setStaged().setEnableRollback().commit();
        PackageInstaller pi = InstrumentationRegistry.getContext().getPackageManager()
                .getPackageInstaller();
        pi.abandonSession(sessionId);

        // Remove the first intent sender result, so that the next staged install session does not
        // erroneously think that it has itself been abandoned.
        // TODO(b/136260017): Restructure LocalIntentSender to negate the need for this step.
        LocalIntentSender.getIntentSenderResult();
        Install.single(TestApp.A2).setStaged().setEnableRollback().commit();
    }

    @Test
    public void testPreviouslyAbandonedRollbacksCommitRollback() throws Exception {
        assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
        InstallUtils.processUserData(TestApp.A);

        RollbackManager rm = RollbackUtils.getRollbackManager();
        RollbackInfo rollback = getUniqueRollbackInfoForPackage(
                rm.getAvailableRollbacks(), TestApp.A);
        RollbackUtils.rollback(rollback.getRollbackId());
    }

    @Test
    public void testPreviouslyAbandonedRollbacksCheckUserdataRollback() throws Exception {
        assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(1);
        InstallUtils.processUserData(TestApp.A);
        Uninstall.packages(TestApp.A);
    }
}
 No newline at end of file
+12 −0
Original line number Diff line number Diff line
@@ -165,4 +165,16 @@ public class StagedRollbackTest extends BaseHostJUnit4Test {
        // Verify rollback was not executed after health check deadline
        runPhase("assertNoNetworkStackRollbackCommitted");
    }

    /**
     * Tests rolling back user data where there are multiple rollbacks for that package.
     */
    @Test
    public void testPreviouslyAbandonedRollbacks() throws Exception {
        runPhase("testPreviouslyAbandonedRollbacksEnableRollback");
        getDevice().reboot();
        runPhase("testPreviouslyAbandonedRollbacksCommitRollback");
        getDevice().reboot();
        runPhase("testPreviouslyAbandonedRollbacksCheckUserdataRollback");
    }
}