blob: 7b3fc358fca4db25ad13e43fd4ab632e6588815a [file] [log] [blame]
Adam Lesinski1ab598f2015-08-14 14:26:04 -07001/*
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#ifndef AAPT_LINKER_LINKERS_H
18#define AAPT_LINKER_LINKERS_H
19
20#include "process/IResourceTableConsumer.h"
21
22#include <set>
23
24namespace aapt {
25
26class ResourceTable;
27struct ResourceEntry;
28struct ConfigDescription;
29
30/**
31 * Determines whether a versioned resource should be created. If a versioned resource already
32 * exists, it takes precedence.
33 */
34bool shouldGenerateVersionedResource(const ResourceEntry* entry, const ConfigDescription& config,
35 const int sdkVersionToGenerate);
36
37struct AutoVersioner : public IResourceTableConsumer {
38 bool consume(IAaptContext* context, ResourceTable* table) override;
39};
40
Adam Lesinski1ab598f2015-08-14 14:26:04 -070041struct XmlAutoVersioner : public IXmlResourceConsumer {
42 bool consume(IAaptContext* context, XmlResource* resource) override;
43};
44
Adam Lesinski9f222042015-11-04 13:51:45 -080045/**
46 * If any attribute resource values are defined as public, this consumer will move all private
47 * attribute resource values to a private ^private-attr type, avoiding backwards compatibility
48 * issues with new apps running on old platforms.
49 *
50 * The Android platform ignores resource attributes it doesn't recognize, so an app developer can
51 * use new attributes in their layout XML files without worrying about versioning. This assumption
52 * actually breaks on older platforms. OEMs may add private attributes that are used internally.
53 * AAPT originally assigned all private attributes IDs immediately proceeding the public attributes'
54 * IDs.
55 *
56 * This means that on a newer Android platform, an ID previously assigned to a private attribute
57 * may end up assigned to a public attribute.
58 *
59 * App developers assume using the newer attribute is safe on older platforms because it will
60 * be ignored. Instead, the platform thinks the new attribute is an older, private attribute and
61 * will interpret it as such. This leads to unintended styling and exceptions thrown due to
62 * unexpected types.
63 *
64 * By moving the private attributes to a completely different type, this ID conflict will never
65 * occur.
66 */
67struct PrivateAttributeMover : public IResourceTableConsumer {
68 bool consume(IAaptContext* context, ResourceTable* table) override;
69};
70
71/**
72 * Resolves all references to resources in the ResourceTable and assigns them IDs.
73 * The ResourceTable must already have IDs assigned to each resource.
74 * Once the ResourceTable is processed by this linker, it is ready to be flattened.
75 */
Adam Lesinski1ab598f2015-08-14 14:26:04 -070076struct ReferenceLinker : public IResourceTableConsumer {
77 bool consume(IAaptContext* context, ResourceTable* table) override;
78};
79
Adam Lesinski9f222042015-11-04 13:51:45 -080080/**
81 * Resolves attributes in the XmlResource and compiles string values to resource values.
82 * Once an XmlResource is processed by this linker, it is ready to be flattened.
83 */
84class XmlReferenceLinker : public IXmlResourceConsumer {
Adam Lesinski1ab598f2015-08-14 14:26:04 -070085private:
86 std::set<int> mSdkLevelsFound;
87
88public:
89 bool consume(IAaptContext* context, XmlResource* resource) override;
90
Adam Lesinski9f222042015-11-04 13:51:45 -080091 /**
92 * Once the XmlResource has been consumed, this returns the various SDK levels in which
93 * framework attributes used within the XML document were defined.
94 */
95 inline const std::set<int>& getSdkLevels() const {
Adam Lesinski1ab598f2015-08-14 14:26:04 -070096 return mSdkLevelsFound;
97 }
98};
99
100} // namespace aapt
101
102#endif /* AAPT_LINKER_LINKERS_H */