Scanner bug fixed for Lollipop.

This commit is contained in:
Aleksander Nowakowski 2015-06-23 13:15:46 +02:00
parent 5a3763506a
commit d420cc2044
3 changed files with 17 additions and 12 deletions

View File

@ -1740,9 +1740,13 @@ public abstract class DfuBaseService extends IntentService {
* We could have save the fact of jumping as a parameter of the service but it ma be that some Android devices must first scan a device before connecting to it. * We could have save the fact of jumping as a parameter of the service but it ma be that some Android devices must first scan a device before connecting to it.
* It a device with the address+1 has never been detected before the service could have failed on connection. * It a device with the address+1 has never been detected before the service could have failed on connection.
*/ */
sendLogBroadcast(LOG_LEVEL_VERBOSE, "Scanning for the DFU bootloader..."); sendLogBroadcast(LOG_LEVEL_VERBOSE, "Scanning for the DFU Bootloader...");
final String newAddress = BootloaderScannerFactory.getScanner().searchFor(mDeviceAddress); final String newAddress = BootloaderScannerFactory.getScanner().searchFor(mDeviceAddress);
sendLogBroadcast(LOG_LEVEL_INFO, "The Bootloader found (" + newAddress + ")"); if (newAddress != null)
sendLogBroadcast(LOG_LEVEL_INFO, "DFU Bootloader found with address " + newAddress);
else {
sendLogBroadcast(LOG_LEVEL_INFO, "DFU Bootloader not found. Trying the same address...");
}
/* /*
* The current service instance has uploaded the Soft Device and/or Bootloader. * The current service instance has uploaded the Soft Device and/or Bootloader.
@ -1753,6 +1757,7 @@ public abstract class DfuBaseService extends IntentService {
newIntent.fillIn(intent, Intent.FILL_IN_COMPONENT | Intent.FILL_IN_PACKAGE); newIntent.fillIn(intent, Intent.FILL_IN_COMPONENT | Intent.FILL_IN_PACKAGE);
newIntent.putExtra(EXTRA_FILE_MIME_TYPE, MIME_TYPE_ZIP); // ensure this is set (e.g. for scripts) newIntent.putExtra(EXTRA_FILE_MIME_TYPE, MIME_TYPE_ZIP); // ensure this is set (e.g. for scripts)
newIntent.putExtra(EXTRA_FILE_TYPE, TYPE_APPLICATION); // set the type to application only newIntent.putExtra(EXTRA_FILE_TYPE, TYPE_APPLICATION); // set the type to application only
if (newAddress != null)
newIntent.putExtra(EXTRA_DEVICE_ADDRESS, newAddress); newIntent.putExtra(EXTRA_DEVICE_ADDRESS, newAddress);
newIntent.putExtra(EXTRA_PART_CURRENT, mPartCurrent + 1); newIntent.putExtra(EXTRA_PART_CURRENT, mPartCurrent + 1);
newIntent.putExtra(EXTRA_PARTS_TOTAL, mPartsTotal); newIntent.putExtra(EXTRA_PARTS_TOTAL, mPartsTotal);

View File

@ -37,7 +37,7 @@ public interface BootloaderScanner {
/** /**
* After the buttonless jump from the application mode to the bootloader mode the service will wait this long for the advertising bootloader (in milliseconds). * After the buttonless jump from the application mode to the bootloader mode the service will wait this long for the advertising bootloader (in milliseconds).
*/ */
public final static long TIMEOUT = 2000l; // ms public final static long TIMEOUT = 5000l; // ms
/** The bootloader may advertise with the same address or one with the last byte incremented by this value. F.e. 00:11:22:33:44:55 -> 00:11:22:33:44:56. FF changes to 00. */ /** The bootloader may advertise with the same address or one with the last byte incremented by this value. F.e. 00:11:22:33:44:55 -> 00:11:22:33:44:56. FF changes to 00. */
public final static int ADDRESS_DIFF = 1; public final static int ADDRESS_DIFF = 1;

View File

@ -22,14 +22,10 @@
package no.nordicsemi.android.dfu.scanner; package no.nordicsemi.android.dfu.scanner;
import java.util.ArrayList;
import java.util.List;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.bluetooth.le.BluetoothLeScanner; import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback; import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanFilter;
import android.bluetooth.le.ScanResult; import android.bluetooth.le.ScanResult;
import android.bluetooth.le.ScanSettings; import android.bluetooth.le.ScanSettings;
import android.os.Build; import android.os.Build;
@ -81,11 +77,15 @@ public class BootloaderScannerLollipop extends ScanCallback implements Bootloade
final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
final BluetoothLeScanner scanner = adapter.getBluetoothLeScanner(); final BluetoothLeScanner scanner = adapter.getBluetoothLeScanner();
final List<ScanFilter> filters = new ArrayList<>(); /*
filters.add(new ScanFilter.Builder().setDeviceAddress(mDeviceAddress).build()); * Scanning with filters does not work on Nexus 9 (Android 5.1). No devices are found and scanner terminates on timeout.
filters.add(new ScanFilter.Builder().setDeviceAddress(mDeviceAddressIncremented).build()); * We will match the device address in the callback method instead. It's not like it should be, but at least it works.
*/
//final List<ScanFilter> filters = new ArrayList<>();
//filters.add(new ScanFilter.Builder().setDeviceAddress(mDeviceAddress).build());
//filters.add(new ScanFilter.Builder().setDeviceAddress(mDeviceAddressIncremented).build());
final ScanSettings settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build(); final ScanSettings settings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build();
scanner.startScan(filters, settings, this); scanner.startScan(/*filters*/ null, settings, this);
try { try {
synchronized (mLock) { synchronized (mLock) {