Skip to content

Commit

Permalink
Force external surround sound flag if requested by device
Browse files Browse the repository at this point in the history
Some FireOS6 devices ask to force the external surround global
flag and ignore any signals from the HDMI connection.

This is the equivalent change of amzn/exoplayer-amazon-port@e341944

PiperOrigin-RevId: 614634499
(cherry picked from commit 410c049)
  • Loading branch information
tonihei authored and SheenaChhabra committed Mar 11, 2024
1 parent a85d9e2 commit fffbf9a
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static java.lang.Math.max;

import android.annotation.SuppressLint;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
Expand Down Expand Up @@ -90,6 +91,13 @@ public final class AudioCapabilities {
/** Global settings key for devices that can specify external surround sound. */
private static final String EXTERNAL_SURROUND_SOUND_KEY = "external_surround_sound_enabled";

/**
* Global setting key for devices that want to force the usage of {@link
* #EXTERNAL_SURROUND_SOUND_KEY} over other signals like HDMI.
*/
private static final String FORCE_EXTERNAL_SURROUND_SOUND_KEY =
"use_external_surround_sound_flag";

/**
* @deprecated Use {@link #getCapabilities(Context, AudioAttributes, AudioDeviceInfo)} instead.
*/
Expand Down Expand Up @@ -168,12 +176,17 @@ 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) {
ContentResolver contentResolver = context.getContentResolver();
boolean forceExternalSurroundSoundSetting =
Global.getInt(contentResolver, FORCE_EXTERNAL_SURROUND_SOUND_KEY, 0) == 1;
if ((forceExternalSurroundSoundSetting || deviceMaySetExternalSurroundSoundGlobalSetting())
&& Global.getInt(contentResolver, EXTERNAL_SURROUND_SOUND_KEY, 0) == 1) {
supportedEncodings.addAll(EXTERNAL_SURROUND_SOUND_ENCODINGS);
}

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

0 comments on commit fffbf9a

Please sign in to comment.