Skip to content

Commit

Permalink
Merge branch 'android-5-scanning-optimize-split'
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgyoung committed Jan 13, 2015
2 parents 2fbe90c + 73895e7 commit 138735f
Show file tree
Hide file tree
Showing 14 changed files with 915 additions and 475 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ dependencies {
androidTestCompile('com.squareup:fest-android:1.0.+@aar') {
exclude group: 'com.android.support', module: 'support-v4'
}
androidTestCompile('org.robolectric:robolectric:2.3') {
androidTestCompile('org.robolectric:robolectric:2.4') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/altbeacon/beacon/AltBeaconParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class AltBeaconParser extends BeaconParser {
*/
public AltBeaconParser() {
super();
mHardwareAssistManufacturers = new int[]{0x0118}; // Radius networks
this.setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25");
}
/**
Expand Down
25 changes: 23 additions & 2 deletions src/main/java/org/altbeacon/beacon/BeaconManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -113,6 +114,7 @@ public class BeaconManager {
*/
public static boolean debug = false;
private static boolean sAndroidLScanningDisabled = false;
private static boolean sManifestCheckingDisabled = false;

/**
* Set to true if you want to show library debugging
Expand Down Expand Up @@ -193,13 +195,25 @@ public static BeaconManager getInstanceForApplication(Context context) {
return client;
}

/**
* Gets a list of the active beaconParsers. This list may only be modified before any consumers
* are bound to the beacon service
*
* @return list of active BeaconParsers
*/

public List<BeaconParser> getBeaconParsers() {
if (isAnyConsumerBound()) {
return Collections.unmodifiableList(beaconParsers);
}
return beaconParsers;
}

protected BeaconManager(Context context) {
mContext = context;
verifyServiceDeclaration();
if (!sManifestCheckingDisabled) {
verifyServiceDeclaration();
}
this.beaconParsers.add(new AltBeaconParser());
}
/**
Expand Down Expand Up @@ -695,5 +709,12 @@ public static void setAndroidLScanningDisabled(boolean disabled) {
sAndroidLScanningDisabled = disabled;
}


/**
* Allows disabling check of manifest for proper configuration of service. Useful for unit
* testing
* @param disabled
*/
public static void setsManifestCheckingDisabled(boolean disabled) {
sManifestCheckingDisabled = disabled;
}
}
43 changes: 42 additions & 1 deletion src/main/java/org/altbeacon/beacon/BeaconParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class BeaconParser {
protected Integer mMatchingBeaconTypeCodeEndOffset;
protected Integer mPowerStartOffset;
protected Integer mPowerEndOffset;
protected int[] mHardwareAssistManufacturers = new int[] { 0x004c };

/**
* Makes a new BeaconParser. Should normally be immediately followed by a call to #setLayout
Expand Down Expand Up @@ -201,6 +202,30 @@ public BeaconParser setBeaconLayout(String beaconLayout) {
return this;
}

/**
* Returns a list of bluetooth manufactuer codes which will be used for hardware-assisted
* accelerated looking for this beacon type
*
* The possible codes are defined onthis list:
* https://www.bluetooth.org/en-us/specification/assigned-numbers/company-identifiers
*
* @return manufacturers
*/
public int[] getHardwareAssistManufacturers() {
return mHardwareAssistManufacturers;
}

/**
* Sets a list of bluetooth manufactuer codes which will be used for hardware-assisted
* accelerated looking for this beacon type
*
* The possible codes are defined onthis list:
* https://www.bluetooth.org/en-us/specification/assigned-numbers/company-identifiers
*
*/
public void setHardwareAssistManufacturerCodes(int[] manufacturers) {
mHardwareAssistManufacturers = manufacturers;
}

/**
* @see #mMatchingBeaconTypeCode
Expand All @@ -210,6 +235,22 @@ public Long getMatchingBeaconTypeCode() {
return mMatchingBeaconTypeCode;
}

/**
* see #mMatchingBeaconTypeCodeStartOffset
* @return
*/
public int getMatchingBeaconTypeCodeStartOffset() {
return mMatchingBeaconTypeCodeStartOffset;
}

/**
* see #mMatchingBeaconTypeCodeEndOffset
* @return
*/
public int getMatchingBeaconTypeCodeEndOffset() {
return mMatchingBeaconTypeCodeEndOffset;
}

/**
* Construct a Beacon from a Bluetooth LE packet collected by Android's Bluetooth APIs,
* including the raw bluetooth device info
Expand Down Expand Up @@ -398,7 +439,7 @@ public BeaconLayoutException(String s) {
}
}

protected byte[] longToByteArray(long longValue, int length) {
public static byte[] longToByteArray(long longValue, int length) {
byte[] array = new byte[length];
for (int i = 0; i < length; i++){
//long mask = (long) Math.pow(256.0,1.0*(length-i))-1;
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/org/altbeacon/beacon/service/BeaconService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@
*/
package org.altbeacon.beacon.service;

import android.annotation.SuppressLint;

import android.annotation.TargetApi;
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothManager;
import android.bluetooth.le.ScanResult;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.os.AsyncTask;
Expand All @@ -45,14 +41,15 @@
import org.altbeacon.beacon.BeaconParser;
import org.altbeacon.beacon.distance.DistanceCalculator;
import org.altbeacon.beacon.distance.ModelSpecificDistanceCalculator;
import org.altbeacon.beacon.service.scanner.CycledLeScanCallback;
import org.altbeacon.beacon.service.scanner.CycledLeScanner;
import org.altbeacon.bluetooth.BluetoothCrashResolver;
import org.altbeacon.beacon.BuildConfig;
import org.altbeacon.beacon.Region;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand All @@ -69,13 +66,11 @@ public class BeaconService extends Service {

private Map<Region, RangeState> rangedRegionState = new HashMap<Region, RangeState>();
private Map<Region, MonitorState> monitoredRegionState = new HashMap<Region, MonitorState>();
private BluetoothAdapter bluetoothAdapter;
private HashSet<Beacon> trackedBeacons;
int trackedBeaconsPacketCount;
private Handler handler = new Handler();
private int bindCount = 0;
private BluetoothCrashResolver bluetoothCrashResolver;
private boolean scanCyclerStarted = false;
private boolean scanningEnabled = false;
private DistanceCalculator defaultDistanceCalculator = null;
private List<BeaconParser> beaconParsers;
Expand Down Expand Up @@ -201,7 +196,7 @@ public void onCreate() {
Log.i(TAG, "beaconService version " + BuildConfig.VERSION_NAME + " is starting up");
bluetoothCrashResolver = new BluetoothCrashResolver(this);
bluetoothCrashResolver.start();
mCycledScanner = new CycledLeScanner(this, BeaconManager.DEFAULT_FOREGROUND_SCAN_PERIOD,
mCycledScanner = CycledLeScanner.createScanner(this, BeaconManager.DEFAULT_FOREGROUND_SCAN_PERIOD,
BeaconManager.DEFAULT_FOREGROUND_BETWEEN_SCAN_PERIOD, mBackgroundFlag, mCycledLeScanCallback, bluetoothCrashResolver);

beaconParsers = BeaconManager.getInstanceForApplication(getApplicationContext()).getBeaconParsers();
Expand Down Expand Up @@ -421,6 +416,7 @@ public ScanData(BluetoothDevice device, int rssi, byte[] scanRecord) {
}

private class ScanProcessor extends AsyncTask<ScanData, Void, Void> {
DetectionTracker mDetectionTracker = DetectionTracker.getInstance();

@Override
protected Void doInBackground(ScanData... params) {
Expand All @@ -435,6 +431,7 @@ protected Void doInBackground(ScanData... params) {
}
}
if (beacon != null) {
mDetectionTracker.recordDetection();
processBeaconFromScan(beacon);
}
return null;
Expand Down
Loading

0 comments on commit 138735f

Please sign in to comment.