From 5e88160aab48efc061e63b9746779db16d339478 Mon Sep 17 00:00:00 2001 From: Garvan Keeley Date: Sat, 8 Nov 2014 09:09:00 -0500 Subject: [PATCH] Bug 1095914 - Fix crash if GPS not available. r=vng https://github.com/mozilla/MozStumbler/pull/1206 --- .../stumblerthread/scanners/GPSScanner.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mobile/android/stumbler/java/org/mozilla/mozstumbler/service/stumblerthread/scanners/GPSScanner.java b/mobile/android/stumbler/java/org/mozilla/mozstumbler/service/stumblerthread/scanners/GPSScanner.java index e72bbfeefa8c..6d4a61131c56 100644 --- a/mobile/android/stumbler/java/org/mozilla/mozstumbler/service/stumblerthread/scanners/GPSScanner.java +++ b/mobile/android/stumbler/java/org/mozilla/mozstumbler/service/stumblerthread/scanners/GPSScanner.java @@ -65,8 +65,23 @@ public class GPSScanner implements LocationListener { } } + private boolean isGpsAvailable(LocationManager locationManager) { + if (locationManager == null || + locationManager.getProvider(LocationManager.GPS_PROVIDER) == null) { + String msg = "No GPS available, scanning not started."; + Log.d(LOG_TAG, msg); + AppGlobals.guiLogError(msg); + return false; + } + return true; + } + private void startPassiveMode() { LocationManager locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); + if (!isGpsAvailable(locationManager)) { + return; + } + locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 0, 0, this); @@ -74,6 +89,10 @@ public class GPSScanner implements LocationListener { private void startActiveMode() { LocationManager lm = getLocationManager(); + if (!isGpsAvailable(lm)) { + return; + } + lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, ACTIVE_MODE_GPS_MIN_UPDATE_TIME_MS, ACTIVE_MODE_GPS_MIN_UPDATE_DISTANCE_M,