diff options
| author | 2019-04-23 16:49:50 -0700 | |
|---|---|---|
| committer | 2019-04-24 08:20:17 -0700 | |
| commit | 9f70d4e29bafe11c592395da9e89d21350bd341b (patch) | |
| tree | 535589e53365c49e5a0e58072123e38205da65fe | |
| parent | 25b06f04d4d79b9fc8f9a74d54b27bdccabd88bb (diff) | |
AudioAttributes: fix regression with setLegacyStreamType in Builder
A regression was introduced by commit @6d69bde which caused a new
Builder instance to be created when using setLegacyStreamType(),
instead of returning the current one.
Bug: 130274354
Test: atest android.media.cts.AudioAttributesTest#testSetLegacyStreamOnBuilder
Change-Id: Ib66a0beb5f0f4489a6003cb9be6b8313b3318eac
| -rw-r--r-- | media/java/android/media/AudioAttributes.java | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/media/java/android/media/AudioAttributes.java b/media/java/android/media/AudioAttributes.java index a9150d4b7455..977e790eb42e 100644 --- a/media/java/android/media/AudioAttributes.java +++ b/media/java/android/media/AudioAttributes.java @@ -786,8 +786,13 @@ public final class AudioAttributes implements Parcelable { /** * Sets attributes as inferred from the legacy stream types. - * Use this method when building an {@link AudioAttributes} instance to initialize some of - * the attributes by information derived from a legacy stream type. + * Warning: do not use this method in combination with setting any other attributes such as + * usage, content type, flags or haptic control, as this method will overwrite (the more + * accurate) information describing the use case previously set in the <code>Builder</code>. + * In general, avoid using it and prefer setting usage and content type directly + * with {@link #setUsage(int)} and {@link #setContentType(int)}. + * <p>Use this method when building an {@link AudioAttributes} instance to initialize some + * of the attributes by information derived from a legacy stream type. * @param streamType one of {@link AudioManager#STREAM_VOICE_CALL}, * {@link AudioManager#STREAM_SYSTEM}, {@link AudioManager#STREAM_RING}, * {@link AudioManager#STREAM_MUSIC}, {@link AudioManager#STREAM_ALARM}, @@ -799,7 +804,8 @@ public final class AudioAttributes implements Parcelable { throw new IllegalArgumentException("STREAM_ACCESSIBILITY is not a legacy stream " + "type that was used for audio playback"); } - return setInternalLegacyStreamType(streamType); + setInternalLegacyStreamType(streamType); + return this; } /** @@ -815,7 +821,14 @@ public final class AudioAttributes implements Parcelable { AudioProductStrategy.getAudioAttributesForStrategyWithLegacyStreamType( streamType); if (attributes != null) { - return new Builder(attributes).setHapticChannelsMuted(mMuteHapticChannels); + mUsage = attributes.mUsage; + mContentType = attributes.mContentType; + mFlags = attributes.mFlags; + mMuteHapticChannels = attributes.areHapticChannelsMuted(); + mTags = attributes.mTags; + mBundle = attributes.mBundle; + mSource = attributes.mSource; + return this; } } switch(streamType) { |