blob: 0c1feb8fecfa736e3a9cd898b0624e52644bb355 [file] [log] [blame]
Yifan Hong443df792017-05-09 18:49:45 -07001/*
2 * Copyright (C) 2017 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 "ListCommand.h"
18
19#include <getopt.h>
20
Nirav Atrecce988d2018-05-16 11:14:46 -070021#include <algorithm>
Yifan Hong443df792017-05-09 18:49:45 -070022#include <fstream>
Yifan Hongb2d096a2018-05-01 15:25:23 -070023#include <functional>
Yifan Hong443df792017-05-09 18:49:45 -070024#include <iomanip>
25#include <iostream>
26#include <map>
Yifan Hong443df792017-05-09 18:49:45 -070027#include <regex>
Yifan Hongb2d096a2018-05-01 15:25:23 -070028#include <sstream>
Yifan Hong443df792017-05-09 18:49:45 -070029
Yifan Hongf31aa052018-02-02 15:17:51 -080030#include <android-base/file.h>
Steven Morelandb4d6c572021-07-29 12:17:25 -070031#include <android-base/hex.h>
Nirav Atrecce988d2018-05-16 11:14:46 -070032#include <android-base/logging.h>
Yifan Hong443df792017-05-09 18:49:45 -070033#include <android/hidl/manager/1.0/IServiceManager.h>
Yifan Hongfee209d2017-09-14 18:23:38 -070034#include <hidl-hash/Hash.h>
Yifan Hong443df792017-05-09 18:49:45 -070035#include <hidl-util/FQName.h>
36#include <private/android_filesystem_config.h>
37#include <sys/stat.h>
38#include <vintf/HalManifest.h>
Yifan Hongf31aa052018-02-02 15:17:51 -080039#include <vintf/parse_string.h>
Yifan Hong443df792017-05-09 18:49:45 -070040#include <vintf/parse_xml.h>
41
42#include "Lshal.h"
43#include "PipeRelay.h"
44#include "Timeout.h"
45#include "utils.h"
46
Yifan Hongb670dd72023-12-18 18:08:18 -080047using ::android::hardware::hidl_array;
Yifan Hong443df792017-05-09 18:49:45 -070048using ::android::hardware::hidl_string;
Yifan Hong22ea7b82017-09-14 18:07:43 -070049using ::android::hardware::hidl_vec;
50using ::android::hidl::base::V1_0::DebugInfo;
51using ::android::hidl::base::V1_0::IBase;
Yifan Hong443df792017-05-09 18:49:45 -070052using ::android::hidl::manager::V1_0::IServiceManager;
53
54namespace android {
55namespace lshal {
56
Yifan Hongf31aa052018-02-02 15:17:51 -080057vintf::SchemaType toSchemaType(Partition p) {
58 return (p == Partition::SYSTEM) ? vintf::SchemaType::FRAMEWORK : vintf::SchemaType::DEVICE;
59}
60
Yifan Hong13ba0a92018-06-25 16:15:56 -070061Partition toPartition(vintf::SchemaType t) {
62 switch (t) {
63 case vintf::SchemaType::FRAMEWORK: return Partition::SYSTEM;
64 // TODO(b/71555570): Device manifest does not distinguish HALs from vendor or ODM.
65 case vintf::SchemaType::DEVICE: return Partition::VENDOR;
66 }
67 return Partition::UNKNOWN;
68}
69
70std::string getPackageAndVersion(const std::string& fqInstance) {
71 return splitFirst(fqInstance, ':').first;
72}
73
Yifan Hong76ac14a2017-09-08 14:59:04 -070074NullableOStream<std::ostream> ListCommand::out() const {
75 return mLshal.out();
76}
77
78NullableOStream<std::ostream> ListCommand::err() const {
79 return mLshal.err();
Yifan Hong443df792017-05-09 18:49:45 -070080}
81
Yifan Hong795b6ec2017-09-13 11:25:28 -070082std::string ListCommand::GetName() {
83 return "list";
84}
85std::string ListCommand::getSimpleDescription() const {
Steven Morelanddbbbc652021-02-02 23:02:38 +000086 return "List HIDL HALs.";
Yifan Hong795b6ec2017-09-13 11:25:28 -070087}
88
Yifan Hong8bf73162017-09-07 18:06:13 -070089std::string ListCommand::parseCmdline(pid_t pid) const {
Yifan Hongf31aa052018-02-02 15:17:51 -080090 return android::procpartition::getCmdline(pid);
Yifan Hong443df792017-05-09 18:49:45 -070091}
92
93const std::string &ListCommand::getCmdline(pid_t pid) {
Yifan Hong13ba0a92018-06-25 16:15:56 -070094 static const std::string kEmptyString{};
95 if (pid == NO_PID) return kEmptyString;
Yifan Hong443df792017-05-09 18:49:45 -070096 auto pair = mCmdlines.find(pid);
97 if (pair != mCmdlines.end()) {
98 return pair->second;
99 }
Yifan Hong8bf73162017-09-07 18:06:13 -0700100 mCmdlines[pid] = parseCmdline(pid);
Yifan Hong443df792017-05-09 18:49:45 -0700101 return mCmdlines[pid];
102}
103
104void ListCommand::removeDeadProcesses(Pids *pids) {
105 static const pid_t myPid = getpid();
Yifan Hong61fb7bc2017-05-12 16:33:57 -0700106 pids->erase(std::remove_if(pids->begin(), pids->end(), [this](auto pid) {
Yifan Hong443df792017-05-09 18:49:45 -0700107 return pid == myPid || this->getCmdline(pid).empty();
Yifan Hong61fb7bc2017-05-12 16:33:57 -0700108 }), pids->end());
Yifan Hong443df792017-05-09 18:49:45 -0700109}
110
Yifan Hongf31aa052018-02-02 15:17:51 -0800111Partition ListCommand::getPartition(pid_t pid) {
Yifan Hong13ba0a92018-06-25 16:15:56 -0700112 if (pid == NO_PID) return Partition::UNKNOWN;
Yifan Hongf31aa052018-02-02 15:17:51 -0800113 auto it = mPartitions.find(pid);
114 if (it != mPartitions.end()) {
115 return it->second;
116 }
117 Partition partition = android::procpartition::getPartition(pid);
118 mPartitions.emplace(pid, partition);
119 return partition;
120}
121
122// Give sensible defaults when nothing can be inferred from runtime.
123// process: Partition inferred from executable location or cmdline.
Yifan Hongb2d096a2018-05-01 15:25:23 -0700124Partition ListCommand::resolvePartition(Partition process, const FqInstance& fqInstance) const {
125 if (fqInstance.inPackage("vendor") || fqInstance.inPackage("com")) {
Yifan Hongf31aa052018-02-02 15:17:51 -0800126 return Partition::VENDOR;
127 }
128
Yifan Hongb2d096a2018-05-01 15:25:23 -0700129 if (fqInstance.inPackage("android.frameworks") || fqInstance.inPackage("android.system") ||
130 fqInstance.inPackage("android.hidl")) {
Yifan Hongf31aa052018-02-02 15:17:51 -0800131 return Partition::SYSTEM;
132 }
133
134 // Some android.hardware HALs are served from system. Check the value from executable
135 // location / cmdline first.
Yifan Hongb2d096a2018-05-01 15:25:23 -0700136 if (fqInstance.inPackage("android.hardware")) {
Yifan Hongf31aa052018-02-02 15:17:51 -0800137 if (process != Partition::UNKNOWN) {
138 return process;
139 }
140 return Partition::VENDOR;
141 }
142
143 return process;
144}
145
Yifan Hongbdf44f82018-05-25 14:20:00 -0700146bool match(const vintf::ManifestInstance& instance, const FqInstance& fqInstance,
147 vintf::TransportArch ta) {
148 // For hwbinder libs, allow missing arch in manifest.
149 // For passthrough libs, allow missing interface/instance in table.
150 return (ta.transport == instance.transport()) &&
151 (ta.transport == vintf::Transport::HWBINDER ||
152 vintf::contains(instance.arch(), ta.arch)) &&
153 (!fqInstance.hasInterface() || fqInstance.getInterface() == instance.interface()) &&
154 (!fqInstance.hasInstance() || fqInstance.getInstance() == instance.instance());
155}
156
157bool match(const vintf::MatrixInstance& instance, const FqInstance& fqInstance,
158 vintf::TransportArch /* ta */) {
159 return (!fqInstance.hasInterface() || fqInstance.getInterface() == instance.interface()) &&
160 (!fqInstance.hasInstance() || instance.matchInstance(fqInstance.getInstance()));
161}
162
163template <typename ObjectType>
164VintfInfo getVintfInfo(const std::shared_ptr<const ObjectType>& object,
165 const FqInstance& fqInstance, vintf::TransportArch ta, VintfInfo value) {
166 bool found = false;
Yifan Hongc346a162019-09-10 19:35:55 -0700167 (void)object->forEachHidlInstanceOfVersion(fqInstance.getPackage(), fqInstance.getVersion(),
168 [&](const auto& instance) {
169 found = match(instance, fqInstance, ta);
170 return !found; // continue if not found
171 });
Yifan Hongbdf44f82018-05-25 14:20:00 -0700172 return found ? value : VINTF_INFO_EMPTY;
173}
174
175std::shared_ptr<const vintf::HalManifest> ListCommand::getDeviceManifest() const {
176 return vintf::VintfObject::GetDeviceHalManifest();
177}
178
179std::shared_ptr<const vintf::CompatibilityMatrix> ListCommand::getDeviceMatrix() const {
180 return vintf::VintfObject::GetDeviceCompatibilityMatrix();
181}
182
183std::shared_ptr<const vintf::HalManifest> ListCommand::getFrameworkManifest() const {
184 return vintf::VintfObject::GetFrameworkHalManifest();
185}
186
187std::shared_ptr<const vintf::CompatibilityMatrix> ListCommand::getFrameworkMatrix() const {
188 return vintf::VintfObject::GetFrameworkCompatibilityMatrix();
189}
190
191VintfInfo ListCommand::getVintfInfo(const std::string& fqInstanceName,
192 vintf::TransportArch ta) const {
193 FqInstance fqInstance;
194 if (!fqInstance.setTo(fqInstanceName) &&
195 // Ignore interface / instance for passthrough libs
Yifan Hong13ba0a92018-06-25 16:15:56 -0700196 !fqInstance.setTo(getPackageAndVersion(fqInstanceName))) {
Yifan Hongbdf44f82018-05-25 14:20:00 -0700197 err() << "Warning: Cannot parse '" << fqInstanceName << "'; no VINTF info." << std::endl;
198 return VINTF_INFO_EMPTY;
199 }
200
201 return lshal::getVintfInfo(getDeviceManifest(), fqInstance, ta, DEVICE_MANIFEST) |
202 lshal::getVintfInfo(getFrameworkManifest(), fqInstance, ta, FRAMEWORK_MANIFEST) |
203 lshal::getVintfInfo(getDeviceMatrix(), fqInstance, ta, DEVICE_MATRIX) |
204 lshal::getVintfInfo(getFrameworkMatrix(), fqInstance, ta, FRAMEWORK_MATRIX);
205}
206
Steven Morelandd8e20192017-05-24 11:23:08 -0700207bool ListCommand::getPidInfo(
Devin Moorec03e3aa2020-12-11 15:11:17 -0800208 pid_t serverPid, BinderPidInfo *pidInfo) const {
209 const auto& status = getBinderPidInfo(BinderDebugContext::HWBINDER, serverPid, pidInfo);
210 return status == OK;
Steven Morelandd8e20192017-05-24 11:23:08 -0700211}
212
Devin Moorec03e3aa2020-12-11 15:11:17 -0800213const BinderPidInfo* ListCommand::getPidInfoCached(pid_t serverPid) {
214 auto pair = mCachedPidInfos.insert({serverPid, BinderPidInfo{}});
Yifan Hong1243dde2017-09-14 17:49:30 -0700215 if (pair.second /* did insertion take place? */) {
216 if (!getPidInfo(serverPid, &pair.first->second)) {
217 return nullptr;
218 }
219 }
220 return &pair.first->second;
221}
222
Yifan Hong13ba0a92018-06-25 16:15:56 -0700223bool ListCommand::shouldFetchHalType(const HalType &type) const {
224 return (std::find(mFetchTypes.begin(), mFetchTypes.end(), type) != mFetchTypes.end());
Nirav Atrecce988d2018-05-16 11:14:46 -0700225}
226
Yifan Hongdb730532018-06-25 16:32:01 -0700227Table* ListCommand::tableForType(HalType type) {
228 switch (type) {
229 case HalType::BINDERIZED_SERVICES:
230 return &mServicesTable;
231 case HalType::PASSTHROUGH_CLIENTS:
232 return &mPassthroughRefTable;
233 case HalType::PASSTHROUGH_LIBRARIES:
234 return &mImplementationsTable;
Yifan Hong13ba0a92018-06-25 16:15:56 -0700235 case HalType::VINTF_MANIFEST:
236 return &mManifestHalsTable;
Yifan Hong3212f172018-06-28 12:39:50 -0700237 case HalType::LAZY_HALS:
238 return &mLazyHalsTable;
Yifan Hongdb730532018-06-25 16:32:01 -0700239 default:
240 LOG(FATAL) << "Unknown HAL type " << static_cast<int64_t>(type);
241 return nullptr;
242 }
243}
244const Table* ListCommand::tableForType(HalType type) const {
245 return const_cast<ListCommand*>(this)->tableForType(type);
Yifan Hong443df792017-05-09 18:49:45 -0700246}
247
248void ListCommand::forEachTable(const std::function<void(Table &)> &f) {
Nirav Atrecce988d2018-05-16 11:14:46 -0700249 for (const auto& type : mListTypes) {
Yifan Hongdb730532018-06-25 16:32:01 -0700250 f(*tableForType(type));
Nirav Atrecce988d2018-05-16 11:14:46 -0700251 }
Yifan Hong443df792017-05-09 18:49:45 -0700252}
253void ListCommand::forEachTable(const std::function<void(const Table &)> &f) const {
Nirav Atrecce988d2018-05-16 11:14:46 -0700254 for (const auto& type : mListTypes) {
Yifan Hongdb730532018-06-25 16:32:01 -0700255 f(*tableForType(type));
Nirav Atrecce988d2018-05-16 11:14:46 -0700256 }
Yifan Hong443df792017-05-09 18:49:45 -0700257}
258
259void ListCommand::postprocess() {
260 forEachTable([this](Table &table) {
261 if (mSortColumn) {
262 std::sort(table.begin(), table.end(), mSortColumn);
263 }
264 for (TableEntry &entry : table) {
265 entry.serverCmdline = getCmdline(entry.serverPid);
266 removeDeadProcesses(&entry.clientPids);
267 for (auto pid : entry.clientPids) {
268 entry.clientCmdlines.push_back(this->getCmdline(pid));
269 }
270 }
Yifan Hongf31aa052018-02-02 15:17:51 -0800271 for (TableEntry& entry : table) {
Yifan Hong13ba0a92018-06-25 16:15:56 -0700272 if (entry.partition == Partition::UNKNOWN) {
273 entry.partition = getPartition(entry.serverPid);
274 }
Yifan Hongbdf44f82018-05-25 14:20:00 -0700275 entry.vintfInfo = getVintfInfo(entry.interfaceName, {entry.transport, entry.arch});
Yifan Hongf31aa052018-02-02 15:17:51 -0800276 }
Yifan Hong443df792017-05-09 18:49:45 -0700277 });
278 // use a double for loop here because lshal doesn't care about efficiency.
279 for (TableEntry &packageEntry : mImplementationsTable) {
280 std::string packageName = packageEntry.interfaceName;
Steven Morelandd4f32b32018-03-06 14:47:58 -0800281 FQName fqPackageName;
282 if (!FQName::parse(packageName.substr(0, packageName.find("::")), &fqPackageName)) {
Yifan Hong443df792017-05-09 18:49:45 -0700283 continue;
284 }
285 for (TableEntry &interfaceEntry : mPassthroughRefTable) {
Yifan Hong0ad64f52018-05-25 15:29:17 -0700286 if (interfaceEntry.arch != vintf::Arch::ARCH_EMPTY) {
Yifan Hong443df792017-05-09 18:49:45 -0700287 continue;
288 }
Steven Morelandd4f32b32018-03-06 14:47:58 -0800289 FQName interfaceName;
290 if (!FQName::parse(splitFirst(interfaceEntry.interfaceName, '/').first, &interfaceName)) {
Yifan Hong443df792017-05-09 18:49:45 -0700291 continue;
292 }
293 if (interfaceName.getPackageAndVersion() == fqPackageName) {
294 interfaceEntry.arch = packageEntry.arch;
295 }
296 }
297 }
Yifan Hongca3b6602017-09-07 16:44:27 -0700298
299 mServicesTable.setDescription(
Steven Morelanddbbbc652021-02-02 23:02:38 +0000300 "| All HIDL binderized services (registered with hwservicemanager)");
Yifan Hongca3b6602017-09-07 16:44:27 -0700301 mPassthroughRefTable.setDescription(
Steven Morelanddbbbc652021-02-02 23:02:38 +0000302 "| All HIDL interfaces getService() has ever returned as a passthrough interface;\n"
Steven Moreland8e0f5392018-12-12 14:27:24 -0800303 "| PIDs / processes shown below might be inaccurate because the process\n"
304 "| might have relinquished the interface or might have died.\n"
305 "| The Server / Server CMD column can be ignored.\n"
306 "| The Clients / Clients CMD column shows all process that have ever dlopen'ed \n"
307 "| the library and successfully fetched the passthrough implementation.");
Yifan Hongca3b6602017-09-07 16:44:27 -0700308 mImplementationsTable.setDescription(
Steven Morelanddbbbc652021-02-02 23:02:38 +0000309 "| All available HIDL passthrough implementations (all -impl.so files).\n"
Steven Moreland8e0f5392018-12-12 14:27:24 -0800310 "| These may return subclasses through their respective HIDL_FETCH_I* functions.");
Yifan Hong13ba0a92018-06-25 16:15:56 -0700311 mManifestHalsTable.setDescription(
Steven Morelanddbbbc652021-02-02 23:02:38 +0000312 "| All HIDL HALs that are in VINTF manifest.");
Yifan Hong3212f172018-06-28 12:39:50 -0700313 mLazyHalsTable.setDescription(
Steven Morelanddbbbc652021-02-02 23:02:38 +0000314 "| All HIDL HALs that are declared in VINTF manifest:\n"
Steven Moreland8e0f5392018-12-12 14:27:24 -0800315 "| - as hwbinder HALs but are not registered to hwservicemanager, and\n"
316 "| - as hwbinder/passthrough HALs with no implementation.");
Yifan Hong443df792017-05-09 18:49:45 -0700317}
318
Yifan Hongb2d096a2018-05-01 15:25:23 -0700319bool ListCommand::addEntryWithInstance(const TableEntry& entry,
320 vintf::HalManifest* manifest) const {
321 FqInstance fqInstance;
322 if (!fqInstance.setTo(entry.interfaceName)) {
323 err() << "Warning: '" << entry.interfaceName << "' is not a valid FqInstance." << std::endl;
324 return false;
Yifan Hong77c87822017-06-19 15:47:39 -0700325 }
Yifan Hongb2d096a2018-05-01 15:25:23 -0700326
Steven Moreland7a99e042020-02-26 13:16:34 -0800327 if (fqInstance.getPackage() == "android.hidl.base") {
Yifan Hongb2d096a2018-05-01 15:25:23 -0700328 return true; // always remove IBase from manifest
329 }
330
331 Partition partition = resolvePartition(entry.partition, fqInstance);
332
333 if (partition == Partition::UNKNOWN) {
334 err() << "Warning: Cannot guess the partition of FqInstance " << fqInstance.string()
335 << std::endl;
336 return false;
337 }
338
339 if (partition != mVintfPartition) {
340 return true; // strip out instances that is in a different partition.
341 }
342
Yifan Hongb2d096a2018-05-01 15:25:23 -0700343 vintf::Arch arch;
Yifan Hong8304e412018-05-25 15:05:36 -0700344 if (entry.transport == vintf::Transport::HWBINDER) {
Yifan Hong0ad64f52018-05-25 15:29:17 -0700345 arch = vintf::Arch::ARCH_EMPTY; // no need to specify arch in manifest
Yifan Hong8304e412018-05-25 15:05:36 -0700346 } else if (entry.transport == vintf::Transport::PASSTHROUGH) {
Yifan Hong0ad64f52018-05-25 15:29:17 -0700347 if (entry.arch == vintf::Arch::ARCH_EMPTY) {
348 err() << "Warning: '" << entry.interfaceName << "' doesn't have bitness info.";
349 return false;
Yifan Hongb2d096a2018-05-01 15:25:23 -0700350 }
Yifan Hong0ad64f52018-05-25 15:29:17 -0700351 arch = entry.arch;
Yifan Hongb2d096a2018-05-01 15:25:23 -0700352 } else {
353 err() << "Warning: '" << entry.transport << "' is not a valid transport." << std::endl;
354 return false;
355 }
356
Yifan Hongcb5a1ab2023-01-12 14:55:55 -0800357 auto vintfFqInstance = vintf::FqInstance::from(fqInstance.string());
358 if (!vintfFqInstance.has_value()) {
359 err() << "Unable to convert " << fqInstance.string() << " to vintf::FqInstance"
360 << std::endl;
361 return false;
362 }
363
Yifan Hongb2d096a2018-05-01 15:25:23 -0700364 std::string e;
Yifan Hongcb5a1ab2023-01-12 14:55:55 -0800365 if (!manifest->insertInstance(*vintfFqInstance, entry.transport, arch, vintf::HalFormat::HIDL,
366 &e)) {
Yifan Hongb2d096a2018-05-01 15:25:23 -0700367 err() << "Warning: Cannot insert '" << fqInstance.string() << ": " << e << std::endl;
368 return false;
369 }
370 return true;
371}
372
373bool ListCommand::addEntryWithoutInstance(const TableEntry& entry,
374 const vintf::HalManifest* manifest) const {
Yifan Hong13ba0a92018-06-25 16:15:56 -0700375 const auto& packageAndVersion = splitFirst(getPackageAndVersion(entry.interfaceName), '@');
Yifan Hongb2d096a2018-05-01 15:25:23 -0700376 const auto& package = packageAndVersion.first;
377 vintf::Version version;
378 if (!vintf::parse(packageAndVersion.second, &version)) {
379 err() << "Warning: Cannot parse version '" << packageAndVersion.second << "' for entry '"
380 << entry.interfaceName << "'" << std::endl;
381 return false;
382 }
383
384 bool found = false;
Yifan Hongc346a162019-09-10 19:35:55 -0700385 (void)manifest->forEachHidlInstanceOfVersion(package, version, [&found](const auto&) {
Yifan Hongb2d096a2018-05-01 15:25:23 -0700386 found = true;
387 return false; // break
388 });
389 return found;
Yifan Hong77c87822017-06-19 15:47:39 -0700390}
391
Yifan Hongca3b6602017-09-07 16:44:27 -0700392void ListCommand::dumpVintf(const NullableOStream<std::ostream>& out) const {
Yifan Hong236301c2017-06-19 12:27:08 -0700393 using vintf::operator|=;
Yifan Hongf31aa052018-02-02 15:17:51 -0800394 using vintf::operator<<;
Yifan Hongb2d096a2018-05-01 15:25:23 -0700395 using namespace std::placeholders;
Yifan Hong443df792017-05-09 18:49:45 -0700396
397 vintf::HalManifest manifest;
Yifan Hongf31aa052018-02-02 15:17:51 -0800398 manifest.setType(toSchemaType(mVintfPartition));
Yifan Hong443df792017-05-09 18:49:45 -0700399
Yifan Hongb2d096a2018-05-01 15:25:23 -0700400 std::vector<std::string> error;
401 for (const TableEntry& entry : mServicesTable)
402 if (!addEntryWithInstance(entry, &manifest)) error.push_back(entry.interfaceName);
403 for (const TableEntry& entry : mPassthroughRefTable)
404 if (!addEntryWithInstance(entry, &manifest)) error.push_back(entry.interfaceName);
Yifan Hong13ba0a92018-06-25 16:15:56 -0700405 for (const TableEntry& entry : mManifestHalsTable)
406 if (!addEntryWithInstance(entry, &manifest)) error.push_back(entry.interfaceName);
Yifan Hong443df792017-05-09 18:49:45 -0700407
Yifan Hongb2d096a2018-05-01 15:25:23 -0700408 std::vector<std::string> passthrough;
409 for (const TableEntry& entry : mImplementationsTable)
410 if (!addEntryWithoutInstance(entry, &manifest)) passthrough.push_back(entry.interfaceName);
Yifan Hongf31aa052018-02-02 15:17:51 -0800411
Yifan Hongf31aa052018-02-02 15:17:51 -0800412 out << "<!-- " << std::endl
Yifan Hongb2d096a2018-05-01 15:25:23 -0700413 << " This is a skeleton " << manifest.type() << " manifest. Notes: " << std::endl
414 << INIT_VINTF_NOTES;
415 if (!error.empty()) {
416 out << std::endl << " The following HALs are not added; see warnings." << std::endl;
417 for (const auto& e : error) {
418 out << " " << e << std::endl;
419 }
420 }
421 if (!passthrough.empty()) {
422 out << std::endl
423 << " The following HALs are passthrough and no interface or instance " << std::endl
424 << " names can be inferred." << std::endl;
425 for (const auto& e : passthrough) {
426 out << " " << e << std::endl;
427 }
428 }
429 out << "-->" << std::endl;
Yifan Honga96f87f2021-04-16 18:59:27 -0700430 out << vintf::toXml(manifest, vintf::SerializeFlags::HALS_ONLY);
Yifan Hong443df792017-05-09 18:49:45 -0700431}
432
Yifan Hongf31aa052018-02-02 15:17:51 -0800433std::string ListCommand::INIT_VINTF_NOTES{
Yifan Hongb2d096a2018-05-01 15:25:23 -0700434 " 1. If a HAL is supported in both hwbinder and passthrough transport,\n"
Yifan Hongf31aa052018-02-02 15:17:51 -0800435 " only hwbinder is shown.\n"
436 " 2. It is likely that HALs in passthrough transport does not have\n"
437 " <interface> declared; users will have to write them by hand.\n"
438 " 3. A HAL with lower minor version can be overridden by a HAL with\n"
439 " higher minor version if they have the same name and major version.\n"
Yifan Hongb2d096a2018-05-01 15:25:23 -0700440 " 4. This output is intended for launch devices.\n"
441 " Upgrading devices should not use this tool to generate device\n"
442 " manifest and replace the existing manifest directly, but should\n"
443 " edit the existing manifest manually.\n"
444 " Specifically, devices which launched at Android O-MR1 or earlier\n"
445 " should not use the 'fqname' format for required HAL entries and\n"
446 " should instead use the legacy package, name, instance-name format\n"
447 " until they are updated.\n"
Yifan Hongf31aa052018-02-02 15:17:51 -0800448};
449
Yifan Hong0ad64f52018-05-25 15:29:17 -0700450static vintf::Arch fromBaseArchitecture(::android::hidl::base::V1_0::DebugInfo::Architecture a) {
Yifan Hong443df792017-05-09 18:49:45 -0700451 switch (a) {
452 case ::android::hidl::base::V1_0::DebugInfo::Architecture::IS_64BIT:
Yifan Hong0ad64f52018-05-25 15:29:17 -0700453 return vintf::Arch::ARCH_64;
Yifan Hong443df792017-05-09 18:49:45 -0700454 case ::android::hidl::base::V1_0::DebugInfo::Architecture::IS_32BIT:
Yifan Hong0ad64f52018-05-25 15:29:17 -0700455 return vintf::Arch::ARCH_32;
Yifan Hong443df792017-05-09 18:49:45 -0700456 case ::android::hidl::base::V1_0::DebugInfo::Architecture::UNKNOWN: // fallthrough
457 default:
Yifan Hong0ad64f52018-05-25 15:29:17 -0700458 return vintf::Arch::ARCH_EMPTY;
Yifan Hong443df792017-05-09 18:49:45 -0700459 }
460}
461
Yifan Hongca3b6602017-09-07 16:44:27 -0700462void ListCommand::dumpTable(const NullableOStream<std::ostream>& out) const {
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700463 if (mNeat) {
Yifan Hongb72f19e2018-06-27 16:58:56 -0700464 std::vector<const Table*> tables;
465 forEachTable([&tables](const Table &table) {
466 tables.push_back(&table);
467 });
468 MergedTable(std::move(tables)).createTextTable().dump(out.buf());
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700469 return;
470 }
471
Yifan Hongca3b6602017-09-07 16:44:27 -0700472 forEachTable([this, &out](const Table &table) {
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700473
Yifan Hongd4a77e82017-09-06 19:40:24 -0700474 // We're only interested in dumping debug info for already
475 // instantiated services. There's little value in dumping the
476 // debug info for a service we create on the fly, so we only operate
477 // on the "mServicesTable".
478 std::function<std::string(const std::string&)> emitDebugInfo = nullptr;
479 if (mEmitDebugInfo && &table == &mServicesTable) {
480 emitDebugInfo = [this](const auto& iName) {
Yifan Hongca3b6602017-09-07 16:44:27 -0700481 std::stringstream ss;
Yifan Hongd4a77e82017-09-06 19:40:24 -0700482 auto pair = splitFirst(iName, '/');
Steven Moreland5f328892018-01-18 14:38:07 -0800483 mLshal.emitDebugInfo(pair.first, pair.second, {},
Yifan Hong6884b872020-07-09 16:38:18 -0700484 ParentDebugInfoLevel::FQNAME_ONLY, ss,
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700485 NullableOStream<std::ostream>(nullptr));
Yifan Hongca3b6602017-09-07 16:44:27 -0700486 return ss.str();
Yifan Hongd4a77e82017-09-06 19:40:24 -0700487 };
Yifan Hong443df792017-05-09 18:49:45 -0700488 }
Yifan Hongca3b6602017-09-07 16:44:27 -0700489 table.createTextTable(mNeat, emitDebugInfo).dump(out.buf());
490 out << std::endl;
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700491 });
Yifan Hong443df792017-05-09 18:49:45 -0700492}
493
Yifan Hongca3b6602017-09-07 16:44:27 -0700494Status ListCommand::dump() {
495 auto dump = mVintf ? &ListCommand::dumpVintf : &ListCommand::dumpTable;
496
497 if (mFileOutputPath.empty()) {
498 (*this.*dump)(out());
499 return OK;
Yifan Hong443df792017-05-09 18:49:45 -0700500 }
Yifan Hongca3b6602017-09-07 16:44:27 -0700501
502 std::ofstream fileOutput(mFileOutputPath);
503 if (!fileOutput.is_open()) {
504 err() << "Could not open file '" << mFileOutputPath << "'." << std::endl;
505 return IO_ERROR;
506 }
507 chown(mFileOutputPath.c_str(), AID_SHELL, AID_SHELL);
508
509 (*this.*dump)(NullableOStream<std::ostream>(fileOutput));
510
511 fileOutput.flush();
512 fileOutput.close();
513 return OK;
Yifan Hong443df792017-05-09 18:49:45 -0700514}
515
Yifan Hong20f4ee82018-06-25 16:21:29 -0700516void ListCommand::putEntry(HalType type, TableEntry &&entry) {
Yifan Hongdb730532018-06-25 16:32:01 -0700517 tableForType(type)->add(std::forward<TableEntry>(entry));
Yifan Hong443df792017-05-09 18:49:45 -0700518}
519
520Status ListCommand::fetchAllLibraries(const sp<IServiceManager> &manager) {
Yifan Hong13ba0a92018-06-25 16:15:56 -0700521 if (!shouldFetchHalType(HalType::PASSTHROUGH_LIBRARIES)) { return OK; }
Nirav Atrecce988d2018-05-16 11:14:46 -0700522
Yifan Hong443df792017-05-09 18:49:45 -0700523 using namespace ::android::hardware;
524 using namespace ::android::hidl::manager::V1_0;
525 using namespace ::android::hidl::base::V1_0;
Yifan Hongb670dd72023-12-18 18:08:18 -0800526
527 // The lambda function may be executed asynchrounously because it is passed to timeoutIPC,
528 // even though the interface function call is synchronous.
529 // However, there's no need to lock because if ret.isOk(), the background thread has
530 // already ended, so it is safe to dereference entries.
531 auto entries = std::make_shared<std::map<std::string, TableEntry>>();
Yifan Hong96bc7142023-12-18 21:57:56 -0800532 auto ret =
533 timeoutIPC(mLshal.getDebugDumpWait(), manager, &IServiceManager::debugDump,
534 [entries](const auto& infos) {
535 for (const auto& info : infos) {
536 std::string interfaceName = std::string{info.interfaceName.c_str()} +
537 "/" + std::string{info.instanceName.c_str()};
538 entries->emplace(interfaceName,
539 TableEntry{
540 .interfaceName = interfaceName,
541 .transport = vintf::Transport::PASSTHROUGH,
542 .clientPids = info.clientPids,
543 })
544 .first->second.arch |= fromBaseArchitecture(info.arch);
545 }
546 });
Yifan Hong443df792017-05-09 18:49:45 -0700547 if (!ret.isOk()) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700548 err() << "Error: Failed to call list on getPassthroughServiceManager(): "
Yifan Hong443df792017-05-09 18:49:45 -0700549 << ret.description() << std::endl;
550 return DUMP_ALL_LIBS_ERROR;
551 }
Yifan Hongb670dd72023-12-18 18:08:18 -0800552 for (auto&& pair : *entries) {
553 putEntry(HalType::PASSTHROUGH_LIBRARIES, std::move(pair.second));
554 }
Yifan Hong443df792017-05-09 18:49:45 -0700555 return OK;
556}
557
558Status ListCommand::fetchPassthrough(const sp<IServiceManager> &manager) {
Yifan Hong13ba0a92018-06-25 16:15:56 -0700559 if (!shouldFetchHalType(HalType::PASSTHROUGH_CLIENTS)) { return OK; }
Nirav Atrecce988d2018-05-16 11:14:46 -0700560
Yifan Hong443df792017-05-09 18:49:45 -0700561 using namespace ::android::hardware;
562 using namespace ::android::hardware::details;
563 using namespace ::android::hidl::manager::V1_0;
564 using namespace ::android::hidl::base::V1_0;
Yifan Hongb670dd72023-12-18 18:08:18 -0800565
566 // The lambda function may be executed asynchrounously because it is passed to timeoutIPC,
567 // even though the interface function call is synchronous.
568 // However, there's no need to lock because if ret.isOk(), the background thread has
569 // already ended, so it is safe to dereference entries.
570 auto entries = std::make_shared<std::vector<TableEntry>>();
Yifan Hong96bc7142023-12-18 21:57:56 -0800571 auto ret =
572 timeoutIPC(mLshal.getIpcCallWait(), manager, &IServiceManager::debugDump,
573 [entries](const auto& infos) {
574 for (const auto& info : infos) {
575 if (info.clientPids.size() <= 0) {
576 continue;
577 }
578 entries->emplace_back(
579 TableEntry{.interfaceName =
580 std::string{info.interfaceName.c_str()} +
581 "/" +
582 std::string{info.instanceName.c_str()},
583 .transport = vintf::Transport::PASSTHROUGH,
584 .serverPid = info.clientPids.size() == 1
585 ? info.clientPids[0]
586 : NO_PID,
587 .clientPids = info.clientPids,
588 .arch = fromBaseArchitecture(info.arch)});
589 }
590 });
Yifan Hong443df792017-05-09 18:49:45 -0700591 if (!ret.isOk()) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700592 err() << "Error: Failed to call debugDump on defaultServiceManager(): "
Yifan Hong443df792017-05-09 18:49:45 -0700593 << ret.description() << std::endl;
594 return DUMP_PASSTHROUGH_ERROR;
595 }
Yifan Hongb670dd72023-12-18 18:08:18 -0800596 for (auto&& entry : *entries) {
597 putEntry(HalType::PASSTHROUGH_CLIENTS, std::move(entry));
598 }
Yifan Hong443df792017-05-09 18:49:45 -0700599 return OK;
600}
601
602Status ListCommand::fetchBinderized(const sp<IServiceManager> &manager) {
Yifan Hong8304e412018-05-25 15:05:36 -0700603 using vintf::operator<<;
604
Yifan Hong13ba0a92018-06-25 16:15:56 -0700605 if (!shouldFetchHalType(HalType::BINDERIZED_SERVICES)) { return OK; }
Yifan Hong443df792017-05-09 18:49:45 -0700606
Yifan Hong8304e412018-05-25 15:05:36 -0700607 const vintf::Transport mode = vintf::Transport::HWBINDER;
Yifan Hongb670dd72023-12-18 18:08:18 -0800608
609 // The lambda function may be executed asynchrounously because it is passed to timeoutIPC,
610 // even though the interface function call is synchronous.
611 // However, there's no need to lock because if listRet.isOk(), the background thread has
612 // already ended, so it is safe to dereference fqInstanceNames.
613 auto fqInstanceNames = std::make_shared<hidl_vec<hidl_string>>();
Yifan Hong96bc7142023-12-18 21:57:56 -0800614 auto listRet = timeoutIPC(mLshal.getIpcCallWait(), manager, &IServiceManager::list,
Yifan Hongb670dd72023-12-18 18:08:18 -0800615 [fqInstanceNames](const auto& names) { *fqInstanceNames = names; });
Yifan Hong443df792017-05-09 18:49:45 -0700616 if (!listRet.isOk()) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700617 err() << "Error: Failed to list services for " << mode << ": "
Yifan Hong443df792017-05-09 18:49:45 -0700618 << listRet.description() << std::endl;
619 return DUMP_BINDERIZED_ERROR;
620 }
621
622 Status status = OK;
Yifan Hong22ea7b82017-09-14 18:07:43 -0700623 std::map<std::string, TableEntry> allTableEntries;
Yifan Hongb670dd72023-12-18 18:08:18 -0800624 for (const auto& fqInstanceName : *fqInstanceNames) {
Yifan Hong22ea7b82017-09-14 18:07:43 -0700625 // create entry and default assign all fields.
626 TableEntry& entry = allTableEntries[fqInstanceName];
627 entry.interfaceName = fqInstanceName;
628 entry.transport = mode;
Yifan Hong13ba0a92018-06-25 16:15:56 -0700629 entry.serviceStatus = ServiceStatus::NON_RESPONSIVE;
Yifan Hong22ea7b82017-09-14 18:07:43 -0700630
631 status |= fetchBinderizedEntry(manager, &entry);
632 }
633
634 for (auto& pair : allTableEntries) {
Yifan Hong20f4ee82018-06-25 16:21:29 -0700635 putEntry(HalType::BINDERIZED_SERVICES, std::move(pair.second));
Yifan Hong22ea7b82017-09-14 18:07:43 -0700636 }
637 return status;
638}
639
640Status ListCommand::fetchBinderizedEntry(const sp<IServiceManager> &manager,
641 TableEntry *entry) {
642 Status status = OK;
643 const auto handleError = [&](Status additionalError, const std::string& msg) {
644 err() << "Warning: Skipping \"" << entry->interfaceName << "\": " << msg << std::endl;
645 status |= DUMP_BINDERIZED_ERROR | additionalError;
646 };
647
648 const auto pair = splitFirst(entry->interfaceName, '/');
649 const auto &serviceName = pair.first;
650 const auto &instanceName = pair.second;
Yifan Hong96bc7142023-12-18 21:57:56 -0800651 auto getRet = timeoutIPC(mLshal.getIpcCallWait(), manager, &IServiceManager::get, serviceName,
652 instanceName);
Yifan Hong22ea7b82017-09-14 18:07:43 -0700653 if (!getRet.isOk()) {
654 handleError(TRANSACTION_ERROR,
655 "cannot be fetched from service manager:" + getRet.description());
656 return status;
657 }
658 sp<IBase> service = getRet;
659 if (service == nullptr) {
660 handleError(NO_INTERFACE, "cannot be fetched from service manager (null)");
661 return status;
662 }
663
664 // getDebugInfo
665 do {
Yifan Hongb670dd72023-12-18 18:08:18 -0800666 // The lambda function may be executed asynchrounously because it is passed to timeoutIPC,
667 // even though the interface function call is synchronous.
668 // However, there's no need to lock because if debugRet.isOk(), the background thread has
669 // already ended, so it is safe to dereference debugInfo.
670 auto debugInfo = std::make_shared<DebugInfo>();
Yifan Hong96bc7142023-12-18 21:57:56 -0800671 auto debugRet = timeoutIPC(mLshal.getIpcCallWait(), service, &IBase::getDebugInfo,
Yifan Hongb670dd72023-12-18 18:08:18 -0800672 [debugInfo](const auto& received) { *debugInfo = received; });
Yifan Hong443df792017-05-09 18:49:45 -0700673 if (!debugRet.isOk()) {
Yifan Hong22ea7b82017-09-14 18:07:43 -0700674 handleError(TRANSACTION_ERROR,
675 "debugging information cannot be retrieved: " + debugRet.description());
676 break; // skip getPidInfo
Yifan Hong443df792017-05-09 18:49:45 -0700677 }
Steven Morelandd8e20192017-05-24 11:23:08 -0700678
Yifan Hongb670dd72023-12-18 18:08:18 -0800679 entry->serverPid = debugInfo->pid;
680 entry->serverObjectAddress = debugInfo->ptr;
681 entry->arch = fromBaseArchitecture(debugInfo->arch);
Steven Morelandd8e20192017-05-24 11:23:08 -0700682
Yifan Hongb670dd72023-12-18 18:08:18 -0800683 if (debugInfo->pid != NO_PID) {
684 const BinderPidInfo* pidInfo = getPidInfoCached(debugInfo->pid);
Yifan Hong22ea7b82017-09-14 18:07:43 -0700685 if (pidInfo == nullptr) {
686 handleError(IO_ERROR,
Yifan Hongb670dd72023-12-18 18:08:18 -0800687 "no information for PID " + std::to_string(debugInfo->pid) +
688 ", are you root?");
Yifan Hong22ea7b82017-09-14 18:07:43 -0700689 break;
690 }
Yifan Hongb670dd72023-12-18 18:08:18 -0800691 if (debugInfo->ptr != NO_PTR) {
692 auto it = pidInfo->refPids.find(debugInfo->ptr);
Yifan Hong22ea7b82017-09-14 18:07:43 -0700693 if (it != pidInfo->refPids.end()) {
694 entry->clientPids = it->second;
695 }
696 }
697 entry->threadUsage = pidInfo->threadUsage;
698 entry->threadCount = pidInfo->threadCount;
699 }
700 } while (0);
Yifan Hongfee209d2017-09-14 18:23:38 -0700701
702 // hash
703 do {
Yifan Hongb670dd72023-12-18 18:08:18 -0800704 // The lambda function may be executed asynchrounously because it is passed to timeoutIPC,
705 // even though the interface function call is synchronous.
706 auto hashIndexStore = std::make_shared<ssize_t>(-1);
Yifan Hong96bc7142023-12-18 21:57:56 -0800707 auto ifaceChainRet = timeoutIPC(mLshal.getIpcCallWait(), service, &IBase::interfaceChain,
Yifan Hongb670dd72023-12-18 18:08:18 -0800708 [hashIndexStore, serviceName](const auto& c) {
709 for (size_t i = 0; i < c.size(); ++i) {
710 if (serviceName == c[i]) {
711 *hashIndexStore = static_cast<ssize_t>(i);
712 break;
713 }
714 }
715 });
Yifan Hongfee209d2017-09-14 18:23:38 -0700716 if (!ifaceChainRet.isOk()) {
717 handleError(TRANSACTION_ERROR,
718 "interfaceChain fails: " + ifaceChainRet.description());
719 break; // skip getHashChain
720 }
Yifan Hongb670dd72023-12-18 18:08:18 -0800721 // if ifaceChainRet.isOk(), the background thread has already ended, so it is safe to
722 // dereference hashIndex without any locking.
723 auto hashIndex = *hashIndexStore;
Yifan Hongfee209d2017-09-14 18:23:38 -0700724 if (hashIndex < 0) {
725 handleError(BAD_IMPL, "Interface name does not exist in interfaceChain.");
726 break; // skip getHashChain
727 }
Yifan Hongb670dd72023-12-18 18:08:18 -0800728 // See comments about hashIndex above.
729 auto hashChain = std::make_shared<hidl_vec<hidl_array<uint8_t, 32>>>();
Yifan Hong96bc7142023-12-18 21:57:56 -0800730 auto hashRet = timeoutIPC(mLshal.getIpcCallWait(), service, &IBase::getHashChain,
Yifan Hongb670dd72023-12-18 18:08:18 -0800731 [hashChain](const auto& ret) { *hashChain = std::move(ret); });
Yifan Hongfee209d2017-09-14 18:23:38 -0700732 if (!hashRet.isOk()) {
733 handleError(TRANSACTION_ERROR, "getHashChain failed: " + hashRet.description());
Yifan Hongb4cb70d2024-03-18 14:14:35 -0700734 break; // skip getHashChain
Yifan Hongfee209d2017-09-14 18:23:38 -0700735 }
Yifan Hongb670dd72023-12-18 18:08:18 -0800736 if (static_cast<size_t>(hashIndex) >= hashChain->size()) {
737 handleError(BAD_IMPL,
738 "interfaceChain indicates position " + std::to_string(hashIndex) +
739 " but getHashChain returns " + std::to_string(hashChain->size()) +
740 " hashes");
Yifan Hongb4cb70d2024-03-18 14:14:35 -0700741 break; // skip getHashChain
Yifan Hongb670dd72023-12-18 18:08:18 -0800742 }
Yifan Hongb4cb70d2024-03-18 14:14:35 -0700743 auto&& hashArray = (*hashChain)[hashIndex];
744 entry->hash = android::base::HexString(hashArray.data(), hashArray.size());
Yifan Hongfee209d2017-09-14 18:23:38 -0700745 } while (0);
Yifan Hong13ba0a92018-06-25 16:15:56 -0700746 if (status == OK) {
747 entry->serviceStatus = ServiceStatus::ALIVE;
748 }
Yifan Hong443df792017-05-09 18:49:45 -0700749 return status;
750}
751
Yifan Hong13ba0a92018-06-25 16:15:56 -0700752Status ListCommand::fetchManifestHals() {
753 if (!shouldFetchHalType(HalType::VINTF_MANIFEST)) { return OK; }
754 Status status = OK;
755
756 for (auto manifest : {getDeviceManifest(), getFrameworkManifest()}) {
757 if (manifest == nullptr) {
758 status |= VINTF_ERROR;
759 continue;
760 }
761
762 std::map<std::string, TableEntry> entries;
763
Yifan Hongc346a162019-09-10 19:35:55 -0700764 manifest->forEachHidlInstance([&] (const vintf::ManifestInstance& manifestInstance) {
Yifan Hong13ba0a92018-06-25 16:15:56 -0700765 TableEntry entry{
Yifan Hongc346a162019-09-10 19:35:55 -0700766 .interfaceName = manifestInstance.description(),
Yifan Hong13ba0a92018-06-25 16:15:56 -0700767 .transport = manifestInstance.transport(),
768 .arch = manifestInstance.arch(),
769 // TODO(b/71555570): Device manifest does not distinguish HALs from vendor or ODM.
770 .partition = toPartition(manifest->type()),
771 .serviceStatus = ServiceStatus::DECLARED};
772 std::string key = entry.interfaceName;
773 entries.emplace(std::move(key), std::move(entry));
774 return true;
775 });
776
777 for (auto&& pair : entries)
778 mManifestHalsTable.add(std::move(pair.second));
779 }
Yifan Hong443df792017-05-09 18:49:45 -0700780 return status;
781}
782
Yifan Hong3212f172018-06-28 12:39:50 -0700783Status ListCommand::fetchLazyHals() {
784 using vintf::operator<<;
785
786 if (!shouldFetchHalType(HalType::LAZY_HALS)) { return OK; }
787 Status status = OK;
788
789 for (const TableEntry& manifestEntry : mManifestHalsTable) {
790 if (manifestEntry.transport == vintf::Transport::HWBINDER) {
791 if (!hasHwbinderEntry(manifestEntry)) {
792 mLazyHalsTable.add(TableEntry(manifestEntry));
793 }
794 continue;
795 }
796 if (manifestEntry.transport == vintf::Transport::PASSTHROUGH) {
797 if (!hasPassthroughEntry(manifestEntry)) {
798 mLazyHalsTable.add(TableEntry(manifestEntry));
799 }
800 continue;
801 }
802 err() << "Warning: unrecognized transport in VINTF manifest: "
803 << manifestEntry.transport;
804 status |= VINTF_ERROR;
805 }
806 return status;
807}
808
809bool ListCommand::hasHwbinderEntry(const TableEntry& entry) const {
810 for (const TableEntry& existing : mServicesTable) {
811 if (existing.interfaceName == entry.interfaceName) {
812 return true;
813 }
814 }
815 return false;
816}
817
818bool ListCommand::hasPassthroughEntry(const TableEntry& entry) const {
819 FqInstance entryFqInstance;
820 if (!entryFqInstance.setTo(entry.interfaceName)) {
821 return false; // cannot parse, so add it anyway.
822 }
823 for (const TableEntry& existing : mImplementationsTable) {
824 FqInstance existingFqInstance;
825 if (!existingFqInstance.setTo(getPackageAndVersion(existing.interfaceName))) {
826 continue;
827 }
828
829 // For example, manifest may say graphics.mapper@2.1 but passthroughServiceManager
830 // can only list graphics.mapper@2.0.
831 if (entryFqInstance.getPackage() == existingFqInstance.getPackage() &&
832 vintf::Version{entryFqInstance.getVersion()}
833 .minorAtLeast(vintf::Version{existingFqInstance.getVersion()})) {
834 return true;
835 }
836 }
837 return false;
838}
839
Yifan Hong443df792017-05-09 18:49:45 -0700840Status ListCommand::fetch() {
841 Status status = OK;
Yifan Hong9881df92017-05-10 14:33:05 -0700842 auto bManager = mLshal.serviceManager();
Yifan Hong443df792017-05-09 18:49:45 -0700843 if (bManager == nullptr) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700844 err() << "Failed to get defaultServiceManager()!" << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700845 status |= NO_BINDERIZED_MANAGER;
846 } else {
847 status |= fetchBinderized(bManager);
848 // Passthrough PIDs are registered to the binderized manager as well.
849 status |= fetchPassthrough(bManager);
850 }
851
Yifan Hong9881df92017-05-10 14:33:05 -0700852 auto pManager = mLshal.passthroughManager();
Yifan Hong443df792017-05-09 18:49:45 -0700853 if (pManager == nullptr) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700854 err() << "Failed to get getPassthroughServiceManager()!" << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700855 status |= NO_PASSTHROUGH_MANAGER;
856 } else {
857 status |= fetchAllLibraries(pManager);
858 }
Yifan Hong13ba0a92018-06-25 16:15:56 -0700859 status |= fetchManifestHals();
Yifan Hong3212f172018-06-28 12:39:50 -0700860 status |= fetchLazyHals();
Yifan Hong443df792017-05-09 18:49:45 -0700861 return status;
862}
863
Yifan Hong13ba0a92018-06-25 16:15:56 -0700864void ListCommand::initFetchTypes() {
Yifan Hong3212f172018-06-28 12:39:50 -0700865 // TODO: refactor to do polymorphism on each table (so that dependency graph is not hardcoded).
866 static const std::map<HalType, std::set<HalType>> kDependencyGraph{
867 {HalType::LAZY_HALS, {HalType::BINDERIZED_SERVICES,
868 HalType::PASSTHROUGH_LIBRARIES,
869 HalType::VINTF_MANIFEST}},
870 };
Yifan Hong13ba0a92018-06-25 16:15:56 -0700871 mFetchTypes.insert(mListTypes.begin(), mListTypes.end());
Yifan Hong3212f172018-06-28 12:39:50 -0700872 for (HalType listType : mListTypes) {
873 auto it = kDependencyGraph.find(listType);
874 if (it != kDependencyGraph.end()) {
875 mFetchTypes.insert(it->second.begin(), it->second.end());
876 }
877 }
Yifan Hong13ba0a92018-06-25 16:15:56 -0700878}
879
Yifan Hong30528a22020-08-07 18:24:06 -0700880// Get all values of enum type T, assuming the first value is 0 and the last value is T::LAST.
881// T::LAST is not included in the returned list.
882template <typename T>
883std::vector<T> GetAllValues() {
884 using BaseType = std::underlying_type_t<T>;
885 std::vector<T> ret;
886 for (BaseType i = 0; i < static_cast<BaseType>(T::LAST); ++i) {
887 ret.push_back(static_cast<T>(i));
888 }
889 return ret;
890}
891
Yifan Honga6b93f02017-09-13 16:53:37 -0700892void ListCommand::registerAllOptions() {
893 int v = mOptions.size();
894 // A list of acceptable command line options
895 // key: value returned by getopt_long
896 // long options with short alternatives
897 mOptions.push_back({'h', "help", no_argument, v++, [](ListCommand*, const char*) {
898 return USAGE;
899 }, ""});
900 mOptions.push_back({'i', "interface", no_argument, v++, [](ListCommand* thiz, const char*) {
901 thiz->mSelectedColumns.push_back(TableColumnType::INTERFACE_NAME);
902 return OK;
903 }, "print the instance name column"});
Yifan Hongfee209d2017-09-14 18:23:38 -0700904 mOptions.push_back({'l', "released", no_argument, v++, [](ListCommand* thiz, const char*) {
905 thiz->mSelectedColumns.push_back(TableColumnType::RELEASED);
906 return OK;
Yifan Hong430f8982018-05-25 17:28:39 -0700907 }, "print the 'is released?' column\n(Y=released, N=unreleased, ?=unknown)"});
Yifan Honga6b93f02017-09-13 16:53:37 -0700908 mOptions.push_back({'t', "transport", no_argument, v++, [](ListCommand* thiz, const char*) {
909 thiz->mSelectedColumns.push_back(TableColumnType::TRANSPORT);
910 return OK;
911 }, "print the transport mode column"});
912 mOptions.push_back({'r', "arch", no_argument, v++, [](ListCommand* thiz, const char*) {
913 thiz->mSelectedColumns.push_back(TableColumnType::ARCH);
914 return OK;
915 }, "print the bitness column"});
Yifan Hongfee209d2017-09-14 18:23:38 -0700916 mOptions.push_back({'s', "hash", no_argument, v++, [](ListCommand* thiz, const char*) {
917 thiz->mSelectedColumns.push_back(TableColumnType::HASH);
918 return OK;
919 }, "print hash of the interface"});
Yifan Honga6b93f02017-09-13 16:53:37 -0700920 mOptions.push_back({'p', "pid", no_argument, v++, [](ListCommand* thiz, const char*) {
921 thiz->mSelectedColumns.push_back(TableColumnType::SERVER_PID);
922 return OK;
923 }, "print the server PID, or server cmdline if -m is set"});
924 mOptions.push_back({'a', "address", no_argument, v++, [](ListCommand* thiz, const char*) {
925 thiz->mSelectedColumns.push_back(TableColumnType::SERVER_ADDR);
926 return OK;
927 }, "print the server object address column"});
928 mOptions.push_back({'c', "clients", no_argument, v++, [](ListCommand* thiz, const char*) {
929 thiz->mSelectedColumns.push_back(TableColumnType::CLIENT_PIDS);
930 return OK;
931 }, "print the client PIDs, or client cmdlines if -m is set"});
932 mOptions.push_back({'e', "threads", no_argument, v++, [](ListCommand* thiz, const char*) {
933 thiz->mSelectedColumns.push_back(TableColumnType::THREADS);
934 return OK;
935 }, "print currently used/available threads\n(note, available threads created lazily)"});
936 mOptions.push_back({'m', "cmdline", no_argument, v++, [](ListCommand* thiz, const char*) {
937 thiz->mEnableCmdlines = true;
938 return OK;
939 }, "print cmdline instead of PIDs"});
940 mOptions.push_back({'d', "debug", optional_argument, v++, [](ListCommand* thiz, const char* arg) {
941 thiz->mEmitDebugInfo = true;
942 if (arg) thiz->mFileOutputPath = arg;
943 return OK;
944 }, "Emit debug info from\nIBase::debug with empty options. Cannot be used with --neat.\n"
945 "Writes to specified file if 'arg' is provided, otherwise stdout."});
946
Yifan Hongbdf44f82018-05-25 14:20:00 -0700947 mOptions.push_back({'V', "vintf", no_argument, v++, [](ListCommand* thiz, const char*) {
948 thiz->mSelectedColumns.push_back(TableColumnType::VINTF);
949 return OK;
950 }, "print VINTF info. This column contains a comma-separated list of:\n"
Steven Morelanddbbbc652021-02-02 23:02:38 +0000951 " - DM: if the HIDL HAL is in the device manifest\n"
952 " - DC: if the HIDL HAL is in the device compatibility matrix\n"
953 " - FM: if the HIDL HAL is in the framework manifest\n"
954 " - FC: if the HIDL HAL is in the framework compatibility matrix\n"
955 " - X: if the HIDL HAL is in none of the above lists"});
Yifan Hong13ba0a92018-06-25 16:15:56 -0700956 mOptions.push_back({'S', "service-status", no_argument, v++, [](ListCommand* thiz, const char*) {
957 thiz->mSelectedColumns.push_back(TableColumnType::SERVICE_STATUS);
958 return OK;
959 }, "print service status column. Possible values are:\n"
960 " - alive: alive and running hwbinder service;\n"
961 " - registered;dead: registered to hwservicemanager but is not responsive;\n"
962 " - declared: only declared in VINTF manifest but is not registered to hwservicemanager;\n"
963 " - N/A: no information for passthrough HALs."});
Yifan Hongbdf44f82018-05-25 14:20:00 -0700964
Yifan Hong30528a22020-08-07 18:24:06 -0700965 mOptions.push_back({'A', "all", no_argument, v++,
966 [](ListCommand* thiz, const char*) {
967 auto allColumns = GetAllValues<TableColumnType>();
968 thiz->mSelectedColumns.insert(thiz->mSelectedColumns.end(),
969 allColumns.begin(), allColumns.end());
970 return OK;
971 },
972 "print all columns"});
973
Yifan Honga6b93f02017-09-13 16:53:37 -0700974 // long options without short alternatives
975 mOptions.push_back({'\0', "init-vintf", no_argument, v++, [](ListCommand* thiz, const char* arg) {
976 thiz->mVintf = true;
Yifan Hongf31aa052018-02-02 15:17:51 -0800977 if (thiz->mVintfPartition == Partition::UNKNOWN)
978 thiz->mVintfPartition = Partition::VENDOR;
Yifan Honga6b93f02017-09-13 16:53:37 -0700979 if (arg) thiz->mFileOutputPath = arg;
980 return OK;
981 }, "form a skeleton HAL manifest to specified file,\nor stdout if no file specified."});
Yifan Hongf31aa052018-02-02 15:17:51 -0800982 mOptions.push_back({'\0', "init-vintf-partition", required_argument, v++, [](ListCommand* thiz, const char* arg) {
983 if (!arg) return USAGE;
984 thiz->mVintfPartition = android::procpartition::parsePartition(arg);
985 if (thiz->mVintfPartition == Partition::UNKNOWN) return USAGE;
986 return OK;
987 }, "Specify the partition of the HAL manifest\ngenerated by --init-vintf.\n"
988 "Valid values are 'system', 'vendor', and 'odm'. Default is 'vendor'."});
Yifan Honga6b93f02017-09-13 16:53:37 -0700989 mOptions.push_back({'\0', "sort", required_argument, v++, [](ListCommand* thiz, const char* arg) {
990 if (strcmp(arg, "interface") == 0 || strcmp(arg, "i") == 0) {
991 thiz->mSortColumn = TableEntry::sortByInterfaceName;
992 } else if (strcmp(arg, "pid") == 0 || strcmp(arg, "p") == 0) {
993 thiz->mSortColumn = TableEntry::sortByServerPid;
994 } else {
995 thiz->err() << "Unrecognized sorting column: " << arg << std::endl;
996 return USAGE;
997 }
998 return OK;
999 }, "sort by a column. 'arg' can be (i|interface) or (p|pid)."});
1000 mOptions.push_back({'\0', "neat", no_argument, v++, [](ListCommand* thiz, const char*) {
1001 thiz->mNeat = true;
1002 return OK;
1003 }, "output is machine parsable (no explanatory text).\nCannot be used with --debug."});
Yifan Hong30528a22020-08-07 18:24:06 -07001004 mOptions.push_back(
1005 {'\0', "types", required_argument, v++,
1006 [](ListCommand* thiz, const char* arg) {
1007 if (!arg) {
1008 return USAGE;
1009 }
Nirav Atrecce988d2018-05-16 11:14:46 -07001010
Yifan Hong30528a22020-08-07 18:24:06 -07001011 static const std::map<std::string, std::vector<HalType>> kHalTypeMap{
1012 {"binderized", {HalType::BINDERIZED_SERVICES}},
1013 {"b", {HalType::BINDERIZED_SERVICES}},
1014 {"passthrough_clients", {HalType::PASSTHROUGH_CLIENTS}},
1015 {"c", {HalType::PASSTHROUGH_CLIENTS}},
1016 {"passthrough_libs", {HalType::PASSTHROUGH_LIBRARIES}},
1017 {"l", {HalType::PASSTHROUGH_LIBRARIES}},
1018 {"vintf", {HalType::VINTF_MANIFEST}},
1019 {"v", {HalType::VINTF_MANIFEST}},
1020 {"lazy", {HalType::LAZY_HALS}},
1021 {"z", {HalType::LAZY_HALS}},
1022 {"all", GetAllValues<HalType>()},
1023 {"a", GetAllValues<HalType>()},
1024 };
Nirav Atrecce988d2018-05-16 11:14:46 -07001025
Yifan Hong30528a22020-08-07 18:24:06 -07001026 std::vector<std::string> halTypesArgs = split(std::string(arg), ',');
1027 for (const auto& halTypeArg : halTypesArgs) {
1028 if (halTypeArg.empty()) continue;
Nirav Atrecce988d2018-05-16 11:14:46 -07001029
Yifan Hong30528a22020-08-07 18:24:06 -07001030 const auto& halTypeIter = kHalTypeMap.find(halTypeArg);
1031 if (halTypeIter == kHalTypeMap.end()) {
1032 thiz->err() << "Unrecognized HAL type: " << halTypeArg << std::endl;
1033 return USAGE;
1034 }
Nirav Atrecce988d2018-05-16 11:14:46 -07001035
Yifan Hong30528a22020-08-07 18:24:06 -07001036 // Append unique (non-repeated) HAL types to the reporting list
1037 for (auto halType : halTypeIter->second) {
1038 if (std::find(thiz->mListTypes.begin(), thiz->mListTypes.end(), halType) ==
1039 thiz->mListTypes.end()) {
1040 thiz->mListTypes.push_back(halType);
1041 }
1042 }
1043 }
Nirav Atrecce988d2018-05-16 11:14:46 -07001044
Yifan Hong30528a22020-08-07 18:24:06 -07001045 if (thiz->mListTypes.empty()) {
1046 return USAGE;
1047 }
1048 return OK;
1049 },
1050 "comma-separated list of one or more sections.\nThe output is restricted to the "
1051 "selected section(s). Valid options\nare: (b|binderized), (c|passthrough_clients), (l|"
1052 "passthrough_libs), (v|vintf), (z|lazy), and (a|all).\nDefault is `b,c,l`."});
Yifan Honga6b93f02017-09-13 16:53:37 -07001053}
1054
1055// Create 'longopts' argument to getopt_long. Caller is responsible for maintaining
1056// the lifetime of "options" during the usage of the returned array.
1057static std::unique_ptr<struct option[]> getLongOptions(
1058 const ListCommand::RegisteredOptions& options,
1059 int* longOptFlag) {
1060 std::unique_ptr<struct option[]> ret{new struct option[options.size() + 1]};
1061 int i = 0;
1062 for (const auto& e : options) {
1063 ret[i].name = e.longOption.c_str();
1064 ret[i].has_arg = e.hasArg;
1065 ret[i].flag = longOptFlag;
1066 ret[i].val = e.val;
1067
1068 i++;
1069 }
1070 // getopt_long last option has all zeros
Yi Kong19d5c002018-07-20 13:39:55 -07001071 ret[i].name = nullptr;
Yifan Honga6b93f02017-09-13 16:53:37 -07001072 ret[i].has_arg = 0;
Yi Kong19d5c002018-07-20 13:39:55 -07001073 ret[i].flag = nullptr;
Yifan Honga6b93f02017-09-13 16:53:37 -07001074 ret[i].val = 0;
1075
1076 return ret;
1077}
1078
1079// Create 'optstring' argument to getopt_long.
1080static std::string getShortOptions(const ListCommand::RegisteredOptions& options) {
1081 std::stringstream ss;
1082 for (const auto& e : options) {
1083 if (e.shortOption != '\0') {
1084 ss << e.shortOption;
1085 }
1086 }
1087 return ss.str();
1088}
1089
Yifan Honga8bedc62017-09-08 18:00:31 -07001090Status ListCommand::parseArgs(const Arg &arg) {
Nirav Atrecce988d2018-05-16 11:14:46 -07001091 mListTypes.clear();
Yifan Hong443df792017-05-09 18:49:45 -07001092
Yifan Honga6b93f02017-09-13 16:53:37 -07001093 if (mOptions.empty()) {
1094 registerAllOptions();
1095 }
1096 int longOptFlag;
1097 std::unique_ptr<struct option[]> longOptions = getLongOptions(mOptions, &longOptFlag);
1098 std::string shortOptions = getShortOptions(mOptions);
Yifan Hongd4a77e82017-09-06 19:40:24 -07001099
Yifan Honga8bedc62017-09-08 18:00:31 -07001100 // suppress output to std::err for unknown options
1101 opterr = 0;
1102
Yifan Hong443df792017-05-09 18:49:45 -07001103 int optionIndex;
1104 int c;
1105 // Lshal::parseArgs has set optind to the next option to parse
1106 for (;;) {
Yifan Hong443df792017-05-09 18:49:45 -07001107 c = getopt_long(arg.argc, arg.argv,
Yifan Honga6b93f02017-09-13 16:53:37 -07001108 shortOptions.c_str(), longOptions.get(), &optionIndex);
Yifan Hong443df792017-05-09 18:49:45 -07001109 if (c == -1) {
1110 break;
1111 }
Yifan Honga6b93f02017-09-13 16:53:37 -07001112 const RegisteredOption* found = nullptr;
1113 if (c == 0) {
1114 // see long option
1115 for (const auto& e : mOptions) {
1116 if (longOptFlag == e.val) found = &e;
Yifan Hong443df792017-05-09 18:49:45 -07001117 }
Yifan Honga6b93f02017-09-13 16:53:37 -07001118 } else {
1119 // see short option
1120 for (const auto& e : mOptions) {
1121 if (c == e.shortOption) found = &e;
1122 }
Yifan Hong443df792017-05-09 18:49:45 -07001123 }
Yifan Honga6b93f02017-09-13 16:53:37 -07001124
1125 if (found == nullptr) {
1126 // see unrecognized options
Yifan Honga8bedc62017-09-08 18:00:31 -07001127 err() << "unrecognized option `" << arg.argv[optind - 1] << "'" << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -07001128 return USAGE;
1129 }
Yifan Honga6b93f02017-09-13 16:53:37 -07001130
1131 Status status = found->op(this, optarg);
1132 if (status != OK) {
1133 return status;
1134 }
Yifan Hong443df792017-05-09 18:49:45 -07001135 }
1136 if (optind < arg.argc) {
1137 // see non option
Yifan Honga8bedc62017-09-08 18:00:31 -07001138 err() << "unrecognized option `" << arg.argv[optind] << "'" << std::endl;
Yifan Hong1bc1e9f2017-08-29 17:28:12 -07001139 return USAGE;
1140 }
1141
1142 if (mNeat && mEmitDebugInfo) {
Yifan Hong76ac14a2017-09-08 14:59:04 -07001143 err() << "Error: --neat should not be used with --debug." << std::endl;
Yifan Hong1bc1e9f2017-08-29 17:28:12 -07001144 return USAGE;
Yifan Hong443df792017-05-09 18:49:45 -07001145 }
1146
Yifan Honga6b93f02017-09-13 16:53:37 -07001147 if (mSelectedColumns.empty()) {
Steven Moreland8e0f5392018-12-12 14:27:24 -08001148 mSelectedColumns = {TableColumnType::VINTF, TableColumnType::RELEASED,
Yifan Hongfee209d2017-09-14 18:23:38 -07001149 TableColumnType::INTERFACE_NAME, TableColumnType::THREADS,
Yifan Hong05494a52017-08-29 18:50:00 -07001150 TableColumnType::SERVER_PID, TableColumnType::CLIENT_PIDS};
Yifan Hong443df792017-05-09 18:49:45 -07001151 }
Yifan Hongd4a77e82017-09-06 19:40:24 -07001152
Yifan Honga6b93f02017-09-13 16:53:37 -07001153 if (mEnableCmdlines) {
1154 for (size_t i = 0; i < mSelectedColumns.size(); ++i) {
1155 if (mSelectedColumns[i] == TableColumnType::SERVER_PID) {
1156 mSelectedColumns[i] = TableColumnType::SERVER_CMD;
Yifan Hongd4a77e82017-09-06 19:40:24 -07001157 }
Yifan Honga6b93f02017-09-13 16:53:37 -07001158 if (mSelectedColumns[i] == TableColumnType::CLIENT_PIDS) {
1159 mSelectedColumns[i] = TableColumnType::CLIENT_CMDS;
Yifan Hongd4a77e82017-09-06 19:40:24 -07001160 }
1161 }
1162 }
1163
Nirav Atrecce988d2018-05-16 11:14:46 -07001164 // By default, list all HAL types
1165 if (mListTypes.empty()) {
1166 mListTypes = {HalType::BINDERIZED_SERVICES, HalType::PASSTHROUGH_CLIENTS,
1167 HalType::PASSTHROUGH_LIBRARIES};
1168 }
Yifan Hong13ba0a92018-06-25 16:15:56 -07001169 initFetchTypes();
Nirav Atrecce988d2018-05-16 11:14:46 -07001170
Yifan Honga6b93f02017-09-13 16:53:37 -07001171 forEachTable([this] (Table& table) {
1172 table.setSelectedColumns(this->mSelectedColumns);
Yifan Hongd4a77e82017-09-06 19:40:24 -07001173 });
1174
Yifan Hong443df792017-05-09 18:49:45 -07001175 return OK;
1176}
1177
Yifan Honga8bedc62017-09-08 18:00:31 -07001178Status ListCommand::main(const Arg &arg) {
1179 Status status = parseArgs(arg);
Yifan Hong443df792017-05-09 18:49:45 -07001180 if (status != OK) {
1181 return status;
1182 }
1183 status = fetch();
1184 postprocess();
Yifan Hongca3b6602017-09-07 16:44:27 -07001185 status |= dump();
Yifan Hong443df792017-05-09 18:49:45 -07001186 return status;
1187}
1188
Yifan Honga6b93f02017-09-13 16:53:37 -07001189const std::string& ListCommand::RegisteredOption::getHelpMessageForArgument() const {
1190 static const std::string empty{};
1191 static const std::string optional{"[=<arg>]"};
1192 static const std::string required{"=<arg>"};
1193
1194 if (hasArg == optional_argument) {
1195 return optional;
1196 }
1197 if (hasArg == required_argument) {
1198 return required;
1199 }
1200 return empty;
1201}
1202
Yifan Honga8bedc62017-09-08 18:00:31 -07001203void ListCommand::usage() const {
1204
Yifan Honga6b93f02017-09-13 16:53:37 -07001205 err() << "list:" << std::endl
1206 << " lshal" << std::endl
1207 << " lshal list" << std::endl
Steven Moreland8e0f5392018-12-12 14:27:24 -08001208 << " List all hals with default ordering and columns (`lshal list -Vliepc`)" << std::endl
Yifan Honga6b93f02017-09-13 16:53:37 -07001209 << " lshal list [-h|--help]" << std::endl
1210 << " -h, --help: Print help message for list (`lshal help list`)" << std::endl
1211 << " lshal [list] [OPTIONS...]" << std::endl;
1212 for (const auto& e : mOptions) {
1213 if (e.help.empty()) {
1214 continue;
1215 }
1216 err() << " ";
1217 if (e.shortOption != '\0')
1218 err() << "-" << e.shortOption << e.getHelpMessageForArgument();
1219 if (e.shortOption != '\0' && !e.longOption.empty())
1220 err() << ", ";
1221 if (!e.longOption.empty())
1222 err() << "--" << e.longOption << e.getHelpMessageForArgument();
1223 err() << ": ";
Nirav Atrecce988d2018-05-16 11:14:46 -07001224 std::vector<std::string> lines = split(e.help, '\n');
Yifan Honga6b93f02017-09-13 16:53:37 -07001225 for (const auto& line : lines) {
1226 if (&line != &lines.front())
1227 err() << " ";
1228 err() << line << std::endl;
1229 }
1230 }
Yifan Honga8bedc62017-09-08 18:00:31 -07001231}
1232
Yifan Hong443df792017-05-09 18:49:45 -07001233} // namespace lshal
1234} // namespace android
Yifan Hong05494a52017-08-29 18:50:00 -07001235