diff options
-rw-r--r-- | common/tests/unit/src/com/android/testutils/DeviceInfoUtilsTest.java | 14 | ||||
-rw-r--r-- | common/testutils/devicetests/com/android/testutils/DeviceInfoUtils.java | 15 |
2 files changed, 29 insertions, 0 deletions
diff --git a/common/tests/unit/src/com/android/testutils/DeviceInfoUtilsTest.java b/common/tests/unit/src/com/android/testutils/DeviceInfoUtilsTest.java index 6f603d50..e46dd599 100644 --- a/common/tests/unit/src/com/android/testutils/DeviceInfoUtilsTest.java +++ b/common/tests/unit/src/com/android/testutils/DeviceInfoUtilsTest.java @@ -106,4 +106,18 @@ public final class DeviceInfoUtilsTest { assertFalse(v1.isAtLeast(v4)); assertFalse(v1.isAtLeast(v5)); } + + @Test + public void testKernelVersionIsAtLeast() { + // Pick a lower kernel version 4.0 which was released at April 2015, the kernel + // version running on all test devices nowadays should be higher than it. + assertTrue(DeviceInfoUtils.isKernelVersionAtLeast("4.0")); + + // Invalid kernel version. + assertTrue(DeviceInfoUtils.isKernelVersionAtLeast("0.0.0")); + + // Pick a higher kernel version which isn't released yet, comparison should return false. + // Need to update the target version in the future to make sure the test still passes. + assertFalse(DeviceInfoUtils.isKernelVersionAtLeast("20.0.0")); + } } diff --git a/common/testutils/devicetests/com/android/testutils/DeviceInfoUtils.java b/common/testutils/devicetests/com/android/testutils/DeviceInfoUtils.java index 1925b559..ea89edaa 100644 --- a/common/testutils/devicetests/com/android/testutils/DeviceInfoUtils.java +++ b/common/testutils/devicetests/com/android/testutils/DeviceInfoUtils.java @@ -16,6 +16,7 @@ package com.android.testutils; +import android.os.VintfRuntimeInfo; import android.text.TextUtils; import android.util.Pair; @@ -157,4 +158,18 @@ public class DeviceInfoUtils { return new KVersion(0, 0, 0); } } + + /** + * Check if the current kernel version is at least satisfied with the given version. + * + * @param version the start version to compare + * @return return true if the current version is at least satisfied with the given version. + * otherwise, return false. + */ + public static boolean isKernelVersionAtLeast(final String version) { + final String kernelVersion = VintfRuntimeInfo.getKernelVersion(); + final KVersion current = DeviceInfoUtils.getMajorMinorSubminorVersion(kernelVersion); + final KVersion from = DeviceInfoUtils.getMajorMinorSubminorVersion(version); + return current.isAtLeast(from); + } } |