Loading services/oboeservice/AAudioClientTracker.cpp +28 −10 Original line number Diff line number Diff line Loading @@ -106,18 +106,9 @@ int32_t AAudioClientTracker::getStreamCount(pid_t pid) { aaudio_result_t AAudioClientTracker::registerClientStream(pid_t pid, sp<AAudioServiceStreamBase> serviceStream) { aaudio_result_t result = AAUDIO_OK; ALOGV("registerClientStream(%d,)\n", pid); std::lock_guard<std::mutex> lock(mLock); sp<NotificationClient> notificationClient = mNotificationClients[pid]; if (notificationClient == 0) { // This will get called the first time the audio server registers an internal stream. ALOGV("registerClientStream(%d,) unrecognized pid\n", pid); notificationClient = new NotificationClient(pid, nullptr); mNotificationClients[pid] = notificationClient; } notificationClient->registerClientStream(serviceStream); return result; return getNotificationClient_l(pid)->registerClientStream(serviceStream); } // Find the tracker for this process and remove it. Loading @@ -136,6 +127,33 @@ AAudioClientTracker::unregisterClientStream(pid_t pid, return AAUDIO_OK; } void AAudioClientTracker::setExclusiveEnabled(pid_t pid, bool enabled) { ALOGD("%s(%d, %d)\n", __func__, pid, enabled); 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); return getNotificationClient_l(pid)->isExclusiveEnabled(); } sp<AAudioClientTracker::NotificationClient> AAudioClientTracker::getNotificationClient_l(pid_t pid) { sp<NotificationClient> notificationClient = mNotificationClients[pid]; if (notificationClient == nullptr) { // This will get called the first time the audio server uses this PID. ALOGV("%s(%d,) unrecognized PID\n", __func__, pid); notificationClient = new AAudioClientTracker::NotificationClient(pid, nullptr); mNotificationClients[pid] = notificationClient; } return notificationClient; } // ======================================= // AAudioClientTracker::NotificationClient // ======================================= AAudioClientTracker::NotificationClient::NotificationClient(pid_t pid, const sp<IBinder>& binder) : mProcessId(pid), mBinder(binder) { } Loading services/oboeservice/AAudioClientTracker.h +22 −1 Original line number Diff line number Diff line Loading @@ -58,6 +58,15 @@ public: aaudio_result_t unregisterClientStream(pid_t pid, android::sp<AAudioServiceStreamBase> serviceStream); /** * Specify whether a process is allowed to create an EXCLUSIVE MMAP stream. * @param pid * @param enabled */ void setExclusiveEnabled(pid_t pid, bool enabled); bool isExclusiveEnabled(pid_t pid); android::AAudioService *getAAudioService() const { return mAAudioService; } Loading @@ -84,17 +93,29 @@ private: aaudio_result_t unregisterClientStream(android::sp<AAudioServiceStreamBase> serviceStream); void setExclusiveEnabled(bool enabled) { mExclusiveEnabled = enabled; } bool isExclusiveEnabled() { return mExclusiveEnabled; } // IBinder::DeathRecipient virtual void binderDied(const android::wp<IBinder>& who); protected: private: mutable std::mutex mLock; const pid_t mProcessId; std::set<android::sp<AAudioServiceStreamBase>> mStreams; // hold onto binder to receive death notifications android::sp<IBinder> mBinder; bool mExclusiveEnabled = true; }; // This must be called under mLock android::sp<NotificationClient> getNotificationClient_l(pid_t pid); mutable std::mutex mLock; std::map<pid_t, android::sp<NotificationClient>> mNotificationClients; android::AAudioService *mAAudioService = nullptr; Loading services/oboeservice/AAudioEndpointManager.cpp +10 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #include <sstream> #include <utility/AAudioUtilities.h> #include "AAudioClientTracker.h" #include "AAudioEndpointManager.h" #include "AAudioServiceEndpointShared.h" #include "AAudioServiceEndpointMMAP.h" Loading Loading @@ -174,7 +175,15 @@ sp<AAudioServiceEndpoint> AAudioEndpointManager::openExclusiveEndpoint( && !request.isSharingModeMatchRequired()) { // app did not request a shared stream ALOGD("%s() endpoint in EXCLUSIVE use. Steal it!", __func__); mExclusiveStolenCount++; endpointToSteal = endpoint; // Prevent this process from getting another EXCLUSIVE stream. // This will prevent two clients from colliding after a DISCONNECTION // when they both try to open an exclusive stream at the same time. // That can result in a stream getting disconnected between the OPEN // 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. AAudioClientTracker::getInstance().setExclusiveEnabled(request.getProcessId(), false); endpointToSteal = endpoint; // return it to caller } return nullptr; } else { Loading services/oboeservice/AAudioService.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -117,7 +117,8 @@ aaudio_handle_t AAudioService::openStream(const aaudio::AAudioStreamRequest &req return AAUDIO_ERROR_ILLEGAL_ARGUMENT; } if (sharingMode == AAUDIO_SHARING_MODE_EXCLUSIVE) { if (sharingMode == AAUDIO_SHARING_MODE_EXCLUSIVE && AAudioClientTracker::getInstance().isExclusiveEnabled(request.getProcessId())) { // only trust audioserver for in service indication bool inService = false; if (isCallerInService()) { Loading Loading
services/oboeservice/AAudioClientTracker.cpp +28 −10 Original line number Diff line number Diff line Loading @@ -106,18 +106,9 @@ int32_t AAudioClientTracker::getStreamCount(pid_t pid) { aaudio_result_t AAudioClientTracker::registerClientStream(pid_t pid, sp<AAudioServiceStreamBase> serviceStream) { aaudio_result_t result = AAUDIO_OK; ALOGV("registerClientStream(%d,)\n", pid); std::lock_guard<std::mutex> lock(mLock); sp<NotificationClient> notificationClient = mNotificationClients[pid]; if (notificationClient == 0) { // This will get called the first time the audio server registers an internal stream. ALOGV("registerClientStream(%d,) unrecognized pid\n", pid); notificationClient = new NotificationClient(pid, nullptr); mNotificationClients[pid] = notificationClient; } notificationClient->registerClientStream(serviceStream); return result; return getNotificationClient_l(pid)->registerClientStream(serviceStream); } // Find the tracker for this process and remove it. Loading @@ -136,6 +127,33 @@ AAudioClientTracker::unregisterClientStream(pid_t pid, return AAUDIO_OK; } void AAudioClientTracker::setExclusiveEnabled(pid_t pid, bool enabled) { ALOGD("%s(%d, %d)\n", __func__, pid, enabled); 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); return getNotificationClient_l(pid)->isExclusiveEnabled(); } sp<AAudioClientTracker::NotificationClient> AAudioClientTracker::getNotificationClient_l(pid_t pid) { sp<NotificationClient> notificationClient = mNotificationClients[pid]; if (notificationClient == nullptr) { // This will get called the first time the audio server uses this PID. ALOGV("%s(%d,) unrecognized PID\n", __func__, pid); notificationClient = new AAudioClientTracker::NotificationClient(pid, nullptr); mNotificationClients[pid] = notificationClient; } return notificationClient; } // ======================================= // AAudioClientTracker::NotificationClient // ======================================= AAudioClientTracker::NotificationClient::NotificationClient(pid_t pid, const sp<IBinder>& binder) : mProcessId(pid), mBinder(binder) { } Loading
services/oboeservice/AAudioClientTracker.h +22 −1 Original line number Diff line number Diff line Loading @@ -58,6 +58,15 @@ public: aaudio_result_t unregisterClientStream(pid_t pid, android::sp<AAudioServiceStreamBase> serviceStream); /** * Specify whether a process is allowed to create an EXCLUSIVE MMAP stream. * @param pid * @param enabled */ void setExclusiveEnabled(pid_t pid, bool enabled); bool isExclusiveEnabled(pid_t pid); android::AAudioService *getAAudioService() const { return mAAudioService; } Loading @@ -84,17 +93,29 @@ private: aaudio_result_t unregisterClientStream(android::sp<AAudioServiceStreamBase> serviceStream); void setExclusiveEnabled(bool enabled) { mExclusiveEnabled = enabled; } bool isExclusiveEnabled() { return mExclusiveEnabled; } // IBinder::DeathRecipient virtual void binderDied(const android::wp<IBinder>& who); protected: private: mutable std::mutex mLock; const pid_t mProcessId; std::set<android::sp<AAudioServiceStreamBase>> mStreams; // hold onto binder to receive death notifications android::sp<IBinder> mBinder; bool mExclusiveEnabled = true; }; // This must be called under mLock android::sp<NotificationClient> getNotificationClient_l(pid_t pid); mutable std::mutex mLock; std::map<pid_t, android::sp<NotificationClient>> mNotificationClients; android::AAudioService *mAAudioService = nullptr; Loading
services/oboeservice/AAudioEndpointManager.cpp +10 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ #include <sstream> #include <utility/AAudioUtilities.h> #include "AAudioClientTracker.h" #include "AAudioEndpointManager.h" #include "AAudioServiceEndpointShared.h" #include "AAudioServiceEndpointMMAP.h" Loading Loading @@ -174,7 +175,15 @@ sp<AAudioServiceEndpoint> AAudioEndpointManager::openExclusiveEndpoint( && !request.isSharingModeMatchRequired()) { // app did not request a shared stream ALOGD("%s() endpoint in EXCLUSIVE use. Steal it!", __func__); mExclusiveStolenCount++; endpointToSteal = endpoint; // Prevent this process from getting another EXCLUSIVE stream. // This will prevent two clients from colliding after a DISCONNECTION // when they both try to open an exclusive stream at the same time. // That can result in a stream getting disconnected between the OPEN // 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. AAudioClientTracker::getInstance().setExclusiveEnabled(request.getProcessId(), false); endpointToSteal = endpoint; // return it to caller } return nullptr; } else { Loading
services/oboeservice/AAudioService.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -117,7 +117,8 @@ aaudio_handle_t AAudioService::openStream(const aaudio::AAudioStreamRequest &req return AAUDIO_ERROR_ILLEGAL_ARGUMENT; } if (sharingMode == AAUDIO_SHARING_MODE_EXCLUSIVE) { if (sharingMode == AAUDIO_SHARING_MODE_EXCLUSIVE && AAudioClientTracker::getInstance().isExclusiveEnabled(request.getProcessId())) { // only trust audioserver for in service indication bool inService = false; if (isCallerInService()) { Loading