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