diff options
| author | 2023-08-25 19:59:22 +0200 | |
|---|---|---|
| committer | 2023-12-04 17:21:04 +0100 | |
| commit | 12bf321b2ae8630a5eef59635797df5aae370fa0 (patch) | |
| tree | ed16a674c255ffe0e4ab1819eb121f523ec3f828 | |
| parent | 8bc28f86428afdf68ffbd56557aa15bfc0c39bc6 (diff) | |
AudioDeviceInventory: improve log for device connection.
Indicate if a device is a source or sink device in the connection or
disconnection events logged in audio dumpsys. Some BT profiles like LE
Audio or HFP where not clearly indicating the nature of the device.
Test: make
Change-Id: I09e2bf19740750e43cfd249ac5f9225268e0fb3c
6 files changed, 20 insertions, 8 deletions
diff --git a/media/java/android/media/AudioDeviceAttributes.java b/media/java/android/media/AudioDeviceAttributes.java index 2b349d498d59..0bc505d3efeb 100644 --- a/media/java/android/media/AudioDeviceAttributes.java +++ b/media/java/android/media/AudioDeviceAttributes.java @@ -177,7 +177,7 @@ public final class AudioDeviceAttributes implements Parcelable { * @param name the name of the device, or an empty string for devices without one */ public AudioDeviceAttributes(int nativeType, @NonNull String address, @NonNull String name) { - mRole = (nativeType & AudioSystem.DEVICE_BIT_IN) != 0 ? ROLE_INPUT : ROLE_OUTPUT; + mRole = AudioSystem.isInputDevice(nativeType) ? ROLE_INPUT : ROLE_OUTPUT; mType = AudioDeviceInfo.convertInternalDeviceToDeviceType(nativeType); mAddress = address; mName = name; diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java index 1e3234902a45..8536e2316006 100644 --- a/media/java/android/media/AudioManager.java +++ b/media/java/android/media/AudioManager.java @@ -6133,7 +6133,7 @@ public class AudioManager { */ public static boolean isOutputDevice(int device) { - return (device & AudioSystem.DEVICE_BIT_IN) == 0; + return !AudioSystem.isInputDevice(device); } /** @@ -6142,7 +6142,7 @@ public class AudioManager { */ public static boolean isInputDevice(int device) { - return (device & AudioSystem.DEVICE_BIT_IN) == AudioSystem.DEVICE_BIT_IN; + return AudioSystem.isInputDevice(device); } diff --git a/media/java/android/media/AudioSystem.java b/media/java/android/media/AudioSystem.java index 9ffd644493db..46a0b9934376 100644 --- a/media/java/android/media/AudioSystem.java +++ b/media/java/android/media/AudioSystem.java @@ -1305,6 +1305,11 @@ public class AudioSystem } /** @hide */ + public static boolean isInputDevice(int deviceType) { + return (deviceType & DEVICE_BIT_IN) == DEVICE_BIT_IN; + } + + /** @hide */ public static boolean isBluetoothDevice(int deviceType) { return isBluetoothA2dpOutDevice(deviceType) || isBluetoothScoDevice(deviceType) @@ -1602,7 +1607,7 @@ public class AudioSystem * @return a string describing the device type */ public static @NonNull String getDeviceName(int device) { - if ((device & DEVICE_BIT_IN) != 0) { + if (isInputDevice(device)) { return getInputDeviceName(device); } return getOutputDeviceName(device); diff --git a/services/core/java/com/android/server/audio/AudioDeviceInventory.java b/services/core/java/com/android/server/audio/AudioDeviceInventory.java index e503f1f2c8c2..3915fc692c8e 100644 --- a/services/core/java/com/android/server/audio/AudioDeviceInventory.java +++ b/services/core/java/com/android/server/audio/AudioDeviceInventory.java @@ -1549,6 +1549,10 @@ public class AudioDeviceInventory { } else { addAudioDeviceInInventoryIfNeeded(device, address, ""); } + AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent( + "SCO " + (AudioSystem.isInputDevice(device) ? "source" : "sink") + + " device addr=" + address + + (connect ? " now available" : " made unavailable")).printLog(TAG)); } mmi.set(MediaMetrics.Property.STATE, MediaMetrics.Value.CONNECTED).record(); } else { @@ -1810,7 +1814,7 @@ public class AudioDeviceInventory { // TODO: return; } else { AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent( - "A2DP device addr=" + Utils.anonymizeBluetoothAddress(address) + "A2DP source device addr=" + Utils.anonymizeBluetoothAddress(address) + " now available").printLog(TAG)); } @@ -2264,7 +2268,8 @@ public class AudioDeviceInventory { // TODO: return; } else { AudioService.sDeviceLogger.enqueue(new EventLogger.StringEvent( - "LE Audio device addr=" + Utils.anonymizeBluetoothAddress(address) + "LE Audio " + (AudioSystem.isInputDevice(device) ? "source" : "sink") + + " device addr=" + Utils.anonymizeBluetoothAddress(address) + " now available").printLog(TAG)); } // Reset LEA suspend state each time a new sink is connected @@ -2403,7 +2408,7 @@ public class AudioDeviceInventory { int delay = 0; Set<Integer> devices = new HashSet<>(); for (DeviceInfo di : mConnectedDevices.values()) { - if (((di.mDeviceType & AudioSystem.DEVICE_BIT_IN) == 0) + if (!AudioSystem.isInputDevice(di.mDeviceType) && BECOMING_NOISY_INTENT_DEVICES_SET.contains(di.mDeviceType)) { devices.add(di.mDeviceType); Log.i(TAG, "NOISY: adding 0x" + Integer.toHexString(di.mDeviceType)); diff --git a/services/core/java/com/android/server/audio/AudioServiceEvents.java b/services/core/java/com/android/server/audio/AudioServiceEvents.java index de8901179028..3417f6501459 100644 --- a/services/core/java/com/android/server/audio/AudioServiceEvents.java +++ b/services/core/java/com/android/server/audio/AudioServiceEvents.java @@ -120,6 +120,8 @@ public class AudioServiceEvents { return new StringBuilder("setWiredDeviceConnectionState(") .append(" type:").append( Integer.toHexString(mState.mAttributes.getInternalType())) + .append(" (").append(AudioSystem.isInputDevice( + mState.mAttributes.getInternalType()) ? "source" : "sink").append(") ") .append(" state:").append(AudioSystem.deviceStateToString(mState.mState)) .append(" addr:").append(mState.mAttributes.getAddress()) .append(" name:").append(mState.mAttributes.getName()) diff --git a/services/core/java/com/android/server/tv/TvInputHardwareManager.java b/services/core/java/com/android/server/tv/TvInputHardwareManager.java index 06a851637b82..58acbe08acf1 100755 --- a/services/core/java/com/android/server/tv/TvInputHardwareManager.java +++ b/services/core/java/com/android/server/tv/TvInputHardwareManager.java @@ -943,7 +943,7 @@ class TvInputHardwareManager implements TvInputHal.Callback { int sinkDevice = mAudioManager.getDevicesForStream(AudioManager.STREAM_MUSIC); for (AudioDevicePort port : devicePorts) { if ((port.type() & sinkDevice) != 0 && - (port.type() & AudioSystem.DEVICE_BIT_IN) == 0) { + !AudioSystem.isInputDevice(port.type())) { sinks.add(port); } } |