@@ -809,6 +809,11 @@ public void onReceive(final Context context, final Intent intent) {
809
809
mConnectionState = STATE_DISCONNECTED ;
810
810
if (mDfuServiceImpl != null )
811
811
mDfuServiceImpl .getGattCallback ().onDisconnected ();
812
+
813
+ // Notify waiting thread
814
+ synchronized (mLock ) {
815
+ mLock .notifyAll ();
816
+ }
812
817
}
813
818
}
814
819
};
@@ -1465,7 +1470,7 @@ private InputStream openInputStream(@NonNull final Uri stream, final String mime
1465
1470
final String [] projection = {MediaStore .Images .Media .DISPLAY_NAME };
1466
1471
final Cursor cursor = getContentResolver ().query (stream , projection , null , null , null );
1467
1472
try {
1468
- if (cursor .moveToNext ()) {
1473
+ if (cursor != null && cursor .moveToNext ()) {
1469
1474
final String fileName = cursor .getString (0 /* DISPLAY_NAME*/ );
1470
1475
1471
1476
if (fileName .toLowerCase (Locale .US ).endsWith ("hex" ))
@@ -1517,8 +1522,20 @@ protected BluetoothGatt connect(@NonNull final String address) {
1517
1522
1518
1523
logi ("Connecting to the device..." );
1519
1524
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
+ }
1522
1539
1523
1540
// We have to wait until the device is connected and services are discovered
1524
1541
// Connection error may occur as well.
0 commit comments