Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Fix SecurityException when scanning for wifis (#581)
Browse files Browse the repository at this point in the history
* Fix SE when scanning for wifis

On specific android versions wifiManager.getScanResults didn't
return an empty list but instead threw an exception. Check if
permission has been granted and only if so access scan results.

Fixes #569

* Remove unused log import
  • Loading branch information
anselm92 authored and pfent committed Nov 12, 2017
1 parent 474eeef commit f6e4500
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public void onReceive(Context context, Intent intent) {
boolean locationsEnabled = ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
boolean wifiScansEnabled = Utils.getInternalSettingBool(context, WifiMeasurementManager.WIFI_SCANS_ALLOWED, false);
boolean nextScanScheduled = false;

if (!locationsEnabled) {
//Stop here as wifi.getScanResults will either return an empty list or throw an exception (on android 6.0.0)
return;
}

WifiScanHandler wifiScanHandler = WifiScanHandler.getInstance(context);
List<ScanResult> scan = wifi.getScanResults();
for (final ScanResult network : scan) {
Expand All @@ -82,7 +88,7 @@ public void onReceive(Context context, Intent intent) {
}

//if user allowed us to store his signal strength, store measurement to the local DB and later sync to remote
if (locationsEnabled && wifiScansEnabled) {
if (wifiScansEnabled) {
storeWifiMeasurement(context, network);
nextScanScheduled = true;
}
Expand Down

0 comments on commit f6e4500

Please sign in to comment.