From 8eadead3f42f4cf8a1265bb31ec74114a58662aa Mon Sep 17 00:00:00 2001 From: henrika Date: Tue, 4 Jul 2017 05:10:48 -0700 Subject: [PATCH] Adds support for USB audio devices in AppRTCMobile on Android. This change extends the definition of wired headset to also include USB devices. The effect is that audio will now be routed to USB audio devices when used in combination with AppRTCMobile. BUG=webrtc:7931 Review-Url: https://codereview.webrtc.org/2971613003 Cr-Commit-Position: refs/heads/master@{#18889} --- .../appspot/apprtc/AppRTCAudioManager.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/webrtc/examples/androidapp/src/org/appspot/apprtc/AppRTCAudioManager.java b/webrtc/examples/androidapp/src/org/appspot/apprtc/AppRTCAudioManager.java index a57e84f8ca..992d9188ba 100644 --- a/webrtc/examples/androidapp/src/org/appspot/apprtc/AppRTCAudioManager.java +++ b/webrtc/examples/androidapp/src/org/appspot/apprtc/AppRTCAudioManager.java @@ -18,7 +18,9 @@ import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.media.AudioDeviceInfo; import android.media.AudioManager; +import android.os.Build; import android.preference.PreferenceManager; import android.util.Log; @@ -437,7 +439,25 @@ public class AppRTCAudioManager { */ @Deprecated private boolean hasWiredHeadset() { - return audioManager.isWiredHeadsetOn(); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { + return audioManager.isWiredHeadsetOn(); + } else { + final AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_ALL); + for (AudioDeviceInfo device : devices) { + final int type = device.getType(); + if (type == AudioDeviceInfo.TYPE_WIRED_HEADSET) { + Log.d(TAG, "hasWiredHeadset: found wired headset"); + return true; + } else if (type == AudioDeviceInfo.TYPE_USB_DEVICE) { + Log.d(TAG, "hasWiredHeadset: found USB audio device"); + return true; + } else if (type == AudioDeviceInfo.TYPE_USB_HEADSET) { + Log.d(TAG, "hasWiredHeadset: found USB headset"); + return true; + } + } + return false; + } } /**