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

Commit 42a97cfd authored by Lloyd Pique's avatar Lloyd Pique
Browse files

SF: Allow debug.sf.hwc_service_name to be fully-qualified

The checks in ComposerHal and AidlComposerHal for whether or not to use
the AIDL service interface or fall back to the HIDL service interface
just checked if the name could qualified using the AIDL service name
prefix, and matched to a name in the VINTF manifest. If it was not
found, the name was assumed to be a HIDL interface.

This check meant that a test that registers its own AIDL service and
sets debug.sf.hwc_service_name appropriately cannot get SurfaceFlinger
to load it.

This change allows the string to be set to a fully qualified name, like
"android.hardware.graphics.composer3.IComposer/fake", and
AidlComposerHal will now recognize from the prefix that it is meant to
be an AIDL implementation, and so it should be used. Importantly this
also skips the check that the name is registered, which is problematic
for a test.

The old functionality is kept. Setting the string to "default" will
cause a check to see if
"android.hardware.graphics.composer3.IComposer/default" is registered,
and use it if found, or otherwise fall back to the HIDL "default"
interface if not.

Flag: EXEMPT for use by tests only
Bug: 372735083
Test: m and run cf target

Change-Id: I26a0d92d1600a48facb75f956400433d03efcf5e
parent 9211819a
Loading
Loading
Loading
Loading
+17 −7
Original line number Diff line number Diff line
@@ -26,12 +26,15 @@
#include <android/binder_manager.h>
#include <common/FlagManager.h>
#include <common/trace.h>
#include <fmt/core.h>
#include <log/log.h>

#include <aidl/android/hardware/graphics/composer3/BnComposerCallback.h>

#include <algorithm>
#include <cinttypes>
#include <string>
#include <string_view>

#include "HWC2.h"

@@ -229,25 +232,32 @@ private:
    HWC2::ComposerCallback& mCallback;
};

std::string AidlComposer::instance(const std::string& serviceName) {
    return std::string(AidlIComposer::descriptor) + "/" + serviceName;
std::string AidlComposer::ensureFullyQualifiedName(std::string_view serviceName) {
    if (!serviceName.starts_with(AidlIComposer::descriptor)) {
        return fmt::format("{}/{}", AidlIComposer::descriptor, serviceName);
    } else {
        return std::string{serviceName};
    }
}

bool AidlComposer::isDeclared(const std::string& serviceName) {
    return AServiceManager_isDeclared(instance(serviceName).c_str());
bool AidlComposer::namesAnAidlComposerService(std::string_view serviceName) {
    if (!serviceName.starts_with(AidlIComposer::descriptor)) {
        return AServiceManager_isDeclared(ensureFullyQualifiedName(serviceName).c_str());
    }
    return true;
}

AidlComposer::AidlComposer(const std::string& serviceName) {
    // This only waits if the service is actually declared
    mAidlComposer = AidlIComposer::fromBinder(
            ndk::SpAIBinder(AServiceManager_waitForService(instance(serviceName).c_str())));
    mAidlComposer = AidlIComposer::fromBinder(ndk::SpAIBinder(
            AServiceManager_waitForService(ensureFullyQualifiedName(serviceName).c_str())));
    if (!mAidlComposer) {
        LOG_ALWAYS_FATAL("Failed to get AIDL composer service");
        return;
    }

    if (!mAidlComposer->createClient(&mAidlComposerClient).isOk()) {
        LOG_ALWAYS_FATAL("Can't create AidlComposerClient, fallback to HIDL");
        LOG_ALWAYS_FATAL("Can't create AidlComposerClient");
        return;
    }

+5 −4
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@
#include <functional>
#include <optional>
#include <string>
#include <utility>
#include <string_view>
#include <vector>

#include <android/hardware/graphics/composer/2.4/IComposer.h>
@@ -53,7 +53,8 @@ class AidlIComposerCallbackWrapper;
// Composer is a wrapper to IComposer, a proxy to server-side composer.
class AidlComposer final : public Hwc2::Composer {
public:
    static bool isDeclared(const std::string& serviceName);
    // Returns true if serviceName appears to be something that is meant to be used by AidlComposer.
    static bool namesAnAidlComposerService(std::string_view serviceName);

    explicit AidlComposer(const std::string& serviceName);
    ~AidlComposer() override;
@@ -258,8 +259,8 @@ private:
    // this function to execute the command queue.
    Error execute(Display) REQUIRES_SHARED(mMutex);

    // returns the default instance name for the given service
    static std::string instance(const std::string& serviceName);
    // Ensures serviceName is fully qualified.
    static std::string ensureFullyQualifiedName(std::string_view serviceName);

    ftl::Optional<std::reference_wrapper<ComposerClientWriter>> getWriter(Display)
            REQUIRES_SHARED(mMutex);
+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ namespace android::Hwc2 {
Composer::~Composer() = default;

std::unique_ptr<Composer> Composer::create(const std::string& serviceName) {
    if (AidlComposer::isDeclared(serviceName)) {
    if (AidlComposer::namesAnAidlComposerService(serviceName)) {
        return std::make_unique<AidlComposer>(serviceName);
    }