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

Commit 9b85a194 authored by Brian Lindahl's avatar Brian Lindahl
Browse files

Add robustness for permissions errors to Surface APIs.

Test: Tested ag/14424498 via testHevcTranscodingWithFileDescriptor on
Test: flame - ab/builds/forrest/run/L38000000884507245

Bug: 184903653
Bug: 184112407
Change-Id: I94dcaa31edcf0f810c6cf69ca6e73277470fa51f
parent 807ae39c
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -1268,8 +1268,11 @@ int Surface::query(int what, int* value) const {
                if (err == NO_ERROR) {
                    return NO_ERROR;
                }
                if (composerService()->authenticateSurfaceTexture(
                        mGraphicBufferProducer)) {
                sp<ISurfaceComposer> surfaceComposer = composerService();
                if (surfaceComposer == nullptr) {
                    return -EPERM; // likely permissions error
                }
                if (surfaceComposer->authenticateSurfaceTexture(mGraphicBufferProducer)) {
                    *value = 1;
                } else {
                    *value = 0;
+8 −7
Original line number Diff line number Diff line
@@ -65,12 +65,12 @@ ComposerService::ComposerService()
    connectLocked();
}

void ComposerService::connectLocked() {
bool ComposerService::connectLocked() {
    const String16 name("SurfaceFlinger");
    while (getService(name, &mComposerService) != NO_ERROR) {
        usleep(250000);
    mComposerService = waitForService<ISurfaceComposer>(name);
    if (mComposerService == nullptr) {
        return false; // fatal error or permission problem
    }
    assert(mComposerService != nullptr);

    // Create the death listener.
    class DeathObserver : public IBinder::DeathRecipient {
@@ -86,16 +86,17 @@ void ComposerService::connectLocked() {

    mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this));
    IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver);
    return true;
}

/*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() {
    ComposerService& instance = ComposerService::getInstance();
    Mutex::Autolock _l(instance.mLock);
    if (instance.mComposerService == nullptr) {
        ComposerService::getInstance().connectLocked();
        assert(instance.mComposerService != nullptr);
        if (ComposerService::getInstance().connectLocked()) {
            ALOGD("ComposerService reconnected");
        }
    }
    return instance.mComposerService;
}

+2 −3
Original line number Diff line number Diff line
@@ -45,13 +45,12 @@ class ComposerService : public Singleton<ComposerService>
    Mutex mLock;

    ComposerService();
    void connectLocked();
    bool connectLocked();
    void composerServiceDied();
    friend class Singleton<ComposerService>;
public:

    // Get a connection to the Composer Service.  This will block until
    // a connection is established.
    // a connection is established. Returns null if permission is denied.
    static sp<ISurfaceComposer> getComposerService();
};