Skip to content

Commit 8d8176d

Browse files
Mike LockwoodAndroid (Google) Code Review
authored andcommitted
Merge "AudioService: Fix problem handling USB audio disconnect" into jb-dev
2 parents 304521b + 9841818 commit 8d8176d

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
@@ -2979,10 +2979,13 @@ private void makeA2dpDeviceAvailable(String address) {
29792979
address);
29802980
}
29812981

2982+
private void sendBecomingNoisyIntent() {
2983+
mContext.sendBroadcast(new Intent(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
2984+
}
2985+
29822986
// must be called synchronized on mConnectedDevices
29832987
private void makeA2dpDeviceUnavailableNow(String address) {
2984-
Intent noisyIntent = new Intent(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
2985-
mContext.sendBroadcast(noisyIntent);
2988+
sendBecomingNoisyIntent();
29862989
AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP,
29872990
AudioSystem.DEVICE_STATE_UNAVAILABLE,
29882991
address);
@@ -3059,12 +3062,12 @@ private void handleA2dpConnectionStateChange(BluetoothDevice btDevice, int state
30593062
private boolean handleDeviceConnection(boolean connected, int device, String params) {
30603063
synchronized (mConnectedDevices) {
30613064
boolean isConnected = (mConnectedDevices.containsKey(device) &&
3062-
mConnectedDevices.get(device).equals(params));
3065+
(params.isEmpty() || mConnectedDevices.get(device).equals(params)));
30633066

30643067
if (isConnected && !connected) {
30653068
AudioSystem.setDeviceConnectionState(device,
30663069
AudioSystem.DEVICE_STATE_UNAVAILABLE,
3067-
params);
3070+
mConnectedDevices.get(device));
30683071
mConnectedDevices.remove(device);
30693072
return true;
30703073
} else if (!isConnected && connected) {
@@ -3185,9 +3188,13 @@ public void onReceive(Context context, Intent intent) {
31853188
} else if (action.equals(Intent.ACTION_USB_AUDIO_ACCESSORY_PLUG) ||
31863189
action.equals(Intent.ACTION_USB_AUDIO_DEVICE_PLUG)) {
31873190
state = intent.getIntExtra("state", 0);
3191+
if (state == 0) {
3192+
sendBecomingNoisyIntent();
3193+
}
31883194
int alsaCard = intent.getIntExtra("card", -1);
31893195
int alsaDevice = intent.getIntExtra("device", -1);
3190-
String params = "card=" + alsaCard + ";device=" + alsaDevice;
3196+
String params = (alsaCard == -1 && alsaDevice == -1 ? ""
3197+
: "card=" + alsaCard + ";device=" + alsaDevice);
31913198
device = action.equals(Intent.ACTION_USB_AUDIO_ACCESSORY_PLUG) ?
31923199
AudioSystem.DEVICE_OUT_USB_ACCESSORY : AudioSystem.DEVICE_OUT_USB_DEVICE;
31933200
Log.v(TAG, "Broadcast Receiver: Got "

0 commit comments

Comments
 (0)