From 9fa656d0f60dd0baf4b0bbd600ffb52c47a7ff28 Mon Sep 17 00:00:00 2001 From: Phil Burk Date: Tue, 6 Aug 2024 17:41:46 -0700 Subject: [PATCH] OboeTester Data Paths handle mix of USB types (#2083) Handle any combination of USB Headset or Device. Find compatible device type in preferred order. --- .../oboetester/BaseAutoGlitchActivity.java | 20 +++++++++++++++---- .../oboetester/TestDataPathsActivity.java | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/apps/OboeTester/app/src/main/java/com/mobileer/oboetester/BaseAutoGlitchActivity.java b/apps/OboeTester/app/src/main/java/com/mobileer/oboetester/BaseAutoGlitchActivity.java index 46ec12a4e..3256fad55 100644 --- a/apps/OboeTester/app/src/main/java/com/mobileer/oboetester/BaseAutoGlitchActivity.java +++ b/apps/OboeTester/app/src/main/java/com/mobileer/oboetester/BaseAutoGlitchActivity.java @@ -455,6 +455,10 @@ protected boolean isDeviceTypeMixedForLoopback(int type) { } } + /** + * @param type + * @return list of compatible device types in preferred order + */ protected ArrayList getCompatibleDeviceTypes(int type) { ArrayList compatibleTypes = new ArrayList(); switch(type) { @@ -466,10 +470,15 @@ protected ArrayList getCompatibleDeviceTypes(int type) { compatibleTypes.add(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER); break; case AudioDeviceInfo.TYPE_USB_DEVICE: + // Give priority to an exact match of DEVICE. compatibleTypes.add(AudioDeviceInfo.TYPE_USB_DEVICE); - // A USB Device is often mistaken for a headset. compatibleTypes.add(AudioDeviceInfo.TYPE_USB_HEADSET); break; + case AudioDeviceInfo.TYPE_USB_HEADSET: + // Give priority to an exact match of HEADSET. + compatibleTypes.add(AudioDeviceInfo.TYPE_USB_HEADSET); + compatibleTypes.add(AudioDeviceInfo.TYPE_USB_DEVICE); + break; default: compatibleTypes.add(type); break; @@ -485,9 +494,12 @@ protected ArrayList getCompatibleDeviceTypes(int type) { protected AudioDeviceInfo findCompatibleInputDevice(int outputDeviceType) { ArrayList compatibleDeviceTypes = getCompatibleDeviceTypes(outputDeviceType); AudioDeviceInfo[] devices = mAudioManager.getDevices(AudioManager.GET_DEVICES_INPUTS); - for (AudioDeviceInfo candidate : devices) { - if (compatibleDeviceTypes.contains(candidate.getType())) { - return candidate; + // Scan the compatible types in order of preference. + for (int compatibleType : compatibleDeviceTypes) { + for (AudioDeviceInfo candidate : devices) { + if (candidate.getType() == compatibleType) { + return candidate; + } } } return null; diff --git a/apps/OboeTester/app/src/main/java/com/mobileer/oboetester/TestDataPathsActivity.java b/apps/OboeTester/app/src/main/java/com/mobileer/oboetester/TestDataPathsActivity.java index bc3ca6f7e..0b1eaab5d 100644 --- a/apps/OboeTester/app/src/main/java/com/mobileer/oboetester/TestDataPathsActivity.java +++ b/apps/OboeTester/app/src/main/java/com/mobileer/oboetester/TestDataPathsActivity.java @@ -676,7 +676,7 @@ private void showDeviceInfo(AudioDeviceInfo outputDeviceInfo, AudioDeviceInfo in setInstructionsText(deviceText); if (inputDeviceInfo == null) { - deviceText += "ERROR - cannot find compatible device type for input!"; + deviceText += "\nERROR - no compatible input device!"; } else { deviceText = "IN: type = " + AudioDeviceInfoConverter.typeToString(inputDeviceInfo.getType())