Skip to content

Commit

Permalink
Possible crash fix caused by wrong raw data
Browse files Browse the repository at this point in the history
  • Loading branch information
officelioneight committed Jan 31, 2022
1 parent c7bbdf0 commit 4d040ce
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 1.1.0

* Possible crash fix caused by wrong raw data (fixed by narrit)
* Ios : try reconnect on unexpected disconnection (fixed by EB-Plum)
* Android: Add missing break in switch, which causes exceptions (fixed by russelltg)
* Android: Enforcing maxSdkVersion on the ACCESS_FINE_LOCATION permission will create issues for Android 12 devices that use location for purposes other than Bluetooth (such as using packages that actually need location). (fixed by rickcasson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,21 @@ static Protos.ScanResult from(BluetoothDevice device, ScanResult scanResult) {
}
// Manufacturer Specific Data
SparseArray<byte[]> msd = scanRecord.getManufacturerSpecificData();
for (int i = 0; i < msd.size(); i++) {
int key = msd.keyAt(i);
byte[] value = msd.valueAt(i);
a.putManufacturerData(key, ByteString.copyFrom(value));
if(msd != null) {
for (int i = 0; i < msd.size(); i++) {
int key = msd.keyAt(i);
byte[] value = msd.valueAt(i);
a.putManufacturerData(key, ByteString.copyFrom(value));
}
}
// Service Data
Map<ParcelUuid, byte[]> serviceData = scanRecord.getServiceData();
for (Map.Entry<ParcelUuid, byte[]> entry : serviceData.entrySet()) {
ParcelUuid key = entry.getKey();
byte[] value = entry.getValue();
a.putServiceData(key.getUuid().toString(), ByteString.copyFrom(value));
if(serviceData != null) {
for (Map.Entry<ParcelUuid, byte[]> entry : serviceData.entrySet()) {
ParcelUuid key = entry.getKey();
byte[] value = entry.getValue();
a.putServiceData(key.getUuid().toString(), ByteString.copyFrom(value));
}
}
// Service UUIDs
List<ParcelUuid> serviceUuids = scanRecord.getServiceUuids();
Expand Down
14 changes: 9 additions & 5 deletions ios/Classes/FlutterBluePlusPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -604,20 +604,24 @@ - (ProtosScanResult*)toScanResultProto:(CBPeripheral *)peripheral advertisementD
}
// Manufacturer Specific Data
NSData *manufData = advertisementData[CBAdvertisementDataManufacturerDataKey];
if(manufData.length > 2) {
if(manufData != nil && manufData.length > 2) {
unsigned short manufacturerId;
[manufData getBytes:&manufacturerId length:2];
[[ads manufacturerData] setObject:[manufData subdataWithRange:NSMakeRange(2, manufData.length - 2)] forKey:manufacturerId];
}
// Service Data
NSDictionary *serviceData = advertisementData[CBAdvertisementDataServiceDataKey];
for (CBUUID *uuid in serviceData) {
[[ads serviceData] setObject:serviceData[uuid] forKey:uuid.UUIDString];
if(serviceData != nil) {
for (CBUUID *uuid in serviceData) {
[[ads serviceData] setObject:serviceData[uuid] forKey:uuid.UUIDString];
}
}
// Service Uuids
NSArray *serviceUuids = advertisementData[CBAdvertisementDataServiceUUIDsKey];
for (CBUUID *uuid in serviceUuids) {
[[ads serviceUuidsArray] addObject:uuid.UUIDString];
if(serviceUuids != nil) {
for (CBUUID *uuid in serviceUuids) {
[[ads serviceUuidsArray] addObject:uuid.UUIDString];
}
}
[result setAdvertisementData:ads];
return result;
Expand Down

0 comments on commit 4d040ce

Please sign in to comment.