Skip to content

Commit 7a5e301

Browse files
authored
Merge pull request #416 from Polidea/release/2.2.0
Release 2.2.0
2 parents 70f6795 + 9ee1603 commit 7a5e301

File tree

90 files changed

+2014
-385
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+2014
-385
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ _android_job_template: &android_job_template
2121
android:
2222
components:
2323
- tools
24-
- build-tools-28.0.3
2524
- android-28
25+
- android-29
26+
- build-tools-28.0.3
27+
- build-tools-29.0.5
2628
- extra-android-m2repository
27-
licenses:
28-
- 'android-sdk-license-.+'
2929
env:
3030
global:
3131
- GRADLE_OPTS="-Xms128m"

.vscode/launch.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Example (debug)",
6+
"request": "launch",
7+
"type": "dart",
8+
"flutterMode": "debug"
9+
}
10+
]
11+
}

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 2.2.0
2+
3+
* **NEW** operations on descriptors
4+
* **BREAKING FOR BLEMULATOR** BLEmulator versions lower than 1.1.0 are not supported from this release
5+
* Support for AndroidX
6+
* Support for Swift 5
7+
* Lower iOS deployment target to 8.0
8+
19
## 2.1.0
210

311
* **BREAKING** ScanResult.AdvertisementData.ManufacturerData has changed type from Int8List to Uint8List

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ For more informations, see [REFERENCE](https://github.com/Polidea/FlutterBleLib/
3939
### Initialising
4040
```dart
4141
BleManager bleManager = BleManager();
42-
bleManager.createClient(); //ready to go!
42+
await bleManager.createClient(); //ready to go!
4343
// your peripheral logic
4444
bleManager.destroyClient(); //remember to release native resources when you're done!
4545
```
@@ -81,6 +81,8 @@ bleManager.startPeripheralScan(
8181
The snippet above starts peripheral scan and stops it after receiving first result.
8282
It filters the scan results to those that advertise a service with specified UUID.
8383

84+
**NOTE:** `isConnectable` and `overflowServiceUuids` fields of `ScanResult` are iOS-only and remain `null` on Android.
85+
8486
### Connecting to peripheral
8587
First you must obtain a _ScanResult_ from _BleManager.startPeripheralScan()_.
8688
```dart

REFERENCE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ Releases native resources. Should be called once there's no further need for BLE
3434
bool allowDuplicates,
3535
});
3636
```
37-
Returns a stream of objects containing advertisement data of the peripheral and the peripheral itself.
3837
`scanMode` and `callbackType` are Android-specific. [More information in Android documentation](https://developer.android.com/reference/android/bluetooth/le/ScanSettings)
3938
`allowDuplicates` is iOS-specific. [More information in iOS documentation](https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerscanoptionallowduplicateskey)
4039
`uuids` is used to filter peripherals to only return those containing services with specified UUIDs.
4140

41+
Returns a stream of objects containing advertisement data of the peripheral and the peripheral itself called `ScanResult`. The object has two iOS-only fields: `isConnectable` and `overflowServiceUuids`.
42+
4243
```dart
4344
Future<void> stopDeviceScan();
4445
```

android/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group 'com.polidea.flutter_ble_lib'
2-
version '1.0'
2+
version '2.2.0'
33

44
buildscript {
55
repositories {
@@ -8,7 +8,7 @@ buildscript {
88
}
99

1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.2.1'
11+
classpath 'com.android.tools.build:gradle:3.5.3'
1212
}
1313
}
1414

@@ -35,6 +35,6 @@ android {
3535
}
3636

3737
dependencies {
38-
implementation 'com.android.support:support-annotations:28.0.0'
39-
implementation 'com.github.Polidea:MultiPlatformBleAdapter:0.1.0'
38+
implementation 'androidx.annotation:annotation:1.1.0'
39+
implementation 'com.github.Polidea:MultiPlatformBleAdapter:0.1.4'
4040
}

android/gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
org.gradle.jvmargs=-Xmx1536M
22

3-
android.useAndroidX=false
4-
android.enableJetifier=false
3+
android.useAndroidX=true
4+
android.enableJetifier=true

android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
33
zipStoreBase=GRADLE_USER_HOME
44
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip

android/src/main/java/com/polidea/flutter_ble_lib/CharacteristicsResponse.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33
import com.polidea.multiplatformbleadapter.Characteristic;
44
import com.polidea.multiplatformbleadapter.Service;
55

6+
import java.util.List;
7+
68
public class CharacteristicsResponse {
7-
private final Characteristic[] characteristics;
9+
private final List<Characteristic> characteristics;
810
private final Service service;
911

10-
public CharacteristicsResponse(Characteristic[] characteristics, Service service) {
12+
public CharacteristicsResponse(List<Characteristic> characteristics, Service service) {
1113
this.characteristics = characteristics;
1214
this.service = service;
1315
}
1416

15-
public Characteristic[] getCharacteristics() {
17+
public List<Characteristic> getCharacteristics() {
1618
return characteristics;
1719
}
1820

android/src/main/java/com/polidea/flutter_ble_lib/FlutterBleLibPlugin.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.polidea.flutter_ble_lib;
22

33
import android.content.Context;
4-
import android.support.annotation.NonNull;
54
import android.util.Log;
65

76
import com.polidea.flutter_ble_lib.constant.ArgumentKey;
@@ -10,6 +9,7 @@
109
import com.polidea.flutter_ble_lib.delegate.BluetoothStateDelegate;
1110
import com.polidea.flutter_ble_lib.delegate.CallDelegate;
1211
import com.polidea.flutter_ble_lib.delegate.CharacteristicsDelegate;
12+
import com.polidea.flutter_ble_lib.delegate.DescriptorsDelegate;
1313
import com.polidea.flutter_ble_lib.delegate.DeviceConnectionDelegate;
1414
import com.polidea.flutter_ble_lib.delegate.DevicesDelegate;
1515
import com.polidea.flutter_ble_lib.delegate.LogLevelDelegate;
@@ -31,6 +31,7 @@
3131
import java.util.LinkedList;
3232
import java.util.List;
3333

34+
import androidx.annotation.NonNull;
3435
import io.flutter.plugin.common.EventChannel;
3536
import io.flutter.plugin.common.MethodCall;
3637
import io.flutter.plugin.common.MethodChannel;
@@ -86,6 +87,7 @@ private void setupAdapter(Context context) {
8687
delegates.add(new MtuDelegate(bleAdapter));
8788
delegates.add(new CharacteristicsDelegate(bleAdapter, characteristicsMonitorStreamHandler));
8889
delegates.add(new DevicesDelegate(bleAdapter));
90+
delegates.add(new DescriptorsDelegate(bleAdapter));
8991
}
9092

9193
@Override

android/src/main/java/com/polidea/flutter_ble_lib/MultiCharacteristicsResponse.java

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,35 @@
33
import com.polidea.multiplatformbleadapter.Characteristic;
44
import com.polidea.multiplatformbleadapter.Service;
55

6+
import java.util.List;
67
import java.util.UUID;
78

89
public class MultiCharacteristicsResponse {
9-
private final Characteristic[] characteristics;
10-
private Service service;
10+
private final List<Characteristic> characteristics;
11+
private int serviceId;
12+
private UUID serviceUuid;
1113

12-
public MultiCharacteristicsResponse(Characteristic[] characteristics, Service service) {
14+
public MultiCharacteristicsResponse(List<Characteristic> characteristics, Service service) {
1315
this.characteristics = characteristics;
14-
this.service = service;
16+
this.serviceId = service.getId();
17+
this.serviceUuid = service.getUuid();
1518
}
1619

17-
public Characteristic[] getCharacteristics() {
20+
public MultiCharacteristicsResponse(List<Characteristic> characteristics, int serviceId, UUID serviceUuid) {
21+
this.characteristics = characteristics;
22+
this.serviceId = serviceId;
23+
this.serviceUuid = serviceUuid;
24+
}
25+
26+
public List<Characteristic> getCharacteristics() {
1827
return characteristics;
1928
}
2029

21-
public Service getService() {
22-
return service;
30+
public int getServiceId() {
31+
return serviceId;
32+
}
33+
34+
public UUID getServiceUuid() {
35+
return serviceUuid;
2336
}
2437
}

android/src/main/java/com/polidea/flutter_ble_lib/SafeMainThreadResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import java.util.concurrent.atomic.AtomicBoolean;
1111

12-
public class SafeMainThreadResolver<T> {
12+
public class SafeMainThreadResolver<T> implements OnSuccessCallback<T>, OnErrorCallback {
1313

1414
private OnErrorCallback onErrorCallback = null;
1515
private OnSuccessCallback<T> onSuccessCallback = null;

android/src/main/java/com/polidea/flutter_ble_lib/constant/ArgumentKey.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public interface ArgumentKey {
2121
String SERVICE_IDENTIFIER = "serviceId";
2222
String CHARACTERISTIC_UUID = "characteristicUuid";
2323
String CHARACTERISTIC_IDENTIFIER = "characteristicIdentifier";
24+
String DESCRIPTOR_UUID = "descriptorUuid";
25+
String DESCRIPTOR_IDENTIFIER = "descriptorIdentifier";
2426
String VALUE = "value";
2527
String WITH_RESPONSE = "withResponse";
2628

android/src/main/java/com/polidea/flutter_ble_lib/constant/MethodName.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public interface MethodName {
2323
String GET_SERVICES = "services";
2424
String GET_CHARACTERISTICS = "characteristics";
2525
String GET_CHARACTERISTICS_FOR_SERVICE = "characteristicsForService";
26+
String GET_DESCRIPTORS_FOR_DEVICE = "descriptorsForDevice";
27+
String GET_DESCRIPTORS_FOR_CHARACTERISTIC = "descriptorsForCharacteristic";
28+
String GET_DESCRIPTORS_FOR_SERVICE = "descriptorsForService";
2629

2730
String LOG_LEVEL = "logLevel";
2831
String SET_LOG_LEVEL = "setLogLevel";
@@ -45,4 +48,14 @@ public interface MethodName {
4548
String MONITOR_CHARACTERISTIC_FOR_IDENTIFIER = "monitorCharacteristicForIdentifier";
4649
String MONITOR_CHARACTERISTIC_FOR_DEVICE = "monitorCharacteristicForDevice";
4750
String MONITOR_CHARACTERISTIC_FOR_SERVICE = "monitorCharacteristicForService";
51+
52+
String READ_DESCRIPTOR_FOR_IDENTIFIER = "readDescriptorForIdentifier";
53+
String READ_DESCRIPTOR_FOR_CHARACTERISTIC = "readDescriptorForCharacteristic";
54+
String READ_DESCRIPTOR_FOR_SERVICE = "readDescriptorForService";
55+
String READ_DESCRIPTOR_FOR_DEVICE = "readDescriptorForDevice";
56+
57+
String WRITE_DESCRIPTOR_FOR_IDENTIFIER = "writeDescriptorForIdentifier";
58+
String WRITE_DESCRIPTOR_FOR_CHARACTERISTIC = "writeDescriptorForCharacteristic";
59+
String WRITE_DESCRIPTOR_FOR_SERVICE = "writeDescriptorForService";
60+
String WRITE_DESCRIPTOR_FOR_DEVICE = "writeDescriptorForDevice";
4861
}

android/src/main/java/com/polidea/flutter_ble_lib/converter/BleErrorJsonConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.polidea.flutter_ble_lib.converter;
22

3-
import android.support.annotation.Nullable;
43

54
import com.polidea.multiplatformbleadapter.errors.BleError;
65

76
import org.json.JSONException;
87
import org.json.JSONObject;
98

9+
import androidx.annotation.Nullable;
10+
1011
public class BleErrorJsonConverter implements JsonConverter<BleError> {
1112

1213
public static final int MAX_ATT_ERROR = 0x80;

android/src/main/java/com/polidea/flutter_ble_lib/converter/CharacteristicJsonConverter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.json.JSONException;
88
import org.json.JSONObject;
99

10+
import java.util.List;
11+
1012
public class CharacteristicJsonConverter implements JsonConverter<Characteristic> {
1113

1214
private interface Metadata {
@@ -25,11 +27,11 @@ public String toJson(Characteristic characteristic) throws JSONException {
2527
return toJsonObject(characteristic).toString();
2628
}
2729

28-
public String toJson(Characteristic[] characteristics) throws JSONException {
30+
public String toJson(List<Characteristic> characteristics) throws JSONException {
2931
return toJsonArray(characteristics).toString();
3032
}
3133

32-
public JSONArray toJsonArray(Characteristic[] characteristics) throws JSONException {
34+
public JSONArray toJsonArray(List<Characteristic> characteristics) throws JSONException {
3335
JSONArray jsonArray = new JSONArray();
3436
for (Characteristic characteristic : characteristics) {
3537
jsonArray.put(toJsonObject(characteristic));

android/src/main/java/com/polidea/flutter_ble_lib/converter/CharacteristicsResponseJsonConverter.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

android/src/main/java/com/polidea/flutter_ble_lib/converter/ConnectionStateChangeJsonConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.polidea.flutter_ble_lib.converter;
22

3-
import android.support.annotation.Nullable;
43

54
import com.polidea.flutter_ble_lib.ConnectionStateChange;
65

76
import org.json.JSONException;
87
import org.json.JSONObject;
98

9+
import androidx.annotation.Nullable;
10+
1011
public class ConnectionStateChangeJsonConverter implements JsonConverter<ConnectionStateChange> {
1112

1213
private interface Metadata {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.polidea.flutter_ble_lib.converter;
2+
3+
import com.polidea.multiplatformbleadapter.Descriptor;
4+
import com.polidea.multiplatformbleadapter.utils.Base64Converter;
5+
6+
import org.json.JSONException;
7+
import org.json.JSONObject;
8+
9+
public class DescriptorJsonConverter implements JsonConverter<Descriptor> {
10+
11+
12+
private interface Metadata {
13+
String SERVICE_UUID = "serviceUuid";
14+
String SERVICE_ID = "serviceId";
15+
String CHARACTERISTIC_UUID = "characteristicUuid";
16+
String CHARACTERISTIC_ID = "id";
17+
String DESCRIPTOR_UUID = "descriptorUuid";
18+
String DESCRIPTOR_ID = "descriptorId";
19+
String DESCRIPTOR_VALUE = "value";
20+
}
21+
22+
@Override
23+
public String toJson(Descriptor descriptor) throws JSONException {
24+
JSONObject jsonObject = toJsonObject(descriptor);
25+
26+
jsonObject.put(Metadata.SERVICE_ID, descriptor.getServiceId());
27+
jsonObject.put(Metadata.SERVICE_UUID, descriptor.getServiceUuid());
28+
jsonObject.put(Metadata.CHARACTERISTIC_ID, descriptor.getCharacteristicId());
29+
jsonObject.put(Metadata.CHARACTERISTIC_UUID, descriptor.getCharacteristicUuid());
30+
31+
return jsonObject.toString();
32+
}
33+
34+
public JSONObject toJsonObject(Descriptor descriptor) throws JSONException {
35+
JSONObject jsonObject = new JSONObject();
36+
37+
38+
jsonObject.put(Metadata.DESCRIPTOR_ID, descriptor.getId());
39+
jsonObject.put(Metadata.DESCRIPTOR_UUID, descriptor.getUuid());
40+
jsonObject.put(Metadata.DESCRIPTOR_VALUE,
41+
descriptor.getValue() != null ?
42+
Base64Converter.encode(descriptor.getValue())
43+
: JSONObject.NULL);
44+
45+
return jsonObject;
46+
}
47+
}

android/src/main/java/com/polidea/flutter_ble_lib/converter/DevicesResultJsonConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.polidea.flutter_ble_lib.converter;
22

3-
import android.support.annotation.Nullable;
43
import android.util.Log;
54

65
import com.polidea.multiplatformbleadapter.Device;
@@ -9,6 +8,8 @@
98
import org.json.JSONException;
109
import org.json.JSONObject;
1110

11+
import androidx.annotation.Nullable;
12+
1213
public class DevicesResultJsonConverter implements JsonConverter<Device[]> {
1314

1415
public static String TAG = DevicesResultJsonConverter.class.getName();

0 commit comments

Comments
 (0)