Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 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 | #ifndef AAPT_RESOURCE_TABLE_H |
| 18 | #define AAPT_RESOURCE_TABLE_H |
| 19 | |
| 20 | #include "ConfigDescription.h" |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 21 | #include "Diagnostics.h" |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 22 | #include "Resource.h" |
| 23 | #include "ResourceValues.h" |
| 24 | #include "Source.h" |
| 25 | #include "StringPool.h" |
Adam Lesinski | 355f285 | 2016-02-13 20:26:45 -0800 | [diff] [blame] | 26 | #include "io/File.h" |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 27 | |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 28 | #include "android-base/macros.h" |
| 29 | #include "androidfw/StringPiece.h" |
| 30 | |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 31 | #include <functional> |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 32 | #include <map> |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 33 | #include <memory> |
| 34 | #include <string> |
| 35 | #include <tuple> |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 36 | #include <unordered_map> |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 37 | #include <vector> |
| 38 | |
| 39 | namespace aapt { |
| 40 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 41 | // The Public status of a resource. |
| 42 | struct Visibility { |
| 43 | enum class Level { |
| 44 | kUndefined, |
| 45 | kPrivate, |
| 46 | kPublic, |
| 47 | }; |
| 48 | |
| 49 | Level level = Level::kUndefined; |
| 50 | Source source; |
| 51 | std::string comment; |
Adam Lesinski | 9e10ac7 | 2015-10-16 14:37:48 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 54 | // Represents <add-resource> in an overlay. |
| 55 | struct AllowNew { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 56 | Source source; |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 57 | std::string comment; |
| 58 | }; |
Adam Lesinski | 4488f1c | 2017-05-26 17:33:38 -0700 | [diff] [blame] | 59 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 60 | // The policy dictating whether an entry is overlayable at runtime by RROs. |
| 61 | struct Overlayable { |
| 62 | Source source; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 63 | std::string comment; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 64 | }; |
| 65 | |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 66 | class ResourceConfigValue { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 67 | public: |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 68 | // The configuration for which this value is defined. |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 69 | const ConfigDescription config; |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 70 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 71 | // The product for which this value is defined. |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 72 | const std::string product; |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 73 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 74 | // The actual Value. |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 75 | std::unique_ptr<Value> value; |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 76 | |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 77 | ResourceConfigValue(const ConfigDescription& config, const android::StringPiece& product) |
| 78 | : config(config), product(product.to_string()) {} |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 79 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 80 | private: |
| 81 | DISALLOW_COPY_AND_ASSIGN(ResourceConfigValue); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 82 | }; |
| 83 | |
Adam Lesinski | 73bff1e | 2017-12-08 16:06:10 -0800 | [diff] [blame] | 84 | // Represents a resource entry, which may have varying values for each defined configuration. |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 85 | class ResourceEntry { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 86 | public: |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 87 | // The name of the resource. Immutable, as this determines the order of this resource |
| 88 | // when doing lookups. |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 89 | const std::string name; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 90 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 91 | // The entry ID for this resource (the EEEE in 0xPPTTEEEE). |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 92 | Maybe<uint16_t> id; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 93 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 94 | // Whether this resource is public (and must maintain the same entry ID across builds). |
| 95 | Visibility visibility; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 96 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 97 | Maybe<AllowNew> allow_new; |
| 98 | |
| 99 | Maybe<Overlayable> overlayable; |
| 100 | |
| 101 | // The resource's values for each configuration. |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 102 | std::vector<std::unique_ptr<ResourceConfigValue>> values; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 103 | |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 104 | explicit ResourceEntry(const android::StringPiece& name) : name(name.to_string()) {} |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 105 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 106 | ResourceConfigValue* FindValue(const ConfigDescription& config); |
Adam Lesinski | 34a1687 | 2018-02-23 16:18:10 -0800 | [diff] [blame] | 107 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 108 | ResourceConfigValue* FindValue(const ConfigDescription& config, |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 109 | const android::StringPiece& product); |
Adam Lesinski | 34a1687 | 2018-02-23 16:18:10 -0800 | [diff] [blame] | 110 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 111 | ResourceConfigValue* FindOrCreateValue(const ConfigDescription& config, |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 112 | const android::StringPiece& product); |
Adam Lesinski | b1afa07 | 2017-03-29 13:52:38 -0700 | [diff] [blame] | 113 | std::vector<ResourceConfigValue*> FindAllValues(const ConfigDescription& config); |
Adam Lesinski | 34a1687 | 2018-02-23 16:18:10 -0800 | [diff] [blame] | 114 | |
| 115 | template <typename Func> |
| 116 | std::vector<ResourceConfigValue*> FindValuesIf(Func f) { |
| 117 | std::vector<ResourceConfigValue*> results; |
| 118 | for (auto& config_value : values) { |
| 119 | if (f(config_value.get())) { |
| 120 | results.push_back(config_value.get()); |
| 121 | } |
| 122 | } |
| 123 | return results; |
| 124 | } |
| 125 | |
| 126 | bool HasDefaultValue() const; |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 127 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 128 | private: |
| 129 | DISALLOW_COPY_AND_ASSIGN(ResourceEntry); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 130 | }; |
| 131 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 132 | // Represents a resource type (eg. string, drawable, layout, etc.) containing resource entries. |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 133 | class ResourceTableType { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 134 | public: |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 135 | // The logical type of resource (string, drawable, layout, etc.). |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 136 | const ResourceType type; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 137 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 138 | // The type ID for this resource (the TT in 0xPPTTEEEE). |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 139 | Maybe<uint8_t> id; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 140 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 141 | // Whether this type is public (and must maintain the same type ID across builds). |
| 142 | Visibility::Level visibility_level = Visibility::Level::kUndefined; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 143 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 144 | // List of resources for this type. |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 145 | std::vector<std::unique_ptr<ResourceEntry>> entries; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 146 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 147 | explicit ResourceTableType(const ResourceType type) : type(type) {} |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 148 | |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 149 | ResourceEntry* FindEntry(const android::StringPiece& name); |
| 150 | ResourceEntry* FindOrCreateEntry(const android::StringPiece& name); |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 151 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 152 | private: |
| 153 | DISALLOW_COPY_AND_ASSIGN(ResourceTableType); |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 154 | }; |
| 155 | |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 156 | class ResourceTablePackage { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 157 | public: |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 158 | std::string name; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 159 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 160 | // The package ID (the PP in 0xPPTTEEEE). |
| 161 | Maybe<uint8_t> id; |
| 162 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 163 | std::vector<std::unique_ptr<ResourceTableType>> types; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 164 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 165 | ResourceTablePackage() = default; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 166 | ResourceTableType* FindType(ResourceType type); |
| 167 | ResourceTableType* FindOrCreateType(const ResourceType type); |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 168 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 169 | private: |
| 170 | DISALLOW_COPY_AND_ASSIGN(ResourceTablePackage); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 171 | }; |
| 172 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 173 | // The container and index for all resources defined for an app. |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 174 | class ResourceTable { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 175 | public: |
| 176 | ResourceTable() = default; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 177 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 178 | enum class CollisionResult { kKeepOriginal, kConflict, kTakeNew }; |
Adam Lesinski | 5c3464c | 2016-08-24 16:03:48 -0700 | [diff] [blame] | 179 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 180 | using CollisionResolverFunc = std::function<CollisionResult(Value*, Value*)>; |
Adam Lesinski | 5c3464c | 2016-08-24 16:03:48 -0700 | [diff] [blame] | 181 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 182 | // When a collision of resources occurs, this method decides which value to keep. |
Adam Lesinski | b1afa07 | 2017-03-29 13:52:38 -0700 | [diff] [blame] | 183 | static CollisionResult ResolveValueCollision(Value* existing, Value* incoming); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 184 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 185 | bool AddResource(const ResourceNameRef& name, const ConfigDescription& config, |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 186 | const android::StringPiece& product, std::unique_ptr<Value> value, |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 187 | IDiagnostics* diag); |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 188 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 189 | bool AddResourceWithId(const ResourceNameRef& name, const ResourceId& res_id, |
| 190 | const ConfigDescription& config, const android::StringPiece& product, |
| 191 | std::unique_ptr<Value> value, IDiagnostics* diag); |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 192 | |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 193 | bool AddFileReference(const ResourceNameRef& name, const ConfigDescription& config, |
| 194 | const Source& source, const android::StringPiece& path, IDiagnostics* diag); |
Adam Lesinski | fb48d29 | 2015-11-07 15:52:13 -0800 | [diff] [blame] | 195 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 196 | bool AddFileReferenceMangled(const ResourceNameRef& name, const ConfigDescription& config, |
| 197 | const Source& source, const android::StringPiece& path, |
| 198 | io::IFile* file, IDiagnostics* diag); |
Adam Lesinski | e78fd61 | 2015-10-22 12:48:43 -0700 | [diff] [blame] | 199 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 200 | // Same as AddResource, but doesn't verify the validity of the name. This is used |
| 201 | // when loading resources from an existing binary resource table that may have mangled names. |
| 202 | bool AddResourceMangled(const ResourceNameRef& name, const ConfigDescription& config, |
| 203 | const android::StringPiece& product, std::unique_ptr<Value> value, |
| 204 | IDiagnostics* diag); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 205 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 206 | bool AddResourceWithIdMangled(const ResourceNameRef& name, const ResourceId& id, |
| 207 | const ConfigDescription& config, |
| 208 | const android::StringPiece& product, std::unique_ptr<Value> value, |
| 209 | IDiagnostics* diag); |
Adam Lesinski | 769de98 | 2015-04-10 19:43:55 -0700 | [diff] [blame] | 210 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 211 | bool SetVisibility(const ResourceNameRef& name, const Visibility& visibility, IDiagnostics* diag); |
| 212 | bool SetVisibilityMangled(const ResourceNameRef& name, const Visibility& visibility, |
| 213 | IDiagnostics* diag); |
| 214 | bool SetVisibilityWithId(const ResourceNameRef& name, const Visibility& visibility, |
| 215 | const ResourceId& res_id, IDiagnostics* diag); |
| 216 | bool SetVisibilityWithIdMangled(const ResourceNameRef& name, const Visibility& visibility, |
| 217 | const ResourceId& res_id, IDiagnostics* diag); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 218 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 219 | bool SetOverlayable(const ResourceNameRef& name, const Overlayable& overlayable, |
| 220 | IDiagnostics* diag); |
| 221 | bool SetOverlayableMangled(const ResourceNameRef& name, const Overlayable& overlayable, |
| 222 | IDiagnostics* diag); |
| 223 | |
| 224 | bool SetAllowNew(const ResourceNameRef& name, const AllowNew& allow_new, IDiagnostics* diag); |
| 225 | bool SetAllowNewMangled(const ResourceNameRef& name, const AllowNew& allow_new, |
| 226 | IDiagnostics* diag); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 227 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 228 | struct SearchResult { |
| 229 | ResourceTablePackage* package; |
| 230 | ResourceTableType* type; |
| 231 | ResourceEntry* entry; |
| 232 | }; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 233 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 234 | Maybe<SearchResult> FindResource(const ResourceNameRef& name) const; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 235 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 236 | // Returns the package struct with the given name, or nullptr if such a package does not |
| 237 | // exist. The empty string is a valid package and typically is used to represent the |
| 238 | // 'current' package before it is known to the ResourceTable. |
| 239 | ResourceTablePackage* FindPackage(const android::StringPiece& name) const; |
Adam Lesinski | ceb9b2f | 2017-02-16 12:05:42 -0800 | [diff] [blame] | 240 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 241 | ResourceTablePackage* FindPackageById(uint8_t id) const; |
Adam Lesinski | ceb9b2f | 2017-02-16 12:05:42 -0800 | [diff] [blame] | 242 | |
| 243 | ResourceTablePackage* CreatePackage(const android::StringPiece& name, Maybe<uint8_t> id = {}); |
| 244 | |
David Chaloupka | e3c1a4a | 2018-01-18 13:44:36 +0000 | [diff] [blame] | 245 | // Attempts to find a package having the specified name and ID. If not found, a new package |
| 246 | // of the specified parameters is created and returned. |
| 247 | ResourceTablePackage* CreatePackageAllowingDuplicateNames(const android::StringPiece& name, |
| 248 | const Maybe<uint8_t> id); |
| 249 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 250 | std::unique_ptr<ResourceTable> Clone() const; |
| 251 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 252 | // The string pool used by this resource table. Values that reference strings must use |
| 253 | // this pool to create their strings. |
| 254 | // NOTE: `string_pool` must come before `packages` so that it is destroyed after. |
| 255 | // When `string_pool` references are destroyed (as they will be when `packages` is destroyed), |
| 256 | // they decrement a refCount, which would cause invalid memory access if the pool was already |
| 257 | // destroyed. |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 258 | StringPool string_pool; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 259 | |
David Chaloupka | e3c1a4a | 2018-01-18 13:44:36 +0000 | [diff] [blame] | 260 | // The list of packages in this table, sorted alphabetically by package name and increasing |
| 261 | // package ID (missing ID being the lowest). |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 262 | std::vector<std::unique_ptr<ResourceTablePackage>> packages; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 263 | |
Adam Lesinski | ceb9b2f | 2017-02-16 12:05:42 -0800 | [diff] [blame] | 264 | // Set of dynamic packages that this table may reference. Their package names get encoded |
| 265 | // into the resources.arsc along with their compile-time assigned IDs. |
| 266 | std::map<size_t, std::string> included_packages_; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 267 | |
| 268 | private: |
Adam Lesinski | b1afa07 | 2017-03-29 13:52:38 -0700 | [diff] [blame] | 269 | // The function type that validates a symbol name. Returns a non-empty StringPiece representing |
| 270 | // the offending character (which may be more than one byte in UTF-8). Returns an empty string |
| 271 | // if the name was valid. |
| 272 | using NameValidator = android::StringPiece(const android::StringPiece&); |
| 273 | |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 274 | ResourceTablePackage* FindOrCreatePackage(const android::StringPiece& name); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 275 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 276 | bool ValidateName(NameValidator validator, const ResourceNameRef& name, const Source& source, |
| 277 | IDiagnostics* diag); |
| 278 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 279 | bool AddResourceImpl(const ResourceNameRef& name, const ResourceId& res_id, |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 280 | const ConfigDescription& config, const android::StringPiece& product, |
Adam Lesinski | b1afa07 | 2017-03-29 13:52:38 -0700 | [diff] [blame] | 281 | std::unique_ptr<Value> value, NameValidator name_validator, |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 282 | const CollisionResolverFunc& conflict_resolver, IDiagnostics* diag); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 283 | |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 284 | bool AddFileReferenceImpl(const ResourceNameRef& name, const ConfigDescription& config, |
| 285 | const Source& source, const android::StringPiece& path, io::IFile* file, |
Adam Lesinski | b1afa07 | 2017-03-29 13:52:38 -0700 | [diff] [blame] | 286 | NameValidator name_validator, IDiagnostics* diag); |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 287 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 288 | bool SetVisibilityImpl(const ResourceNameRef& name, const Visibility& visibility, |
| 289 | const ResourceId& res_id, NameValidator name_validator, |
| 290 | IDiagnostics* diag); |
| 291 | |
| 292 | bool SetAllowNewImpl(const ResourceNameRef& name, const AllowNew& allow_new, |
| 293 | NameValidator name_validator, IDiagnostics* diag); |
| 294 | |
| 295 | bool SetOverlayableImpl(const ResourceNameRef& name, const Overlayable& overlayable, |
| 296 | NameValidator name_validator, IDiagnostics* diag); |
| 297 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 298 | bool SetSymbolStateImpl(const ResourceNameRef& name, const ResourceId& res_id, |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 299 | const Visibility& symbol, NameValidator name_validator, |
| 300 | IDiagnostics* diag); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 301 | |
| 302 | DISALLOW_COPY_AND_ASSIGN(ResourceTable); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 303 | }; |
| 304 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 305 | } // namespace aapt |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 306 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 307 | #endif // AAPT_RESOURCE_TABLE_H |