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

Commit bab4b47e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "aaudio service: prevent disconnected endpoints from being used"

parents d5cbcfd2 be0a5b6e
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ std::string AAudioServiceEndpoint::dump() const {
    result << "    Reference Count:      " << mOpenCount << "\n";
    result << "    Requested Device Id:  " << mRequestedDeviceId << "\n";
    result << "    Device Id:            " << getDeviceId() << "\n";
    result << "    Connected:            " << mConnected.load() << "\n";
    result << "    Registered Streams:" << "\n";
    result << AAudioServiceStreamShared::dumpHeader() << "\n";
    for (const auto stream : mRegisteredStreams) {
@@ -74,7 +75,9 @@ std::string AAudioServiceEndpoint::dump() const {

void AAudioServiceEndpoint::disconnectRegisteredStreams() {
    std::lock_guard<std::mutex> lock(mLockStreams);
    mConnected.store(false);
    for (const auto stream : mRegisteredStreams) {
        ALOGD("disconnectRegisteredStreams() stop and disconnect %p", stream.get());
        stream->stop();
        stream->disconnect();
    }
@@ -96,6 +99,9 @@ aaudio_result_t AAudioServiceEndpoint::unregisterStream(sp<AAudioServiceStreamBa
}

bool AAudioServiceEndpoint::matches(const AAudioStreamConfiguration& configuration) {
    if (!mConnected.load()) {
        return false; // Only use an endpoint if it is connected to a device.
    }
    if (configuration.getDirection() != getDirection()) {
        return false;
    }
+6 −0
Original line number Diff line number Diff line
@@ -97,6 +97,10 @@ public:
        mOpenCount = count;
    }

    bool isConnected() const {
        return mConnected;
    }

protected:
    void                     disconnectRegisteredStreams();

@@ -111,6 +115,8 @@ protected:
    int32_t                  mOpenCount = 0;
    int32_t                  mRequestedDeviceId = 0;

    std::atomic<bool>        mConnected{true};

};

} /* namespace aaudio */
+6 −1
Original line number Diff line number Diff line
@@ -91,7 +91,12 @@ aaudio_result_t AAudioServiceEndpointShared::close() {
static void *aaudio_endpoint_thread_proc(void *context) {
    AAudioServiceEndpointShared *endpoint = (AAudioServiceEndpointShared *) context;
    if (endpoint != NULL) {
        return endpoint->callbackLoop();
        void *result = endpoint->callbackLoop();
        // Close now so that the HW resource is freed and we can open a new device.
        if (!endpoint->isConnected()) {
            endpoint->close();
        }
        return result;
    } else {
        return NULL;
    }