From 732fc3ef3ac4a141ae742b020079eb5209f16f41 Mon Sep 17 00:00:00 2001 From: Dean Wheatley Date: Fri, 24 Sep 2021 13:49:23 +1000 Subject: [PATCH] Check direct playback capabilities for automotive devices For Automotive devices, surround encodings can be supported via the passthrough path. Therefore, include automotive in the allowed device types in the isDirectPlaybackSupported checks. The automotive system feature is checked, rather then UI_MODE_TYPE_CAR, because the UI_MODE_TYPE_CAR can be force enabled via android.app.UiModeManager.enableCarMode(), whereas FEATURE_AUTOMOTIVE cannot be forced. --- .../java/com/google/android/exoplayer2/util/Util.java | 10 ++++++++++ .../android/exoplayer2/audio/AudioCapabilities.java | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/library/common/src/main/java/com/google/android/exoplayer2/util/Util.java b/library/common/src/main/java/com/google/android/exoplayer2/util/Util.java index ec913e52e1..1f6822151d 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/util/Util.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/util/Util.java @@ -2305,6 +2305,16 @@ public final class Util { && uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION; } + /** + * Returns whether the app is running on an Automotive device. + * + * @param context Any context. + * @return Whether the app is running on an Automotive device. + */ + public static boolean isAutomotive(Context context) { + return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE); + } + /** * Gets the size of the current mode of the default display, in pixels. * diff --git a/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioCapabilities.java b/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioCapabilities.java index 1510aa6e22..39fa2860a6 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioCapabilities.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/audio/AudioCapabilities.java @@ -90,8 +90,9 @@ public final class AudioCapabilities { } // 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 devices, which generally shouldn't support audio offload for surround encodings. - if (Util.SDK_INT >= 29 && Util.isTv(context)) { + // it on TV and Automotive devices, which generally shouldn't support audio offload for surround + // encodings. + if (Util.SDK_INT >= 29 && (Util.isTv(context) || Util.isAutomotive(context))) { return new AudioCapabilities( Api29.getDirectPlaybackSupportedEncodings(), DEFAULT_MAX_CHANNEL_COUNT); }