Skip to content

Commit 6203896

Browse files
committed
1 parent 852a51f commit 6203896

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

dfu/src/main/java/no/nordicsemi/android/dfu/DfuBaseService.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,11 @@ public void onReceive(final Context context, final Intent intent) {
809809
mConnectionState = STATE_DISCONNECTED;
810810
if (mDfuServiceImpl != null)
811811
mDfuServiceImpl.getGattCallback().onDisconnected();
812+
813+
// Notify waiting thread
814+
synchronized (mLock) {
815+
mLock.notifyAll();
816+
}
812817
}
813818
}
814819
};
@@ -1465,7 +1470,7 @@ private InputStream openInputStream(@NonNull final Uri stream, final String mime
14651470
final String[] projection = {MediaStore.Images.Media.DISPLAY_NAME};
14661471
final Cursor cursor = getContentResolver().query(stream, projection, null, null, null);
14671472
try {
1468-
if (cursor.moveToNext()) {
1473+
if (cursor != null && cursor.moveToNext()) {
14691474
final String fileName = cursor.getString(0 /* DISPLAY_NAME*/);
14701475

14711476
if (fileName.toLowerCase(Locale.US).endsWith("hex"))
@@ -1517,8 +1522,20 @@ protected BluetoothGatt connect(@NonNull final String address) {
15171522

15181523
logi("Connecting to the device...");
15191524
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
1520-
sendLogBroadcast(LOG_LEVEL_DEBUG, "gatt = device.connectGatt(autoConnect = false)");
1521-
final BluetoothGatt gatt = device.connectGatt(this, false, mGattCallback);
1525+
BluetoothGatt gatt;
1526+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
1527+
sendLogBroadcast(LOG_LEVEL_DEBUG, "gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE, preferredPhy = LE_1M | LE_2M)");
1528+
gatt = device.connectGatt(this, false, mGattCallback,
1529+
BluetoothDevice.TRANSPORT_LE,
1530+
BluetoothDevice.PHY_LE_1M_MASK | BluetoothDevice.PHY_LE_2M_MASK);
1531+
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
1532+
sendLogBroadcast(LOG_LEVEL_DEBUG, "gatt = device.connectGatt(autoConnect = false, TRANSPORT_LE)");
1533+
gatt = device.connectGatt(this, false, mGattCallback,
1534+
BluetoothDevice.TRANSPORT_LE);
1535+
} else {
1536+
sendLogBroadcast(LOG_LEVEL_DEBUG, "gatt = device.connectGatt(autoConnect = false)");
1537+
gatt = device.connectGatt(this, false, mGattCallback);
1538+
}
15221539

15231540
// We have to wait until the device is connected and services are discovered
15241541
// Connection error may occur as well.

0 commit comments

Comments
 (0)