AudioRecord: fix issues with privacy sensitive mode
Fix two issues with privacy sensitive mode implementation: 1) default applied by AudioAttributes based on source could override explicit flag set. 2) when privacy mode was explicitly set in AudioRecord builder, the audio source was reset. Bug: 137850106 Test: CTS test for AudioRecord Change-Id: I73f69d3d214102dcc237cac616c9bfc3f85b288e
This commit is contained in:
@@ -598,6 +598,11 @@ public final class AudioAttributes implements Parcelable {
|
||||
private boolean mMuteHapticChannels = true;
|
||||
private HashSet<String> mTags = new HashSet<String>();
|
||||
private Bundle mBundle;
|
||||
private int mPrivacySensitive = PRIVACY_SENSITIVE_DEFAULT;
|
||||
|
||||
private static final int PRIVACY_SENSITIVE_DEFAULT = -1;
|
||||
private static final int PRIVACY_SENSITIVE_DISABLED = 0;
|
||||
private static final int PRIVACY_SENSITIVE_ENABLED = 1;
|
||||
|
||||
/**
|
||||
* Constructs a new Builder with the defaults.
|
||||
@@ -638,11 +643,20 @@ public final class AudioAttributes implements Parcelable {
|
||||
if (mMuteHapticChannels) {
|
||||
aa.mFlags |= FLAG_MUTE_HAPTIC;
|
||||
}
|
||||
// capturing for camcorder of communication is private by default to
|
||||
// reflect legacy behavior
|
||||
if (aa.mSource == MediaRecorder.AudioSource.VOICE_COMMUNICATION
|
||||
|| aa.mSource == MediaRecorder.AudioSource.CAMCORDER) {
|
||||
|
||||
if (mPrivacySensitive == PRIVACY_SENSITIVE_DEFAULT) {
|
||||
// capturing for camcorder or communication is private by default to
|
||||
// reflect legacy behavior
|
||||
if (mSource == MediaRecorder.AudioSource.VOICE_COMMUNICATION
|
||||
|| mSource == MediaRecorder.AudioSource.CAMCORDER) {
|
||||
aa.mFlags |= FLAG_CAPTURE_PRIVATE;
|
||||
} else {
|
||||
aa.mFlags &= ~FLAG_CAPTURE_PRIVATE;
|
||||
}
|
||||
} else if (mPrivacySensitive == PRIVACY_SENSITIVE_ENABLED) {
|
||||
aa.mFlags |= FLAG_CAPTURE_PRIVATE;
|
||||
} else {
|
||||
aa.mFlags &= ~FLAG_CAPTURE_PRIVATE;
|
||||
}
|
||||
aa.mTags = (HashSet<String>) mTags.clone();
|
||||
aa.mFormattedTags = TextUtils.join(";", mTags);
|
||||
@@ -967,6 +981,20 @@ public final class AudioAttributes implements Parcelable {
|
||||
mMuteHapticChannels = muted;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
* Indicates if an AudioRecord build with this AudioAttributes is privacy sensitive or not.
|
||||
* See {@link AudioRecord.Builder#setPrivacySensitive(boolean)}.
|
||||
* @param privacySensitive True if capture must be marked as privacy sensitive,
|
||||
* false otherwise.
|
||||
* @return the same Builder instance.
|
||||
*/
|
||||
public @NonNull Builder setPrivacySensitive(boolean privacySensitive) {
|
||||
mPrivacySensitive =
|
||||
privacySensitive ? PRIVACY_SENSITIVE_ENABLED : PRIVACY_SENSITIVE_DISABLED;
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
|
||||
@@ -315,7 +315,7 @@ public class AudioRecord implements AudioRouting, MicrophoneDirection,
|
||||
* @hide
|
||||
* Class constructor with {@link AudioAttributes} and {@link AudioFormat}.
|
||||
* @param attributes a non-null {@link AudioAttributes} instance. Use
|
||||
* {@link AudioAttributes.Builder#setAudioSource(int)} for configuring the audio
|
||||
* {@link AudioAttributes.Builder#setCapturePreset(int)} for configuring the audio
|
||||
* source for this instance.
|
||||
* @param format a non-null {@link AudioFormat} instance describing the format of the data
|
||||
* that will be recorded through this AudioRecord. See {@link AudioFormat.Builder} for
|
||||
@@ -754,17 +754,10 @@ public class AudioRecord implements AudioRouting, MicrophoneDirection,
|
||||
"Cannot request private capture with source: " + source);
|
||||
}
|
||||
|
||||
int flags = mAttributes.getAllFlags();
|
||||
if (mPrivacySensitive == PRIVACY_SENSITIVE_DISABLED) {
|
||||
flags &= ~AudioAttributes.FLAG_CAPTURE_PRIVATE;
|
||||
} else if (mPrivacySensitive == PRIVACY_SENSITIVE_ENABLED) {
|
||||
flags |= AudioAttributes.FLAG_CAPTURE_PRIVATE;
|
||||
}
|
||||
if (flags != mAttributes.getAllFlags()) {
|
||||
mAttributes = new AudioAttributes.Builder(mAttributes)
|
||||
.replaceFlags(flags)
|
||||
.build();
|
||||
}
|
||||
mAttributes = new AudioAttributes.Builder(mAttributes)
|
||||
.setInternalCapturePreset(source)
|
||||
.setPrivacySensitive(mPrivacySensitive == PRIVACY_SENSITIVE_ENABLED)
|
||||
.build();
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user