@Test public void testBeaconHavingWrongBeaconTypeIsIgnored() throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { final String bluetoothAddress = "00:11:22:33:FF:EE"; final String proximityUuid = "E56E1F2C-C756-476F-8323-8D1F9CD245EA"; final int major = 100; final int minor = 65520; final byte rssi = -95; final byte txPower = -105; final byte data = 0x01; final ScanResult scanResult = createAltBeaconScanResult( bluetoothAddress, new byte[] {(byte) 0x25, (byte) 0xDE}, proximityUuid, major, minor, rssi, txPower, data ); final Beacon beacon = parser.parse(scanResult); assertNull(beacon); }
@Override @Nullable public Beacon parse(@NonNull ScanResult scanResult) { if (scanResult.getScanRecord() == null) { return null; } final SparseArray<byte[]> manufacturerData = scanResult .getScanRecord() .getManufacturerSpecificData(); for (int i = 0; i < manufacturerData.size(); i++) { final int key = manufacturerData.keyAt(i); final byte[] rawBytes = manufacturerData.get(key); final List<Byte> bytesList = Conversions.asList(rawBytes); try { final List<Object> identifiers = new ArrayList<>(); for (int j = 0; j < fieldConverters.size(); j++) { final IFieldConverter<?> converter = fieldConverters.get(j); final Object parsedField = converter.consume(bytesList); identifiers.add(parsedField); if (j == beaconTypeIndex && !beaconType.equals(parsedField)) { BeaconLogger.e( format( Locale.US, "Expected beacon type is %s, while the actual beacon type is %s;" + " the data %s will be skipped", beaconType, parsedField, Conversions.byteArrayToHexString(rawBytes) ) ); return null; } } final Byte txPower = txPowerIndex != -1 ? ((byte) identifiers.get(txPowerIndex)) : null; return new Beacon( scanResult.getDevice().getAddress(), identifiers, txPower ); } catch (Exception e) { BeaconLogger.e( "An attempt to parse the following manufacturerData: " + byteArrayToHexString(rawBytes) + " have resulted in the following " + "exception: " + e.toString() ); } } return null; }
BeaconParser implements IBeaconParser { @Override @Nullable public Beacon parse(@NonNull ScanResult scanResult) { if (scanResult.getScanRecord() == null) { return null; } final SparseArray<byte[]> manufacturerData = scanResult .getScanRecord() .getManufacturerSpecificData(); for (int i = 0; i < manufacturerData.size(); i++) { final int key = manufacturerData.keyAt(i); final byte[] rawBytes = manufacturerData.get(key); final List<Byte> bytesList = Conversions.asList(rawBytes); try { final List<Object> identifiers = new ArrayList<>(); for (int j = 0; j < fieldConverters.size(); j++) { final IFieldConverter<?> converter = fieldConverters.get(j); final Object parsedField = converter.consume(bytesList); identifiers.add(parsedField); if (j == beaconTypeIndex && !beaconType.equals(parsedField)) { BeaconLogger.e( format( Locale.US, "Expected beacon type is %s, while the actual beacon type is %s;" + " the data %s will be skipped", beaconType, parsedField, Conversions.byteArrayToHexString(rawBytes) ) ); return null; } } final Byte txPower = txPowerIndex != -1 ? ((byte) identifiers.get(txPowerIndex)) : null; return new Beacon( scanResult.getDevice().getAddress(), identifiers, txPower ); } catch (Exception e) { BeaconLogger.e( "An attempt to parse the following manufacturerData: " + byteArrayToHexString(rawBytes) + " have resulted in the following " + "exception: " + e.toString() ); } } return null; } }
BeaconParser implements IBeaconParser { @Override @Nullable public Beacon parse(@NonNull ScanResult scanResult) { if (scanResult.getScanRecord() == null) { return null; } final SparseArray<byte[]> manufacturerData = scanResult .getScanRecord() .getManufacturerSpecificData(); for (int i = 0; i < manufacturerData.size(); i++) { final int key = manufacturerData.keyAt(i); final byte[] rawBytes = manufacturerData.get(key); final List<Byte> bytesList = Conversions.asList(rawBytes); try { final List<Object> identifiers = new ArrayList<>(); for (int j = 0; j < fieldConverters.size(); j++) { final IFieldConverter<?> converter = fieldConverters.get(j); final Object parsedField = converter.consume(bytesList); identifiers.add(parsedField); if (j == beaconTypeIndex && !beaconType.equals(parsedField)) { BeaconLogger.e( format( Locale.US, "Expected beacon type is %s, while the actual beacon type is %s;" + " the data %s will be skipped", beaconType, parsedField, Conversions.byteArrayToHexString(rawBytes) ) ); return null; } } final Byte txPower = txPowerIndex != -1 ? ((byte) identifiers.get(txPowerIndex)) : null; return new Beacon( scanResult.getDevice().getAddress(), identifiers, txPower ); } catch (Exception e) { BeaconLogger.e( "An attempt to parse the following manufacturerData: " + byteArrayToHexString(rawBytes) + " have resulted in the following " + "exception: " + e.toString() ); } } return null; } BeaconParser(@NonNull List<IFieldConverter<?>> fieldConverters,
                 int beaconTypeIndex,
                 int manufacturerId,
                 Object beaconType,
                 int txPowerIndex); }
BeaconParser implements IBeaconParser { @Override @Nullable public Beacon parse(@NonNull ScanResult scanResult) { if (scanResult.getScanRecord() == null) { return null; } final SparseArray<byte[]> manufacturerData = scanResult .getScanRecord() .getManufacturerSpecificData(); for (int i = 0; i < manufacturerData.size(); i++) { final int key = manufacturerData.keyAt(i); final byte[] rawBytes = manufacturerData.get(key); final List<Byte> bytesList = Conversions.asList(rawBytes); try { final List<Object> identifiers = new ArrayList<>(); for (int j = 0; j < fieldConverters.size(); j++) { final IFieldConverter<?> converter = fieldConverters.get(j); final Object parsedField = converter.consume(bytesList); identifiers.add(parsedField); if (j == beaconTypeIndex && !beaconType.equals(parsedField)) { BeaconLogger.e( format( Locale.US, "Expected beacon type is %s, while the actual beacon type is %s;" + " the data %s will be skipped", beaconType, parsedField, Conversions.byteArrayToHexString(rawBytes) ) ); return null; } } final Byte txPower = txPowerIndex != -1 ? ((byte) identifiers.get(txPowerIndex)) : null; return new Beacon( scanResult.getDevice().getAddress(), identifiers, txPower ); } catch (Exception e) { BeaconLogger.e( "An attempt to parse the following manufacturerData: " + byteArrayToHexString(rawBytes) + " have resulted in the following " + "exception: " + e.toString() ); } } return null; } BeaconParser(@NonNull List<IFieldConverter<?>> fieldConverters,
                 int beaconTypeIndex,
                 int manufacturerId,
                 Object beaconType,
                 int txPowerIndex); @Override @Nullable Beacon parse(@NonNull ScanResult scanResult); @NonNull @Override List<ScanFilter> asScanFilters(@NonNull List<Region> regions); }
BeaconParser implements IBeaconParser { @Override @Nullable public Beacon parse(@NonNull ScanResult scanResult) { if (scanResult.getScanRecord() == null) { return null; } final SparseArray<byte[]> manufacturerData = scanResult .getScanRecord() .getManufacturerSpecificData(); for (int i = 0; i < manufacturerData.size(); i++) { final int key = manufacturerData.keyAt(i); final byte[] rawBytes = manufacturerData.get(key); final List<Byte> bytesList = Conversions.asList(rawBytes); try { final List<Object> identifiers = new ArrayList<>(); for (int j = 0; j < fieldConverters.size(); j++) { final IFieldConverter<?> converter = fieldConverters.get(j); final Object parsedField = converter.consume(bytesList); identifiers.add(parsedField); if (j == beaconTypeIndex && !beaconType.equals(parsedField)) { BeaconLogger.e( format( Locale.US, "Expected beacon type is %s, while the actual beacon type is %s;" + " the data %s will be skipped", beaconType, parsedField, Conversions.byteArrayToHexString(rawBytes) ) ); return null; } } final Byte txPower = txPowerIndex != -1 ? ((byte) identifiers.get(txPowerIndex)) : null; return new Beacon( scanResult.getDevice().getAddress(), identifiers, txPower ); } catch (Exception e) { BeaconLogger.e( "An attempt to parse the following manufacturerData: " + byteArrayToHexString(rawBytes) + " have resulted in the following " + "exception: " + e.toString() ); } } return null; } BeaconParser(@NonNull List<IFieldConverter<?>> fieldConverters,
                 int beaconTypeIndex,
                 int manufacturerId,
                 Object beaconType,
                 int txPowerIndex); @Override @Nullable Beacon parse(@NonNull ScanResult scanResult); @NonNull @Override List<ScanFilter> asScanFilters(@NonNull List<Region> regions);  }