Merge "Fix code and test related to rules version check"

am: a3579d4b84

Change-Id: I2021e64f04e0e55de21dcdc0a932ce535e6a7f9f
This commit is contained in:
Neil Fuller
2017-06-22 21:37:48 +00:00
committed by android-build-merger
2 changed files with 12 additions and 68 deletions

View File

@@ -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 * Returns true if the system image data files contain IANA rules data that are newer than the
* the system image data files. * 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) { public boolean isSystemVersionNewerThan(DistroRulesVersion distroRulesVersion) {
return mSystemRulesVersion.compareTo(distroRulesVersion.getRulesVersion()) < 0; 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 static final Parcelable.Creator<RulesState> CREATOR = public static final Parcelable.Creator<RulesState> CREATOR =

View File

@@ -107,7 +107,7 @@ public class RulesStateTest {
"2016a", formatVersion(1, 1), true /* operationInProgress */, "2016a", formatVersion(1, 1), true /* operationInProgress */,
RulesState.STAGED_OPERATION_UNKNOWN, null /* stagedDistroRulesVersion */, RulesState.STAGED_OPERATION_UNKNOWN, null /* stagedDistroRulesVersion */,
RulesState.DISTRO_STATUS_UNKNOWN, null /* installedDistroRulesVersion */); RulesState.DISTRO_STATUS_UNKNOWN, null /* installedDistroRulesVersion */);
checkParcelableRoundTrip(rulesStateWithNulls); checkParcelableRoundTrip(rulesStateWithUnknowns);
} }
private static void checkParcelableRoundTrip(RulesState rulesState) { private static void checkParcelableRoundTrip(RulesState rulesState) {
@@ -121,55 +121,14 @@ public class RulesStateTest {
} }
@Test @Test
public void isSystemVersionOlderThan() { public void isSystemVersionNewerThan() {
RulesState rulesState = new RulesState( RulesState rulesState = new RulesState(
"2016b", formatVersion(1, 1), false /* operationInProgress */, "2016b", formatVersion(1, 1), false /* operationInProgress */,
RulesState.STAGED_OPERATION_NONE, null /* stagedDistroRulesVersion */, RulesState.STAGED_OPERATION_NONE, null /* stagedDistroRulesVersion */,
RulesState.DISTRO_STATUS_INSTALLED, rulesVersion("2016b", 3)); RulesState.DISTRO_STATUS_INSTALLED, rulesVersion("2016b", 3));
assertFalse(rulesState.isSystemVersionOlderThan(rulesVersion("2016a", 1))); assertTrue(rulesState.isSystemVersionNewerThan(rulesVersion("2016a", 1)));
assertFalse(rulesState.isSystemVersionOlderThan(rulesVersion("2016b", 1))); assertFalse(rulesState.isSystemVersionNewerThan(rulesVersion("2016b", 1)));
assertTrue(rulesState.isSystemVersionOlderThan(rulesVersion("2016c", 1))); assertFalse(rulesState.isSystemVersionNewerThan(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));
} }
private static void assertEqualsContract(RulesState one, RulesState two) { private static void assertEqualsContract(RulesState one, RulesState two) {