Skip to content

Commit

Permalink
Merge pull request NordicSemiconductor#225 from NordicSemiconductor/d…
Browse files Browse the repository at this point in the history
…evelop

Version 2.2.4
  • Loading branch information
philips77 authored Aug 12, 2020
2 parents 9ef7fcc + 5f9672a commit 1b836ad
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,19 @@ The library may be found on jcenter and Maven Central repository.
Add it to your project by adding the following dependency:

```grovy
implementation 'no.nordicsemi.android:ble:2.2.3'
implementation 'no.nordicsemi.android:ble:2.2.4'
```
The last version not migrated to AndroidX is 2.0.5.

To import the BLE library with set of parsers for common Bluetooth SIG characteristics, use:
```grovy
implementation 'no.nordicsemi.android:ble-common:2.2.3'
implementation 'no.nordicsemi.android:ble-common:2.2.4'
```
For more information, read [this](BLE-COMMON.md).

An extension for easier integration with `LiveData` is available after adding:
```grovy
implementation 'no.nordicsemi.android:ble-livedata:2.2.3'
implementation 'no.nordicsemi.android:ble-livedata:2.2.4'
```
This extension adds `ObservableBleManager` with `state` and `bondingState` properties, which
notify about connection and bond state using `androidx.lifecycle.LiveData`.
Expand Down
37 changes: 21 additions & 16 deletions ble/src/main/java/no/nordicsemi/android/ble/BleManagerHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -535,11 +535,13 @@ private boolean internalConnect(@NonNull final BluetoothDevice device,
return true;
}
} else {
// Register bonding broadcast receiver
context.registerReceiver(bluetoothStateBroadcastReceiver,
new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
context.registerReceiver(mBondingBroadcastReceiver,
new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED));
if (connectRequest != null) {
// Register bonding broadcast receiver
context.registerReceiver(bluetoothStateBroadcastReceiver,
new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
context.registerReceiver(mBondingBroadcastReceiver,
new IntentFilter(BluetoothDevice.ACTION_BOND_STATE_CHANGED));
}
}
}

Expand Down Expand Up @@ -587,34 +589,37 @@ private boolean internalDisconnect() {
initialConnection = false;
ready = false;

if (bluetoothGatt != null) {
final BluetoothGatt gatt = bluetoothGatt;
if (gatt != null) {
final boolean wasConnected = connected;
connectionState = BluetoothGatt.STATE_DISCONNECTING;
log(Log.VERBOSE, connected ? "Disconnecting..." : "Cancelling connection...");
final BluetoothDevice device = bluetoothGatt.getDevice();
if (connected) {
log(Log.VERBOSE, wasConnected ? "Disconnecting..." : "Cancelling connection...");
final BluetoothDevice device = gatt.getDevice();
if (wasConnected) {
postCallback(c -> c.onDeviceDisconnecting(device));
postConnectionStateChange(o -> o.onDeviceDisconnecting(device));
}
log(Log.DEBUG, "gatt.disconnect()");
bluetoothGatt.disconnect();
final boolean wasConnected = connected;
gatt.disconnect();
if (wasConnected)
return true;

// If the device wasn't connected, there will be no callback after calling
// gatt.disconnect(), the connection attempt will be stopped.
connectionState = BluetoothGatt.STATE_DISCONNECTED;
log(Log.INFO, "Disconnected");
close();
postCallback(c -> c.onDeviceDisconnected(device));
postConnectionStateChange(o -> o.onDeviceDisconnected(device, ConnectionObserver.REASON_SUCCESS));
}
// request may be of type DISCONNECT or CONNECT (timeout).
// For the latter, it has already been notified with REASON_TIMEOUT.
if (request != null && request.type == Request.Type.DISCONNECT) {
if (bluetoothDevice != null)
request.notifySuccess(bluetoothDevice);
final Request r = request;
if (r != null && r.type == Request.Type.DISCONNECT) {
if (bluetoothDevice != null || gatt != null)
r.notifySuccess(bluetoothDevice != null ? bluetoothDevice : gatt.getDevice());
else
request.notifyInvalidRequest();
r.notifyInvalidRequest();
}
nextRequest(true);
return true;
Expand Down Expand Up @@ -3211,7 +3216,7 @@ private synchronized void nextRequest(final boolean force) {
// on the device, or the feature is not supported on the Android.
// In that case, proceed with next operation and ignore the one that failed.
if (!result) {
this.request.notifyFail(bluetoothDevice,
request.notifyFail(bluetoothDevice,
connected ?
FailCallback.REASON_NULL_ATTRIBUTE :
BluetoothAdapter.getDefaultAdapter().isEnabled() ?
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# org.gradle.parallel=true
android.useAndroidX=true

VERSION_NAME=2.2.3
VERSION_NAME=2.2.4
GROUP=no.nordicsemi.android

POM_DESCRIPTION=Bluetooth Low Energy library for Android
Expand Down

0 comments on commit 1b836ad

Please sign in to comment.