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 | |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 20 | #include "Diagnostics.h" |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 21 | #include "Resource.h" |
| 22 | #include "ResourceValues.h" |
| 23 | #include "Source.h" |
| 24 | #include "StringPool.h" |
Adam Lesinski | 355f285 | 2016-02-13 20:26:45 -0800 | [diff] [blame] | 25 | #include "io/File.h" |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 26 | |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 27 | #include "android-base/macros.h" |
Mårten Kongstad | 24c9aa6 | 2018-06-20 08:46:41 +0200 | [diff] [blame] | 28 | #include "androidfw/ConfigDescription.h" |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 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 | |
Winson | 62ac8b5 | 2019-12-04 08:36:48 -0800 | [diff] [blame] | 39 | using PolicyFlags = android::ResTable_overlayable_policy_header::PolicyFlags; |
| 40 | |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 41 | namespace aapt { |
| 42 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 43 | // The Public status of a resource. |
| 44 | struct Visibility { |
| 45 | enum class Level { |
| 46 | kUndefined, |
| 47 | kPrivate, |
| 48 | kPublic, |
| 49 | }; |
| 50 | |
| 51 | Level level = Level::kUndefined; |
| 52 | Source source; |
| 53 | std::string comment; |
Adam Lesinski | 9e10ac7 | 2015-10-16 14:37:48 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 56 | // Represents <add-resource> in an overlay. |
| 57 | struct AllowNew { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 58 | Source source; |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 59 | std::string comment; |
| 60 | }; |
Adam Lesinski | 4488f1c | 2017-05-26 17:33:38 -0700 | [diff] [blame] | 61 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 62 | struct Overlayable { |
Ryan Mitchell | 54237ff | 2018-12-13 15:44:29 -0800 | [diff] [blame] | 63 | Overlayable() = default; |
| 64 | Overlayable(const android::StringPiece& name, const android::StringPiece& actor) |
| 65 | : name(name.to_string()), actor(actor.to_string()) {} |
| 66 | Overlayable(const android::StringPiece& name, const android::StringPiece& actor, |
| 67 | const Source& source) |
| 68 | : name(name.to_string()), actor(actor.to_string()), source(source ){} |
| 69 | |
| 70 | static const char* kActorScheme; |
| 71 | std::string name; |
| 72 | std::string actor; |
| 73 | Source source; |
| 74 | }; |
| 75 | |
| 76 | // Represents a declaration that a resource is overlayable at runtime. |
| 77 | struct OverlayableItem { |
| 78 | explicit OverlayableItem(const std::shared_ptr<Overlayable>& overlayable) |
| 79 | : overlayable(overlayable) {} |
Ryan Mitchell | 54237ff | 2018-12-13 15:44:29 -0800 | [diff] [blame] | 80 | std::shared_ptr<Overlayable> overlayable; |
Winson | 62ac8b5 | 2019-12-04 08:36:48 -0800 | [diff] [blame] | 81 | PolicyFlags policies = PolicyFlags::NONE; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 82 | std::string comment; |
Ryan Mitchell | 54237ff | 2018-12-13 15:44:29 -0800 | [diff] [blame] | 83 | Source source; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 84 | }; |
| 85 | |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 86 | class ResourceConfigValue { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 87 | public: |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 88 | // The configuration for which this value is defined. |
Mårten Kongstad | 24c9aa6 | 2018-06-20 08:46:41 +0200 | [diff] [blame] | 89 | const android::ConfigDescription config; |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 90 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 91 | // The product for which this value is defined. |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 92 | const std::string product; |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 93 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 94 | // The actual Value. |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 95 | std::unique_ptr<Value> value; |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 96 | |
Mårten Kongstad | 24c9aa6 | 2018-06-20 08:46:41 +0200 | [diff] [blame] | 97 | ResourceConfigValue(const android::ConfigDescription& config, const android::StringPiece& product) |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 98 | : config(config), product(product.to_string()) {} |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 99 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 100 | private: |
| 101 | DISALLOW_COPY_AND_ASSIGN(ResourceConfigValue); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 102 | }; |
| 103 | |
Adam Lesinski | 73bff1e | 2017-12-08 16:06:10 -0800 | [diff] [blame] | 104 | // 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] | 105 | class ResourceEntry { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 106 | public: |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 107 | // The name of the resource. Immutable, as this determines the order of this resource |
| 108 | // when doing lookups. |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 109 | const std::string name; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 110 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 111 | // The entry ID for this resource (the EEEE in 0xPPTTEEEE). |
Ryan Mitchell | 9634efb | 2021-03-19 14:53:17 -0700 | [diff] [blame^] | 112 | Maybe<ResourceId> id; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 113 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 114 | // Whether this resource is public (and must maintain the same entry ID across builds). |
| 115 | Visibility visibility; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 116 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 117 | Maybe<AllowNew> allow_new; |
| 118 | |
Ryan Mitchell | e4e989c | 2018-10-29 02:21:50 -0700 | [diff] [blame] | 119 | // The declarations of this resource as overlayable for RROs |
Ryan Mitchell | 54237ff | 2018-12-13 15:44:29 -0800 | [diff] [blame] | 120 | Maybe<OverlayableItem> overlayable_item; |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 121 | |
| 122 | // The resource's values for each configuration. |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 123 | std::vector<std::unique_ptr<ResourceConfigValue>> values; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 124 | |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 125 | explicit ResourceEntry(const android::StringPiece& name) : name(name.to_string()) {} |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 126 | |
Mårten Kongstad | 24c9aa6 | 2018-06-20 08:46:41 +0200 | [diff] [blame] | 127 | ResourceConfigValue* FindValue(const android::ConfigDescription& config, |
Ryan Mitchell | 9634efb | 2021-03-19 14:53:17 -0700 | [diff] [blame^] | 128 | android::StringPiece product = {}); |
| 129 | const ResourceConfigValue* FindValue(const android::ConfigDescription& config, |
| 130 | android::StringPiece product = {}) const; |
Adam Lesinski | 34a1687 | 2018-02-23 16:18:10 -0800 | [diff] [blame] | 131 | |
Mårten Kongstad | 24c9aa6 | 2018-06-20 08:46:41 +0200 | [diff] [blame] | 132 | ResourceConfigValue* FindOrCreateValue(const android::ConfigDescription& config, |
Adam Lesinski | d5083f6 | 2017-01-16 15:07:21 -0800 | [diff] [blame] | 133 | const android::StringPiece& product); |
Mårten Kongstad | 24c9aa6 | 2018-06-20 08:46:41 +0200 | [diff] [blame] | 134 | std::vector<ResourceConfigValue*> FindAllValues(const android::ConfigDescription& config); |
Adam Lesinski | 34a1687 | 2018-02-23 16:18:10 -0800 | [diff] [blame] | 135 | |
| 136 | template <typename Func> |
| 137 | std::vector<ResourceConfigValue*> FindValuesIf(Func f) { |
| 138 | std::vector<ResourceConfigValue*> results; |
| 139 | for (auto& config_value : values) { |
| 140 | if (f(config_value.get())) { |
| 141 | results.push_back(config_value.get()); |
| 142 | } |
| 143 | } |
| 144 | return results; |
| 145 | } |
| 146 | |
| 147 | bool HasDefaultValue() const; |
Adam Lesinski | 458b877 | 2016-04-25 14:20:21 -0700 | [diff] [blame] | 148 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 149 | private: |
| 150 | DISALLOW_COPY_AND_ASSIGN(ResourceEntry); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 151 | }; |
| 152 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 153 | // Represents a resource type (eg. string, drawable, layout, etc.) containing resource entries. |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 154 | class ResourceTableType { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 155 | public: |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 156 | // The logical type of resource (string, drawable, layout, etc.). |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 157 | const ResourceType type; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 158 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 159 | // Whether this type is public (and must maintain the same type ID across builds). |
| 160 | Visibility::Level visibility_level = Visibility::Level::kUndefined; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 161 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 162 | // List of resources for this type. |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 163 | std::vector<std::unique_ptr<ResourceEntry>> entries; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 164 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 165 | explicit ResourceTableType(const ResourceType type) : type(type) {} |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 166 | |
Ryan Mitchell | 9634efb | 2021-03-19 14:53:17 -0700 | [diff] [blame^] | 167 | ResourceEntry* CreateEntry(const android::StringPiece& name); |
| 168 | ResourceEntry* FindEntry(const android::StringPiece& name) const; |
| 169 | ResourceEntry* FindOrCreateEntry(const android::StringPiece& name); |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 170 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 171 | private: |
| 172 | DISALLOW_COPY_AND_ASSIGN(ResourceTableType); |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 173 | }; |
| 174 | |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 175 | class ResourceTablePackage { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 176 | public: |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 177 | std::string name; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 178 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 179 | std::vector<std::unique_ptr<ResourceTableType>> types; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 180 | |
Ryan Mitchell | 9634efb | 2021-03-19 14:53:17 -0700 | [diff] [blame^] | 181 | explicit ResourceTablePackage(const android::StringPiece& name) : name(name.to_string()) { |
| 182 | } |
| 183 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 184 | ResourceTablePackage() = default; |
Ryan Mitchell | 9634efb | 2021-03-19 14:53:17 -0700 | [diff] [blame^] | 185 | ResourceTableType* FindType(ResourceType type) const; |
| 186 | ResourceTableType* FindOrCreateType(ResourceType type); |
Adam Lesinski | e4bb9eb | 2016-02-12 22:18:51 -0800 | [diff] [blame] | 187 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 188 | private: |
| 189 | DISALLOW_COPY_AND_ASSIGN(ResourceTablePackage); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 190 | }; |
| 191 | |
Ryan Mitchell | 9634efb | 2021-03-19 14:53:17 -0700 | [diff] [blame^] | 192 | struct ResourceTableTypeView { |
| 193 | ResourceType type; |
| 194 | Maybe<uint8_t> id; |
| 195 | Visibility::Level visibility_level = Visibility::Level::kUndefined; |
| 196 | |
| 197 | // Entries sorted in ascending entry id order. If ids have not been assigned, the entries are |
| 198 | // // sorted lexicographically. |
| 199 | std::vector<const ResourceEntry*> entries; |
| 200 | }; |
| 201 | |
| 202 | struct ResourceTablePackageView { |
| 203 | std::string name; |
| 204 | Maybe<uint8_t> id; |
| 205 | // Types sorted in ascending type id order. If ids have not been assigned, the types are sorted by |
| 206 | // their declaration order in the ResourceType enum. |
| 207 | std::vector<ResourceTableTypeView> types; |
| 208 | }; |
| 209 | |
| 210 | struct ResourceTableView { |
| 211 | // Packages sorted in ascending package id order. If ids have not been assigned, the packages are |
| 212 | // sorted lexicographically. |
| 213 | std::vector<ResourceTablePackageView> packages; |
| 214 | }; |
| 215 | |
| 216 | enum class OnIdConflict { |
| 217 | // If the resource entry already exists but has a different resource id, the resource value will |
| 218 | // not be added to the table. |
| 219 | ERROR, |
| 220 | |
| 221 | // If the resource entry already exists but has a different resource id, create a new resource |
| 222 | // with this resource name and id combination. |
| 223 | CREATE_ENTRY, |
| 224 | }; |
| 225 | |
| 226 | struct NewResource { |
| 227 | ResourceName name; |
| 228 | std::unique_ptr<Value> value; |
| 229 | android::ConfigDescription config; |
| 230 | std::string product; |
| 231 | std::optional<std::pair<ResourceId, OnIdConflict>> id; |
| 232 | std::optional<Visibility> visibility; |
| 233 | std::optional<OverlayableItem> overlayable; |
| 234 | std::optional<AllowNew> allow_new; |
| 235 | bool allow_mangled = false; |
| 236 | }; |
| 237 | |
| 238 | struct NewResourceBuilder { |
| 239 | explicit NewResourceBuilder(const ResourceNameRef& name); |
| 240 | explicit NewResourceBuilder(const std::string& name); |
| 241 | NewResourceBuilder& SetValue(std::unique_ptr<Value> value, android::ConfigDescription config = {}, |
| 242 | std::string product = {}); |
| 243 | NewResourceBuilder& SetId(ResourceId id, OnIdConflict on_conflict = OnIdConflict::ERROR); |
| 244 | NewResourceBuilder& SetVisibility(Visibility id); |
| 245 | NewResourceBuilder& SetOverlayable(OverlayableItem overlayable); |
| 246 | NewResourceBuilder& SetAllowNew(AllowNew allow_new); |
| 247 | NewResourceBuilder& SetAllowMangled(bool allow_mangled); |
| 248 | NewResource Build(); |
| 249 | |
| 250 | private: |
| 251 | NewResource res_; |
| 252 | }; |
| 253 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 254 | // The container and index for all resources defined for an app. |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 255 | class ResourceTable { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 256 | public: |
Ryan Mitchell | 9634efb | 2021-03-19 14:53:17 -0700 | [diff] [blame^] | 257 | enum class Validation { |
| 258 | kEnabled, |
| 259 | kDisabled, |
| 260 | }; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 261 | |
Ryan Mitchell | 83a37ad | 2018-08-06 16:32:24 -0700 | [diff] [blame] | 262 | enum class CollisionResult { kKeepBoth, kKeepOriginal, kConflict, kTakeNew }; |
Adam Lesinski | 5c3464c | 2016-08-24 16:03:48 -0700 | [diff] [blame] | 263 | |
Ryan Mitchell | 9634efb | 2021-03-19 14:53:17 -0700 | [diff] [blame^] | 264 | ResourceTable() = default; |
| 265 | explicit ResourceTable(Validation validation); |
Adam Lesinski | 5c3464c | 2016-08-24 16:03:48 -0700 | [diff] [blame] | 266 | |
Ryan Mitchell | 9634efb | 2021-03-19 14:53:17 -0700 | [diff] [blame^] | 267 | bool AddResource(NewResource&& res, IDiagnostics* diag); |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 268 | |
Ryan Mitchell | 9634efb | 2021-03-19 14:53:17 -0700 | [diff] [blame^] | 269 | // Retrieves a sorted a view of the packages, types, and entries sorted in ascending resource id |
| 270 | // order. |
| 271 | ResourceTableView GetPartitionedView() const; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 272 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 273 | struct SearchResult { |
| 274 | ResourceTablePackage* package; |
| 275 | ResourceTableType* type; |
| 276 | ResourceEntry* entry; |
| 277 | }; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 278 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 279 | Maybe<SearchResult> FindResource(const ResourceNameRef& name) const; |
Ryan Mitchell | 9634efb | 2021-03-19 14:53:17 -0700 | [diff] [blame^] | 280 | Maybe<SearchResult> FindResource(const ResourceNameRef& name, ResourceId id) const; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 281 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 282 | // Returns the package struct with the given name, or nullptr if such a package does not |
| 283 | // exist. The empty string is a valid package and typically is used to represent the |
| 284 | // 'current' package before it is known to the ResourceTable. |
| 285 | ResourceTablePackage* FindPackage(const android::StringPiece& name) const; |
Ryan Mitchell | 9634efb | 2021-03-19 14:53:17 -0700 | [diff] [blame^] | 286 | ResourceTablePackage* FindOrCreatePackage(const android::StringPiece& name); |
David Chaloupka | e3c1a4a | 2018-01-18 13:44:36 +0000 | [diff] [blame] | 287 | |
Shane Farmer | 0a5b201 | 2017-06-22 12:24:12 -0700 | [diff] [blame] | 288 | std::unique_ptr<ResourceTable> Clone() const; |
| 289 | |
Ryan Mitchell | 9634efb | 2021-03-19 14:53:17 -0700 | [diff] [blame^] | 290 | // When a collision of resources occurs, this method decides which value to keep. |
| 291 | static CollisionResult ResolveValueCollision(Value* existing, Value* incoming); |
| 292 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 293 | // The string pool used by this resource table. Values that reference strings must use |
| 294 | // this pool to create their strings. |
| 295 | // NOTE: `string_pool` must come before `packages` so that it is destroyed after. |
| 296 | // When `string_pool` references are destroyed (as they will be when `packages` is destroyed), |
| 297 | // they decrement a refCount, which would cause invalid memory access if the pool was already |
| 298 | // destroyed. |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 299 | StringPool string_pool; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 300 | |
David Chaloupka | e3c1a4a | 2018-01-18 13:44:36 +0000 | [diff] [blame] | 301 | // The list of packages in this table, sorted alphabetically by package name and increasing |
| 302 | // package ID (missing ID being the lowest). |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 303 | std::vector<std::unique_ptr<ResourceTablePackage>> packages; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 304 | |
Adam Lesinski | ceb9b2f | 2017-02-16 12:05:42 -0800 | [diff] [blame] | 305 | // Set of dynamic packages that this table may reference. Their package names get encoded |
| 306 | // into the resources.arsc along with their compile-time assigned IDs. |
| 307 | std::map<size_t, std::string> included_packages_; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 308 | |
| 309 | private: |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 310 | DISALLOW_COPY_AND_ASSIGN(ResourceTable); |
Ryan Mitchell | 9634efb | 2021-03-19 14:53:17 -0700 | [diff] [blame^] | 311 | |
| 312 | Validation validation_ = Validation::kEnabled; |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 313 | }; |
| 314 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 315 | } // namespace aapt |
Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame] | 316 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 317 | #endif // AAPT_RESOURCE_TABLE_H |