Enable clang-tidy in oboeservice.
Warnings and errors generated by clang-tidy are eliminated by this CL.
Bug: 186572209
Test: make
Test: atest AAudioTests
Change-Id: I3296193bac18fee499f39314ac32a5750a385855
diff --git a/services/oboeservice/AAudioClientTracker.cpp b/services/oboeservice/AAudioClientTracker.cpp
index 054a896..c0dac11 100644
--- a/services/oboeservice/AAudioClientTracker.cpp
+++ b/services/oboeservice/AAudioClientTracker.cpp
@@ -73,13 +73,13 @@
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 @@
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 @@
}
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 @@
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 @@
: 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 @@
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);
}
diff --git a/services/oboeservice/AAudioClientTracker.h b/services/oboeservice/AAudioClientTracker.h
index 2b38621..cd3b75a 100644
--- a/services/oboeservice/AAudioClientTracker.h
+++ b/services/oboeservice/AAudioClientTracker.h
@@ -54,10 +54,10 @@
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 @@
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 @@
}
// IBinder::DeathRecipient
- virtual void binderDied(const android::wp<IBinder>& who);
+ void binderDied(const android::wp<IBinder>& who) override;
private:
mutable std::mutex mLock;
diff --git a/services/oboeservice/AAudioCommandQueue.cpp b/services/oboeservice/AAudioCommandQueue.cpp
index 9bd18b3..be80b12 100644
--- a/services/oboeservice/AAudioCommandQueue.cpp
+++ b/services/oboeservice/AAudioCommandQueue.cpp
@@ -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) {
diff --git a/services/oboeservice/AAudioCommandQueue.h b/services/oboeservice/AAudioCommandQueue.h
index 64442a3..ad62d8a 100644
--- a/services/oboeservice/AAudioCommandQueue.h
+++ b/services/oboeservice/AAudioCommandQueue.h
@@ -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 @@
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 @@
* @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.
diff --git a/services/oboeservice/AAudioEndpointManager.cpp b/services/oboeservice/AAudioEndpointManager.cpp
index 20e4cc5..b5ee2f2 100644
--- a/services/oboeservice/AAudioEndpointManager.cpp
+++ b/services/oboeservice/AAudioEndpointManager.cpp
@@ -162,7 +162,7 @@
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 @@
// 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 @@
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 @@
// 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 @@
}
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 @@
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::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::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.
diff --git a/services/oboeservice/AAudioEndpointManager.h b/services/oboeservice/AAudioEndpointManager.h
index b07bcef..1d38d26 100644
--- a/services/oboeservice/AAudioEndpointManager.h
+++ b/services/oboeservice/AAudioEndpointManager.h
@@ -61,7 +61,7 @@
android::sp<AAudioServiceEndpoint> openEndpoint(android::AAudioService &audioService,
const aaudio::AAudioStreamRequest &request);
- void closeEndpoint(android::sp<AAudioServiceEndpoint> serviceEndpoint);
+ void closeEndpoint(const android::sp<AAudioServiceEndpoint>& serviceEndpoint);
private:
android::sp<AAudioServiceEndpoint> openExclusiveEndpoint(android::AAudioService &aaudioService,
@@ -79,8 +79,8 @@
const AAudioStreamConfiguration& configuration)
REQUIRES(mSharedLock);
- void closeExclusiveEndpoint(android::sp<AAudioServiceEndpoint> serviceEndpoint);
- void closeSharedEndpoint(android::sp<AAudioServiceEndpoint> serviceEndpoint);
+ void closeExclusiveEndpoint(const android::sp<AAudioServiceEndpoint>& serviceEndpoint);
+ void closeSharedEndpoint(const android::sp<AAudioServiceEndpoint>& serviceEndpoint);
// Use separate locks because opening a Shared endpoint requires opening an Exclusive one.
// That could cause a recursive lock.
diff --git a/services/oboeservice/AAudioMixer.cpp b/services/oboeservice/AAudioMixer.cpp
index ad4b830..6890985 100644
--- a/services/oboeservice/AAudioMixer.cpp
+++ b/services/oboeservice/AAudioMixer.cpp
@@ -45,7 +45,8 @@
memset(mOutputBuffer.get(), 0, mBufferSizeInBytes);
}
-int32_t AAudioMixer::mix(int streamIndex, std::shared_ptr<FifoBuffer> fifo, bool allowUnderflow) {
+int32_t AAudioMixer::mix(
+ int streamIndex, const std::shared_ptr<FifoBuffer>& fifo, bool allowUnderflow) {
WrappingBuffer wrappingBuffer;
float *destination = mOutputBuffer.get();
diff --git a/services/oboeservice/AAudioMixer.h b/services/oboeservice/AAudioMixer.h
index 1a120f2..d773178 100644
--- a/services/oboeservice/AAudioMixer.h
+++ b/services/oboeservice/AAudioMixer.h
@@ -24,7 +24,7 @@
class AAudioMixer {
public:
- AAudioMixer() {}
+ AAudioMixer() = default;
void allocate(int32_t samplesPerFrame, int32_t framesPerBurst);
@@ -37,7 +37,9 @@
* @param allowUnderflow if true then allow mixer to advance read index past the write index
* @return frames read from this stream
*/
- int32_t mix(int streamIndex, std::shared_ptr<android::FifoBuffer> fifo, bool allowUnderflow);
+ int32_t mix(int streamIndex,
+ const std::shared_ptr<android::FifoBuffer>& fifo,
+ bool allowUnderflow);
float *getOutputBuffer();
diff --git a/services/oboeservice/AAudioService.cpp b/services/oboeservice/AAudioService.cpp
index 2679b2e..e9c0884 100644
--- a/services/oboeservice/AAudioService.cpp
+++ b/services/oboeservice/AAudioService.cpp
@@ -62,7 +62,7 @@
AAudioClientTracker::getInstance().setAAudioService(this);
}
-status_t AAudioService::dump(int fd, const Vector<String16>& args) {
+status_t AAudioService::dump(int fd, const Vector<String16>& /*args*/) {
std::string result;
if (!dumpAllowed()) {
@@ -83,7 +83,7 @@
}
Status AAudioService::registerClient(const sp<IAAudioClient> &client) {
- pid_t pid = IPCThreadState::self()->getCallingPid();
+ const pid_t pid = IPCThreadState::self()->getCallingPid();
AAudioClientTracker::getInstance().registerClient(pid, client);
return Status::ok();
}
@@ -106,24 +106,24 @@
// 4) Thread A can then get the lock and also open a shared stream.
// Without the lock. Thread A might sneak in and reallocate an exclusive stream
// before B can open the shared stream.
- std::unique_lock<std::recursive_mutex> lock(mOpenLock);
+ const std::unique_lock<std::recursive_mutex> lock(mOpenLock);
aaudio_result_t result = AAUDIO_OK;
sp<AAudioServiceStreamBase> serviceStream;
const AAudioStreamConfiguration &configurationInput = request.getConstantConfiguration();
- bool sharingModeMatchRequired = request.isSharingModeMatchRequired();
- aaudio_sharing_mode_t sharingMode = configurationInput.getSharingMode();
+ const bool sharingModeMatchRequired = request.isSharingModeMatchRequired();
+ const aaudio_sharing_mode_t sharingMode = configurationInput.getSharingMode();
// Enforce limit on client processes.
AttributionSourceState attributionSource = request.getAttributionSource();
- pid_t pid = IPCThreadState::self()->getCallingPid();
+ const pid_t pid = IPCThreadState::self()->getCallingPid();
attributionSource.pid = VALUE_OR_RETURN_ILLEGAL_ARG_STATUS(
legacy2aidl_pid_t_int32_t(pid));
attributionSource.uid = VALUE_OR_RETURN_ILLEGAL_ARG_STATUS(
legacy2aidl_uid_t_int32_t(IPCThreadState::self()->getCallingUid()));
attributionSource.token = sp<BBinder>::make();
if (attributionSource.pid != mAudioClient.attributionSource.pid) {
- int32_t count = AAudioClientTracker::getInstance().getStreamCount(pid);
+ const int32_t count = AAudioClientTracker::getInstance().getStreamCount(pid);
if (count >= MAX_STREAMS_PER_PROCESS) {
ALOGE("openStream(): exceeded max streams per process %d >= %d",
count, MAX_STREAMS_PER_PROCESS);
@@ -168,7 +168,7 @@
serviceStream.clear();
AIDL_RETURN(result);
} else {
- aaudio_handle_t handle = mStreamTracker.addStreamForHandle(serviceStream.get());
+ const aaudio_handle_t handle = mStreamTracker.addStreamForHandle(serviceStream.get());
serviceStream->setHandle(handle);
AAudioClientTracker::getInstance().registerClientStream(pid, serviceStream);
paramsOut.copyFrom(*serviceStream);
@@ -185,7 +185,7 @@
static_assert(std::is_same_v<aaudio_result_t, std::decay_t<typeof(*_aidl_return)>>);
// Check permission and ownership first.
- sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
+ const sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
if (serviceStream.get() == nullptr) {
ALOGE("closeStream(0x%0x), illegal stream handle", streamHandle);
AIDL_RETURN(AAUDIO_ERROR_INVALID_HANDLE);
@@ -197,13 +197,13 @@
int32_t *_aidl_return) {
static_assert(std::is_same_v<aaudio_result_t, std::decay_t<typeof(*_aidl_return)>>);
- sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
+ const sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
if (serviceStream.get() == nullptr) {
ALOGE("getStreamDescription(), illegal stream handle = 0x%0x", streamHandle);
AIDL_RETURN(AAUDIO_ERROR_INVALID_HANDLE);
}
AudioEndpointParcelable endpointParcelable;
- aaudio_result_t result = serviceStream->getDescription(endpointParcelable);
+ const aaudio_result_t result = serviceStream->getDescription(endpointParcelable);
if (result == AAUDIO_OK) {
*endpoint = std::move(endpointParcelable).parcelable();
}
@@ -213,7 +213,7 @@
Status AAudioService::startStream(int32_t streamHandle, int32_t *_aidl_return) {
static_assert(std::is_same_v<aaudio_result_t, std::decay_t<typeof(*_aidl_return)>>);
- sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
+ const sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
if (serviceStream.get() == nullptr) {
ALOGW("%s(), invalid streamHandle = 0x%0x", __func__, streamHandle);
AIDL_RETURN(AAUDIO_ERROR_INVALID_HANDLE);
@@ -224,7 +224,7 @@
Status AAudioService::pauseStream(int32_t streamHandle, int32_t *_aidl_return) {
static_assert(std::is_same_v<aaudio_result_t, std::decay_t<typeof(*_aidl_return)>>);
- sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
+ const sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
if (serviceStream.get() == nullptr) {
ALOGW("%s(), invalid streamHandle = 0x%0x", __func__, streamHandle);
AIDL_RETURN(AAUDIO_ERROR_INVALID_HANDLE);
@@ -235,7 +235,7 @@
Status AAudioService::stopStream(int32_t streamHandle, int32_t *_aidl_return) {
static_assert(std::is_same_v<aaudio_result_t, std::decay_t<typeof(*_aidl_return)>>);
- sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
+ const sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
if (serviceStream.get() == nullptr) {
ALOGW("%s(), invalid streamHandle = 0x%0x", __func__, streamHandle);
AIDL_RETURN(AAUDIO_ERROR_INVALID_HANDLE);
@@ -246,7 +246,7 @@
Status AAudioService::flushStream(int32_t streamHandle, int32_t *_aidl_return) {
static_assert(std::is_same_v<aaudio_result_t, std::decay_t<typeof(*_aidl_return)>>);
- sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
+ const sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
if (serviceStream.get() == nullptr) {
ALOGW("%s(), invalid streamHandle = 0x%0x", __func__, streamHandle);
AIDL_RETURN(AAUDIO_ERROR_INVALID_HANDLE);
@@ -254,16 +254,16 @@
AIDL_RETURN(serviceStream->flush());
}
-Status AAudioService::registerAudioThread(int32_t streamHandle, int32_t clientThreadId, int64_t periodNanoseconds,
- int32_t *_aidl_return) {
+Status AAudioService::registerAudioThread(int32_t streamHandle, int32_t clientThreadId,
+ int64_t /*periodNanoseconds*/, int32_t *_aidl_return) {
static_assert(std::is_same_v<aaudio_result_t, std::decay_t<typeof(*_aidl_return)>>);
- sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
+ const sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
if (serviceStream.get() == nullptr) {
ALOGW("%s(), invalid streamHandle = 0x%0x", __func__, streamHandle);
AIDL_RETURN(AAUDIO_ERROR_INVALID_HANDLE);
}
- int32_t priority = isCallerInService()
+ const int32_t priority = isCallerInService()
? kRealTimeAudioPriorityService : kRealTimeAudioPriorityClient;
AIDL_RETURN(serviceStream->registerAudioThread(clientThreadId, priority));
}
@@ -272,7 +272,7 @@
int32_t *_aidl_return) {
static_assert(std::is_same_v<aaudio_result_t, std::decay_t<typeof(*_aidl_return)>>);
- sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
+ const sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
if (serviceStream.get() == nullptr) {
ALOGW("%s(), invalid streamHandle = 0x%0x", __func__, streamHandle);
AIDL_RETURN(AAUDIO_ERROR_INVALID_HANDLE);
@@ -283,13 +283,13 @@
Status AAudioService::exitStandby(int32_t streamHandle, Endpoint* endpoint, int32_t *_aidl_return) {
static_assert(std::is_same_v<aaudio_result_t, std::decay_t<typeof(*_aidl_return)>>);
- sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
+ const sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
if (serviceStream.get() == nullptr) {
ALOGE("getStreamDescription(), illegal stream handle = 0x%0x", streamHandle);
AIDL_RETURN(AAUDIO_ERROR_INVALID_HANDLE);
}
AudioEndpointParcelable endpointParcelable;
- aaudio_result_t result = serviceStream->exitStandby(&endpointParcelable);
+ const aaudio_result_t result = serviceStream->exitStandby(&endpointParcelable);
if (result == AAUDIO_OK) {
*endpoint = std::move(endpointParcelable).parcelable();
}
@@ -297,16 +297,18 @@
}
bool AAudioService::isCallerInService() {
- pid_t clientPid = VALUE_OR_FATAL(aidl2legacy_int32_t_pid_t(mAudioClient.attributionSource.pid));
- uid_t clientUid = VALUE_OR_FATAL(aidl2legacy_int32_t_uid_t(mAudioClient.attributionSource.uid));
+ const pid_t clientPid = VALUE_OR_FATAL(
+ aidl2legacy_int32_t_pid_t(mAudioClient.attributionSource.pid));
+ const uid_t clientUid = VALUE_OR_FATAL(
+ aidl2legacy_int32_t_uid_t(mAudioClient.attributionSource.uid));
return clientPid == IPCThreadState::self()->getCallingPid() &&
clientUid == IPCThreadState::self()->getCallingUid();
}
-aaudio_result_t AAudioService::closeStream(sp<AAudioServiceStreamBase> serviceStream) {
+aaudio_result_t AAudioService::closeStream(const sp<AAudioServiceStreamBase>& serviceStream) {
// This is protected by a lock in AAudioClientTracker.
// It is safe to unregister the same stream twice.
- pid_t pid = serviceStream->getOwnerProcessId();
+ const pid_t pid = serviceStream->getOwnerProcessId();
AAudioClientTracker::getInstance().unregisterClientStream(pid, serviceStream);
// This is protected by a lock in mStreamTracker.
// It is safe to remove the same stream twice.
@@ -325,10 +327,10 @@
const uid_t ownerUserId = serviceStream->getOwnerUserId();
const uid_t clientUid = VALUE_OR_FATAL(
aidl2legacy_int32_t_uid_t(mAudioClient.attributionSource.uid));
- bool callerOwnsIt = callingUserId == ownerUserId;
- bool serverCalling = callingUserId == clientUid;
- bool serverOwnsIt = ownerUserId == clientUid;
- bool allowed = callerOwnsIt || serverCalling || serverOwnsIt;
+ const bool callerOwnsIt = callingUserId == ownerUserId;
+ const bool serverCalling = callingUserId == clientUid;
+ const bool serverOwnsIt = ownerUserId == clientUid;
+ const bool allowed = callerOwnsIt || serverCalling || serverOwnsIt;
if (!allowed) {
ALOGE("AAudioService: calling uid %d cannot access stream 0x%08X owned by %d",
callingUserId, streamHandle, ownerUserId);
@@ -342,7 +344,7 @@
const android::AudioClient& client,
const audio_attributes_t *attr,
audio_port_handle_t *clientHandle) {
- sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
+ const sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
if (serviceStream.get() == nullptr) {
ALOGW("%s(), invalid streamHandle = 0x%0x", __func__, streamHandle);
return AAUDIO_ERROR_INVALID_HANDLE;
@@ -352,7 +354,7 @@
aaudio_result_t AAudioService::stopClient(aaudio_handle_t streamHandle,
audio_port_handle_t portHandle) {
- sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
+ const sp<AAudioServiceStreamBase> serviceStream = convertHandleToServiceStream(streamHandle);
if (serviceStream.get() == nullptr) {
ALOGW("%s(), invalid streamHandle = 0x%0x", __func__, streamHandle);
return AAUDIO_ERROR_INVALID_HANDLE;
@@ -364,14 +366,14 @@
// So we do not have to check permissions.
aaudio_result_t AAudioService::disconnectStreamByPortHandle(audio_port_handle_t portHandle) {
ALOGD("%s(%d) called", __func__, portHandle);
- sp<AAudioServiceStreamBase> serviceStream =
+ const sp<AAudioServiceStreamBase> serviceStream =
mStreamTracker.findStreamByPortHandle(portHandle);
if (serviceStream.get() == nullptr) {
ALOGE("%s(), could not find stream with portHandle = %d", __func__, portHandle);
return AAUDIO_ERROR_INVALID_HANDLE;
}
// This is protected by a lock and will just return if already stopped.
- aaudio_result_t result = serviceStream->stop();
+ const aaudio_result_t result = serviceStream->stop();
serviceStream->disconnect();
return result;
}
diff --git a/services/oboeservice/AAudioService.h b/services/oboeservice/AAudioService.h
index 0a111fb..df66f1b 100644
--- a/services/oboeservice/AAudioService.h
+++ b/services/oboeservice/AAudioService.h
@@ -45,7 +45,7 @@
public:
AAudioService();
- virtual ~AAudioService() = default;
+ ~AAudioService() override = default;
aaudio::AAudioServiceInterface& asAAudioServiceInterface() {
return mAdapter;
@@ -53,7 +53,7 @@
static const char* getServiceName() { return AAUDIO_SERVICE_NAME; }
- virtual status_t dump(int fd, const Vector<String16>& args) override;
+ status_t dump(int fd, const Vector<String16>& args) override;
binder::Status registerClient(const ::android::sp<::aaudio::IAAudioClient>& client) override;
@@ -103,7 +103,7 @@
* This is only called from within the Service.
* It bypasses the permission checks in closeStream(handle).
*/
- aaudio_result_t closeStream(sp<aaudio::AAudioServiceStreamBase> serviceStream);
+ aaudio_result_t closeStream(const sp<aaudio::AAudioServiceStreamBase>& serviceStream);
private:
class Adapter : public aaudio::AAudioBinderAdapter {
diff --git a/services/oboeservice/AAudioServiceEndpoint.cpp b/services/oboeservice/AAudioServiceEndpoint.cpp
index fd546f6..2b94dbf 100644
--- a/services/oboeservice/AAudioServiceEndpoint.cpp
+++ b/services/oboeservice/AAudioServiceEndpoint.cpp
@@ -88,7 +88,7 @@
// @return true if stream found
bool AAudioServiceEndpoint::isStreamRegistered(audio_port_handle_t portHandle) {
- std::lock_guard<std::mutex> lock(mLockStreams);
+ const std::lock_guard<std::mutex> lock(mLockStreams);
for (const auto& stream : mRegisteredStreams) {
if (stream->getPortHandle() == portHandle) {
return true;
@@ -101,7 +101,7 @@
AAudioServiceEndpoint::disconnectRegisteredStreams() {
std::vector<android::sp<AAudioServiceStreamBase>> streamsDisconnected;
{
- std::lock_guard<std::mutex> lock(mLockStreams);
+ const std::lock_guard<std::mutex> lock(mLockStreams);
mRegisteredStreams.swap(streamsDisconnected);
}
mConnected.store(false);
@@ -122,7 +122,7 @@
void AAudioServiceEndpoint::releaseRegisteredStreams() {
// List of streams to be closed after we disconnect everything.
- std::vector<android::sp<AAudioServiceStreamBase>> streamsToClose
+ const std::vector<android::sp<AAudioServiceStreamBase>> streamsToClose
= disconnectRegisteredStreams();
// Close outside the lock to avoid recursive locks.
@@ -133,14 +133,14 @@
}
}
-aaudio_result_t AAudioServiceEndpoint::registerStream(sp<AAudioServiceStreamBase>stream) {
- std::lock_guard<std::mutex> lock(mLockStreams);
+aaudio_result_t AAudioServiceEndpoint::registerStream(const sp<AAudioServiceStreamBase>& stream) {
+ const std::lock_guard<std::mutex> lock(mLockStreams);
mRegisteredStreams.push_back(stream);
return AAUDIO_OK;
}
-aaudio_result_t AAudioServiceEndpoint::unregisterStream(sp<AAudioServiceStreamBase>stream) {
- std::lock_guard<std::mutex> lock(mLockStreams);
+aaudio_result_t AAudioServiceEndpoint::unregisterStream(const sp<AAudioServiceStreamBase>& stream) {
+ const std::lock_guard<std::mutex> lock(mLockStreams);
mRegisteredStreams.erase(std::remove(
mRegisteredStreams.begin(), mRegisteredStreams.end(), stream),
mRegisteredStreams.end());
diff --git a/services/oboeservice/AAudioServiceEndpoint.h b/services/oboeservice/AAudioServiceEndpoint.h
index 92004c5..dff571b 100644
--- a/services/oboeservice/AAudioServiceEndpoint.h
+++ b/services/oboeservice/AAudioServiceEndpoint.h
@@ -43,7 +43,7 @@
, public AAudioStreamParameters {
public:
- virtual ~AAudioServiceEndpoint();
+ ~AAudioServiceEndpoint() override;
virtual std::string dump() const;
@@ -55,9 +55,9 @@
*/
virtual void close() = 0;
- aaudio_result_t registerStream(android::sp<AAudioServiceStreamBase> stream);
+ aaudio_result_t registerStream(const android::sp<AAudioServiceStreamBase>& stream);
- aaudio_result_t unregisterStream(android::sp<AAudioServiceStreamBase> stream);
+ aaudio_result_t unregisterStream(const android::sp<AAudioServiceStreamBase>& stream);
virtual aaudio_result_t startStream(android::sp<AAudioServiceStreamBase> stream,
audio_port_handle_t *clientHandle) = 0;
@@ -65,14 +65,14 @@
virtual aaudio_result_t stopStream(android::sp<AAudioServiceStreamBase> stream,
audio_port_handle_t clientHandle) = 0;
- virtual aaudio_result_t startClient(const android::AudioClient& client,
- const audio_attributes_t *attr,
- audio_port_handle_t *clientHandle) {
+ virtual aaudio_result_t startClient(const android::AudioClient& /*client*/,
+ const audio_attributes_t* /*attr*/,
+ audio_port_handle_t* /*clientHandle*/) {
ALOGD("AAudioServiceEndpoint::startClient(...) AAUDIO_ERROR_UNAVAILABLE");
return AAUDIO_ERROR_UNAVAILABLE;
}
- virtual aaudio_result_t stopClient(audio_port_handle_t clientHandle) {
+ virtual aaudio_result_t stopClient(audio_port_handle_t /*clientHandle*/) {
ALOGD("AAudioServiceEndpoint::stopClient(...) AAUDIO_ERROR_UNAVAILABLE");
return AAUDIO_ERROR_UNAVAILABLE;
}
@@ -82,7 +82,7 @@
return AAUDIO_ERROR_UNAVAILABLE;
}
- virtual aaudio_result_t exitStandby(AudioEndpointParcelable* parcelable) {
+ virtual aaudio_result_t exitStandby(AudioEndpointParcelable* /*parcelable*/) {
ALOGD("AAudioServiceEndpoint::exitStandby() AAUDIO_ERROR_UNAVAILABLE");
return AAUDIO_ERROR_UNAVAILABLE;
}
diff --git a/services/oboeservice/AAudioServiceEndpointCapture.cpp b/services/oboeservice/AAudioServiceEndpointCapture.cpp
index 95bd4bb..ba8070b 100644
--- a/services/oboeservice/AAudioServiceEndpointCapture.cpp
+++ b/services/oboeservice/AAudioServiceEndpointCapture.cpp
@@ -90,5 +90,5 @@
}
ALOGD("callbackLoop() exiting");
- return NULL; // TODO review
+ return nullptr; // TODO review
}
diff --git a/services/oboeservice/AAudioServiceEndpointCapture.h b/services/oboeservice/AAudioServiceEndpointCapture.h
index 2ca43cf..b77100d 100644
--- a/services/oboeservice/AAudioServiceEndpointCapture.h
+++ b/services/oboeservice/AAudioServiceEndpointCapture.h
@@ -30,7 +30,7 @@
class AAudioServiceEndpointCapture : public AAudioServiceEndpointShared {
public:
explicit AAudioServiceEndpointCapture(android::AAudioService &audioService);
- virtual ~AAudioServiceEndpointCapture() = default;
+ ~AAudioServiceEndpointCapture() override = default;
aaudio_result_t open(const aaudio::AAudioStreamRequest &request) override;
diff --git a/services/oboeservice/AAudioServiceEndpointMMAP.cpp b/services/oboeservice/AAudioServiceEndpointMMAP.cpp
index 3d237b3..d4cdb0b 100644
--- a/services/oboeservice/AAudioServiceEndpointMMAP.cpp
+++ b/services/oboeservice/AAudioServiceEndpointMMAP.cpp
@@ -37,7 +37,7 @@
#include "AAudioServiceEndpointPlay.h"
#include "AAudioServiceEndpointMMAP.h"
-#define AAUDIO_BUFFER_CAPACITY_MIN 4 * 512
+#define AAUDIO_BUFFER_CAPACITY_MIN (4 * 512)
#define AAUDIO_SAMPLE_RATE_DEFAULT 48000
// This is an estimate of the time difference between the HW and the MMAP time.
@@ -85,7 +85,7 @@
return it != NEXT_FORMAT_TO_TRY.end() ? it->second : AUDIO_FORMAT_DEFAULT;
}
-}
+} // namespace
aaudio_result_t AAudioServiceEndpointMMAP::open(const aaudio::AAudioStreamRequest &request) {
aaudio_result_t result = AAUDIO_OK;
@@ -111,7 +111,7 @@
audio_format_t nextFormatToTry = AUDIO_FORMAT_DEFAULT;
result = openWithFormat(audioFormat, &nextFormatToTry);
- if (result == AAUDIO_OK || result != AAUDIO_ERROR_UNAVAILABLE) {
+ if (result != AAUDIO_ERROR_UNAVAILABLE) {
// Return if it is successful or there is an error that is not
// AAUDIO_ERROR_UNAVAILABLE happens.
ALOGI("Opened format=%#x with result=%d", audioFormat, result);
@@ -165,12 +165,12 @@
return AAUDIO_ERROR_ILLEGAL_ARGUMENT;
}
- MmapStreamInterface::stream_direction_t streamDirection =
+ const MmapStreamInterface::stream_direction_t streamDirection =
(direction == AAUDIO_DIRECTION_OUTPUT)
? MmapStreamInterface::DIRECTION_OUTPUT
: MmapStreamInterface::DIRECTION_INPUT;
- aaudio_session_id_t requestedSessionId = getSessionId();
+ const aaudio_session_id_t requestedSessionId = getSessionId();
audio_session_t sessionId = AAudioConvert_aaudioToAndroidSessionId(requestedSessionId);
// Open HAL stream. Set mMmapStream
@@ -178,15 +178,15 @@
"sample_rate=%u, channel_mask=%#x, device=%d",
__func__, config.format, config.sample_rate,
config.channel_mask, deviceId);
- status_t status = MmapStreamInterface::openMmapStream(streamDirection,
- &attributes,
- &config,
- mMmapClient,
- &deviceId,
- &sessionId,
- this, // callback
- mMmapStream,
- &mPortHandle);
+ const status_t status = MmapStreamInterface::openMmapStream(streamDirection,
+ &attributes,
+ &config,
+ mMmapClient,
+ &deviceId,
+ &sessionId,
+ this, // callback
+ mMmapStream,
+ &mPortHandle);
ALOGD("%s() mMapClient.attributionSource = %s => portHandle = %d\n",
__func__, mMmapClient.attributionSource.toString().c_str(), mPortHandle);
if (status != OK) {
@@ -209,7 +209,7 @@
ALOGW("%s() - openMmapStream() failed to set sessionId", __func__);
}
- aaudio_session_id_t actualSessionId =
+ const aaudio_session_id_t actualSessionId =
(requestedSessionId == AAUDIO_SESSION_ID_NONE)
? AAUDIO_SESSION_ID_NONE
: (aaudio_session_id_t) sessionId;
@@ -278,7 +278,7 @@
if (stream != nullptr) {
attr = getAudioAttributesFrom(stream.get());
}
- aaudio_result_t result = startClient(
+ const aaudio_result_t result = startClient(
mMmapClient, stream == nullptr ? nullptr : &attr, &tempHandle);
// When AudioFlinger is passed a valid port handle then it should not change it.
LOG_ALWAYS_FATAL_IF(tempHandle != mPortHandle,
@@ -288,8 +288,8 @@
return result;
}
-aaudio_result_t AAudioServiceEndpointMMAP::stopStream(sp<AAudioServiceStreamBase> stream,
- audio_port_handle_t clientHandle __unused) {
+aaudio_result_t AAudioServiceEndpointMMAP::stopStream(sp<AAudioServiceStreamBase> /*stream*/,
+ audio_port_handle_t /*clientHandle*/) {
mFramesTransferred.reset32();
// Round 64-bit counter up to a multiple of the buffer capacity.
@@ -306,23 +306,21 @@
aaudio_result_t AAudioServiceEndpointMMAP::startClient(const android::AudioClient& client,
const audio_attributes_t *attr,
audio_port_handle_t *clientHandle) {
- if (mMmapStream == nullptr) return AAUDIO_ERROR_NULL;
- status_t status = mMmapStream->start(client, attr, clientHandle);
- return AAudioConvert_androidToAAudioResult(status);
+ return mMmapStream == nullptr
+ ? AAUDIO_ERROR_NULL
+ : AAudioConvert_androidToAAudioResult(mMmapStream->start(client, attr, clientHandle));
}
aaudio_result_t AAudioServiceEndpointMMAP::stopClient(audio_port_handle_t clientHandle) {
- if (mMmapStream == nullptr) return AAUDIO_ERROR_NULL;
- aaudio_result_t result = AAudioConvert_androidToAAudioResult(mMmapStream->stop(clientHandle));
- return result;
+ return mMmapStream == nullptr
+ ? AAUDIO_ERROR_NULL
+ : AAudioConvert_androidToAAudioResult(mMmapStream->stop(clientHandle));
}
aaudio_result_t AAudioServiceEndpointMMAP::standby() {
- if (mMmapStream == nullptr) {
- return AAUDIO_ERROR_NULL;
- }
- aaudio_result_t result = AAudioConvert_androidToAAudioResult(mMmapStream->standby());
- return result;
+ return mMmapStream == nullptr
+ ? AAUDIO_ERROR_NULL
+ : AAudioConvert_androidToAAudioResult(mMmapStream->standby());
}
aaudio_result_t AAudioServiceEndpointMMAP::exitStandby(AudioEndpointParcelable* parcelable) {
@@ -330,11 +328,12 @@
return AAUDIO_ERROR_NULL;
}
mAudioDataFileDescriptor.reset();
- aaudio_result_t result = createMmapBuffer(&mAudioDataFileDescriptor);
+ const aaudio_result_t result = createMmapBuffer(&mAudioDataFileDescriptor);
if (result == AAUDIO_OK) {
- int32_t bytesPerFrame = calculateBytesPerFrame();
- int32_t capacityInBytes = getBufferCapacity() * bytesPerFrame;
- int fdIndex = parcelable->addFileDescriptor(mAudioDataFileDescriptor, capacityInBytes);
+ const int32_t bytesPerFrame = calculateBytesPerFrame();
+ const int32_t capacityInBytes = getBufferCapacity() * bytesPerFrame;
+ const int fdIndex = parcelable->addFileDescriptor(
+ mAudioDataFileDescriptor, capacityInBytes);
parcelable->mDownDataQueueParcelable.setupMemory(fdIndex, 0, capacityInBytes);
parcelable->mDownDataQueueParcelable.setBytesPerFrame(bytesPerFrame);
parcelable->mDownDataQueueParcelable.setFramesPerBurst(mFramesPerBurst);
@@ -350,10 +349,10 @@
if (mMmapStream == nullptr) {
return AAUDIO_ERROR_NULL;
}
- status_t status = mMmapStream->getMmapPosition(&position);
+ const status_t status = mMmapStream->getMmapPosition(&position);
ALOGV("%s() status= %d, pos = %d, nanos = %lld\n",
__func__, status, position.position_frames, (long long) position.time_nanoseconds);
- aaudio_result_t result = AAudioConvert_androidToAAudioResult(status);
+ const aaudio_result_t result = AAudioConvert_androidToAAudioResult(status);
if (result == AAUDIO_ERROR_UNAVAILABLE) {
ALOGW("%s(): getMmapPosition() has no position data available", __func__);
} else if (result != AAUDIO_OK) {
@@ -367,8 +366,8 @@
return result;
}
-aaudio_result_t AAudioServiceEndpointMMAP::getTimestamp(int64_t *positionFrames,
- int64_t *timeNanos) {
+aaudio_result_t AAudioServiceEndpointMMAP::getTimestamp(int64_t* /*positionFrames*/,
+ int64_t* /*timeNanos*/) {
return 0; // TODO
}
@@ -381,7 +380,7 @@
} else {
// Must be a SHARED stream?
ALOGD("%s(%d) disconnect a specific stream", __func__, portHandle);
- aaudio_result_t result = mAAudioService.disconnectStreamByPortHandle(portHandle);
+ const aaudio_result_t result = mAAudioService.disconnectStreamByPortHandle(portHandle);
ALOGD("%s(%d) disconnectStreamByPortHandle returned %d", __func__, portHandle, result);
}
};
@@ -389,7 +388,7 @@
// This is called by AudioFlinger when it wants to destroy a stream.
void AAudioServiceEndpointMMAP::onTearDown(audio_port_handle_t portHandle) {
ALOGD("%s(portHandle = %d) called", __func__, portHandle);
- android::sp<AAudioServiceEndpointMMAP> holdEndpoint(this);
+ const android::sp<AAudioServiceEndpointMMAP> holdEndpoint(this);
std::thread asyncTask([holdEndpoint, portHandle]() {
holdEndpoint->handleTearDownAsync(portHandle);
});
@@ -398,18 +397,18 @@
void AAudioServiceEndpointMMAP::onVolumeChanged(float volume) {
ALOGD("%s() volume = %f", __func__, volume);
- std::lock_guard<std::mutex> lock(mLockStreams);
+ const std::lock_guard<std::mutex> lock(mLockStreams);
for(const auto& stream : mRegisteredStreams) {
stream->onVolumeChanged(volume);
}
};
void AAudioServiceEndpointMMAP::onRoutingChanged(audio_port_handle_t portHandle) {
- const int32_t deviceId = static_cast<int32_t>(portHandle);
+ const auto deviceId = static_cast<int32_t>(portHandle);
ALOGD("%s() called with dev %d, old = %d", __func__, deviceId, getDeviceId());
if (getDeviceId() != deviceId) {
if (getDeviceId() != AUDIO_PORT_HANDLE_NONE) {
- android::sp<AAudioServiceEndpointMMAP> holdEndpoint(this);
+ const android::sp<AAudioServiceEndpointMMAP> holdEndpoint(this);
std::thread asyncTask([holdEndpoint, deviceId]() {
ALOGD("onRoutingChanged() asyncTask launched");
holdEndpoint->disconnectRegisteredStreams();
@@ -429,9 +428,9 @@
AudioEndpointParcelable* parcelable)
{
// Gather information on the data queue based on HAL info.
- int32_t bytesPerFrame = calculateBytesPerFrame();
- int32_t capacityInBytes = getBufferCapacity() * bytesPerFrame;
- int fdIndex = parcelable->addFileDescriptor(mAudioDataFileDescriptor, capacityInBytes);
+ const int32_t bytesPerFrame = calculateBytesPerFrame();
+ const int32_t capacityInBytes = getBufferCapacity() * bytesPerFrame;
+ const int fdIndex = parcelable->addFileDescriptor(mAudioDataFileDescriptor, capacityInBytes);
parcelable->mDownDataQueueParcelable.setupMemory(fdIndex, 0, capacityInBytes);
parcelable->mDownDataQueueParcelable.setBytesPerFrame(bytesPerFrame);
parcelable->mDownDataQueueParcelable.setFramesPerBurst(mFramesPerBurst);
@@ -447,7 +446,7 @@
}
uint64_t tempPositionFrames;
int64_t tempTimeNanos;
- status_t status = mMmapStream->getExternalPosition(&tempPositionFrames, &tempTimeNanos);
+ const status_t status = mMmapStream->getExternalPosition(&tempPositionFrames, &tempTimeNanos);
if (status != OK) {
// getExternalPosition reports error. The HAL may not support the API. Cache the result
// so that the call will not go to the HAL next time.
@@ -527,8 +526,8 @@
if (minSizeFrames <= 0) { // zero will get rejected
minSizeFrames = AAUDIO_BUFFER_CAPACITY_MIN;
}
- status_t status = mMmapStream->createMmapBuffer(minSizeFrames, &mMmapBufferinfo);
- bool isBufferShareable = mMmapBufferinfo.flags & AUDIO_MMAP_APPLICATION_SHAREABLE;
+ const status_t status = mMmapStream->createMmapBuffer(minSizeFrames, &mMmapBufferinfo);
+ const bool isBufferShareable = mMmapBufferinfo.flags & AUDIO_MMAP_APPLICATION_SHAREABLE;
if (status != OK) {
ALOGE("%s() - createMmapBuffer() failed with status %d %s",
__func__, status, strerror(-status));
@@ -545,7 +544,7 @@
setBufferCapacity(mMmapBufferinfo.buffer_size_frames);
if (!isBufferShareable) {
// Exclusive mode can only be used by the service because the FD cannot be shared.
- int32_t audioServiceUid =
+ const int32_t audioServiceUid =
VALUE_OR_FATAL(legacy2aidl_uid_t_int32_t(getuid()));
if ((mMmapClient.attributionSource.uid != audioServiceUid) &&
getSharingMode() == AAUDIO_SHARING_MODE_EXCLUSIVE) {
diff --git a/services/oboeservice/AAudioServiceEndpointMMAP.h b/services/oboeservice/AAudioServiceEndpointMMAP.h
index 73e0f61..4f77393 100644
--- a/services/oboeservice/AAudioServiceEndpointMMAP.h
+++ b/services/oboeservice/AAudioServiceEndpointMMAP.h
@@ -44,7 +44,7 @@
public:
explicit AAudioServiceEndpointMMAP(android::AAudioService &audioService);
- virtual ~AAudioServiceEndpointMMAP() = default;
+ ~AAudioServiceEndpointMMAP() override = default;
std::string dump() const override;
diff --git a/services/oboeservice/AAudioServiceEndpointPlay.cpp b/services/oboeservice/AAudioServiceEndpointPlay.cpp
index 2a5939f..637405d 100644
--- a/services/oboeservice/AAudioServiceEndpointPlay.cpp
+++ b/services/oboeservice/AAudioServiceEndpointPlay.cpp
@@ -158,5 +158,5 @@
ALOGD("%s() exiting, enabled = %d, state = %d, result = %d <<<<<<<<<<<<< MIXER",
__func__, mCallbackEnabled.load(), getStreamInternal()->getState(), result);
- return NULL; // TODO review
+ return nullptr; // TODO review
}
diff --git a/services/oboeservice/AAudioServiceEndpointShared.cpp b/services/oboeservice/AAudioServiceEndpointShared.cpp
index 02202d8..1dd0c3a 100644
--- a/services/oboeservice/AAudioServiceEndpointShared.cpp
+++ b/services/oboeservice/AAudioServiceEndpointShared.cpp
@@ -103,8 +103,7 @@
// Prevent the stream from being deleted while being used.
// This is just for extra safety. It is probably not needed because
// this callback should be joined before the stream is closed.
- AAudioServiceEndpointShared *endpointPtr =
- static_cast<AAudioServiceEndpointShared *>(arg);
+ auto endpointPtr = static_cast<AAudioServiceEndpointShared *>(arg);
android::sp<AAudioServiceEndpointShared> endpoint(endpointPtr);
// Balance the incStrong() in startSharingThread_l().
endpoint->decStrong(nullptr);
@@ -140,7 +139,7 @@
aaudio_result_t aaudio::AAudioServiceEndpointShared::stopSharingThread() {
mCallbackEnabled.store(false);
- return getStreamInternal()->joinThread(NULL);
+ return getStreamInternal()->joinThread(nullptr);
}
aaudio_result_t AAudioServiceEndpointShared::startStream(
@@ -180,8 +179,8 @@
return result;
}
-aaudio_result_t AAudioServiceEndpointShared::stopStream(sp<AAudioServiceStreamBase> sharedStream,
- audio_port_handle_t clientHandle) {
+aaudio_result_t AAudioServiceEndpointShared::stopStream(
+ sp<AAudioServiceStreamBase> /*sharedStream*/, audio_port_handle_t clientHandle) {
// Ignore result.
(void) getStreamInternal()->stopClient(clientHandle);
diff --git a/services/oboeservice/AAudioServiceEndpointShared.h b/services/oboeservice/AAudioServiceEndpointShared.h
index 3e760c4..0efb227 100644
--- a/services/oboeservice/AAudioServiceEndpointShared.h
+++ b/services/oboeservice/AAudioServiceEndpointShared.h
@@ -39,7 +39,7 @@
public:
explicit AAudioServiceEndpointShared(AudioStreamInternal *streamInternal);
- virtual ~AAudioServiceEndpointShared() = default;
+ ~AAudioServiceEndpointShared() override = default;
std::string dump() const override;
@@ -79,6 +79,6 @@
std::atomic<int> mRunningStreamCount{0};
};
-}
+} // namespace aaudio
#endif //AAUDIO_SERVICE_ENDPOINT_SHARED_H
diff --git a/services/oboeservice/AAudioServiceStreamBase.cpp b/services/oboeservice/AAudioServiceStreamBase.cpp
index 35d712c..8e1e497 100644
--- a/services/oboeservice/AAudioServiceStreamBase.cpp
+++ b/services/oboeservice/AAudioServiceStreamBase.cpp
@@ -83,9 +83,8 @@
}
std::string AAudioServiceStreamBase::dumpHeader() {
- return std::string(
- " T Handle UId Port Run State Format Burst Chan Mask Capacity"
- " HwFormat HwChan HwRate");
+ return {" T Handle UId Port Run State Format Burst Chan Mask Capacity"
+ " HwFormat HwChan HwRate"};
}
std::string AAudioServiceStreamBase::dump() const {
@@ -477,8 +476,7 @@
disconnect_l();
break;
case REGISTER_AUDIO_THREAD: {
- RegisterAudioThreadParam *param =
- (RegisterAudioThreadParam *) command->parameter.get();
+ auto param = (RegisterAudioThreadParam *) command->parameter.get();
command->result =
param == nullptr ? AAUDIO_ERROR_ILLEGAL_ARGUMENT
: registerAudioThread_l(param->mOwnerPid,
@@ -487,21 +485,20 @@
}
break;
case UNREGISTER_AUDIO_THREAD: {
- UnregisterAudioThreadParam *param =
- (UnregisterAudioThreadParam *) command->parameter.get();
+ auto param = (UnregisterAudioThreadParam *) command->parameter.get();
command->result =
param == nullptr ? AAUDIO_ERROR_ILLEGAL_ARGUMENT
: unregisterAudioThread_l(param->mClientThreadId);
}
break;
case GET_DESCRIPTION: {
- GetDescriptionParam *param = (GetDescriptionParam *) command->parameter.get();
+ auto param = (GetDescriptionParam *) command->parameter.get();
command->result = param == nullptr ? AAUDIO_ERROR_ILLEGAL_ARGUMENT
: getDescription_l(param->mParcelable);
}
break;
case EXIT_STANDBY: {
- ExitStandbyParam *param = (ExitStandbyParam *) command->parameter.get();
+ auto param = (ExitStandbyParam *) command->parameter.get();
command->result = param == nullptr ? AAUDIO_ERROR_ILLEGAL_ARGUMENT
: exitStandby_l(param->mParcelable);
standbyTime = AudioClock::getNanoseconds() + IDLE_TIMEOUT_NANOS;
diff --git a/services/oboeservice/AAudioServiceStreamBase.h b/services/oboeservice/AAudioServiceStreamBase.h
index b5f8b90..0f51503 100644
--- a/services/oboeservice/AAudioServiceStreamBase.h
+++ b/services/oboeservice/AAudioServiceStreamBase.h
@@ -62,7 +62,7 @@
public:
explicit AAudioServiceStreamBase(android::AAudioService &aAudioService);
- virtual ~AAudioServiceStreamBase();
+ ~AAudioServiceStreamBase() override;
enum {
ILLEGAL_THREAD_ID = 0
@@ -254,7 +254,7 @@
RegisterAudioThreadParam(pid_t ownerPid, pid_t clientThreadId, int priority)
: AAudioCommandParam(), mOwnerPid(ownerPid),
mClientThreadId(clientThreadId), mPriority(priority) { }
- ~RegisterAudioThreadParam() = default;
+ ~RegisterAudioThreadParam() override = default;
pid_t mOwnerPid;
pid_t mClientThreadId;
@@ -265,9 +265,9 @@
class UnregisterAudioThreadParam : public AAudioCommandParam {
public:
- UnregisterAudioThreadParam(pid_t clientThreadId)
+ explicit UnregisterAudioThreadParam(pid_t clientThreadId)
: AAudioCommandParam(), mClientThreadId(clientThreadId) { }
- ~UnregisterAudioThreadParam() = default;
+ ~UnregisterAudioThreadParam() override = default;
pid_t mClientThreadId;
};
@@ -275,9 +275,9 @@
class GetDescriptionParam : public AAudioCommandParam {
public:
- GetDescriptionParam(AudioEndpointParcelable* parcelable)
+ explicit GetDescriptionParam(AudioEndpointParcelable* parcelable)
: AAudioCommandParam(), mParcelable(parcelable) { }
- ~GetDescriptionParam() = default;
+ ~GetDescriptionParam() override = default;
AudioEndpointParcelable* mParcelable;
};
@@ -324,9 +324,9 @@
}
class ExitStandbyParam : public AAudioCommandParam {
public:
- ExitStandbyParam(AudioEndpointParcelable* parcelable)
+ explicit ExitStandbyParam(AudioEndpointParcelable* parcelable)
: AAudioCommandParam(), mParcelable(parcelable) { }
- ~ExitStandbyParam() = default;
+ ~ExitStandbyParam() override = default;
AudioEndpointParcelable* mParcelable;
};
diff --git a/services/oboeservice/AAudioServiceStreamMMAP.h b/services/oboeservice/AAudioServiceStreamMMAP.h
index cd8c91e..8b8c5e6 100644
--- a/services/oboeservice/AAudioServiceStreamMMAP.h
+++ b/services/oboeservice/AAudioServiceStreamMMAP.h
@@ -47,7 +47,7 @@
public:
AAudioServiceStreamMMAP(android::AAudioService &aAudioService,
bool inService);
- virtual ~AAudioServiceStreamMMAP() = default;
+ ~AAudioServiceStreamMMAP() override = default;
aaudio_result_t open(const aaudio::AAudioStreamRequest &request) override;
diff --git a/services/oboeservice/AAudioServiceStreamShared.h b/services/oboeservice/AAudioServiceStreamShared.h
index 78f9787..0b2513a 100644
--- a/services/oboeservice/AAudioServiceStreamShared.h
+++ b/services/oboeservice/AAudioServiceStreamShared.h
@@ -44,7 +44,7 @@
public:
explicit AAudioServiceStreamShared(android::AAudioService &aAudioService);
- virtual ~AAudioServiceStreamShared() = default;
+ ~AAudioServiceStreamShared() override = default;
static std::string dumpHeader();
diff --git a/services/oboeservice/AAudioStreamTracker.cpp b/services/oboeservice/AAudioStreamTracker.cpp
index 9bbbc73..c86a7a2 100644
--- a/services/oboeservice/AAudioStreamTracker.cpp
+++ b/services/oboeservice/AAudioStreamTracker.cpp
@@ -78,7 +78,8 @@
return handle;
}
-aaudio_handle_t AAudioStreamTracker::addStreamForHandle(sp<AAudioServiceStreamBase> serviceStream) {
+aaudio_handle_t AAudioStreamTracker::addStreamForHandle(
+ const sp<AAudioServiceStreamBase>& serviceStream) {
std::lock_guard<std::mutex> lock(mHandleLock);
aaudio_handle_t handle = mPreviousHandle;
// Assign a unique handle.
diff --git a/services/oboeservice/AAudioStreamTracker.h b/services/oboeservice/AAudioStreamTracker.h
index 43870fc..99f4b6c 100644
--- a/services/oboeservice/AAudioStreamTracker.h
+++ b/services/oboeservice/AAudioStreamTracker.h
@@ -64,7 +64,7 @@
* @param serviceStream
* @return handle for identifying the stream
*/
- aaudio_handle_t addStreamForHandle(android::sp<AAudioServiceStreamBase> serviceStream);
+ aaudio_handle_t addStreamForHandle(const android::sp<AAudioServiceStreamBase>& serviceStream);
/**
* @return string that can be added to dumpsys
diff --git a/services/oboeservice/AAudioThread.h b/services/oboeservice/AAudioThread.h
index b2774e0..91ad715 100644
--- a/services/oboeservice/AAudioThread.h
+++ b/services/oboeservice/AAudioThread.h
@@ -29,7 +29,7 @@
*/
class Runnable {
public:
- Runnable() {};
+ Runnable() = default;
virtual ~Runnable() = default;
virtual void run() = 0;
diff --git a/services/oboeservice/Android.bp b/services/oboeservice/Android.bp
index 5076239..56c0dc9 100644
--- a/services/oboeservice/Android.bp
+++ b/services/oboeservice/Android.bp
@@ -21,6 +21,64 @@
default_applicable_licenses: ["frameworks_av_license"],
}
+tidy_errors = [
+ // https://clang.llvm.org/extra/clang-tidy/checks/list.html
+ // For many categories, the checks are too many to specify individually.
+ // Feel free to disable as needed - as warnings are generally ignored,
+ // we treat warnings as errors.
+ "android-*",
+ "bugprone-*",
+ "cert-*",
+ "clang-analyzer-security*",
+ "google-*",
+ "misc-*",
+ //"modernize-*", // explicitly list the modernize as they can be subjective.
+ "modernize-avoid-bind",
+ //"modernize-avoid-c-arrays", // std::array<> can be verbose
+ "modernize-concat-nested-namespaces",
+ //"modernize-deprecated-headers", // C headers still ok even if there is C++ equivalent.
+ "modernize-deprecated-ios-base-aliases",
+ "modernize-loop-convert",
+ "modernize-make-shared",
+ "modernize-make-unique",
+ "modernize-pass-by-value",
+ "modernize-raw-string-literal",
+ "modernize-redundant-void-arg",
+ "modernize-replace-auto-ptr",
+ "modernize-replace-random-shuffle",
+ "modernize-return-braced-init-list",
+ "modernize-shrink-to-fit",
+ "modernize-unary-static-assert",
+ "modernize-use-auto",
+ "modernize-use-bool-literals",
+ "modernize-use-default-member-init",
+ "modernize-use-emplace",
+ "modernize-use-equals-default",
+ "modernize-use-equals-delete",
+ // "modernize-use-nodiscard", // Maybe add this in the future
+ "modernize-use-noexcept",
+ "modernize-use-nullptr",
+ "modernize-use-override",
+ // "modernize-use-trailing-return-type", // not necessarily more readable
+ "modernize-use-transparent-functors",
+ "modernize-use-uncaught-exceptions",
+ "modernize-use-using",
+ "performance-*",
+
+ // Remove some pedantic stylistic requirements.
+ "-android-cloexec-dup", // found in AAudioServiceEndpointMMAP.cpp
+ "-bugprone-narrowing-conversions", // found in several interface from size_t to int32_t
+
+ "-google-readability-casting", // C++ casts not always necessary and may be verbose
+ "-google-readability-todo", // do not require TODO(info)
+ "-google-build-using-namespace", // Reenable and fix later.
+ "-google-global-names-in-headers", // found in several files
+
+ "-misc-non-private-member-variables-in-classes", // found in aidl generated files
+
+]
+
+
cc_library {
name: "libaaudioservice",
@@ -89,4 +147,11 @@
"frameworks/av/media/libnbaio/include_mono",
"frameworks/av/media/libnbaio/include",
],
+
+ tidy: true,
+ tidy_checks: tidy_errors,
+ tidy_checks_as_errors: tidy_errors,
+ tidy_flags: [
+ "-format-style=file",
+ ]
}
diff --git a/services/oboeservice/SharedMemoryProxy.cpp b/services/oboeservice/SharedMemoryProxy.cpp
index 78d4884..549a36e 100644
--- a/services/oboeservice/SharedMemoryProxy.cpp
+++ b/services/oboeservice/SharedMemoryProxy.cpp
@@ -58,7 +58,7 @@
}
// Get original memory address.
- mOriginalSharedMemory = (uint8_t *) mmap(0, mSharedMemorySizeInBytes,
+ mOriginalSharedMemory = (uint8_t *) mmap(nullptr, mSharedMemorySizeInBytes,
PROT_READ|PROT_WRITE,
MAP_SHARED,
mOriginalFileDescriptor, 0);
diff --git a/services/oboeservice/SharedMemoryProxy.h b/services/oboeservice/SharedMemoryProxy.h
index 89eeb4b..81a0753 100644
--- a/services/oboeservice/SharedMemoryProxy.h
+++ b/services/oboeservice/SharedMemoryProxy.h
@@ -30,7 +30,7 @@
*/
class SharedMemoryProxy {
public:
- SharedMemoryProxy() {}
+ SharedMemoryProxy() = default;
~SharedMemoryProxy();
diff --git a/services/oboeservice/SharedRingBuffer.cpp b/services/oboeservice/SharedRingBuffer.cpp
index fd2a454..eebff51 100644
--- a/services/oboeservice/SharedRingBuffer.cpp
+++ b/services/oboeservice/SharedRingBuffer.cpp
@@ -62,7 +62,7 @@
// Map the fd to memory addresses. Use a temporary pointer to keep the mmap result and update
// it to `mSharedMemory` only when mmap operate successfully.
- uint8_t* tmpPtr = (uint8_t *) mmap(0, mSharedMemorySizeInBytes,
+ auto tmpPtr = (uint8_t *) mmap(nullptr, mSharedMemorySizeInBytes,
PROT_READ|PROT_WRITE,
MAP_SHARED,
mFileDescriptor.get(), 0);
@@ -74,10 +74,8 @@
mSharedMemory = tmpPtr;
// Get addresses for our counters and data from the shared memory.
- fifo_counter_t *readCounterAddress =
- (fifo_counter_t *) &mSharedMemory[SHARED_RINGBUFFER_READ_OFFSET];
- fifo_counter_t *writeCounterAddress =
- (fifo_counter_t *) &mSharedMemory[SHARED_RINGBUFFER_WRITE_OFFSET];
+ auto readCounterAddress = (fifo_counter_t *) &mSharedMemory[SHARED_RINGBUFFER_READ_OFFSET];
+ auto writeCounterAddress = (fifo_counter_t *) &mSharedMemory[SHARED_RINGBUFFER_WRITE_OFFSET];
uint8_t *dataAddress = &mSharedMemory[SHARED_RINGBUFFER_DATA_OFFSET];
mFifoBuffer = std::make_shared<FifoBufferIndirect>(bytesPerFrame, capacityInFrames,
diff --git a/services/oboeservice/SharedRingBuffer.h b/services/oboeservice/SharedRingBuffer.h
index cff1261..463bf11 100644
--- a/services/oboeservice/SharedRingBuffer.h
+++ b/services/oboeservice/SharedRingBuffer.h
@@ -39,7 +39,7 @@
*/
class SharedRingBuffer {
public:
- SharedRingBuffer() {}
+ SharedRingBuffer() = default;
virtual ~SharedRingBuffer();
diff --git a/services/oboeservice/TimestampScheduler.h b/services/oboeservice/TimestampScheduler.h
index baa5c41..6b5f4b1 100644
--- a/services/oboeservice/TimestampScheduler.h
+++ b/services/oboeservice/TimestampScheduler.h
@@ -31,7 +31,7 @@
class TimestampScheduler
{
public:
- TimestampScheduler() {};
+ TimestampScheduler() = default;
virtual ~TimestampScheduler() = default;
/**