/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package info.zamojski.soft.towercollector.utils;

import android.content.Context;
import android.location.LocationManager;

public class GpsUtils {

    public static boolean isGpsEnabled(Context context) {
        LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    }

    public static boolean isGpsAvailable(Context context) {
        LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
        return (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER));
    }
}

@@ -249,16 +249,41 @@
 utils;%0A%0A
+import android.Manifest;%0A
 import a
@@ -346,16 +346,69 @@
 Manager;
+%0Aimport android.support.v4.content.PermissionChecker;
 %0A%0Apublic
@@ -476,32 +476,181 @@
 text context) %7B%0A
+%0A        if (PermissionChecker.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PermissionChecker.PERMISSION_GRANTED) %7B%0A    
         Location
@@ -737,32 +737,36 @@
 ATION_SERVICE);%0A
+    
         return l
@@ -829,16 +829,121 @@
 VIDER);%0A
+        %7D%0A        // to cover the case when permission denied on API lower than 21%0A        return false;%0A
     %7D%0A%0A 

Fix crash when checking for GPS availability denied on API lower than 21.