From: Eric Laurent Date: Wed, 1 May 2019 21:24:40 +0000 (-0700) Subject: AudioAttributes: fix setInternalLegacyStreamType() X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=e6c8972013c073bf386bf2b5f4cfb84a256529f0;p=android-x86%2Fframeworks-base.git AudioAttributes: fix setInternalLegacyStreamType() Make sure that the content type is always properly set from legacy stream type in the case where the product strategy matching this legacy stream type does not specify it. Bug: 129506383 Test: playback with Youtube and check content type with audio service dumpsys Change-Id: Ibaac0edc21bc44a56c632fb420b94deee710869d --- diff --git a/media/java/android/media/AudioAttributes.java b/media/java/android/media/AudioAttributes.java index 977e790eb42e..8612e1bf324c 100644 --- a/media/java/android/media/AudioAttributes.java +++ b/media/java/android/media/AudioAttributes.java @@ -816,6 +816,8 @@ public final class AudioAttributes implements Parcelable { */ @UnsupportedAppUsage public Builder setInternalLegacyStreamType(int streamType) { + mContentType = CONTENT_TYPE_UNKNOWN; + mUsage = USAGE_UNKNOWN; if (AudioProductStrategy.getAudioProductStrategies().size() > 0) { AudioAttributes attributes = AudioProductStrategy.getAudioAttributesForStrategyWithLegacyStreamType( @@ -828,49 +830,52 @@ public final class AudioAttributes implements Parcelable { mTags = attributes.mTags; mBundle = attributes.mBundle; mSource = attributes.mSource; - return this; } } - switch(streamType) { - case AudioSystem.STREAM_VOICE_CALL: - mContentType = CONTENT_TYPE_SPEECH; - break; - case AudioSystem.STREAM_SYSTEM_ENFORCED: - mFlags |= FLAG_AUDIBILITY_ENFORCED; - // intended fall through, attributes in common with STREAM_SYSTEM - case AudioSystem.STREAM_SYSTEM: - mContentType = CONTENT_TYPE_SONIFICATION; - break; - case AudioSystem.STREAM_RING: - mContentType = CONTENT_TYPE_SONIFICATION; - break; - case AudioSystem.STREAM_MUSIC: - mContentType = CONTENT_TYPE_MUSIC; - break; - case AudioSystem.STREAM_ALARM: - mContentType = CONTENT_TYPE_SONIFICATION; - break; - case AudioSystem.STREAM_NOTIFICATION: - mContentType = CONTENT_TYPE_SONIFICATION; - break; - case AudioSystem.STREAM_BLUETOOTH_SCO: - mContentType = CONTENT_TYPE_SPEECH; - mFlags |= FLAG_SCO; - break; - case AudioSystem.STREAM_DTMF: - mContentType = CONTENT_TYPE_SONIFICATION; - break; - case AudioSystem.STREAM_TTS: - mContentType = CONTENT_TYPE_SONIFICATION; - mFlags |= FLAG_BEACON; - break; - case AudioSystem.STREAM_ACCESSIBILITY: - mContentType = CONTENT_TYPE_SPEECH; - break; - default: - Log.e(TAG, "Invalid stream type " + streamType + " for AudioAttributes"); + if (mContentType == CONTENT_TYPE_UNKNOWN) { + switch (streamType) { + case AudioSystem.STREAM_VOICE_CALL: + mContentType = CONTENT_TYPE_SPEECH; + break; + case AudioSystem.STREAM_SYSTEM_ENFORCED: + mFlags |= FLAG_AUDIBILITY_ENFORCED; + // intended fall through, attributes in common with STREAM_SYSTEM + case AudioSystem.STREAM_SYSTEM: + mContentType = CONTENT_TYPE_SONIFICATION; + break; + case AudioSystem.STREAM_RING: + mContentType = CONTENT_TYPE_SONIFICATION; + break; + case AudioSystem.STREAM_MUSIC: + mContentType = CONTENT_TYPE_MUSIC; + break; + case AudioSystem.STREAM_ALARM: + mContentType = CONTENT_TYPE_SONIFICATION; + break; + case AudioSystem.STREAM_NOTIFICATION: + mContentType = CONTENT_TYPE_SONIFICATION; + break; + case AudioSystem.STREAM_BLUETOOTH_SCO: + mContentType = CONTENT_TYPE_SPEECH; + mFlags |= FLAG_SCO; + break; + case AudioSystem.STREAM_DTMF: + mContentType = CONTENT_TYPE_SONIFICATION; + break; + case AudioSystem.STREAM_TTS: + mContentType = CONTENT_TYPE_SONIFICATION; + mFlags |= FLAG_BEACON; + break; + case AudioSystem.STREAM_ACCESSIBILITY: + mContentType = CONTENT_TYPE_SPEECH; + break; + default: + Log.e(TAG, "Invalid stream type " + streamType + " for AudioAttributes"); + } + } + if (mUsage == USAGE_UNKNOWN) { + mUsage = usageForStreamType(streamType); } - mUsage = usageForStreamType(streamType); return this; }