blob: 29ef648bb3faaaf7a44468178d4b873952418f23 [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(
Steven Moreland3d2c1e12018-03-14 10:41:13 -0700283 "All available passthrough implementations (all -impl.so files).\n"
284 "These may return subclasses through their respective HIDL_FETCH_I* functions.");
Yifan Hong443df792017-05-09 18:49:45 -0700285}
286
Yifan Hong77c87822017-06-19 15:47:39 -0700287static inline bool findAndBumpVersion(vintf::ManifestHal* hal, const vintf::Version& version) {
288 for (vintf::Version& v : hal->versions) {
289 if (v.majorVer == version.majorVer) {
290 v.minorVer = std::max(v.minorVer, version.minorVer);
291 return true;
292 }
293 }
294 return false;
295}
296
Yifan Hongca3b6602017-09-07 16:44:27 -0700297void ListCommand::dumpVintf(const NullableOStream<std::ostream>& out) const {
Yifan Hong236301c2017-06-19 12:27:08 -0700298 using vintf::operator|=;
Yifan Hongf31aa052018-02-02 15:17:51 -0800299 using vintf::operator<<;
Yifan Hong443df792017-05-09 18:49:45 -0700300
301 vintf::HalManifest manifest;
Yifan Hongf31aa052018-02-02 15:17:51 -0800302 manifest.setType(toSchemaType(mVintfPartition));
Yifan Hong443df792017-05-09 18:49:45 -0700303 forEachTable([this, &manifest] (const Table &table) {
304 for (const TableEntry &entry : table) {
305
306 std::string fqInstanceName = entry.interfaceName;
307
308 if (&table == &mImplementationsTable) {
309 // Quick hack to work around *'s
310 replaceAll(&fqInstanceName, '*', 'D');
311 }
Steven Morelandd4f32b32018-03-06 14:47:58 -0800312 auto splitFqInstanceName = splitFirst(fqInstanceName, '/');
313 FQName fqName;
314 if (!FQName::parse(splitFqInstanceName.first, &fqName)) {
315 err() << "Warning: '" << splitFqInstanceName.first
Yifan Hong443df792017-05-09 18:49:45 -0700316 << "' is not a valid FQName." << std::endl;
317 continue;
318 }
Yifan Hongf31aa052018-02-02 15:17:51 -0800319
320 if (fqName.package() == gIBaseFqName.package()) {
321 continue; // always remove IBase from manifest
322 }
323
324 Partition partition = resolvePartition(entry.partition, fqName);
325
326 if (partition == Partition::UNKNOWN) {
327 err() << "Warning: Cannot guess the partition of instance " << fqInstanceName
328 << ". It is removed from the generated manifest." << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700329 continue;
330 }
Yifan Hongf31aa052018-02-02 15:17:51 -0800331
332 if (partition != mVintfPartition) {
333 continue; // strip out instances that is in a different partition.
334 }
335
Yifan Hong443df792017-05-09 18:49:45 -0700336 std::string interfaceName =
337 &table == &mImplementationsTable ? "" : fqName.name();
338 std::string instanceName =
Steven Morelandd4f32b32018-03-06 14:47:58 -0800339 &table == &mImplementationsTable ? "" : splitFqInstanceName.second;
Yifan Hong443df792017-05-09 18:49:45 -0700340
341 vintf::Version version{fqName.getPackageMajorVersion(),
342 fqName.getPackageMinorVersion()};
343 vintf::Transport transport;
344 vintf::Arch arch;
345 if (entry.transport == "hwbinder") {
346 transport = vintf::Transport::HWBINDER;
347 arch = vintf::Arch::ARCH_EMPTY;
348 } else if (entry.transport == "passthrough") {
349 transport = vintf::Transport::PASSTHROUGH;
350 switch (entry.arch) {
351 case lshal::ARCH32:
352 arch = vintf::Arch::ARCH_32; break;
353 case lshal::ARCH64:
354 arch = vintf::Arch::ARCH_64; break;
355 case lshal::ARCH_BOTH:
356 arch = vintf::Arch::ARCH_32_64; break;
357 case lshal::ARCH_UNKNOWN: // fallthrough
358 default:
Yifan Hong76ac14a2017-09-08 14:59:04 -0700359 err() << "Warning: '" << fqName.package()
Yifan Hong443df792017-05-09 18:49:45 -0700360 << "' doesn't have bitness info, assuming 32+64." << std::endl;
361 arch = vintf::Arch::ARCH_32_64;
362 }
363 } else {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700364 err() << "Warning: '" << entry.transport << "' is not a valid transport." << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700365 continue;
366 }
367
368 bool done = false;
369 for (vintf::ManifestHal *hal : manifest.getHals(fqName.package())) {
370 if (hal->transport() != transport) {
371 if (transport != vintf::Transport::PASSTHROUGH) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700372 err() << "Fatal: should not reach here. Generated result may be wrong for '"
Yifan Hong236301c2017-06-19 12:27:08 -0700373 << hal->name << "'."
Yifan Hong443df792017-05-09 18:49:45 -0700374 << std::endl;
375 }
376 done = true;
377 break;
378 }
Yifan Hong77c87822017-06-19 15:47:39 -0700379 if (findAndBumpVersion(hal, version)) {
Yifan Hong443df792017-05-09 18:49:45 -0700380 if (&table != &mImplementationsTable) {
Yifan Hong3cd623f2018-03-22 13:23:33 -0700381 hal->insertLegacyInstance(interfaceName, instanceName);
Yifan Hong443df792017-05-09 18:49:45 -0700382 }
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 }
Yifan Hong3cd623f2018-03-22 13:23:33 -0700391 vintf::ManifestHal manifestHal{
Yifan Honga63a16b2018-03-13 14:03:03 -0700392 vintf::HalFormat::HIDL,
393 std::string{fqName.package()},
394 {version},
395 {transport, arch},
Yifan Hong3cd623f2018-03-22 13:23:33 -0700396 {}};
397 if (&table != &mImplementationsTable) {
398 manifestHal.insertLegacyInstance(interfaceName, instanceName);
399 }
400 if (!manifest.add(std::move(manifestHal))) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700401 err() << "Warning: cannot add hal '" << fqInstanceName << "'" << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700402 }
403 }
404 });
Yifan Hongf31aa052018-02-02 15:17:51 -0800405 out << "<!-- " << std::endl
406 << " This is a skeleton " << manifest.type() << " manifest. Notes: " << std::endl
407 << INIT_VINTF_NOTES
408 << "-->" << std::endl;
Yifan Hong3cd623f2018-03-22 13:23:33 -0700409 out << vintf::gHalManifestConverter(manifest, vintf::SerializeFlag::HALS_NO_FQNAME);
Yifan Hong443df792017-05-09 18:49:45 -0700410}
411
Yifan Hongf31aa052018-02-02 15:17:51 -0800412std::string ListCommand::INIT_VINTF_NOTES{
413 " 1. If a HAL is supported in both hwbinder and passthrough transport, \n"
414 " only hwbinder is shown.\n"
415 " 2. It is likely that HALs in passthrough transport does not have\n"
416 " <interface> declared; users will have to write them by hand.\n"
417 " 3. A HAL with lower minor version can be overridden by a HAL with\n"
418 " higher minor version if they have the same name and major version.\n"
419};
420
Yifan Hong443df792017-05-09 18:49:45 -0700421static Architecture fromBaseArchitecture(::android::hidl::base::V1_0::DebugInfo::Architecture a) {
422 switch (a) {
423 case ::android::hidl::base::V1_0::DebugInfo::Architecture::IS_64BIT:
424 return ARCH64;
425 case ::android::hidl::base::V1_0::DebugInfo::Architecture::IS_32BIT:
426 return ARCH32;
427 case ::android::hidl::base::V1_0::DebugInfo::Architecture::UNKNOWN: // fallthrough
428 default:
429 return ARCH_UNKNOWN;
430 }
431}
432
Yifan Hongca3b6602017-09-07 16:44:27 -0700433void ListCommand::dumpTable(const NullableOStream<std::ostream>& out) const {
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700434 if (mNeat) {
Yifan Hongd4a77e82017-09-06 19:40:24 -0700435 MergedTable({&mServicesTable, &mPassthroughRefTable, &mImplementationsTable})
Yifan Hongca3b6602017-09-07 16:44:27 -0700436 .createTextTable().dump(out.buf());
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700437 return;
438 }
439
Yifan Hongca3b6602017-09-07 16:44:27 -0700440 forEachTable([this, &out](const Table &table) {
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700441
Yifan Hongd4a77e82017-09-06 19:40:24 -0700442 // We're only interested in dumping debug info for already
443 // instantiated services. There's little value in dumping the
444 // debug info for a service we create on the fly, so we only operate
445 // on the "mServicesTable".
446 std::function<std::string(const std::string&)> emitDebugInfo = nullptr;
447 if (mEmitDebugInfo && &table == &mServicesTable) {
448 emitDebugInfo = [this](const auto& iName) {
Yifan Hongca3b6602017-09-07 16:44:27 -0700449 std::stringstream ss;
Yifan Hongd4a77e82017-09-06 19:40:24 -0700450 auto pair = splitFirst(iName, '/');
Steven Moreland5f328892018-01-18 14:38:07 -0800451 mLshal.emitDebugInfo(pair.first, pair.second, {},
452 false /* excludesParentInstances */, ss,
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700453 NullableOStream<std::ostream>(nullptr));
Yifan Hongca3b6602017-09-07 16:44:27 -0700454 return ss.str();
Yifan Hongd4a77e82017-09-06 19:40:24 -0700455 };
Yifan Hong443df792017-05-09 18:49:45 -0700456 }
Yifan Hongca3b6602017-09-07 16:44:27 -0700457 table.createTextTable(mNeat, emitDebugInfo).dump(out.buf());
458 out << std::endl;
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700459 });
Yifan Hong443df792017-05-09 18:49:45 -0700460}
461
Yifan Hongca3b6602017-09-07 16:44:27 -0700462Status ListCommand::dump() {
463 auto dump = mVintf ? &ListCommand::dumpVintf : &ListCommand::dumpTable;
464
465 if (mFileOutputPath.empty()) {
466 (*this.*dump)(out());
467 return OK;
Yifan Hong443df792017-05-09 18:49:45 -0700468 }
Yifan Hongca3b6602017-09-07 16:44:27 -0700469
470 std::ofstream fileOutput(mFileOutputPath);
471 if (!fileOutput.is_open()) {
472 err() << "Could not open file '" << mFileOutputPath << "'." << std::endl;
473 return IO_ERROR;
474 }
475 chown(mFileOutputPath.c_str(), AID_SHELL, AID_SHELL);
476
477 (*this.*dump)(NullableOStream<std::ostream>(fileOutput));
478
479 fileOutput.flush();
480 fileOutput.close();
481 return OK;
Yifan Hong443df792017-05-09 18:49:45 -0700482}
483
484void ListCommand::putEntry(TableEntrySource source, TableEntry &&entry) {
485 Table *table = nullptr;
486 switch (source) {
487 case HWSERVICEMANAGER_LIST :
488 table = &mServicesTable; break;
489 case PTSERVICEMANAGER_REG_CLIENT :
490 table = &mPassthroughRefTable; break;
491 case LIST_DLLIB :
492 table = &mImplementationsTable; break;
493 default:
Yifan Hong76ac14a2017-09-08 14:59:04 -0700494 err() << "Error: Unknown source of entry " << source << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700495 }
496 if (table) {
Yifan Hongd4a77e82017-09-06 19:40:24 -0700497 table->add(std::forward<TableEntry>(entry));
Yifan Hong443df792017-05-09 18:49:45 -0700498 }
499}
500
501Status ListCommand::fetchAllLibraries(const sp<IServiceManager> &manager) {
502 using namespace ::android::hardware;
503 using namespace ::android::hidl::manager::V1_0;
504 using namespace ::android::hidl::base::V1_0;
Yifan Hongf2d557b2017-05-24 19:45:02 -0700505 using std::literals::chrono_literals::operator""s;
506 auto ret = timeoutIPC(2s, manager, &IServiceManager::debugDump, [&] (const auto &infos) {
Yifan Hong443df792017-05-09 18:49:45 -0700507 std::map<std::string, TableEntry> entries;
508 for (const auto &info : infos) {
509 std::string interfaceName = std::string{info.interfaceName.c_str()} + "/" +
510 std::string{info.instanceName.c_str()};
511 entries.emplace(interfaceName, TableEntry{
512 .interfaceName = interfaceName,
513 .transport = "passthrough",
Yifan Hongf2d557b2017-05-24 19:45:02 -0700514 .clientPids = info.clientPids,
Yifan Hong443df792017-05-09 18:49:45 -0700515 }).first->second.arch |= fromBaseArchitecture(info.arch);
516 }
517 for (auto &&pair : entries) {
518 putEntry(LIST_DLLIB, std::move(pair.second));
519 }
520 });
521 if (!ret.isOk()) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700522 err() << "Error: Failed to call list on getPassthroughServiceManager(): "
Yifan Hong443df792017-05-09 18:49:45 -0700523 << ret.description() << std::endl;
524 return DUMP_ALL_LIBS_ERROR;
525 }
526 return OK;
527}
528
529Status ListCommand::fetchPassthrough(const sp<IServiceManager> &manager) {
530 using namespace ::android::hardware;
531 using namespace ::android::hardware::details;
532 using namespace ::android::hidl::manager::V1_0;
533 using namespace ::android::hidl::base::V1_0;
534 auto ret = timeoutIPC(manager, &IServiceManager::debugDump, [&] (const auto &infos) {
535 for (const auto &info : infos) {
536 if (info.clientPids.size() <= 0) {
537 continue;
538 }
539 putEntry(PTSERVICEMANAGER_REG_CLIENT, {
540 .interfaceName =
541 std::string{info.interfaceName.c_str()} + "/" +
542 std::string{info.instanceName.c_str()},
543 .transport = "passthrough",
544 .serverPid = info.clientPids.size() == 1 ? info.clientPids[0] : NO_PID,
Yifan Hong443df792017-05-09 18:49:45 -0700545 .clientPids = info.clientPids,
546 .arch = fromBaseArchitecture(info.arch)
547 });
548 }
549 });
550 if (!ret.isOk()) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700551 err() << "Error: Failed to call debugDump on defaultServiceManager(): "
Yifan Hong443df792017-05-09 18:49:45 -0700552 << ret.description() << std::endl;
553 return DUMP_PASSTHROUGH_ERROR;
554 }
555 return OK;
556}
557
558Status ListCommand::fetchBinderized(const sp<IServiceManager> &manager) {
Yifan Hong443df792017-05-09 18:49:45 -0700559 const std::string mode = "hwbinder";
560
561 hidl_vec<hidl_string> fqInstanceNames;
562 // copying out for timeoutIPC
563 auto listRet = timeoutIPC(manager, &IServiceManager::list, [&] (const auto &names) {
564 fqInstanceNames = names;
565 });
566 if (!listRet.isOk()) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700567 err() << "Error: Failed to list services for " << mode << ": "
Yifan Hong443df792017-05-09 18:49:45 -0700568 << listRet.description() << std::endl;
569 return DUMP_BINDERIZED_ERROR;
570 }
571
572 Status status = OK;
Yifan Hong22ea7b82017-09-14 18:07:43 -0700573 std::map<std::string, TableEntry> allTableEntries;
Yifan Hong443df792017-05-09 18:49:45 -0700574 for (const auto &fqInstanceName : fqInstanceNames) {
Yifan Hong22ea7b82017-09-14 18:07:43 -0700575 // create entry and default assign all fields.
576 TableEntry& entry = allTableEntries[fqInstanceName];
577 entry.interfaceName = fqInstanceName;
578 entry.transport = mode;
579
580 status |= fetchBinderizedEntry(manager, &entry);
581 }
582
583 for (auto& pair : allTableEntries) {
584 putEntry(HWSERVICEMANAGER_LIST, std::move(pair.second));
585 }
586 return status;
587}
588
589Status ListCommand::fetchBinderizedEntry(const sp<IServiceManager> &manager,
590 TableEntry *entry) {
591 Status status = OK;
592 const auto handleError = [&](Status additionalError, const std::string& msg) {
593 err() << "Warning: Skipping \"" << entry->interfaceName << "\": " << msg << std::endl;
594 status |= DUMP_BINDERIZED_ERROR | additionalError;
595 };
596
597 const auto pair = splitFirst(entry->interfaceName, '/');
598 const auto &serviceName = pair.first;
599 const auto &instanceName = pair.second;
600 auto getRet = timeoutIPC(manager, &IServiceManager::get, serviceName, instanceName);
601 if (!getRet.isOk()) {
602 handleError(TRANSACTION_ERROR,
603 "cannot be fetched from service manager:" + getRet.description());
604 return status;
605 }
606 sp<IBase> service = getRet;
607 if (service == nullptr) {
608 handleError(NO_INTERFACE, "cannot be fetched from service manager (null)");
609 return status;
610 }
611
612 // getDebugInfo
613 do {
614 DebugInfo debugInfo;
615 auto debugRet = timeoutIPC(service, &IBase::getDebugInfo, [&] (const auto &received) {
616 debugInfo = received;
Yifan Hong443df792017-05-09 18:49:45 -0700617 });
618 if (!debugRet.isOk()) {
Yifan Hong22ea7b82017-09-14 18:07:43 -0700619 handleError(TRANSACTION_ERROR,
620 "debugging information cannot be retrieved: " + debugRet.description());
621 break; // skip getPidInfo
Yifan Hong443df792017-05-09 18:49:45 -0700622 }
Steven Morelandd8e20192017-05-24 11:23:08 -0700623
Yifan Hong22ea7b82017-09-14 18:07:43 -0700624 entry->serverPid = debugInfo.pid;
625 entry->serverObjectAddress = debugInfo.ptr;
626 entry->arch = fromBaseArchitecture(debugInfo.arch);
Steven Morelandd8e20192017-05-24 11:23:08 -0700627
Yifan Hong22ea7b82017-09-14 18:07:43 -0700628 if (debugInfo.pid != NO_PID) {
629 const PidInfo* pidInfo = getPidInfoCached(debugInfo.pid);
630 if (pidInfo == nullptr) {
631 handleError(IO_ERROR,
632 "no information for PID " + std::to_string(debugInfo.pid) +
633 ", are you root?");
634 break;
635 }
636 if (debugInfo.ptr != NO_PTR) {
637 auto it = pidInfo->refPids.find(debugInfo.ptr);
638 if (it != pidInfo->refPids.end()) {
639 entry->clientPids = it->second;
640 }
641 }
642 entry->threadUsage = pidInfo->threadUsage;
643 entry->threadCount = pidInfo->threadCount;
644 }
645 } while (0);
Yifan Hongfee209d2017-09-14 18:23:38 -0700646
647 // hash
648 do {
649 ssize_t hashIndex = -1;
650 auto ifaceChainRet = timeoutIPC(service, &IBase::interfaceChain, [&] (const auto& c) {
651 for (size_t i = 0; i < c.size(); ++i) {
652 if (serviceName == c[i]) {
653 hashIndex = static_cast<ssize_t>(i);
654 break;
655 }
656 }
657 });
658 if (!ifaceChainRet.isOk()) {
659 handleError(TRANSACTION_ERROR,
660 "interfaceChain fails: " + ifaceChainRet.description());
661 break; // skip getHashChain
662 }
663 if (hashIndex < 0) {
664 handleError(BAD_IMPL, "Interface name does not exist in interfaceChain.");
665 break; // skip getHashChain
666 }
667 auto hashRet = timeoutIPC(service, &IBase::getHashChain, [&] (const auto& hashChain) {
668 if (static_cast<size_t>(hashIndex) >= hashChain.size()) {
669 handleError(BAD_IMPL,
670 "interfaceChain indicates position " + std::to_string(hashIndex) +
671 " but getHashChain returns " + std::to_string(hashChain.size()) +
672 " hashes");
673 return;
674 }
675
676 auto&& hashArray = hashChain[hashIndex];
677 std::vector<uint8_t> hashVec{hashArray.data(), hashArray.data() + hashArray.size()};
678 entry->hash = Hash::hexString(hashVec);
679 });
680 if (!hashRet.isOk()) {
681 handleError(TRANSACTION_ERROR, "getHashChain failed: " + hashRet.description());
682 }
683 } while (0);
Yifan Hong443df792017-05-09 18:49:45 -0700684 return status;
685}
686
687Status ListCommand::fetch() {
688 Status status = OK;
Yifan Hong9881df92017-05-10 14:33:05 -0700689 auto bManager = mLshal.serviceManager();
Yifan Hong443df792017-05-09 18:49:45 -0700690 if (bManager == nullptr) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700691 err() << "Failed to get defaultServiceManager()!" << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700692 status |= NO_BINDERIZED_MANAGER;
693 } else {
694 status |= fetchBinderized(bManager);
695 // Passthrough PIDs are registered to the binderized manager as well.
696 status |= fetchPassthrough(bManager);
697 }
698
Yifan Hong9881df92017-05-10 14:33:05 -0700699 auto pManager = mLshal.passthroughManager();
Yifan Hong443df792017-05-09 18:49:45 -0700700 if (pManager == nullptr) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700701 err() << "Failed to get getPassthroughServiceManager()!" << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700702 status |= NO_PASSTHROUGH_MANAGER;
703 } else {
704 status |= fetchAllLibraries(pManager);
705 }
706 return status;
707}
708
Yifan Honga6b93f02017-09-13 16:53:37 -0700709void ListCommand::registerAllOptions() {
710 int v = mOptions.size();
711 // A list of acceptable command line options
712 // key: value returned by getopt_long
713 // long options with short alternatives
714 mOptions.push_back({'h', "help", no_argument, v++, [](ListCommand*, const char*) {
715 return USAGE;
716 }, ""});
717 mOptions.push_back({'i', "interface", no_argument, v++, [](ListCommand* thiz, const char*) {
718 thiz->mSelectedColumns.push_back(TableColumnType::INTERFACE_NAME);
719 return OK;
720 }, "print the instance name column"});
Yifan Hongfee209d2017-09-14 18:23:38 -0700721 mOptions.push_back({'l', "released", no_argument, v++, [](ListCommand* thiz, const char*) {
722 thiz->mSelectedColumns.push_back(TableColumnType::RELEASED);
723 return OK;
724 }, "print the 'is released?' column\n(Y=released, empty=unreleased or unknown)"});
Yifan Honga6b93f02017-09-13 16:53:37 -0700725 mOptions.push_back({'t', "transport", no_argument, v++, [](ListCommand* thiz, const char*) {
726 thiz->mSelectedColumns.push_back(TableColumnType::TRANSPORT);
727 return OK;
728 }, "print the transport mode column"});
729 mOptions.push_back({'r', "arch", no_argument, v++, [](ListCommand* thiz, const char*) {
730 thiz->mSelectedColumns.push_back(TableColumnType::ARCH);
731 return OK;
732 }, "print the bitness column"});
Yifan Hongfee209d2017-09-14 18:23:38 -0700733 mOptions.push_back({'s', "hash", no_argument, v++, [](ListCommand* thiz, const char*) {
734 thiz->mSelectedColumns.push_back(TableColumnType::HASH);
735 return OK;
736 }, "print hash of the interface"});
Yifan Honga6b93f02017-09-13 16:53:37 -0700737 mOptions.push_back({'p', "pid", no_argument, v++, [](ListCommand* thiz, const char*) {
738 thiz->mSelectedColumns.push_back(TableColumnType::SERVER_PID);
739 return OK;
740 }, "print the server PID, or server cmdline if -m is set"});
741 mOptions.push_back({'a', "address", no_argument, v++, [](ListCommand* thiz, const char*) {
742 thiz->mSelectedColumns.push_back(TableColumnType::SERVER_ADDR);
743 return OK;
744 }, "print the server object address column"});
745 mOptions.push_back({'c', "clients", no_argument, v++, [](ListCommand* thiz, const char*) {
746 thiz->mSelectedColumns.push_back(TableColumnType::CLIENT_PIDS);
747 return OK;
748 }, "print the client PIDs, or client cmdlines if -m is set"});
749 mOptions.push_back({'e', "threads", no_argument, v++, [](ListCommand* thiz, const char*) {
750 thiz->mSelectedColumns.push_back(TableColumnType::THREADS);
751 return OK;
752 }, "print currently used/available threads\n(note, available threads created lazily)"});
753 mOptions.push_back({'m', "cmdline", no_argument, v++, [](ListCommand* thiz, const char*) {
754 thiz->mEnableCmdlines = true;
755 return OK;
756 }, "print cmdline instead of PIDs"});
757 mOptions.push_back({'d', "debug", optional_argument, v++, [](ListCommand* thiz, const char* arg) {
758 thiz->mEmitDebugInfo = true;
759 if (arg) thiz->mFileOutputPath = arg;
760 return OK;
761 }, "Emit debug info from\nIBase::debug with empty options. Cannot be used with --neat.\n"
762 "Writes to specified file if 'arg' is provided, otherwise stdout."});
763
764 // long options without short alternatives
765 mOptions.push_back({'\0', "init-vintf", no_argument, v++, [](ListCommand* thiz, const char* arg) {
766 thiz->mVintf = true;
Yifan Hongf31aa052018-02-02 15:17:51 -0800767 if (thiz->mVintfPartition == Partition::UNKNOWN)
768 thiz->mVintfPartition = Partition::VENDOR;
Yifan Honga6b93f02017-09-13 16:53:37 -0700769 if (arg) thiz->mFileOutputPath = arg;
770 return OK;
771 }, "form a skeleton HAL manifest to specified file,\nor stdout if no file specified."});
Yifan Hongf31aa052018-02-02 15:17:51 -0800772 mOptions.push_back({'\0', "init-vintf-partition", required_argument, v++, [](ListCommand* thiz, const char* arg) {
773 if (!arg) return USAGE;
774 thiz->mVintfPartition = android::procpartition::parsePartition(arg);
775 if (thiz->mVintfPartition == Partition::UNKNOWN) return USAGE;
776 return OK;
777 }, "Specify the partition of the HAL manifest\ngenerated by --init-vintf.\n"
778 "Valid values are 'system', 'vendor', and 'odm'. Default is 'vendor'."});
Yifan Honga6b93f02017-09-13 16:53:37 -0700779 mOptions.push_back({'\0', "sort", required_argument, v++, [](ListCommand* thiz, const char* arg) {
780 if (strcmp(arg, "interface") == 0 || strcmp(arg, "i") == 0) {
781 thiz->mSortColumn = TableEntry::sortByInterfaceName;
782 } else if (strcmp(arg, "pid") == 0 || strcmp(arg, "p") == 0) {
783 thiz->mSortColumn = TableEntry::sortByServerPid;
784 } else {
785 thiz->err() << "Unrecognized sorting column: " << arg << std::endl;
786 return USAGE;
787 }
788 return OK;
789 }, "sort by a column. 'arg' can be (i|interface) or (p|pid)."});
790 mOptions.push_back({'\0', "neat", no_argument, v++, [](ListCommand* thiz, const char*) {
791 thiz->mNeat = true;
792 return OK;
793 }, "output is machine parsable (no explanatory text).\nCannot be used with --debug."});
794}
795
796// Create 'longopts' argument to getopt_long. Caller is responsible for maintaining
797// the lifetime of "options" during the usage of the returned array.
798static std::unique_ptr<struct option[]> getLongOptions(
799 const ListCommand::RegisteredOptions& options,
800 int* longOptFlag) {
801 std::unique_ptr<struct option[]> ret{new struct option[options.size() + 1]};
802 int i = 0;
803 for (const auto& e : options) {
804 ret[i].name = e.longOption.c_str();
805 ret[i].has_arg = e.hasArg;
806 ret[i].flag = longOptFlag;
807 ret[i].val = e.val;
808
809 i++;
810 }
811 // getopt_long last option has all zeros
812 ret[i].name = NULL;
813 ret[i].has_arg = 0;
814 ret[i].flag = NULL;
815 ret[i].val = 0;
816
817 return ret;
818}
819
820// Create 'optstring' argument to getopt_long.
821static std::string getShortOptions(const ListCommand::RegisteredOptions& options) {
822 std::stringstream ss;
823 for (const auto& e : options) {
824 if (e.shortOption != '\0') {
825 ss << e.shortOption;
826 }
827 }
828 return ss.str();
829}
830
Yifan Honga8bedc62017-09-08 18:00:31 -0700831Status ListCommand::parseArgs(const Arg &arg) {
Yifan Hong443df792017-05-09 18:49:45 -0700832
Yifan Honga6b93f02017-09-13 16:53:37 -0700833 if (mOptions.empty()) {
834 registerAllOptions();
835 }
836 int longOptFlag;
837 std::unique_ptr<struct option[]> longOptions = getLongOptions(mOptions, &longOptFlag);
838 std::string shortOptions = getShortOptions(mOptions);
Yifan Hongd4a77e82017-09-06 19:40:24 -0700839
Yifan Honga8bedc62017-09-08 18:00:31 -0700840 // suppress output to std::err for unknown options
841 opterr = 0;
842
Yifan Hong443df792017-05-09 18:49:45 -0700843 int optionIndex;
844 int c;
845 // Lshal::parseArgs has set optind to the next option to parse
846 for (;;) {
Yifan Hong443df792017-05-09 18:49:45 -0700847 c = getopt_long(arg.argc, arg.argv,
Yifan Honga6b93f02017-09-13 16:53:37 -0700848 shortOptions.c_str(), longOptions.get(), &optionIndex);
Yifan Hong443df792017-05-09 18:49:45 -0700849 if (c == -1) {
850 break;
851 }
Yifan Honga6b93f02017-09-13 16:53:37 -0700852 const RegisteredOption* found = nullptr;
853 if (c == 0) {
854 // see long option
855 for (const auto& e : mOptions) {
856 if (longOptFlag == e.val) found = &e;
Yifan Hong443df792017-05-09 18:49:45 -0700857 }
Yifan Honga6b93f02017-09-13 16:53:37 -0700858 } else {
859 // see short option
860 for (const auto& e : mOptions) {
861 if (c == e.shortOption) found = &e;
862 }
Yifan Hong443df792017-05-09 18:49:45 -0700863 }
Yifan Honga6b93f02017-09-13 16:53:37 -0700864
865 if (found == nullptr) {
866 // see unrecognized options
Yifan Honga8bedc62017-09-08 18:00:31 -0700867 err() << "unrecognized option `" << arg.argv[optind - 1] << "'" << std::endl;
Yifan Hong443df792017-05-09 18:49:45 -0700868 return USAGE;
869 }
Yifan Honga6b93f02017-09-13 16:53:37 -0700870
871 Status status = found->op(this, optarg);
872 if (status != OK) {
873 return status;
874 }
Yifan Hong443df792017-05-09 18:49:45 -0700875 }
876 if (optind < arg.argc) {
877 // see non option
Yifan Honga8bedc62017-09-08 18:00:31 -0700878 err() << "unrecognized option `" << arg.argv[optind] << "'" << std::endl;
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700879 return USAGE;
880 }
881
882 if (mNeat && mEmitDebugInfo) {
Yifan Hong76ac14a2017-09-08 14:59:04 -0700883 err() << "Error: --neat should not be used with --debug." << std::endl;
Yifan Hong1bc1e9f2017-08-29 17:28:12 -0700884 return USAGE;
Yifan Hong443df792017-05-09 18:49:45 -0700885 }
886
Yifan Honga6b93f02017-09-13 16:53:37 -0700887 if (mSelectedColumns.empty()) {
Yifan Hongfee209d2017-09-14 18:23:38 -0700888 mSelectedColumns = {TableColumnType::RELEASED,
889 TableColumnType::INTERFACE_NAME, TableColumnType::THREADS,
Yifan Hong05494a52017-08-29 18:50:00 -0700890 TableColumnType::SERVER_PID, TableColumnType::CLIENT_PIDS};
Yifan Hong443df792017-05-09 18:49:45 -0700891 }
Yifan Hongd4a77e82017-09-06 19:40:24 -0700892
Yifan Honga6b93f02017-09-13 16:53:37 -0700893 if (mEnableCmdlines) {
894 for (size_t i = 0; i < mSelectedColumns.size(); ++i) {
895 if (mSelectedColumns[i] == TableColumnType::SERVER_PID) {
896 mSelectedColumns[i] = TableColumnType::SERVER_CMD;
Yifan Hongd4a77e82017-09-06 19:40:24 -0700897 }
Yifan Honga6b93f02017-09-13 16:53:37 -0700898 if (mSelectedColumns[i] == TableColumnType::CLIENT_PIDS) {
899 mSelectedColumns[i] = TableColumnType::CLIENT_CMDS;
Yifan Hongd4a77e82017-09-06 19:40:24 -0700900 }
901 }
902 }
903
Yifan Honga6b93f02017-09-13 16:53:37 -0700904 forEachTable([this] (Table& table) {
905 table.setSelectedColumns(this->mSelectedColumns);
Yifan Hongd4a77e82017-09-06 19:40:24 -0700906 });
907
Yifan Hong443df792017-05-09 18:49:45 -0700908 return OK;
909}
910
Yifan Honga8bedc62017-09-08 18:00:31 -0700911Status ListCommand::main(const Arg &arg) {
912 Status status = parseArgs(arg);
Yifan Hong443df792017-05-09 18:49:45 -0700913 if (status != OK) {
914 return status;
915 }
916 status = fetch();
917 postprocess();
Yifan Hongca3b6602017-09-07 16:44:27 -0700918 status |= dump();
Yifan Hong443df792017-05-09 18:49:45 -0700919 return status;
920}
921
Yifan Honga6b93f02017-09-13 16:53:37 -0700922static std::vector<std::string> splitString(const std::string &s, char c) {
923 std::vector<std::string> components;
924
925 size_t startPos = 0;
926 size_t matchPos;
927 while ((matchPos = s.find(c, startPos)) != std::string::npos) {
928 components.push_back(s.substr(startPos, matchPos - startPos));
929 startPos = matchPos + 1;
930 }
931
932 if (startPos <= s.length()) {
933 components.push_back(s.substr(startPos));
934 }
935 return components;
936}
937
938const std::string& ListCommand::RegisteredOption::getHelpMessageForArgument() const {
939 static const std::string empty{};
940 static const std::string optional{"[=<arg>]"};
941 static const std::string required{"=<arg>"};
942
943 if (hasArg == optional_argument) {
944 return optional;
945 }
946 if (hasArg == required_argument) {
947 return required;
948 }
949 return empty;
950}
951
Yifan Honga8bedc62017-09-08 18:00:31 -0700952void ListCommand::usage() const {
953
Yifan Honga6b93f02017-09-13 16:53:37 -0700954 err() << "list:" << std::endl
955 << " lshal" << std::endl
956 << " lshal list" << std::endl
Yifan Hongfee209d2017-09-14 18:23:38 -0700957 << " List all hals with default ordering and columns (`lshal list -riepc`)" << std::endl
Yifan Honga6b93f02017-09-13 16:53:37 -0700958 << " lshal list [-h|--help]" << std::endl
959 << " -h, --help: Print help message for list (`lshal help list`)" << std::endl
960 << " lshal [list] [OPTIONS...]" << std::endl;
961 for (const auto& e : mOptions) {
962 if (e.help.empty()) {
963 continue;
964 }
965 err() << " ";
966 if (e.shortOption != '\0')
967 err() << "-" << e.shortOption << e.getHelpMessageForArgument();
968 if (e.shortOption != '\0' && !e.longOption.empty())
969 err() << ", ";
970 if (!e.longOption.empty())
971 err() << "--" << e.longOption << e.getHelpMessageForArgument();
972 err() << ": ";
973 std::vector<std::string> lines = splitString(e.help, '\n');
974 for (const auto& line : lines) {
975 if (&line != &lines.front())
976 err() << " ";
977 err() << line << std::endl;
978 }
979 }
Yifan Honga8bedc62017-09-08 18:00:31 -0700980}
981
Yifan Hong443df792017-05-09 18:49:45 -0700982} // namespace lshal
983} // namespace android
Yifan Hong05494a52017-08-29 18:50:00 -0700984