Skip to content

Commit 9841818

Browse files
author
Mike Lockwood
committed
AudioService: Fix problem handling USB audio disconnect
Also broadcast ACTION_AUDIO_BECOMING_NOISY on USB audio disconnect Change-Id: I46dfcc744df880066aea6bf651334a081c14af0f Signed-off-by: Mike Lockwood <lockwood@google.com>
1 parent bf91046 commit 9841818

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

media/java/android/media/AudioService.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2887,10 +2887,13 @@ private void makeA2dpDeviceAvailable(String address) {
28872887
address);
28882888
}
28892889

2890+
private void sendBecomingNoisyIntent() {
2891+
mContext.sendBroadcast(new Intent(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
2892+
}
2893+
28902894
// must be called synchronized on mConnectedDevices
28912895
private void makeA2dpDeviceUnavailableNow(String address) {
2892-
Intent noisyIntent = new Intent(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
2893-
mContext.sendBroadcast(noisyIntent);
2896+
sendBecomingNoisyIntent();
28942897
AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,
28952898
AudioSystem.DEVICE_STATE_UNAVAILABLE,
28962899
address);
@@ -2967,12 +2970,12 @@ private void handleA2dpConnectionStateChange(BluetoothDevice btDevice, int state
29672970
private boolean handleDeviceConnection(boolean connected, int device, String params) {
29682971
synchronized (mConnectedDevices) {
29692972
boolean isConnected = (mConnectedDevices.containsKey(device) &&
2970-
mConnectedDevices.get(device).equals(params));
2973+
(params.isEmpty() || mConnectedDevices.get(device).equals(params)));
29712974

29722975
if (isConnected && !connected) {
29732976
AudioSystem.setDeviceConnectionState(device,
29742977
AudioSystem.DEVICE_STATE_UNAVAILABLE,
2975-
params);
2978+
mConnectedDevices.get(device));
29762979
mConnectedDevices.remove(device);
29772980
return true;
29782981
} else if (!isConnected && connected) {
@@ -3093,9 +3096,13 @@ public void onReceive(Context context, Intent intent) {
30933096
} else if (action.equals(Intent.ACTION_USB_AUDIO_ACCESSORY_PLUG) ||
30943097
action.equals(Intent.ACTION_USB_AUDIO_DEVICE_PLUG)) {
30953098
state = intent.getIntExtra("state", 0);
3099+
if (state == 0) {
3100+
sendBecomingNoisyIntent();
3101+
}
30963102
int alsaCard = intent.getIntExtra("card", -1);
30973103
int alsaDevice = intent.getIntExtra("device", -1);
3098-
String params = "card=" + alsaCard + ";device=" + alsaDevice;
3104+
String params = (alsaCard == -1 && alsaDevice == -1 ? ""
3105+
: "card=" + alsaCard + ";device=" + alsaDevice);
30993106
device = action.equals(Intent.ACTION_USB_AUDIO_ACCESSORY_PLUG) ?
31003107
AudioSystem.DEVICE_OUT_USB_ACCESSORY : AudioSystem.DEVICE_OUT_USB_DEVICE;
31013108
Log.v(TAG, "Broadcast Receiver: Got "

0 commit comments

Comments
 (0)