diff options
-rw-r--r-- | libs/gui/ISurfaceComposer.cpp | 18 | ||||
-rw-r--r-- | libs/gui/SurfaceComposerClient.cpp | 9 | ||||
-rw-r--r-- | libs/gui/SurfaceControl.cpp | 7 | ||||
-rw-r--r-- | libs/gui/include/gui/ISurfaceComposer.h | 16 | ||||
-rw-r--r-- | libs/gui/include/gui/SurfaceComposerClient.h | 2 | ||||
-rw-r--r-- | libs/gui/include/gui/SurfaceControl.h | 2 | ||||
-rw-r--r-- | libs/gui/tests/Surface_test.cpp | 4 | ||||
-rw-r--r-- | services/surfaceflinger/Client.cpp | 63 | ||||
-rw-r--r-- | services/surfaceflinger/Client.h | 9 | ||||
-rw-r--r-- | services/surfaceflinger/Layer.cpp | 12 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.cpp | 31 | ||||
-rw-r--r-- | services/surfaceflinger/SurfaceFlinger.h | 4 | ||||
-rw-r--r-- | services/surfaceflinger/tests/Credentials_test.cpp | 20 |
13 files changed, 27 insertions, 170 deletions
diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp index 2f6ef79af9..a481e81131 100644 --- a/libs/gui/ISurfaceComposer.cpp +++ b/libs/gui/ISurfaceComposer.cpp @@ -63,16 +63,6 @@ public: return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder()); } - virtual sp<ISurfaceComposerClient> createScopedConnection( - const sp<IGraphicBufferProducer>& parent) - { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - data.writeStrongBinder(IInterface::asBinder(parent)); - remote()->transact(BnSurfaceComposer::CREATE_SCOPED_CONNECTION, data, &reply); - return interface_cast<ISurfaceComposerClient>(reply.readStrongBinder()); - } - virtual void setTransactionState(const Vector<ComposerState>& state, const Vector<DisplayState>& displays, uint32_t flags, const sp<IBinder>& applyToken, @@ -711,14 +701,6 @@ status_t BnSurfaceComposer::onTransact( reply->writeStrongBinder(b); return NO_ERROR; } - case CREATE_SCOPED_CONNECTION: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - sp<IGraphicBufferProducer> bufferProducer = - interface_cast<IGraphicBufferProducer>(data.readStrongBinder()); - sp<IBinder> b = IInterface::asBinder(createScopedConnection(bufferProducer)); - reply->writeStrongBinder(b); - return NO_ERROR; - } case SET_TRANSACTION_STATE: { CHECK_INTERFACE(ISurfaceComposer, data, reply); diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index e043762653..824e43fb07 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -910,11 +910,6 @@ SurfaceComposerClient::SurfaceComposerClient() { } -SurfaceComposerClient::SurfaceComposerClient(const sp<IGraphicBufferProducer>& root) - : mStatus(NO_INIT), mParent(root) -{ -} - SurfaceComposerClient::SurfaceComposerClient(const sp<ISurfaceComposerClient>& client) : mStatus(NO_ERROR), mClient(client) { @@ -923,10 +918,8 @@ SurfaceComposerClient::SurfaceComposerClient(const sp<ISurfaceComposerClient>& c void SurfaceComposerClient::onFirstRef() { sp<ISurfaceComposer> sf(ComposerService::getComposerService()); if (sf != nullptr && mStatus == NO_INIT) { - auto rootProducer = mParent.promote(); sp<ISurfaceComposerClient> conn; - conn = (rootProducer != nullptr) ? sf->createScopedConnection(rootProducer) : - sf->createConnection(); + conn = sf->createConnection(); if (conn != nullptr) { mClient = conn; mStatus = NO_ERROR; diff --git a/libs/gui/SurfaceControl.cpp b/libs/gui/SurfaceControl.cpp index 3a6dfdada5..b6ef286fd4 100644 --- a/libs/gui/SurfaceControl.cpp +++ b/libs/gui/SurfaceControl.cpp @@ -54,6 +54,13 @@ SurfaceControl::SurfaceControl( { } +SurfaceControl::SurfaceControl(const sp<SurfaceControl>& other) { + mClient = other->mClient; + mHandle = other->mHandle; + mGraphicBufferProducer = other->mGraphicBufferProducer; + mOwned = false; +} + SurfaceControl::~SurfaceControl() { destroy(); diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h index e0ff410873..1534fca790 100644 --- a/libs/gui/include/gui/ISurfaceComposer.h +++ b/libs/gui/include/gui/ISurfaceComposer.h @@ -87,22 +87,11 @@ public: eVsyncSourceSurfaceFlinger = 1 }; - /* create connection with surface flinger, requires - * ACCESS_SURFACE_FLINGER permission + /* + * Create a connection with SurfaceFlinger. */ virtual sp<ISurfaceComposerClient> createConnection() = 0; - /** create a scoped connection with surface flinger. - * Surfaces produced with this connection will act - * as children of the passed in GBP. That is to say - * SurfaceFlinger will draw them relative and confined to - * drawing of buffers from the layer associated with parent. - * As this is graphically equivalent in reach to just drawing - * pixels into the parent buffers, it requires no special permission. - */ - virtual sp<ISurfaceComposerClient> createScopedConnection( - const sp<IGraphicBufferProducer>& parent) = 0; - /* return an IDisplayEventConnection */ virtual sp<IDisplayEventConnection> createDisplayEventConnection( VsyncSource vsyncSource = eVsyncSourceApp) = 0; @@ -356,7 +345,6 @@ public: ENABLE_VSYNC_INJECTIONS, INJECT_VSYNC, GET_LAYER_DEBUG_INFO, - CREATE_SCOPED_CONNECTION, GET_COMPOSITION_PREFERENCE, GET_COLOR_MANAGEMENT, GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES, diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h index 9765cdd714..4a8e01bec1 100644 --- a/libs/gui/include/gui/SurfaceComposerClient.h +++ b/libs/gui/include/gui/SurfaceComposerClient.h @@ -90,7 +90,6 @@ class SurfaceComposerClient : public RefBase public: SurfaceComposerClient(); SurfaceComposerClient(const sp<ISurfaceComposerClient>& client); - SurfaceComposerClient(const sp<IGraphicBufferProducer>& parent); virtual ~SurfaceComposerClient(); // Always make sure we could initialize @@ -402,7 +401,6 @@ private: mutable Mutex mLock; status_t mStatus; sp<ISurfaceComposerClient> mClient; - wp<IGraphicBufferProducer> mParent; }; // --------------------------------------------------------------------------- diff --git a/libs/gui/include/gui/SurfaceControl.h b/libs/gui/include/gui/SurfaceControl.h index ccb30fa8e7..9bba76674d 100644 --- a/libs/gui/include/gui/SurfaceControl.h +++ b/libs/gui/include/gui/SurfaceControl.h @@ -75,6 +75,8 @@ public: status_t getLayerFrameStats(FrameStats* outStats) const; sp<SurfaceComposerClient> getClient() const; + + explicit SurfaceControl(const sp<SurfaceControl>& other); private: // can't be copied diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp index 13fac7fa04..afc30d17b0 100644 --- a/libs/gui/tests/Surface_test.cpp +++ b/libs/gui/tests/Surface_test.cpp @@ -545,10 +545,6 @@ public: } sp<ISurfaceComposerClient> createConnection() override { return nullptr; } - sp<ISurfaceComposerClient> createScopedConnection( - const sp<IGraphicBufferProducer>& /* parent */) override { - return nullptr; - } sp<IDisplayEventConnection> createDisplayEventConnection(ISurfaceComposer::VsyncSource) override { return nullptr; diff --git a/services/surfaceflinger/Client.cpp b/services/surfaceflinger/Client.cpp index 0b59147c5a..ee4ec506f7 100644 --- a/services/surfaceflinger/Client.cpp +++ b/services/surfaceflinger/Client.cpp @@ -35,13 +35,7 @@ const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER" // --------------------------------------------------------------------------- Client::Client(const sp<SurfaceFlinger>& flinger) - : Client(flinger, nullptr) -{ -} - -Client::Client(const sp<SurfaceFlinger>& flinger, const sp<Layer>& parentLayer) - : mFlinger(flinger), - mParentLayer(parentLayer) + : mFlinger(flinger) { } @@ -65,25 +59,6 @@ Client::~Client() } } -void Client::updateParent(const sp<Layer>& parentLayer) { - Mutex::Autolock _l(mLock); - - // If we didn't ever have a parent, then we must instead be - // relying on permissions and we never need a parent. - if (mParentLayer != nullptr) { - mParentLayer = parentLayer; - } -} - -sp<Layer> Client::getParentLayer(bool* outParentDied) const { - Mutex::Autolock _l(mLock); - sp<Layer> parent = mParentLayer.promote(); - if (outParentDied != nullptr) { - *outParentDied = (mParentLayer != nullptr && parent == nullptr); - } - return parent; -} - status_t Client::initCheck() const { return NO_ERROR; } @@ -119,32 +94,6 @@ sp<Layer> Client::getLayerUser(const sp<IBinder>& handle) const } -status_t Client::onTransact( - uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) -{ - // these must be checked - IPCThreadState* ipc = IPCThreadState::self(); - const int pid = ipc->getCallingPid(); - const int uid = ipc->getCallingUid(); - const int self_pid = getpid(); - // If we are called from another non root process without the GRAPHICS, SYSTEM, or ROOT - // uid we require the sAccessSurfaceFlinger permission. - // We grant an exception in the case that the Client has a "parent layer", as its - // effects will be scoped to that layer. - if (CC_UNLIKELY(pid != self_pid && uid != AID_GRAPHICS && uid != AID_SYSTEM && uid != 0) - && (getParentLayer() == nullptr)) { - // we're called from a different process, do the real check - if (!PermissionCache::checkCallingPermission(sAccessSurfaceFlinger)) - { - ALOGE("Permission Denial: " - "can't openGlobalTransaction pid=%d, uid<=%d", pid, uid); - return PERMISSION_DENIED; - } - } - return BnSurfaceComposerClient::onTransact(code, data, reply, flags); -} - - status_t Client::createSurface( const String8& name, uint32_t w, uint32_t h, PixelFormat format, uint32_t flags, @@ -160,16 +109,8 @@ status_t Client::createSurface( return NAME_NOT_FOUND; } } - if (parent == nullptr) { - bool parentDied; - parent = getParentLayer(&parentDied); - // If we had a parent, but it died, we've lost all - // our capabilities. - if (parentDied) { - return NAME_NOT_FOUND; - } - } + // We rely on createLayer to check permissions. return mFlinger->createLayer(name, this, w, h, format, flags, windowType, ownerUid, handle, gbp, &parent); } diff --git a/services/surfaceflinger/Client.h b/services/surfaceflinger/Client.h index 49437ed7fd..4a74739a10 100644 --- a/services/surfaceflinger/Client.h +++ b/services/surfaceflinger/Client.h @@ -39,7 +39,6 @@ class Client : public BnSurfaceComposerClient { public: explicit Client(const sp<SurfaceFlinger>& flinger); - Client(const sp<SurfaceFlinger>& flinger, const sp<Layer>& parentLayer); ~Client(); status_t initCheck() const; @@ -51,8 +50,6 @@ public: sp<Layer> getLayerUser(const sp<IBinder>& handle) const; - void updateParent(const sp<Layer>& parentLayer); - private: // ISurfaceComposerClient interface virtual status_t createSurface( @@ -68,17 +65,11 @@ private: virtual status_t getLayerFrameStats(const sp<IBinder>& handle, FrameStats* outStats) const; - virtual status_t onTransact( - uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags); - - sp<Layer> getParentLayer(bool* outParentDied = nullptr) const; - // constant sp<SurfaceFlinger> mFlinger; // protected by mLock DefaultKeyedVector< wp<IBinder>, wp<Layer> > mLayers; - wp<Layer> mParentLayer; // thread-safe mutable Mutex mLock; diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index f4b3cddc63..2d3fd8ecbb 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -1666,11 +1666,6 @@ bool Layer::reparentChildren(const sp<IBinder>& newParentHandle) { } for (const sp<Layer>& child : mCurrentChildren) { newParent->addChild(child); - - sp<Client> client(child->mClientRef.promote()); - if (client != nullptr) { - client->updateParent(newParent); - } } mCurrentChildren.clear(); @@ -1705,13 +1700,6 @@ bool Layer::reparent(const sp<IBinder>& newParentHandle) { addToCurrentState(); } - sp<Client> client(mClientRef.promote()); - sp<Client> newParentClient(newParent->mClientRef.promote()); - - if (client != newParentClient) { - client->updateParent(newParent); - } - Mutex::Autolock lock(mStateMutex); if (mLayerDetached) { mLayerDetached = false; diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 4d685590cb..13997bea21 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -458,19 +458,6 @@ sp<ISurfaceComposerClient> SurfaceFlinger::createConnection() { return initClient(new Client(this)); } -sp<ISurfaceComposerClient> SurfaceFlinger::createScopedConnection( - const sp<IGraphicBufferProducer>& gbp) { - if (authenticateSurfaceTexture(gbp) == false) { - return nullptr; - } - const auto& layer = (static_cast<MonitoredProducer*>(gbp.get()))->getLayer(); - if (layer == nullptr) { - return nullptr; - } - - return initClient(new Client(this, layer)); -} - sp<IBinder> SurfaceFlinger::createDisplay(const String8& displayName, bool secure) { @@ -3243,7 +3230,8 @@ status_t SurfaceFlinger::addClientLayer(const sp<Client>& client, const sp<IBinder>& handle, const sp<IGraphicBufferProducer>& gbc, const sp<Layer>& lbc, - const sp<Layer>& parent) + const sp<Layer>& parent, + bool addToCurrentState) { // add this layer to the current state list { @@ -3253,13 +3241,12 @@ status_t SurfaceFlinger::addClientLayer(const sp<Client>& client, MAX_LAYERS); return NO_MEMORY; } - if (parent == nullptr) { + if (parent == nullptr && addToCurrentState) { mCurrentState.layersSortedByZ.add(lbc); - } else { - if (parent->isRemovedFromCurrentState()) { + } else if (parent == nullptr || parent->isRemovedFromCurrentState()) { ALOGE("addClientLayer called with a removed parent"); lbc->onRemovedFromCurrentState(); - } + } else { parent->addChild(lbc); } @@ -3864,7 +3851,9 @@ status_t SurfaceFlinger::createLayer( layer->setInfo(windowType, ownerUid); - result = addClientLayer(client, *handle, *gbp, layer, *parent); + bool addToCurrentState = callingThreadHasUnscopedSurfaceFlingerAccess(); + result = addClientLayer(client, *handle, *gbp, layer, *parent, + addToCurrentState); if (result != NO_ERROR) { return result; } @@ -4828,7 +4817,6 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { // access to SF. case BOOT_FINISHED: case CLEAR_ANIMATION_FRAME_STATS: - case CREATE_CONNECTION: case CREATE_DISPLAY: case DESTROY_DISPLAY: case ENABLE_VSYNC_INJECTIONS: @@ -4875,8 +4863,7 @@ status_t SurfaceFlinger::CheckTransactCodeCredentials(uint32_t code) { // Calling setTransactionState is safe, because you need to have been // granted a reference to Client* and Handle* to do anything with it. case SET_TRANSACTION_STATE: - // Creating a scoped connection is safe, as per discussion in ISurfaceComposer.h - case CREATE_SCOPED_CONNECTION: + case CREATE_CONNECTION: case GET_COLOR_MANAGEMENT: case GET_COMPOSITION_PREFERENCE: { return OK; diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index c37f159f7b..bfc87a02eb 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -437,7 +437,6 @@ private: * ISurfaceComposer interface */ virtual sp<ISurfaceComposerClient> createConnection(); - virtual sp<ISurfaceComposerClient> createScopedConnection(const sp<IGraphicBufferProducer>& gbp); virtual sp<IBinder> createDisplay(const String8& displayName, bool secure); virtual void destroyDisplay(const sp<IBinder>& displayToken); virtual sp<IBinder> getBuiltInDisplay(int32_t id); @@ -620,7 +619,8 @@ private: const sp<IBinder>& handle, const sp<IGraphicBufferProducer>& gbc, const sp<Layer>& lbc, - const sp<Layer>& parent); + const sp<Layer>& parent, + bool addToCurrentState); /* ------------------------------------------------------------------------ * Boot animation, on/off animations and screen capture diff --git a/services/surfaceflinger/tests/Credentials_test.cpp b/services/surfaceflinger/tests/Credentials_test.cpp index a73ec6c7ef..8560f5ed3e 100644 --- a/services/surfaceflinger/tests/Credentials_test.cpp +++ b/services/surfaceflinger/tests/Credentials_test.cpp @@ -162,10 +162,10 @@ TEST_F(CredentialsTest, ClientInitTest) { setSystemUID(); ASSERT_NO_FATAL_FAILURE(initClient()); - // No one else can init the client. + // Anyone else can init the client. setBinUID(); mComposerClient = new SurfaceComposerClient; - ASSERT_EQ(NO_INIT, mComposerClient->initCheck()); + ASSERT_NO_FATAL_FAILURE(initClient()); } TEST_F(CredentialsTest, GetBuiltInDisplayAccessTest) { @@ -222,22 +222,6 @@ TEST_F(CredentialsTest, SetActiveColorModeTest) { ASSERT_NO_FATAL_FAILURE(checkWithPrivileges<status_t>(condition, NO_ERROR, PERMISSION_DENIED)); } -TEST_F(CredentialsTest, CreateSurfaceTest) { - sp<IBinder> display(SurfaceComposerClient::getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain)); - DisplayInfo info; - SurfaceComposerClient::getDisplayInfo(display, &info); - const ssize_t displayWidth = info.w; - const ssize_t displayHeight = info.h; - - std::function<bool()> condition = [=]() { - mBGSurfaceControl = - mComposerClient->createSurface(SURFACE_NAME, displayWidth, displayHeight, - PIXEL_FORMAT_RGBA_8888, 0); - return mBGSurfaceControl != nullptr && mBGSurfaceControl->isValid(); - }; - ASSERT_NO_FATAL_FAILURE(checkWithPrivileges(condition, true, false)); -} - TEST_F(CredentialsTest, CreateDisplayTest) { std::function<bool()> condition = [=]() { sp<IBinder> testDisplay = SurfaceComposerClient::createDisplay(DISPLAY_NAME, true); |