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-Original-Commit-Position: refs/heads/master@{#18889}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: 8eadead3f42f4cf8a1265bb31ec74114a58662aa
diff --git a/examples/androidapp/src/org/appspot/apprtc/AppRTCAudioManager.java b/examples/androidapp/src/org/appspot/apprtc/AppRTCAudioManager.java
index a57e84f..992d918 100644
--- a/examples/androidapp/src/org/appspot/apprtc/AppRTCAudioManager.java
+++ b/examples/androidapp/src/org/appspot/apprtc/AppRTCAudioManager.java
@@ -18,7 +18,9 @@
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 @@
*/
@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;
+ }
}
/**