• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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	case 202604:
31		sdkVersion = 37
32	default:
33		ok = false
34	}
35	return sdkVersion, ok
36}
37
38func GetSdkVersionForVendorApiLevel(vendorApiLevel string) (ApiLevel, error) {
39	vendorApiLevelInt, err := strconv.Atoi(vendorApiLevel)
40	if err != nil {
41		return NoneApiLevel, fmt.Errorf("The vendor API level %q must be able to be parsed as an integer", vendorApiLevel)
42	}
43	if vendorApiLevelInt < 35 {
44		return uncheckedFinalApiLevel(vendorApiLevelInt), nil
45	}
46
47	if sdkInt, ok := getSdkVersionOfVendorApiLevel(vendorApiLevelInt); ok {
48		return uncheckedFinalApiLevel(sdkInt), nil
49	}
50	return NoneApiLevel, fmt.Errorf("Unknown vendor API level %q. Requires updating the map in vendor_api_level.go?", vendorApiLevel)
51}
52