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

Commit 0153481a authored by Neil Fuller's avatar Neil Fuller
Browse files

Fix code and test related to rules version check

Fix code and test related to an incorrectly implemented
rules version check.

This meant that a device could not return the rules version
it shipped with.

Another unused (and also confusing) method and
associated test is being deleted here.

To run tests:
make -j30 FrameworksServicesTests
adb install -r -g \
  "out/target/product/angler/data/app/FrameworksServicesTests/FrameworksServicesTests.apk"
adb shell am instrument -e package com.android.server.timezone -w \
  com.android.frameworks.servicestests \
  "com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner"

Test: See above.
Bug: 31008728
Change-Id: I31b55e88072dd73055cb3d8cf252be6eac920322
parent ba6b96d9
Loading
Loading
Loading
Loading
+7 −22
Original line number Original line 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
     * 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 =
+5 −46
Original line number Original line Diff line number Diff line
@@ -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) {