diff options
author | 2017-04-03 13:27:12 -0700 | |
---|---|---|
committer | 2017-04-06 11:56:06 -0700 | |
commit | 2d191c302df1c7b2443d333a5a243c0043a37101 (patch) | |
tree | 1c2557d22febfb6ace1dd6ff9d74345834aeb3fa | |
parent | 6b698e4fe4ff50dcef818452283637f9870ae770 (diff) |
libgui: Make IDisplayEventConn... a SafeInterface
Converts IDisplayEventConnection to be a SafeInterface such that all
parceling/unparceling is done automatically.
Test: libgui_test + SurfaceFlinger_test + manual testing
Change-Id: I2f5311315dc4fadbf3599f2b28f150097f53de57
-rw-r--r-- | include/gui/IDisplayEventConnection.h | 11 | ||||
-rw-r--r-- | libs/gui/IDisplayEventConnection.cpp | 67 |
2 files changed, 35 insertions, 43 deletions
diff --git a/include/gui/IDisplayEventConnection.h b/include/gui/IDisplayEventConnection.h index 07794489b9..d783f74d7c 100644 --- a/include/gui/IDisplayEventConnection.h +++ b/include/gui/IDisplayEventConnection.h @@ -17,10 +17,10 @@ #pragma once #include <binder/IInterface.h> +#include <binder/SafeInterface.h> #include <utils/Errors.h> -#include <sys/types.h> #include <cstdint> namespace android { @@ -53,10 +53,13 @@ public: virtual void requestNextVsync() = 0; // Asynchronous }; -class BnDisplayEventConnection : public BnInterface<IDisplayEventConnection> { +class BnDisplayEventConnection : public SafeBnInterface<IDisplayEventConnection> { public: - virtual status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, - uint32_t flags = 0); + BnDisplayEventConnection() + : SafeBnInterface<IDisplayEventConnection>("BnDisplayEventConnection") {} + + status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, + uint32_t flags = 0) override; }; } // namespace android diff --git a/libs/gui/IDisplayEventConnection.cpp b/libs/gui/IDisplayEventConnection.cpp index a1974264cd..c0e246fa15 100644 --- a/libs/gui/IDisplayEventConnection.cpp +++ b/libs/gui/IDisplayEventConnection.cpp @@ -18,74 +18,63 @@ #include <private/gui/BitTube.h> -#include <binder/Parcel.h> - namespace android { -enum { +namespace { // Anonymous + +enum class Tag : uint32_t { STEAL_RECEIVE_CHANNEL = IBinder::FIRST_CALL_TRANSACTION, SET_VSYNC_RATE, - REQUEST_NEXT_VSYNC + REQUEST_NEXT_VSYNC, + LAST = REQUEST_NEXT_VSYNC, }; -class BpDisplayEventConnection : public BpInterface<IDisplayEventConnection> { +} // Anonymous namespace + +class BpDisplayEventConnection : public SafeBpInterface<IDisplayEventConnection> { public: explicit BpDisplayEventConnection(const sp<IBinder>& impl) - : BpInterface<IDisplayEventConnection>(impl) {} + : SafeBpInterface<IDisplayEventConnection>(impl, "BpDisplayEventConnection") {} ~BpDisplayEventConnection() override; status_t stealReceiveChannel(gui::BitTube* outChannel) override { - Parcel data, reply; - data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor()); - remote()->transact(STEAL_RECEIVE_CHANNEL, data, &reply); - outChannel->readFromParcel(&reply); - return NO_ERROR; + return callRemote<decltype( + &IDisplayEventConnection::stealReceiveChannel)>(Tag::STEAL_RECEIVE_CHANNEL, + outChannel); } status_t setVsyncRate(uint32_t count) override { - Parcel data, reply; - data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor()); - data.writeUint32(count); - remote()->transact(SET_VSYNC_RATE, data, &reply); - return NO_ERROR; + return callRemote<decltype(&IDisplayEventConnection::setVsyncRate)>(Tag::SET_VSYNC_RATE, + count); } void requestNextVsync() override { - Parcel data, reply; - data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor()); - remote()->transact(REQUEST_NEXT_VSYNC, data, &reply, IBinder::FLAG_ONEWAY); + callRemoteAsync<decltype(&IDisplayEventConnection::requestNextVsync)>( + Tag::REQUEST_NEXT_VSYNC); } }; // Out-of-line virtual method definition to trigger vtable emission in this translation unit (see // clang warning -Wweak-vtables) -BpDisplayEventConnection::~BpDisplayEventConnection() {} +BpDisplayEventConnection::~BpDisplayEventConnection() = default; IMPLEMENT_META_INTERFACE(DisplayEventConnection, "android.gui.DisplayEventConnection"); status_t BnDisplayEventConnection::onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { - switch (code) { - case STEAL_RECEIVE_CHANNEL: { - CHECK_INTERFACE(IDisplayEventConnection, data, reply); - gui::BitTube channel; - stealReceiveChannel(&channel); - channel.writeToParcel(reply); - return NO_ERROR; - } - case SET_VSYNC_RATE: { - CHECK_INTERFACE(IDisplayEventConnection, data, reply); - setVsyncRate(data.readUint32()); - return NO_ERROR; - } - case REQUEST_NEXT_VSYNC: { - CHECK_INTERFACE(IDisplayEventConnection, data, reply); - requestNextVsync(); - return NO_ERROR; - } + if (code < IBinder::FIRST_CALL_TRANSACTION || code > static_cast<uint32_t>(Tag::LAST)) { + return BBinder::onTransact(code, data, reply, flags); + } + auto tag = static_cast<Tag>(code); + switch (tag) { + case Tag::STEAL_RECEIVE_CHANNEL: + return callLocal(data, reply, &IDisplayEventConnection::stealReceiveChannel); + case Tag::SET_VSYNC_RATE: + return callLocal(data, reply, &IDisplayEventConnection::setVsyncRate); + case Tag::REQUEST_NEXT_VSYNC: + return callLocalAsync(data, reply, &IDisplayEventConnection::requestNextVsync); } - return BBinder::onTransact(code, data, reply, flags); } } // namespace android |