diff options
author | 2022-02-14 14:26:04 -0800 | |
---|---|---|
committer | 2022-02-24 14:17:33 -0800 | |
commit | 07e723660ca6265844be1ebd8c4696977151eeba (patch) | |
tree | d2958abdbd2afe8b143419966e192f9f1311480d | |
parent | d234ff36809daa3aea0196be82b80dbc17067775 (diff) |
Migrate display related methods to AIDL
This migrates display related methods from ISurfaceComposer.h to the AIDL interface.
Bug: 219574942
Test: manual
Change-Id: I11f011ce61bdd6dfbd8e0f1a1af8925820e3de58
-rw-r--r-- | libs/gui/ISurfaceComposer.cpp | 116 | ||||
-rw-r--r-- | libs/gui/Surface.cpp | 5 | ||||
-rw-r--r-- | libs/gui/SurfaceComposerClient.cpp | 43 | ||||
-rw-r--r-- | libs/gui/aidl/android/gui/ISurfaceComposer.aidl | 22 | ||||
-rw-r--r-- | libs/gui/include/gui/ISurfaceComposer.h | 44 | ||||
-rw-r--r-- | libs/gui/include/private/gui/ComposerServiceAIDL.h | 21 | ||||
-rw-r--r-- | libs/gui/tests/Surface_test.cpp | 10 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 75 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.h | 34 |
9 files changed, 185 insertions, 185 deletions
diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp index 5ab0abc561..6911d89cdb 100644 --- a/libs/gui/ISurfaceComposer.cpp +++ b/libs/gui/ISurfaceComposer.cpp @@ -220,81 +220,6 @@ public: return result; } - sp<IBinder> createDisplay(const String8& displayName, bool secure) override { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - status_t status = data.writeString8(displayName); - if (status) { - return nullptr; - } - status = data.writeBool(secure); - if (status) { - return nullptr; - } - - status = remote()->transact(BnSurfaceComposer::CREATE_DISPLAY, data, &reply); - if (status) { - return nullptr; - } - sp<IBinder> display; - status = reply.readNullableStrongBinder(&display); - if (status) { - return nullptr; - } - return display; - } - - void destroyDisplay(const sp<IBinder>& display) override { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - data.writeStrongBinder(display); - remote()->transact(BnSurfaceComposer::DESTROY_DISPLAY, data, &reply); - } - - std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const override { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - if (remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_IDS, data, &reply) == - NO_ERROR) { - std::vector<uint64_t> rawIds; - if (reply.readUint64Vector(&rawIds) == NO_ERROR) { - std::vector<PhysicalDisplayId> displayIds; - displayIds.reserve(rawIds.size()); - - for (const uint64_t rawId : rawIds) { - if (const auto id = DisplayId::fromValue<PhysicalDisplayId>(rawId)) { - displayIds.push_back(*id); - } - } - return displayIds; - } - } - - return {}; - } - - status_t getPrimaryPhysicalDisplayId(PhysicalDisplayId* displayId) const override { - Parcel data, reply; - SAFE_PARCEL(data.writeInterfaceToken, ISurfaceComposer::getInterfaceDescriptor()); - SAFE_PARCEL(remote()->transact, BnSurfaceComposer::GET_PRIMARY_PHYSICAL_DISPLAY_ID, data, - &reply); - uint64_t rawId; - SAFE_PARCEL(reply.readUint64, &rawId); - if (const auto id = DisplayId::fromValue<PhysicalDisplayId>(rawId)) { - *displayId = *id; - return NO_ERROR; - } - return NAME_NOT_FOUND; - } - - sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const override { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - data.writeUint64(displayId.value); - remote()->transact(BnSurfaceComposer::GET_PHYSICAL_DISPLAY_TOKEN, data, &reply); - return reply.readStrongBinder(); - } - void setPowerMode(const sp<IBinder>& display, int mode) override { Parcel data, reply; data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); @@ -1461,29 +1386,6 @@ status_t BnSurfaceComposer::onTransact( reply->writeStrongBinder(IInterface::asBinder(connection)); return NO_ERROR; } - case CREATE_DISPLAY: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - String8 displayName; - SAFE_PARCEL(data.readString8, &displayName); - bool secure = false; - SAFE_PARCEL(data.readBool, &secure); - sp<IBinder> display = createDisplay(displayName, secure); - SAFE_PARCEL(reply->writeStrongBinder, display); - return NO_ERROR; - } - case DESTROY_DISPLAY: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - sp<IBinder> display = data.readStrongBinder(); - destroyDisplay(display); - return NO_ERROR; - } - case GET_PHYSICAL_DISPLAY_TOKEN: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - const auto id = DisplayId::fromValue<PhysicalDisplayId>(data.readUint64()); - if (!id) return BAD_VALUE; - reply->writeStrongBinder(getPhysicalDisplayToken(*id)); - return NO_ERROR; - } case GET_DISPLAY_STATE: { CHECK_INTERFACE(ISurfaceComposer, data, reply); ui::DisplayState state; @@ -1820,24 +1722,6 @@ status_t BnSurfaceComposer::onTransact( } return error; } - case GET_PHYSICAL_DISPLAY_IDS: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - std::vector<PhysicalDisplayId> ids = getPhysicalDisplayIds(); - std::vector<uint64_t> rawIds(ids.size()); - std::transform(ids.begin(), ids.end(), rawIds.begin(), - [](PhysicalDisplayId id) { return id.value; }); - return reply->writeUint64Vector(rawIds); - } - case GET_PRIMARY_PHYSICAL_DISPLAY_ID: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - PhysicalDisplayId id; - status_t result = getPrimaryPhysicalDisplayId(&id); - if (result != NO_ERROR) { - ALOGE("getPrimaryPhysicalDisplayId: Failed to get id"); - return result; - } - return reply->writeUint64(id.value); - } case ADD_REGION_SAMPLING_LISTENER: { CHECK_INTERFACE(ISurfaceComposer, data, reply); Rect samplingArea; diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 20c41460d4..82067580a9 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -45,6 +45,7 @@ #include <gui/ISurfaceComposer.h> #include <gui/LayerState.h> #include <private/gui/ComposerService.h> +#include <private/gui/ComposerServiceAIDL.h> namespace android { @@ -343,7 +344,7 @@ status_t Surface::getFrameTimestamps(uint64_t frameNumber, status_t Surface::getWideColorSupport(bool* supported) { ATRACE_CALL(); - const sp<IBinder> display = composerService()->getInternalDisplayToken(); + const sp<IBinder> display = ComposerServiceAIDL::getInstance().getInternalDisplayToken(); if (display == nullptr) { return NAME_NOT_FOUND; } @@ -356,7 +357,7 @@ status_t Surface::getWideColorSupport(bool* supported) { status_t Surface::getHdrSupport(bool* supported) { ATRACE_CALL(); - const sp<IBinder> display = composerService()->getInternalDisplayToken(); + const sp<IBinder> display = ComposerServiceAIDL::getInstance().getInternalDisplayToken(); if (display == nullptr) { return NAME_NOT_FOUND; } diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index 26ccda580a..52d89657b5 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -1014,32 +1014,59 @@ status_t SurfaceComposerClient::Transaction::apply(bool synchronous) { // --------------------------------------------------------------------------- sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName, bool secure) { - return ComposerService::getComposerService()->createDisplay(displayName, - secure); + sp<IBinder> display = nullptr; + binder::Status status = + ComposerServiceAIDL::getComposerService()->createDisplay(std::string( + displayName.string()), + secure, &display); + return status.isOk() ? display : nullptr; } void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) { - return ComposerService::getComposerService()->destroyDisplay(display); + ComposerServiceAIDL::getComposerService()->destroyDisplay(display); } std::vector<PhysicalDisplayId> SurfaceComposerClient::getPhysicalDisplayIds() { - return ComposerService::getComposerService()->getPhysicalDisplayIds(); + std::vector<int64_t> displayIds; + std::vector<PhysicalDisplayId> physicalDisplayIds; + binder::Status status = + ComposerServiceAIDL::getComposerService()->getPhysicalDisplayIds(&displayIds); + if (status.isOk()) { + physicalDisplayIds.reserve(displayIds.size()); + for (auto item : displayIds) { + auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(item)); + physicalDisplayIds.push_back(*id); + } + } + return physicalDisplayIds; } status_t SurfaceComposerClient::getPrimaryPhysicalDisplayId(PhysicalDisplayId* id) { - return ComposerService::getComposerService()->getPrimaryPhysicalDisplayId(id); + int64_t displayId; + binder::Status status = + ComposerServiceAIDL::getComposerService()->getPrimaryPhysicalDisplayId(&displayId); + if (status.isOk()) { + *id = *DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); + } + return status.transactionError(); } std::optional<PhysicalDisplayId> SurfaceComposerClient::getInternalDisplayId() { - return ComposerService::getComposerService()->getInternalDisplayId(); + ComposerServiceAIDL& instance = ComposerServiceAIDL::getInstance(); + return instance.getInternalDisplayId(); } sp<IBinder> SurfaceComposerClient::getPhysicalDisplayToken(PhysicalDisplayId displayId) { - return ComposerService::getComposerService()->getPhysicalDisplayToken(displayId); + sp<IBinder> display = nullptr; + binder::Status status = + ComposerServiceAIDL::getComposerService()->getPhysicalDisplayToken(displayId.value, + &display); + return status.isOk() ? display : nullptr; } sp<IBinder> SurfaceComposerClient::getInternalDisplayToken() { - return ComposerService::getComposerService()->getInternalDisplayToken(); + ComposerServiceAIDL& instance = ComposerServiceAIDL::getInstance(); + return instance.getInternalDisplayToken(); } void SurfaceComposerClient::Transaction::setAnimationTransaction() { diff --git a/libs/gui/aidl/android/gui/ISurfaceComposer.aidl b/libs/gui/aidl/android/gui/ISurfaceComposer.aidl index 07921a59a5..345c47d5b9 100644 --- a/libs/gui/aidl/android/gui/ISurfaceComposer.aidl +++ b/libs/gui/aidl/android/gui/ISurfaceComposer.aidl @@ -22,6 +22,28 @@ import android.gui.IScreenCaptureListener; /** @hide */ interface ISurfaceComposer { + + /* create a virtual display + * requires ACCESS_SURFACE_FLINGER permission. + */ + @nullable IBinder createDisplay(@utf8InCpp String displayName, boolean secure); + + /* destroy a virtual display + * requires ACCESS_SURFACE_FLINGER permission. + */ + void destroyDisplay(IBinder display); + + /* get stable IDs for connected physical displays. + */ + long[] getPhysicalDisplayIds(); + + long getPrimaryPhysicalDisplayId(); + + /* get token for a physical display given its stable ID obtained via getPhysicalDisplayIds or a + * DisplayEventReceiver hotplug event. + */ + @nullable IBinder getPhysicalDisplayToken(long displayId); + /** * Capture the specified screen. This requires READ_FRAME_BUFFER * permission. This function will fail if there is a secure window on diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h index 4dfc383b57..a2870db2fa 100644 --- a/libs/gui/include/gui/ISurfaceComposer.h +++ b/libs/gui/include/gui/ISurfaceComposer.h @@ -137,40 +137,6 @@ public: VsyncSource vsyncSource = eVsyncSourceApp, EventRegistrationFlags eventRegistration = {}) = 0; - /* create a virtual display - * requires ACCESS_SURFACE_FLINGER permission. - */ - virtual sp<IBinder> createDisplay(const String8& displayName, - bool secure) = 0; - - /* destroy a virtual display - * requires ACCESS_SURFACE_FLINGER permission. - */ - virtual void destroyDisplay(const sp<IBinder>& display) = 0; - - /* get stable IDs for connected physical displays. - */ - virtual std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const = 0; - - virtual status_t getPrimaryPhysicalDisplayId(PhysicalDisplayId*) const = 0; - - // TODO(b/74619554): Remove this stopgap once the framework is display-agnostic. - std::optional<PhysicalDisplayId> getInternalDisplayId() const { - const auto displayIds = getPhysicalDisplayIds(); - return displayIds.empty() ? std::nullopt : std::make_optional(displayIds.front()); - } - - /* get token for a physical display given its stable ID obtained via getPhysicalDisplayIds or a - * DisplayEventReceiver hotplug event. - */ - virtual sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const = 0; - - // TODO(b/74619554): Remove this stopgap once the framework is display-agnostic. - sp<IBinder> getInternalDisplayToken() const { - const auto displayId = getInternalDisplayId(); - return displayId ? getPhysicalDisplayToken(*displayId) : nullptr; - } - /* open/close transactions. requires ACCESS_SURFACE_FLINGER permission */ virtual status_t setTransactionState( const FrameTimelineInfo& frameTimelineInfo, const Vector<ComposerState>& state, @@ -596,9 +562,9 @@ public: CREATE_CONNECTION, GET_STATIC_DISPLAY_INFO, CREATE_DISPLAY_EVENT_CONNECTION, - CREATE_DISPLAY, - DESTROY_DISPLAY, - GET_PHYSICAL_DISPLAY_TOKEN, + CREATE_DISPLAY, // Deprecated. Autogenerated by .aidl now. + DESTROY_DISPLAY, // Deprecated. Autogenerated by .aidl now. + GET_PHYSICAL_DISPLAY_TOKEN, // Deprecated. Autogenerated by .aidl now. SET_TRANSACTION_STATE, AUTHENTICATE_SURFACE, GET_SUPPORTED_FRAME_TIMESTAMPS, @@ -626,7 +592,7 @@ public: GET_PROTECTED_CONTENT_SUPPORT, IS_WIDE_COLOR_DISPLAY, GET_DISPLAY_NATIVE_PRIMARIES, - GET_PHYSICAL_DISPLAY_IDS, + GET_PHYSICAL_DISPLAY_IDS, // Deprecated. Autogenerated by .aidl now. ADD_REGION_SAMPLING_LISTENER, REMOVE_REGION_SAMPLING_LISTENER, SET_DESIRED_DISPLAY_MODE_SPECS, @@ -658,7 +624,7 @@ public: REMOVE_TUNNEL_MODE_ENABLED_LISTENER, ADD_WINDOW_INFOS_LISTENER, REMOVE_WINDOW_INFOS_LISTENER, - GET_PRIMARY_PHYSICAL_DISPLAY_ID, + GET_PRIMARY_PHYSICAL_DISPLAY_ID, // Deprecated. Autogenerated by .aidl now. GET_DISPLAY_DECORATION_SUPPORT, GET_BOOT_DISPLAY_MODE_SUPPORT, SET_BOOT_DISPLAY_MODE, diff --git a/libs/gui/include/private/gui/ComposerServiceAIDL.h b/libs/gui/include/private/gui/ComposerServiceAIDL.h index fee37eefe0..b32cf2a9c2 100644 --- a/libs/gui/include/private/gui/ComposerServiceAIDL.h +++ b/libs/gui/include/private/gui/ComposerServiceAIDL.h @@ -50,6 +50,27 @@ public: // Get a connection to the Composer Service. This will block until // a connection is established. Returns null if permission is denied. static sp<gui::ISurfaceComposer> getComposerService(); + + // the following two methods are moved from ISurfaceComposer.h + // TODO(b/74619554): Remove this stopgap once the framework is display-agnostic. + std::optional<PhysicalDisplayId> getInternalDisplayId() const { + std::vector<int64_t> displayIds; + binder::Status status = mComposerService->getPhysicalDisplayIds(&displayIds); + return (!status.isOk() || displayIds.empty()) + ? std::nullopt + : DisplayId::fromValue<PhysicalDisplayId>( + static_cast<uint64_t>(displayIds.front())); + } + + // TODO(b/74619554): Remove this stopgap once the framework is display-agnostic. + sp<IBinder> getInternalDisplayToken() const { + const auto displayId = getInternalDisplayId(); + if (!displayId) return nullptr; + sp<IBinder> display; + binder::Status status = + mComposerService->getPhysicalDisplayToken(displayId->value, &display); + return status.isOk() ? display : nullptr; + } }; // --------------------------------------------------------------------------- diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp index a885e926a3..07ac2d4065 100644 --- a/libs/gui/tests/Surface_test.cpp +++ b/libs/gui/tests/Surface_test.cpp @@ -260,9 +260,7 @@ TEST_F(SurfaceTest, ScreenshotsOfProtectedBuffersDontSucceed) { sp<ANativeWindow> anw(mSurface); // Verify the screenshot works with no protected buffers. - sp<ISurfaceComposer> sf(ComposerService::getComposerService()); - - const sp<IBinder> display = sf->getInternalDisplayToken(); + const sp<IBinder> display = ComposerServiceAIDL::getInstance().getInternalDisplayToken(); ASSERT_FALSE(display == nullptr); DisplayCaptureArgs captureArgs; @@ -696,12 +694,6 @@ public: ISurfaceComposer::VsyncSource, ISurfaceComposer::EventRegistrationFlags) override { return nullptr; } - sp<IBinder> createDisplay(const String8& /*displayName*/, - bool /*secure*/) override { return nullptr; } - void destroyDisplay(const sp<IBinder>& /*display */) override {} - std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const override { return {}; } - status_t getPrimaryPhysicalDisplayId(PhysicalDisplayId*) const override { return NO_ERROR; } - sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId) const override { return nullptr; } status_t setTransactionState(const FrameTimelineInfo& /*frameTimelineInfo*/, const Vector<ComposerState>& /*state*/, const Vector<DisplayState>& /*displays*/, uint32_t /*flags*/, diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 815febe53d..d50869ff90 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -5396,8 +5396,6 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { // access to SF. case BOOT_FINISHED: case CLEAR_ANIMATION_FRAME_STATS: - case CREATE_DISPLAY: - case DESTROY_DISPLAY: case GET_ANIMATION_FRAME_STATS: case OVERRIDE_HDR_TYPES: case GET_HDR_CAPABILITIES: @@ -5419,7 +5417,6 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { case REMOVE_TUNNEL_MODE_ENABLED_LISTENER: case NOTIFY_POWER_BOOST: case SET_GLOBAL_SHADOW_SETTINGS: - case GET_PRIMARY_PHYSICAL_DISPLAY_ID: case ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN: { // OVERRIDE_HDR_TYPES is used by CTS tests, which acquire the necessary // permission dynamically. Don't use the permission cache for this check. @@ -5450,8 +5447,6 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { case AUTHENTICATE_SURFACE: case GET_ACTIVE_COLOR_MODE: case GET_ACTIVE_DISPLAY_MODE: - case GET_PHYSICAL_DISPLAY_IDS: - case GET_PHYSICAL_DISPLAY_TOKEN: case GET_DISPLAY_COLOR_MODES: case GET_DISPLAY_NATIVE_PRIMARIES: case GET_STATIC_DISPLAY_INFO: @@ -5537,10 +5532,15 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { } return PERMISSION_DENIED; } + case CREATE_DISPLAY: + case DESTROY_DISPLAY: + case GET_PRIMARY_PHYSICAL_DISPLAY_ID: + case GET_PHYSICAL_DISPLAY_IDS: + case GET_PHYSICAL_DISPLAY_TOKEN: case CAPTURE_LAYERS: case CAPTURE_DISPLAY: case CAPTURE_DISPLAY_BY_ID: - LOG_FATAL("Deprecated opcode: %d", code); + LOG_FATAL("Deprecated opcode: %d, migrated to AIDL", code); return PERMISSION_DENIED; } @@ -7192,6 +7192,59 @@ bool SurfaceFlinger::commitCreatedLayers() { } // gui::ISurfaceComposer + +binder::Status SurfaceComposerAIDL::createDisplay(const std::string& displayName, bool secure, + sp<IBinder>* outDisplay) { + status_t status = checkAccessPermission(); + if (status == OK) { + String8 displayName8 = String8::format("%s", displayName.c_str()); + *outDisplay = mFlinger->createDisplay(displayName8, secure); + return binder::Status::ok(); + } + return binder::Status::fromStatusT(status); +} + +binder::Status SurfaceComposerAIDL::destroyDisplay(const sp<IBinder>& display) { + status_t status = checkAccessPermission(); + if (status == OK) { + mFlinger->destroyDisplay(display); + return binder::Status::ok(); + } + return binder::Status::fromStatusT(status); +} + +binder::Status SurfaceComposerAIDL::getPhysicalDisplayIds(std::vector<int64_t>* outDisplayIds) { + std::vector<PhysicalDisplayId> physicalDisplayIds = mFlinger->getPhysicalDisplayIds(); + std::vector<int64_t> displayIds; + displayIds.reserve(physicalDisplayIds.size()); + for (auto item : physicalDisplayIds) { + displayIds.push_back(static_cast<int64_t>(item.value)); + } + *outDisplayIds = displayIds; + return binder::Status::ok(); +} + +binder::Status SurfaceComposerAIDL::getPrimaryPhysicalDisplayId(int64_t* outDisplayId) { + status_t status = checkAccessPermission(); + if (status != OK) { + return binder::Status::fromStatusT(status); + } + + PhysicalDisplayId id; + status = mFlinger->getPrimaryPhysicalDisplayId(&id); + if (status == NO_ERROR) { + *outDisplayId = id.value; + } + return binder::Status::fromStatusT(status); +} + +binder::Status SurfaceComposerAIDL::getPhysicalDisplayToken(int64_t displayId, + sp<IBinder>* outDisplay) { + const auto id = DisplayId::fromValue<PhysicalDisplayId>(static_cast<uint64_t>(displayId)); + *outDisplay = mFlinger->getPhysicalDisplayToken(*id); + return binder::Status::ok(); +} + binder::Status SurfaceComposerAIDL::captureDisplay( const DisplayCaptureArgs& args, const sp<IScreenCaptureListener>& captureListener) { status_t status = mFlinger->captureDisplay(args, captureListener); @@ -7218,6 +7271,16 @@ binder::Status SurfaceComposerAIDL::captureLayers( return binder::Status::fromStatusT(status); } +status_t SurfaceComposerAIDL::checkAccessPermission(bool usePermissionCache) { + if (!mFlinger->callingThreadHasUnscopedSurfaceFlingerAccess(usePermissionCache)) { + IPCThreadState* ipc = IPCThreadState::self(); + ALOGE("Permission Denial: can't access SurfaceFlinger pid=%d, uid=%d", ipc->getCallingPid(), + ipc->getCallingUid()); + return PERMISSION_DENIED; + } + return OK; +} + } // namespace android #if defined(__gl_h_) diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index f09ee5fad0..3670777713 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -517,17 +517,30 @@ private: bool callingThreadHasUnscopedSurfaceFlingerAccess(bool usePermissionCache = true) EXCLUDES(mStateLock); + // the following two methods are moved from ISurfaceComposer.h + // TODO(b/74619554): Remove this stopgap once the framework is display-agnostic. + std::optional<PhysicalDisplayId> getInternalDisplayId() const { + const auto displayIds = getPhysicalDisplayIds(); + return displayIds.empty() ? std::nullopt : std::make_optional(displayIds.front()); + } + + // TODO(b/74619554): Remove this stopgap once the framework is display-agnostic. + sp<IBinder> getInternalDisplayToken() const { + const auto displayId = getInternalDisplayId(); + return displayId ? getPhysicalDisplayToken(*displayId) : nullptr; + } + // Implements ISurfaceComposer sp<ISurfaceComposerClient> createConnection() override; - sp<IBinder> createDisplay(const String8& displayName, bool secure) override; - void destroyDisplay(const sp<IBinder>& displayToken) override; - std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const override EXCLUDES(mStateLock) { + sp<IBinder> createDisplay(const String8& displayName, bool secure); + void destroyDisplay(const sp<IBinder>& displayToken); + std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const EXCLUDES(mStateLock) { Mutex::Autolock lock(mStateLock); return getPhysicalDisplayIdsLocked(); } - status_t getPrimaryPhysicalDisplayId(PhysicalDisplayId*) const override EXCLUDES(mStateLock); + status_t getPrimaryPhysicalDisplayId(PhysicalDisplayId*) const EXCLUDES(mStateLock); - sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const override; + sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId) const; status_t setTransactionState(const FrameTimelineInfo& frameTimelineInfo, const Vector<ComposerState>& state, const Vector<DisplayState>& displays, uint32_t flags, @@ -1414,6 +1427,13 @@ class SurfaceComposerAIDL : public gui::BnSurfaceComposer { public: SurfaceComposerAIDL(sp<SurfaceFlinger> sf) { mFlinger = sf; } + binder::Status createDisplay(const std::string& displayName, bool secure, + sp<IBinder>* outDisplay) override; + binder::Status destroyDisplay(const sp<IBinder>& display) override; + binder::Status getPhysicalDisplayIds(std::vector<int64_t>* outDisplayIds) override; + binder::Status getPrimaryPhysicalDisplayId(int64_t* outDisplayId) override; + binder::Status getPhysicalDisplayToken(int64_t displayId, sp<IBinder>* outDisplay) override; + binder::Status captureDisplay(const DisplayCaptureArgs&, const sp<IScreenCaptureListener>&) override; binder::Status captureDisplayById(int64_t, const sp<IScreenCaptureListener>&) override; @@ -1421,6 +1441,10 @@ public: const sp<IScreenCaptureListener>&) override; private: + static const constexpr bool kUsePermissionCache = true; + status_t checkAccessPermission(bool usePermissionCache = kUsePermissionCache); + +private: sp<SurfaceFlinger> mFlinger; }; |