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.
This commit is contained in:
@@ -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];
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
propertyValues.put(properties[i], value);
|
||||
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 {
|
||||
newValue = properties[++i];
|
||||
}
|
||||
propertyValues.put(name, newValue);
|
||||
}
|
||||
mRemoteDeviceProperties.put(address, propertyValues);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user