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 | |
Chris Warrington | 057456d | 2022-07-18 11:06:17 +0000 | [diff] [blame] | 19 | #include <stdint.h> |
| 20 | |
Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 21 | #include <algorithm> |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 22 | #include <string> |
Chris Warrington | 057456d | 2022-07-18 11:06:17 +0000 | [diff] [blame] | 23 | #include <string_view> |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 24 | |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 25 | using android::StringPiece; |
Chris Warrington | 057456d | 2022-07-18 11:06:17 +0000 | [diff] [blame] | 26 | using namespace std::literals; |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 27 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 28 | namespace aapt { |
| 29 | |
Chris Warrington | 057456d | 2022-07-18 11:06:17 +0000 | [diff] [blame] | 30 | static constexpr ApiVersion sDevelopmentSdkLevel = 10000; |
Mårten Kongstad | bc7e747 | 2024-09-25 09:59:05 +0200 | [diff] [blame] | 31 | |
| 32 | // clang-format off |
Chris Warrington | 057456d | 2022-07-18 11:06:17 +0000 | [diff] [blame] | 33 | static constexpr StringPiece sDevelopmentSdkCodeNames[] = { |
Mårten Kongstad | bc7e747 | 2024-09-25 09:59:05 +0200 | [diff] [blame] | 34 | "Q"sv, |
| 35 | "R"sv, |
| 36 | "S"sv, |
| 37 | "Sv2"sv, |
| 38 | "Tiramisu"sv, |
| 39 | "UpsideDownCake"sv, |
| 40 | "VanillaIceCream"sv, |
| 41 | "Baklava"sv, |
| 42 | }; |
| 43 | // clang-format on |
Adam Lesinski | fb6312f | 2016-06-28 14:40:32 -0700 | [diff] [blame] | 44 | |
Chris Warrington | 057456d | 2022-07-18 11:06:17 +0000 | [diff] [blame] | 45 | static constexpr auto sPrivacySandboxSuffix = "PrivacySandbox"sv; |
| 46 | |
| 47 | static constexpr std::pair<uint16_t, ApiVersion> sAttrIdMap[] = { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 48 | {0x021c, 1}, |
| 49 | {0x021d, 2}, |
| 50 | {0x0269, SDK_CUPCAKE}, |
| 51 | {0x028d, SDK_DONUT}, |
| 52 | {0x02ad, SDK_ECLAIR}, |
| 53 | {0x02b3, SDK_ECLAIR_0_1}, |
| 54 | {0x02b5, SDK_ECLAIR_MR1}, |
| 55 | {0x02bd, SDK_FROYO}, |
| 56 | {0x02cb, SDK_GINGERBREAD}, |
| 57 | {0x0361, SDK_HONEYCOMB}, |
| 58 | {0x0363, SDK_HONEYCOMB_MR1}, |
| 59 | {0x0366, SDK_HONEYCOMB_MR2}, |
| 60 | {0x03a6, SDK_ICE_CREAM_SANDWICH}, |
| 61 | {0x03ae, SDK_JELLY_BEAN}, |
| 62 | {0x03cc, SDK_JELLY_BEAN_MR1}, |
| 63 | {0x03da, SDK_JELLY_BEAN_MR2}, |
| 64 | {0x03f1, SDK_KITKAT}, |
| 65 | {0x03f6, SDK_KITKAT_WATCH}, |
| 66 | {0x04ce, SDK_LOLLIPOP}, |
Adam Lesinski | c744ae8 | 2017-05-17 19:28:38 -0700 | [diff] [blame] | 67 | {0x04d8, SDK_LOLLIPOP_MR1}, |
| 68 | {0x04f1, SDK_MARSHMALLOW}, |
| 69 | {0x0527, SDK_NOUGAT}, |
| 70 | {0x0530, SDK_NOUGAT_MR1}, |
| 71 | {0x0568, SDK_O}, |
Adam Lesinski | ec58a00 | 2017-10-04 14:20:06 -0700 | [diff] [blame] | 72 | {0x056d, SDK_O_MR1}, |
Ryan Mitchell | eb9c9ac | 2018-08-09 09:18:26 -0700 | [diff] [blame] | 73 | {0x0586, SDK_P}, |
Svet Ganov | ed460aa | 2020-04-15 15:10:14 -0700 | [diff] [blame] | 74 | {0x0606, SDK_Q}, |
Jeff Sharkey | 7c5f433 | 2021-05-27 09:26:59 -0600 | [diff] [blame] | 75 | {0x0616, SDK_R}, |
| 76 | {0x064b, SDK_S}, |
Michael Wright | 534f298 | 2021-10-28 17:05:25 +0100 | [diff] [blame] | 77 | {0x064c, SDK_S_V2}, |
Yurii Zubrytskyi | 7571c0b | 2024-07-11 15:35:02 -0700 | [diff] [blame] | 78 | // TODO(zyy): add these when we need more rules for converting new attributes to the |
| 79 | // older ones, but don't bother for now as this would increase the array size for no |
| 80 | // real benefit |
| 81 | // {0x0672, SDK_TIRAMISU}, |
| 82 | // {0x0687, SDK_UPSIDE_DOWN_CAKE}, |
| 83 | // {0x06a3, SDK_VANILLA_ICE_CREAM}, |
Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
Chris Warrington | 057456d | 2022-07-18 11:06:17 +0000 | [diff] [blame] | 86 | static_assert(std::is_sorted(std::begin(sAttrIdMap), std::end(sAttrIdMap), |
| 87 | [](auto&& l, auto&& r) { return l.first < r.first; })); |
Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 88 | |
Adam Lesinski | c744ae8 | 2017-05-17 19:28:38 -0700 | [diff] [blame] | 89 | ApiVersion FindAttributeSdkLevel(const ResourceId& id) { |
| 90 | if (id.package_id() != 0x01 || id.type_id() != 0x01) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 91 | return 0; |
| 92 | } |
Chris Warrington | 057456d | 2022-07-18 11:06:17 +0000 | [diff] [blame] | 93 | const auto it = |
| 94 | std::lower_bound(std::begin(sAttrIdMap), std::end(sAttrIdMap), id.entry_id(), |
| 95 | [](const auto& pair, uint16_t entryId) { return pair.first < entryId; }); |
| 96 | if (it == std::end(sAttrIdMap)) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 97 | return SDK_LOLLIPOP_MR1; |
| 98 | } |
Chris Warrington | 057456d | 2022-07-18 11:06:17 +0000 | [diff] [blame] | 99 | return it->second; |
Adam Lesinski | 75f3a55 | 2015-06-03 14:54:23 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Yurii Zubrytskyi | a577514 | 2022-11-02 17:49:49 -0700 | [diff] [blame] | 102 | std::optional<ApiVersion> GetDevelopmentSdkCodeNameVersion(StringPiece code_name) { |
Chris Warrington | 057456d | 2022-07-18 11:06:17 +0000 | [diff] [blame] | 103 | const auto it = |
| 104 | std::find_if(std::begin(sDevelopmentSdkCodeNames), std::end(sDevelopmentSdkCodeNames), |
| 105 | [code_name](const auto& item) { return code_name.starts_with(item); }); |
| 106 | if (it == std::end(sDevelopmentSdkCodeNames)) { |
| 107 | return {}; |
| 108 | } |
| 109 | if (code_name.size() == it->size()) { |
| 110 | return sDevelopmentSdkLevel; |
| 111 | } |
| 112 | if (code_name.size() == it->size() + sPrivacySandboxSuffix.size() && |
| 113 | code_name.ends_with(sPrivacySandboxSuffix)) { |
| 114 | return sDevelopmentSdkLevel; |
| 115 | } |
| 116 | return {}; |
Adam Lesinski | fb6312f | 2016-06-28 14:40:32 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 119 | } // namespace aapt |