xref: /aosp_15_r20/build/soong/android/vendor_api_levels.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
1// Copyright 2024 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package android
16
17import (
18	"fmt"
19	"strconv"
20)
21
22func getSdkVersionOfVendorApiLevel(apiLevel int) (int, bool) {
23	ok := true
24	sdkVersion := -1
25	switch apiLevel {
26	case 202404:
27		sdkVersion = 35
28	case 202504:
29		sdkVersion = 36
30	default:
31		ok = false
32	}
33	return sdkVersion, ok
34}
35
36func GetSdkVersionForVendorApiLevel(vendorApiLevel string) (ApiLevel, error) {
37	vendorApiLevelInt, err := strconv.Atoi(vendorApiLevel)
38	if err != nil {
39		return NoneApiLevel, fmt.Errorf("The vendor API level %q must be able to be parsed as an integer", vendorApiLevel)
40	}
41	if vendorApiLevelInt < 35 {
42		return uncheckedFinalApiLevel(vendorApiLevelInt), nil
43	}
44
45	if sdkInt, ok := getSdkVersionOfVendorApiLevel(vendorApiLevelInt); ok {
46		return uncheckedFinalApiLevel(sdkInt), nil
47	}
48	return NoneApiLevel, fmt.Errorf("Unknown vendor API level %q. Requires updating the map in vendor_api_level.go?", vendorApiLevel)
49}
50