Loading services/core/java/com/android/server/audio/AudioDeviceBroker.java +5 −4 Original line number Diff line number Diff line Loading @@ -2793,12 +2793,13 @@ public class AudioDeviceBroker { return mDeviceInventory.getImmutableDeviceInventory(); } void addOrUpdateDeviceSAStateInInventory(AdiDeviceState deviceState) { mDeviceInventory.addOrUpdateDeviceSAStateInInventory(deviceState); void addOrUpdateDeviceSAStateInInventory(AdiDeviceState deviceState, boolean syncInventory) { mDeviceInventory.addOrUpdateDeviceSAStateInInventory(deviceState, syncInventory); } void addOrUpdateBtAudioDeviceCategoryInInventory(AdiDeviceState deviceState) { mDeviceInventory.addOrUpdateAudioDeviceCategoryInInventory(deviceState); void addOrUpdateBtAudioDeviceCategoryInInventory( AdiDeviceState deviceState, boolean syncInventory) { mDeviceInventory.addOrUpdateAudioDeviceCategoryInInventory(deviceState, syncInventory); } @Nullable Loading services/core/java/com/android/server/audio/AudioDeviceInventory.java +46 −17 Original line number Diff line number Diff line Loading @@ -135,9 +135,10 @@ public class AudioDeviceInventory { * AdiDeviceState in the {@link AudioDeviceInventory#mDeviceInventory} list. * @param deviceState the device to update */ void addOrUpdateDeviceSAStateInInventory(AdiDeviceState deviceState) { void addOrUpdateDeviceSAStateInInventory(AdiDeviceState deviceState, boolean syncInventory) { synchronized (mDeviceInventoryLock) { mDeviceInventory.merge(deviceState.getDeviceId(), deviceState, (oldState, newState) -> { mDeviceInventory.merge(deviceState.getDeviceId(), deviceState, (oldState, newState) -> { oldState.setHasHeadTracker(newState.hasHeadTracker()); oldState.setHeadTrackerEnabled(newState.isHeadTrackerEnabled()); oldState.setSAEnabled(newState.isSAEnabled()); Loading @@ -145,8 +146,10 @@ public class AudioDeviceInventory { }); checkDeviceInventorySize_l(); } if (syncInventory) { mDeviceBroker.postSynchronizeAdiDevicesInInventory(deviceState); } } /** * Adds a new entry in mDeviceInventory if the attributes passed represent a sink Loading Loading @@ -196,7 +199,8 @@ public class AudioDeviceInventory { * AdiDeviceState in the {@link AudioDeviceInventory#mDeviceInventory} list. * @param deviceState the device to update */ void addOrUpdateAudioDeviceCategoryInInventory(AdiDeviceState deviceState) { void addOrUpdateAudioDeviceCategoryInInventory( AdiDeviceState deviceState, boolean syncInventory) { AtomicBoolean updatedCategory = new AtomicBoolean(false); synchronized (mDeviceInventoryLock) { if (automaticBtDeviceType()) { Loading @@ -218,8 +222,10 @@ public class AudioDeviceInventory { if (updatedCategory.get()) { mDeviceBroker.postUpdatedAdiDeviceState(deviceState, false /*initSA*/); } if (syncInventory) { mDeviceBroker.postSynchronizeAdiDevicesInInventory(deviceState); } } void addAudioDeviceWithCategoryInInventoryIfNeeded(@NonNull String address, @AudioDeviceCategory int btAudioDeviceCategory) { Loading @@ -235,14 +241,14 @@ public class AudioDeviceInventory { boolean bleCategoryFound = false; AdiDeviceState deviceState = findBtDeviceStateForAddress(address, DEVICE_OUT_BLE_HEADSET); if (deviceState != null) { addOrUpdateAudioDeviceCategoryInInventory(deviceState); addOrUpdateAudioDeviceCategoryInInventory(deviceState, true /*syncInventory*/); btCategory = deviceState.getAudioDeviceCategory(); bleCategoryFound = true; } deviceState = findBtDeviceStateForAddress(address, DEVICE_OUT_BLUETOOTH_A2DP); if (deviceState != null) { addOrUpdateAudioDeviceCategoryInInventory(deviceState); addOrUpdateAudioDeviceCategoryInInventory(deviceState, true /*syncInventory*/); int a2dpCategory = deviceState.getAudioDeviceCategory(); if (bleCategoryFound && a2dpCategory != btCategory) { Log.w(TAG, "Found different audio device category for A2DP and BLE profiles with " Loading @@ -269,11 +275,33 @@ public class AudioDeviceInventory { } /** * synchronize AdiDeviceState for LE devices in the same group * Synchronize AdiDeviceState for LE devices in the same group * or BT classic devices with the same address. * @param updatedDevice the device state to synchronize or null. * Called with null once after the device inventory and spatializer helper * have been initialized to resync all devices. */ void onSynchronizeAdiDevicesInInventory(AdiDeviceState updatedDevice) { synchronized (mDevicesLock) { synchronized (mDeviceInventoryLock) { if (updatedDevice != null) { onSynchronizeAdiDeviceInInventory_l(updatedDevice); } else { for (AdiDeviceState ads : mDeviceInventory.values()) { onSynchronizeAdiDeviceInInventory_l(ads); } } } } } /** * Synchronize AdiDeviceState for LE devices in the same group * or BT classic devices with the same address. * @param updatedDevice the device state to synchronize. */ @GuardedBy({"mDevicesLock", "mDeviceInventoryLock"}) void onSynchronizeAdiDeviceInInventory_l(AdiDeviceState updatedDevice) { boolean found = false; found |= synchronizeBleDeviceInInventory(updatedDevice); if (automaticBtDeviceType()) { Loading @@ -283,8 +311,6 @@ public class AudioDeviceInventory { mDeviceBroker.postPersistAudioDeviceSettings(); } } } } @GuardedBy("mDeviceInventoryLock") private void checkDeviceInventorySize_l() { Loading Loading @@ -595,6 +621,9 @@ public class AudioDeviceInventory { mDeviceName = TextUtils.emptyIfNull(deviceName); mDeviceAddress = TextUtils.emptyIfNull(address); mDeviceIdentityAddress = TextUtils.emptyIfNull(identityAddress); if (mDeviceIdentityAddress.isEmpty()) { mDeviceIdentityAddress = mDeviceAddress; } mDeviceCodecFormat = codecFormat; mGroupId = groupId; mPeerDeviceAddress = TextUtils.emptyIfNull(peerAddress); Loading Loading @@ -2951,8 +2980,8 @@ public class AudioDeviceInventory { // Note if the device is not compatible with spatialization mode or the device // type is not canonical, it will be ignored in {@link SpatializerHelper}. if (devState != null) { addOrUpdateDeviceSAStateInInventory(devState); addOrUpdateAudioDeviceCategoryInInventory(devState); addOrUpdateDeviceSAStateInInventory(devState, false /*syncInventory*/); addOrUpdateAudioDeviceCategoryInInventory(devState, false /*syncInventory*/); } } } Loading services/core/java/com/android/server/audio/AudioService.java +5 −1 Original line number Diff line number Diff line Loading @@ -9639,6 +9639,9 @@ public class AudioService extends IAudioService.Stub case MSG_INIT_SPATIALIZER: onInitSpatializer(); // the device inventory can only be synchronized after the // spatializer has been initialized mDeviceBroker.postSynchronizeAdiDevicesInInventory(null); mAudioEventWakeLock.release(); break; Loading Loading @@ -11394,7 +11397,8 @@ public class AudioService extends IAudioService.Stub deviceState.setAudioDeviceCategory(btAudioDeviceCategory); mDeviceBroker.addOrUpdateBtAudioDeviceCategoryInInventory(deviceState); mDeviceBroker.addOrUpdateBtAudioDeviceCategoryInInventory( deviceState, true /*syncInventory*/); mDeviceBroker.postPersistAudioDeviceSettings(); mSpatializerHelper.refreshDevice(deviceState.getAudioDeviceAttributes(), Loading services/core/java/com/android/server/audio/SpatializerHelper.java +3 −2 Original line number Diff line number Diff line Loading @@ -568,7 +568,8 @@ public class SpatializerHelper { updatedDevice = new AdiDeviceState(canonicalDeviceType, ada.getInternalType(), ada.getAddress()); initSAState(updatedDevice); mDeviceBroker.addOrUpdateDeviceSAStateInInventory(updatedDevice); mDeviceBroker.addOrUpdateDeviceSAStateInInventory( updatedDevice, true /*syncInventory*/); } if (updatedDevice != null) { onRoutingUpdated(); Loading Loading @@ -723,7 +724,7 @@ public class SpatializerHelper { new AdiDeviceState(canonicalDeviceType, ada.getInternalType(), ada.getAddress()); initSAState(deviceState); mDeviceBroker.addOrUpdateDeviceSAStateInInventory(deviceState); mDeviceBroker.addOrUpdateDeviceSAStateInInventory(deviceState, true /*syncInventory*/); mDeviceBroker.postPersistAudioDeviceSettings(); logDeviceState(deviceState, "addWirelessDeviceIfNew"); // may be updated later. } Loading Loading
services/core/java/com/android/server/audio/AudioDeviceBroker.java +5 −4 Original line number Diff line number Diff line Loading @@ -2793,12 +2793,13 @@ public class AudioDeviceBroker { return mDeviceInventory.getImmutableDeviceInventory(); } void addOrUpdateDeviceSAStateInInventory(AdiDeviceState deviceState) { mDeviceInventory.addOrUpdateDeviceSAStateInInventory(deviceState); void addOrUpdateDeviceSAStateInInventory(AdiDeviceState deviceState, boolean syncInventory) { mDeviceInventory.addOrUpdateDeviceSAStateInInventory(deviceState, syncInventory); } void addOrUpdateBtAudioDeviceCategoryInInventory(AdiDeviceState deviceState) { mDeviceInventory.addOrUpdateAudioDeviceCategoryInInventory(deviceState); void addOrUpdateBtAudioDeviceCategoryInInventory( AdiDeviceState deviceState, boolean syncInventory) { mDeviceInventory.addOrUpdateAudioDeviceCategoryInInventory(deviceState, syncInventory); } @Nullable Loading
services/core/java/com/android/server/audio/AudioDeviceInventory.java +46 −17 Original line number Diff line number Diff line Loading @@ -135,9 +135,10 @@ public class AudioDeviceInventory { * AdiDeviceState in the {@link AudioDeviceInventory#mDeviceInventory} list. * @param deviceState the device to update */ void addOrUpdateDeviceSAStateInInventory(AdiDeviceState deviceState) { void addOrUpdateDeviceSAStateInInventory(AdiDeviceState deviceState, boolean syncInventory) { synchronized (mDeviceInventoryLock) { mDeviceInventory.merge(deviceState.getDeviceId(), deviceState, (oldState, newState) -> { mDeviceInventory.merge(deviceState.getDeviceId(), deviceState, (oldState, newState) -> { oldState.setHasHeadTracker(newState.hasHeadTracker()); oldState.setHeadTrackerEnabled(newState.isHeadTrackerEnabled()); oldState.setSAEnabled(newState.isSAEnabled()); Loading @@ -145,8 +146,10 @@ public class AudioDeviceInventory { }); checkDeviceInventorySize_l(); } if (syncInventory) { mDeviceBroker.postSynchronizeAdiDevicesInInventory(deviceState); } } /** * Adds a new entry in mDeviceInventory if the attributes passed represent a sink Loading Loading @@ -196,7 +199,8 @@ public class AudioDeviceInventory { * AdiDeviceState in the {@link AudioDeviceInventory#mDeviceInventory} list. * @param deviceState the device to update */ void addOrUpdateAudioDeviceCategoryInInventory(AdiDeviceState deviceState) { void addOrUpdateAudioDeviceCategoryInInventory( AdiDeviceState deviceState, boolean syncInventory) { AtomicBoolean updatedCategory = new AtomicBoolean(false); synchronized (mDeviceInventoryLock) { if (automaticBtDeviceType()) { Loading @@ -218,8 +222,10 @@ public class AudioDeviceInventory { if (updatedCategory.get()) { mDeviceBroker.postUpdatedAdiDeviceState(deviceState, false /*initSA*/); } if (syncInventory) { mDeviceBroker.postSynchronizeAdiDevicesInInventory(deviceState); } } void addAudioDeviceWithCategoryInInventoryIfNeeded(@NonNull String address, @AudioDeviceCategory int btAudioDeviceCategory) { Loading @@ -235,14 +241,14 @@ public class AudioDeviceInventory { boolean bleCategoryFound = false; AdiDeviceState deviceState = findBtDeviceStateForAddress(address, DEVICE_OUT_BLE_HEADSET); if (deviceState != null) { addOrUpdateAudioDeviceCategoryInInventory(deviceState); addOrUpdateAudioDeviceCategoryInInventory(deviceState, true /*syncInventory*/); btCategory = deviceState.getAudioDeviceCategory(); bleCategoryFound = true; } deviceState = findBtDeviceStateForAddress(address, DEVICE_OUT_BLUETOOTH_A2DP); if (deviceState != null) { addOrUpdateAudioDeviceCategoryInInventory(deviceState); addOrUpdateAudioDeviceCategoryInInventory(deviceState, true /*syncInventory*/); int a2dpCategory = deviceState.getAudioDeviceCategory(); if (bleCategoryFound && a2dpCategory != btCategory) { Log.w(TAG, "Found different audio device category for A2DP and BLE profiles with " Loading @@ -269,11 +275,33 @@ public class AudioDeviceInventory { } /** * synchronize AdiDeviceState for LE devices in the same group * Synchronize AdiDeviceState for LE devices in the same group * or BT classic devices with the same address. * @param updatedDevice the device state to synchronize or null. * Called with null once after the device inventory and spatializer helper * have been initialized to resync all devices. */ void onSynchronizeAdiDevicesInInventory(AdiDeviceState updatedDevice) { synchronized (mDevicesLock) { synchronized (mDeviceInventoryLock) { if (updatedDevice != null) { onSynchronizeAdiDeviceInInventory_l(updatedDevice); } else { for (AdiDeviceState ads : mDeviceInventory.values()) { onSynchronizeAdiDeviceInInventory_l(ads); } } } } } /** * Synchronize AdiDeviceState for LE devices in the same group * or BT classic devices with the same address. * @param updatedDevice the device state to synchronize. */ @GuardedBy({"mDevicesLock", "mDeviceInventoryLock"}) void onSynchronizeAdiDeviceInInventory_l(AdiDeviceState updatedDevice) { boolean found = false; found |= synchronizeBleDeviceInInventory(updatedDevice); if (automaticBtDeviceType()) { Loading @@ -283,8 +311,6 @@ public class AudioDeviceInventory { mDeviceBroker.postPersistAudioDeviceSettings(); } } } } @GuardedBy("mDeviceInventoryLock") private void checkDeviceInventorySize_l() { Loading Loading @@ -595,6 +621,9 @@ public class AudioDeviceInventory { mDeviceName = TextUtils.emptyIfNull(deviceName); mDeviceAddress = TextUtils.emptyIfNull(address); mDeviceIdentityAddress = TextUtils.emptyIfNull(identityAddress); if (mDeviceIdentityAddress.isEmpty()) { mDeviceIdentityAddress = mDeviceAddress; } mDeviceCodecFormat = codecFormat; mGroupId = groupId; mPeerDeviceAddress = TextUtils.emptyIfNull(peerAddress); Loading Loading @@ -2951,8 +2980,8 @@ public class AudioDeviceInventory { // Note if the device is not compatible with spatialization mode or the device // type is not canonical, it will be ignored in {@link SpatializerHelper}. if (devState != null) { addOrUpdateDeviceSAStateInInventory(devState); addOrUpdateAudioDeviceCategoryInInventory(devState); addOrUpdateDeviceSAStateInInventory(devState, false /*syncInventory*/); addOrUpdateAudioDeviceCategoryInInventory(devState, false /*syncInventory*/); } } } Loading
services/core/java/com/android/server/audio/AudioService.java +5 −1 Original line number Diff line number Diff line Loading @@ -9639,6 +9639,9 @@ public class AudioService extends IAudioService.Stub case MSG_INIT_SPATIALIZER: onInitSpatializer(); // the device inventory can only be synchronized after the // spatializer has been initialized mDeviceBroker.postSynchronizeAdiDevicesInInventory(null); mAudioEventWakeLock.release(); break; Loading Loading @@ -11394,7 +11397,8 @@ public class AudioService extends IAudioService.Stub deviceState.setAudioDeviceCategory(btAudioDeviceCategory); mDeviceBroker.addOrUpdateBtAudioDeviceCategoryInInventory(deviceState); mDeviceBroker.addOrUpdateBtAudioDeviceCategoryInInventory( deviceState, true /*syncInventory*/); mDeviceBroker.postPersistAudioDeviceSettings(); mSpatializerHelper.refreshDevice(deviceState.getAudioDeviceAttributes(), Loading
services/core/java/com/android/server/audio/SpatializerHelper.java +3 −2 Original line number Diff line number Diff line Loading @@ -568,7 +568,8 @@ public class SpatializerHelper { updatedDevice = new AdiDeviceState(canonicalDeviceType, ada.getInternalType(), ada.getAddress()); initSAState(updatedDevice); mDeviceBroker.addOrUpdateDeviceSAStateInInventory(updatedDevice); mDeviceBroker.addOrUpdateDeviceSAStateInInventory( updatedDevice, true /*syncInventory*/); } if (updatedDevice != null) { onRoutingUpdated(); Loading Loading @@ -723,7 +724,7 @@ public class SpatializerHelper { new AdiDeviceState(canonicalDeviceType, ada.getInternalType(), ada.getAddress()); initSAState(deviceState); mDeviceBroker.addOrUpdateDeviceSAStateInInventory(deviceState); mDeviceBroker.addOrUpdateDeviceSAStateInInventory(deviceState, true /*syncInventory*/); mDeviceBroker.postPersistAudioDeviceSettings(); logDeviceState(deviceState, "addWirelessDeviceIfNew"); // may be updated later. } Loading