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

Commit 8e20f172 authored by Yifan Hong's avatar Yifan Hong Committed by Android (Google) Code Review
Browse files

Merge "Fix lshal not to squash HAL entries incorrectly." into oc-dev

parents 949c9ce5 70a39e7b
Loading
Loading
Loading
Loading
+39 −25
Original line number Original line Diff line number Diff line
@@ -163,6 +163,7 @@ bool Lshal::getReferencedPids(
    return true;
    return true;
}
}


// Must process hwbinder services first, then passthrough services.
void Lshal::forEachTable(const std::function<void(Table &)> &f) {
void Lshal::forEachTable(const std::function<void(Table &)> &f) {
    f(mServicesTable);
    f(mServicesTable);
    f(mPassthroughRefTable);
    f(mPassthroughRefTable);
@@ -243,6 +244,18 @@ void Lshal::printLine(
}
}


void Lshal::dumpVintf() const {
void Lshal::dumpVintf() const {
    mOut << "<!-- " << std::endl
         << "    This is a skeleton device manifest. Notes: " << std::endl
         << "    1. android.hidl.*, android.frameworks.*, android.system.* are not included." << std::endl
         << "    2. If a HAL is supported in both hwbinder and passthrough transport, " << std::endl
         << "       only hwbinder is shown." << std::endl
         << "    3. It is likely that HALs in passthrough transport does not have" << std::endl
         << "       <interface> declared; users will have to write them by hand." << std::endl
         << "    4. sepolicy version is set to 0.0. It is recommended that the entry" << std::endl
         << "       is removed from the manifest file and written by assemble_vintf" << std::endl
         << "       at build time." << std::endl
         << "-->" << std::endl;

    vintf::HalManifest manifest;
    vintf::HalManifest manifest;
    forEachTable([this, &manifest] (const Table &table) {
    forEachTable([this, &manifest] (const Table &table) {
        for (const TableEntry &entry : table) {
        for (const TableEntry &entry : table) {
@@ -271,6 +284,8 @@ void Lshal::dumpVintf() const {
            std::string instanceName =
            std::string instanceName =
                    &table == &mImplementationsTable ? "" : splittedFqInstanceName.second;
                    &table == &mImplementationsTable ? "" : splittedFqInstanceName.second;


            vintf::Version version{fqName.getPackageMajorVersion(),
                                   fqName.getPackageMinorVersion()};
            vintf::Transport transport;
            vintf::Transport transport;
            vintf::Arch arch;
            vintf::Arch arch;
            if (entry.transport == "hwbinder") {
            if (entry.transport == "hwbinder") {
@@ -296,34 +311,33 @@ void Lshal::dumpVintf() const {
                continue;
                continue;
            }
            }


            vintf::ManifestHal *hal = manifest.getAnyHal(fqName.package());
            bool done = false;
            if (hal == nullptr) {
            for (vintf::ManifestHal *hal : manifest.getHals(fqName.package())) {
                if (!manifest.add(vintf::ManifestHal{
                if (hal->transport() != transport) {
                    .format = vintf::HalFormat::HIDL,
                    if (transport != vintf::Transport::PASSTHROUGH) {
                    .name = fqName.package(),
                        mErr << "Fatal: should not reach here. Generated result may be wrong."
                    .transportArch = {transport, arch}
                             << std::endl;
                })) {
                    mErr << "Warning: cannot add hal '" << fqInstanceName << "'" << std::endl;
                    continue;
                    }
                    }
                hal = manifest.getAnyHal(fqName.package());
                    done = true;
                    break;
                }
                }
            if (hal == nullptr) {
                if (hal->hasVersion(version)) {
                mErr << "Warning: cannot get hal '" << fqInstanceName
                    hal->interfaces[interfaceName].name = interfaceName;
                     << "' after adding it" << std::endl;
                    hal->interfaces[interfaceName].instances.insert(instanceName);
                continue;
                    done = true;
                    break;
                }
                }
            vintf::Version version{fqName.getPackageMajorVersion(), fqName.getPackageMinorVersion()};
            if (std::find(hal->versions.begin(), hal->versions.end(), version) == hal->versions.end()) {
                hal->versions.push_back(version);
            }
            }
            if (&table != &mImplementationsTable) {
            if (done) {
                auto it = hal->interfaces.find(interfaceName);
                continue; // to next TableEntry
                if (it == hal->interfaces.end()) {
                    hal->interfaces.insert({interfaceName, {interfaceName, {{instanceName}}}});
                } else {
                    it->second.instances.insert(instanceName);
            }
            }
            if (!manifest.add(vintf::ManifestHal{
                    .format = vintf::HalFormat::HIDL,
                    .name = fqName.package(),
                    .versions = {version},
                    .transportArch = {transport, arch},
                    .interfaces = {{interfaceName, {interfaceName, {{instanceName}}}}}})) {
                mErr << "Warning: cannot add hal '" << fqInstanceName << "'" << std::endl;
            }
            }
        }
        }
    });
    });