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
17 #include "SdkConstants.h"
18
19 #include <algorithm>
20 #include <string>
21 #include <unordered_map>
22 #include <vector>
23
24 using android::StringPiece;
25
26 namespace aapt {
27
28 static const char* sDevelopmentSdkCodeName = "Q";
29 static ApiVersion sDevelopmentSdkLevel = 10000;
30
31 static const std::vector<std::pair<uint16_t, ApiVersion>> sAttrIdMap = {
32 {0x021c, 1},
33 {0x021d, 2},
34 {0x0269, SDK_CUPCAKE},
35 {0x028d, SDK_DONUT},
36 {0x02ad, SDK_ECLAIR},
37 {0x02b3, SDK_ECLAIR_0_1},
38 {0x02b5, SDK_ECLAIR_MR1},
39 {0x02bd, SDK_FROYO},
40 {0x02cb, SDK_GINGERBREAD},
41 {0x0361, SDK_HONEYCOMB},
42 {0x0363, SDK_HONEYCOMB_MR1},
43 {0x0366, SDK_HONEYCOMB_MR2},
44 {0x03a6, SDK_ICE_CREAM_SANDWICH},
45 {0x03ae, SDK_JELLY_BEAN},
46 {0x03cc, SDK_JELLY_BEAN_MR1},
47 {0x03da, SDK_JELLY_BEAN_MR2},
48 {0x03f1, SDK_KITKAT},
49 {0x03f6, SDK_KITKAT_WATCH},
50 {0x04ce, SDK_LOLLIPOP},
51 {0x04d8, SDK_LOLLIPOP_MR1},
52 {0x04f1, SDK_MARSHMALLOW},
53 {0x0527, SDK_NOUGAT},
54 {0x0530, SDK_NOUGAT_MR1},
55 {0x0568, SDK_O},
56 {0x056d, SDK_O_MR1},
57 {0x0586, SDK_P},
58 };
59
less_entry_id(const std::pair<uint16_t,ApiVersion> & p,uint16_t entryId)60 static bool less_entry_id(const std::pair<uint16_t, ApiVersion>& p, uint16_t entryId) {
61 return p.first < entryId;
62 }
63
FindAttributeSdkLevel(const ResourceId & id)64 ApiVersion FindAttributeSdkLevel(const ResourceId& id) {
65 if (id.package_id() != 0x01 || id.type_id() != 0x01) {
66 return 0;
67 }
68 auto iter = std::lower_bound(sAttrIdMap.begin(), sAttrIdMap.end(), id.entry_id(), less_entry_id);
69 if (iter == sAttrIdMap.end()) {
70 return SDK_LOLLIPOP_MR1;
71 }
72 return iter->second;
73 }
74
GetDevelopmentSdkCodeNameAndVersion()75 std::pair<StringPiece, ApiVersion> GetDevelopmentSdkCodeNameAndVersion() {
76 return std::make_pair(StringPiece(sDevelopmentSdkCodeName), sDevelopmentSdkLevel);
77 }
78
79 } // namespace aapt
80