auto import from //branches/cupcake/...@127101
This commit is contained in:
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user