From 0153481a22d679818d9eb5ea997bfd967be1c206 Mon Sep 17 00:00:00 2001 From: Neil Fuller Date: Thu, 22 Jun 2017 17:58:02 +0100 Subject: [PATCH] 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 --- .../java/android/app/timezone/RulesState.java | 29 +++-------- .../android/app/timezone/RulesStateTest.java | 51 ++----------------- 2 files changed, 12 insertions(+), 68 deletions(-) diff --git a/core/java/android/app/timezone/RulesState.java b/core/java/android/app/timezone/RulesState.java index 33f4e8060b3e6..7d6ad2119fb7d 100644 --- a/core/java/android/app/timezone/RulesState.java +++ b/core/java/android/app/timezone/RulesState.java @@ -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 CREATOR = diff --git a/core/tests/coretests/src/android/app/timezone/RulesStateTest.java b/core/tests/coretests/src/android/app/timezone/RulesStateTest.java index a9357c9175ab3..7f4819bf63a1d 100644 --- a/core/tests/coretests/src/android/app/timezone/RulesStateTest.java +++ b/core/tests/coretests/src/android/app/timezone/RulesStateTest.java @@ -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) {