diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-08-15 03:15:47 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-08-15 03:15:47 +0000 |
commit | 8e182ba4758d81a7281451db4e3640da77026eb3 (patch) | |
tree | 170db3c206812d9786be44bbe163bb32e66c104a | |
parent | 21bcc7ee42a556b003879eefb1e6f9451c9a6770 (diff) | |
parent | 1c1cecdab4600baefcc1d3ccfbb4f9753b57840b (diff) | |
download | net-android14-d2-s1-release.tar.gz |
Snap for 10658762 from 1c1cecdab4600baefcc1d3ccfbb4f9753b57840b to udc-d2-releaseandroid-14.0.0_r45android-14.0.0_r44android-14.0.0_r43android-14.0.0_r42android-14.0.0_r41android-14.0.0_r40android-14.0.0_r39android-14.0.0_r38android14-d2-s5-releaseandroid14-d2-s4-releaseandroid14-d2-s3-releaseandroid14-d2-s2-releaseandroid14-d2-s1-releaseandroid14-d2-release
Change-Id: Ib913de539e2212d2d6719c8487cb5d86baa0144e
-rw-r--r-- | common/testutils/devicetests/com/android/testutils/DevSdkIgnoreRule.kt | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/common/testutils/devicetests/com/android/testutils/DevSdkIgnoreRule.kt b/common/testutils/devicetests/com/android/testutils/DevSdkIgnoreRule.kt index 21e84daf..35f22b9e 100644 --- a/common/testutils/devicetests/com/android/testutils/DevSdkIgnoreRule.kt +++ b/common/testutils/devicetests/com/android/testutils/DevSdkIgnoreRule.kt @@ -19,11 +19,11 @@ package com.android.testutils import android.os.Build import androidx.test.InstrumentationRegistry import com.android.modules.utils.build.UnboundedSdkLevel +import java.util.regex.Pattern import org.junit.Assume.assumeTrue import org.junit.rules.TestRule import org.junit.runner.Description import org.junit.runners.model.Statement -import java.util.regex.Pattern @Deprecated("Use Build.VERSION_CODES", ReplaceWith("Build.VERSION_CODES.S_V2")) const val SC_V2 = Build.VERSION_CODES.S_V2 @@ -32,8 +32,22 @@ private val MAX_TARGET_SDK_ANNOTATION_RE = Pattern.compile("MaxTargetSdk([0-9]+) private val targetSdk = InstrumentationRegistry.getContext().applicationInfo.targetSdkVersion private fun isDevSdkInRange(minExclusive: String?, maxInclusive: String?): Boolean { - return (minExclusive == null || !UnboundedSdkLevel.isAtMost(minExclusive)) && - (maxInclusive == null || UnboundedSdkLevel.isAtMost(maxInclusive)) + return (minExclusive == null || !isAtMost(minExclusive)) && + (maxInclusive == null || isAtMost(maxInclusive)) +} + +private fun isAtMost(sdkVersionOrCodename: String): Boolean { + // UnboundedSdkLevel does not support builds < Q, and may stop supporting Q as well since it + // is intended for mainline modules that are now R+. + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) { + // Assume that any codename passed as argument from current code is a more recent build than + // Q: this util did not exist before Q, and codenames are only used before the corresponding + // build is finalized. This util could list 28 older codenames to check against (as per + // ro.build.version.known_codenames in more recent builds), but this does not seem valuable. + val intVersion = sdkVersionOrCodename.toIntOrNull() ?: return true + return Build.VERSION.SDK_INT <= intVersion + } + return UnboundedSdkLevel.isAtMost(sdkVersionOrCodename) } /** |