summaryrefslogtreecommitdiff
path: root/android/api_levels.go
diff options
context:
space:
mode:
author Spandan Das <spandandas@google.com> 2023-03-03 21:20:36 +0000
committer Spandan Das <spandandas@google.com> 2023-03-20 16:51:32 +0000
commite773739787394e9632043749e88ca6cfd5a40a67 (patch)
treec069277b81df80f608af7f97b33e62c3e0d18ff8 /android/api_levels.go
parent3015e38a5f0d466dd850fd0a77648844a1364efc (diff)
Update min_sdk_version from SdkSpec to ApiLevel
min_sdk_version signifies device version and does not need an sdkKind to describe it fully. Update the type and cleanup existing usages. As a side benefit, we also get better error handling since users can no longer enter something like `public_30` as a valid min_sdk_version in bp files Will do a similar cleanup for targetSdkVersion and maxSdkVersion in a followup CL Test: m nothing Test: no change in ninja files (this should be a no-op) Bug: 208456999 Change-Id: Ie6ae7e267d093c5e4787e82685daaca1021d202e
Diffstat (limited to 'android/api_levels.go')
-rw-r--r--android/api_levels.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/android/api_levels.go b/android/api_levels.go
index e48a69ea2..0c0b2b433 100644
--- a/android/api_levels.go
+++ b/android/api_levels.go
@@ -185,6 +185,14 @@ func (l ApiLevel) EffectiveVersionString(ctx EarlyModuleContext) (string, error)
return ret.String(), nil
}
+// Specified returns true if the module is targeting a recognzized api_level.
+// It returns false if either
+// 1. min_sdk_version is not an int or a recognized codename
+// 2. both min_sdk_version and sdk_version are empty. In this case, MinSdkVersion() defaults to SdkSpecPrivate.ApiLevel
+func (this ApiLevel) Specified() bool {
+ return !this.IsInvalid() && !this.IsPrivate()
+}
+
// Returns -1 if the current API level is less than the argument, 0 if they
// are equal, and 1 if it is greater than the argument.
func (this ApiLevel) CompareTo(other ApiLevel) int {
@@ -289,6 +297,16 @@ func ReplaceFinalizedCodenames(config Config, raw string) string {
return strconv.Itoa(num)
}
+// ApiLevelFrom converts the given string `raw` to an ApiLevel.
+// If `raw` is invalid (empty string, unrecognized codename etc.) it returns an invalid ApiLevel
+func ApiLevelFrom(ctx PathContext, raw string) ApiLevel {
+ ret, err := ApiLevelFromUser(ctx, raw)
+ if err != nil {
+ return NewInvalidApiLevel(raw)
+ }
+ return ret
+}
+
// ApiLevelFromUser converts the given string `raw` to an ApiLevel, possibly returning an error.
//
// `raw` must be non-empty. Passing an empty string results in a panic.