Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get filter nullpointerexception #1181

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/src/main/java/org/altbeacon/beacon/BeaconManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1529,9 +1529,9 @@ public static void setDistanceModelUpdateUrl(@NonNull String url) {
}

/**
* Default class for rssi filter/calculation implementation
* Set class for rssi filter/calculation implementation
*/
protected static Class rssiFilterImplClass = RunningAverageRssiFilter.class;
protected static Class rssiFilterImplClass = null;

public static void setRssiFilterImplClass(@NonNull Class c) {
warnIfScannerNotInSameProcess();
Expand Down
20 changes: 13 additions & 7 deletions lib/src/main/java/org/altbeacon/beacon/service/RangedBeacon.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,21 @@ public boolean isExpired() {

private RssiFilter getFilter() {
if (mFilter == null) {
//set RSSI filter
try {
Constructor cons = BeaconManager.getRssiFilterImplClass().getConstructors()[0];
mFilter = (RssiFilter)cons.newInstance();
} catch (Exception e) {
LogManager.e(TAG, "Could not construct RssiFilterImplClass %s", BeaconManager.getRssiFilterImplClass().getName());
// Use custom RSSI filter
if (BeaconManager.getRssiFilterImplClass() != null) {
try {
mFilter = (RssiFilter) BeaconManager.getRssiFilterImplClass().newInstance();
} catch (Exception e) {
LogManager.e(TAG, "Failed with exception %s", e.toString());
LogManager.e(TAG, "Could not construct class %s", BeaconManager.getRssiFilterImplClass().getName());
LogManager.e(TAG, "Will default to RunningAverageRssiFilter");
mFilter = new RunningAverageRssiFilter();
}
} else {
// Use default rssi filter
mFilter = new RunningAverageRssiFilter();
}
}
return mFilter;
}

}