Merge change 9602

* changes:
  Add incoming connections to the cache and change authorization check.
This commit is contained in:
Android (Google) Code Review
2009-08-04 10:09:47 -07:00
3 changed files with 66 additions and 31 deletions

View File

@@ -375,6 +375,10 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
}
private synchronized void onSinkPropertyChanged(String path, String []propValues) {
if (!mBluetoothService.isEnabled()) {
return;
}
String name = propValues[0];
String address = mBluetoothService.getAddressFromObjectPath(path);
if (address == null) {
@@ -382,15 +386,16 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
return;
}
if (mAudioDevices.get(address) == null) {
// Ignore this state change, since it means we have got it after
// bluetooth has been disabled.
return;
}
if (name.equals(PROPERTY_STATE)) {
int state = convertBluezSinkStringtoState(propValues[1]);
int prevState = mAudioDevices.get(address);
handleSinkStateChange(address, prevState, state);
if (mAudioDevices.get(address) == null) {
// This is for an incoming connection for a device not known to us.
// We have authorized it and bluez state has changed.
addAudioSink(address);
} else {
int prevState = mAudioDevices.get(address);
handleSinkStateChange(address, prevState, state);
}
}
}
@@ -437,7 +442,6 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
return sinks;
}
@Override
protected synchronized void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
if (mAudioDevices.isEmpty()) return;

View File

@@ -804,6 +804,15 @@ public class BluetoothDeviceService extends IBluetoothDevice.Stub {
return mBondState.getBondState(address.toUpperCase());
}
/*package*/ boolean isRemoteDeviceInCache(String address) {
return (mRemoteDeviceProperties.get(address) != null);
}
/*package*/ String[] getRemoteDeviceProperties(String address) {
String objectPath = getObjectPathFromAddress(address);
return (String [])getDevicePropertiesNative(objectPath);
}
/*package*/ synchronized String getRemoteDeviceProperty(String address, String property) {
Map<String, String> properties = mRemoteDeviceProperties.get(address);
if (properties != null) {
@@ -812,8 +821,7 @@ public class BluetoothDeviceService extends IBluetoothDevice.Stub {
// Query for remote device properties, again.
// We will need to reload the cache when we switch Bluetooth on / off
// or if we crash.
String objectPath = getObjectPathFromAddress(address);
String propValues[] = (String [])getDevicePropertiesNative(objectPath);
String[] propValues = getRemoteDeviceProperties(address);
if (propValues != null) {
addRemoteDeviceProperties(address, propValues);
return getRemoteDeviceProperty(address, property);

View File

@@ -122,33 +122,41 @@ class BluetoothEventLoop {
return isEventLoopRunningNative();
}
private void addDevice(String address, String[] properties) {
mBluetoothService.addRemoteDeviceProperties(address, properties);
String rssi = mBluetoothService.getRemoteDeviceProperty(address, "RSSI");
String classValue = mBluetoothService.getRemoteDeviceProperty(address, "Class");
String name = mBluetoothService.getRemoteDeviceProperty(address, "Name");
short rssiValue;
// For incoming connections, we don't get the RSSI value. Use a default of MIN_VALUE.
// If we accept the pairing, we will automatically show it at the top of the list.
if (rssi != null) {
rssiValue = (short)Integer.valueOf(rssi).intValue();
} else {
rssiValue = Short.MIN_VALUE;
}
if (classValue != null) {
Intent intent = new Intent(BluetoothIntent.REMOTE_DEVICE_FOUND_ACTION);
intent.putExtra(BluetoothIntent.ADDRESS, address);
intent.putExtra(BluetoothIntent.CLASS, Integer.valueOf(classValue));
intent.putExtra(BluetoothIntent.RSSI, rssiValue);
intent.putExtra(BluetoothIntent.NAME, name);
mContext.sendBroadcast(intent, BLUETOOTH_PERM);
} else {
log ("ClassValue: " + classValue + " for remote device: " + address + " is null");
}
}
private void onDeviceFound(String address, String[] properties) {
if (properties == null) {
Log.e(TAG, "ERROR: Remote device properties are null");
return;
}
mBluetoothService.addRemoteDeviceProperties(address, properties);
String rssi = mBluetoothService.getRemoteDeviceProperty(address, "RSSI");
String classValue = mBluetoothService.getRemoteDeviceProperty(address, "Class");
String name = mBluetoothService.getRemoteDeviceProperty(address, "Name");
if (rssi != null && classValue != null) {
Intent intent = new Intent(BluetoothIntent.REMOTE_DEVICE_FOUND_ACTION);
intent.putExtra(BluetoothIntent.ADDRESS, address);
intent.putExtra(BluetoothIntent.CLASS, Integer.valueOf(classValue));
intent.putExtra(BluetoothIntent.RSSI, (short)Integer.valueOf(rssi).intValue());
intent.putExtra(BluetoothIntent.NAME, name);
mContext.sendBroadcast(intent, BLUETOOTH_PERM);
} else {
log ("RSSI: " + rssi + " or ClassValue: " + classValue +
" for remote device: " + address + " is null");
}
addDevice(address, properties);
}
private void onDeviceDisappeared(String address) {
mBluetoothService.removeRemoteDeviceProperties(address);
Intent intent = new Intent(BluetoothIntent.REMOTE_DEVICE_DISAPPEARED_ACTION);
intent.putExtra(BluetoothIntent.ADDRESS, address);
mContext.sendBroadcast(intent, BLUETOOTH_PERM);
@@ -208,7 +216,14 @@ class BluetoothEventLoop {
}
private void onDeviceCreated(String deviceObjectPath) {
// do nothing.
String address = mBluetoothService.getAddressFromObjectPath(deviceObjectPath);
if (!mBluetoothService.isRemoteDeviceInCache(address)) {
// Incoming connection, we haven't seen this device, add to cache.
String[] properties = mBluetoothService.getRemoteDeviceProperties(address);
if (properties != null) {
addDevice(address, properties);
}
}
return;
}
@@ -316,6 +331,13 @@ class BluetoothEventLoop {
}
}
mBluetoothService.setRemoteDeviceProperty(address, name, uuid);
} else if (name.equals("Paired")) {
if (propValues[1].equals("true")) {
mBluetoothService.getBondState().setBondState(address, BluetoothDevice.BOND_BONDED);
} else {
mBluetoothService.getBondState().setBondState(address,
BluetoothDevice.BOND_NOT_BONDED);
}
}
}
@@ -403,7 +425,8 @@ class BluetoothEventLoop {
boolean authorized = false;
UUID uuid = UUID.fromString(deviceUuid);
if (mBluetoothService.isEnabled() &&
(BluetoothUuid.isAudioSink(uuid) || BluetoothUuid.isAvrcpController(uuid))) {
(BluetoothUuid.isAudioSink(uuid) || BluetoothUuid.isAvrcpController(uuid)
|| BluetoothUuid.isAdvAudioDist(uuid))) {
BluetoothA2dp a2dp = new BluetoothA2dp(mContext);
authorized = a2dp.getSinkPriority(address) > BluetoothA2dp.PRIORITY_OFF;
if (authorized) {