Skip to content

Commit

Permalink
Merge pull request #235 from AltBeacon/altbeacon-filter-fix
Browse files Browse the repository at this point in the history
Detect various AltBeacon manufacturers in the foreground
  • Loading branch information
davidgyoung committed Jul 10, 2015
2 parents 506f575 + ad301ea commit 247d083
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/main/java/org/altbeacon/beacon/AltBeaconParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ public class AltBeaconParser extends BeaconParser {
*/
public AltBeaconParser() {
super();
mHardwareAssistManufacturers = new int[]{0x0118}; // Radius networks
// Radius networks and other manufacturers seen in AltBeacons
// Note: Other manufacturer codes that have been seen in the wild with AltBeacons are:
// 0x004c, 0x00e0
// We are not adding these here because there is no indication they are widely used
// for production purposes. We need to keep the hardware assist list short in order to
// save slots. If you are a manufacturer of AltBeacons and want you company code added to
// this list, please open an issue on the Github project for this library. If a beacon
// manufacturer code not in this list is used for AltBeacons, phones using Andoroid 5.x+
// detection APIs will not be able to detect the beacon in the background.
mHardwareAssistManufacturers = new int[]{0x0118};
this.setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");
}
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ protected void startScan() {
if (mBackgroundFlag) {
LogManager.d(TAG, "starting scan in SCAN_MODE_LOW_POWER");
settings = (new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_POWER)).build();
filters = new ScanFilterUtils().createScanFiltersForBeaconParsers(
mBeaconManager.getBeaconParsers());

} else {
LogManager.d(TAG, "starting scan in SCAN_MODE_LOW_LATENCY");
settings = (new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)).build();
Expand All @@ -174,11 +177,9 @@ protected void startScan() {

try {
if (getScanner() != null) {
List scanFilters = new ScanFilterUtils().createScanFiltersForBeaconParsers(
mBeaconManager.getBeaconParsers());
ScanCallback callback = getNewLeScanCallback();
try {
getScanner().startScan(scanFilters, settings, callback);
getScanner().startScan(filters, settings, callback);
}
catch (NullPointerException npe) {
// Necessary because of https://code.google.com/p/android/issues/detail?id=160503
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/org/altbeacon/beacon/BeaconParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,22 @@ public void testParseIdentifierThatRunsUnderPduLength() {
assertNull("beacon should not be parsed", beacon);
}

@Test
public void testParseProblematicBeaconFromIssue229() {
org.robolectric.shadows.ShadowLog.stream = System.err;

// Note that the length field below is 0x16 instead of 0x1b, indicating that the packet ends
// one byte before the second identifier field starts

byte[] bytes = hexStringToByteArray("0201061bffe000beac7777772e626c756b692e636f6d000100010001abaa000000");
BeaconParser parser = new BeaconParser();
parser.setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");

Beacon beacon = parser.fromScanData(bytes, -55, null);
assertNotNull("beacon should be parsed", beacon);
}


@Test
public void testCanParseLocationBeacon() {
double latitude = 38.93;
Expand Down

0 comments on commit 247d083

Please sign in to comment.