Add attributionTag to audio-recordings
... by replacing packageName/uid/pid by the Identity class.
This allows us to track which parts of the app trigger audio-recordings.
90% of the code is just sending around the additional parameters.
This adds it for the Java and native API.
Test: atest CtsAppOpsTestCases
CtsNativeMediaAAudioTestCases
Fixes: 160150145
Change-Id: Ibd7b884f7fcd4668a4e27f997e59cfc3217a9e89
diff --git a/services/oboeservice/AAudioServiceStreamBase.cpp b/services/oboeservice/AAudioServiceStreamBase.cpp
index 7edc25c..694094c 100644
--- a/services/oboeservice/AAudioServiceStreamBase.cpp
+++ b/services/oboeservice/AAudioServiceStreamBase.cpp
@@ -39,6 +39,8 @@
using namespace android; // TODO just import names needed
using namespace aaudio; // TODO just import names needed
+using media::permission::Identity;
+
/**
* Base class for streams in the service.
* @return
@@ -48,9 +50,7 @@
: mTimestampThread("AATime")
, mAtomicStreamTimestamp()
, mAudioService(audioService) {
- mMmapClient.clientUid = -1;
- mMmapClient.clientPid = -1;
- mMmapClient.packageName = String16("");
+ mMmapClient.identity = Identity();
}
AAudioServiceStreamBase::~AAudioServiceStreamBase() {
@@ -82,7 +82,7 @@
result << " 0x" << std::setfill('0') << std::setw(8) << std::hex << mHandle
<< std::dec << std::setfill(' ') ;
- result << std::setw(6) << mMmapClient.clientUid;
+ result << std::setw(6) << mMmapClient.identity.uid;
result << std::setw(7) << mClientHandle;
result << std::setw(4) << (isRunning() ? "yes" : " no");
result << std::setw(6) << getState();
@@ -128,9 +128,12 @@
AAudioEndpointManager &mEndpointManager = AAudioEndpointManager::getInstance();
aaudio_result_t result = AAUDIO_OK;
- mMmapClient.clientUid = request.getUserId();
- mMmapClient.clientPid = request.getProcessId();
- mMmapClient.packageName.setTo(String16("")); // TODO What should we do here?
+ mMmapClient.identity = request.getIdentity();
+ // TODO b/182392769: use identity util
+ mMmapClient.identity.uid = VALUE_OR_FATAL(
+ legacy2aidl_uid_t_int32_t(IPCThreadState::self()->getCallingUid()));
+ mMmapClient.identity.pid = VALUE_OR_FATAL(
+ legacy2aidl_pid_t_int32_t(IPCThreadState::self()->getCallingPid()));
// Limit scope of lock to avoid recursive lock in close().
{