blob: 5545966e161c936d17b35e0d90f046a7d6d68af4 [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
21#include <fstream>
22#include <iomanip>
23#include <iostream>
24#include <map>
25#include <sstream>
26#include <regex>
27
Yifan Hongf31aa052018-02-02 15:17:51 -080028#include <android-base/file.h>
Yifan Hong443df792017-05-09 18:49:45 -070029#include <android-base/parseint.h>
30#include <android/hidl/manager/1.0/IServiceManager.h>
Yifan Hongfee209d2017-09-14 18:23:38 -070031#include <hidl-hash/Hash.h>
Yifan Hong443df792017-05-09 18:49:45 -070032#include <hidl-util/FQName.h>
33#include <private/android_filesystem_config.h>
34#include <sys/stat.h>
35#include <vintf/HalManifest.h>
Yifan Hongf31aa052018-02-02 15:17:51 -080036#include <vintf/parse_string.h>
Yifan Hong443df792017-05-09 18:49:45 -070037#include <vintf/parse_xml.h>
38
39#include "Lshal.h"
40#include "PipeRelay.h"
41#include "Timeout.h"
42#include "utils.h"
43
44using ::android::hardware::hidl_string;
Yifan Hong22ea7b82017-09-14 18:07:43 -070045using ::android::hardware::hidl_vec;
46using ::android::hidl::base::V1_0::DebugInfo;
47using ::android::hidl::base::V1_0::IBase;
Yifan Hong443df792017-05-09 18:49:45 -070048using ::android::hidl::manager::V1_0::IServiceManager;
49
50namespace android {
51namespace lshal {
52
Yifan Hongf31aa052018-02-02 15:17:51 -080053vintf::SchemaType toSchemaType(Partition p) {
54 return (p == Partition::SYSTEM) ? vintf::SchemaType::FRAMEWORK : vintf::SchemaType::DEVICE;
55}
56
Yifan Hong76ac14a2017-09-08 14:59:04 -070057NullableOStream<std::ostream> ListCommand::out() const {
58 return mLshal.out();
59}
60
61NullableOStream<std::ostream> ListCommand::err() const {
62 return mLshal.err();
Yifan Hong443df792017-05-09 18:49:45 -070063}
64
Yifan Hong795b6ec2017-09-13 11:25:28 -070065std::string ListCommand::GetName() {
66 return "list";
67}
68std::string ListCommand::getSimpleDescription() const {
69 return "List HALs.";
70}
71
Yifan Hong8bf73162017-09-07 18:06:13 -070072std::string ListCommand::parseCmdline(pid_t pid) const {
Yifan Hongf31aa052018-02-02 15:17:51 -080073 return android::procpartition::getCmdline(pid);
Yifan Hong443df792017-05-09 18:49:45 -070074}
75
76const std::string &ListCommand::getCmdline(pid_t pid) {
77 auto pair = mCmdlines.find(pid);
78 if (pair != mCmdlines.end()) {
79 return pair->second;
80 }
Yifan Hong8bf73162017-09-07 18:06:13 -070081 mCmdlines[pid] = parseCmdline(pid);
Yifan Hong443df792017-05-09 18:49:45 -070082 return mCmdlines[pid];
83}
84
85void ListCommand::removeDeadProcesses(Pids *pids) {
86 static const pid_t myPid = getpid();
Yifan Hong61fb7bc2017-05-12 16:33:57 -070087 pids->erase(std::remove_if(pids->begin(), pids->end(), [this](auto pid) {
Yifan Hong443df792017-05-09 18:49:45 -070088 return pid == myPid || this->getCmdline(pid).empty();
Yifan Hong61fb7bc2017-05-12 16:33:57 -070089 }), pids->end());
Yifan Hong443df792017-05-09 18:49:45 -070090}
91
Yifan Hongf31aa052018-02-02 15:17:51 -080092Partition ListCommand::getPartition(pid_t pid) {
93 auto it = mPartitions.find(pid);
94 if (it != mPartitions.end()) {
95 return it->second;
96 }
97 Partition partition = android::procpartition::getPartition(pid);
98 mPartitions.emplace(pid, partition);
99 return partition;
100}
101
102// Give sensible defaults when nothing can be inferred from runtime.
103// process: Partition inferred from executable location or cmdline.
104Partition ListCommand::resolvePartition(Partition process, const FQName& fqName) const {
105 if (fqName.inPackage("vendor") ||
106 fqName.inPackage("com")) {
107 return Partition::VENDOR;
108 }
109
110 if (fqName.inPackage("android.frameworks") ||
111 fqName.inPackage("android.system") ||
112 fqName.inPackage("android.hidl")) {
113 return Partition::SYSTEM;
114 }
115
116 // Some android.hardware HALs are served from system. Check the value from executable
117 // location / cmdline first.
118 if (fqName.inPackage("android.hardware")) {
119 if (process != Partition::UNKNOWN) {
120 return process;
121 }
122 return Partition::VENDOR;
123 }
124
125 return process;
126}
127
Yifan Hong1243dde2017-09-14 17:49:30 -0700128static bool scanBinderContext(pid_t pid,
Steven Morelandd8e20192017-05-24 11:23:08 -0700129 const std::string &contextName,
130 std::function<void(const std::string&)> eachLine) {
131 std::ifstream ifs("/d/binder/proc/" + std::to_string(pid));
Yifan Hong443df792017-05-09 18:49:45 -0700132 if (!ifs.is_open()) {
133 return false;
134 }
135
Steven Morelandd8e20192017-05-24 11:23:08 -0700136 static const std::regex kContextLine("^context (\\w+)$");
Yifan Hong443df792017-05-09 18:49:45 -0700137
Steven Morelandd8e20192017-05-24 11:23:08 -0700138 bool isDesiredContext = false;
Yifan Hong443df792017-05-09 18:49:45 -0700139 std::string line;
140 std::smatch match;
141 while(getline(ifs, line)) {
Steven Morelandd8e20192017-05-24 11:23:08 -0700142 if (std::regex_search(line, match, kContextLine)) {
143 isDesiredContext = match.str(1) == contextName;
Yifan Hong443df792017-05-09 18:49:45 -0700144 continue;
145 }
Steven Morelandd8e20192017-05-24 11:23:08 -0700146
147 if (!isDesiredContext) {
Yifan Hong443df792017-05-09 18:49:45 -0700148 continue;
149 }
Steven Morelandd8e20192017-05-24 11:23:08 -0700150
151 eachLine(line);
Yifan Hong443df792017-05-09 18:49:45 -0700152 }
153 return true;
154}
155
Steven Morelandd8e20192017-05-24 11:23:08 -0700156bool ListCommand::getPidInfo(
157 pid_t serverPid, PidInfo *pidInfo) const {
158 static const std::regex kReferencePrefix("^\\s*node \\d+:\\s+u([0-9a-f]+)\\s+c([0-9a-f]+)\\s+");
159 static const std::regex kThreadPrefix("^\\s*thread \\d+:\\s+l\\s+(\\d)(\\d)");
160
161 std::smatch match;
162 return scanBinderContext(serverPid, "hwbinder", [&](const std::string& line) {
163 if (std::regex_search(line, match, kReferencePrefix)) {
164 const std::string &ptrString = "0x" + match.str(2); // use number after c
165 uint64_t ptr;
166 if (!::android::base::ParseUint(ptrString.c_str(), &ptr)) {
167 // Should not reach here, but just be tolerant.
Yifan Hong76ac14a2017-09-08 14:59:04 -0700168 err() << "Could not parse number " << ptrString << std::endl;
Steven Morelandd8e20192017-05-24 11:23:08 -0700169 return;
170 }
171 const std::string proc = " proc ";
172 auto pos = line.rfind(proc);
173 if (pos != std::string::npos) {
174 for (const std::string &pidStr : split(line.substr(pos + proc.size()), ' ')) {
175 int32_t pid;
176 if (!::android::base::ParseInt(pidStr, &pid)) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700177 err() << "Could not parse number " << pidStr << std::endl;
Steven Morelandd8e20192017-05-24 11:23:08 -0700178 return;
179 }
180 pidInfo->refPids[ptr].push_back(pid);
181 }
182 }
183
184 return;
185 }
186
187 if (std::regex_search(line, match, kThreadPrefix)) {
188 // "1" is waiting in binder driver
189 // "2" is poll. It's impossible to tell if these are in use.
190 // and HIDL default code doesn't use it.
191 bool isInUse = match.str(1) != "1";
192 // "0" is a thread that has called into binder
193 // "1" is looper thread
194 // "2" is main looper thread
195 bool isHwbinderThread = match.str(2) != "0";
196
197 if (!isHwbinderThread) {
198 return;
199 }
200
201 if (isInUse) {
202 pidInfo->threadUsage++;
203 }
204
205 pidInfo->threadCount++;
206 return;
207 }
208
209 // not reference or thread line
210 return;
211 });
212}
213
Yifan Hong1243dde2017-09-14 17:49:30 -0700214const PidInfo* ListCommand::getPidInfoCached(pid_t serverPid) {
215 auto pair = mCachedPidInfos.insert({serverPid, PidInfo{}});
216 if (pair.second /* did insertion take place? */) {
217 if (!getPidInfo(serverPid, &pair.first->second)) {
218 return nullptr;
219 }
220 }
221 return &pair.first->second;
222}
223
Yifan Hong443df792017-05-09 18:49:45 -0700224// Must process hwbinder services first, then passthrough services.
225void ListCommand::forEachTable(const std::function<void(Table &)> &f) {
226 f(mServicesTable);
227 f(mPassthroughRefTable);
228 f(mImplementationsTable);
229}
230void ListCommand::forEachTable(const std::function<void(const Table &)> &f) const {
231 f(mServicesTable);
232 f(mPassthroughRefTable);
233 f(mImplementationsTable);
234}
235
236void ListCommand::postprocess() {
237 forEachTable([this](Table &table) {
238 if (mSortColumn) {
239 std::sort(table.begin(), table.end(), mSortColumn);
240 }
241 for (TableEntry &entry : table) {
242 entry.serverCmdline = getCmdline(entry.serverPid);
243 removeDeadProcesses(&entry.clientPids);
244 for (auto pid : entry.clientPids) {
245 entry.clientCmdlines.push_back(this->getCmdline(pid));
246 }
247 }
Yifan Hongf31aa052018-02-02 15:17:51 -0800248 for (TableEntry& entry : table) {
249 entry.partition = getPartition(entry.serverPid);
250 }
Yifan Hong443df792017-05-09 18:49:45 -0700251 });
252 // use a double for loop here because lshal doesn't care about efficiency.
253 for (TableEntry &packageEntry : mImplementationsTable) {
254 std::string packageName = packageEntry.interfaceName;
Steven Morelandd4f32b32018-03-06 14:47:58 -0800255 FQName fqPackageName;
256 if (!FQName::parse(packageName.substr(0, packageName.find("::")), &fqPackageName)) {
Yifan Hong443df792017-05-09 18:49:45 -0700257 continue;
258 }
259 for (TableEntry &interfaceEntry : mPassthroughRefTable) {
260 if (interfaceEntry.arch != ARCH_UNKNOWN) {
261 continue;
262 }
Steven Morelandd4f32b32018-03-06 14:47:58 -0800263 FQName interfaceName;
264 if (!FQName::parse(splitFirst(interfaceEntry.interfaceName, '/').first, &interfaceName)) {
Yifan Hong443df792017-05-09 18:49:45 -0700265 continue;
266 }
267 if (interfaceName.getPackageAndVersion() == fqPackageName) {
268 interfaceEntry.arch = packageEntry.arch;
269 }
270 }
271 }
Yifan Hongca3b6602017-09-07 16:44:27 -0700272
273 mServicesTable.setDescription(
274 "All binderized services (registered services through hwservicemanager)");
275 mPassthroughRefTable.setDescription(
276 "All interfaces that getService() has ever return as a passthrough interface;\n"
277 "PIDs / processes shown below might be inaccurate because the process\n"
278 "might have relinquished the interface or might have died.\n"
279 "The Server / Server CMD column can be ignored.\n"
280 "The Clients / Clients CMD column shows all process that have ever dlopen'ed \n"
281 "the library and successfully fetched the passthrough implementation.");
282 mImplementationsTable.setDescription(
283 "All available passthrough implementations (all -impl.so files)");
Yifan Hong443df792017-05-09 18:49:45 -0700284}
285
Yifan Hong77c87822017-06-19 15:47:39 -0700286static inline bool findAndBumpVersion(vintf::ManifestHal* hal, const vintf::Version& version) {
287 for (vintf::Version& v : hal->versions) {
288 if (v.majorVer == version.majorVer) {
289 v.minorVer = std::max(v.minorVer, version.minorVer);
290 return true;
291 }
292 }
293 return false;
294}
295
Yifan Hongca3b6602017-09-07 16:44:27 -0700296void ListCommand::dumpVintf(const NullableOStream<std::ostream>& out) const {
Yifan Hong236301c2017-06-19 12:27:08 -0700297 using vintf::operator|=;
Yifan Hongf31aa052018-02-02 15:17:51 -0800298 using vintf::operator<<;
Yifan Hong443df792017-05-09 18:49:45 -0700299
300 vintf::HalManifest manifest;
Yifan Hongf31aa052018-02-02 15:17:51 -0800301 manifest.setType(toSchemaType(mVintfPartition));
Yifan Hong443df792017-05-09 18:49:45 -0700302 forEachTable([this, &manifest] (const Table &table) {
303 for (const TableEntry &entry : table) {
304
305 std::string fqInstanceName = entry.interfaceName;
306
307 if (&table == &mImplementationsTable) {
308 // Quick hack to work around *'s
309 replaceAll(&fqInstanceName, '*', 'D');
310 }
Steven Morelandd4f32b32018-03-06 14:47:58 -0800311 auto splitFqInstanceName = splitFirst(fqInstanceName, '/');
312 FQName fqName;
313 if (!FQName::parse(splitFqInstanceName.first, &fqName)) {
314 err() << "Warning: '" << splitFqInstanceName.first
Yifan Hong443df792017-05-09 18:49:45 -0700315 << "' is not a valid FQName." << std::endl;
316 continue;
317 }
Yifan Hongf31aa052018-02-02 15:17:51 -0800318
319 if (fqName.package() == gIBaseFqName.package()) {
320 continue; // always remove IBase from manifest
321 }
322
323 Partition partition = resolvePartition(entry.partition, fqName);
324
325 if (partition == Partition::UNKNOWN) {
326 err() << "Warning: Cannot guess the partition of instance " << fqInstanceName
327 << ". It is removed from the generated manifest." << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700328 continue;
329 }
Yifan Hongf31aa052018-02-02 15:17:51 -0800330
331 if (partition != mVintfPartition) {
332 continue; // strip out instances that is in a different partition.
333 }
334
Yifan Hong443df792017-05-09 18:49:45 -0700335 std::string interfaceName =
336 &table == &mImplementationsTable ? "" : fqName.name();
337 std::string instanceName =
Steven Morelandd4f32b32018-03-06 14:47:58 -0800338 &table == &mImplementationsTable ? "" : splitFqInstanceName.second;
Yifan Hong443df792017-05-09 18:49:45 -0700339
340 vintf::Version version{fqName.getPackageMajorVersion(),
341 fqName.getPackageMinorVersion()};
342 vintf::Transport transport;
343 vintf::Arch arch;
344 if (entry.transport == "hwbinder") {
345 transport = vintf::Transport::HWBINDER;
346 arch = vintf::Arch::ARCH_EMPTY;
347 } else if (entry.transport == "passthrough") {
348 transport = vintf::Transport::PASSTHROUGH;
349 switch (entry.arch) {
350 case lshal::ARCH32:
351 arch = vintf::Arch::ARCH_32; break;
352 case lshal::ARCH64:
353 arch = vintf::Arch::ARCH_64; break;
354 case lshal::ARCH_BOTH:
355 arch = vintf::Arch::ARCH_32_64; break;
356 case lshal::ARCH_UNKNOWN: // fallthrough
357 default:
Yifan Hong76ac14a2017-09-08 14:59:04 -0700358 err() << "Warning: '" << fqName.package()
Yifan Hong443df792017-05-09 18:49:45 -0700359 << "' doesn't have bitness info, assuming 32+64." << std::endl;
360 arch = vintf::Arch::ARCH_32_64;
361 }
362 } else {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700363 err() << "Warning: '" << entry.transport << "' is not a valid transport." << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700364 continue;
365 }
366
367 bool done = false;
368 for (vintf::ManifestHal *hal : manifest.getHals(fqName.package())) {
369 if (hal->transport() != transport) {
370 if (transport != vintf::Transport::PASSTHROUGH) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700371 err() << "Fatal: should not reach here. Generated result may be wrong for '"
Yifan Hong236301c2017-06-19 12:27:08 -0700372 << hal->name << "'."
Yifan Hong443df792017-05-09 18:49:45 -0700373 << std::endl;
374 }
375 done = true;
376 break;
377 }
Yifan Hong77c87822017-06-19 15:47:39 -0700378 if (findAndBumpVersion(hal, version)) {
Yifan Hong443df792017-05-09 18:49:45 -0700379 if (&table != &mImplementationsTable) {
380 hal->interfaces[interfaceName].name = interfaceName;
381 hal->interfaces[interfaceName].instances.insert(instanceName);
382 }
Yifan Hong236301c2017-06-19 12:27:08 -0700383 hal->transportArch.arch |= arch;
Yifan Hong443df792017-05-09 18:49:45 -0700384 done = true;
385 break;
386 }
387 }
388 if (done) {
389 continue; // to next TableEntry
390 }
391 decltype(vintf::ManifestHal::interfaces) interfaces;
392 if (&table != &mImplementationsTable) {
393 interfaces[interfaceName].name = interfaceName;
394 interfaces[interfaceName].instances.insert(instanceName);
395 }
396 if (!manifest.add(vintf::ManifestHal{
397 .format = vintf::HalFormat::HIDL,
398 .name = fqName.package(),
399 .versions = {version},
400 .transportArch = {transport, arch},
401 .interfaces = interfaces})) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700402 err() << "Warning: cannot add hal '" << fqInstanceName << "'" << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700403 }
404 }
405 });
Yifan Hongf31aa052018-02-02 15:17:51 -0800406 out << "<!-- " << std::endl
407 << " This is a skeleton " << manifest.type() << " manifest. Notes: " << std::endl
408 << INIT_VINTF_NOTES
409 << "-->" << std::endl;
Yifan Hongacc12122018-01-25 10:49:39 -0800410 out << vintf::gHalManifestConverter(manifest, vintf::SerializeFlag::HALS_ONLY);
Yifan Hong443df792017-05-09 18:49:45 -0700411}
412
Yifan Hongf31aa052018-02-02 15:17:51 -0800413std::string ListCommand::INIT_VINTF_NOTES{
414 " 1. If a HAL is supported in both hwbinder and passthrough transport, \n"
415 " only hwbinder is shown.\n"
416 " 2. It is likely that HALs in passthrough transport does not have\n"
417 " <interface> declared; users will have to write them by hand.\n"
418 " 3. A HAL with lower minor version can be overridden by a HAL with\n"
419 " higher minor version if they have the same name and major version.\n"
420};
421
Yifan Hong443df792017-05-09 18:49:45 -0700422static Architecture fromBaseArchitecture(::android::hidl::base::V1_0::DebugInfo::Architecture a) {
423 switch (a) {
424 case ::android::hidl::base::V1_0::DebugInfo::Architecture::IS_64BIT:
425 return ARCH64;
426 case ::android::hidl::base::V1_0::DebugInfo::Architecture::IS_32BIT:
427 return ARCH32;
428 case ::android::hidl::base::V1_0::DebugInfo::Architecture::UNKNOWN: // fallthrough
429 default:
430 return ARCH_UNKNOWN;
431 }
432}
433
Yifan Hongca3b6602017-09-07 16:44:27 -0700434void ListCommand::dumpTable(const NullableOStream<std::ostream>& out) const {
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700435 if (mNeat) {
Yifan Hongd4a77e82017-09-06 19:40:24 -0700436 MergedTable({&mServicesTable, &mPassthroughRefTable, &mImplementationsTable})
Yifan Hongca3b6602017-09-07 16:44:27 -0700437 .createTextTable().dump(out.buf());
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700438 return;
439 }
440
Yifan Hongca3b6602017-09-07 16:44:27 -0700441 forEachTable([this, &out](const Table &table) {
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700442
Yifan Hongd4a77e82017-09-06 19:40:24 -0700443 // We're only interested in dumping debug info for already
444 // instantiated services. There's little value in dumping the
445 // debug info for a service we create on the fly, so we only operate
446 // on the "mServicesTable".
447 std::function<std::string(const std::string&)> emitDebugInfo = nullptr;
448 if (mEmitDebugInfo && &table == &mServicesTable) {
449 emitDebugInfo = [this](const auto& iName) {
Yifan Hongca3b6602017-09-07 16:44:27 -0700450 std::stringstream ss;
Yifan Hongd4a77e82017-09-06 19:40:24 -0700451 auto pair = splitFirst(iName, '/');
Steven Moreland5f328892018-01-18 14:38:07 -0800452 mLshal.emitDebugInfo(pair.first, pair.second, {},
453 false /* excludesParentInstances */, ss,
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700454 NullableOStream<std::ostream>(nullptr));
Yifan Hongca3b6602017-09-07 16:44:27 -0700455 return ss.str();
Yifan Hongd4a77e82017-09-06 19:40:24 -0700456 };
Yifan Hong443df792017-05-09 18:49:45 -0700457 }
Yifan Hongca3b6602017-09-07 16:44:27 -0700458 table.createTextTable(mNeat, emitDebugInfo).dump(out.buf());
459 out << std::endl;
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700460 });
Yifan Hong443df792017-05-09 18:49:45 -0700461}
462
Yifan Hongca3b6602017-09-07 16:44:27 -0700463Status ListCommand::dump() {
464 auto dump = mVintf ? &ListCommand::dumpVintf : &ListCommand::dumpTable;
465
466 if (mFileOutputPath.empty()) {
467 (*this.*dump)(out());
468 return OK;
Yifan Hong443df792017-05-09 18:49:45 -0700469 }
Yifan Hongca3b6602017-09-07 16:44:27 -0700470
471 std::ofstream fileOutput(mFileOutputPath);
472 if (!fileOutput.is_open()) {
473 err() << "Could not open file '" << mFileOutputPath << "'." << std::endl;
474 return IO_ERROR;
475 }
476 chown(mFileOutputPath.c_str(), AID_SHELL, AID_SHELL);
477
478 (*this.*dump)(NullableOStream<std::ostream>(fileOutput));
479
480 fileOutput.flush();
481 fileOutput.close();
482 return OK;
Yifan Hong443df792017-05-09 18:49:45 -0700483}
484
485void ListCommand::putEntry(TableEntrySource source, TableEntry &&entry) {
486 Table *table = nullptr;
487 switch (source) {
488 case HWSERVICEMANAGER_LIST :
489 table = &mServicesTable; break;
490 case PTSERVICEMANAGER_REG_CLIENT :
491 table = &mPassthroughRefTable; break;
492 case LIST_DLLIB :
493 table = &mImplementationsTable; break;
494 default:
Yifan Hong76ac14a2017-09-08 14:59:04 -0700495 err() << "Error: Unknown source of entry " << source << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700496 }
497 if (table) {
Yifan Hongd4a77e82017-09-06 19:40:24 -0700498 table->add(std::forward<TableEntry>(entry));
Yifan Hong443df792017-05-09 18:49:45 -0700499 }
500}
501
502Status ListCommand::fetchAllLibraries(const sp<IServiceManager> &manager) {
503 using namespace ::android::hardware;
504 using namespace ::android::hidl::manager::V1_0;
505 using namespace ::android::hidl::base::V1_0;
Yifan Hongf2d557b2017-05-24 19:45:02 -0700506 using std::literals::chrono_literals::operator""s;
507 auto ret = timeoutIPC(2s, manager, &IServiceManager::debugDump, [&] (const auto &infos) {
Yifan Hong443df792017-05-09 18:49:45 -0700508 std::map<std::string, TableEntry> entries;
509 for (const auto &info : infos) {
510 std::string interfaceName = std::string{info.interfaceName.c_str()} + "/" +
511 std::string{info.instanceName.c_str()};
512 entries.emplace(interfaceName, TableEntry{
513 .interfaceName = interfaceName,
514 .transport = "passthrough",
Yifan Hongf2d557b2017-05-24 19:45:02 -0700515 .clientPids = info.clientPids,
Yifan Hong443df792017-05-09 18:49:45 -0700516 }).first->second.arch |= fromBaseArchitecture(info.arch);
517 }
518 for (auto &&pair : entries) {
519 putEntry(LIST_DLLIB, std::move(pair.second));
520 }
521 });
522 if (!ret.isOk()) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700523 err() << "Error: Failed to call list on getPassthroughServiceManager(): "
Yifan Hong443df792017-05-09 18:49:45 -0700524 << ret.description() << std::endl;
525 return DUMP_ALL_LIBS_ERROR;
526 }
527 return OK;
528}
529
530Status ListCommand::fetchPassthrough(const sp<IServiceManager> &manager) {
531 using namespace ::android::hardware;
532 using namespace ::android::hardware::details;
533 using namespace ::android::hidl::manager::V1_0;
534 using namespace ::android::hidl::base::V1_0;
535 auto ret = timeoutIPC(manager, &IServiceManager::debugDump, [&] (const auto &infos) {
536 for (const auto &info : infos) {
537 if (info.clientPids.size() <= 0) {
538 continue;
539 }
540 putEntry(PTSERVICEMANAGER_REG_CLIENT, {
541 .interfaceName =
542 std::string{info.interfaceName.c_str()} + "/" +
543 std::string{info.instanceName.c_str()},
544 .transport = "passthrough",
545 .serverPid = info.clientPids.size() == 1 ? info.clientPids[0] : NO_PID,
Yifan Hong443df792017-05-09 18:49:45 -0700546 .clientPids = info.clientPids,
547 .arch = fromBaseArchitecture(info.arch)
548 });
549 }
550 });
551 if (!ret.isOk()) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700552 err() << "Error: Failed to call debugDump on defaultServiceManager(): "
Yifan Hong443df792017-05-09 18:49:45 -0700553 << ret.description() << std::endl;
554 return DUMP_PASSTHROUGH_ERROR;
555 }
556 return OK;
557}
558
559Status ListCommand::fetchBinderized(const sp<IServiceManager> &manager) {
Yifan Hong443df792017-05-09 18:49:45 -0700560 const std::string mode = "hwbinder";
561
562 hidl_vec<hidl_string> fqInstanceNames;
563 // copying out for timeoutIPC
564 auto listRet = timeoutIPC(manager, &IServiceManager::list, [&] (const auto &names) {
565 fqInstanceNames = names;
566 });
567 if (!listRet.isOk()) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700568 err() << "Error: Failed to list services for " << mode << ": "
Yifan Hong443df792017-05-09 18:49:45 -0700569 << listRet.description() << std::endl;
570 return DUMP_BINDERIZED_ERROR;
571 }
572
573 Status status = OK;
Yifan Hong22ea7b82017-09-14 18:07:43 -0700574 std::map<std::string, TableEntry> allTableEntries;
Yifan Hong443df792017-05-09 18:49:45 -0700575 for (const auto &fqInstanceName : fqInstanceNames) {
Yifan Hong22ea7b82017-09-14 18:07:43 -0700576 // create entry and default assign all fields.
577 TableEntry& entry = allTableEntries[fqInstanceName];
578 entry.interfaceName = fqInstanceName;
579 entry.transport = mode;
580
581 status |= fetchBinderizedEntry(manager, &entry);
582 }
583
584 for (auto& pair : allTableEntries) {
585 putEntry(HWSERVICEMANAGER_LIST, std::move(pair.second));
586 }
587 return status;
588}
589
590Status ListCommand::fetchBinderizedEntry(const sp<IServiceManager> &manager,
591 TableEntry *entry) {
592 Status status = OK;
593 const auto handleError = [&](Status additionalError, const std::string& msg) {
594 err() << "Warning: Skipping \"" << entry->interfaceName << "\": " << msg << std::endl;
595 status |= DUMP_BINDERIZED_ERROR | additionalError;
596 };
597
598 const auto pair = splitFirst(entry->interfaceName, '/');
599 const auto &serviceName = pair.first;
600 const auto &instanceName = pair.second;
601 auto getRet = timeoutIPC(manager, &IServiceManager::get, serviceName, instanceName);
602 if (!getRet.isOk()) {
603 handleError(TRANSACTION_ERROR,
604 "cannot be fetched from service manager:" + getRet.description());
605 return status;
606 }
607 sp<IBase> service = getRet;
608 if (service == nullptr) {
609 handleError(NO_INTERFACE, "cannot be fetched from service manager (null)");
610 return status;
611 }
612
613 // getDebugInfo
614 do {
615 DebugInfo debugInfo;
616 auto debugRet = timeoutIPC(service, &IBase::getDebugInfo, [&] (const auto &received) {
617 debugInfo = received;
Yifan Hong443df792017-05-09 18:49:45 -0700618 });
619 if (!debugRet.isOk()) {
Yifan Hong22ea7b82017-09-14 18:07:43 -0700620 handleError(TRANSACTION_ERROR,
621 "debugging information cannot be retrieved: " + debugRet.description());
622 break; // skip getPidInfo
Yifan Hong443df792017-05-09 18:49:45 -0700623 }
Steven Morelandd8e20192017-05-24 11:23:08 -0700624
Yifan Hong22ea7b82017-09-14 18:07:43 -0700625 entry->serverPid = debugInfo.pid;
626 entry->serverObjectAddress = debugInfo.ptr;
627 entry->arch = fromBaseArchitecture(debugInfo.arch);
Steven Morelandd8e20192017-05-24 11:23:08 -0700628
Yifan Hong22ea7b82017-09-14 18:07:43 -0700629 if (debugInfo.pid != NO_PID) {
630 const PidInfo* pidInfo = getPidInfoCached(debugInfo.pid);
631 if (pidInfo == nullptr) {
632 handleError(IO_ERROR,
633 "no information for PID " + std::to_string(debugInfo.pid) +
634 ", are you root?");
635 break;
636 }
637 if (debugInfo.ptr != NO_PTR) {
638 auto it = pidInfo->refPids.find(debugInfo.ptr);
639 if (it != pidInfo->refPids.end()) {
640 entry->clientPids = it->second;
641 }
642 }
643 entry->threadUsage = pidInfo->threadUsage;
644 entry->threadCount = pidInfo->threadCount;
645 }
646 } while (0);
Yifan Hongfee209d2017-09-14 18:23:38 -0700647
648 // hash
649 do {
650 ssize_t hashIndex = -1;
651 auto ifaceChainRet = timeoutIPC(service, &IBase::interfaceChain, [&] (const auto& c) {
652 for (size_t i = 0; i < c.size(); ++i) {
653 if (serviceName == c[i]) {
654 hashIndex = static_cast<ssize_t>(i);
655 break;
656 }
657 }
658 });
659 if (!ifaceChainRet.isOk()) {
660 handleError(TRANSACTION_ERROR,
661 "interfaceChain fails: " + ifaceChainRet.description());
662 break; // skip getHashChain
663 }
664 if (hashIndex < 0) {
665 handleError(BAD_IMPL, "Interface name does not exist in interfaceChain.");
666 break; // skip getHashChain
667 }
668 auto hashRet = timeoutIPC(service, &IBase::getHashChain, [&] (const auto& hashChain) {
669 if (static_cast<size_t>(hashIndex) >= hashChain.size()) {
670 handleError(BAD_IMPL,
671 "interfaceChain indicates position " + std::to_string(hashIndex) +
672 " but getHashChain returns " + std::to_string(hashChain.size()) +
673 " hashes");
674 return;
675 }
676
677 auto&& hashArray = hashChain[hashIndex];
678 std::vector<uint8_t> hashVec{hashArray.data(), hashArray.data() + hashArray.size()};
679 entry->hash = Hash::hexString(hashVec);
680 });
681 if (!hashRet.isOk()) {
682 handleError(TRANSACTION_ERROR, "getHashChain failed: " + hashRet.description());
683 }
684 } while (0);
Yifan Hong443df792017-05-09 18:49:45 -0700685 return status;
686}
687
688Status ListCommand::fetch() {
689 Status status = OK;
Yifan Hong9881df92017-05-10 14:33:05 -0700690 auto bManager = mLshal.serviceManager();
Yifan Hong443df792017-05-09 18:49:45 -0700691 if (bManager == nullptr) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700692 err() << "Failed to get defaultServiceManager()!" << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700693 status |= NO_BINDERIZED_MANAGER;
694 } else {
695 status |= fetchBinderized(bManager);
696 // Passthrough PIDs are registered to the binderized manager as well.
697 status |= fetchPassthrough(bManager);
698 }
699
Yifan Hong9881df92017-05-10 14:33:05 -0700700 auto pManager = mLshal.passthroughManager();
Yifan Hong443df792017-05-09 18:49:45 -0700701 if (pManager == nullptr) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700702 err() << "Failed to get getPassthroughServiceManager()!" << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700703 status |= NO_PASSTHROUGH_MANAGER;
704 } else {
705 status |= fetchAllLibraries(pManager);
706 }
707 return status;
708}
709
Yifan Honga6b93f02017-09-13 16:53:37 -0700710void ListCommand::registerAllOptions() {
711 int v = mOptions.size();
712 // A list of acceptable command line options
713 // key: value returned by getopt_long
714 // long options with short alternatives
715 mOptions.push_back({'h', "help", no_argument, v++, [](ListCommand*, const char*) {
716 return USAGE;
717 }, ""});
718 mOptions.push_back({'i', "interface", no_argument, v++, [](ListCommand* thiz, const char*) {
719 thiz->mSelectedColumns.push_back(TableColumnType::INTERFACE_NAME);
720 return OK;
721 }, "print the instance name column"});
Yifan Hongfee209d2017-09-14 18:23:38 -0700722 mOptions.push_back({'l', "released", no_argument, v++, [](ListCommand* thiz, const char*) {
723 thiz->mSelectedColumns.push_back(TableColumnType::RELEASED);
724 return OK;
725 }, "print the 'is released?' column\n(Y=released, empty=unreleased or unknown)"});
Yifan Honga6b93f02017-09-13 16:53:37 -0700726 mOptions.push_back({'t', "transport", no_argument, v++, [](ListCommand* thiz, const char*) {
727 thiz->mSelectedColumns.push_back(TableColumnType::TRANSPORT);
728 return OK;
729 }, "print the transport mode column"});
730 mOptions.push_back({'r', "arch", no_argument, v++, [](ListCommand* thiz, const char*) {
731 thiz->mSelectedColumns.push_back(TableColumnType::ARCH);
732 return OK;
733 }, "print the bitness column"});
Yifan Hongfee209d2017-09-14 18:23:38 -0700734 mOptions.push_back({'s', "hash", no_argument, v++, [](ListCommand* thiz, const char*) {
735 thiz->mSelectedColumns.push_back(TableColumnType::HASH);
736 return OK;
737 }, "print hash of the interface"});
Yifan Honga6b93f02017-09-13 16:53:37 -0700738 mOptions.push_back({'p', "pid", no_argument, v++, [](ListCommand* thiz, const char*) {
739 thiz->mSelectedColumns.push_back(TableColumnType::SERVER_PID);
740 return OK;
741 }, "print the server PID, or server cmdline if -m is set"});
742 mOptions.push_back({'a', "address", no_argument, v++, [](ListCommand* thiz, const char*) {
743 thiz->mSelectedColumns.push_back(TableColumnType::SERVER_ADDR);
744 return OK;
745 }, "print the server object address column"});
746 mOptions.push_back({'c', "clients", no_argument, v++, [](ListCommand* thiz, const char*) {
747 thiz->mSelectedColumns.push_back(TableColumnType::CLIENT_PIDS);
748 return OK;
749 }, "print the client PIDs, or client cmdlines if -m is set"});
750 mOptions.push_back({'e', "threads", no_argument, v++, [](ListCommand* thiz, const char*) {
751 thiz->mSelectedColumns.push_back(TableColumnType::THREADS);
752 return OK;
753 }, "print currently used/available threads\n(note, available threads created lazily)"});
754 mOptions.push_back({'m', "cmdline", no_argument, v++, [](ListCommand* thiz, const char*) {
755 thiz->mEnableCmdlines = true;
756 return OK;
757 }, "print cmdline instead of PIDs"});
758 mOptions.push_back({'d', "debug", optional_argument, v++, [](ListCommand* thiz, const char* arg) {
759 thiz->mEmitDebugInfo = true;
760 if (arg) thiz->mFileOutputPath = arg;
761 return OK;
762 }, "Emit debug info from\nIBase::debug with empty options. Cannot be used with --neat.\n"
763 "Writes to specified file if 'arg' is provided, otherwise stdout."});
764
765 // long options without short alternatives
766 mOptions.push_back({'\0', "init-vintf", no_argument, v++, [](ListCommand* thiz, const char* arg) {
767 thiz->mVintf = true;
Yifan Hongf31aa052018-02-02 15:17:51 -0800768 if (thiz->mVintfPartition == Partition::UNKNOWN)
769 thiz->mVintfPartition = Partition::VENDOR;
Yifan Honga6b93f02017-09-13 16:53:37 -0700770 if (arg) thiz->mFileOutputPath = arg;
771 return OK;
772 }, "form a skeleton HAL manifest to specified file,\nor stdout if no file specified."});
Yifan Hongf31aa052018-02-02 15:17:51 -0800773 mOptions.push_back({'\0', "init-vintf-partition", required_argument, v++, [](ListCommand* thiz, const char* arg) {
774 if (!arg) return USAGE;
775 thiz->mVintfPartition = android::procpartition::parsePartition(arg);
776 if (thiz->mVintfPartition == Partition::UNKNOWN) return USAGE;
777 return OK;
778 }, "Specify the partition of the HAL manifest\ngenerated by --init-vintf.\n"
779 "Valid values are 'system', 'vendor', and 'odm'. Default is 'vendor'."});
Yifan Honga6b93f02017-09-13 16:53:37 -0700780 mOptions.push_back({'\0', "sort", required_argument, v++, [](ListCommand* thiz, const char* arg) {
781 if (strcmp(arg, "interface") == 0 || strcmp(arg, "i") == 0) {
782 thiz->mSortColumn = TableEntry::sortByInterfaceName;
783 } else if (strcmp(arg, "pid") == 0 || strcmp(arg, "p") == 0) {
784 thiz->mSortColumn = TableEntry::sortByServerPid;
785 } else {
786 thiz->err() << "Unrecognized sorting column: " << arg << std::endl;
787 return USAGE;
788 }
789 return OK;
790 }, "sort by a column. 'arg' can be (i|interface) or (p|pid)."});
791 mOptions.push_back({'\0', "neat", no_argument, v++, [](ListCommand* thiz, const char*) {
792 thiz->mNeat = true;
793 return OK;
794 }, "output is machine parsable (no explanatory text).\nCannot be used with --debug."});
795}
796
797// Create 'longopts' argument to getopt_long. Caller is responsible for maintaining
798// the lifetime of "options" during the usage of the returned array.
799static std::unique_ptr<struct option[]> getLongOptions(
800 const ListCommand::RegisteredOptions& options,
801 int* longOptFlag) {
802 std::unique_ptr<struct option[]> ret{new struct option[options.size() + 1]};
803 int i = 0;
804 for (const auto& e : options) {
805 ret[i].name = e.longOption.c_str();
806 ret[i].has_arg = e.hasArg;
807 ret[i].flag = longOptFlag;
808 ret[i].val = e.val;
809
810 i++;
811 }
812 // getopt_long last option has all zeros
813 ret[i].name = NULL;
814 ret[i].has_arg = 0;
815 ret[i].flag = NULL;
816 ret[i].val = 0;
817
818 return ret;
819}
820
821// Create 'optstring' argument to getopt_long.
822static std::string getShortOptions(const ListCommand::RegisteredOptions& options) {
823 std::stringstream ss;
824 for (const auto& e : options) {
825 if (e.shortOption != '\0') {
826 ss << e.shortOption;
827 }
828 }
829 return ss.str();
830}
831
Yifan Honga8bedc62017-09-08 18:00:31 -0700832Status ListCommand::parseArgs(const Arg &arg) {
Yifan Hong443df792017-05-09 18:49:45 -0700833
Yifan Honga6b93f02017-09-13 16:53:37 -0700834 if (mOptions.empty()) {
835 registerAllOptions();
836 }
837 int longOptFlag;
838 std::unique_ptr<struct option[]> longOptions = getLongOptions(mOptions, &longOptFlag);
839 std::string shortOptions = getShortOptions(mOptions);
Yifan Hongd4a77e82017-09-06 19:40:24 -0700840
Yifan Honga8bedc62017-09-08 18:00:31 -0700841 // suppress output to std::err for unknown options
842 opterr = 0;
843
Yifan Hong443df792017-05-09 18:49:45 -0700844 int optionIndex;
845 int c;
846 // Lshal::parseArgs has set optind to the next option to parse
847 for (;;) {
Yifan Hong443df792017-05-09 18:49:45 -0700848 c = getopt_long(arg.argc, arg.argv,
Yifan Honga6b93f02017-09-13 16:53:37 -0700849 shortOptions.c_str(), longOptions.get(), &optionIndex);
Yifan Hong443df792017-05-09 18:49:45 -0700850 if (c == -1) {
851 break;
852 }
Yifan Honga6b93f02017-09-13 16:53:37 -0700853 const RegisteredOption* found = nullptr;
854 if (c == 0) {
855 // see long option
856 for (const auto& e : mOptions) {
857 if (longOptFlag == e.val) found = &e;
Yifan Hong443df792017-05-09 18:49:45 -0700858 }
Yifan Honga6b93f02017-09-13 16:53:37 -0700859 } else {
860 // see short option
861 for (const auto& e : mOptions) {
862 if (c == e.shortOption) found = &e;
863 }
Yifan Hong443df792017-05-09 18:49:45 -0700864 }
Yifan Honga6b93f02017-09-13 16:53:37 -0700865
866 if (found == nullptr) {
867 // see unrecognized options
Yifan Honga8bedc62017-09-08 18:00:31 -0700868 err() << "unrecognized option `" << arg.argv[optind - 1] << "'" << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700869 return USAGE;
870 }
Yifan Honga6b93f02017-09-13 16:53:37 -0700871
872 Status status = found->op(this, optarg);
873 if (status != OK) {
874 return status;
875 }
Yifan Hong443df792017-05-09 18:49:45 -0700876 }
877 if (optind < arg.argc) {
878 // see non option
Yifan Honga8bedc62017-09-08 18:00:31 -0700879 err() << "unrecognized option `" << arg.argv[optind] << "'" << std::endl;
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700880 return USAGE;
881 }
882
883 if (mNeat && mEmitDebugInfo) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700884 err() << "Error: --neat should not be used with --debug." << std::endl;
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700885 return USAGE;
Yifan Hong443df792017-05-09 18:49:45 -0700886 }
887
Yifan Honga6b93f02017-09-13 16:53:37 -0700888 if (mSelectedColumns.empty()) {
Yifan Hongfee209d2017-09-14 18:23:38 -0700889 mSelectedColumns = {TableColumnType::RELEASED,
890 TableColumnType::INTERFACE_NAME, TableColumnType::THREADS,
Yifan Hong05494a52017-08-29 18:50:00 -0700891 TableColumnType::SERVER_PID, TableColumnType::CLIENT_PIDS};
Yifan Hong443df792017-05-09 18:49:45 -0700892 }
Yifan Hongd4a77e82017-09-06 19:40:24 -0700893
Yifan Honga6b93f02017-09-13 16:53:37 -0700894 if (mEnableCmdlines) {
895 for (size_t i = 0; i < mSelectedColumns.size(); ++i) {
896 if (mSelectedColumns[i] == TableColumnType::SERVER_PID) {
897 mSelectedColumns[i] = TableColumnType::SERVER_CMD;
Yifan Hongd4a77e82017-09-06 19:40:24 -0700898 }
Yifan Honga6b93f02017-09-13 16:53:37 -0700899 if (mSelectedColumns[i] == TableColumnType::CLIENT_PIDS) {
900 mSelectedColumns[i] = TableColumnType::CLIENT_CMDS;
Yifan Hongd4a77e82017-09-06 19:40:24 -0700901 }
902 }
903 }
904
Yifan Honga6b93f02017-09-13 16:53:37 -0700905 forEachTable([this] (Table& table) {
906 table.setSelectedColumns(this->mSelectedColumns);
Yifan Hongd4a77e82017-09-06 19:40:24 -0700907 });
908
Yifan Hong443df792017-05-09 18:49:45 -0700909 return OK;
910}
911
Yifan Honga8bedc62017-09-08 18:00:31 -0700912Status ListCommand::main(const Arg &arg) {
913 Status status = parseArgs(arg);
Yifan Hong443df792017-05-09 18:49:45 -0700914 if (status != OK) {
915 return status;
916 }
917 status = fetch();
918 postprocess();
Yifan Hongca3b6602017-09-07 16:44:27 -0700919 status |= dump();
Yifan Hong443df792017-05-09 18:49:45 -0700920 return status;
921}
922
Yifan Honga6b93f02017-09-13 16:53:37 -0700923static std::vector<std::string> splitString(const std::string &s, char c) {
924 std::vector<std::string> components;
925
926 size_t startPos = 0;
927 size_t matchPos;
928 while ((matchPos = s.find(c, startPos)) != std::string::npos) {
929 components.push_back(s.substr(startPos, matchPos - startPos));
930 startPos = matchPos + 1;
931 }
932
933 if (startPos <= s.length()) {
934 components.push_back(s.substr(startPos));
935 }
936 return components;
937}
938
939const std::string& ListCommand::RegisteredOption::getHelpMessageForArgument() const {
940 static const std::string empty{};
941 static const std::string optional{"[=<arg>]"};
942 static const std::string required{"=<arg>"};
943
944 if (hasArg == optional_argument) {
945 return optional;
946 }
947 if (hasArg == required_argument) {
948 return required;
949 }
950 return empty;
951}
952
Yifan Honga8bedc62017-09-08 18:00:31 -0700953void ListCommand::usage() const {
954
Yifan Honga6b93f02017-09-13 16:53:37 -0700955 err() << "list:" << std::endl
956 << " lshal" << std::endl
957 << " lshal list" << std::endl
Yifan Hongfee209d2017-09-14 18:23:38 -0700958 << " List all hals with default ordering and columns (`lshal list -riepc`)" << std::endl
Yifan Honga6b93f02017-09-13 16:53:37 -0700959 << " lshal list [-h|--help]" << std::endl
960 << " -h, --help: Print help message for list (`lshal help list`)" << std::endl
961 << " lshal [list] [OPTIONS...]" << std::endl;
962 for (const auto& e : mOptions) {
963 if (e.help.empty()) {
964 continue;
965 }
966 err() << " ";
967 if (e.shortOption != '\0')
968 err() << "-" << e.shortOption << e.getHelpMessageForArgument();
969 if (e.shortOption != '\0' && !e.longOption.empty())
970 err() << ", ";
971 if (!e.longOption.empty())
972 err() << "--" << e.longOption << e.getHelpMessageForArgument();
973 err() << ": ";
974 std::vector<std::string> lines = splitString(e.help, '\n');
975 for (const auto& line : lines) {
976 if (&line != &lines.front())
977 err() << " ";
978 err() << line << std::endl;
979 }
980 }
Yifan Honga8bedc62017-09-08 18:00:31 -0700981}
982
Yifan Hong443df792017-05-09 18:49:45 -0700983} // namespace lshal
984} // namespace android
Yifan Hong05494a52017-08-29 18:50:00 -0700985