package com.urbanairship.location;

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

/* loaded from: /storage/emulated/0/Documents/jadec/sources/com.UBI.A90.WW/dex-files/2.dex */
public class LastLocationFinder {
    private LocationManager locationManager;

    public LastLocationFinder(Context context) {
        this.locationManager = (LocationManager) context.getSystemService("location");
    }

    public Location getLastBestLocation(int i, long j) {
        long j2;
        float f;
        Location location;
        Location location2 = null;
        long j3 = Long.MAX_VALUE;
        float f2 = Float.MAX_VALUE;
        for (String str : this.locationManager.getAllProviders()) {
            Location lastKnownLocation = this.locationManager.getLastKnownLocation(str);
            if (lastKnownLocation != null) {
                float accuracy = lastKnownLocation.getAccuracy();
                j2 = lastKnownLocation.getTime();
                if (j2 < j && accuracy < f2) {
                    f = accuracy;
                    location = lastKnownLocation;
                } else if (j2 > j && f2 == Float.MAX_VALUE && j2 < j3) {
                    f = f2;
                    location = lastKnownLocation;
                }
                f2 = f;
                location2 = location;
                j3 = j2;
            }
            j2 = j3;
            f = f2;
            location = location2;
            f2 = f;
            location2 = location;
            j3 = j2;
        }
        return location2;
    }
}
