OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 package org.appspot.apprtc; | 11 package org.appspot.apprtc; |
12 | 12 |
13 import org.appspot.apprtc.util.AppRTCUtils; | 13 import org.appspot.apprtc.util.AppRTCUtils; |
14 | 14 |
15 import android.content.BroadcastReceiver; | 15 import android.content.BroadcastReceiver; |
16 import android.content.Context; | 16 import android.content.Context; |
17 import android.content.Intent; | 17 import android.content.Intent; |
18 import android.content.IntentFilter; | 18 import android.content.IntentFilter; |
19 import android.content.SharedPreferences; | 19 import android.content.SharedPreferences; |
20 import android.content.pm.PackageManager; | 20 import android.content.pm.PackageManager; |
| 21 import android.media.AudioDeviceInfo; |
21 import android.media.AudioManager; | 22 import android.media.AudioManager; |
| 23 import android.os.Build; |
22 import android.preference.PreferenceManager; | 24 import android.preference.PreferenceManager; |
23 import android.util.Log; | 25 import android.util.Log; |
24 | 26 |
25 import org.webrtc.ThreadUtils; | 27 import org.webrtc.ThreadUtils; |
26 | 28 |
27 import java.util.Collections; | 29 import java.util.Collections; |
28 import java.util.HashSet; | 30 import java.util.HashSet; |
29 import java.util.List; | 31 import java.util.List; |
30 import java.util.Set; | 32 import java.util.Set; |
31 | 33 |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 | 432 |
431 /** | 433 /** |
432 * Checks whether a wired headset is connected or not. | 434 * Checks whether a wired headset is connected or not. |
433 * This is not a valid indication that audio playback is actually over | 435 * This is not a valid indication that audio playback is actually over |
434 * the wired headset as audio routing depends on other conditions. We | 436 * the wired headset as audio routing depends on other conditions. We |
435 * only use it as an early indicator (during initialization) of an attached | 437 * only use it as an early indicator (during initialization) of an attached |
436 * wired headset. | 438 * wired headset. |
437 */ | 439 */ |
438 @Deprecated | 440 @Deprecated |
439 private boolean hasWiredHeadset() { | 441 private boolean hasWiredHeadset() { |
440 return audioManager.isWiredHeadsetOn(); | 442 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { |
| 443 return audioManager.isWiredHeadsetOn(); |
| 444 } else { |
| 445 final AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET
_DEVICES_ALL); |
| 446 for (AudioDeviceInfo device : devices) { |
| 447 final int type = device.getType(); |
| 448 if (type == AudioDeviceInfo.TYPE_WIRED_HEADSET) { |
| 449 Log.d(TAG, "hasWiredHeadset: found wired headset"); |
| 450 return true; |
| 451 } else if (type == AudioDeviceInfo.TYPE_USB_DEVICE) { |
| 452 Log.d(TAG, "hasWiredHeadset: found USB audio device"); |
| 453 return true; |
| 454 } else if (type == AudioDeviceInfo.TYPE_USB_HEADSET) { |
| 455 Log.d(TAG, "hasWiredHeadset: found USB headset"); |
| 456 return true; |
| 457 } |
| 458 } |
| 459 return false; |
| 460 } |
441 } | 461 } |
442 | 462 |
443 /** | 463 /** |
444 * Updates list of possible audio devices and make new device selection. | 464 * Updates list of possible audio devices and make new device selection. |
445 * TODO(henrika): add unit test to verify all state transitions. | 465 * TODO(henrika): add unit test to verify all state transitions. |
446 */ | 466 */ |
447 public void updateAudioDeviceState() { | 467 public void updateAudioDeviceState() { |
448 ThreadUtils.checkIsOnMainThread(); | 468 ThreadUtils.checkIsOnMainThread(); |
449 Log.d(TAG, "--- updateAudioDeviceState: " | 469 Log.d(TAG, "--- updateAudioDeviceState: " |
450 + "wired headset=" + hasWiredHeadset + ", " | 470 + "wired headset=" + hasWiredHeadset + ", " |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 + "available=" + audioDevices + ", " | 589 + "available=" + audioDevices + ", " |
570 + "selected=" + newAudioDevice); | 590 + "selected=" + newAudioDevice); |
571 if (audioManagerEvents != null) { | 591 if (audioManagerEvents != null) { |
572 // Notify a listening client that audio device has been changed. | 592 // Notify a listening client that audio device has been changed. |
573 audioManagerEvents.onAudioDeviceChanged(selectedAudioDevice, audioDevice
s); | 593 audioManagerEvents.onAudioDeviceChanged(selectedAudioDevice, audioDevice
s); |
574 } | 594 } |
575 } | 595 } |
576 Log.d(TAG, "--- updateAudioDeviceState done"); | 596 Log.d(TAG, "--- updateAudioDeviceState done"); |
577 } | 597 } |
578 } | 598 } |
OLD | NEW |