summaryrefslogtreecommitdiffstats
path: root/core/java/android/server/BluetoothService.java
diff options
context:
space:
mode:
authorJaikumar Ganesh <jaikumar@google.com>2009-09-18 11:32:54 -0700
committerJaikumar Ganesh <jaikumar@google.com>2009-09-19 11:29:24 -0700
commit1caa6d111eff6814760ec156b14adc29aa3aae6c (patch)
tree387141a3a427623b218b43318640185c885339f8 /core/java/android/server/BluetoothService.java
parent074c11c1649a097ba1beae719069f8d4a2dd43e3 (diff)
downloadframeworks_base-1caa6d111eff6814760ec156b14adc29aa3aae6c.zip
frameworks_base-1caa6d111eff6814760ec156b14adc29aa3aae6c.tar.gz
frameworks_base-1caa6d111eff6814760ec156b14adc29aa3aae6c.tar.bz2
Add new API for fetching UUIDs using SDP.
Add new API which clients can use to force an SDP query. The result is broadcast using an intent having the UUIDs. The intent is broadcast after a timeout, in case of an error. This timeout is greater than the page timeout. Change-Id: I61e6db4c05b34c42f679a66987e37e2063a793b6
Diffstat (limited to 'core/java/android/server/BluetoothService.java')
-rw-r--r--core/java/android/server/BluetoothService.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/core/java/android/server/BluetoothService.java b/core/java/android/server/BluetoothService.java
index c0e4f34..ce62f07 100644
--- a/core/java/android/server/BluetoothService.java
+++ b/core/java/android/server/BluetoothService.java
@@ -76,10 +76,17 @@ public class BluetoothService extends IBluetooth.Stub {
private static final int MESSAGE_REGISTER_SDP_RECORDS = 1;
private static final int MESSAGE_FINISH_DISABLE = 2;
+ private static final int MESSAGE_UUID_INTENT = 3;
+
+ // The timeout used to sent the UUIDs Intent
+ // This timeout should be greater than the page timeout
+ private static final int UUID_INTENT_DELAY = 6000;
private final Map<String, String> mAdapterProperties;
private final HashMap <String, Map<String, String>> mDeviceProperties;
+ private final ArrayList <String> mUuidIntentTracker;
+
static {
classInitNative();
}
@@ -104,6 +111,7 @@ public class BluetoothService extends IBluetooth.Stub {
mIsDiscovering = false;
mAdapterProperties = new HashMap<String, String>();
mDeviceProperties = new HashMap<String, Map<String,String>>();
+ mUuidIntentTracker = new ArrayList<String>();
registerForAirplaneMode();
}
@@ -291,6 +299,11 @@ public class BluetoothService extends IBluetooth.Stub {
case MESSAGE_FINISH_DISABLE:
finishDisable(msg.arg1 != 0);
break;
+ case MESSAGE_UUID_INTENT:
+ String address = (String)msg.obj;
+ if (address != null)
+ sendUuidIntent(address);
+ break;
}
}
};
@@ -976,6 +989,10 @@ public class BluetoothService extends IBluetooth.Stub {
if (!BluetoothAdapter.checkBluetoothAddress(address)) {
return null;
}
+ return getUuidFromCache(address);
+ }
+
+ private ParcelUuid[] getUuidFromCache(String address) {
String value = getRemoteDeviceProperty(address, "UUIDs");
if (value == null) return null;
@@ -990,6 +1007,36 @@ public class BluetoothService extends IBluetooth.Stub {
return uuids;
}
+ public synchronized boolean fetchRemoteUuidsWithSdp(String address) {
+ mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
+ if (!BluetoothAdapter.checkBluetoothAddress(address)) {
+ return false;
+ }
+
+ if (mUuidIntentTracker.contains(address)) {
+ // An SDP query for this address is already in progress
+ return true;
+ }
+
+ boolean ret;
+ if (getBondState(address) == BluetoothDevice.BOND_BONDED) {
+ String path = getObjectPathFromAddress(address);
+ if (path == null) return false;
+
+ // Use an empty string for the UUID pattern
+ ret = discoverServicesNative(path, "");
+ } else {
+ ret = createDeviceNative(address);
+ }
+
+ mUuidIntentTracker.add(address);
+
+ Message message = mHandler.obtainMessage(MESSAGE_UUID_INTENT);
+ message.obj = address;
+ mHandler.sendMessageDelayed(message, UUID_INTENT_DELAY);
+ return ret;
+ }
+
/**
* Gets the rfcomm channel associated with the UUID.
*
@@ -1121,6 +1168,18 @@ public class BluetoothService extends IBluetooth.Stub {
Settings.System.AIRPLANE_MODE_ON, 0) == 1;
}
+ /* Broadcast the Uuid intent */
+ /*package*/ synchronized void sendUuidIntent(String address) {
+ if (mUuidIntentTracker.contains(address)) {
+ ParcelUuid[] uuid = getUuidFromCache(address);
+ Intent intent = new Intent(BluetoothDevice.ACTION_UUID);
+ intent.putExtra(BluetoothDevice.EXTRA_UUID, uuid);
+ mContext.sendBroadcast(intent, BLUETOOTH_ADMIN_PERM);
+
+ mUuidIntentTracker.remove(address);
+ }
+ }
+
@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
pw.println("\nmIsAirplaneSensitive = " + mIsAirplaneSensitive + "\n");
@@ -1284,4 +1343,6 @@ public class BluetoothService extends IBluetooth.Stub {
private native boolean setPairingConfirmationNative(String address, boolean confirm,
int nativeData);
private native boolean setDevicePropertyBooleanNative(String objectPath, String key, int value);
+ private native boolean createDeviceNative(String address);
+ private native boolean discoverServicesNative(String objectPath, String pattern);
}