summaryrefslogtreecommitdiffstats
path: root/core/java/android/server
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-01-20 14:03:58 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-01-20 14:03:58 -0800
commit22f7dfd23490a3de2f21ff96949ba47003aac8f8 (patch)
tree41bc290bb2f1f08a0e37cfda4955742a85d42ecf /core/java/android/server
parent9266c558bf1d21ff647525ff99f7dadbca417309 (diff)
downloadframeworks_base-22f7dfd23490a3de2f21ff96949ba47003aac8f8.zip
frameworks_base-22f7dfd23490a3de2f21ff96949ba47003aac8f8.tar.gz
frameworks_base-22f7dfd23490a3de2f21ff96949ba47003aac8f8.tar.bz2
auto import from //branches/cupcake/...@127101
Diffstat (limited to 'core/java/android/server')
-rw-r--r--core/java/android/server/BluetoothA2dpService.java52
1 files changed, 40 insertions, 12 deletions
diff --git a/core/java/android/server/BluetoothA2dpService.java b/core/java/android/server/BluetoothA2dpService.java
index 90ef8f6..be784ff 100644
--- a/core/java/android/server/BluetoothA2dpService.java
+++ b/core/java/android/server/BluetoothA2dpService.java
@@ -35,6 +35,7 @@ import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.media.AudioManager;
import android.os.Binder;
+import android.provider.Settings;
import android.util.Log;
import java.io.FileDescriptor;
@@ -83,6 +84,8 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
mIntentFilter = new IntentFilter(BluetoothIntent.ENABLED_ACTION);
mIntentFilter.addAction(BluetoothIntent.DISABLED_ACTION);
+ mIntentFilter.addAction(BluetoothIntent.BONDING_CREATED_ACTION);
+ mIntentFilter.addAction(BluetoothIntent.BONDING_REMOVED_ACTION);
mContext.registerReceiver(mReceiver, mIntentFilter);
if (device.isEnabled()) {
@@ -103,10 +106,15 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
+ String address = intent.getStringExtra(BluetoothIntent.ADDRESS);
if (action.equals(BluetoothIntent.ENABLED_ACTION)) {
onBluetoothEnable();
} else if (action.equals(BluetoothIntent.DISABLED_ACTION)) {
onBluetoothDisable();
+ } else if (action.equals(BluetoothIntent.BONDING_CREATED_ACTION)) {
+ setSinkPriority(address, BluetoothA2dp.PRIORITY_AUTO);
+ } else if (action.equals(BluetoothIntent.BONDING_REMOVED_ACTION)) {
+ setSinkPriority(address, BluetoothA2dp.PRIORITY_OFF);
}
}
};
@@ -145,7 +153,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
if (path == null) {
return BluetoothError.ERROR;
}
-
+
SinkState sink = mAudioDevices.get(path);
int state = BluetoothA2dp.STATE_DISCONNECTED;
if (sink != null) {
@@ -159,8 +167,8 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
case BluetoothA2dp.STATE_CONNECTING:
return BluetoothError.SUCCESS;
}
-
- // State is DISCONNECTED
+
+ // State is DISCONNECTED
if (!connectSinkNative(path)) {
return BluetoothError.ERROR;
}
@@ -189,7 +197,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
return BluetoothError.SUCCESS;
}
- // State is CONNECTING or CONNECTED or PLAYING
+ // State is CONNECTING or CONNECTED or PLAYING
if (!disconnectSinkNative(path)) {
return BluetoothError.ERROR;
} else {
@@ -229,16 +237,37 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
return BluetoothA2dp.STATE_DISCONNECTED;
}
- public synchronized void onHeadsetCreated(String path) {
+ public synchronized int getSinkPriority(String address) {
+ mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+ if (!BluetoothDevice.checkBluetoothAddress(address)) {
+ return BluetoothError.ERROR;
+ }
+ return Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.getBluetoothA2dpSinkPriorityKey(address),
+ BluetoothA2dp.PRIORITY_OFF);
+ }
+
+ public synchronized int setSinkPriority(String address, int priority) {
+ mContext.enforceCallingOrSelfPermission(BLUETOOTH_ADMIN_PERM,
+ "Need BLUETOOTH_ADMIN permission");
+ if (!BluetoothDevice.checkBluetoothAddress(address)) {
+ return BluetoothError.ERROR;
+ }
+ return Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.getBluetoothA2dpSinkPriorityKey(address), priority) ?
+ BluetoothError.SUCCESS : BluetoothError.ERROR;
+ }
+
+ private synchronized void onHeadsetCreated(String path) {
updateState(path, BluetoothA2dp.STATE_DISCONNECTED);
}
- public synchronized void onHeadsetRemoved(String path) {
+ private synchronized void onHeadsetRemoved(String path) {
if (mAudioDevices == null) return;
mAudioDevices.remove(path);
}
- public synchronized void onSinkConnected(String path) {
+ private synchronized void onSinkConnected(String path) {
if (mAudioDevices == null) return;
// bluez 3.36 quietly disconnects the previous sink when a new sink
// is connected, so we need to mark all previously connected sinks as
@@ -258,16 +287,16 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
updateState(path, BluetoothA2dp.STATE_CONNECTED);
}
- public synchronized void onSinkDisconnected(String path) {
+ private synchronized void onSinkDisconnected(String path) {
mAudioManager.setBluetoothA2dpOn(false);
updateState(path, BluetoothA2dp.STATE_DISCONNECTED);
}
- public synchronized void onSinkPlaying(String path) {
+ private synchronized void onSinkPlaying(String path) {
updateState(path, BluetoothA2dp.STATE_PLAYING);
}
- public synchronized void onSinkStopped(String path) {
+ private synchronized void onSinkStopped(String path) {
updateState(path, BluetoothA2dp.STATE_CONNECTED);
}
@@ -307,7 +336,7 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
if (state != prevState) {
if (DBG) log("state " + address + " (" + path + ") " + prevState + "->" + state);
-
+
Intent intent = new Intent(BluetoothA2dp.SINK_STATE_CHANGED_ACTION);
intent.putExtra(BluetoothIntent.ADDRESS, address);
intent.putExtra(BluetoothA2dp.SINK_PREVIOUS_STATE, prevState);
@@ -339,5 +368,4 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
private synchronized native boolean connectSinkNative(String path);
private synchronized native boolean disconnectSinkNative(String path);
private synchronized native boolean isSinkConnectedNative(String path);
-
}