Skip to content

Commit

Permalink
Update to v2.8.1
Browse files Browse the repository at this point in the history
Fix for specific android phones.
  • Loading branch information
perssonmagnus committed Oct 18, 2019
1 parent d97773b commit a0bf7ab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "com.ublox.BLE"
minSdkVersion 18
targetSdkVersion 28
versionCode 15
versionName "2.8"
versionCode 16
versionName "2.8.1"
vectorDrawables.useSupportLibrary = true

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/ublox/BLE/services/BluetoothLeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.RequiresApi;
import android.util.Log;

Expand Down Expand Up @@ -274,6 +275,7 @@ public boolean connect(BluetoothDeviceRepresentation device) {
if (address.equals(mBluetoothDeviceAddress) && mBluetoothGatt != null) {
if (mBluetoothGatt.connect()) {
mConnectionState = STATE_CONNECTING;
scheduleTimeoutAbort();
return true;
} else {
return false;
Expand All @@ -283,9 +285,20 @@ public boolean connect(BluetoothDeviceRepresentation device) {
mBluetoothGatt = device.connectGatt(mContext, mGattCallback, supports2MPhy);
mBluetoothDeviceAddress = address;
mConnectionState = STATE_CONNECTING;
scheduleTimeoutAbort();
return true;
}

private void scheduleTimeoutAbort() {
final long STANDARD_ANDROID_TIMEOUT_MILLIS = 30000;
new Handler(Looper.getMainLooper()).postDelayed(() -> {
if (mConnectionState != STATE_CONNECTING) return;
close();
mConnectionState = STATE_DISCONNECTED;
broadcastUpdate(ACTION_GATT_DISCONNECTED);
}, STANDARD_ANDROID_TIMEOUT_MILLIS);
}

/**
* Disconnects an existing connection or cancel a pending connection. The disconnection result
* is reported asynchronously through the
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/ublox/BLE/utils/UBloxDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public BluetoothGattRepresentation connectGatt(Context context, BluetoothGattCal
BluetoothGatt gatt;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (phy2M) {
gatt = device.connectGatt(context, false, callback, TRANSPORT_LE,PHY_LE_CODED_MASK ^ PHY_LE_2M_MASK);
gatt = device.connectGatt(context, false, callback, TRANSPORT_LE,PHY_LE_CODED_MASK ^ PHY_LE_2M_MASK ^ PHY_LE_1M_MASK);
} else {
gatt = device.connectGatt(context, false, callback, TRANSPORT_LE,PHY_LE_CODED_MASK ^ PHY_LE_1M_MASK);
}
Expand Down

0 comments on commit a0bf7ab

Please sign in to comment.