Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8304e416 authored by Yifan Hong's avatar Yifan Hong
Browse files

lshal: refactor: Use vintf::Transport instead of string

Enums are better.
Test: lshal_test

Change-Id: Iee8af520de866106d3384b12058e94f423217347
parent d5ee11a5
Loading
Loading
Loading
Loading
+8 −9
Original line number Diff line number Diff line
@@ -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) {
+3 −1
Original line number Diff line number Diff line
@@ -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
+2 −1
Original line number Diff line number Diff line
@@ -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};
+11 −7
Original line number Diff line number Diff line
@@ -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],