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

Commit 9b28a61f authored by Neil Fuller's avatar Neil Fuller Committed by android-build-merger
Browse files

Merge "Fix code and test related to rules version check" am: a3579d4b am: c506ade2

am: af32c3d2

Change-Id: I2dc13436ceb93eb620dcaaa6d141210dc57ea1fc
parents f541405a af32c3d2
Loading
Loading
Loading
Loading
+7 −22
Original line number Diff line number Diff line
@@ -174,29 +174,14 @@ public final class RulesState implements Parcelable {
    }

    /**
     * Returns true if the distro IANA rules version supplied is newer or the same as the version in
     * the system image data files.
     * Returns true if the system image data files contain IANA rules data that are newer than the
     * distro IANA rules version supplied, i.e. true when the version specified would be "worse"
     * than the one that is in the system image. Returns false if the system image version is the
     * same or older, i.e. false when the version specified would be "better" than the one that is
     * in the system image.
     */
    public boolean isSystemVersionOlderThan(DistroRulesVersion distroRulesVersion) {
        return mSystemRulesVersion.compareTo(distroRulesVersion.getRulesVersion()) < 0;
    }

    public boolean isDistroInstalled() {
        return mDistroStatus == DISTRO_STATUS_INSTALLED;
    }

    /**
     * Returns true if the rules version supplied is newer than the one currently installed. If
     * there is no installed distro this method throws IllegalStateException.
     */
    public boolean isInstalledDistroOlderThan(DistroRulesVersion distroRulesVersion) {
        if (mOperationInProgress) {
            throw new IllegalStateException("Distro state not known: operation in progress.");
        }
        if (!isDistroInstalled()) {
            throw new IllegalStateException("No distro installed.");
        }
        return mInstalledDistroRulesVersion.isOlderThan(distroRulesVersion);
    public boolean isSystemVersionNewerThan(DistroRulesVersion distroRulesVersion) {
        return mSystemRulesVersion.compareTo(distroRulesVersion.getRulesVersion()) > 0;
    }

    public static final Parcelable.Creator<RulesState> CREATOR =
+5 −46
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ public class RulesStateTest {
                "2016a", formatVersion(1, 1), true /* operationInProgress */,
                RulesState.STAGED_OPERATION_UNKNOWN, null /* stagedDistroRulesVersion */,
                RulesState.DISTRO_STATUS_UNKNOWN, null /* installedDistroRulesVersion */);
        checkParcelableRoundTrip(rulesStateWithNulls);
        checkParcelableRoundTrip(rulesStateWithUnknowns);
    }

    private static void checkParcelableRoundTrip(RulesState rulesState) {
@@ -121,55 +121,14 @@ public class RulesStateTest {
    }

    @Test
    public void isSystemVersionOlderThan() {
    public void isSystemVersionNewerThan() {
        RulesState rulesState = new RulesState(
                "2016b", formatVersion(1, 1), false /* operationInProgress */,
                RulesState.STAGED_OPERATION_NONE, null /* stagedDistroRulesVersion */,
                RulesState.DISTRO_STATUS_INSTALLED, rulesVersion("2016b", 3));
        assertFalse(rulesState.isSystemVersionOlderThan(rulesVersion("2016a", 1)));
        assertFalse(rulesState.isSystemVersionOlderThan(rulesVersion("2016b", 1)));
        assertTrue(rulesState.isSystemVersionOlderThan(rulesVersion("2016c", 1)));
    }

    @Test
    public void isInstalledDistroOlderThan() {
        RulesState operationInProgress = new RulesState(
                "2016b", formatVersion(1, 1), true /* operationInProgress */,
                RulesState.STAGED_OPERATION_UNKNOWN, null /* stagedDistroRulesVersion */,
                RulesState.STAGED_OPERATION_UNKNOWN, null /* installedDistroRulesVersion */);
        try {
            operationInProgress.isInstalledDistroOlderThan(rulesVersion("2016b", 1));
            fail();
        } catch (IllegalStateException expected) {
        }

        RulesState nothingInstalled = new RulesState(
                "2016b", formatVersion(1, 1), false /* operationInProgress */,
                RulesState.STAGED_OPERATION_NONE, null /* stagedDistroRulesVersion */,
                RulesState.DISTRO_STATUS_NONE, null /* installedDistroRulesVersion */);
        try {
            nothingInstalled.isInstalledDistroOlderThan(rulesVersion("2016b", 1));
            fail();
        } catch (IllegalStateException expected) {
        }

        DistroRulesVersion installedVersion = rulesVersion("2016b", 3);
        RulesState rulesStateWithInstalledVersion = new RulesState(
                "2016b", formatVersion(1, 1), false /* operationInProgress */,
                RulesState.STAGED_OPERATION_NONE, null /* stagedDistroRulesVersion */,
                RulesState.DISTRO_STATUS_INSTALLED, installedVersion);

        DistroRulesVersion olderRules = rulesVersion("2016a", 1);
        assertEquals(installedVersion.isOlderThan(olderRules),
                rulesStateWithInstalledVersion.isInstalledDistroOlderThan(olderRules));

        DistroRulesVersion sameRules = rulesVersion("2016b", 1);
        assertEquals(installedVersion.isOlderThan(sameRules),
                rulesStateWithInstalledVersion.isInstalledDistroOlderThan(sameRules));

        DistroRulesVersion newerRules = rulesVersion("2016c", 1);
        assertEquals(installedVersion.isOlderThan(newerRules),
                rulesStateWithInstalledVersion.isInstalledDistroOlderThan(newerRules));
        assertTrue(rulesState.isSystemVersionNewerThan(rulesVersion("2016a", 1)));
        assertFalse(rulesState.isSystemVersionNewerThan(rulesVersion("2016b", 1)));
        assertFalse(rulesState.isSystemVersionNewerThan(rulesVersion("2016c", 1)));
    }

    private static void assertEqualsContract(RulesState one, RulesState two) {