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

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

Merge "Enable clang-tidy in oboeservice."

parents 3a7cf73b 613e6aec
Loading
Loading
Loading
Loading
+21 −23
Original line number Diff line number Diff line
@@ -73,13 +73,13 @@ aaudio_result_t AAudioClientTracker::registerClient(pid_t pid,
        return AAUDIO_ERROR_NULL;
    }

    std::lock_guard<std::mutex> lock(mLock);
    const std::lock_guard<std::mutex> lock(mLock);
    if (mNotificationClients.count(pid) == 0) {
        sp<IBinder> binder = IInterface::asBinder(client);
        sp<NotificationClient> notificationClient = new NotificationClient(pid, binder);
        const sp<IBinder> binder = IInterface::asBinder(client);
        const sp<NotificationClient> notificationClient = new NotificationClient(pid, binder);
        mNotificationClients[pid] = notificationClient;

        status_t status = binder->linkToDeath(notificationClient);
        const status_t status = binder->linkToDeath(notificationClient);
        ALOGW_IF(status != NO_ERROR, "registerClient() linkToDeath = %d\n", status);
        return AAudioConvert_androidToAAudioResult(status);
    } else {
@@ -90,12 +90,12 @@ aaudio_result_t AAudioClientTracker::registerClient(pid_t pid,

void AAudioClientTracker::unregisterClient(pid_t pid) {
    ALOGV("unregisterClient(), calling pid = %d, getpid() = %d\n", pid, getpid());
    std::lock_guard<std::mutex> lock(mLock);
    const std::lock_guard<std::mutex> lock(mLock);
    mNotificationClients.erase(pid);
}

int32_t AAudioClientTracker::getStreamCount(pid_t pid) {
    std::lock_guard<std::mutex> lock(mLock);
    const std::lock_guard<std::mutex> lock(mLock);
    auto it = mNotificationClients.find(pid);
    if (it != mNotificationClients.end()) {
        return it->second->getStreamCount();
@@ -105,18 +105,19 @@ int32_t AAudioClientTracker::getStreamCount(pid_t pid) {
}

aaudio_result_t
AAudioClientTracker::registerClientStream(pid_t pid, sp<AAudioServiceStreamBase> serviceStream) {
AAudioClientTracker::registerClientStream(
        pid_t pid, const sp<AAudioServiceStreamBase>& serviceStream) {
    ALOGV("registerClientStream(%d,)\n", pid);
    std::lock_guard<std::mutex> lock(mLock);
    const std::lock_guard<std::mutex> lock(mLock);
    return getNotificationClient_l(pid)->registerClientStream(serviceStream);
}

// Find the tracker for this process and remove it.
aaudio_result_t
AAudioClientTracker::unregisterClientStream(pid_t pid,
                                            sp<AAudioServiceStreamBase> serviceStream) {
                                            const sp<AAudioServiceStreamBase>& serviceStream) {
    ALOGV("unregisterClientStream(%d,)\n", pid);
    std::lock_guard<std::mutex> lock(mLock);
    const std::lock_guard<std::mutex> lock(mLock);
    auto it = mNotificationClients.find(pid);
    if (it != mNotificationClients.end()) {
        ALOGV("unregisterClientStream(%d,) found NotificationClient\n", pid);
@@ -129,12 +130,12 @@ AAudioClientTracker::unregisterClientStream(pid_t pid,

void AAudioClientTracker::setExclusiveEnabled(pid_t pid, bool enabled) {
    ALOGD("%s(%d, %d)\n", __func__, pid, enabled);
    std::lock_guard<std::mutex> lock(mLock);
    const std::lock_guard<std::mutex> lock(mLock);
    getNotificationClient_l(pid)->setExclusiveEnabled(enabled);
}

bool AAudioClientTracker::isExclusiveEnabled(pid_t pid) {
    std::lock_guard<std::mutex> lock(mLock);
    const std::lock_guard<std::mutex> lock(mLock);
    return getNotificationClient_l(pid)->isExclusiveEnabled();
}

@@ -158,24 +159,21 @@ AAudioClientTracker::NotificationClient::NotificationClient(pid_t pid, const sp<
        : mProcessId(pid), mBinder(binder) {
}

AAudioClientTracker::NotificationClient::~NotificationClient() {
}

int32_t AAudioClientTracker::NotificationClient::getStreamCount() {
    std::lock_guard<std::mutex> lock(mLock);
    const std::lock_guard<std::mutex> lock(mLock);
    return mStreams.size();
}

aaudio_result_t AAudioClientTracker::NotificationClient::registerClientStream(
        sp<AAudioServiceStreamBase> serviceStream) {
    std::lock_guard<std::mutex> lock(mLock);
        const sp<AAudioServiceStreamBase>& serviceStream) {
    const std::lock_guard<std::mutex> lock(mLock);
    mStreams.insert(serviceStream);
    return AAUDIO_OK;
}

aaudio_result_t AAudioClientTracker::NotificationClient::unregisterClientStream(
        sp<AAudioServiceStreamBase> serviceStream) {
    std::lock_guard<std::mutex> lock(mLock);
        const sp<AAudioServiceStreamBase>& serviceStream) {
    const std::lock_guard<std::mutex> lock(mLock);
    mStreams.erase(serviceStream);
    return AAUDIO_OK;
}
@@ -189,20 +187,20 @@ void AAudioClientTracker::NotificationClient::binderDied(const wp<IBinder>& who
        std::set<sp<AAudioServiceStreamBase>>  streamsToClose;

        {
            std::lock_guard<std::mutex> lock(mLock);
            const std::lock_guard<std::mutex> lock(mLock);
            for (const auto& serviceStream : mStreams) {
                streamsToClose.insert(serviceStream);
            }
        }

        for (const auto& serviceStream : streamsToClose) {
            aaudio_handle_t handle = serviceStream->getHandle();
            const aaudio_handle_t handle = serviceStream->getHandle();
            ALOGW("binderDied() close abandoned stream 0x%08X\n", handle);
            aaudioService->asAAudioServiceInterface().closeStream(handle);
        }
        // mStreams should be empty now
    }
    sp<NotificationClient> keep(this);
    const sp<NotificationClient> keep(this);
    AAudioClientTracker::getInstance().unregisterClient(mProcessId);
}

+9 −7
Original line number Diff line number Diff line
@@ -54,10 +54,10 @@ public:
    int32_t getStreamCount(pid_t pid);

    aaudio_result_t registerClientStream(pid_t pid,
                                         android::sp<AAudioServiceStreamBase> serviceStream);
                                         const android::sp<AAudioServiceStreamBase>& serviceStream);

    aaudio_result_t unregisterClientStream(pid_t pid,
                                           android::sp<AAudioServiceStreamBase> serviceStream);
    aaudio_result_t unregisterClientStream(
            pid_t pid, const android::sp<AAudioServiceStreamBase>& serviceStream);

    /**
     * Specify whether a process is allowed to create an EXCLUSIVE MMAP stream.
@@ -84,15 +84,17 @@ private:
    class NotificationClient : public IBinder::DeathRecipient {
    public:
        NotificationClient(pid_t pid, const android::sp<IBinder>& binder);
        virtual ~NotificationClient();
        ~NotificationClient() override = default;

        int32_t getStreamCount();

        std::string dump() const;

        aaudio_result_t registerClientStream(android::sp<AAudioServiceStreamBase> serviceStream);
        aaudio_result_t registerClientStream(
                const android::sp<AAudioServiceStreamBase>& serviceStream);

        aaudio_result_t unregisterClientStream(android::sp<AAudioServiceStreamBase> serviceStream);
        aaudio_result_t unregisterClientStream(
                const android::sp<AAudioServiceStreamBase>& serviceStream);

        void setExclusiveEnabled(bool enabled) {
            mExclusiveEnabled = enabled;
@@ -103,7 +105,7 @@ private:
        }

        // IBinder::DeathRecipient
        virtual     void    binderDied(const android::wp<IBinder>& who);
        void binderDied(const android::wp<IBinder>& who) override;

    private:
        mutable std::mutex                              mLock;
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@

namespace aaudio {

aaudio_result_t AAudioCommandQueue::sendCommand(std::shared_ptr<AAudioCommand> command) {
aaudio_result_t AAudioCommandQueue::sendCommand(const std::shared_ptr<AAudioCommand>& command) {
    {
        std::scoped_lock<std::mutex> _l(mLock);
        if (!mRunning) {
+3 −3
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@

namespace aaudio {

typedef int32_t aaudio_command_opcode;
using aaudio_command_opcode = int32_t;

class AAudioCommandParam {
public:
@@ -39,7 +39,7 @@ public:
    explicit AAudioCommand(
            aaudio_command_opcode opCode, std::shared_ptr<AAudioCommandParam> param = nullptr,
            bool waitForReply = false, int64_t timeoutNanos = 0)
            : operationCode(opCode), parameter(param), isWaitingForReply(waitForReply),
            : operationCode(opCode), parameter(std::move(param)), isWaitingForReply(waitForReply),
              timeoutNanoseconds(timeoutNanos) { }
    virtual ~AAudioCommand() = default;

@@ -66,7 +66,7 @@ public:
     * @return the result of sending the command or the result of executing the command if command
     *         need to wait for a reply. If timeout happens, AAUDIO_ERROR_TIMEOUT will be returned.
     */
    aaudio_result_t sendCommand(std::shared_ptr<AAudioCommand> command);
    aaudio_result_t sendCommand(const std::shared_ptr<AAudioCommand>& command);

    /**
     * Wait for next available command OR until the timeout is expired.
+17 −15
Original line number Diff line number Diff line
@@ -162,7 +162,7 @@ sp<AAudioServiceEndpoint> AAudioEndpointManager::openExclusiveEndpoint(
        const aaudio::AAudioStreamRequest &request,
        sp<AAudioServiceEndpoint> &endpointToSteal) {

    std::lock_guard<std::mutex> lock(mExclusiveLock);
    const std::lock_guard<std::mutex> lock(mExclusiveLock);

    const AAudioStreamConfiguration &configuration = request.getConstantConfiguration();

@@ -183,19 +183,20 @@ sp<AAudioServiceEndpoint> AAudioEndpointManager::openExclusiveEndpoint(
            // and START calls. This will help preserve app compatibility.
            // An app can avoid having this happen by closing their streams when
            // the app is paused.
            pid_t pid = VALUE_OR_FATAL(
            const pid_t pid = VALUE_OR_FATAL(
                aidl2legacy_int32_t_pid_t(request.getAttributionSource().pid));
            AAudioClientTracker::getInstance().setExclusiveEnabled(pid, false);
            endpointToSteal = endpoint; // return it to caller
        }
        return nullptr;
    } else {
        sp<AAudioServiceEndpointMMAP> endpointMMap = new AAudioServiceEndpointMMAP(aaudioService);
        const sp<AAudioServiceEndpointMMAP> endpointMMap =
                new AAudioServiceEndpointMMAP(aaudioService);
        ALOGV("%s(), no match so try to open MMAP %p for dev %d",
              __func__, endpointMMap.get(), configuration.getDeviceId());
        endpoint = endpointMMap;

        aaudio_result_t result = endpoint->open(request);
        const aaudio_result_t result = endpoint->open(request);
        if (result != AAUDIO_OK) {
            endpoint.clear();
        } else {
@@ -217,10 +218,10 @@ sp<AAudioServiceEndpoint> AAudioEndpointManager::openSharedEndpoint(
        AAudioService &aaudioService,
        const aaudio::AAudioStreamRequest &request) {

    std::lock_guard<std::mutex> lock(mSharedLock);
    const std::lock_guard<std::mutex> lock(mSharedLock);

    const AAudioStreamConfiguration &configuration = request.getConstantConfiguration();
    aaudio_direction_t direction = configuration.getDirection();
    const aaudio_direction_t direction = configuration.getDirection();

    // Try to find an existing endpoint.
    sp<AAudioServiceEndpointShared> endpoint = findSharedEndpoint_l(configuration);
@@ -228,7 +229,7 @@ sp<AAudioServiceEndpoint> AAudioEndpointManager::openSharedEndpoint(
    // If we can't find an existing one then open a new one.
    if (endpoint.get() == nullptr) {
        // we must call openStream with audioserver identity
        int64_t token = IPCThreadState::self()->clearCallingIdentity();
        const int64_t token = IPCThreadState::self()->clearCallingIdentity();
        switch (direction) {
            case AAUDIO_DIRECTION_INPUT:
                endpoint = new AAudioServiceEndpointCapture(aaudioService);
@@ -241,7 +242,7 @@ sp<AAudioServiceEndpoint> AAudioEndpointManager::openSharedEndpoint(
        }

        if (endpoint.get() != nullptr) {
            aaudio_result_t result = endpoint->open(request);
            const aaudio_result_t result = endpoint->open(request);
            if (result != AAUDIO_OK) {
                endpoint.clear();
            } else {
@@ -261,7 +262,7 @@ sp<AAudioServiceEndpoint> AAudioEndpointManager::openSharedEndpoint(
    return endpoint;
}

void AAudioEndpointManager::closeEndpoint(sp<AAudioServiceEndpoint>serviceEndpoint) {
void AAudioEndpointManager::closeEndpoint(const sp<AAudioServiceEndpoint>& serviceEndpoint) {
    if (serviceEndpoint->getSharingMode() == AAUDIO_SHARING_MODE_EXCLUSIVE) {
        return closeExclusiveEndpoint(serviceEndpoint);
    } else {
@@ -269,14 +270,15 @@ void AAudioEndpointManager::closeEndpoint(sp<AAudioServiceEndpoint>serviceEndpoi
    }
}

void AAudioEndpointManager::closeExclusiveEndpoint(sp<AAudioServiceEndpoint> serviceEndpoint) {
void AAudioEndpointManager::closeExclusiveEndpoint(
        const sp<AAudioServiceEndpoint>& serviceEndpoint) {
    if (serviceEndpoint.get() == nullptr) {
        return;
    }

    // Decrement the reference count under this lock.
    std::lock_guard<std::mutex> lock(mExclusiveLock);
    int32_t newRefCount = serviceEndpoint->getOpenCount() - 1;
    const std::lock_guard<std::mutex> lock(mExclusiveLock);
    const int32_t newRefCount = serviceEndpoint->getOpenCount() - 1;
    serviceEndpoint->setOpenCount(newRefCount);

    // If no longer in use then actually close it.
@@ -292,14 +294,14 @@ void AAudioEndpointManager::closeExclusiveEndpoint(sp<AAudioServiceEndpoint> ser
    }
}

void AAudioEndpointManager::closeSharedEndpoint(sp<AAudioServiceEndpoint> serviceEndpoint) {
void AAudioEndpointManager::closeSharedEndpoint(const sp<AAudioServiceEndpoint>& serviceEndpoint) {
    if (serviceEndpoint.get() == nullptr) {
        return;
    }

    // Decrement the reference count under this lock.
    std::lock_guard<std::mutex> lock(mSharedLock);
    int32_t newRefCount = serviceEndpoint->getOpenCount() - 1;
    const std::lock_guard<std::mutex> lock(mSharedLock);
    const int32_t newRefCount = serviceEndpoint->getOpenCount() - 1;
    serviceEndpoint->setOpenCount(newRefCount);

    // If no longer in use then actually close it.
Loading