Add aaudio APC opt-out
The opt-out was only present in the java API but not on the native ones.
Test: atest test_attributes
Change-Id: I1b84f1a428508e00de65e615b59405b9ee2ba009
Signed-off-by: Kevin Rocard <krocard@google.com>
diff --git a/media/libaaudio/examples/utils/AAudioArgsParser.h b/media/libaaudio/examples/utils/AAudioArgsParser.h
index f5ed7aa..755ecc5 100644
--- a/media/libaaudio/examples/utils/AAudioArgsParser.h
+++ b/media/libaaudio/examples/utils/AAudioArgsParser.h
@@ -36,11 +36,14 @@
aaudio_content_type_t contentType) = nullptr;
static void (*s_setInputPreset)(AAudioStreamBuilder* builder,
aaudio_input_preset_t inputPreset) = nullptr;
+static void (*s_setAllowedCapturePolicy)(AAudioStreamBuilder* builder,
+ aaudio_allowed_capture_policy_t usage) = nullptr;
static bool s_loadAttempted = false;
static aaudio_usage_t (*s_getUsage)(AAudioStream *stream) = nullptr;
static aaudio_content_type_t (*s_getContentType)(AAudioStream *stream) = nullptr;
static aaudio_input_preset_t (*s_getInputPreset)(AAudioStream *stream) = nullptr;
+static aaudio_allowed_capture_policy_t (*s_getAllowedCapturePolicy)(AAudioStream *stream) = nullptr;
// Link to test functions in shared library.
static void loadFutureFunctions() {
@@ -61,6 +64,10 @@
dlsym(handle, "AAudioStreamBuilder_setInputPreset");
if (s_setInputPreset == nullptr) goto error;
+ s_setAllowedCapturePolicy = (void (*)(AAudioStreamBuilder *, aaudio_input_preset_t))
+ dlsym(handle, "AAudioStreamBuilder_setAllowedCapturePolicy");
+ if (s_setAllowedCapturePolicy == nullptr) goto error;
+
s_getUsage = (aaudio_usage_t (*)(AAudioStream *))
dlsym(handle, "AAudioStream_getUsage");
if (s_getUsage == nullptr) goto error;
@@ -72,6 +79,10 @@
s_getInputPreset = (aaudio_input_preset_t (*)(AAudioStream *))
dlsym(handle, "AAudioStream_getInputPreset");
if (s_getInputPreset == nullptr) goto error;
+
+ s_getAllowedCapturePolicy = (aaudio_input_preset_t (*)(AAudioStream *))
+ dlsym(handle, "AAudioStream_getAllowedCapturePolicy");
+ if (s_getAllowedCapturePolicy == nullptr) goto error;
}
return;
@@ -169,6 +180,14 @@
mInputPreset = inputPreset;
}
+ aaudio_allowed_capture_policy_t getAllowedCapturePolicy() const {
+ return mAllowedCapturePolicy;
+ }
+
+ void setAllowedCapturePolicy(aaudio_allowed_capture_policy_t policy) {
+ mAllowedCapturePolicy = policy;
+ }
+
int32_t getDeviceId() const {
return mDeviceId;
}
@@ -223,6 +242,13 @@
} else if (mUsage != AAUDIO_UNSPECIFIED){
printf("WARNING: setInputPreset not supported");
}
+
+ // Call Q functions if supported.
+ if (s_setAllowedCapturePolicy != nullptr) {
+ s_setAllowedCapturePolicy(builder, mAllowedCapturePolicy);
+ } else if (mAllowedCapturePolicy != AAUDIO_UNSPECIFIED){
+ printf("WARNING: setAllowedCapturePolicy not supported");
+ }
}
private:
@@ -238,6 +264,7 @@
aaudio_usage_t mUsage = AAUDIO_UNSPECIFIED;
aaudio_content_type_t mContentType = AAUDIO_UNSPECIFIED;
aaudio_input_preset_t mInputPreset = AAUDIO_UNSPECIFIED;
+ aaudio_allowed_capture_policy_t mAllowedCapturePolicy = AAUDIO_UNSPECIFIED;
int32_t mNumberOfBursts = AAUDIO_UNSPECIFIED;
int32_t mFramesPerCallback = AAUDIO_UNSPECIFIED;
@@ -267,6 +294,9 @@
case 'c':
setChannelCount(atoi(&arg[2]));
break;
+ case 'C':
+ setAllowedCapturePolicy(parseAllowedCapturePolicy(arg[2]));
+ break;
case 'd':
setDeviceId(atoi(&arg[2]));
break;
@@ -341,6 +371,10 @@
printf(" Default values are UNSPECIFIED unless otherwise stated.\n");
printf(" -b{bufferCapacity} frames\n");
printf(" -c{channels} for example 2 for stereo\n");
+ printf(" -C{a|s|n} set playback capture policy\n");
+ printf(" a = _ALL (default)\n");
+ printf(" s = _SYSTEM\n");
+ printf(" n = _NONE\n");
printf(" -d{deviceId} default is %d\n", AAUDIO_UNSPECIFIED);
printf(" -f{0|1|2} set format\n");
printf(" 0 = UNSPECIFIED\n");
@@ -365,6 +399,25 @@
printf(" -z{callbackSize} or block size, in frames, default = 0\n");
}
+ static aaudio_performance_mode_t parseAllowedCapturePolicy(char c) {
+ aaudio_allowed_capture_policy_t policy = AAUDIO_ALLOW_CAPTURE_BY_ALL;
+ switch (c) {
+ case 'a':
+ policy = AAUDIO_ALLOW_CAPTURE_BY_ALL;
+ break;
+ case 's':
+ policy = AAUDIO_ALLOW_CAPTURE_BY_SYSTEM;
+ break;
+ case 'n':
+ policy = AAUDIO_ALLOW_CAPTURE_BY_NONE;
+ break;
+ default:
+ printf("ERROR: invalid playback capture policy %c\n", c);
+ break;
+ }
+ return policy;
+ }
+
static aaudio_performance_mode_t parsePerformanceMode(char c) {
aaudio_performance_mode_t mode = AAUDIO_PERFORMANCE_MODE_NONE;
switch (c) {
@@ -449,6 +502,11 @@
printf(" Is MMAP used? %s\n", AAudioStream_isMMapUsed(stream)
? "yes" : "no");
+ if (s_getAllowedCapturePolicy != nullptr) {
+ printf(" ContentType: requested = %d, actual = %d\n",
+ getAllowedCapturePolicy(), s_getAllowedCapturePolicy(stream));
+ }
+
}
int32_t getDurationSeconds() const {
diff --git a/media/libaaudio/include/aaudio/AAudio.h b/media/libaaudio/include/aaudio/AAudio.h
index 8e36c77..19e22f1 100644
--- a/media/libaaudio/include/aaudio/AAudio.h
+++ b/media/libaaudio/include/aaudio/AAudio.h
@@ -232,7 +232,8 @@
* This information is used by certain platforms or routing policies
* to make more refined volume or routing decisions.
*
- * Note that these match the equivalent values in AudioAttributes in the Android Java API.
+ * Note that these match the equivalent values in {@link android.media.AudioAttributes}
+ * in the Android Java API.
*
* Added in API level 28.
*/
@@ -308,7 +309,8 @@
* an audio book application) this information might be used by the audio framework to
* enforce audio focus.
*
- * Note that these match the equivalent values in AudioAttributes in the Android Java API.
+ * Note that these match the equivalent values in {@link android.media.AudioAttributes}
+ * in the Android Java API.
*
* Added in API level 28.
*/
@@ -384,6 +386,48 @@
typedef int32_t aaudio_input_preset_t;
/**
+ * Specifying if audio may or may not be captured by other apps or the system.
+ *
+ * Note that these match the equivalent values in {@link android.media.AudioAttributes}
+ * in the Android Java API.
+ *
+ * Added in API level 29.
+ */
+enum {
+ /**
+ * Indicates that the audio may be captured by any app.
+ *
+ * For privacy, the following usages can not be recorded: AAUDIO_VOICE_COMMUNICATION*,
+ * AAUDIO_USAGE_NOTIFICATION*, AAUDIO_USAGE_ASSISTANCE* and AAUDIO_USAGE_ASSISTANT.
+ *
+ * On {@link Android.os.Build.VERSION_CODES.Q}, this means only {@link AAUDIO_USAGE_MEDIA}
+ * and {@link AAUDIO_USAGE_GAME} may be captured.
+ *
+ * See {@link android.media.AudioAttributes.ALLOW_CAPTURE_BY_ALL}.
+ */
+ AAUDIO_ALLOW_CAPTURE_BY_ALL = 1,
+ /**
+ * Indicates that the audio may only be captured by system apps.
+ *
+ * System apps can capture for many purposes like accessibility, user guidance...
+ * but have strong restriction. See
+ * {@link android.media.AudioAttributes.ALLOW_CAPTURE_BY_SYSTEM} for what the system apps
+ * can do with the capture audio.
+ */
+ AAUDIO_ALLOW_CAPTURE_BY_SYSTEM = 2,
+ /**
+ * Indicates that the audio may not be recorded by any app, even if it is a system app.
+ *
+ * It is encouraged to use {@link ALLOW_CAPTURE_BY_SYSTEM} instead of this value as system apps
+ * provide significant and useful features for the user (eg. accessibility).
+ * See {@link android.media.AudioAttributes.ALLOW_CAPTURE_BY_NONE}.
+ */
+ AAUDIO_ALLOW_CAPTURE_BY_NONE = 3,
+};
+
+typedef int32_t aaudio_allowed_capture_policy_t;
+
+/**
* These may be used with AAudioStreamBuilder_setSessionId().
*
* Added in API level 28.
@@ -643,6 +687,22 @@
AAUDIO_API void AAudioStreamBuilder_setInputPreset(AAudioStreamBuilder* builder,
aaudio_input_preset_t inputPreset) __INTRODUCED_IN(28);
+/**
+ * Specify whether this stream audio may or may not be captured by other apps or the system.
+ *
+ * The default is AAUDIO_ALLOW_CAPTURE_BY_ALL.
+ *
+ * Note that an application can also set its global policy, in which case the most restrictive
+ * policy is always applied. See {@link android.media.AudioAttributes.setAllowedCapturePolicy}
+ *
+ * Added in API level 29.
+ *
+ * @param builder reference provided by AAudio_createStreamBuilder()
+ * @param inputPreset the desired level of opt-out from being captured.
+ */
+AAUDIO_API void AAudioStreamBuilder_setAllowedCapturePolicy(AAudioStreamBuilder* builder,
+ aaudio_allowed_capture_policy_t capturePolicy) __INTRODUCED_IN(29);
+
/** Set the requested session ID.
*
* The session ID can be used to associate a stream with effects processors.
@@ -1277,6 +1337,18 @@
AAUDIO_API aaudio_input_preset_t AAudioStream_getInputPreset(AAudioStream* stream)
__INTRODUCED_IN(28);
+/**
+ * Return the policy that determines whether the audio may or may not be captured
+ * by other apps or the system.
+ *
+ * Added in API level 29.
+ *
+ * @param stream reference provided by AAudioStreamBuilder_openStream()
+ * @return the allowed capture policy, for example AAUDIO_ALLOW_CAPTURE_BY_ALL
+ */
+AAUDIO_API aaudio_allowed_capture_policy_t AAudioStream_getAllowedCapturePolicy(
+ AAudioStream* stream) __INTRODUCED_IN(29);
+
#ifdef __cplusplus
}
#endif
diff --git a/media/libaaudio/src/binding/AAudioStreamConfiguration.cpp b/media/libaaudio/src/binding/AAudioStreamConfiguration.cpp
index 3d1bc9b..a987fab 100644
--- a/media/libaaudio/src/binding/AAudioStreamConfiguration.cpp
+++ b/media/libaaudio/src/binding/AAudioStreamConfiguration.cpp
@@ -62,6 +62,8 @@
if (status != NO_ERROR) goto error;
status = parcel->writeInt32((int32_t) getInputPreset());
if (status != NO_ERROR) goto error;
+ status = parcel->writeInt32((int32_t) getAllowedCapturePolicy());
+ if (status != NO_ERROR) goto error;
status = parcel->writeInt32(getSessionId());
if (status != NO_ERROR) goto error;
return NO_ERROR;
@@ -105,6 +107,9 @@
setInputPreset((aaudio_input_preset_t) value);
status = parcel->readInt32(&value);
if (status != NO_ERROR) goto error;
+ setAllowedCapturePolicy((aaudio_allowed_capture_policy_t) value);
+ status = parcel->readInt32(&value);
+ if (status != NO_ERROR) goto error;
setSessionId(value);
return NO_ERROR;
diff --git a/media/libaaudio/src/core/AAudioAudio.cpp b/media/libaaudio/src/core/AAudioAudio.cpp
index 0d71efc..8ae2644 100644
--- a/media/libaaudio/src/core/AAudioAudio.cpp
+++ b/media/libaaudio/src/core/AAudioAudio.cpp
@@ -204,6 +204,12 @@
streamBuilder->setBufferCapacity(frames);
}
+AAUDIO_API void AAudioStreamBuilder_setAllowedCapturePolicy(
+ AAudioStreamBuilder* builder, aaudio_allowed_capture_policy_t policy) {
+ AudioStreamBuilder *streamBuilder = convertAAudioBuilderToStreamBuilder(builder);
+ streamBuilder->setAllowedCapturePolicy(policy);
+}
+
AAUDIO_API void AAudioStreamBuilder_setSessionId(AAudioStreamBuilder* builder,
aaudio_session_id_t sessionId)
{
@@ -494,6 +500,13 @@
return audioStream->getInputPreset();
}
+AAUDIO_API aaudio_allowed_capture_policy_t AAudioStream_getAllowedCapturePolicy(
+ AAudioStream* stream)
+{
+ AudioStream *audioStream = convertAAudioStreamToAudioStream(stream);
+ return audioStream->getAllowedCapturePolicy();
+}
+
AAUDIO_API int32_t AAudioStream_getSessionId(AAudioStream* stream)
{
AudioStream *audioStream = convertAAudioStreamToAudioStream(stream);
diff --git a/media/libaaudio/src/core/AAudioStreamParameters.cpp b/media/libaaudio/src/core/AAudioStreamParameters.cpp
index 88da53a..e5bda30 100644
--- a/media/libaaudio/src/core/AAudioStreamParameters.cpp
+++ b/media/libaaudio/src/core/AAudioStreamParameters.cpp
@@ -35,17 +35,18 @@
AAudioStreamParameters::~AAudioStreamParameters() {}
void AAudioStreamParameters::copyFrom(const AAudioStreamParameters &other) {
- mSamplesPerFrame = other.mSamplesPerFrame;
- mSampleRate = other.mSampleRate;
- mDeviceId = other.mDeviceId;
- mSessionId = other.mSessionId;
- mSharingMode = other.mSharingMode;
- mAudioFormat = other.mAudioFormat;
- mDirection = other.mDirection;
- mBufferCapacity = other.mBufferCapacity;
- mUsage = other.mUsage;
- mContentType = other.mContentType;
- mInputPreset = other.mInputPreset;
+ mSamplesPerFrame = other.mSamplesPerFrame;
+ mSampleRate = other.mSampleRate;
+ mDeviceId = other.mDeviceId;
+ mSessionId = other.mSessionId;
+ mSharingMode = other.mSharingMode;
+ mAudioFormat = other.mAudioFormat;
+ mDirection = other.mDirection;
+ mBufferCapacity = other.mBufferCapacity;
+ mUsage = other.mUsage;
+ mContentType = other.mContentType;
+ mInputPreset = other.mInputPreset;
+ mAllowedCapturePolicy = other.mAllowedCapturePolicy;
}
static aaudio_result_t isFormatValid(audio_format_t format) {
@@ -166,19 +167,32 @@
// break;
}
+ switch (mAllowedCapturePolicy) {
+ case AAUDIO_UNSPECIFIED:
+ case AAUDIO_ALLOW_CAPTURE_BY_ALL:
+ case AAUDIO_ALLOW_CAPTURE_BY_SYSTEM:
+ case AAUDIO_ALLOW_CAPTURE_BY_NONE:
+ break; // valid
+ default:
+ ALOGE("allowed capture policy not valid = %d", mAllowedCapturePolicy);
+ return AAUDIO_ERROR_ILLEGAL_ARGUMENT;
+ // break;
+ }
+
return AAUDIO_OK;
}
void AAudioStreamParameters::dump() const {
- ALOGD("mDeviceId = %6d", mDeviceId);
- ALOGD("mSessionId = %6d", mSessionId);
- ALOGD("mSampleRate = %6d", mSampleRate);
- ALOGD("mSamplesPerFrame = %6d", mSamplesPerFrame);
- ALOGD("mSharingMode = %6d", (int)mSharingMode);
- ALOGD("mAudioFormat = %6d", (int)mAudioFormat);
- ALOGD("mDirection = %6d", mDirection);
- ALOGD("mBufferCapacity = %6d", mBufferCapacity);
- ALOGD("mUsage = %6d", mUsage);
- ALOGD("mContentType = %6d", mContentType);
- ALOGD("mInputPreset = %6d", mInputPreset);
+ ALOGD("mDeviceId = %6d", mDeviceId);
+ ALOGD("mSessionId = %6d", mSessionId);
+ ALOGD("mSampleRate = %6d", mSampleRate);
+ ALOGD("mSamplesPerFrame = %6d", mSamplesPerFrame);
+ ALOGD("mSharingMode = %6d", (int)mSharingMode);
+ ALOGD("mAudioFormat = %6d", (int)mAudioFormat);
+ ALOGD("mDirection = %6d", mDirection);
+ ALOGD("mBufferCapacity = %6d", mBufferCapacity);
+ ALOGD("mUsage = %6d", mUsage);
+ ALOGD("mContentType = %6d", mContentType);
+ ALOGD("mInputPreset = %6d", mInputPreset);
+ ALOGD("mAllowedCapturePolicy = %6d", mAllowedCapturePolicy);
}
diff --git a/media/libaaudio/src/core/AAudioStreamParameters.h b/media/libaaudio/src/core/AAudioStreamParameters.h
index 6beb4b2..2e21a8d 100644
--- a/media/libaaudio/src/core/AAudioStreamParameters.h
+++ b/media/libaaudio/src/core/AAudioStreamParameters.h
@@ -112,6 +112,14 @@
mInputPreset = inputPreset;
}
+ aaudio_allowed_capture_policy_t getAllowedCapturePolicy() const {
+ return mAllowedCapturePolicy;
+ }
+
+ void setAllowedCapturePolicy(aaudio_allowed_capture_policy_t policy) {
+ mAllowedCapturePolicy = policy;
+ }
+
aaudio_session_id_t getSessionId() const {
return mSessionId;
}
@@ -138,17 +146,18 @@
void dump() const;
private:
- int32_t mSamplesPerFrame = AAUDIO_UNSPECIFIED;
- int32_t mSampleRate = AAUDIO_UNSPECIFIED;
- int32_t mDeviceId = AAUDIO_UNSPECIFIED;
- aaudio_sharing_mode_t mSharingMode = AAUDIO_SHARING_MODE_SHARED;
- audio_format_t mAudioFormat = AUDIO_FORMAT_DEFAULT;
- aaudio_direction_t mDirection = AAUDIO_DIRECTION_OUTPUT;
- aaudio_usage_t mUsage = AAUDIO_UNSPECIFIED;
- aaudio_content_type_t mContentType = AAUDIO_UNSPECIFIED;
- aaudio_input_preset_t mInputPreset = AAUDIO_UNSPECIFIED;
- int32_t mBufferCapacity = AAUDIO_UNSPECIFIED;
- aaudio_session_id_t mSessionId = AAUDIO_SESSION_ID_NONE;
+ int32_t mSamplesPerFrame = AAUDIO_UNSPECIFIED;
+ int32_t mSampleRate = AAUDIO_UNSPECIFIED;
+ int32_t mDeviceId = AAUDIO_UNSPECIFIED;
+ aaudio_sharing_mode_t mSharingMode = AAUDIO_SHARING_MODE_SHARED;
+ audio_format_t mAudioFormat = AUDIO_FORMAT_DEFAULT;
+ aaudio_direction_t mDirection = AAUDIO_DIRECTION_OUTPUT;
+ aaudio_usage_t mUsage = AAUDIO_UNSPECIFIED;
+ aaudio_content_type_t mContentType = AAUDIO_UNSPECIFIED;
+ aaudio_input_preset_t mInputPreset = AAUDIO_UNSPECIFIED;
+ int32_t mBufferCapacity = AAUDIO_UNSPECIFIED;
+ aaudio_allowed_capture_policy_t mAllowedCapturePolicy = AAUDIO_UNSPECIFIED;
+ aaudio_session_id_t mSessionId = AAUDIO_SESSION_ID_NONE;
};
} /* namespace aaudio */
diff --git a/media/libaaudio/src/core/AudioStream.cpp b/media/libaaudio/src/core/AudioStream.cpp
index e39a075..732d45c 100644
--- a/media/libaaudio/src/core/AudioStream.cpp
+++ b/media/libaaudio/src/core/AudioStream.cpp
@@ -94,6 +94,10 @@
if (mInputPreset == AAUDIO_UNSPECIFIED) {
mInputPreset = AAUDIO_INPUT_PRESET_VOICE_RECOGNITION;
}
+ mAllowedCapturePolicy = builder.getAllowedCapturePolicy();
+ if (mAllowedCapturePolicy == AAUDIO_UNSPECIFIED) {
+ mAllowedCapturePolicy = AAUDIO_ALLOW_CAPTURE_BY_ALL;
+ }
// callbacks
mFramesPerDataCallback = builder.getFramesPerDataCallback();
@@ -113,8 +117,8 @@
mPerformanceMode,
(isDataCallbackSet() ? "ON" : "OFF"),
mFramesPerDataCallback);
- ALOGI("open() usage = %d, contentType = %d, inputPreset = %d",
- mUsage, mContentType, mInputPreset);
+ ALOGI("open() usage = %d, contentType = %d, inputPreset = %d, allowedCapturePolicy = %d",
+ mUsage, mContentType, mInputPreset, mAllowedCapturePolicy);
return AAUDIO_OK;
}
diff --git a/media/libaaudio/src/core/AudioStream.h b/media/libaaudio/src/core/AudioStream.h
index 46951f5..32713b1 100644
--- a/media/libaaudio/src/core/AudioStream.h
+++ b/media/libaaudio/src/core/AudioStream.h
@@ -219,6 +219,10 @@
return mInputPreset;
}
+ aaudio_allowed_capture_policy_t getAllowedCapturePolicy() const {
+ return mAllowedCapturePolicy;
+ }
+
int32_t getSessionId() const {
return mSessionId;
}
@@ -525,6 +529,13 @@
mInputPreset = inputPreset;
}
+ /**
+ * This should not be called after the open() call.
+ */
+ void setAllowedCapturePolicy(aaudio_allowed_capture_policy_t policy) {
+ mAllowedCapturePolicy = policy;
+ }
+
private:
aaudio_result_t safeStop();
@@ -546,6 +557,7 @@
aaudio_usage_t mUsage = AAUDIO_UNSPECIFIED;
aaudio_content_type_t mContentType = AAUDIO_UNSPECIFIED;
aaudio_input_preset_t mInputPreset = AAUDIO_UNSPECIFIED;
+ aaudio_allowed_capture_policy_t mAllowedCapturePolicy = AAUDIO_ALLOW_CAPTURE_BY_ALL;
int32_t mSessionId = AAUDIO_UNSPECIFIED;
diff --git a/media/libaaudio/src/legacy/AudioStreamTrack.cpp b/media/libaaudio/src/legacy/AudioStreamTrack.cpp
index ff95aed..e359c1c 100644
--- a/media/libaaudio/src/legacy/AudioStreamTrack.cpp
+++ b/media/libaaudio/src/legacy/AudioStreamTrack.cpp
@@ -134,12 +134,14 @@
AAudioConvert_contentTypeToInternal(builder.getContentType());
const audio_usage_t usage =
AAudioConvert_usageToInternal(builder.getUsage());
+ const audio_flags_mask_t attributesFlags =
+ AAudioConvert_allowCapturePolicyToAudioFlagsMask(builder.getAllowedCapturePolicy());
const audio_attributes_t attributes = {
.content_type = contentType,
.usage = usage,
.source = AUDIO_SOURCE_DEFAULT, // only used for recording
- .flags = AUDIO_FLAG_NONE, // Different than the AUDIO_OUTPUT_FLAGS
+ .flags = attributesFlags,
.tags = ""
};
diff --git a/media/libaaudio/src/utility/AAudioUtilities.cpp b/media/libaaudio/src/utility/AAudioUtilities.cpp
index 723cbf1..96ed56a 100644
--- a/media/libaaudio/src/utility/AAudioUtilities.cpp
+++ b/media/libaaudio/src/utility/AAudioUtilities.cpp
@@ -217,6 +217,22 @@
return (audio_source_t) preset; // same value
}
+audio_flags_mask_t AAudioConvert_allowCapturePolicyToAudioFlagsMask(
+ aaudio_allowed_capture_policy_t policy) {
+ switch (policy) {
+ case AAUDIO_UNSPECIFIED:
+ case AAUDIO_ALLOW_CAPTURE_BY_ALL:
+ return AUDIO_FLAG_NONE;
+ case AAUDIO_ALLOW_CAPTURE_BY_SYSTEM:
+ return AUDIO_FLAG_NO_MEDIA_PROJECTION;
+ case AAUDIO_ALLOW_CAPTURE_BY_NONE:
+ return AUDIO_FLAG_NO_MEDIA_PROJECTION | AUDIO_FLAG_NO_SYSTEM_CAPTURE;
+ default:
+ ALOGE("%s() 0x%08X unrecognized", __func__, policy);
+ return AUDIO_FLAG_NONE; //
+ }
+}
+
int32_t AAudioConvert_framesToBytes(int32_t numFrames,
int32_t bytesPerFrame,
int32_t *sizeInBytes) {
diff --git a/media/libaaudio/src/utility/AAudioUtilities.h b/media/libaaudio/src/utility/AAudioUtilities.h
index dc2b198..76d0457 100644
--- a/media/libaaudio/src/utility/AAudioUtilities.h
+++ b/media/libaaudio/src/utility/AAudioUtilities.h
@@ -84,6 +84,14 @@
*/
audio_source_t AAudioConvert_inputPresetToAudioSource(aaudio_input_preset_t preset);
+/**
+ * Note that this function does not validate the passed in value.
+ * That is done somewhere else.
+ * @return internal audio flags mask
+ */
+audio_flags_mask_t AAudioConvert_allowCapturePolicyToAudioFlagsMask(
+ aaudio_allowed_capture_policy_t policy);
+
// Note that this code may be replaced by Settings or by some other system configuration tool.
#define AAUDIO_PROP_MMAP_POLICY "aaudio.mmap_policy"
diff --git a/media/libaaudio/tests/test_attributes.cpp b/media/libaaudio/tests/test_attributes.cpp
index dbf8712..32ee2a3 100644
--- a/media/libaaudio/tests/test_attributes.cpp
+++ b/media/libaaudio/tests/test_attributes.cpp
@@ -32,6 +32,7 @@
aaudio_usage_t usage,
aaudio_content_type_t contentType,
aaudio_input_preset_t preset = DONT_SET,
+ aaudio_allowed_capture_policy_t capturePolicy = DONT_SET,
aaudio_direction_t direction = AAUDIO_DIRECTION_OUTPUT) {
float *buffer = new float[kNumFrames * kChannelCount];
@@ -56,6 +57,9 @@
if (preset != DONT_SET) {
AAudioStreamBuilder_setInputPreset(aaudioBuilder, preset);
}
+ if (capturePolicy != DONT_SET) {
+ AAudioStreamBuilder_setAllowedCapturePolicy(aaudioBuilder, capturePolicy);
+ }
// Create an AAudioStream using the Builder.
ASSERT_EQ(AAUDIO_OK, AAudioStreamBuilder_openStream(aaudioBuilder, &aaudioStream));
@@ -80,6 +84,12 @@
: preset;
EXPECT_EQ(expectedPreset, AAudioStream_getInputPreset(aaudioStream));
+ aaudio_allowed_capture_policy_t expectedCapturePolicy =
+ (capturePolicy == DONT_SET || capturePolicy == AAUDIO_UNSPECIFIED)
+ ? AAUDIO_ALLOW_CAPTURE_BY_ALL // default
+ : preset;
+ EXPECT_EQ(expectedCapturePolicy, AAudioStream_getAllowedCapturePolicy(aaudioStream));
+
EXPECT_EQ(AAUDIO_OK, AAudioStream_requestStart(aaudioStream));
if (direction == AAUDIO_DIRECTION_INPUT) {
@@ -133,13 +143,21 @@
AAUDIO_INPUT_PRESET_VOICE_PERFORMANCE,
};
+static const aaudio_input_preset_t sAllowCapturePolicies[] = {
+ DONT_SET,
+ AAUDIO_UNSPECIFIED,
+ AAUDIO_ALLOW_CAPTURE_BY_ALL,
+ AAUDIO_ALLOW_CAPTURE_BY_SYSTEM,
+ AAUDIO_ALLOW_CAPTURE_BY_NONE,
+};
+
static void checkAttributesUsage(aaudio_performance_mode_t perfMode) {
for (aaudio_usage_t usage : sUsages) {
checkAttributes(perfMode, usage, DONT_SET);
}
}
-static void checkAttributesContentType(aaudio_input_preset_t perfMode) {
+static void checkAttributesContentType(aaudio_performance_mode_t perfMode) {
for (aaudio_content_type_t contentType : sContentypes) {
checkAttributes(perfMode, DONT_SET, contentType);
}
@@ -151,6 +169,18 @@
DONT_SET,
DONT_SET,
inputPreset,
+ DONT_SET,
+ AAUDIO_DIRECTION_INPUT);
+ }
+}
+
+static void checkAttributesAllowedCapturePolicy(aaudio_performance_mode_t perfMode) {
+ for (aaudio_allowed_capture_policy_t policy : sAllowCapturePolicies) {
+ checkAttributes(perfMode,
+ DONT_SET,
+ DONT_SET,
+ DONT_SET,
+ policy,
AAUDIO_DIRECTION_INPUT);
}
}
@@ -167,6 +197,10 @@
checkAttributesInputPreset(AAUDIO_PERFORMANCE_MODE_NONE);
}
+TEST(test_attributes, aaudio_allowed_capture_policy_perfnone) {
+ checkAttributesAllowedCapturePolicy(AAUDIO_PERFORMANCE_MODE_NONE);
+}
+
TEST(test_attributes, aaudio_usage_lowlat) {
checkAttributesUsage(AAUDIO_PERFORMANCE_MODE_LOW_LATENCY);
}
@@ -178,3 +212,7 @@
TEST(test_attributes, aaudio_input_preset_lowlat) {
checkAttributesInputPreset(AAUDIO_PERFORMANCE_MODE_LOW_LATENCY);
}
+
+TEST(test_attributes, aaudio_allowed_capture_policy_lowlat) {
+ checkAttributesAllowedCapturePolicy(AAUDIO_PERFORMANCE_MODE_LOW_LATENCY);
+}