// Path: src/it/reyboz/bustorino/util/LocationCriteria.java
// public class LocationCriteria extends Criteria {
//     private final float minAccuracy;
//     private final int timeInterval;
// 
//     /**
//      * Constructor
//      * @param minAccuracy in meters
//      * @param timeInterval in milliseconds
//      */
//     public LocationCriteria(float minAccuracy,int timeInterval){
//         this.minAccuracy = minAccuracy;
//         this.timeInterval = timeInterval;
//     }
// 
//     public float getMinAccuracy() {
//         return minAccuracy;
//     }
// 
// 
//     public int getTimeInterval() {
//         return timeInterval;
//     }
// 
// }
// 
// Path: src/it/reyboz/bustorino/util/Permissions.java
// public class Permissions {
//     final static public String DEBUG_TAG = "BusTO -Permissions";
// 
//     final static public int PERMISSION_REQUEST_POSITION = 33;
//     final static public String LOCATION_PERMISSION_GIVEN = "loc_permission";
//     final static public int STORAGE_PERMISSION_REQ = 291;
// 
//     final static public int PERMISSION_OK = 0;
//     final static public int PERMISSION_ASKING = 11;
//     final static public int PERMISSION_NEG_CANNOT_ASK = -3;
// 
//     final static public String[] LOCATION_PERMISSIONS={Manifest.permission.ACCESS_COARSE_LOCATION,
//             Manifest.permission.ACCESS_FINE_LOCATION};
// 
//     public static boolean anyLocationProviderMatchesCriteria(LocationManager mng, Criteria cr, boolean enabled) {
//         List<String> providers = mng.getProviders(cr, enabled);
//         Log.d(DEBUG_TAG, "Getting enabled location providers: ");
//         for (String s : providers) {
//             Log.d(DEBUG_TAG, "Provider " + s);
//         }
//         return providers.size() > 0;
//     }
//     public static boolean isPermissionGranted(Context con,String permission){
//         return ContextCompat.checkSelfPermission(con, permission) == PackageManager.PERMISSION_GRANTED;
//     }
// 
//     public static boolean locationPermissionGranted(Context con){
//         return isPermissionGranted(con, Manifest.permission.ACCESS_FINE_LOCATION) &&
//                 isPermissionGranted(con, Manifest.permission.ACCESS_COARSE_LOCATION);
//     }
// 
//     public static void assertLocationPermissions(Context con, Activity activity) {
//         if(!isPermissionGranted(con, Manifest.permission.ACCESS_FINE_LOCATION) ||
//                 !isPermissionGranted(con,Manifest.permission.ACCESS_COARSE_LOCATION)){
//             ActivityCompat.requestPermissions(activity,new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSION_REQUEST_POSITION);
//         }
//     }
// }


import it.reyboz.bustorino.util.LocationCriteria;
import it.reyboz.bustorino.util.Permissions;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.ListIterator;
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import androidx.core.content.ContextCompat;
            }
                oldGPSLocStatus = status;
            }
        Log.d(DEBUG_TAG, "Provider status changed: "+provider+" status: "+status);
    }

    @Override
    public void onProviderEnabled(String provider) {
        cleanAndUpdateRequesters();
        requestGPSPositionUpdates();
        Log.d(DEBUG_TAG, "Provider: "+provider+" enabled");
        for(WeakReference<LocationRequester> req: requestersRef){
            if(req.get()==null) continue;
            req.get().onLocationProviderAvailable();
        }

    }

    @Override
    public void onProviderDisabled(String provider) {
        cleanAndUpdateRequesters();
        for(WeakReference<LocationRequester> req: requestersRef){
            if(req.get()==null) continue;
            req.get().onLocationDisabled();
        }
        //locMan.removeUpdates(this);
        Log.d(DEBUG_TAG, "Provider: "+provider+" disabled");
    }

    public boolean anyLocationProviderMatchesCriteria(Criteria cr) {
// Path: src/it/reyboz/bustorino/util/LocationCriteria.java
// public class LocationCriteria extends Criteria {
//     private final float minAccuracy;
//     private final int timeInterval;
// 
//     /**
//      * Constructor
//      * @param minAccuracy in meters
//      * @param timeInterval in milliseconds
//      */
//     public LocationCriteria(float minAccuracy,int timeInterval){
//         this.minAccuracy = minAccuracy;
//         this.timeInterval = timeInterval;
//     }
// 
//     public float getMinAccuracy() {
//         return minAccuracy;
//     }
// 
// 
//     public int getTimeInterval() {
//         return timeInterval;
//     }
// 
// }
// 
// Path: src/it/reyboz/bustorino/util/Permissions.java
// public class Permissions {
//     final static public String DEBUG_TAG = "BusTO -Permissions";
// 
//     final static public int PERMISSION_REQUEST_POSITION = 33;
//     final static public String LOCATION_PERMISSION_GIVEN = "loc_permission";
//     final static public int STORAGE_PERMISSION_REQ = 291;
// 
//     final static public int PERMISSION_OK = 0;
//     final static public int PERMISSION_ASKING = 11;
//     final static public int PERMISSION_NEG_CANNOT_ASK = -3;
// 
//     final static public String[] LOCATION_PERMISSIONS={Manifest.permission.ACCESS_COARSE_LOCATION,
//             Manifest.permission.ACCESS_FINE_LOCATION};
// 
//     public static boolean anyLocationProviderMatchesCriteria(LocationManager mng, Criteria cr, boolean enabled) {
//         List<String> providers = mng.getProviders(cr, enabled);
//         Log.d(DEBUG_TAG, "Getting enabled location providers: ");
//         for (String s : providers) {
//             Log.d(DEBUG_TAG, "Provider " + s);
//         }
//         return providers.size() > 0;
//     }
//     public static boolean isPermissionGranted(Context con,String permission){
//         return ContextCompat.checkSelfPermission(con, permission) == PackageManager.PERMISSION_GRANTED;
//     }
// 
//     public static boolean locationPermissionGranted(Context con){
//         return isPermissionGranted(con, Manifest.permission.ACCESS_FINE_LOCATION) &&
//                 isPermissionGranted(con, Manifest.permission.ACCESS_COARSE_LOCATION);
//     }
// 
//     public static void assertLocationPermissions(Context con, Activity activity) {
//         if(!isPermissionGranted(con, Manifest.permission.ACCESS_FINE_LOCATION) ||
//                 !isPermissionGranted(con,Manifest.permission.ACCESS_COARSE_LOCATION)){
//             ActivityCompat.requestPermissions(activity,new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSION_REQUEST_POSITION);
//         }
//     }
// }


// Path: src/it/reyboz/bustorino/middleware/AppLocationManager.java
import it.reyboz.bustorino.util.LocationCriteria;
import it.reyboz.bustorino.util.Permissions;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.ListIterator;
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import androidx.core.content.ContextCompat;

            }
                oldGPSLocStatus = status;
            }
        Log.d(DEBUG_TAG, "Provider status changed: "+provider+" status: "+status);
    }

    @Override
    public void onProviderEnabled(String provider) {
        cleanAndUpdateRequesters();
        requestGPSPositionUpdates();
        Log.d(DEBUG_TAG, "Provider: "+provider+" enabled");
        for(WeakReference<LocationRequester> req: requestersRef){
            if(req.get()==null) continue;
            req.get().onLocationProviderAvailable();
        }

    }

    @Override
    public void onProviderDisabled(String provider) {
        cleanAndUpdateRequesters();
        for(WeakReference<LocationRequester> req: requestersRef){
            if(req.get()==null) continue;
            req.get().onLocationDisabled();
        }
        //locMan.removeUpdates(this);
        Log.d(DEBUG_TAG, "Provider: "+provider+" disabled");
    }

    public boolean anyLocationProviderMatchesCriteria(Criteria cr) {
        return Permissions.anyLocationProviderMatchesCriteria(locMan, cr, true);