diff options
| author | 2024-11-25 19:15:32 -0800 | |
|---|---|---|
| committer | 2025-01-15 13:26:34 -0800 | |
| commit | 42a97cfd7acf05acd95dfd76b360bcb4c71526ec (patch) | |
| tree | e1b256734b684b1e80b390b84b83bf152911ede7 | |
| parent | 9211819aed730f1f8254daff2a8045932ccc90e2 (diff) | |
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
3 files changed, 23 insertions, 12 deletions
diff --git a/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp b/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp index 366d3f40e2..5cef0514b4 100644 --- a/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp +++ b/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp @@ -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; } diff --git a/services/surfaceflinger/DisplayHardware/AidlComposerHal.h b/services/surfaceflinger/DisplayHardware/AidlComposerHal.h index 79e3349f83..5fcc8b00ba 100644 --- a/services/surfaceflinger/DisplayHardware/AidlComposerHal.h +++ b/services/surfaceflinger/DisplayHardware/AidlComposerHal.h @@ -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); diff --git a/services/surfaceflinger/DisplayHardware/ComposerHal.cpp b/services/surfaceflinger/DisplayHardware/ComposerHal.cpp index d69a923b4e..1e4132cfc6 100644 --- a/services/surfaceflinger/DisplayHardware/ComposerHal.cpp +++ b/services/surfaceflinger/DisplayHardware/ComposerHal.cpp @@ -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); } |