Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [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 | #include "Debug.h" |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 18 | |
| 19 | #include <algorithm> |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 20 | #include <map> |
| 21 | #include <memory> |
Adam Lesinski | d13fb24 | 2015-05-12 20:40:48 -0700 | [diff] [blame] | 22 | #include <queue> |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 23 | #include <set> |
| 24 | #include <vector> |
| 25 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 26 | #include "android-base/logging.h" |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 27 | #include "android-base/stringprintf.h" |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 28 | |
| 29 | #include "ResourceTable.h" |
| 30 | #include "ResourceValues.h" |
| 31 | #include "ValueVisitor.h" |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 32 | #include "text/Printer.h" |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 33 | #include "util/Util.h" |
| 34 | |
Winson | 62ac8b5 | 2019-12-04 08:36:48 -0800 | [diff] [blame] | 35 | #include "idmap2/Policies.h" |
| 36 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 37 | using ::aapt::text::Printer; |
| 38 | using ::android::StringPiece; |
| 39 | using ::android::base::StringPrintf; |
| 40 | |
Winson | 62ac8b5 | 2019-12-04 08:36:48 -0800 | [diff] [blame] | 41 | using android::idmap2::policy::kPolicyStringToFlag; |
| 42 | |
| 43 | using PolicyFlags = android::ResTable_overlayable_policy_header::PolicyFlags; |
| 44 | |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 45 | namespace aapt { |
| 46 | |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 47 | namespace { |
| 48 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 49 | class ValueHeadlinePrinter : public ConstValueVisitor { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 50 | public: |
Adam Lesinski | e59f0d8 | 2017-10-13 09:36:53 -0700 | [diff] [blame] | 51 | using ConstValueVisitor::Visit; |
Adam Lesinski | 1ab598f | 2015-08-14 14:26:04 -0700 | [diff] [blame] | 52 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 53 | explicit ValueHeadlinePrinter(const std::string& package, Printer* printer) |
| 54 | : package_(package), printer_(printer) { |
| 55 | } |
| 56 | |
Adam Lesinski | e59f0d8 | 2017-10-13 09:36:53 -0700 | [diff] [blame] | 57 | void Visit(const Attribute* attr) override { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 58 | printer_->Print("(attr) type="); |
| 59 | printer_->Print(attr->MaskString()); |
| 60 | if (!attr->symbols.empty()) { |
| 61 | printer_->Print(StringPrintf(" size=%zd", attr->symbols.size())); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | void Visit(const Style* style) override { |
| 66 | printer_->Print(StringPrintf("(style) size=%zd", style->entries.size())); |
| 67 | if (style->parent) { |
| 68 | printer_->Print(" parent="); |
| 69 | |
| 70 | const Reference& parent_ref = style->parent.value(); |
| 71 | if (parent_ref.name) { |
| 72 | if (parent_ref.private_reference) { |
| 73 | printer_->Print("*"); |
| 74 | } |
| 75 | |
| 76 | const ResourceName& parent_name = parent_ref.name.value(); |
| 77 | if (package_ != parent_name.package) { |
| 78 | printer_->Print(parent_name.package); |
| 79 | printer_->Print(":"); |
| 80 | } |
| 81 | printer_->Print(to_string(parent_name.type)); |
| 82 | printer_->Print("/"); |
| 83 | printer_->Print(parent_name.entry); |
| 84 | if (parent_ref.id) { |
| 85 | printer_->Print(" ("); |
| 86 | printer_->Print(parent_ref.id.value().to_string()); |
| 87 | printer_->Print(")"); |
| 88 | } |
| 89 | } else if (parent_ref.id) { |
| 90 | printer_->Print(parent_ref.id.value().to_string()); |
| 91 | } else { |
| 92 | printer_->Print("???"); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | void Visit(const Array* array) override { |
| 98 | printer_->Print(StringPrintf("(array) size=%zd", array->elements.size())); |
| 99 | } |
| 100 | |
| 101 | void Visit(const Plural* plural) override { |
| 102 | size_t count = std::count_if(plural->values.begin(), plural->values.end(), |
| 103 | [](const std::unique_ptr<Item>& v) { return v != nullptr; }); |
| 104 | printer_->Print(StringPrintf("(plurals) size=%zd", count)); |
| 105 | } |
| 106 | |
| 107 | void Visit(const Styleable* styleable) override { |
| 108 | printer_->Println(StringPrintf("(styleable) size=%zd", styleable->entries.size())); |
| 109 | } |
| 110 | |
| 111 | void VisitItem(const Item* item) override { |
| 112 | // Pretty much guaranteed to be one line. |
| 113 | if (const Reference* ref = ValueCast<Reference>(item)) { |
| 114 | // Special case Reference so that we can print local resources without a package name. |
| 115 | ref->PrettyPrint(package_, printer_); |
| 116 | } else { |
| 117 | item->PrettyPrint(printer_); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | private: |
| 122 | std::string package_; |
| 123 | Printer* printer_; |
| 124 | }; |
| 125 | |
| 126 | class ValueBodyPrinter : public ConstValueVisitor { |
| 127 | public: |
| 128 | using ConstValueVisitor::Visit; |
| 129 | |
| 130 | explicit ValueBodyPrinter(const std::string& package, Printer* printer) |
| 131 | : package_(package), printer_(printer) { |
| 132 | } |
| 133 | |
| 134 | void Visit(const Attribute* attr) override { |
| 135 | constexpr uint32_t kMask = android::ResTable_map::TYPE_ENUM | android::ResTable_map::TYPE_FLAGS; |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 136 | if (attr->type_mask & kMask) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 137 | for (const auto& symbol : attr->symbols) { |
Ryan Mitchell | 0c0cedf | 2019-04-15 16:47:58 -0700 | [diff] [blame] | 138 | if (symbol.symbol.name) { |
| 139 | printer_->Print(symbol.symbol.name.value().entry); |
| 140 | |
| 141 | if (symbol.symbol.id) { |
| 142 | printer_->Print("("); |
| 143 | printer_->Print(symbol.symbol.id.value().to_string()); |
| 144 | printer_->Print(")"); |
| 145 | } |
| 146 | } else if (symbol.symbol.id) { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 147 | printer_->Print(symbol.symbol.id.value().to_string()); |
Ryan Mitchell | 0c0cedf | 2019-04-15 16:47:58 -0700 | [diff] [blame] | 148 | } else { |
| 149 | printer_->Print("???"); |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 150 | } |
Ryan Mitchell | 0c0cedf | 2019-04-15 16:47:58 -0700 | [diff] [blame] | 151 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 152 | printer_->Println(StringPrintf("=0x%08x", symbol.value)); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 153 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 154 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 155 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 156 | |
Adam Lesinski | e59f0d8 | 2017-10-13 09:36:53 -0700 | [diff] [blame] | 157 | void Visit(const Style* style) override { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 158 | for (const auto& entry : style->entries) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 159 | if (entry.key.name) { |
| 160 | const ResourceName& name = entry.key.name.value(); |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 161 | if (!name.package.empty() && name.package != package_) { |
| 162 | printer_->Print(name.package); |
| 163 | printer_->Print(":"); |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 164 | } |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 165 | printer_->Print(name.entry); |
| 166 | |
| 167 | if (entry.key.id) { |
| 168 | printer_->Print("("); |
| 169 | printer_->Print(entry.key.id.value().to_string()); |
| 170 | printer_->Print(")"); |
| 171 | } |
| 172 | } else if (entry.key.id) { |
| 173 | printer_->Print(entry.key.id.value().to_string()); |
| 174 | } else { |
| 175 | printer_->Print("???"); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 178 | printer_->Print("="); |
| 179 | PrintItem(*entry.value); |
| 180 | printer_->Println(); |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 181 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 182 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 183 | |
Adam Lesinski | e59f0d8 | 2017-10-13 09:36:53 -0700 | [diff] [blame] | 184 | void Visit(const Array* array) override { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 185 | const size_t count = array->elements.size(); |
| 186 | printer_->Print("["); |
Donald Chai | 42fe2b2 | 2019-05-07 20:03:27 -0700 | [diff] [blame] | 187 | for (size_t i = 0u; i < count; i++) { |
| 188 | if (i != 0u && i % 4u == 0u) { |
| 189 | printer_->Println(); |
| 190 | printer_->Print(" "); |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 191 | } |
Donald Chai | 42fe2b2 | 2019-05-07 20:03:27 -0700 | [diff] [blame] | 192 | PrintItem(*array->elements[i]); |
| 193 | if (i != count - 1) { |
| 194 | printer_->Print(", "); |
| 195 | } |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 196 | } |
Donald Chai | 42fe2b2 | 2019-05-07 20:03:27 -0700 | [diff] [blame] | 197 | printer_->Println("]"); |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 198 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 199 | |
Adam Lesinski | e59f0d8 | 2017-10-13 09:36:53 -0700 | [diff] [blame] | 200 | void Visit(const Plural* plural) override { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 201 | constexpr std::array<const char*, Plural::Count> kPluralNames = { |
| 202 | {"zero", "one", "two", "few", "many", "other"}}; |
| 203 | |
| 204 | for (size_t i = 0; i < Plural::Count; i++) { |
| 205 | if (plural->values[i] != nullptr) { |
| 206 | printer_->Print(StringPrintf("%s=", kPluralNames[i])); |
| 207 | PrintItem(*plural->values[i]); |
| 208 | printer_->Println(); |
| 209 | } |
| 210 | } |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 211 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 212 | |
Adam Lesinski | e59f0d8 | 2017-10-13 09:36:53 -0700 | [diff] [blame] | 213 | void Visit(const Styleable* styleable) override { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 214 | for (const auto& attr : styleable->entries) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 215 | if (attr.name) { |
| 216 | const ResourceName& name = attr.name.value(); |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 217 | if (!name.package.empty() && name.package != package_) { |
| 218 | printer_->Print(name.package); |
| 219 | printer_->Print(":"); |
Adam Lesinski | 355f285 | 2016-02-13 20:26:45 -0800 | [diff] [blame] | 220 | } |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 221 | printer_->Print(name.entry); |
| 222 | |
| 223 | if (attr.id) { |
| 224 | printer_->Print("("); |
| 225 | printer_->Print(attr.id.value().to_string()); |
| 226 | printer_->Print(")"); |
| 227 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 228 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 229 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 230 | if (attr.id) { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 231 | printer_->Print(attr.id.value().to_string()); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 232 | } |
Adam Lesinski | 5a217b0 | 2017-11-16 16:58:02 -0800 | [diff] [blame] | 233 | printer_->Println(); |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 234 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 235 | } |
| 236 | |
Adam Lesinski | e59f0d8 | 2017-10-13 09:36:53 -0700 | [diff] [blame] | 237 | void VisitItem(const Item* item) override { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 238 | // Intentionally left empty, we already printed the Items. |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 239 | } |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 240 | |
| 241 | private: |
| 242 | void PrintItem(const Item& item) { |
| 243 | if (const Reference* ref = ValueCast<Reference>(&item)) { |
| 244 | // Special case Reference so that we can print local resources without a package name. |
| 245 | ref->PrettyPrint(package_, printer_); |
| 246 | } else { |
| 247 | item.PrettyPrint(printer_); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | std::string package_; |
| 252 | Printer* printer_; |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 253 | }; |
| 254 | |
Winson | 62ac8b5 | 2019-12-04 08:36:48 -0800 | [diff] [blame] | 255 | std::string OverlayablePoliciesToString(PolicyFlags policies) { |
MÃ¥rten Kongstad | 1d3b6485 | 2019-09-17 13:02:32 +0200 | [diff] [blame] | 256 | std::string str; |
Winson | 62ac8b5 | 2019-12-04 08:36:48 -0800 | [diff] [blame] | 257 | |
| 258 | uint32_t remaining = policies; |
| 259 | for (auto const& policy : kPolicyStringToFlag) { |
| 260 | if ((policies & policy.second) != policy.second) { |
MÃ¥rten Kongstad | 1d3b6485 | 2019-09-17 13:02:32 +0200 | [diff] [blame] | 261 | continue; |
| 262 | } |
| 263 | if (!str.empty()) { |
| 264 | str.append("|"); |
| 265 | } |
Winson | 62ac8b5 | 2019-12-04 08:36:48 -0800 | [diff] [blame] | 266 | str.append(policy.first.data()); |
| 267 | remaining &= ~policy.second; |
MÃ¥rten Kongstad | 1d3b6485 | 2019-09-17 13:02:32 +0200 | [diff] [blame] | 268 | } |
Winson | 62ac8b5 | 2019-12-04 08:36:48 -0800 | [diff] [blame] | 269 | if (remaining != 0) { |
MÃ¥rten Kongstad | 1d3b6485 | 2019-09-17 13:02:32 +0200 | [diff] [blame] | 270 | if (!str.empty()) { |
| 271 | str.append("|"); |
| 272 | } |
Winson | 62ac8b5 | 2019-12-04 08:36:48 -0800 | [diff] [blame] | 273 | str.append(StringPrintf("0x%08x", remaining)); |
MÃ¥rten Kongstad | 1d3b6485 | 2019-09-17 13:02:32 +0200 | [diff] [blame] | 274 | } |
| 275 | return !str.empty() ? str : "none"; |
| 276 | } |
| 277 | |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 278 | } // namespace |
| 279 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 280 | void Debug::PrintTable(const ResourceTable& table, const DebugPrintTableOptions& options, |
| 281 | Printer* printer) { |
Adam Lesinski | e59f0d8 | 2017-10-13 09:36:53 -0700 | [diff] [blame] | 282 | for (const auto& package : table.packages) { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 283 | ValueHeadlinePrinter headline_printer(package->name, printer); |
| 284 | ValueBodyPrinter body_printer(package->name, printer); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 285 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 286 | printer->Print("Package name="); |
| 287 | printer->Print(package->name); |
| 288 | if (package->id) { |
| 289 | printer->Print(StringPrintf(" id=%02x", package->id.value())); |
| 290 | } |
| 291 | printer->Println(); |
| 292 | |
| 293 | printer->Indent(); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 294 | for (const auto& type : package->types) { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 295 | printer->Print("type "); |
| 296 | printer->Print(to_string(type->type)); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 297 | if (type->id) { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 298 | printer->Print(StringPrintf(" id=%02x", type->id.value())); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 299 | } |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 300 | printer->Println(StringPrintf(" entryCount=%zd", type->entries.size())); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 301 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 302 | std::vector<const ResourceEntry*> sorted_entries; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 303 | for (const auto& entry : type->entries) { |
| 304 | auto iter = std::lower_bound( |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 305 | sorted_entries.begin(), sorted_entries.end(), entry.get(), |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 306 | [](const ResourceEntry* a, const ResourceEntry* b) -> bool { |
| 307 | if (a->id && b->id) { |
| 308 | return a->id.value() < b->id.value(); |
| 309 | } else if (a->id) { |
| 310 | return true; |
| 311 | } else { |
| 312 | return false; |
| 313 | } |
| 314 | }); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 315 | sorted_entries.insert(iter, entry.get()); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 318 | printer->Indent(); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 319 | for (const ResourceEntry* entry : sorted_entries) { |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 320 | const ResourceId id(package->id.value_or_default(0), type->id.value_or_default(0), |
| 321 | entry->id.value_or_default(0)); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 322 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 323 | printer->Print("resource "); |
| 324 | printer->Print(id.to_string()); |
| 325 | printer->Print(" "); |
| 326 | |
| 327 | // Write the name without the package (this is obvious and too verbose). |
| 328 | printer->Print(to_string(type->type)); |
| 329 | printer->Print("/"); |
| 330 | printer->Print(entry->name); |
| 331 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 332 | switch (entry->visibility.level) { |
| 333 | case Visibility::Level::kPublic: |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 334 | printer->Print(" PUBLIC"); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 335 | break; |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 336 | case Visibility::Level::kPrivate: |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 337 | printer->Print(" _PRIVATE_"); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 338 | break; |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 339 | case Visibility::Level::kUndefined: |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 340 | // Print nothing. |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 341 | break; |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 342 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 343 | |
MÃ¥rten Kongstad | 1d3b6485 | 2019-09-17 13:02:32 +0200 | [diff] [blame] | 344 | if (entry->overlayable_item) { |
| 345 | printer->Print(" OVERLAYABLE"); |
| 346 | } |
| 347 | |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 348 | printer->Println(); |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 349 | |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 350 | if (options.show_values) { |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 351 | printer->Indent(); |
Adam Lesinski | 71be705 | 2017-12-12 16:48:07 -0800 | [diff] [blame] | 352 | for (const auto& value : entry->values) { |
| 353 | printer->Print("("); |
| 354 | printer->Print(value->config.to_string()); |
| 355 | printer->Print(") "); |
| 356 | value->value->Accept(&headline_printer); |
| 357 | if (options.show_sources && !value->value->GetSource().path.empty()) { |
| 358 | printer->Print(" src="); |
| 359 | printer->Print(value->value->GetSource().to_string()); |
| 360 | } |
| 361 | printer->Println(); |
| 362 | printer->Indent(); |
| 363 | value->value->Accept(&body_printer); |
| 364 | printer->Undent(); |
| 365 | } |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 366 | printer->Undent(); |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 367 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 368 | } |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 369 | printer->Undent(); |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 370 | } |
Adam Lesinski | 93190b7 | 2017-11-03 15:20:17 -0700 | [diff] [blame] | 371 | printer->Undent(); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 372 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 375 | static size_t GetNodeIndex(const std::vector<ResourceName>& names, const ResourceName& name) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 376 | auto iter = std::lower_bound(names.begin(), names.end(), name); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 377 | CHECK(iter != names.end()); |
| 378 | CHECK(*iter == name); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 379 | return std::distance(names.begin(), iter); |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 382 | void Debug::PrintStyleGraph(ResourceTable* table, const ResourceName& target_style) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 383 | std::map<ResourceName, std::set<ResourceName>> graph; |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 384 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 385 | std::queue<ResourceName> styles_to_visit; |
| 386 | styles_to_visit.push(target_style); |
| 387 | for (; !styles_to_visit.empty(); styles_to_visit.pop()) { |
| 388 | const ResourceName& style_name = styles_to_visit.front(); |
| 389 | std::set<ResourceName>& parents = graph[style_name]; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 390 | if (!parents.empty()) { |
| 391 | // We've already visited this style. |
| 392 | continue; |
| 393 | } |
| 394 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 395 | Maybe<ResourceTable::SearchResult> result = table->FindResource(style_name); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 396 | if (result) { |
| 397 | ResourceEntry* entry = result.value().entry; |
| 398 | for (const auto& value : entry->values) { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 399 | if (Style* style = ValueCast<Style>(value->value.get())) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 400 | if (style->parent && style->parent.value().name) { |
| 401 | parents.insert(style->parent.value().name.value()); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 402 | styles_to_visit.push(style->parent.value().name.value()); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 403 | } |
Adam Lesinski | d13fb24 | 2015-05-12 20:40:48 -0700 | [diff] [blame] | 404 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 405 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 406 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 407 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 408 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 409 | std::vector<ResourceName> names; |
| 410 | for (const auto& entry : graph) { |
| 411 | names.push_back(entry.first); |
| 412 | } |
| 413 | |
| 414 | std::cout << "digraph styles {\n"; |
| 415 | for (const auto& name : names) { |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 416 | std::cout << " node_" << GetNodeIndex(names, name) << " [label=\"" << name << "\"];\n"; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | for (const auto& entry : graph) { |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 420 | const ResourceName& style_name = entry.first; |
| 421 | size_t style_node_index = GetNodeIndex(names, style_name); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 422 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 423 | for (const auto& parent_name : entry.second) { |
| 424 | std::cout << " node_" << style_node_index << " -> " |
| 425 | << "node_" << GetNodeIndex(names, parent_name) << ";\n"; |
Adam Lesinski | d13fb24 | 2015-05-12 20:40:48 -0700 | [diff] [blame] | 426 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 427 | } |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 428 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 429 | std::cout << "}" << std::endl; |
Adam Lesinski | 330edcd | 2015-05-04 17:40:56 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 432 | void Debug::DumpHex(const void* data, size_t len) { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 433 | const uint8_t* d = (const uint8_t*)data; |
| 434 | for (size_t i = 0; i < len; i++) { |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 435 | std::cerr << std::hex << std::setfill('0') << std::setw(2) << (uint32_t)d[i] << " "; |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 436 | if (i % 8 == 7) { |
| 437 | std::cerr << "\n"; |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 438 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 439 | } |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 440 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 441 | if (len - 1 % 8 != 7) { |
| 442 | std::cerr << std::endl; |
| 443 | } |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 444 | } |
| 445 | |
Ryan Mitchell | 5d27551 | 2018-07-19 14:29:00 -0700 | [diff] [blame] | 446 | void Debug::DumpResStringPool(const android::ResStringPool* pool, text::Printer* printer) { |
| 447 | using namespace android; |
Ryan Mitchell | 4e9a922 | 2018-11-13 10:40:07 -0800 | [diff] [blame] | 448 | |
Ryan Mitchell | 5d27551 | 2018-07-19 14:29:00 -0700 | [diff] [blame] | 449 | if (pool->getError() == NO_INIT) { |
| 450 | printer->Print("String pool is unitialized.\n"); |
| 451 | return; |
| 452 | } else if (pool->getError() != NO_ERROR) { |
| 453 | printer->Print("String pool is corrupt/invalid.\n"); |
| 454 | return; |
| 455 | } |
| 456 | |
| 457 | SortedVector<const void*> uniqueStrings; |
| 458 | const size_t N = pool->size(); |
| 459 | for (size_t i=0; i<N; i++) { |
| 460 | size_t len; |
| 461 | if (pool->isUTF8()) { |
| 462 | uniqueStrings.add(pool->string8At(i, &len)); |
| 463 | } else { |
| 464 | uniqueStrings.add(pool->stringAt(i, &len)); |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | printer->Print(StringPrintf("String pool of %zd unique %s %s strings, %zd entries and %zd styles " |
| 469 | "using %zd bytes:\n", uniqueStrings.size(), |
| 470 | pool->isUTF8() ? "UTF-8" : "UTF-16", |
| 471 | pool->isSorted() ? "sorted" : "non-sorted", N, pool->styleCount(), |
| 472 | pool->bytes())); |
| 473 | |
| 474 | const size_t NS = pool->size(); |
| 475 | for (size_t s=0; s<NS; s++) { |
| 476 | String8 str = pool->string8ObjectAt(s); |
Ryan Mitchell | 90b7a08 | 2019-02-15 17:39:58 +0000 | [diff] [blame] | 477 | printer->Print(StringPrintf("String #%zd : %s\n", s, str.string())); |
Ryan Mitchell | 5d27551 | 2018-07-19 14:29:00 -0700 | [diff] [blame] | 478 | } |
| 479 | } |
| 480 | |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 481 | namespace { |
| 482 | |
Adam Lesinski | e59f0d8 | 2017-10-13 09:36:53 -0700 | [diff] [blame] | 483 | class XmlPrinter : public xml::ConstVisitor { |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 484 | public: |
Adam Lesinski | e59f0d8 | 2017-10-13 09:36:53 -0700 | [diff] [blame] | 485 | using xml::ConstVisitor::Visit; |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 486 | |
Chih-Hung Hsieh | 1fc78e1 | 2018-12-20 13:37:44 -0800 | [diff] [blame] | 487 | explicit XmlPrinter(Printer* printer) : printer_(printer) { |
Adam Lesinski | da9eba3 | 2018-02-13 16:44:10 -0800 | [diff] [blame] | 488 | } |
| 489 | |
Adam Lesinski | e59f0d8 | 2017-10-13 09:36:53 -0700 | [diff] [blame] | 490 | void Visit(const xml::Element* el) override { |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 491 | for (const xml::NamespaceDecl& decl : el->namespace_decls) { |
Adam Lesinski | da9eba3 | 2018-02-13 16:44:10 -0800 | [diff] [blame] | 492 | printer_->Println(StringPrintf("N: %s=%s (line=%zu)", decl.prefix.c_str(), decl.uri.c_str(), |
| 493 | decl.line_number)); |
| 494 | printer_->Indent(); |
Adam Lesinski | 6b37299 | 2017-08-09 10:54:23 -0700 | [diff] [blame] | 495 | } |
| 496 | |
Adam Lesinski | da9eba3 | 2018-02-13 16:44:10 -0800 | [diff] [blame] | 497 | printer_->Print("E: "); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 498 | if (!el->namespace_uri.empty()) { |
Adam Lesinski | da9eba3 | 2018-02-13 16:44:10 -0800 | [diff] [blame] | 499 | printer_->Print(el->namespace_uri); |
| 500 | printer_->Print(":"); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 501 | } |
Adam Lesinski | da9eba3 | 2018-02-13 16:44:10 -0800 | [diff] [blame] | 502 | printer_->Println(StringPrintf("%s (line=%zu)", el->name.c_str(), el->line_number)); |
| 503 | printer_->Indent(); |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 504 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 505 | for (const xml::Attribute& attr : el->attributes) { |
Adam Lesinski | da9eba3 | 2018-02-13 16:44:10 -0800 | [diff] [blame] | 506 | printer_->Print("A: "); |
Adam Lesinski | ce5e56e | 2016-10-21 17:56:45 -0700 | [diff] [blame] | 507 | if (!attr.namespace_uri.empty()) { |
Adam Lesinski | da9eba3 | 2018-02-13 16:44:10 -0800 | [diff] [blame] | 508 | printer_->Print(attr.namespace_uri); |
| 509 | printer_->Print(":"); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 510 | } |
Adam Lesinski | da9eba3 | 2018-02-13 16:44:10 -0800 | [diff] [blame] | 511 | printer_->Print(attr.name); |
Adam Lesinski | 4ca5697 | 2017-04-26 21:49:53 -0700 | [diff] [blame] | 512 | |
| 513 | if (attr.compiled_attribute) { |
Adam Lesinski | da9eba3 | 2018-02-13 16:44:10 -0800 | [diff] [blame] | 514 | printer_->Print("("); |
| 515 | printer_->Print( |
| 516 | attr.compiled_attribute.value().id.value_or_default(ResourceId(0)).to_string()); |
| 517 | printer_->Print(")"); |
Adam Lesinski | 4ca5697 | 2017-04-26 21:49:53 -0700 | [diff] [blame] | 518 | } |
Adam Lesinski | da9eba3 | 2018-02-13 16:44:10 -0800 | [diff] [blame] | 519 | printer_->Print("="); |
Shane Farmer | 6ed4061 | 2017-09-06 10:00:07 -0700 | [diff] [blame] | 520 | if (attr.compiled_value != nullptr) { |
Adam Lesinski | da9eba3 | 2018-02-13 16:44:10 -0800 | [diff] [blame] | 521 | attr.compiled_value->PrettyPrint(printer_); |
Shane Farmer | 6ed4061 | 2017-09-06 10:00:07 -0700 | [diff] [blame] | 522 | } else { |
Adam Lesinski | bbf4297 | 2018-02-14 13:36:09 -0800 | [diff] [blame] | 523 | printer_->Print("\""); |
Adam Lesinski | da9eba3 | 2018-02-13 16:44:10 -0800 | [diff] [blame] | 524 | printer_->Print(attr.value); |
Adam Lesinski | bbf4297 | 2018-02-14 13:36:09 -0800 | [diff] [blame] | 525 | printer_->Print("\""); |
| 526 | } |
| 527 | |
| 528 | if (!attr.value.empty()) { |
| 529 | printer_->Print(" (Raw: \""); |
| 530 | printer_->Print(attr.value); |
| 531 | printer_->Print("\")"); |
Shane Farmer | 6ed4061 | 2017-09-06 10:00:07 -0700 | [diff] [blame] | 532 | } |
Adam Lesinski | da9eba3 | 2018-02-13 16:44:10 -0800 | [diff] [blame] | 533 | printer_->Println(); |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Adam Lesinski | da9eba3 | 2018-02-13 16:44:10 -0800 | [diff] [blame] | 536 | printer_->Indent(); |
Adam Lesinski | e59f0d8 | 2017-10-13 09:36:53 -0700 | [diff] [blame] | 537 | xml::ConstVisitor::Visit(el); |
Adam Lesinski | da9eba3 | 2018-02-13 16:44:10 -0800 | [diff] [blame] | 538 | printer_->Undent(); |
| 539 | printer_->Undent(); |
| 540 | |
| 541 | for (size_t i = 0; i < el->namespace_decls.size(); i++) { |
| 542 | printer_->Undent(); |
| 543 | } |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 544 | } |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 545 | |
Adam Lesinski | e59f0d8 | 2017-10-13 09:36:53 -0700 | [diff] [blame] | 546 | void Visit(const xml::Text* text) override { |
Adam Lesinski | da9eba3 | 2018-02-13 16:44:10 -0800 | [diff] [blame] | 547 | printer_->Println(StringPrintf("T: '%s'", text->text.c_str())); |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | private: |
Adam Lesinski | da9eba3 | 2018-02-13 16:44:10 -0800 | [diff] [blame] | 551 | Printer* printer_; |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 552 | }; |
| 553 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 554 | } // namespace |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 555 | |
Adam Lesinski | da9eba3 | 2018-02-13 16:44:10 -0800 | [diff] [blame] | 556 | void Debug::DumpXml(const xml::XmlResource& doc, Printer* printer) { |
| 557 | XmlPrinter xml_visitor(printer); |
| 558 | doc.root->Accept(&xml_visitor); |
Adam Lesinski | 5eeaadd | 2016-08-25 12:26:56 -0700 | [diff] [blame] | 559 | } |
Adam Lesinski | 52364f7 | 2016-01-11 13:10:24 -0800 | [diff] [blame] | 560 | |
MÃ¥rten Kongstad | 1d3b6485 | 2019-09-17 13:02:32 +0200 | [diff] [blame] | 561 | struct DumpOverlayableEntry { |
| 562 | std::string overlayable_section; |
| 563 | std::string policy_subsection; |
| 564 | std::string resource_name; |
| 565 | }; |
| 566 | |
| 567 | void Debug::DumpOverlayable(const ResourceTable& table, text::Printer* printer) { |
| 568 | std::vector<DumpOverlayableEntry> items; |
| 569 | for (const auto& package : table.packages) { |
| 570 | for (const auto& type : package->types) { |
| 571 | for (const auto& entry : type->entries) { |
| 572 | if (entry->overlayable_item) { |
| 573 | const auto& overlayable_item = entry->overlayable_item.value(); |
| 574 | const auto overlayable_section = StringPrintf(R"(name="%s" actor="%s")", |
| 575 | overlayable_item.overlayable->name.c_str(), |
| 576 | overlayable_item.overlayable->actor.c_str()); |
| 577 | const auto policy_subsection = StringPrintf(R"(policies="%s")", |
| 578 | OverlayablePoliciesToString(overlayable_item.policies).c_str()); |
| 579 | const auto value = |
| 580 | StringPrintf("%s/%s", to_string(type->type).data(), entry->name.c_str()); |
| 581 | items.push_back(DumpOverlayableEntry{overlayable_section, policy_subsection, value}); |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | std::sort(items.begin(), items.end(), |
| 588 | [](const DumpOverlayableEntry& a, const DumpOverlayableEntry& b) { |
| 589 | if (a.overlayable_section != b.overlayable_section) { |
| 590 | return a.overlayable_section < b.overlayable_section; |
| 591 | } |
| 592 | if (a.policy_subsection != b.policy_subsection) { |
| 593 | return a.policy_subsection < b.policy_subsection; |
| 594 | } |
| 595 | return a.resource_name < b.resource_name; |
| 596 | }); |
| 597 | |
| 598 | std::string last_overlayable_section; |
| 599 | std::string last_policy_subsection; |
| 600 | for (const auto& item : items) { |
| 601 | if (last_overlayable_section != item.overlayable_section) { |
| 602 | printer->Println(item.overlayable_section); |
| 603 | last_overlayable_section = item.overlayable_section; |
| 604 | } |
| 605 | if (last_policy_subsection != item.policy_subsection) { |
| 606 | printer->Indent(); |
| 607 | printer->Println(item.policy_subsection); |
| 608 | last_policy_subsection = item.policy_subsection; |
| 609 | printer->Undent(); |
| 610 | } |
| 611 | printer->Indent(); |
| 612 | printer->Indent(); |
| 613 | printer->Println(item.resource_name); |
| 614 | printer->Undent(); |
| 615 | printer->Undent(); |
| 616 | } |
| 617 | } |
| 618 | |
Adam Lesinski | cacb28f | 2016-10-19 12:18:14 -0700 | [diff] [blame] | 619 | } // namespace aapt |