diff options
| author | Eric Laurent <elaurent@google.com> | 2012-05-31 08:25:33 -0700 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2012-05-31 08:25:33 -0700 |
| commit | c383b407ad24474b87de68f93ea95de495f6d2c1 (patch) | |
| tree | 6d05993963607f3b6ae2ec6decd80483db7d7511 /core | |
| parent | 64846efd6dfeb70303caa1d495fdad08a13eadce (diff) | |
| parent | cee7203f9ac3e54f39b5f528e014f2d3583f60dc (diff) | |
| download | frameworks_base-c383b407ad24474b87de68f93ea95de495f6d2c1.zip frameworks_base-c383b407ad24474b87de68f93ea95de495f6d2c1.tar.gz frameworks_base-c383b407ad24474b87de68f93ea95de495f6d2c1.tar.bz2 | |
am cee7203f: Merge "Send device connection intents from AudioService" into jb-dev
* commit 'cee7203f9ac3e54f39b5f528e014f2d3583f60dc':
Send device connection intents from AudioService
Diffstat (limited to 'core')
| -rw-r--r-- | core/java/android/server/BluetoothA2dpService.java | 59 |
1 files changed, 49 insertions, 10 deletions
diff --git a/core/java/android/server/BluetoothA2dpService.java b/core/java/android/server/BluetoothA2dpService.java index 300bc68..08a99d2 100644 --- a/core/java/android/server/BluetoothA2dpService.java +++ b/core/java/android/server/BluetoothA2dpService.java @@ -33,7 +33,11 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.media.AudioManager; +import android.os.Handler; +import android.os.Message; import android.os.ParcelUuid; +import android.os.PowerManager; +import android.os.PowerManager.WakeLock; import android.provider.Settings; import android.util.Log; @@ -65,6 +69,10 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { private final BluetoothAdapter mAdapter; private int mTargetA2dpState; private BluetoothDevice mPlayingA2dpDevice; + private IntentBroadcastHandler mIntentBroadcastHandler; + private final WakeLock mWakeLock; + + private static final int MSG_CONNECTION_STATE_CHANGED = 0; private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override @@ -131,6 +139,11 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { public BluetoothA2dpService(Context context, BluetoothService bluetoothService) { mContext = context; + PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE); + mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "BluetoothA2dpService"); + + mIntentBroadcastHandler = new IntentBroadcastHandler(); + mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); mBluetoothService = bluetoothService; @@ -514,17 +527,15 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { adjustOtherSinkPriorities(device); } - Intent intent = new Intent(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED); - intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); - intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState); - intent.putExtra(BluetoothProfile.EXTRA_STATE, state); - intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); - mContext.sendBroadcast(intent, BLUETOOTH_PERM); + int delay = mAudioManager.setBluetoothA2dpDeviceConnectionState(device, state); - if (DBG) log("A2DP state : device: " + device + " State:" + prevState + "->" + state); - - mBluetoothService.sendConnectionStateChange(device, BluetoothProfile.A2DP, state, - prevState); + mWakeLock.acquire(); + mIntentBroadcastHandler.sendMessageDelayed(mIntentBroadcastHandler.obtainMessage( + MSG_CONNECTION_STATE_CHANGED, + prevState, + state, + device), + delay); } } @@ -586,6 +597,34 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub { } } + /** Handles A2DP connection state change intent broadcasts. */ + private class IntentBroadcastHandler extends Handler { + + private void onConnectionStateChanged(BluetoothDevice device, int prevState, int state) { + Intent intent = new Intent(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED); + intent.putExtra(BluetoothDevice.EXTRA_DEVICE, device); + intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState); + intent.putExtra(BluetoothProfile.EXTRA_STATE, state); + intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); + mContext.sendBroadcast(intent, BLUETOOTH_PERM); + + if (DBG) log("A2DP state : device: " + device + " State:" + prevState + "->" + state); + + mBluetoothService.sendConnectionStateChange(device, BluetoothProfile.A2DP, state, + prevState); + } + + @Override + public void handleMessage(Message msg) { + switch (msg.what) { + case MSG_CONNECTION_STATE_CHANGED: + onConnectionStateChanged((BluetoothDevice) msg.obj, msg.arg1, msg.arg2); + mWakeLock.release(); + break; + } + } + } + @Override protected synchronized void dump(FileDescriptor fd, PrintWriter pw, String[] args) { mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG); |
