diff options
author | Eric Laurent <elaurent@google.com> | 2009-10-08 10:58:19 -0700 |
---|---|---|
committer | Eric Laurent <elaurent@google.com> | 2009-10-08 12:03:51 -0700 |
commit | 80a6a229b33b0868944fe011af2d778e23c83322 (patch) | |
tree | b14ae7e641c595cd2e34e5e4daa63ed6d324f300 /core | |
parent | bd324c9bd32a3c86634c1cc1ab8525f46a56b694 (diff) | |
download | frameworks_base-80a6a229b33b0868944fe011af2d778e23c83322.zip frameworks_base-80a6a229b33b0868944fe011af2d778e23c83322.tar.gz frameworks_base-80a6a229b33b0868944fe011af2d778e23c83322.tar.bz2 |
Fix issue 2174002: After rejecting Call when device ringtone is mute and playing music, audio is not transfered to BT device.
Added a workarouond to request the A2DP output standby directly to audio hardware when the sink is suspended as it seems that the suspend request often fails.
Also take into account resume requests received while a suspend request is pending.
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/server/BluetoothA2dpService.java | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/core/java/android/server/BluetoothA2dpService.java b/core/java/android/server/BluetoothA2dpService.java index b73e53f..9a2d6d9 100644 --- a/core/java/android/server/BluetoothA2dpService.java +++ b/core/java/android/server/BluetoothA2dpService.java @@ -72,6 +72,8 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { private final AudioManager mAudioManager; private final BluetoothService mBluetoothService; private final BluetoothAdapter mAdapter; + private boolean mSuspending; + private boolean mResuming; private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override @@ -149,6 +151,8 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { if (mBluetoothService.isEnabled()) onBluetoothEnable(); + mSuspending = false; + mResuming = false; } @Override @@ -241,6 +245,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { } } mAudioManager.setParameters(BLUETOOTH_ENABLED+"=true"); + mAudioManager.setParameters("A2dpSuspended=false"); } private synchronized void onBluetoothDisable() { @@ -336,7 +341,10 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { public synchronized boolean suspendSink(BluetoothDevice device) { mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission"); - if (DBG) log("suspendSink(" + device + ")"); + if (DBG) log("suspendSink(" + device + "), mSuspending: "+mSuspending+", mResuming: "+mResuming); + if (mSuspending) { + return true; + } if (device == null || mAudioDevices == null) { return false; } @@ -347,9 +355,14 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { } switch (state.intValue()) { case BluetoothA2dp.STATE_CONNECTED: + if (mResuming) { + mSuspending = true; + } return true; case BluetoothA2dp.STATE_PLAYING: - return suspendSinkNative(path); + mAudioManager.setParameters("A2dpSuspended=true"); + mSuspending = suspendSinkNative(path); + return mSuspending; default: return false; } @@ -358,7 +371,10 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { public synchronized boolean resumeSink(BluetoothDevice device) { mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM, "Need BLUETOOTH_ADMIN permission"); - if (DBG) log("resumeSink(" + device + ")"); + if (DBG) log("resumeSink(" + device + "), mResuming: "+mResuming+", mSuspending: "+mSuspending); + if (mResuming) { + return true; + } if (device == null || mAudioDevices == null) { return false; } @@ -369,9 +385,14 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { } switch (state.intValue()) { case BluetoothA2dp.STATE_PLAYING: + if (mSuspending) { + mResuming = true; + } return true; case BluetoothA2dp.STATE_CONNECTED: - return resumeSinkNative(path); + mResuming = resumeSinkNative(path); + mAudioManager.setParameters("A2dpSuspended=false"); + return mResuming; default: return false; } @@ -437,6 +458,10 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { } private void handleSinkStateChange(BluetoothDevice device, int prevState, int state) { + if (state == BluetoothA2dp.STATE_DISCONNECTED) { + mSuspending = false; + mResuming = false; + } if (state != prevState) { if (state == BluetoothA2dp.STATE_DISCONNECTED || state == BluetoothA2dp.STATE_DISCONNECTING) { @@ -452,6 +477,29 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { } mAudioDevices.put(device, state); + if (state == BluetoothA2dp.STATE_CONNECTED && prevState == BluetoothA2dp.STATE_PLAYING) { + if (DBG) log("handleSinkStateChange() STATE_PLAYING -> STATE_CONNECTED: mSuspending: " + +mSuspending+", mResuming: "+mResuming); + if (mSuspending) { + mSuspending = false; + if (mResuming) { + mResuming = false; + resumeSink(device); + } + } + } + if (state == BluetoothA2dp.STATE_PLAYING && prevState == BluetoothA2dp.STATE_CONNECTED) { + if (DBG) log("handleSinkStateChange() STATE_CONNECTED -> STATE_PLAYING: mSuspending: " + +mSuspending+", mResuming: "+mResuming); + + if (mResuming) { + mResuming = false; + if (mSuspending) { + mSuspending = false; + suspendSink(device); + } + } + } Intent intent = new Intent(BluetoothA2dp.ACTION_SINK_STATE_CHANGED); intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); intent.putExtra(BluetoothA2dp.EXTRA_PREVIOUS_SINK_STATE, prevState); |