blob: ce455da9b58b28cd75632d1aecf649049987ed23 [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
Adam Lesinski467f1712015-11-16 17:35:44 -080020#include "Resource.h"
Adam Lesinski1ab598f2015-08-14 14:26:04 -070021#include "process/IResourceTableConsumer.h"
Adam Lesinski467f1712015-11-16 17:35:44 -080022#include "xml/XmlDom.h"
Adam Lesinski1ab598f2015-08-14 14:26:04 -070023
24#include <set>
25
26namespace aapt {
27
28class ResourceTable;
Adam Lesinskie4bb9eb2016-02-12 22:18:51 -080029class ResourceEntry;
Adam Lesinski1ab598f2015-08-14 14:26:04 -070030struct ConfigDescription;
31
32/**
Adam Lesinski467f1712015-11-16 17:35:44 -080033 * Defines the location in which a value exists. This determines visibility of other
34 * package's private symbols.
35 */
36struct CallSite {
37 ResourceNameRef resource;
38};
39
40/**
Adam Lesinski1ab598f2015-08-14 14:26:04 -070041 * Determines whether a versioned resource should be created. If a versioned resource already
42 * exists, it takes precedence.
43 */
44bool shouldGenerateVersionedResource(const ResourceEntry* entry, const ConfigDescription& config,
45 const int sdkVersionToGenerate);
46
Adam Lesinskifb6312f2016-06-28 14:40:32 -070047class AutoVersioner : public IResourceTableConsumer {
48public:
Adam Lesinski1ab598f2015-08-14 14:26:04 -070049 bool consume(IAaptContext* context, ResourceTable* table) override;
50};
51
Adam Lesinskifb6312f2016-06-28 14:40:32 -070052class XmlAutoVersioner : public IXmlResourceConsumer {
53public:
Adam Lesinski467f1712015-11-16 17:35:44 -080054 bool consume(IAaptContext* context, xml::XmlResource* resource) override;
Adam Lesinski1ab598f2015-08-14 14:26:04 -070055};
56
Adam Lesinskifb6312f2016-06-28 14:40:32 -070057class VersionCollapser : public IResourceTableConsumer {
58public:
59 bool consume(IAaptContext* context, ResourceTable* table) override;
60};
61
Adam Lesinski9f222042015-11-04 13:51:45 -080062/**
Alexandria Cornwall77788eb2016-09-06 15:16:49 -070063 * Removes duplicated key-value entries from dominated resources.
64 */
65class ResourceDeduper : public IResourceTableConsumer {
66public:
67 bool consume(IAaptContext* context, ResourceTable* table) override;
68};
69
70/**
Adam Lesinski9f222042015-11-04 13:51:45 -080071 * If any attribute resource values are defined as public, this consumer will move all private
72 * attribute resource values to a private ^private-attr type, avoiding backwards compatibility
73 * issues with new apps running on old platforms.
74 *
75 * The Android platform ignores resource attributes it doesn't recognize, so an app developer can
76 * use new attributes in their layout XML files without worrying about versioning. This assumption
77 * actually breaks on older platforms. OEMs may add private attributes that are used internally.
78 * AAPT originally assigned all private attributes IDs immediately proceeding the public attributes'
79 * IDs.
80 *
81 * This means that on a newer Android platform, an ID previously assigned to a private attribute
82 * may end up assigned to a public attribute.
83 *
84 * App developers assume using the newer attribute is safe on older platforms because it will
85 * be ignored. Instead, the platform thinks the new attribute is an older, private attribute and
86 * will interpret it as such. This leads to unintended styling and exceptions thrown due to
87 * unexpected types.
88 *
89 * By moving the private attributes to a completely different type, this ID conflict will never
90 * occur.
91 */
92struct PrivateAttributeMover : public IResourceTableConsumer {
93 bool consume(IAaptContext* context, ResourceTable* table) override;
94};
95
96/**
Alexandria Cornwalla7cc3f12016-08-16 13:33:32 -070097 * Removes namespace nodes and URI information from the XmlResource.
98 *
99 * Once an XmlResource is processed by this consumer, it is no longer able to have its attributes
100 * parsed. As such, this XmlResource must have already been processed by XmlReferenceLinker.
101 */
102class XmlNamespaceRemover : public IXmlResourceConsumer {
103private:
104 bool mKeepUris;
105
106public:
107 XmlNamespaceRemover(bool keepUris = false) : mKeepUris(keepUris) {
108 };
109
110 bool consume(IAaptContext* context, xml::XmlResource* resource) override;
111};
112
113/**
Adam Lesinski9f222042015-11-04 13:51:45 -0800114 * Resolves attributes in the XmlResource and compiles string values to resource values.
115 * Once an XmlResource is processed by this linker, it is ready to be flattened.
116 */
117class XmlReferenceLinker : public IXmlResourceConsumer {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700118private:
119 std::set<int> mSdkLevelsFound;
120
121public:
Adam Lesinski467f1712015-11-16 17:35:44 -0800122 bool consume(IAaptContext* context, xml::XmlResource* resource) override;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700123
Adam Lesinski9f222042015-11-04 13:51:45 -0800124 /**
125 * Once the XmlResource has been consumed, this returns the various SDK levels in which
126 * framework attributes used within the XML document were defined.
127 */
128 inline const std::set<int>& getSdkLevels() const {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700129 return mSdkLevelsFound;
130 }
131};
132
133} // namespace aapt
134
135#endif /* AAPT_LINKER_LINKERS_H */