org.altbeacon.beacon.Beacon Java Examples

The following examples show how to use org.altbeacon.beacon.Beacon. 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: TimedBeaconSimulator.java    From android-beacon-library-reference with Apache License 2.0 6 votes vote down vote up
/**
 * Creates simulated beacons all at once.
 */
public void createBasicSimulatedBeacons(){
	if (USE_SIMULATED_BEACONS) {
           Beacon beacon1 = new AltBeacon.Builder().setId1("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A")
                   .setId2("1").setId3("1").setRssi(-55).setTxPower(-55).build();
           Beacon beacon2 = new AltBeacon.Builder().setId1("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A")
                   .setId2("1").setId3("2").setRssi(-55).setTxPower(-55).build();
           Beacon beacon3 = new AltBeacon.Builder().setId1("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A")
                   .setId2("1").setId3("3").setRssi(-55).setTxPower(-55).build();
           Beacon beacon4 = new AltBeacon.Builder().setId1("DF7E1C79-43E9-44FF-886F-1D1F7DA6997A")
                   .setId2("1").setId3("4").setRssi(-55).setTxPower(-55).build();
		beacons.add(beacon1);
		beacons.add(beacon2);
		beacons.add(beacon3);
		beacons.add(beacon4);


	}
}
 
Example #2
Source File: RangingActivity.java    From android-beacon-library-reference with Apache License 2.0 6 votes vote down vote up
@Override
public void onBeaconServiceConnect() {

    RangeNotifier rangeNotifier = new RangeNotifier() {
       @Override
       public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
          if (beacons.size() > 0) {
              Log.d(TAG, "didRangeBeaconsInRegion called with beacon count:  "+beacons.size());
              Beacon firstBeacon = beacons.iterator().next();
              logToDisplay("The first beacon " + firstBeacon.toString() + " is about " + firstBeacon.getDistance() + " meters away.");
          }
       }

    };
    try {
        beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
        beaconManager.addRangeNotifier(rangeNotifier);
        beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
        beaconManager.addRangeNotifier(rangeNotifier);
    } catch (RemoteException e) {   }
}
 
Example #3
Source File: BleManager.java    From thunderboard-android with Apache License 2.0 6 votes vote down vote up
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {

    Iterator<Beacon> iterator = beacons.iterator();

    while (iterator.hasNext()) {

        //EditText editText = (EditText)RangingActivity.this.findViewById(R.id.rangingText);
        Beacon beacon = iterator.next();
        Timber.d("beacon %s  is about: %f meters away.", beacon.toString(), beacon.getDistance());

        deviceFound(beacon);
        if (backgroundPowerSaver.isScannerActivityResumed()) {
            publishRecentBeacons();
        } else if (SystemClock.elapsedRealtime() - backgroundPowerSaver.getScannerActivityDestroyedTimestamp() >
                ThunderBoardPowerSaver.DELAY_NOTIFICATIONS_TIME_THRESHOLD
                && backgroundPowerSaver.isApplicationBackgrounded()) {
            Timber.d("Sending notification.");
            sendNotification(beacon);
        }
    }
}
 
Example #4
Source File: BeaconsAndroidModule.java    From react-native-beacons-android with MIT License 6 votes vote down vote up
private WritableMap createRangingResponse(Collection<Beacon> beacons, Region region) {
    WritableMap map = new WritableNativeMap();
    map.putString("identifier", region.getUniqueId());
    map.putString("uuid", region.getId1() != null ? region.getId1().toString() : "");
    WritableArray a = new WritableNativeArray();
    for (Beacon beacon : beacons) {
        WritableMap b = new WritableNativeMap();
        b.putString("uuid", beacon.getId1().toString());
        b.putInt("major", beacon.getId2().toInt());
        b.putInt("minor", beacon.getId3().toInt());
        b.putInt("rssi", beacon.getRssi());
        b.putDouble("distance", beacon.getDistance());
        b.putString("proximity", getProximity(beacon.getDistance()));
        a.pushMap(b);
    }
    map.putArray("beacons", a);
    return map;
}
 
Example #5
Source File: BeaconSimulatorFragment.java    From iBeacon-Android with Apache License 2.0 6 votes vote down vote up
private void setupBeacon() {
    beacon = new Beacon.Builder()
            .setId1(getString(R.string.beacon_uuid_simulator)) // UUID for beacon
            .setId2(getString(R.string.beacon_major_simulator)) // Major for beacon
            .setId3(getString(R.string.beacon_minor_simulator)) // Minor for beacon
            .setManufacturer(0x004C) // Radius Networks.0x0118  Change this for other beacon layouts//0x004C for iPhone
            .setTxPower(-56) // Power in dB
            .setDataFields(Arrays.asList(new Long[]{0l})) // Remove this for beacon layouts without d: fields
            .build();

    btManager = (BluetoothManager) getActivity().getSystemService (Context.BLUETOOTH_SERVICE);
    btAdapter = btManager.getAdapter ();

    beaconTransmitter = new BeaconTransmitter (getActivity(), new BeaconParser()
            .setBeaconLayout ("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
}
 
Example #6
Source File: MonitoringStatus.java    From android-beacon-library with Apache License 2.0 6 votes vote down vote up
public synchronized void updateNewlyInsideInRegionsContaining(Beacon beacon) {
    List<Region> matchingRegions = regionsMatchingTo(beacon);
    boolean needsMonitoringStateSaving = false;
    for(Region region : matchingRegions) {
        RegionMonitoringState state = getRegionsStateMap().get(region);
        if (state != null && state.markInside()) {
            needsMonitoringStateSaving = true;
            state.getCallback().call(mContext, "monitoringData",
                    new MonitoringData(state.getInside(), region).toBundle());
        }
    }
    if (needsMonitoringStateSaving) {
        saveMonitoringStatusIfOn();
    }
    else {
        updateMonitoringStatusTime(System.currentTimeMillis());
    }
}
 
Example #7
Source File: RxBeacon.java    From RxBeacon with Apache License 2.0 6 votes vote down vote up
public Observable<RxBeaconRange> beaconsInRegion() {
    return startup()
            .flatMap(new Function<Boolean, ObservableSource<RxBeaconRange>>() {
                @Override
                public ObservableSource<RxBeaconRange> apply(@NonNull Boolean aBoolean) throws Exception {
                    return Observable.create(new ObservableOnSubscribe<RxBeaconRange>() {
                        @Override
                        public void subscribe(@NonNull final ObservableEmitter<RxBeaconRange> objectObservableEmitter) throws Exception {
                            beaconManager.addRangeNotifier(new RangeNotifier() {
                                @Override
                                public void didRangeBeaconsInRegion(Collection<Beacon> collection, Region region) {
                                    objectObservableEmitter.onNext(new RxBeaconRange(collection, region));
                                }
                            });
                            beaconManager.startRangingBeaconsInRegion(getRegion());
                        }
                    });
                }
            });
}
 
Example #8
Source File: ExtraDataBeaconTracker.java    From android-beacon-library with Apache License 2.0 6 votes vote down vote up
/**
 * The following code is for dealing with merging data fields in beacons
 */
@Nullable
private Beacon trackGattBeacon(@NonNull Beacon beacon) {
    if (beacon.isExtraBeaconData()) {
        updateTrackedBeacons(beacon);
        return null;
    }

    String key = getBeaconKey(beacon);
    HashMap<Integer,Beacon> matchingTrackedBeacons = mBeaconsByKey.get(key);
    if (null == matchingTrackedBeacons) {
        matchingTrackedBeacons = new HashMap<>();
    }
    else {
        Beacon trackedBeacon = matchingTrackedBeacons.values().iterator().next();
        beacon.setExtraDataFields(trackedBeacon.getExtraDataFields());
    }
    matchingTrackedBeacons.put(beacon.hashCode(), beacon);
    mBeaconsByKey.put(key, matchingTrackedBeacons);

    return beacon;
}
 
Example #9
Source File: EddystoneTelemetryAccessor.java    From android-beacon-library with Apache License 2.0 6 votes vote down vote up
/**
 * Extracts the raw Eddystone telemetry bytes from the extra data fields of an associated beacon.
 * This is useful for passing the telemetry to Google's backend services.
 * @param beacon
 * @return the bytes of the telemetry frame
 */
public byte[] getTelemetryBytes(Beacon beacon) {
    if (beacon.getExtraDataFields().size() >= 5) {
        Beacon telemetryBeacon = new Beacon.Builder()
                .setDataFields(beacon.getExtraDataFields())
                .build();
        BeaconParser telemetryParser = new BeaconParser()
                .setBeaconLayout(BeaconParser.EDDYSTONE_TLM_LAYOUT);
        byte[] telemetryBytes = telemetryParser.getBeaconAdvertisementData(telemetryBeacon);
        Log.d(TAG, "Rehydrated telemetry bytes are :" + byteArrayToString(telemetryBytes));
        return telemetryBytes;
    }
    else {
        return null;
    }
}
 
Example #10
Source File: RangingDataTest.java    From android-beacon-library with Apache License 2.0 6 votes vote down vote up
@Test
// On MacBookPro 2.5 GHz Core I7, 10000 serialization/deserialiation cycles of RangingData took 22ms
public void testSerializationBenchmark() throws Exception {
    Context context = RuntimeEnvironment.application;
    ArrayList<Identifier> identifiers = new ArrayList<Identifier>();
    identifiers.add(Identifier.parse("2f234454-cf6d-4a0f-adf2-f4911ba9ffa6"));
    identifiers.add(Identifier.parse("1"));
    identifiers.add(Identifier.parse("2"));
    Region region = new Region("testRegion", identifiers);
    ArrayList<Beacon> beacons = new ArrayList<Beacon>();
    Beacon beacon = new Beacon.Builder().setIdentifiers(identifiers).setRssi(-1).setRunningAverageRssi(-2).setTxPower(-50).setBluetoothAddress("01:02:03:04:05:06").build();
    for (int i=0; i < 10; i++) {
        beacons.add(beacon);
    }
    RangingData data = new RangingData(beacons, region);
    long time1 = System.currentTimeMillis();
    for (int i=0; i< 10000; i++) {
        Bundle bundle = data.toBundle();
        RangingData data2 = RangingData.fromBundle(bundle);
    }
    long time2 = System.currentTimeMillis();
    System.out.println("*** Ranging Data Serialization benchmark: "+(time2-time1));
}
 
Example #11
Source File: ExtraDataBeaconTrackerTest.java    From android-beacon-library with Apache License 2.0 6 votes vote down vote up
@Test
public void gattBeaconExtraDataGetUpdated() {
    Beacon beacon = getGattBeacon();
    Beacon extraDataBeacon = getGattBeaconExtraData();
    Beacon extraDataBeacon2 = getGattBeaconExtraData2();
    ExtraDataBeaconTracker tracker = new ExtraDataBeaconTracker();
    tracker.track(beacon);
    tracker.track(extraDataBeacon);
    Beacon trackedBeacon = tracker.track(beacon);
    assertEquals("rssi should be updated", extraDataBeacon.getRssi(), trackedBeacon.getRssi());
    assertEquals("extra data is updated", extraDataBeacon.getDataFields(), trackedBeacon.getExtraDataFields());

    tracker.track(extraDataBeacon2);
    trackedBeacon = tracker.track(beacon);
    assertEquals("rssi should be updated", extraDataBeacon2.getRssi(), trackedBeacon.getRssi());
    assertEquals("extra data is updated", extraDataBeacon2.getDataFields(), trackedBeacon.getExtraDataFields());
}
 
Example #12
Source File: Application.java    From PresencePublisher with MIT License 6 votes vote down vote up
private void initBeaconReceiver() {
    if (supportsBeacons()) {
        LogManager.setLogger(new HyperlogLogger());
        Beacon.setHardwareEqualityEnforced(true);
        Beacon.setDistanceCalculator(new ModelSpecificDistanceCalculator(this, org.altbeacon.beacon.BeaconManager.getDistanceModelUpdateUrl()));
        org.altbeacon.beacon.BeaconManager beaconManager = org.altbeacon.beacon.BeaconManager.getInstanceForApplication(this);
        List<BeaconParser> beaconParsers = beaconManager.getBeaconParsers();
        beaconParsers.add(new BeaconParser("iBeacon")
                .setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
        beaconParsers.add(new BeaconParser("Eddystone UID")
                .setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT));

        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        if (!sharedPreferences.getStringSet(BEACON_LIST, Collections.emptySet()).isEmpty()) {
            BeaconManager.getInstance().initialize(this);
        }
        if (Build.VERSION.SDK_INT >= 18) {
            backgroundPowerSaver = new BackgroundPowerSaver(this);
        }
    }
}
 
Example #13
Source File: RangingData.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
public Bundle toBundle() {
    Bundle bundle = new Bundle();
    bundle.putSerializable(REGION_KEY, mRegion);
    ArrayList<Serializable> serializableBeacons = new ArrayList<Serializable>();
    for (Beacon beacon : mBeacons) {
        serializableBeacons.add(beacon);
    }
    bundle.putSerializable(BEACONS_KEY, serializableBeacons);

    return bundle;
}
 
Example #14
Source File: RunningAverageRssiFilterTest.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@Test
public void rangedBeaconDoesNotOverrideSampleExpirationMillisecondsText() {
    RangedBeacon.setSampleExpirationMilliseconds(20000);
    RunningAverageRssiFilter.setSampleExpirationMilliseconds(20000);
    Beacon beacon = new Beacon.Builder().setId1("1").build();
    RunningAverageRssiFilter.setSampleExpirationMilliseconds(33l);
    RangedBeacon rb = new RangedBeacon(beacon);
    assertEquals("RunningAverageRssiFilter sampleExprirationMilliseconds should not be altered by constructing RangedBeacon", 33l, RunningAverageRssiFilter.getSampleExpirationMilliseconds());
}
 
Example #15
Source File: EddystoneTelemetryAccessorTest.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@Test
public void testAllowsAccessToTelemetryBytes() throws MalformedURLException {
    ArrayList<Long> telemetryFields = new ArrayList<Long>();
    telemetryFields.add(0x01l); // version
    telemetryFields.add(0x0212l); // battery level
    telemetryFields.add(0x0313l); // temperature
    telemetryFields.add(0x04142434l); // pdu count
    telemetryFields.add(0x05152535l); // uptime

    Beacon beaconWithTelemetry = new Beacon.Builder().setId1("0x0102030405060708090a").setId2("0x01020304050607").setTxPower(-59).setExtraDataFields(telemetryFields).build();
    byte[] telemetryBytes = new EddystoneTelemetryAccessor().getTelemetryBytes(beaconWithTelemetry);

    byte[] expectedBytes = {0x20, 0x01, 0x02, 0x12, 0x03, 0x13, 0x04, 0x14, 0x24, 0x34, 0x05, 0x15, 0x25, 0x35};
    assertEquals(byteArrayToHexString(telemetryBytes), byteArrayToHexString(expectedBytes));
}
 
Example #16
Source File: ExtraDataBeaconTrackerTest.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
Beacon getGattBeaconUpdate() {
    return new Beacon.Builder().setId1("1")
            .setBluetoothAddress("01:02:03:04:05:06")
            .setServiceUuid(1234)
            .setRssi(-50)
            .setDataFields(getDataFields())
            .build();
}
 
Example #17
Source File: BeaconSimulatorTest.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetBeacons(){
    StaticBeaconSimulator staticBeaconSimulator = new StaticBeaconSimulator();
    byte[] beaconBytes = hexStringToByteArray("02011a1bff1801beac2f234454cf6d4a0fadf2f4911ba9ffa600010002c509");
    Beacon beacon = new AltBeaconParser().fromScanData(beaconBytes, -55, null,123456L);
    ArrayList<Beacon> beacons = new ArrayList<Beacon>();
    beacons.add(beacon);
    staticBeaconSimulator.setBeacons(beacons);
    assertEquals("getBeacons should match values entered with setBeacons", staticBeaconSimulator.getBeacons(), beacons);
}
 
Example #18
Source File: EddystoneTelemetryAccessorTest.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@Test
public void testAllowsAccessToBase64EncodedTelemetryBytes() throws MalformedURLException {
    ArrayList<Long> telemetryFields = new ArrayList<Long>();
    telemetryFields.add(0x01l); // version
    telemetryFields.add(0x0212l); // battery level
    telemetryFields.add(0x0313l); // temperature
    telemetryFields.add(0x04142434l); // pdu count
    telemetryFields.add(0x05152535l); // uptime

    Beacon beaconWithTelemetry = new Beacon.Builder().setId1("0x0102030405060708090a").setId2("0x01020304050607").setTxPower(-59).setExtraDataFields(telemetryFields).build();
    byte[] telemetryBytes = new EddystoneTelemetryAccessor().getTelemetryBytes(beaconWithTelemetry);

    String encodedTelemetryBytes = new EddystoneTelemetryAccessor().getBase64EncodedTelemetry(beaconWithTelemetry);
    assertNotNull(telemetryBytes);
}
 
Example #19
Source File: ExtraDataBeaconTrackerTest.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@Test
public void gattBeaconExtraDataIsNotReturned() {
    Beacon extraDataBeacon = getGattBeaconExtraData();
    ExtraDataBeaconTracker tracker = new ExtraDataBeaconTracker();
    Beacon trackedBeacon = tracker.track(extraDataBeacon);
    assertNull("trackedBeacon should be null", trackedBeacon);
}
 
Example #20
Source File: RadarScanView.java    From beaconloc with Apache License 2.0 5 votes vote down vote up
private void insertBeacons(Collection<Beacon> beacons) {
    Iterator<Beacon> iterator = beacons.iterator();
    while (iterator.hasNext()) {
        DetectedBeacon dBeacon = new DetectedBeacon(iterator.next());
        dBeacon.setTimeLastSeen(System.currentTimeMillis());
        this.mBeacons.put(dBeacon.getId(), dBeacon);
    }
}
 
Example #21
Source File: ScanJob.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
private boolean startScanning() {
    BeaconManager beaconManager = BeaconManager.getInstanceForApplication(getApplicationContext());
    beaconManager.setScannerInSameProcess(true);
    if (beaconManager.isMainProcess()) {
        LogManager.i(TAG, "scanJob version %s is starting up on the main process", BuildConfig.VERSION_NAME);
    }
    else {
        LogManager.i(TAG, "beaconScanJob library version %s is starting up on a separate process", BuildConfig.VERSION_NAME);
        ProcessUtils processUtils = new ProcessUtils(ScanJob.this);
        LogManager.i(TAG, "beaconScanJob PID is "+processUtils.getPid()+" with process name "+processUtils.getProcessName());
    }
    ModelSpecificDistanceCalculator defaultDistanceCalculator =  new ModelSpecificDistanceCalculator(ScanJob.this, BeaconManager.getDistanceModelUpdateUrl());
    Beacon.setDistanceCalculator(defaultDistanceCalculator);
    return restartScanning();
}
 
Example #22
Source File: RunningAverageRssiFilterTest.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@Test
public void legacySetSampleExpirationMillisecondsWorksText() {
    RangedBeacon.setSampleExpirationMilliseconds(20000);
    RunningAverageRssiFilter.setSampleExpirationMilliseconds(20000);
    Beacon beacon = new Beacon.Builder().setId1("1").build();
    RangedBeacon.setSampleExpirationMilliseconds(33l);
    RangedBeacon rb = new RangedBeacon(beacon);
    assertEquals("RunningAverageRssiFilter sampleExprirationMilliseconds should not be altered by constructing RangedBeacon", 33l, RunningAverageRssiFilter.getSampleExpirationMilliseconds());
}
 
Example #23
Source File: ExtraDataBeaconTrackerTest.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@Test
public void gattBeaconFieldsAreNotUpdated() {
    Beacon beacon = getGattBeacon();
    final int originalRssi = beacon.getRssi();
    final List<Long> originalData = beacon.getDataFields();
    final List<Long> originalExtra = beacon.getExtraDataFields();
    Beacon beaconUpdate = getGattBeaconUpdate();
    ExtraDataBeaconTracker tracker = new ExtraDataBeaconTracker();
    tracker.track(beacon);
    tracker.track(beaconUpdate);
    Beacon trackedBeacon = tracker.track(beacon);
    assertEquals("rssi should NOT be updated", originalRssi, trackedBeacon.getRssi());
    assertEquals("data should NOT be updated", originalData, trackedBeacon.getDataFields());
    assertEquals("extra data should NOT be updated", originalExtra, trackedBeacon.getExtraDataFields());
}
 
Example #24
Source File: ScanHelper.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
private List<Region> matchingRegions(Beacon beacon, Collection<Region> regions) {
    List<Region> matched = new ArrayList<>();
    for (Region region : regions) {
        // Need to check if region is null in case it was removed from the collection by
        // another thread during iteration
        if (region != null) {
            if (region.matchesBeacon(beacon)) {
                matched.add(region);
            } else {
                LogManager.d(TAG, "This region (%s) does not match beacon: %s", region, beacon);
            }
        }
    }
    return matched;
}
 
Example #25
Source File: ScanHelper.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@WorkerThread
@Override
protected Void doInBackground(ScanHelper.ScanData... params) {
    ScanHelper.ScanData scanData = params[0];
    Beacon beacon = null;

    for (BeaconParser parser : ScanHelper.this.mBeaconParsers) {
        beacon = parser.fromScanData(scanData.scanRecord, scanData.rssi, scanData.device, scanData.timestampMs);

        if (beacon != null) {
            break;
        }
    }
    if (beacon != null) {
        if (LogManager.isVerboseLoggingEnabled()) {
            LogManager.d(TAG, "Beacon packet detected for: "+beacon+" with rssi "+beacon.getRssi());
        }
        mDetectionTracker.recordDetection();
        if (mCycledScanner != null && !mCycledScanner.getDistinctPacketsDetectedPerScan()) {
            if (!mDistinctPacketDetector.isPacketDistinct(scanData.device.getAddress(),
                    scanData.scanRecord)) {
                LogManager.i(TAG, "Non-distinct packets detected in a single scan.  Restarting scans unecessary.");
                mCycledScanner.setDistinctPacketsDetectedPerScan(true);
            }
        }
        processBeaconFromScan(beacon);
    } else {
        if (mNonBeaconLeScanCallback != null) {
            mNonBeaconLeScanCallback.onNonBeaconLeScan(scanData.device, scanData.rssi, scanData.scanRecord);
        }
    }
    return null;
}
 
Example #26
Source File: DetectedBeaconAdapter.java    From beaconloc with Apache License 2.0 5 votes vote down vote up
public void insertBeacons(Collection<Beacon> beacons) {
    Iterator<Beacon> iterator = beacons.iterator();
    while (iterator.hasNext()) {
        DetectedBeacon dBeacon = new DetectedBeacon(iterator.next());
        dBeacon.setTimeLastSeen(System.currentTimeMillis());
        this.mBeacons.put(dBeacon.getId(), dBeacon);
    }
    notifyDataSetChanged();
}
 
Example #27
Source File: ScanHelper.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@Override
@MainThread
@SuppressLint("WrongThread")
public void onCycleEnd() {
    if (BeaconManager.getBeaconSimulator() != null) {
        LogManager.d(TAG, "Beacon simulator enabled");
        // if simulatedScanData is provided, it will be seen every scan cycle.  *in addition* to anything actually seen in the air
        // it will not be used if we are not in debug mode
        if (BeaconManager.getBeaconSimulator().getBeacons() != null) {
            if (0 != (mContext.getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) {
                LogManager.d(TAG, "Beacon simulator returns "+BeaconManager.getBeaconSimulator().getBeacons().size()+" beacons.");
                for (Beacon beacon : BeaconManager.getBeaconSimulator().getBeacons()) {
                    // This is an expensive call and we do not want to block the main thread.
                    // But here we are in debug/test mode so we allow it on the main thread.
                    //noinspection WrongThread
                    processBeaconFromScan(beacon);
                }
            } else {
                LogManager.w(TAG, "Beacon simulations provided, but ignored because we are not running in debug mode.  Please remove beacon simulations for production.");
            }
        } else {
            LogManager.w(TAG, "getBeacons is returning null. No simulated beacons to report.");
        }
    }
    else {
        if (LogManager.isVerboseLoggingEnabled()) {
            LogManager.d(TAG, "Beacon simulator not enabled");
        }
    }
    mDistinctPacketDetector.clearDetections();
    mMonitoringStatus.updateNewlyOutside();
    processRangeData();
}
 
Example #28
Source File: ExtraDataBeaconTracker.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
private String getBeaconKey(@NonNull Beacon beacon) {
    if (matchBeaconsByServiceUUID) {
        return beacon.getBluetoothAddress() + beacon.getServiceUuid();
    } else {
        return beacon.getBluetoothAddress();
    }
}
 
Example #29
Source File: ExtraDataBeaconTrackerTest.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
@Test
public void trackingManufacturerBeaconReturnsSelf() {
    Beacon beacon = getManufacturerBeacon();
    ExtraDataBeaconTracker tracker = new ExtraDataBeaconTracker();
    Beacon trackedBeacon = tracker.track(beacon);
    assertEquals("Returns itself", trackedBeacon, beacon);
}
 
Example #30
Source File: ExtraDataBeaconTracker.java    From android-beacon-library with Apache License 2.0 5 votes vote down vote up
/**
 * Tracks a beacon. For Gatt-based beacons, returns a merged copy of fields from multiple
 * frames. Returns null when passed a Gatt-based beacon that has is only extra beacon data.
 */
@Nullable
public synchronized Beacon track(@NonNull Beacon beacon) {
    Beacon trackedBeacon = null;
    if (beacon.isMultiFrameBeacon() || beacon.getServiceUuid() != -1) {
        trackedBeacon = trackGattBeacon(beacon);
    }
    else {
        trackedBeacon = beacon;
    }
    return trackedBeacon;
}