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

Commit 0ad64f52 authored by Yifan Hong's avatar Yifan Hong
Browse files

lshal: refactor: Use vintf::Arch instead of enum Architecture

The Architecture enum was invented
when there was no operator| and operator|= implemented
for vintf::Arch. Now that |= is properly defined, it
makes sense to remove duplicated definition of classes.

Test: lshal_test

Change-Id: I5d4786c3a460e20a49b32fa42226294ab2899d20
parent 8304e416
Loading
Loading
Loading
Loading
+10 −20
Original line number Diff line number Diff line
@@ -279,7 +279,7 @@ void ListCommand::postprocess() {
            continue;
        }
        for (TableEntry &interfaceEntry : mPassthroughRefTable) {
            if (interfaceEntry.arch != ARCH_UNKNOWN) {
            if (interfaceEntry.arch != vintf::Arch::ARCH_EMPTY) {
                continue;
            }
            FQName interfaceName;
@@ -332,23 +332,13 @@ bool ListCommand::addEntryWithInstance(const TableEntry& entry,

    vintf::Arch arch;
    if (entry.transport == vintf::Transport::HWBINDER) {
        arch = vintf::Arch::ARCH_EMPTY;
        arch = vintf::Arch::ARCH_EMPTY; // no need to specify arch in manifest
    } else if (entry.transport == vintf::Transport::PASSTHROUGH) {
        switch (entry.arch) {
            case lshal::ARCH32:
                arch = vintf::Arch::ARCH_32;
                break;
            case lshal::ARCH64:
                arch = vintf::Arch::ARCH_64;
                break;
            case lshal::ARCH_BOTH:
                arch = vintf::Arch::ARCH_32_64;
                break;
            case lshal::ARCH_UNKNOWN: // fallthrough
            default:
        if (entry.arch == vintf::Arch::ARCH_EMPTY) {
            err() << "Warning: '" << entry.interfaceName << "' doesn't have bitness info.";
            return false;
        }
        arch = entry.arch;
    } else {
        err() << "Warning: '" << entry.transport << "' is not a valid transport." << std::endl;
        return false;
@@ -437,15 +427,15 @@ std::string ListCommand::INIT_VINTF_NOTES{
    "       until they are updated.\n"
};

static Architecture fromBaseArchitecture(::android::hidl::base::V1_0::DebugInfo::Architecture a) {
static vintf::Arch fromBaseArchitecture(::android::hidl::base::V1_0::DebugInfo::Architecture a) {
    switch (a) {
        case ::android::hidl::base::V1_0::DebugInfo::Architecture::IS_64BIT:
            return ARCH64;
            return vintf::Arch::ARCH_64;
        case ::android::hidl::base::V1_0::DebugInfo::Architecture::IS_32BIT:
            return ARCH32;
            return vintf::Arch::ARCH_32;
        case ::android::hidl::base::V1_0::DebugInfo::Architecture::UNKNOWN: // fallthrough
        default:
            return ARCH_UNKNOWN;
            return vintf::Arch::ARCH_EMPTY;
    }
}

+5 −5
Original line number Diff line number Diff line
@@ -27,19 +27,19 @@
namespace android {
namespace lshal {

static const std::string &getArchString(Architecture arch) {
static const std::string &getArchString(vintf::Arch arch) {
    static const std::string sStr64 = "64";
    static const std::string sStr32 = "32";
    static const std::string sStrBoth = "32+64";
    static const std::string sStrUnknown = "";
    switch (arch) {
        case ARCH64:
        case vintf::Arch::ARCH_64:
            return sStr64;
        case ARCH32:
        case vintf::Arch::ARCH_32:
            return sStr32;
        case ARCH_BOTH:
        case vintf::Arch::ARCH_32_64:
            return sStrBoth;
        case ARCH_UNKNOWN: // fall through
        case vintf::Arch::ARCH_EMPTY: // fall through
        default:
            return sStrUnknown;
    }
+2 −9
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include <iostream>

#include <procpartition/procpartition.h>
#include <vintf/Arch.h>
#include <vintf/Transport.h>

#include "TextTable.h"
@@ -41,14 +42,6 @@ enum : unsigned int {
};
using TableEntrySource = unsigned int;

enum : unsigned int {
    ARCH_UNKNOWN = 0,
    ARCH32       = 1 << 0,
    ARCH64       = 1 << 1,
    ARCH_BOTH    = ARCH32 | ARCH64
};
using Architecture = unsigned int;

enum class TableColumnType : unsigned int {
    INTERFACE_NAME,
    TRANSPORT,
@@ -78,7 +71,7 @@ struct TableEntry {
    uint64_t serverObjectAddress{NO_PTR};
    Pids clientPids{};
    std::vector<std::string> clientCmdlines{};
    Architecture arch{ARCH_UNKNOWN};
    vintf::Arch arch{vintf::Arch::ARCH_EMPTY};
    // empty: unknown, all zeros: unreleased, otherwise: released
    std::string hash{};
    Partition partition{Partition::UNKNOWN};
+7 −6
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::Arch;
using android::vintf::Transport;

using InstanceDebugInfo = IServiceManager::InstanceDebugInfo;
@@ -390,15 +391,15 @@ TEST_F(ListTest, GetPidInfoCached) {

TEST_F(ListTest, Fetch) {
    EXPECT_EQ(0u, mockList->fetch());
    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}};
    vintf::TransportArch hwbinder{Transport::HWBINDER, Arch::ARCH_64};
    vintf::TransportArch passthrough{Transport::PASSTHROUGH, Arch::ARCH_32};
    std::array<vintf::TransportArch, 6> transportArchs{{hwbinder, hwbinder, passthrough,
                                                        passthrough, passthrough, passthrough}};
    int id = 1;
    mockList->forEachTable([&](const Table& table) {
        ASSERT_EQ(2u, table.size());
        for (const auto& entry : table) {
            auto transport = transports[id - 1];
            auto transport = transportArchs.at(id - 1).transport;
            TableEntry expected{
                .interfaceName = getFqInstanceName(id),
                .transport = transport,
@@ -411,7 +412,7 @@ TEST_F(ListTest, Fetch) {
                .serverObjectAddress = transport == Transport::HWBINDER ? getPtr(id) : NO_PTR,
                .clientPids = getClients(id),
                .clientCmdlines = {},
                .arch = archs[id - 1],
                .arch = transportArchs.at(id - 1).arch,
            };
            EXPECT_EQ(expected, entry) << expected.to_string() << " vs. " << entry.to_string();