From 8bc8ce44f7e5a720e7b989bdd63bb33da512103b Mon Sep 17 00:00:00 2001 From: Jaikumar Ganesh Date: Wed, 24 Jun 2009 16:42:51 -0700 Subject: 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. --- core/java/android/server/BluetoothEventLoop.java | 25 +++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'core/java/android/server/BluetoothEventLoop.java') 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); } } -- cgit v1.1