diff options
author | Jaikumar Ganesh <jaikumar@google.com> | 2009-06-24 16:42:51 -0700 |
---|---|---|
committer | Jaikumar Ganesh <jaikumar@google.com> | 2009-06-29 11:41:19 -0700 |
commit | 8bc8ce44f7e5a720e7b989bdd63bb33da512103b (patch) | |
tree | bb35a2276936b4bf48888a3e30b1cdcec0b3b948 /core/java/android/server | |
parent | afed82bca9e173cabe2c2f25314b202e5c1ccbca (diff) | |
download | frameworks_base-8bc8ce44f7e5a720e7b989bdd63bb33da512103b.zip frameworks_base-8bc8ce44f7e5a720e7b989bdd63bb33da512103b.tar.gz frameworks_base-8bc8ce44f7e5a720e7b989bdd63bb33da512103b.tar.bz2 |
Rework the property parsing code.
1. Fix and remove CodeDuplication TODO
2. Fix crash while unpairing.
3. For array properties, make it a bit more efficient by passing,
lesser String objects from JNI.
4. Remove void pointer usage and use union to make code more readble.
Diffstat (limited to 'core/java/android/server')
-rw-r--r-- | core/java/android/server/BluetoothDeviceService.java | 55 | ||||
-rw-r--r-- | core/java/android/server/BluetoothEventLoop.java | 25 |
2 files changed, 56 insertions, 24 deletions
diff --git a/core/java/android/server/BluetoothDeviceService.java b/core/java/android/server/BluetoothDeviceService.java index 75c590d..77b1b1d 100644 --- a/core/java/android/server/BluetoothDeviceService.java +++ b/core/java/android/server/BluetoothDeviceService.java @@ -545,15 +545,28 @@ public class BluetoothDeviceService extends IBluetoothDevice.Stub { Log.e(TAG, "*Error*: GetAdapterProperties returned NULL"); return; } - for (int i = 0; i < properties.length; i+=2) { - String value = null; - if (mProperties.containsKey(properties[i])) { - value = mProperties.get(properties[i]); - value = value + ',' + properties[i+1]; - } else - value = properties[i+1]; - mProperties.put(properties[i], value); + for (int i = 0; i < properties.length; i++) { + String name = properties[i]; + String newValue; + int len; + if (name == null) { + Log.e(TAG, "Error:Adapter Property at index" + i + "is null"); + continue; + } + if (name.equals("Devices")) { + len = Integer.valueOf(properties[++i]); + if (len != 0) + newValue = ""; + else + newValue = null; + for (int j = 0; j < len; j++) { + newValue += properties[++i] + ","; + } + } else { + newValue = properties[++i]; + } + mProperties.put(name, newValue); } // Add adapter object path property. @@ -819,15 +832,27 @@ public class BluetoothDeviceService extends IBluetoothDevice.Stub { propertyValues = new HashMap<String, String>(); } - for (int i = 0; i < properties.length; i+=2) { - String value = null; - if (propertyValues.containsKey(properties[i])) { - value = propertyValues.get(properties[i]); - value = value + ',' + properties[i+1]; + for (int i = 0; i < properties.length; i++) { + String name = properties[i]; + String newValue; + int len; + if (name == null) { + Log.e(TAG, "Error: Remote Device Property at index" + i + "is null"); + continue; + } + if (name.equals("UUIDs") || name.equals("Nodes")) { + len = Integer.valueOf(properties[++i]); + if (len != 0) + newValue = ""; + else + newValue = null; + for (int j = 0; j < len; j++) { + newValue += properties[++i] + ","; + } } else { - value = properties[i+1]; + newValue = properties[++i]; } - propertyValues.put(properties[i], value); + propertyValues.put(name, newValue); } mRemoteDeviceProperties.put(address, propertyValues); } diff --git a/core/java/android/server/BluetoothEventLoop.java b/core/java/android/server/BluetoothEventLoop.java index ed66dce..38eb4d7 100644 --- a/core/java/android/server/BluetoothEventLoop.java +++ b/core/java/android/server/BluetoothEventLoop.java @@ -260,11 +260,15 @@ class BluetoothEventLoop { mContext.sendBroadcast(intent, BLUETOOTH_PERM); mBluetoothService.setProperty(name, propValues[1]); } else if (name.equals("Devices")) { - String value = ""; - for (int i = 1; i < propValues.length; i++) { - value = value + propValues[i] + ','; + String value = null; + int len = Integer.valueOf(propValues[1]); + if (len > 0) { + value = ""; + for (int i = 2; i < propValues.length; i++) { + value = value + propValues[i] + ','; + } } - mBluetoothService.setProperty(name, value.equals("") ? null : value); + mBluetoothService.setProperty(name, value); } else if (name.equals("Powered")) { // bluetoothd has restarted, re-read all our properties. // Note: bluez only sends this property change when it restarts. @@ -303,12 +307,15 @@ class BluetoothEventLoop { mContext.sendBroadcast(intent, BLUETOOTH_PERM); mBluetoothService.setRemoteDeviceProperty(address, name, propValues[1]); } else if (name.equals("UUIDs")) { - String uuid = "" ; - for (int i = 1; i < propValues.length; i++) { - uuid = uuid + propValues[i] + ","; + String uuid = null; + int len = Integer.valueOf(propValues[1]); + if (len > 0) { + uuid = ""; + for (int i = 2; i < propValues.length; i++) { + uuid = uuid + propValues[i] + ","; + } } - mBluetoothService.setRemoteDeviceProperty(address, name, - uuid.equals("") ? null : uuid); + mBluetoothService.setRemoteDeviceProperty(address, name, uuid); } } |