Open davidgyoung opened 3 years ago
The redesign needs to replace and deprecate the BeaconManager configuration method public static void setRssiFilterImplClass(@NonNull Class c)
due to issues in #1164. The RssiFilter interface will hopefully remain unchanged.
Work in progress PR is here: #1177
The Problem
Configuring the library has evolved over time with a mixed bag of styles of settings including:
In addition, changing settings at runtime (after scanning has started) can sometimes cause problems and behavior is either poorly documented, non-deterministic, or at worst cause crashes. Even in the best of cases, changes to not necessarily take effect right away, and it is unclear to users what does take effect right away and what does not.
Constraints
This proposal for improvement in the library API is designed to stay within the following constraints:
Settings API Proposal
The Settings Class below is used to set up library scanning settings. These are typically set before starting ranging/monitoring. If you want to change them after ranging and monitoring are already started, the settings change will stop and restart ranging and monitoring.
The class design below is designed to use a Kotlin data class with a Builder class designed for use by Java apps
Kotlin:
Java:
There are three methods added to BeaconManager for applying a Settings object:
Configure scheduled job strategy (default on Android 8+)
Configure background service strategy (default on Android 4.3-7.x)
Configure foreground service strategy
Configure intent scan strategy
Deprecated settings that will not be supported by new API
New BeaconParsers and Region API
Instead of manually configuring BeaconParsers on the BeaconManager using the
beaconManager.getBeaconParsers()
collection, a newRegion
class calledBeaconRegion
will explicitly set the BeaconParser used for each region. Starting ranging or monitoring will auto-register the parser with the library if it has not already been registered.The point of this change is to make it pretty much impossible to forget to register a parser before starting ranging/monitoring. This also makes it explicit which beacon type you are looking for with the region, and only beacons of that type will match the region.
While proprietary closed-source beacon types cannot be configured in the AltBeacon project due to intellectual property restrictions, external libraries can define them. Referencing these external libraries with the parser definitions makes it much easier to configure apps to work with proprietary beacons:
build.gradle:
Start ranging:
Note in the above that there is a new second parameter in the region constructor for the BeaconParser. This is parser is activated in the library the first time ranging or monitoring is started as shown in the second line.