<commit_before>package de.stephanlindauer.criticalmaps.utils;

import android.location.LocationManager;

import org.osmdroid.util.GeoPoint;

public class LocationUtils {
    public static GeoPoint getBestLastKnownLocation(LocationManager locationManager) {
        GeoPoint lastKnownLocation = null;

        if (locationManager.isProviderEnabled(LocationManager.PASSIVE_PROVIDER)) {
            lastKnownLocation = new GeoPoint(
                    locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER).getLatitude(),
                    locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER).getLongitude());
        }

        if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
            lastKnownLocation = new GeoPoint(
                    locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER).getLatitude(),
                    locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER).getLongitude());
        }

        if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            lastKnownLocation = new GeoPoint(
                    locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER).getLatitude(),
                    locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER).getLongitude());
        }
        return lastKnownLocation;
    }
}<commit_msg>null pointer fix<commit_after>package de.stephanlindauer.criticalmaps.utils;

import android.location.Location;
import android.location.LocationManager;

import org.osmdroid.util.GeoPoint;

public class LocationUtils {
    public static GeoPoint getBestLastKnownLocation(LocationManager locationManager) {
        if (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER) && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            Location lastKnownLocationGps = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
            if (lastKnownLocationGps != null) {
                return new GeoPoint(
                        lastKnownLocationGps.getLatitude(),
                        lastKnownLocationGps.getLongitude());
            }
        }

        if (locationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER) && locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
            Location lastKnownLocationNetwork = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
            if (lastKnownLocationNetwork != null) {
                return new GeoPoint(
                        lastKnownLocationNetwork.getLatitude(),
                        lastKnownLocationNetwork.getLongitude());
            }
        }

        if (locationManager.getAllProviders().contains(LocationManager.PASSIVE_PROVIDER) && locationManager.isProviderEnabled(LocationManager.PASSIVE_PROVIDER)) {
            Location lastKnownLocationPassive = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
            if (lastKnownLocationPassive != null) {
                return new GeoPoint(
                        lastKnownLocationPassive.getLatitude(),
                        lastKnownLocationPassive.getLongitude());
            }
        }

        return null;
    }
}
{'fraction_non_alphanumeric': 0.07446808510638298, 'fraction_numerical': 0.0, 'mean_word_length': 3.047970479704797, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5833730', 'n_tokens_mistral': 852, 'n_tokens_neox': 791, 'n_words': 102}