blob: f40c0e863d7226c81d9490dce98488ef46b094db [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 Lesinskicacb28f2016-10-19 12:18:14 -070033 * Defines the location in which a value exists. This determines visibility of
34 * other
Adam Lesinski467f1712015-11-16 17:35:44 -080035 * package's private symbols.
36 */
37struct CallSite {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070038 ResourceNameRef resource;
Adam Lesinski467f1712015-11-16 17:35:44 -080039};
40
41/**
Adam Lesinskicacb28f2016-10-19 12:18:14 -070042 * Determines whether a versioned resource should be created. If a versioned
43 * resource already
Adam Lesinski1ab598f2015-08-14 14:26:04 -070044 * exists, it takes precedence.
45 */
Adam Lesinskicacb28f2016-10-19 12:18:14 -070046bool shouldGenerateVersionedResource(const ResourceEntry* entry,
47 const ConfigDescription& config,
Adam Lesinski1ab598f2015-08-14 14:26:04 -070048 const int sdkVersionToGenerate);
49
Adam Lesinskifb6312f2016-06-28 14:40:32 -070050class AutoVersioner : public IResourceTableConsumer {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070051 public:
52 bool consume(IAaptContext* context, ResourceTable* table) override;
Adam Lesinski1ab598f2015-08-14 14:26:04 -070053};
54
Adam Lesinskifb6312f2016-06-28 14:40:32 -070055class XmlAutoVersioner : public IXmlResourceConsumer {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070056 public:
57 bool consume(IAaptContext* context, xml::XmlResource* resource) override;
Adam Lesinski1ab598f2015-08-14 14:26:04 -070058};
59
Adam Lesinskifb6312f2016-06-28 14:40:32 -070060class VersionCollapser : public IResourceTableConsumer {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070061 public:
62 bool consume(IAaptContext* context, ResourceTable* table) override;
Adam Lesinskifb6312f2016-06-28 14:40:32 -070063};
64
Adam Lesinski9f222042015-11-04 13:51:45 -080065/**
Alexandria Cornwall77788eb2016-09-06 15:16:49 -070066 * Removes duplicated key-value entries from dominated resources.
67 */
68class ResourceDeduper : public IResourceTableConsumer {
Adam Lesinskicacb28f2016-10-19 12:18:14 -070069 public:
70 bool consume(IAaptContext* context, ResourceTable* table) override;
Alexandria Cornwall77788eb2016-09-06 15:16:49 -070071};
72
73/**
Adam Lesinskicacb28f2016-10-19 12:18:14 -070074 * If any attribute resource values are defined as public, this consumer will
75 * move all private
76 * attribute resource values to a private ^private-attr type, avoiding backwards
77 * compatibility
Adam Lesinski9f222042015-11-04 13:51:45 -080078 * issues with new apps running on old platforms.
79 *
Adam Lesinskicacb28f2016-10-19 12:18:14 -070080 * The Android platform ignores resource attributes it doesn't recognize, so an
81 * app developer can
82 * use new attributes in their layout XML files without worrying about
83 * versioning. This assumption
84 * actually breaks on older platforms. OEMs may add private attributes that are
85 * used internally.
86 * AAPT originally assigned all private attributes IDs immediately proceeding
87 * the public attributes'
Adam Lesinski9f222042015-11-04 13:51:45 -080088 * IDs.
89 *
Adam Lesinskicacb28f2016-10-19 12:18:14 -070090 * This means that on a newer Android platform, an ID previously assigned to a
91 * private attribute
Adam Lesinski9f222042015-11-04 13:51:45 -080092 * may end up assigned to a public attribute.
93 *
Adam Lesinskicacb28f2016-10-19 12:18:14 -070094 * App developers assume using the newer attribute is safe on older platforms
95 * because it will
96 * be ignored. Instead, the platform thinks the new attribute is an older,
97 * private attribute and
98 * will interpret it as such. This leads to unintended styling and exceptions
99 * thrown due to
Adam Lesinski9f222042015-11-04 13:51:45 -0800100 * unexpected types.
101 *
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700102 * By moving the private attributes to a completely different type, this ID
103 * conflict will never
Adam Lesinski9f222042015-11-04 13:51:45 -0800104 * occur.
105 */
106struct PrivateAttributeMover : public IResourceTableConsumer {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700107 bool consume(IAaptContext* context, ResourceTable* table) override;
Adam Lesinski9f222042015-11-04 13:51:45 -0800108};
109
110/**
Alexandria Cornwalla7cc3f12016-08-16 13:33:32 -0700111 * Removes namespace nodes and URI information from the XmlResource.
112 *
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700113 * Once an XmlResource is processed by this consumer, it is no longer able to
114 * have its attributes
115 * parsed. As such, this XmlResource must have already been processed by
116 * XmlReferenceLinker.
Alexandria Cornwalla7cc3f12016-08-16 13:33:32 -0700117 */
118class XmlNamespaceRemover : public IXmlResourceConsumer {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700119 private:
120 bool mKeepUris;
Alexandria Cornwalla7cc3f12016-08-16 13:33:32 -0700121
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700122 public:
123 XmlNamespaceRemover(bool keepUris = false) : mKeepUris(keepUris){};
Alexandria Cornwalla7cc3f12016-08-16 13:33:32 -0700124
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700125 bool consume(IAaptContext* context, xml::XmlResource* resource) override;
Alexandria Cornwalla7cc3f12016-08-16 13:33:32 -0700126};
127
128/**
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700129 * Resolves attributes in the XmlResource and compiles string values to resource
130 * values.
Adam Lesinski9f222042015-11-04 13:51:45 -0800131 * Once an XmlResource is processed by this linker, it is ready to be flattened.
132 */
133class XmlReferenceLinker : public IXmlResourceConsumer {
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700134 private:
135 std::set<int> mSdkLevelsFound;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700136
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700137 public:
138 bool consume(IAaptContext* context, xml::XmlResource* resource) override;
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700139
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700140 /**
141 * Once the XmlResource has been consumed, this returns the various SDK levels
142 * in which
143 * framework attributes used within the XML document were defined.
144 */
145 inline const std::set<int>& getSdkLevels() const { return mSdkLevelsFound; }
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700146};
147
Adam Lesinskicacb28f2016-10-19 12:18:14 -0700148} // namespace aapt
Adam Lesinski1ab598f2015-08-14 14:26:04 -0700149
150#endif /* AAPT_LINKER_LINKERS_H */