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

Commit 936c33b1 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "SF: Allow debug.sf.hwc_service_name to be fully-qualified" into main

parents e7158108 42a97cfd
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);
    }