diff options
author | Jaikumar Ganesh <jaikumar@google.com> | 2009-09-16 12:30:02 -0700 |
---|---|---|
committer | Jaikumar Ganesh <jaikumar@google.com> | 2009-09-16 17:05:15 -0700 |
commit | dd0463aef18d251c741bfc9dc7a2787443ef36f1 (patch) | |
tree | 8a479d072af6e783e0f46de0fb60045d4fe72df2 /core/java | |
parent | 82c3ef7adc235e857736b09864c2aa81d41d7132 (diff) | |
download | frameworks_base-dd0463aef18d251c741bfc9dc7a2787443ef36f1.zip frameworks_base-dd0463aef18d251c741bfc9dc7a2787443ef36f1.tar.gz frameworks_base-dd0463aef18d251c741bfc9dc7a2787443ef36f1.tar.bz2 |
Change handling of remoteUuids.
Use the ParcelUuid instead of UUID
Change-Id:Ie05d65a62e8a4df8182a4c737d46c14142bfec43
Diffstat (limited to 'core/java')
-rw-r--r-- | core/java/android/bluetooth/BluetoothDevice.java | 4 | ||||
-rw-r--r-- | core/java/android/bluetooth/BluetoothUuid.java | 96 | ||||
-rw-r--r-- | core/java/android/bluetooth/IBluetooth.aidl | 6 | ||||
-rw-r--r-- | core/java/android/server/BluetoothA2dpService.java | 32 | ||||
-rw-r--r-- | core/java/android/server/BluetoothEventLoop.java | 4 | ||||
-rw-r--r-- | core/java/android/server/BluetoothService.java | 35 |
6 files changed, 117 insertions, 60 deletions
diff --git a/core/java/android/bluetooth/BluetoothDevice.java b/core/java/android/bluetooth/BluetoothDevice.java index b1861ac..0b3f3c7 100644 --- a/core/java/android/bluetooth/BluetoothDevice.java +++ b/core/java/android/bluetooth/BluetoothDevice.java @@ -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);} diff --git a/core/java/android/bluetooth/BluetoothUuid.java b/core/java/android/bluetooth/BluetoothUuid.java index c15bc20..409c744 100644 --- a/core/java/android/bluetooth/BluetoothUuid.java +++ b/core/java/android/bluetooth/BluetoothUuid.java @@ -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 boolean isAudioSource(UUID uuid) { + 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(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; + } + } diff --git a/core/java/android/bluetooth/IBluetooth.aidl b/core/java/android/bluetooth/IBluetooth.aidl index a11ceac..04c8ec9 100644 --- a/core/java/android/bluetooth/IBluetooth.aidl +++ b/core/java/android/bluetooth/IBluetooth.aidl @@ -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); diff --git a/core/java/android/server/BluetoothA2dpService.java b/core/java/android/server/BluetoothA2dpService.java index 9c687e2..be8c777 100644 --- a/core/java/android/server/BluetoothA2dpService.java +++ b/core/java/android/server/BluetoothA2dpService.java @@ -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"); } diff --git a/core/java/android/server/BluetoothEventLoop.java b/core/java/android/server/BluetoothEventLoop.java index 1ed5c49..ba53307 100644 --- a/core/java/android/server/BluetoothEventLoop.java +++ b/core/java/android/server/BluetoothEventLoop.java @@ -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() && diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java index de0cad7..c0e4f34 100644 --- a/core/java/android/server/BluetoothService.java +++ b/core/java/android/server/BluetoothService.java @@ -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. - * - * Note: This method may be obsoleted soon. + * Gets the UUIDs supported by the remote device * - * @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"); } } |