From fbaee6c0889702e5df4a9589d9689511cf088423 Mon Sep 17 00:00:00 2001 From: jiabin Date: Thu, 16 Mar 2023 20:46:29 +0000 Subject: [PATCH] AS: only dispatch preferred mixer attributes change if the device is found. When device is disconnected, only dispatch preferred mixer attributes change if the device is found. When setting the device as connected, it may not be cached by audio policy manager if there is any lower layer issue happens while connecting the device. In that case, it may fail to get AudioDeviceInfo for the disconnected device. To avoid crash, AudioService should only notify preferred mixer attributes changed when the disconnected device is found. Bug: 273894204 Test: connect and disconnect USB devices Change-Id: I4da7f7cc11336ea40f4f5dc0e042d781b1063733 --- .../com/android/server/audio/AudioDeviceInventory.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/audio/AudioDeviceInventory.java b/services/core/java/com/android/server/audio/AudioDeviceInventory.java index aae1d3884344f..6758581d1fc0e 100644 --- a/services/core/java/com/android/server/audio/AudioDeviceInventory.java +++ b/services/core/java/com/android/server/audio/AudioDeviceInventory.java @@ -597,7 +597,13 @@ public class AudioDeviceInventory { if (wdcs.mState == AudioService.CONNECTION_STATE_DISCONNECTED && AudioSystem.DEVICE_OUT_ALL_USB_SET.contains( wdcs.mAttributes.getInternalType())) { - mDeviceBroker.dispatchPreferredMixerAttributesChangedCausedByDeviceRemoved(info); + if (info != null) { + mDeviceBroker.dispatchPreferredMixerAttributesChangedCausedByDeviceRemoved( + info); + } else { + Log.e(TAG, "Didn't find AudioDeviceInfo to notify preferred mixer " + + "attributes change for type=" + wdcs.mAttributes.getType()); + } } sendDeviceConnectionIntent(type, wdcs.mState, wdcs.mAttributes.getAddress(), wdcs.mAttributes.getName());