diff options
author | 2018-05-25 15:05:36 -0700 | |
---|---|---|
committer | 2018-05-29 10:31:07 -0700 | |
commit | 8304e4169449b6cf1ed3d96aa9b37e6fe7e583c1 (patch) | |
tree | 085c17854217eef3a71f122ec7967f09cae6e57d | |
parent | d5ee11a531ec0f6bf47ebfe9850a60e3c3e6308f (diff) |
lshal: refactor: Use vintf::Transport instead of string
Enums are better.
Test: lshal_test
Change-Id: Iee8af520de866106d3384b12058e94f423217347
-rw-r--r-- | cmds/lshal/ListCommand.cpp | 17 | ||||
-rw-r--r-- | cmds/lshal/TableEntry.cpp | 4 | ||||
-rw-r--r-- | cmds/lshal/TableEntry.h | 3 | ||||
-rw-r--r-- | cmds/lshal/test.cpp | 18 |
4 files changed, 24 insertions, 18 deletions
diff --git a/cmds/lshal/ListCommand.cpp b/cmds/lshal/ListCommand.cpp index c99b8637f3..82d4a98209 100644 --- a/cmds/lshal/ListCommand.cpp +++ b/cmds/lshal/ListCommand.cpp @@ -330,13 +330,10 @@ bool ListCommand::addEntryWithInstance(const TableEntry& entry, return true; // strip out instances that is in a different partition. } - vintf::Transport transport; vintf::Arch arch; - if (entry.transport == "hwbinder") { - transport = vintf::Transport::HWBINDER; + if (entry.transport == vintf::Transport::HWBINDER) { arch = vintf::Arch::ARCH_EMPTY; - } else if (entry.transport == "passthrough") { - transport = vintf::Transport::PASSTHROUGH; + } else if (entry.transport == vintf::Transport::PASSTHROUGH) { switch (entry.arch) { case lshal::ARCH32: arch = vintf::Arch::ARCH_32; @@ -358,7 +355,7 @@ bool ListCommand::addEntryWithInstance(const TableEntry& entry, } std::string e; - if (!manifest->insertInstance(fqInstance, transport, arch, vintf::HalFormat::HIDL, &e)) { + if (!manifest->insertInstance(fqInstance, entry.transport, arch, vintf::HalFormat::HIDL, &e)) { err() << "Warning: Cannot insert '" << fqInstance.string() << ": " << e << std::endl; return false; } @@ -534,7 +531,7 @@ Status ListCommand::fetchAllLibraries(const sp<IServiceManager> &manager) { std::string{info.instanceName.c_str()}; entries.emplace(interfaceName, TableEntry{ .interfaceName = interfaceName, - .transport = "passthrough", + .transport = vintf::Transport::PASSTHROUGH, .clientPids = info.clientPids, }).first->second.arch |= fromBaseArchitecture(info.arch); } @@ -566,7 +563,7 @@ Status ListCommand::fetchPassthrough(const sp<IServiceManager> &manager) { .interfaceName = std::string{info.interfaceName.c_str()} + "/" + std::string{info.instanceName.c_str()}, - .transport = "passthrough", + .transport = vintf::Transport::PASSTHROUGH, .serverPid = info.clientPids.size() == 1 ? info.clientPids[0] : NO_PID, .clientPids = info.clientPids, .arch = fromBaseArchitecture(info.arch) @@ -582,9 +579,11 @@ Status ListCommand::fetchPassthrough(const sp<IServiceManager> &manager) { } Status ListCommand::fetchBinderized(const sp<IServiceManager> &manager) { + using vintf::operator<<; + if (!shouldReportHalType(HalType::BINDERIZED_SERVICES)) { return OK; } - const std::string mode = "hwbinder"; + const vintf::Transport mode = vintf::Transport::HWBINDER; hidl_vec<hidl_string> fqInstanceNames; // copying out for timeoutIPC auto listRet = timeoutIPC(manager, &IServiceManager::list, [&] (const auto &names) { diff --git a/cmds/lshal/TableEntry.cpp b/cmds/lshal/TableEntry.cpp index f390850e01..f023bb839e 100644 --- a/cmds/lshal/TableEntry.cpp +++ b/cmds/lshal/TableEntry.cpp @@ -17,6 +17,7 @@ #include <android-base/logging.h> #include <hidl-hash/Hash.h> +#include <vintf/parse_string.h> #include "TableEntry.h" @@ -68,7 +69,7 @@ std::string TableEntry::getField(TableColumnType type) const { case TableColumnType::INTERFACE_NAME: return interfaceName; case TableColumnType::TRANSPORT: - return transport; + return vintf::to_string(transport); case TableColumnType::SERVER_PID: return serverPid == NO_PID ? "N/A" : std::to_string(serverPid); case TableColumnType::SERVER_CMD: @@ -155,6 +156,7 @@ bool TableEntry::operator==(const TableEntry& other) const { } std::string TableEntry::to_string() const { + using vintf::operator<<; std::stringstream ss; ss << "name=" << interfaceName << ";transport=" << transport << ";thread=" << getThreadUsage() << ";server=" << serverPid diff --git a/cmds/lshal/TableEntry.h b/cmds/lshal/TableEntry.h index 24ea4383b1..04dfb8041f 100644 --- a/cmds/lshal/TableEntry.h +++ b/cmds/lshal/TableEntry.h @@ -24,6 +24,7 @@ #include <iostream> #include <procpartition/procpartition.h> +#include <vintf/Transport.h> #include "TextTable.h" @@ -69,7 +70,7 @@ enum { struct TableEntry { std::string interfaceName{}; - std::string transport{}; + vintf::Transport transport{vintf::Transport::EMPTY}; int32_t serverPid{NO_PID}; uint32_t threadUsage{0}; uint32_t threadCount{0}; diff --git a/cmds/lshal/test.cpp b/cmds/lshal/test.cpp index 4a9b061b12..eeb830902e 100644 --- a/cmds/lshal/test.cpp +++ b/cmds/lshal/test.cpp @@ -44,6 +44,7 @@ using ::android::hardware::hidl_death_recipient; using ::android::hardware::hidl_handle; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; +using android::vintf::Transport; using InstanceDebugInfo = IServiceManager::InstanceDebugInfo; @@ -389,22 +390,25 @@ TEST_F(ListTest, GetPidInfoCached) { TEST_F(ListTest, Fetch) { EXPECT_EQ(0u, mockList->fetch()); - std::array<std::string, 6> transports{{"hwbinder", "hwbinder", "passthrough", - "passthrough", "passthrough", "passthrough"}}; + std::array<Transport, 6> transports{{Transport::HWBINDER, Transport::HWBINDER, + Transport::PASSTHROUGH, Transport::PASSTHROUGH, + Transport::PASSTHROUGH, Transport::PASSTHROUGH}}; std::array<Architecture, 6> archs{{ARCH64, ARCH64, ARCH32, ARCH32, ARCH32, ARCH32}}; int id = 1; mockList->forEachTable([&](const Table& table) { ASSERT_EQ(2u, table.size()); for (const auto& entry : table) { - const auto& transport = transports[id - 1]; + auto transport = transports[id - 1]; TableEntry expected{ .interfaceName = getFqInstanceName(id), .transport = transport, - .serverPid = transport == "hwbinder" ? id : NO_PID, - .threadUsage = transport == "hwbinder" ? getPidInfoFromId(id).threadUsage : 0, - .threadCount = transport == "hwbinder" ? getPidInfoFromId(id).threadCount : 0, + .serverPid = transport == Transport::HWBINDER ? id : NO_PID, + .threadUsage = + transport == Transport::HWBINDER ? getPidInfoFromId(id).threadUsage : 0, + .threadCount = + transport == Transport::HWBINDER ? getPidInfoFromId(id).threadCount : 0, .serverCmdline = {}, - .serverObjectAddress = transport == "hwbinder" ? getPtr(id) : NO_PTR, + .serverObjectAddress = transport == Transport::HWBINDER ? getPtr(id) : NO_PTR, .clientPids = getClients(id), .clientCmdlines = {}, .arch = archs[id - 1], |