summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2012-05-29 09:24:28 -0700
committerEric Laurent <elaurent@google.com>2012-05-30 14:44:43 -0700
commitb1fbaaccb656ef09a8770c28df15e3e91a452e64 (patch)
tree200c9e04729844783efdf360375297483113d6cc /core
parent48c22c84c089213dda6495fbdeb384e400c7c5c5 (diff)
downloadframeworks_base-b1fbaaccb656ef09a8770c28df15e3e91a452e64.zip
frameworks_base-b1fbaaccb656ef09a8770c28df15e3e91a452e64.tar.gz
frameworks_base-b1fbaaccb656ef09a8770c28df15e3e91a452e64.tar.bz2
Send device connection intents from AudioService
AudioService is currently notified of wired headset and A2DP sink connection states via broadcast intents from WiredAccessoryObserver and BluetoothA2dpService. This is a problem as there is no guaranty that AudioService can take actions upon the change before other apps are notified. For instance, the Play On feature requires the UI to be refreshed when a device is inserted/removed and we must guaranty that the UI component can read new A2DP enable state from AudioManager after it receives a device connection state change intent. - Added hidden methods to AudioManager so that WiredAccessoryObserver and BluetoothA2dpService can notify AudioService of device connection directly. - The wired accessories connection intents are now sent by AudioService. - The A2DP state change intent is delayed by BluetoothA2DPService when ACTION_AUDIO_BECOMING_NOISY is sent by AudioService - ACTION_AUDIO_BECOMING_NOISY intent is not sent when disconnecting A2DP while a wired headset is present and vice versa. Bug 6485897. Change-Id: Ie160b3ee5f451132065530772b868593c90afd94
Diffstat (limited to 'core')
-rw-r--r--core/java/android/server/BluetoothA2dpService.java59
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);