android.bluetooth.le.ScanFilter Java Examples

The following examples show how to use android.bluetooth.le.ScanFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScanFilterCompat.java    From AndroidBleManager with Apache License 2.0 8 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ScanFilter toApi21() {
    ScanFilter.Builder builder = new ScanFilter.Builder();
    if (mDeviceName != null) {
        builder.setDeviceName(mDeviceName);
    }
    if (mServiceUuid != null) {
        builder.setServiceUuid(mServiceUuid, mServiceUuidMask);
    }
    if (mDeviceAddress != null) {
        builder.setDeviceAddress(mDeviceAddress);
    }
    if (mServiceDataUuid != null) {
        builder.setServiceData(mServiceDataUuid, mServiceData, mServiceDataMask);
    }
    if (mManufacturerId < 0) {
        builder.setManufacturerData(mManufacturerId, mManufacturerData, mManufacturerDataMask);
    }
    return builder.build();
}
 
Example #2
Source File: BluetoothCentral.java    From blessed-android with MIT License 8 votes vote down vote up
/**
 * Scan for peripherals that have any of the specified peripheral mac addresses.
 *
 * @param peripheralAddresses array of peripheral mac addresses to scan for
 */
public void scanForPeripheralsWithAddresses(final String[] peripheralAddresses) {
    List<ScanFilter> filters = null;
    if (peripheralAddresses != null) {
        filters = new ArrayList<>();
        for (String address : peripheralAddresses) {
            if (BluetoothAdapter.checkBluetoothAddress(address)) {
                ScanFilter filter = new ScanFilter.Builder()
                        .setDeviceAddress(address)
                        .build();
                filters.add(filter);
            } else {
                Timber.e("%s is not a valid address. Make sure all alphabetic characters are uppercase.", address);
            }
        }
    }

    startScan(filters, scanSettings, scanByServiceUUIDCallback);
}
 
Example #3
Source File: LollipopScanner.java    From RxCentralBle with Apache License 2.0 7 votes vote down vote up
private void startScan(PublishSubject scanDataSubject) {
  BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
  if (adapter != null && adapter.isEnabled()) {
    // Setting service uuid scan filter failing on Galaxy S6 on Android 7.
    // Other devices and versions of Android have additional issues with Scan Filters.
    // Manually filter on scan operation.  Add a dummy filter to avoid Android 8.1+ enforcement
    // of filters during background scanning.
    List<ScanFilter> filters = new ArrayList<>();
    ScanFilter.Builder scanFilterBuilder = new ScanFilter.Builder();
    filters.add(scanFilterBuilder.build());

    ScanSettings.Builder settingsBuilder = new ScanSettings.Builder();
    settingsBuilder.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY);

    BluetoothLeScanner bleScanner = adapter.getBluetoothLeScanner();
    if (bleScanner != null) {
      bleScanner.startScan(filters, settingsBuilder.build(), scanCallback);
    } else {
      if (RxCentralLogger.isError()) {
        RxCentralLogger.error("startScan - BluetoothLeScanner is null!");
      }

      scanDataSubject.onError(new ConnectionError(SCAN_FAILED));
    }
  } else {
    if (RxCentralLogger.isError()) {
      if (adapter == null) {
        RxCentralLogger.error("startScan - Default Bluetooth Adapter is null!");
      } else {
        RxCentralLogger.error("startScan - Bluetooth Adapter is disabled.");
      }
    }

    scanDataSubject.onError(new ConnectionError(SCAN_FAILED));
  }

}
 
Example #4
Source File: MainActivity.java    From AndroidDemoProjects with Apache License 2.0 6 votes vote down vote up
private void discover() {
    List<ScanFilter> filters = new ArrayList<ScanFilter>();

    ScanFilter filter = new ScanFilter.Builder()
            .setServiceUuid( new ParcelUuid(UUID.fromString( getString(R.string.ble_uuid ) ) ) )
            .build();
    filters.add( filter );

    ScanSettings settings = new ScanSettings.Builder()
            .setScanMode( ScanSettings.SCAN_MODE_LOW_LATENCY )
            .build();

    mBluetoothLeScanner.startScan(filters, settings, mScanCallback);

    mHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            mBluetoothLeScanner.stopScan(mScanCallback);
        }
    }, 10000);
}
 
Example #5
Source File: EddystoneScannerService.java    From nearby-beacons with MIT License 6 votes vote down vote up
private void startScanning() {
    List<ScanFilter> filters = new ArrayList<>();
    //Filter on just our requested namespaces
    for (String namespace : NAMESPACE_IDS) {
        ScanFilter beaconFilter = new ScanFilter.Builder()
                .setServiceUuid(UID_SERVICE)
                .setServiceData(UID_SERVICE, getNamespaceFilter(namespace),
                        NAMESPACE_FILTER_MASK)
                .build();
        filters.add(beaconFilter);
    }

    //Run in background mode
    ScanSettings settings = new ScanSettings.Builder()
            .setScanMode(ScanSettings.SCAN_MODE_LOW_POWER)
            .build();

    mBluetoothLeScanner.startScan(filters, settings, mScanCallback);
    if (DEBUG_SCAN) Log.d(TAG, "Scanning started…");
}
 
Example #6
Source File: BleScanner.java    From esp-idf-provisioning-android with Apache License 2.0 6 votes vote down vote up
/**
 * This method is used to start BLE scan.
 */
@RequiresPermission(allOf = {Manifest.permission.BLUETOOTH, Manifest.permission.BLUETOOTH_ADMIN})
public void startScan() {

    if (!bluetoothAdapter.isEnabled()) {
        bleScanListener.scanStartFailed();
        return;
    }
    Log.d(TAG, "Starting BLE device scanning...");

    bluetoothLeScanner = bluetoothAdapter.getBluetoothLeScanner();
    List<ScanFilter> filters = new ArrayList<>();
    ScanSettings settings = new ScanSettings.Builder()
            .setScanMode(ScanSettings.SCAN_MODE_BALANCED)
            .build();

    isScanning = true;
    bluetoothLeScanner.startScan(filters, settings, scanCallback);
    handler.postDelayed(stopScanTask, SCAN_TIME_OUT);
}
 
Example #7
Source File: BluetoothLeDeviceFilter.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private BluetoothLeDeviceFilter(Pattern namePattern, ScanFilter scanFilter,
        byte[] rawDataFilter, byte[] rawDataFilterMask, String renamePrefix,
        String renameSuffix, int renameBytesFrom, int renameBytesLength,
        int renameNameFrom, int renameNameLength, boolean renameBytesReverseOrder) {
    mNamePattern = namePattern;
    mScanFilter = ObjectUtils.firstNotNull(scanFilter, ScanFilter.EMPTY);
    mRawDataFilter = rawDataFilter;
    mRawDataFilterMask = rawDataFilterMask;
    mRenamePrefix = renamePrefix;
    mRenameSuffix = renameSuffix;
    mRenameBytesFrom = renameBytesFrom;
    mRenameBytesLength = renameBytesLength;
    mRenameNameFrom = renameNameFrom;
    mRenameNameLength = renameNameLength;
    mRenameBytesReverseOrder = renameBytesReverseOrder;
}
 
Example #8
Source File: MockLollipopScanner.java    From bitgatt with Mozilla Public License 2.0 6 votes vote down vote up
private boolean isSettingsAndFilterComboAllowed(ScanSettings settings,
                                                List<ScanFilter> filterList) {
    final int callbackType = settings.getCallbackType();
    // If onlost/onfound is requested, a non-empty filter is expected
    if ((callbackType & (ScanSettings.CALLBACK_TYPE_FIRST_MATCH
        | ScanSettings.CALLBACK_TYPE_MATCH_LOST)) != 0) {
        if (filterList == null) {
            return false;
        }
        for (ScanFilter filter : filterList) {
            if (filter.equals(EMPTY)) {
                return false;
            }
        }
    }
    return true;
}
 
Example #9
Source File: ScanFilterCompat.java    From EFRConnect-android with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ScanFilter createScanFilter() {
    ScanFilter.Builder builder = new ScanFilter.Builder()
            .setDeviceAddress(deviceAddress)
            .setDeviceName(deviceName);

    if (serviceUuid != null) {
        builder.setServiceUuid(serviceUuid, serviceUuidMask);
    }
    if (serviceDataUuid != null) {
        builder.setServiceData(serviceDataUuid, serviceData, serviceDataMask);
    }
    if (manufacturerId >= 0) {
        builder.setManufacturerData(manufacturerId, manufacturerData, manufacturerDataMask);
    }

    return builder.build();
}
 
Example #10
Source File: MockLollipopScanner.java    From bitgatt with Mozilla Public License 2.0 6 votes vote down vote up
public BleScanCallbackWrapper(IBluetoothGatt bluetoothGatt,
                              List<ScanFilter> filters, ScanSettings settings,
                              WorkSource workSource, ScanCallback scanCallback,
                              List<List<ResultStorageDescriptor>> resultStorages) {
    mBluetoothGatt = bluetoothGatt;
    mFilters = filters;
    mSettings = settings;
    mWorkSource = workSource;
    mScanCallback = scanCallback;
    mScannerId = 0;
    mResultStorages = resultStorages;
}
 
Example #11
Source File: PeripheralScannerTest.java    From bitgatt with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testStartPendingIntentScanNotPeriodicalScan() {
    assertFalse(FitbitGatt.getInstance().getPeripheralScanner().isScanning());
    assertFalse(FitbitGatt.getInstance().getPeripheralScanner().isPendingIntentScanning());
    FitbitGatt.getInstance().getPeripheralScanner().setDeviceNameFilters(names);
    ArrayList<ScanFilter> filters = new ArrayList<>();
    for (String name : names) {
        filters.add(new ScanFilter.Builder().setDeviceName(name).build());
    }
    FitbitGatt.getInstance().getPeripheralScanner().startPendingIntentBasedBackgroundScan(filters, appContext);
    CountDownLatch cdl = new CountDownLatch(1);
    handler.postDelayed(() -> {
        assertFalse(FitbitGatt.getInstance().getPeripheralScanner().isScanning());
        cdl.countDown();
    }, 300);
    verifyCountDown(cdl);
}
 
Example #12
Source File: PeripheralScannerTest.java    From bitgatt with Mozilla Public License 2.0 6 votes vote down vote up
@Test
public void testStartPendingIntentScanNotHighPriorityScan() {
    assertFalse(FitbitGatt.getInstance().getPeripheralScanner().isScanning());
    assertFalse(FitbitGatt.getInstance().getPeripheralScanner().isPendingIntentScanning());
    FitbitGatt.getInstance().getPeripheralScanner().setDeviceNameFilters(names);
    ArrayList<ScanFilter> filters = new ArrayList<>();
    for (String name : names) {
        filters.add(new ScanFilter.Builder().setDeviceName(name).build());
    }
    FitbitGatt.getInstance().getPeripheralScanner().startPendingIntentBasedBackgroundScan(filters, appContext);
    CountDownLatch cdl = new CountDownLatch(1);
    handler.postDelayed(() -> {
        assertFalse(FitbitGatt.getInstance().getPeripheralScanner().isScanning());
        cdl.countDown();
    }, 300);
    verifyCountDown(cdl);
}
 
Example #13
Source File: BluetoothGlucoseMeter.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private void beginScan() {
    if (Build.VERSION.SDK_INT >= 21) {
        if (d) Log.d(TAG, "Preparing for scan...");

        // set up v21 scanner
        mLEScanner = mBluetoothAdapter.getBluetoothLeScanner();
        settings = new ScanSettings.Builder()
                .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
                .build();
        filters = new ArrayList<>();

        filters.add(new ScanFilter.Builder().setServiceUuid(new ParcelUuid(GLUCOSE_SERVICE)).build());
    }
    // all api versions
    scanLeDevice(true);
}
 
Example #14
Source File: BluetoothCentral.java    From blessed-android with MIT License 6 votes vote down vote up
/**
 * Set scan timeout timer, timeout time is {@code SCAN_TIMEOUT}.
 * If timeout is executed the scan is stopped and automatically restarted. This is done to avoid Android 9 scan restrictions
 */
private void setScanTimer() {
    cancelTimeoutTimer();

    timeoutRunnable = new Runnable() {
        @Override
        public void run() {
            Timber.d("scanning timeout, restarting scan");
            final ScanCallback callback = currentCallback;
            final List<ScanFilter> filters = currentFilters;
            stopScan();

            // Restart the scan and timer
            callBackHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    startScan(filters, scanSettings, callback);
                }
            }, SCAN_RESTART_DELAY);
        }
    };

    mainHandler.postDelayed(timeoutRunnable, SCAN_TIMEOUT);
}
 
Example #15
Source File: BluetoothGlucoseMeter.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void beginScan() {
    if (Build.VERSION.SDK_INT >= 21) {
        if (d) Log.d(TAG, "Preparing for scan...");

        // set up v21 scanner
        mLEScanner = mBluetoothAdapter.getBluetoothLeScanner();
        settings = new ScanSettings.Builder()
                .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
                .build();
        filters = new ArrayList<>();

        filters.add(new ScanFilter.Builder().setServiceUuid(new ParcelUuid(GLUCOSE_SERVICE)).build());
    }
    // all api versions
    scanLeDevice(true);
}
 
Example #16
Source File: ThrottledLollipopScanner.java    From RxCentralBle with Apache License 2.0 5 votes vote down vote up
private void startScan(int scanMode) {
  BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
  if (adapter != null && adapter.isEnabled()) {
    // Add a dummy filter to avoid Android 8.1+ enforcement of filters during background isScanning.
    List<ScanFilter> filters = new ArrayList<>();
    ScanFilter.Builder scanFilterBuilder = new ScanFilter.Builder();
    filters.add(scanFilterBuilder.build());

    ScanSettings.Builder settingsBuilder = new ScanSettings.Builder();
    settingsBuilder.setScanMode(scanMode);

    BluetoothLeScanner bleScanner = adapter.getBluetoothLeScanner();
    if (bleScanner != null) {
      bleScanner.startScan(filters, settingsBuilder.build(), scanCallback);
    } else {
      if (RxCentralLogger.isError()) {
        RxCentralLogger.error("startScan - BluetoothLeScanner is null!");
      }

      getErrorSubject().onError(new ConnectionError(SCAN_FAILED));
    }
  } else {
    if (RxCentralLogger.isError()) {
      if (adapter == null) {
        RxCentralLogger.error("startScan - Default Bluetooth Adapter is null!");
      } else {
        RxCentralLogger.error("startScan - Bluetooth Adapter is disabled.");
      }
    }

    getErrorSubject().onError(new ConnectionError(SCAN_FAILED));
  }
}
 
Example #17
Source File: BlueToothService.java    From EFRConnect-android with Apache License 2.0 5 votes vote down vote up
List<?> getScanFilterL() {

            List<ScanFilterCompat> scanFiltersCompat = getScanFilters();
            List<ScanFilter> scanFilters = (scanFiltersCompat != null) ? new ArrayList<ScanFilter>(scanFiltersCompat.size()) : null;
            if (scanFiltersCompat != null) {
                for (ScanFilterCompat scanFilterCompat : scanFiltersCompat) {
                    scanFilters.add(scanFilterCompat.createScanFilter());
                }
                return scanFilters.isEmpty() ? null : scanFilters;
            } else {
                return null;
            }
        }
 
Example #18
Source File: Manager.java    From BlueSTSDK_Android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void startBleScan_post21() {
    mScanCallBack_post21 = new ScanCallbackBridge(mScanCallBack_pre21);
    if(mBtAdapter!=null && mBtAdapter.getBluetoothLeScanner()!=null) {
        ScanSettings settings = new ScanSettings.Builder()
                .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
                .build();
        List<ScanFilter> noFilter = Collections.emptyList();
        mBtAdapter.getBluetoothLeScanner().startScan(noFilter,settings,mScanCallBack_post21);

    }
}
 
Example #19
Source File: DeviceDiscovererV21.java    From science-journal with Apache License 2.0 5 votes vote down vote up
@Override
public void onStartScanning(ParcelUuid[] serviceUuids) {
  scanner = getBluetoothAdapter().getBluetoothLeScanner();
  List<ScanFilter> filters = new ArrayList<>();
  for (ParcelUuid uuid : serviceUuids) {
    filters.add(new ScanFilter.Builder().setServiceUuid(uuid).build());
  }
  ScanSettings settings =
      new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_BALANCED).build();
  scanner.startScan(filters, settings, callback);
}
 
Example #20
Source File: ScannerFragment.java    From android-BluetoothAdvertisements with Apache License 2.0 5 votes vote down vote up
/**
 * Return a List of {@link ScanFilter} objects to filter by Service UUID.
 */
private List<ScanFilter> buildScanFilters() {
    List<ScanFilter> scanFilters = new ArrayList<>();

    ScanFilter.Builder builder = new ScanFilter.Builder();
    // Comment out the below line to see all BLE devices around you
    builder.setServiceUuid(Constants.Service_UUID);
    scanFilters.add(builder.build());

    return scanFilters;
}
 
Example #21
Source File: G5CollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public void setupBluetooth() {

        getTransmitterDetails();
        if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
            //First time using the app or bluetooth was turned off?
            Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            Timer single_timer = new Timer();
            single_timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    if (mBluetoothAdapter != null) mBluetoothAdapter.enable();
                }
            }, 1000);
            single_timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    setupBluetooth();
                }
            }, 10000);
        } else {
            if (Build.VERSION.SDK_INT >= 21) {
                mLEScanner = mBluetoothAdapter.getBluetoothLeScanner();
                settings = new ScanSettings.Builder()
                        .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
                        .build();
                filters = new ArrayList<>();
                //Only look for CGM.
                //filters.add(new ScanFilter.Builder().setServiceUuid(new ParcelUuid(BluetoothServices.Advertisement)).build());
                String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
                filters.add(new ScanFilter.Builder().setDeviceName("Dexcom" + transmitterIdLastTwo).build());
            }

            // unbond here to avoid clashes when we are mid-connection
            if (alwaysUnbond()) {
                forgetDevice();
            }
            JoH.ratelimit("G5-timeout",0);//re-init to ensure onStartCommand always executes cycleScan
            cycleScan(0);
        }
    }
 
Example #22
Source File: G5CollectionService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public void setupBluetooth() {

        getTransmitterDetails();
        if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
            //First time using the app or bluetooth was turned off?
            Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            Timer single_timer = new Timer();
            single_timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    if (mBluetoothAdapter != null) mBluetoothAdapter.enable();
                }
            }, 1000);
            single_timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    setupBluetooth();
                }
            }, 10000);
        } else {
            if (Build.VERSION.SDK_INT >= 21) {
                mLEScanner = mBluetoothAdapter.getBluetoothLeScanner();
                settings = new ScanSettings.Builder()
                        .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
                        .build();
                filters = new ArrayList<>();
                //Only look for CGM.
                //filters.add(new ScanFilter.Builder().setServiceUuid(new ParcelUuid(BluetoothServices.Advertisement)).build());
                String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
                filters.add(new ScanFilter.Builder().setDeviceName("Dexcom" + transmitterIdLastTwo).build());
            }

            // unbond here to avoid clashes when we are mid-connection
            if (alwaysUnbond()) {
                forgetDevice();
            }
            JoH.ratelimit("G5-timeout",0);//re-init to ensure onStartCommand always executes cycleScan
            cycleScan(0);
        }
    }
 
Example #23
Source File: G5CollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
public void setupBluetooth() {
    getTransmitterDetails();
    if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
        //First time using the app or bluetooth was turned off?
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        Timer single_timer = new Timer();
            single_timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    mBluetoothAdapter.enable();
                }
            }, 1000);
        single_timer.schedule(new TimerTask() {
            @Override
            public void run() {
                setupBluetooth();
            }
        }, 10000);
    } else {
        if (Build.VERSION.SDK_INT >= 21) {
            mLEScanner = mBluetoothAdapter.getBluetoothLeScanner();
            settings = new ScanSettings.Builder()
                    .setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
                    .build();
            filters = new ArrayList<>();
            //Only look for CGM.
            //filters.add(new ScanFilter.Builder().setServiceUuid(new ParcelUuid(BluetoothServices.Advertisement)).build());
            String transmitterIdLastTwo = Extensions.lastTwoCharactersOfString(defaultTransmitter.transmitterId);
            filters.add(new ScanFilter.Builder().setDeviceName("Dexcom" + transmitterIdLastTwo).build());
        }

        cycleScan(0);
    }
}
 
Example #24
Source File: FitbitGattTest.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void startSystemManagedPendingIntentScanAlwaysOnEnabled() {
    doReturn(true).when(alwaysConnectedScannerMock).isAlwaysConnectedScannerEnabled();

    List<ScanFilter> filters = new ArrayList<>();
    fitbitGatt.setStarted(true);
    fitbitGatt.setPeripheralScanner(scannerMock);
    fitbitGatt.startSystemManagedPendingIntentScan(contextMock, filters);

    verifyZeroInteractions(scannerMock);
}
 
Example #25
Source File: BluetoothCentral.java    From blessed-android with MIT License 5 votes vote down vote up
private void startScan(List<ScanFilter> filters, ScanSettings scanSettings, ScanCallback scanCallback) {
    // Check is BLE is available, enabled and all permission granted
    if (!isBleReady()) return;

    // Make sure we are not already scanning, we only want one scan at the time
    if (isScanning()) {
        Timber.e("other scan still active, stopping scan");
        stopScan();
    }

    // Get a new scanner object
    if (bluetoothScanner == null) {
        bluetoothScanner = bluetoothAdapter.getBluetoothLeScanner();
    }

    // If get scanner was succesful, start the scan
    if (bluetoothScanner != null) {
        // Start the scanner
        setScanTimer();
        currentCallback = scanCallback;
        currentFilters = filters;
        bluetoothScanner.startScan(filters, scanSettings, scanCallback);
        Timber.i("scan started");
    } else {
        Timber.e("starting scan failed");
    }
}
 
Example #26
Source File: FitbitGattTest.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void startSystemManagedPendingIntentScanAlwaysOnDisabled() {
    doReturn(false).when(alwaysConnectedScannerMock).isAlwaysConnectedScannerEnabled();

    List<ScanFilter> filters = new ArrayList<>();
    fitbitGatt.setStarted(true);
    fitbitGatt.setPeripheralScanner(scannerMock);
    fitbitGatt.startSystemManagedPendingIntentScan(contextMock, filters);

    verify(scannerMock).startPendingIntentBasedBackgroundScan(filters, contextMock);
    verifyNoMoreInteractions(scannerMock);
}
 
Example #27
Source File: MockLollipopScanner.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
public void startScan(int mScannerId, ScanSettings mSettings, List<ScanFilter> mFilters, List<List<ResultStorageDescriptor>> mResultStorages, String packageName) {
    if (mSettings.getScanMode() == ScanSettings.SCAN_MODE_LOW_LATENCY) {
        currentScanState = ScanState.LOW_LATENCY;
    } else if (mSettings.getScanMode() == ScanSettings.SCAN_MODE_BALANCED) {
        currentScanState = ScanState.BALANCED_LATENCY;
    } else if (mSettings.getScanMode() == ScanSettings.SCAN_MODE_LOW_POWER) {
        currentScanState = ScanState.HIGH_LATENCY;
    }
    Timber.v("Current scan state: %s", currentScanState);
    SystemClock.sleep(TIME_BETWEEN_RESULTS);
    resultsRunnable.run();
}
 
Example #28
Source File: MockLollipopScanner.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
public void startScanForIntent(PendingIntent callbackIntent, ScanSettings settings, List<ScanFilter> filters, String packageName) {
    singleThreadExecutor.schedule(resultsRunnable, TIME_BETWEEN_RESULTS, TimeUnit.MILLISECONDS);
    if (settings.getScanMode() == ScanSettings.SCAN_MODE_LOW_LATENCY) {
        currentScanState = ScanState.INTENT_SCANNING;
    } else if (settings.getScanMode() == ScanSettings.SCAN_MODE_BALANCED) {
        currentScanState = ScanState.INTENT_SCANNING;
    } else if (settings.getScanMode() == ScanSettings.SCAN_MODE_LOW_POWER) {
        currentScanState = ScanState.INTENT_SCANNING;
    }
}
 
Example #29
Source File: AlwaysConnectedScannerTest.java    From bitgatt with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testTryToScanAlwaysConnectedButRegularScannerRunning(){
    // generic scan filter
    ScanFilter filter = new ScanFilter.Builder().build();
    alwaysConnectedScanner.setNumberOfExpectedDevices(1);
    alwaysConnectedScanner.setShouldKeepLooking(false);
    alwaysConnectedScanner.addScanFilter(mockContext, filter);
    // there is a single set of filters for all scanners
    peripheralScanner.isScanning.set(true);
    assertFalse(alwaysConnectedScanner.start(mockContext));
}
 
Example #30
Source File: BLEService.java    From android_wear_for_ios with MIT License 5 votes vote down vote up
@TargetApi(21)
    private List<ScanFilter> create_scan_filter(){
//        ScanFilter filter = new ScanFilter.Builder().setServiceUuid(ParcelUuid.fromString(service_ancs)).build();
        ScanFilter filter = new ScanFilter.Builder().setServiceUuid(ParcelUuid.fromString(service_blank)).build();
        List<ScanFilter> list = new ArrayList<ScanFilter>(1);
        list.add(filter);
        return list;
    }