| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2015 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
| Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 17 | #include "SdkConstants.h" | 
|  | 18 |  | 
|  | 19 | #include <algorithm> | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 20 | #include <string> | 
| Ryan Mitchell | 48002f6 | 2019-04-11 14:29:25 -0700 | [diff] [blame] | 21 | #include <unordered_set> | 
| Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 22 | #include <vector> | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 23 |  | 
| Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 24 | using android::StringPiece; | 
|  | 25 |  | 
| Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 26 | namespace aapt { | 
|  | 27 |  | 
| Ryan Mitchell | eb9c9ac | 2018-08-09 09:18:26 -0700 | [diff] [blame] | 28 | static ApiVersion sDevelopmentSdkLevel = 10000; | 
| Colin Cross | 9ada354 | 2023-02-15 15:02:51 -0800 | [diff] [blame] | 29 | static const auto sDevelopmentSdkCodeNames = std::unordered_set<StringPiece>( | 
|  | 30 | {"Q", "R", "S", "Sv2", "Tiramisu", "UpsideDownCake", "VanillaIceCream"}); | 
| Adam Lesinski | fb6312f | 2016-06-28 14:40:32 -0700 | [diff] [blame] | 31 |  | 
| Adam Lesinski | c744ae8 | 2017-05-17 19:28:38 -0700 | [diff] [blame] | 32 | static const std::vector<std::pair<uint16_t, ApiVersion>> sAttrIdMap = { | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 33 | {0x021c, 1}, | 
|  | 34 | {0x021d, 2}, | 
|  | 35 | {0x0269, SDK_CUPCAKE}, | 
|  | 36 | {0x028d, SDK_DONUT}, | 
|  | 37 | {0x02ad, SDK_ECLAIR}, | 
|  | 38 | {0x02b3, SDK_ECLAIR_0_1}, | 
|  | 39 | {0x02b5, SDK_ECLAIR_MR1}, | 
|  | 40 | {0x02bd, SDK_FROYO}, | 
|  | 41 | {0x02cb, SDK_GINGERBREAD}, | 
|  | 42 | {0x0361, SDK_HONEYCOMB}, | 
|  | 43 | {0x0363, SDK_HONEYCOMB_MR1}, | 
|  | 44 | {0x0366, SDK_HONEYCOMB_MR2}, | 
|  | 45 | {0x03a6, SDK_ICE_CREAM_SANDWICH}, | 
|  | 46 | {0x03ae, SDK_JELLY_BEAN}, | 
|  | 47 | {0x03cc, SDK_JELLY_BEAN_MR1}, | 
|  | 48 | {0x03da, SDK_JELLY_BEAN_MR2}, | 
|  | 49 | {0x03f1, SDK_KITKAT}, | 
|  | 50 | {0x03f6, SDK_KITKAT_WATCH}, | 
|  | 51 | {0x04ce, SDK_LOLLIPOP}, | 
| Adam Lesinski | c744ae8 | 2017-05-17 19:28:38 -0700 | [diff] [blame] | 52 | {0x04d8, SDK_LOLLIPOP_MR1}, | 
|  | 53 | {0x04f1, SDK_MARSHMALLOW}, | 
|  | 54 | {0x0527, SDK_NOUGAT}, | 
|  | 55 | {0x0530, SDK_NOUGAT_MR1}, | 
|  | 56 | {0x0568, SDK_O}, | 
| Adam Lesinski | ec58a00 | 2017-10-04 14:20:06 -0700 | [diff] [blame] | 57 | {0x056d, SDK_O_MR1}, | 
| Ryan Mitchell | eb9c9ac | 2018-08-09 09:18:26 -0700 | [diff] [blame] | 58 | {0x0586, SDK_P}, | 
| Svet Ganov | ed460aa | 2020-04-15 15:10:14 -0700 | [diff] [blame] | 59 | {0x0606, SDK_Q}, | 
| Jeff Sharkey | 7c5f433 | 2021-05-27 09:26:59 -0600 | [diff] [blame] | 60 | {0x0616, SDK_R}, | 
|  | 61 | {0x064b, SDK_S}, | 
| Michael Wright | 534f298 | 2021-10-28 17:05:25 +0100 | [diff] [blame] | 62 | {0x064c, SDK_S_V2}, | 
| Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 63 | }; | 
|  | 64 |  | 
| Adam Lesinski | c744ae8 | 2017-05-17 19:28:38 -0700 | [diff] [blame] | 65 | static bool less_entry_id(const std::pair<uint16_t, ApiVersion>& p, uint16_t entryId) { | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 66 | return p.first < entryId; | 
| Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 67 | } | 
|  | 68 |  | 
| Adam Lesinski | c744ae8 | 2017-05-17 19:28:38 -0700 | [diff] [blame] | 69 | ApiVersion FindAttributeSdkLevel(const ResourceId& id) { | 
|  | 70 | if (id.package_id() != 0x01 || id.type_id() != 0x01) { | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 71 | return 0; | 
|  | 72 | } | 
| Adam Lesinski | c744ae8 | 2017-05-17 19:28:38 -0700 | [diff] [blame] | 73 | auto iter = std::lower_bound(sAttrIdMap.begin(), sAttrIdMap.end(), id.entry_id(), less_entry_id); | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 74 | if (iter == sAttrIdMap.end()) { | 
|  | 75 | return SDK_LOLLIPOP_MR1; | 
|  | 76 | } | 
|  | 77 | return iter->second; | 
| Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 78 | } | 
|  | 79 |  | 
| Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 80 | std::optional<ApiVersion> GetDevelopmentSdkCodeNameVersion(StringPiece code_name) { | 
| Ryan Mitchell | 48002f6 | 2019-04-11 14:29:25 -0700 | [diff] [blame] | 81 | return (sDevelopmentSdkCodeNames.find(code_name) == sDevelopmentSdkCodeNames.end()) | 
| Ryan Mitchell | 4382e44 | 2021-07-14 12:53:01 -0700 | [diff] [blame] | 82 | ? std::optional<ApiVersion>() | 
|  | 83 | : sDevelopmentSdkLevel; | 
| Adam Lesinski | fb6312f | 2016-06-28 14:40:32 -0700 | [diff] [blame] | 84 | } | 
|  | 85 |  | 
| Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 86 | }  // namespace aapt |