blob: b4b6ff1daaaadf12b171ade4b87305a5dd07b0d0 [file] [log] [blame]
Adam Lesinski6f6ceb72014-11-14 14:48:12 -08001/*
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 Lesinski75f3a552015-06-03 14:54:23 -070017#include "SdkConstants.h"
18
19#include <algorithm>
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080020#include <string>
Ryan Mitchell48002f62019-04-11 14:29:25 -070021#include <unordered_set>
Adam Lesinski75f3a552015-06-03 14:54:23 -070022#include <vector>
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080023
Adam Lesinskid5083f62017-01-16 15:07:21 -080024using android::StringPiece;
25
Adam Lesinski6f6ceb72014-11-14 14:48:12 -080026namespace aapt {
27
Ryan Mitchelleb9c9ac2018-08-09 09:18:26 -070028static ApiVersion sDevelopmentSdkLevel = 10000;
Ryan Mitchell48002f62019-04-11 14:29:25 -070029static const auto sDevelopmentSdkCodeNames = std::unordered_set<StringPiece>({
30 "Q", "R"
31});
Adam Lesinskifb6312f2016-06-28 14:40:32 -070032
Adam Lesinskic744ae82017-05-17 19:28:38 -070033static const std::vector<std::pair<uint16_t, ApiVersion>> sAttrIdMap = {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070034 {0x021c, 1},
35 {0x021d, 2},
36 {0x0269, SDK_CUPCAKE},
37 {0x028d, SDK_DONUT},
38 {0x02ad, SDK_ECLAIR},
39 {0x02b3, SDK_ECLAIR_0_1},
40 {0x02b5, SDK_ECLAIR_MR1},
41 {0x02bd, SDK_FROYO},
42 {0x02cb, SDK_GINGERBREAD},
43 {0x0361, SDK_HONEYCOMB},
44 {0x0363, SDK_HONEYCOMB_MR1},
45 {0x0366, SDK_HONEYCOMB_MR2},
46 {0x03a6, SDK_ICE_CREAM_SANDWICH},
47 {0x03ae, SDK_JELLY_BEAN},
48 {0x03cc, SDK_JELLY_BEAN_MR1},
49 {0x03da, SDK_JELLY_BEAN_MR2},
50 {0x03f1, SDK_KITKAT},
51 {0x03f6, SDK_KITKAT_WATCH},
52 {0x04ce, SDK_LOLLIPOP},
Adam Lesinskic744ae82017-05-17 19:28:38 -070053 {0x04d8, SDK_LOLLIPOP_MR1},
54 {0x04f1, SDK_MARSHMALLOW},
55 {0x0527, SDK_NOUGAT},
56 {0x0530, SDK_NOUGAT_MR1},
57 {0x0568, SDK_O},
Adam Lesinskiec58a002017-10-04 14:20:06 -070058 {0x056d, SDK_O_MR1},
Ryan Mitchelleb9c9ac2018-08-09 09:18:26 -070059 {0x0586, SDK_P},
Adam Lesinski75f3a552015-06-03 14:54:23 -070060};
61
Adam Lesinskic744ae82017-05-17 19:28:38 -070062static bool less_entry_id(const std::pair<uint16_t, ApiVersion>& p, uint16_t entryId) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070063 return p.first < entryId;
Adam Lesinski75f3a552015-06-03 14:54:23 -070064}
65
Adam Lesinskic744ae82017-05-17 19:28:38 -070066ApiVersion FindAttributeSdkLevel(const ResourceId& id) {
67 if (id.package_id() != 0x01 || id.type_id() != 0x01) {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070068 return 0;
69 }
Adam Lesinskic744ae82017-05-17 19:28:38 -070070 auto iter = std::lower_bound(sAttrIdMap.begin(), sAttrIdMap.end(), id.entry_id(), less_entry_id);
Adam Lesinskicacb28f2016-10-19 12:18:14 -070071 if (iter == sAttrIdMap.end()) {
72 return SDK_LOLLIPOP_MR1;
73 }
74 return iter->second;
Adam Lesinski75f3a552015-06-03 14:54:23 -070075}
76
Ryan Mitchell48002f62019-04-11 14:29:25 -070077Maybe<ApiVersion> GetDevelopmentSdkCodeNameVersion(const StringPiece& code_name) {
78 return (sDevelopmentSdkCodeNames.find(code_name) == sDevelopmentSdkCodeNames.end())
79 ? Maybe<ApiVersion>() : sDevelopmentSdkLevel;
Adam Lesinskifb6312f2016-06-28 14:40:32 -070080}
81
Adam Lesinskicacb28f2016-10-19 12:18:14 -070082} // namespace aapt