<commit_before>using Plugin.Geolocator.Abstractions;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Android.Locations;
using System.Threading;
using Android.App;
using Android.OS;
using System.Linq;
using Android.Content;
using Android.Content.PM;
using Plugin.Permissions;
using Android.Runtime;
using Address = Plugin.Geolocator.Abstractions.Address;

namespace Plugin.Geolocator
{
    /// <summary>
    /// Implementation for Feature
    /// </summary>
    [Preserve(AllMembers = true)]
    public class GeolocatorImplementation : IGeolocator
    {
        string[] allProviders;
        LocationManager locationManager;

        GeolocationContinuousListener listener;

        readonly object positionSync = new object();
        Position lastPosition;

        /// <summary>
        /// Default constructor
        /// </summary>
        public GeolocatorImplementation()
        {
            DesiredAccuracy = 100;
        }

        string[] Providers => Manager.GetProviders(enabledOnly: false).ToArray();
       

        LocationManager Manager
        {
            get
            {
                if (locationManager == null)
                    locationManager = (LocationManager)Application.Context.GetSystemService(Context.LocationService);

                return locationManager;
            }
        }

        /// <inheritdoc/>
        public event EventHandler<PositionErrorEventArgs> PositionError;
        /// <inheritdoc/>
        public event EventHandler<PositionEventArgs> PositionChanged;
        /// <inheritdoc/>
        public bool IsListening => listener != null;


        /// <inheritdoc/>
        public double DesiredAccuracy
        {
            get;
            set;
        }

        /// <inheritdoc/>
        public bool SupportsHeading => true;


        /// <inheritdoc/>
        public bool IsGeolocationAvailable => Providers.Length > 0;


        /// <inheritdoc/>
        public bool IsGeolocationEnabled => Providers.Any(p => p != LocationManager.PassiveProvider && Manager.IsProviderEnabled(p));


        public async Task<Position> GetLastKnownLocationAsync()
        {
            var hasPermission = await CheckPermissions();
            if (!hasPermission)
                return null;

            Location bestLocation = null;
            foreach (var provider in Providers)
            {
                var location = Manager.GetLastKnownLocation(provider);
                if (location != null && GeolocationUtils.IsBetterLocation(location, bestLocation))
                    bestLocation = location;
            }

            return bestLocation?.ToPosition();

        }

        async Task<bool> CheckPermissions()
        {
            var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permissions.Abstractions.Permission.Location);
            if (status != Permissions.Abstractions.PermissionStatus.Granted)
            {
                Console.WriteLine("Currently does not have Location permissions, requesting permissions");

                var request = await CrossPermissions.Current.RequestPermissionsAsync(Permissions.Abstractions.Permission.Location);

                if (request[Permissions.Abstractions.Permission.Location] != Permissions.Abstractions.PermissionStatus.Granted)
                {<commit_msg>Fix for #75 list ignored providers for enabled flag<commit_after>using Plugin.Geolocator.Abstractions;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Android.Locations;
using System.Threading;
using Android.App;
using Android.OS;
using System.Linq;
using Android.Content;
using Android.Content.PM;
using Plugin.Permissions;
using Android.Runtime;
using Address = Plugin.Geolocator.Abstractions.Address;

namespace Plugin.Geolocator
{
    /// <summary>
    /// Implementation for Feature
    /// </summary>
    [Preserve(AllMembers = true)]
    public class GeolocatorImplementation : IGeolocator
    {
        string[] allProviders;
        LocationManager locationManager;

        GeolocationContinuousListener listener;

        readonly object positionSync = new object();
        Position lastPosition;

        /// <summary>
        /// Default constructor
        /// </summary>
        public GeolocatorImplementation()
        {
            DesiredAccuracy = 100;
        }

        string[] Providers => Manager.GetProviders(enabledOnly: false).ToArray();
        string[] IgnoredProviders => new string[] { LocationManager.PassiveProvider, "local_database" };

        LocationManager Manager
        {
            get
            {
                if (locationManager == null)
                    locationManager = (LocationManager)Application.Context.GetSystemService(Context.LocationService);

                return locationManager;
            }
        }

        /// <inheritdoc/>
        public event EventHandler<PositionErrorEventArgs> PositionError;
        /// <inheritdoc/>
        public event EventHandler<PositionEventArgs> PositionChanged;
        /// <inheritdoc/>
        public bool IsListening => listener != null;


        /// <inheritdoc/>
        public double DesiredAccuracy
        {
            get;
            set;
        }

        /// <inheritdoc/>
        public bool SupportsHeading => true;


        /// <inheritdoc/>
        public bool IsGeolocationAvailable => Providers.Length > 0;


        /// <inheritdoc/>
        public bool IsGeolocationEnabled => Providers.Any(p => !IgnoredProviders.Contains(p) && Manager.IsProviderEnabled(p));


        public async Task<Position> GetLastKnownLocationAsync()
        {
            var hasPermission = await CheckPermissions();
            if (!hasPermission)
                return null;

            Location bestLocation = null;
            foreach (var provider in Providers)
            {
                var location = Manager.GetLastKnownLocation(provider);
                if (location != null && GeolocationUtils.IsBetterLocation(location, bestLocation))
                    bestLocation = location;
            }

            return bestLocation?.ToPosition();

        }

        async Task<bool> CheckPermissions()
        {
            var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permissions.Abstractions.Permission.Location);
            if (status != Permissions.Abstractions.PermissionStatus.Granted)
            {
                Console.WriteLine("Currently does not have Location permissions, requesting permissions");

                var request = await CrossPermissions.Current.RequestPermissionsAsync(Permissions.Abstractions.Permission.Location);

                if (request[Permissions.Abstractions.Permission.Location] != Permissions.Abstractions.PermissionStatus.Granted)
                {
{'fraction_non_alphanumeric': 0.08833870495165544, 'fraction_numerical': 0.001464986815118664, 'mean_word_length': 2.2248464808691546, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5041627', 'n_tokens_mistral': 1661, 'n_tokens_neox': 1581, 'n_words': 363}