summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-08-15 03:15:47 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-08-15 03:15:47 +0000
commit8e182ba4758d81a7281451db4e3640da77026eb3 (patch)
tree170db3c206812d9786be44bbe163bb32e66c104a
parent21bcc7ee42a556b003879eefb1e6f9451c9a6770 (diff)
parent1c1cecdab4600baefcc1d3ccfbb4f9753b57840b (diff)
downloadnet-android14-d2-s1-release.tar.gz
Change-Id: Ib913de539e2212d2d6719c8487cb5d86baa0144e
-rw-r--r--common/testutils/devicetests/com/android/testutils/DevSdkIgnoreRule.kt20
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)
}
/**