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

Commit bda4575c authored by Philip P. Moltmann's avatar Philip P. Moltmann Committed by Nate Myren
Browse files

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
parent 6d988df3
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@ LOCAL_SHARED_LIBRARIES := \
        libstagefright_foundation libjpeg libui libgui libcutils liblog \
        libhidlbase libdatasource libaudioclient \
        android.hardware.media.omx@1.0 \
        media_permission-aidl-cpp

LOCAL_STATIC_LIBRARIES := media_permission-aidl-cpp

LOCAL_C_INCLUDES:= \
        frameworks/av/media/libstagefright \
@@ -48,7 +51,8 @@ LOCAL_HEADER_LIBRARIES := \

LOCAL_SHARED_LIBRARIES := \
        libstagefright libmedia liblog libutils libbinder \
        libstagefright_foundation libdatasource libaudioclient
        libstagefright_foundation libdatasource libaudioclient \
        media_permission-aidl-cpp

LOCAL_C_INCLUDES:= \
        frameworks/av/camera/include \
@@ -85,7 +89,8 @@ LOCAL_SHARED_LIBRARIES := \
LOCAL_C_INCLUDES:= \
        frameworks/av/media/libstagefright \
        frameworks/native/include/media/openmax \
        frameworks/native/include/media/hardware
        frameworks/native/include/media/hardware \
        media_permission-aidl-cpp

LOCAL_CFLAGS += -Wno-multichar -Werror -Wall

@@ -113,7 +118,8 @@ LOCAL_HEADER_LIBRARIES := \

LOCAL_SHARED_LIBRARIES := \
        libstagefright libmedia liblog libutils libbinder \
        libstagefright_foundation libaudioclient
        libstagefright_foundation libaudioclient \
        media_permission-aidl-cpp

LOCAL_C_INCLUDES:= \
        frameworks/av/media/libstagefright \
+5 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@

#include <utils/String16.h>

#include <android/media/permission/Identity.h>
#include <binder/ProcessState.h>
#include <media/mediarecorder.h>
#include <media/stagefright/foundation/ADebug.h>
@@ -38,6 +39,8 @@

using namespace android;

using media::permission::Identity;

static void usage(const char* name)
{
    fprintf(stderr, "Usage: %s [-d du.ration] [-m] [-w] [-N name] [<output-file>]\n", name);
@@ -110,9 +113,10 @@ int main(int argc, char* argv[])
        audio_attributes_t attr = AUDIO_ATTRIBUTES_INITIALIZER;
        attr.source = AUDIO_SOURCE_MIC;

        // TODO b/182392769: use identity util
        source = new AudioSource(
                &attr,
                String16(),
                Identity(),
                sampleRate,
                channels);
    } else {
+31 −0
Original line number Diff line number Diff line
@@ -580,6 +580,37 @@ AAUDIO_API aaudio_result_t AAudio_createStreamBuilder(AAudioStreamBuilder** buil
AAUDIO_API void AAudioStreamBuilder_setDeviceId(AAudioStreamBuilder* builder,
                                                int32_t deviceId) __INTRODUCED_IN(26);

// TODO b/182392769: reexamine if Identity can be used
/**
 * Declare the name of the package creating the stream.
 *
 * This is usually {@code Context#getPackageName()}.
 *
 * The default, if you do not call this function, is a random package in the calling uid.
 *
 * Available since API level 31.
 *
 * @param builder reference provided by AAudio_createStreamBuilder()
 * @param packageName packageName of the calling app.
 */
AAUDIO_API void AAudioStreamBuilder_setPackageName(AAudioStreamBuilder* builder,
                                                   const char * packageName) __INTRODUCED_IN(31);

/**
 * Declare the attribution tag of the context creating the stream.
 *
 * This is usually {@code Context#getAttributionTag()}.
 *
 * The default, if you do not call this function, is the default attribution tag.
 *
 * Available since API level 31.
 *
 * @param builder reference provided by AAudio_createStreamBuilder()
 * @param attributionTag attributionTag of the calling context.
 */
AAUDIO_API void AAudioStreamBuilder_setAttributionTag(AAudioStreamBuilder* builder,
        const char * attributionTag) __INTRODUCED_IN(31);

/**
 * Request a sample rate in Hertz.
 *
+11 −0
Original line number Diff line number Diff line
@@ -85,6 +85,10 @@ cc_library {
    ],
    export_header_lib_headers: ["libaaudio_headers"],

    export_shared_lib_headers: [
        "media_permission-aidl-cpp",
    ],

    shared_libs: [
        "libaudioclient",
        "libaudioutils",
@@ -96,6 +100,12 @@ cc_library {
        "libutils",
        "libbinder",
        "aaudio-aidl-cpp",
        "media_permission-aidl-cpp",
        "libaudioclient_aidl_conversion",
    ],

    static_libs: [
        "media_permission-aidl-cpp",
    ],

    cflags: [
@@ -167,6 +177,7 @@ aidl_interface {
    imports: [
        "audio_common-aidl",
        "shared-file-region-aidl",
        "media_permission-aidl",
    ],
    backend:
    {
+3 −8
Original line number Diff line number Diff line
@@ -31,19 +31,15 @@ using namespace aaudio;

AAudioStreamRequest::AAudioStreamRequest(const StreamRequest& parcelable) :
        mConfiguration(std::move(parcelable.params)),
        mUserId(parcelable.userId),
        mProcessId(parcelable.processId),
        mIdentity(parcelable.identity),
        mSharingModeMatchRequired(parcelable.sharingModeMatchRequired),
        mInService(parcelable.inService) {
    static_assert(sizeof(mUserId) == sizeof(parcelable.userId));
    static_assert(sizeof(mProcessId) == sizeof(parcelable.processId));
}

StreamRequest AAudioStreamRequest::parcelable() const {
    StreamRequest result;
    result.params = std::move(mConfiguration).parcelable();
    result.userId = mUserId;
    result.processId = mProcessId;
    result.identity = mIdentity;
    result.sharingModeMatchRequired = mSharingModeMatchRequired;
    result.inService = mInService;
    return result;
@@ -54,8 +50,7 @@ aaudio_result_t AAudioStreamRequest::validate() const {
}

void AAudioStreamRequest::dump() const {
    ALOGD("mUserId    = %d", mUserId);
    ALOGD("mProcessId = %d", mProcessId);
    ALOGD("mIdentity  = %s", mIdentity.toString().c_str());
    ALOGD("mSharingModeMatchRequired = %d", mSharingModeMatchRequired);
    ALOGD("mInService = %d", mInService);
    mConfiguration.dump();
Loading