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