blob: 82e28682f78e496992d9d9878cbba91fd9096ea0 [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/**
63 * If any attribute resource values are defined as public, this consumer will move all private
64 * attribute resource values to a private ^private-attr type, avoiding backwards compatibility
65 * issues with new apps running on old platforms.
66 *
67 * The Android platform ignores resource attributes it doesn't recognize, so an app developer can
68 * use new attributes in their layout XML files without worrying about versioning. This assumption
69 * actually breaks on older platforms. OEMs may add private attributes that are used internally.
70 * AAPT originally assigned all private attributes IDs immediately proceeding the public attributes'
71 * IDs.
72 *
73 * This means that on a newer Android platform, an ID previously assigned to a private attribute
74 * may end up assigned to a public attribute.
75 *
76 * App developers assume using the newer attribute is safe on older platforms because it will
77 * be ignored. Instead, the platform thinks the new attribute is an older, private attribute and
78 * will interpret it as such. This leads to unintended styling and exceptions thrown due to
79 * unexpected types.
80 *
81 * By moving the private attributes to a completely different type, this ID conflict will never
82 * occur.
83 */
84struct PrivateAttributeMover : public IResourceTableConsumer {
85 bool consume(IAaptContext* context, ResourceTable* table) override;
86};
87
88/**
Alexandria Cornwalla7cc3f12016-08-16 13:33:32 -070089 * Removes namespace nodes and URI information from the XmlResource.
90 *
91 * Once an XmlResource is processed by this consumer, it is no longer able to have its attributes
92 * parsed. As such, this XmlResource must have already been processed by XmlReferenceLinker.
93 */
94class XmlNamespaceRemover : public IXmlResourceConsumer {
95private:
96 bool mKeepUris;
97
98public:
99 XmlNamespaceRemover(bool keepUris = false) : mKeepUris(keepUris) {
100 };
101
102 bool consume(IAaptContext* context, xml::XmlResource* resource) override;
103};
104
105/**
Adam Lesinski9f222042015-11-04 13:51:45 -0800106 * Resolves attributes in the XmlResource and compiles string values to resource values.
107 * Once an XmlResource is processed by this linker, it is ready to be flattened.
108 */
109class XmlReferenceLinker : public IXmlResourceConsumer {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700110private:
111 std::set<int> mSdkLevelsFound;
112
113public:
Adam Lesinski467f1712015-11-16 17:35:44 -0800114 bool consume(IAaptContext* context, xml::XmlResource* resource) override;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700115
Adam Lesinski9f222042015-11-04 13:51:45 -0800116 /**
117 * Once the XmlResource has been consumed, this returns the various SDK levels in which
118 * framework attributes used within the XML document were defined.
119 */
120 inline const std::set<int>& getSdkLevels() const {
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700121 return mSdkLevelsFound;
122 }
123};
124
125} // namespace aapt
126
127#endif /* AAPT_LINKER_LINKERS_H */