am cc670b5c: Merge change 25323 into eclair
Merge commit 'cc670b5ca26e4a6ac8d34fa0ee0e51c895067c48' into eclair-plus-aosp * commit 'cc670b5ca26e4a6ac8d34fa0ee0e51c895067c48': Change handling of remoteUuids.
This commit is contained in:
@@ -503,7 +503,7 @@ public final class BluetoothDevice implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public String[] getUuids() {
|
public ParcelUuid[] getUuids() {
|
||||||
try {
|
try {
|
||||||
return sService.getRemoteUuids(mAddress);
|
return sService.getRemoteUuids(mAddress);
|
||||||
} catch (RemoteException e) {Log.e(TAG, "", e);}
|
} catch (RemoteException e) {Log.e(TAG, "", e);}
|
||||||
@@ -511,7 +511,7 @@ public final class BluetoothDevice implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
public int getServiceChannel(String uuid) {
|
public int getServiceChannel(ParcelUuid uuid) {
|
||||||
try {
|
try {
|
||||||
return sService.getRemoteServiceChannel(mAddress, uuid);
|
return sService.getRemoteServiceChannel(mAddress, uuid);
|
||||||
} catch (RemoteException e) {Log.e(TAG, "", e);}
|
} catch (RemoteException e) {Log.e(TAG, "", e);}
|
||||||
|
|||||||
@@ -16,10 +16,11 @@
|
|||||||
|
|
||||||
package android.bluetooth;
|
package android.bluetooth;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static helper methods and constants to decode the UUID of remote devices.
|
* Static helper methods and constants to decode the ParcelUuid of remote devices.
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public final class BluetoothUuid {
|
public final class BluetoothUuid {
|
||||||
@@ -30,40 +31,99 @@ public final class BluetoothUuid {
|
|||||||
* The following 128 bit values are calculated as:
|
* The following 128 bit values are calculated as:
|
||||||
* uuid * 2^96 + BASE_UUID
|
* uuid * 2^96 + BASE_UUID
|
||||||
*/
|
*/
|
||||||
public static final UUID AudioSink = UUID.fromString("0000110B-0000-1000-8000-00805F9B34FB");
|
public static final ParcelUuid AudioSink =
|
||||||
public static final UUID AudioSource = UUID.fromString("0000110A-0000-1000-8000-00805F9B34FB");
|
ParcelUuid.fromString("0000110B-0000-1000-8000-00805F9B34FB");
|
||||||
public static final UUID AdvAudioDist = UUID.fromString("0000110D-0000-1000-8000-00805F9B34FB");
|
public static final ParcelUuid AudioSource =
|
||||||
public static final UUID HSP = UUID.fromString("00001108-0000-1000-8000-00805F9B34FB");
|
ParcelUuid.fromString("0000110A-0000-1000-8000-00805F9B34FB");
|
||||||
public static final UUID Handsfree = UUID.fromString("0000111E-0000-1000-8000-00805F9B34FB");
|
public static final ParcelUuid AdvAudioDist =
|
||||||
public static final UUID AvrcpController =
|
ParcelUuid.fromString("0000110D-0000-1000-8000-00805F9B34FB");
|
||||||
UUID.fromString("0000110E-0000-1000-8000-00805F9B34FB");
|
public static final ParcelUuid HSP =
|
||||||
public static final UUID AvrcpTarget = UUID.fromString("0000110C-0000-1000-8000-00805F9B34FB");
|
ParcelUuid.fromString("00001108-0000-1000-8000-00805F9B34FB");
|
||||||
|
public static final ParcelUuid Handsfree =
|
||||||
|
ParcelUuid.fromString("0000111E-0000-1000-8000-00805F9B34FB");
|
||||||
|
public static final ParcelUuid AvrcpController =
|
||||||
|
ParcelUuid.fromString("0000110E-0000-1000-8000-00805F9B34FB");
|
||||||
|
public static final ParcelUuid AvrcpTarget =
|
||||||
|
ParcelUuid.fromString("0000110C-0000-1000-8000-00805F9B34FB");
|
||||||
|
public static final ParcelUuid ObexObjectPush =
|
||||||
|
ParcelUuid.fromString("00001105-0000-1000-8000-00805f9b34fb");
|
||||||
|
|
||||||
public static boolean isAudioSource(UUID uuid) {
|
public static boolean isAudioSource(ParcelUuid uuid) {
|
||||||
return uuid.equals(AudioSource);
|
return uuid.equals(AudioSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAudioSink(UUID uuid) {
|
public static boolean isAudioSink(ParcelUuid uuid) {
|
||||||
return uuid.equals(AudioSink);
|
return uuid.equals(AudioSink);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAdvAudioDist(UUID uuid) {
|
public static boolean isAdvAudioDist(ParcelUuid uuid) {
|
||||||
return uuid.equals(AdvAudioDist);
|
return uuid.equals(AdvAudioDist);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isHandsfree(UUID uuid) {
|
public static boolean isHandsfree(ParcelUuid uuid) {
|
||||||
return uuid.equals(Handsfree);
|
return uuid.equals(Handsfree);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isHeadset(UUID uuid) {
|
public static boolean isHeadset(ParcelUuid uuid) {
|
||||||
return uuid.equals(HSP);
|
return uuid.equals(HSP);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAvrcpController(UUID uuid) {
|
public static boolean isAvrcpController(ParcelUuid uuid) {
|
||||||
return uuid.equals(AvrcpController);
|
return uuid.equals(AvrcpController);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAvrcpTarget(UUID uuid) {
|
public static boolean isAvrcpTarget(ParcelUuid uuid) {
|
||||||
return uuid.equals(AvrcpTarget);
|
return uuid.equals(AvrcpTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if ParcelUuid is present in uuidArray
|
||||||
|
*
|
||||||
|
* @param uuidArray - Array of ParcelUuids
|
||||||
|
* @param uuid
|
||||||
|
*/
|
||||||
|
public static boolean isUuidPresent(ParcelUuid[] uuidArray, ParcelUuid uuid) {
|
||||||
|
for (ParcelUuid element: uuidArray) {
|
||||||
|
if (element.equals(uuid)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if there any common ParcelUuids in uuidA and uuidB.
|
||||||
|
*
|
||||||
|
* @param uuidA - List of ParcelUuids
|
||||||
|
* @param uuidB - List of ParcelUuids
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static boolean containsAnyUuid(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
|
||||||
|
if (uuidA == null && uuidB == null) return true;
|
||||||
|
if (uuidA == null || uuidB == null) return false;
|
||||||
|
|
||||||
|
HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA));
|
||||||
|
for (ParcelUuid uuid: uuidB) {
|
||||||
|
if (uuidSet.contains(uuid)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if all the ParcelUuids in ParcelUuidB are present in
|
||||||
|
* ParcelUuidA
|
||||||
|
*
|
||||||
|
* @param uuidA - Array of ParcelUuidsA
|
||||||
|
* @param uuidB - Array of ParcelUuidsB
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static boolean containsAllUuids(ParcelUuid[] uuidA, ParcelUuid[] uuidB) {
|
||||||
|
if (uuidA == null && uuidB == null) return true;
|
||||||
|
if (uuidA == null || uuidB == null) return false;
|
||||||
|
|
||||||
|
HashSet<ParcelUuid> uuidSet = new HashSet<ParcelUuid> (Arrays.asList(uuidA));
|
||||||
|
for (ParcelUuid uuid: uuidB) {
|
||||||
|
if (!uuidSet.contains(uuid)) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package android.bluetooth;
|
package android.bluetooth;
|
||||||
|
|
||||||
|
import android.bluetooth.ParcelUuid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* System private API for talking with the Bluetooth service.
|
* System private API for talking with the Bluetooth service.
|
||||||
*
|
*
|
||||||
@@ -50,8 +52,8 @@ interface IBluetooth
|
|||||||
|
|
||||||
String getRemoteName(in String address);
|
String getRemoteName(in String address);
|
||||||
int getRemoteClass(in String address);
|
int getRemoteClass(in String address);
|
||||||
String[] getRemoteUuids(in String address);
|
ParcelUuid[] getRemoteUuids(in String address);
|
||||||
int getRemoteServiceChannel(in String address, String uuid);
|
int getRemoteServiceChannel(in String address,in ParcelUuid uuid);
|
||||||
|
|
||||||
boolean setPin(in String address, in byte[] pin);
|
boolean setPin(in String address, in byte[] pin);
|
||||||
boolean setPasskey(in String address, int passkey);
|
boolean setPasskey(in String address, int passkey);
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import android.bluetooth.BluetoothAdapter;
|
|||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.bluetooth.BluetoothUuid;
|
import android.bluetooth.BluetoothUuid;
|
||||||
import android.bluetooth.IBluetoothA2dp;
|
import android.bluetooth.IBluetoothA2dp;
|
||||||
|
import android.bluetooth.ParcelUuid;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -42,7 +43,6 @@ import java.io.PrintWriter;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
|
public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
|
||||||
private static final String TAG = "BluetoothA2dpService";
|
private static final String TAG = "BluetoothA2dpService";
|
||||||
@@ -188,15 +188,9 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSinkDevice(BluetoothDevice device) {
|
private boolean isSinkDevice(BluetoothDevice device) {
|
||||||
String uuids[] = mBluetoothService.getRemoteUuids(device.getAddress());
|
ParcelUuid[] uuids = mBluetoothService.getRemoteUuids(device.getAddress());
|
||||||
UUID uuid;
|
if (uuids != null && BluetoothUuid.isUuidPresent(uuids, BluetoothUuid.AudioSink)) {
|
||||||
if (uuids != null) {
|
return true;
|
||||||
for (String deviceUuid: uuids) {
|
|
||||||
uuid = UUID.fromString(deviceUuid);
|
|
||||||
if (BluetoothUuid.isAudioSink(uuid)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -229,18 +223,14 @@ public class BluetoothA2dpService extends IBluetoothA2dp.Stub {
|
|||||||
for (String path: paths) {
|
for (String path: paths) {
|
||||||
String address = mBluetoothService.getAddressFromObjectPath(path);
|
String address = mBluetoothService.getAddressFromObjectPath(path);
|
||||||
BluetoothDevice device = mAdapter.getRemoteDevice(address);
|
BluetoothDevice device = mAdapter.getRemoteDevice(address);
|
||||||
String []uuids = mBluetoothService.getRemoteUuids(address);
|
ParcelUuid[] remoteUuids = mBluetoothService.getRemoteUuids(address);
|
||||||
if (uuids != null)
|
if (remoteUuids != null)
|
||||||
for (String uuid: uuids) {
|
if (BluetoothUuid.containsAnyUuid(remoteUuids,
|
||||||
UUID remoteUuid = UUID.fromString(uuid);
|
new ParcelUuid[] {BluetoothUuid.AudioSink,
|
||||||
if (BluetoothUuid.isAudioSink(remoteUuid) ||
|
BluetoothUuid.AdvAudioDist})) {
|
||||||
BluetoothUuid.isAudioSource(remoteUuid) ||
|
addAudioSink(device);
|
||||||
BluetoothUuid.isAdvAudioDist(remoteUuid)) {
|
|
||||||
addAudioSink(device);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mAudioManager.setParameters(BLUETOOTH_ENABLED+"=true");
|
mAudioManager.setParameters(BLUETOOTH_ENABLED+"=true");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import android.bluetooth.BluetoothAdapter;
|
|||||||
import android.bluetooth.BluetoothClass;
|
import android.bluetooth.BluetoothClass;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.bluetooth.BluetoothUuid;
|
import android.bluetooth.BluetoothUuid;
|
||||||
|
import android.bluetooth.ParcelUuid;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -28,7 +29,6 @@ import android.os.Message;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Move this to
|
* TODO: Move this to
|
||||||
@@ -501,7 +501,7 @@ class BluetoothEventLoop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean authorized = false;
|
boolean authorized = false;
|
||||||
UUID uuid = UUID.fromString(deviceUuid);
|
ParcelUuid uuid = ParcelUuid.fromString(deviceUuid);
|
||||||
// Bluez sends the UUID of the local service being accessed, _not_ the
|
// Bluez sends the UUID of the local service being accessed, _not_ the
|
||||||
// remote service
|
// remote service
|
||||||
if (mBluetoothService.isEnabled() &&
|
if (mBluetoothService.isEnabled() &&
|
||||||
|
|||||||
@@ -24,11 +24,12 @@
|
|||||||
|
|
||||||
package android.server;
|
package android.server;
|
||||||
|
|
||||||
import android.bluetooth.BluetoothClass;
|
|
||||||
import android.bluetooth.BluetoothAdapter;
|
import android.bluetooth.BluetoothAdapter;
|
||||||
|
import android.bluetooth.BluetoothClass;
|
||||||
import android.bluetooth.BluetoothDevice;
|
import android.bluetooth.BluetoothDevice;
|
||||||
import android.bluetooth.BluetoothHeadset;
|
import android.bluetooth.BluetoothHeadset;
|
||||||
import android.bluetooth.IBluetooth;
|
import android.bluetooth.IBluetooth;
|
||||||
|
import android.bluetooth.ParcelUuid;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -51,7 +52,6 @@ import java.io.UnsupportedEncodingException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class BluetoothService extends IBluetooth.Stub {
|
public class BluetoothService extends IBluetooth.Stub {
|
||||||
@@ -967,22 +967,26 @@ public class BluetoothService extends IBluetooth.Stub {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the remote features encoded as bit mask.
|
* Gets the UUIDs supported by the remote device
|
||||||
*
|
*
|
||||||
* Note: This method may be obsoleted soon.
|
* @return array of 128bit ParcelUuids
|
||||||
*
|
|
||||||
* @return String array of 128bit UUIDs
|
|
||||||
*/
|
*/
|
||||||
public synchronized String[] getRemoteUuids(String address) {
|
public synchronized ParcelUuid[] getRemoteUuids(String address) {
|
||||||
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
|
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
|
||||||
if (!BluetoothAdapter.checkBluetoothAddress(address)) {
|
if (!BluetoothAdapter.checkBluetoothAddress(address)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String value = getRemoteDeviceProperty(address, "UUIDs");
|
String value = getRemoteDeviceProperty(address, "UUIDs");
|
||||||
String[] uuids = null;
|
if (value == null) return null;
|
||||||
|
|
||||||
|
String[] uuidStrings = null;
|
||||||
// The UUIDs are stored as a "," separated string.
|
// The UUIDs are stored as a "," separated string.
|
||||||
if (value != null)
|
uuidStrings = value.split(",");
|
||||||
uuids = value.split(",");
|
ParcelUuid[] uuids = new ParcelUuid[uuidStrings.length];
|
||||||
|
|
||||||
|
for (int i = 0; i < uuidStrings.length; i++) {
|
||||||
|
uuids[i] = ParcelUuid.fromString(uuidStrings[i]);
|
||||||
|
}
|
||||||
return uuids;
|
return uuids;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -990,16 +994,17 @@ public class BluetoothService extends IBluetooth.Stub {
|
|||||||
* Gets the rfcomm channel associated with the UUID.
|
* Gets the rfcomm channel associated with the UUID.
|
||||||
*
|
*
|
||||||
* @param address Address of the remote device
|
* @param address Address of the remote device
|
||||||
* @param uuid UUID of the service attribute
|
* @param uuid ParcelUuid of the service attribute
|
||||||
*
|
*
|
||||||
* @return rfcomm channel associated with the service attribute
|
* @return rfcomm channel associated with the service attribute
|
||||||
*/
|
*/
|
||||||
public int getRemoteServiceChannel(String address, String uuid) {
|
public int getRemoteServiceChannel(String address, ParcelUuid uuid) {
|
||||||
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
|
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
|
||||||
if (!BluetoothAdapter.checkBluetoothAddress(address)) {
|
if (!BluetoothAdapter.checkBluetoothAddress(address)) {
|
||||||
return BluetoothDevice.ERROR;
|
return BluetoothDevice.ERROR;
|
||||||
}
|
}
|
||||||
return getDeviceServiceChannelNative(getObjectPathFromAddress(address), uuid, 0x0004);
|
return getDeviceServiceChannelNative(getObjectPathFromAddress(address), uuid.toString(),
|
||||||
|
0x0004);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean setPin(String address, byte[] pin) {
|
public synchronized boolean setPin(String address, byte[] pin) {
|
||||||
@@ -1148,11 +1153,11 @@ public class BluetoothService extends IBluetooth.Stub {
|
|||||||
mBondState.getAttempt(address),
|
mBondState.getAttempt(address),
|
||||||
getRemoteName(address));
|
getRemoteName(address));
|
||||||
if (bondState == BluetoothDevice.BOND_BONDED) {
|
if (bondState == BluetoothDevice.BOND_BONDED) {
|
||||||
String[] uuids = getRemoteUuids(address);
|
ParcelUuid[] uuids = getRemoteUuids(address);
|
||||||
if (uuids == null) {
|
if (uuids == null) {
|
||||||
pw.printf("\tuuids = null\n");
|
pw.printf("\tuuids = null\n");
|
||||||
} else {
|
} else {
|
||||||
for (String uuid : uuids) {
|
for (ParcelUuid uuid : uuids) {
|
||||||
pw.printf("\t" + uuid + "\n");
|
pw.printf("\t" + uuid + "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user