Skip to content

Commit

Permalink
Reorder audio capability checks
Browse files Browse the repository at this point in the history
Using the more accurate check available on later API versions
first is likely better than falling back to a fallback solution
from older API versions.

PiperOrigin-RevId: 614612628
(cherry picked from commit 18cbbf3)
  • Loading branch information
tonihei authored and SheenaChhabra committed Mar 11, 2024
1 parent a72a232 commit a85d9e2
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,7 @@ public static AudioCapabilities getCapabilities(

ImmutableSet.Builder<Integer> supportedEncodings = new ImmutableSet.Builder<>();
supportedEncodings.add(C.ENCODING_PCM_16BIT);
if (deviceMaySetExternalSurroundSoundGlobalSetting()
&& Global.getInt(context.getContentResolver(), EXTERNAL_SURROUND_SOUND_KEY, 0) == 1) {
supportedEncodings.addAll(EXTERNAL_SURROUND_SOUND_ENCODINGS);
}

// AudioTrack.isDirectPlaybackSupported returns true for encodings that are supported for audio
// offload, as well as for encodings we want to list for passthrough mode. Therefore we only use
// it on TV and automotive devices, which generally shouldn't support audio offload for surround
Expand All @@ -171,6 +168,11 @@ public static AudioCapabilities getCapabilities(
getAudioProfiles(Ints.toArray(supportedEncodings.build()), DEFAULT_MAX_CHANNEL_COUNT));
}

if (deviceMaySetExternalSurroundSoundGlobalSetting()
&& Global.getInt(context.getContentResolver(), EXTERNAL_SURROUND_SOUND_KEY, 0) == 1) {
supportedEncodings.addAll(EXTERNAL_SURROUND_SOUND_ENCODINGS);
}

if (intent != null && intent.getIntExtra(AudioManager.EXTRA_AUDIO_PLUG_STATE, 0) == 1) {
@Nullable int[] encodingsFromExtra = intent.getIntArrayExtra(AudioManager.EXTRA_ENCODINGS);
if (encodingsFromExtra != null) {
Expand Down

0 comments on commit a85d9e2

Please sign in to comment.