diff options
| author | 2023-09-01 00:44:55 +0000 | |
|---|---|---|
| committer | 2023-09-01 00:44:55 +0000 | |
| commit | f857b88f11fede3435c47f641126904e2b652791 (patch) | |
| tree | 1ed8b8815da2cfa7e4871197bcc13091a969f1e1 | |
| parent | ab63ec47929800f1c93b14317fd84582641730b7 (diff) | |
| parent | e0db7b76c40b5aa38eb7f6a1acef88859c4c2d68 (diff) | |
Merge changes from topic "spat_audio_types" into udc-qpr-dev am: e0db7b76c4
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/24531364
Change-Id: I01706dcd6ec110033cb60d618447abbe7f5bf581
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
3 files changed, 50 insertions, 2 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java index f03ff00828a6..ceda9024eaa6 100644 --- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java +++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/CachedBluetoothDevice.java @@ -728,6 +728,14 @@ public class CachedBluetoothDevice implements Comparable<CachedBluetoothDevice> void onAudioModeChanged() { dispatchAttributesChanged(); } + + /** + * Notify that the audio category has changed. + */ + public void onAudioDeviceCategoryChanged() { + dispatchAttributesChanged(); + } + /** * Get the device status as active or non-active per Bluetooth profile. * diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 1b3443d32cfb..749e792d00ea 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -10738,6 +10738,7 @@ public class AudioService extends IAudioService.Stub mDeviceBroker.addOrUpdateBtAudioDeviceCategoryInInventory(deviceState); mDeviceBroker.persistAudioDeviceSettings(); + mSpatializerHelper.refreshDevice(deviceState.getAudioDeviceAttributes()); mSoundDoseHelper.setAudioDeviceCategory(addr, internalType, btAudioDeviceCategory == AUDIO_DEVICE_CATEGORY_HEADPHONES); } diff --git a/services/core/java/com/android/server/audio/SpatializerHelper.java b/services/core/java/com/android/server/audio/SpatializerHelper.java index 9fa569af316d..35260ed6f148 100644 --- a/services/core/java/com/android/server/audio/SpatializerHelper.java +++ b/services/core/java/com/android/server/audio/SpatializerHelper.java @@ -16,6 +16,8 @@ package com.android.server.audio; +import static android.media.AudioManager.AUDIO_DEVICE_CATEGORY_HEADPHONES; +import static android.media.AudioManager.AUDIO_DEVICE_CATEGORY_UNKNOWN; import static android.media.AudioSystem.isBluetoothDevice; import android.annotation.NonNull; @@ -682,8 +684,20 @@ public class SpatializerHelper { Log.i(TAG, "no spatialization device state found for Spatial Audio device:" + ada); return new Pair<>(false, false); } + boolean available = true; + if (isBluetoothDevice(deviceType)) { + // only checking headphones/binaural because external speakers cannot use transaural + // since their physical characteristics are unknown + if (deviceState.getAudioDeviceCategory() == AUDIO_DEVICE_CATEGORY_UNKNOWN + || deviceState.getAudioDeviceCategory() == AUDIO_DEVICE_CATEGORY_HEADPHONES) { + available = (spatMode == SpatializationMode.SPATIALIZER_BINAURAL) + && mBinauralSupported; + } else { + available = false; + } + } // found the matching device state. - return new Pair<>(deviceState.isSAEnabled(), true /* available */); + return new Pair<>(deviceState.isSAEnabled(), available); } private synchronized void addWirelessDeviceIfNew(@NonNull AudioDeviceAttributes ada) { @@ -740,11 +754,36 @@ public class SpatializerHelper { } } + synchronized void refreshDevice(@NonNull AudioDeviceAttributes ada) { + final AdiDeviceState deviceState = findSACompatibleDeviceStateForAudioDeviceAttributes(ada); + if (isAvailableForAdiDeviceState(deviceState)) { + addCompatibleAudioDevice(ada, /*forceEnable=*/deviceState.isSAEnabled()); + setHeadTrackerEnabled(deviceState.isHeadTrackerEnabled(), ada); + } else { + removeCompatibleAudioDevice(ada); + } + } + synchronized boolean isAvailableForDevice(@NonNull AudioDeviceAttributes ada) { if (ada.getRole() != AudioDeviceAttributes.ROLE_OUTPUT) { return false; } - return findSACompatibleDeviceStateForAudioDeviceAttributes(ada) != null; + + return isAvailableForAdiDeviceState( + findSACompatibleDeviceStateForAudioDeviceAttributes(ada)); + } + + private boolean isAvailableForAdiDeviceState(AdiDeviceState deviceState) { + if (deviceState == null) { + return false; + } + + if (isBluetoothDevice(deviceState.getInternalDeviceType()) + && deviceState.getAudioDeviceCategory() != AUDIO_DEVICE_CATEGORY_UNKNOWN + && deviceState.getAudioDeviceCategory() != AUDIO_DEVICE_CATEGORY_HEADPHONES) { + return false; + } + return true; } private synchronized boolean canBeSpatializedOnDevice(@NonNull AudioAttributes attributes, |