/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  javax.microedition.location.Coordinates
 *  javax.microedition.location.Criteria
 *  javax.microedition.location.Location
 *  javax.microedition.location.LocationException
 *  javax.microedition.location.LocationListener
 *  javax.microedition.location.LocationProvider
 *  javax.microedition.location.QualifiedCoordinates
 */
import javax.microedition.location.Coordinates;
import javax.microedition.location.Criteria;
import javax.microedition.location.Location;
import javax.microedition.location.LocationException;
import javax.microedition.location.LocationListener;
import javax.microedition.location.LocationProvider;
import javax.microedition.location.QualifiedCoordinates;

public class fy
extends px
implements LocationListener {
    private LocationProvider j;
    private Coordinates k;
    private boolean l = false;
    public String a = "";

    public final boolean d() {
        return true;
    }

    public String b() {
        return "gps";
    }

    public static LocationProvider a(Criteria criteria) {
        return LocationProvider.getInstance((Criteria)criteria);
    }

    public static void a(fy fy2) {
        fy2.m();
    }

    public fy(lh lh2) {
        super(lh2, true, false);
        lh2.g = true;
    }

    public void locationUpdated(LocationProvider locationProvider, Location location) {
        if (this.g && !this.h) {
            this.a(location);
        }
    }

    public void providerStateChanged(LocationProvider locationProvider, int n) {
        if (n == 3) {
            this.m();
        }
    }

    private static boolean b(LocationProvider locationProvider) {
        return locationProvider.getState() == 3;
    }

    public final void c() {
        this.a = "";
        try {
            if (this.j != null) {
                this.j.reset();
                this.j = null;
            }
            return;
        }
        catch (SecurityException securityException) {
            this.j = null;
            return;
        }
        catch (NullPointerException nullPointerException) {
            this.j = null;
            return;
        }
    }

    private void g() {
        this.g = false;
        this.a(3);
    }

    private void m() {
        this.g = false;
        this.a = "";
        this.a(false);
    }

    public final void a(int n) {
        this.a = n == 5 ? lh.d(265) : "";
        super.a(n);
    }

    private void a(boolean bl2) {
        if (!this.l) {
            String string = !bl2 ? "n" : "y";
            me.a((short)58, "jsr179", string);
            this.l = true;
        }
    }

    /*
     * Enabled aggressive block sorting
     */
    private void a(Location location) {
        this.a = "";
        if (location != null && location.isValid()) {
            QualifiedCoordinates qualifiedCoordinates = location.getQualifiedCoordinates();
            if (qualifiedCoordinates.getLatitude() == 0.0 && qualifiedCoordinates.getLongitude() == 0.0) {
                this.a(false);
                return;
            }
            int n = (int)location.getSpeed();
            int n2 = location.getLocationMethod() != 8 ? (!Float.isNaN(qualifiedCoordinates.getHorizontalAccuracy()) ? Math.max((int)qualifiedCoordinates.getHorizontalAccuracy(), 3) : -1) : 1000;
            this.g = true;
            int n3 = !Float.isNaN(location.getCourse()) ? (int)location.getCourse() : -1;
            if (n2 == -1 || this.i() == -1 || this.i() > n2 || this.k == null || this.k.distance((Coordinates)qualifiedCoordinates) > (float)this.i() || System.currentTimeMillis() - this.b > (long)6000) {
                this.a(new iv((int)(qualifiedCoordinates.getLatitude() * 1000000.0), (int)(qualifiedCoordinates.getLongitude() * 1000000.0)), n3, n, n2);
            }
            this.k = qualifiedCoordinates;
            return;
        } else {
            if (this.j()) return;
            this.a(5);
            this.g = false;
            return;
        }
    }

    public void a() {
        this.a = "";
        try {
            this.j = LocationProvider.getInstance((Criteria)new Criteria());
            if (this.j == null) {
                this.m();
                return;
            }
            this.j.setLocationListener((LocationListener)new br(this, null), 1, 1, 1);
            if (!fy.b(this.j)) {
                this.a(this.j, 360);
                this.g = this.j();
                this.a(this.g);
                if (this.g && !this.h) {
                    this.j.setLocationListener((LocationListener)this, 1, 1, 1);
                    return;
                }
                this.j = null;
                return;
            }
            this.m();
            return;
        }
        catch (SecurityException securityException) {
            this.c();
            this.g();
            return;
        }
        catch (LocationException locationException) {
            if (this.j != null && fy.b(this.j)) {
                this.m();
                return;
            }
            me.a("GPS", locationException);
            this.a(1);
            return;
        }
    }

    public final void a(LocationProvider locationProvider, int n) {
        try {
            this.a = lh.d(267);
            this.a(locationProvider.getLocation(n));
            return;
        }
        catch (LocationException locationException) {
            if (!fy.b(locationProvider)) {
                this.a(5);
                return;
            }
            this.m();
            return;
        }
        catch (IllegalArgumentException illegalArgumentException) {
            IllegalArgumentException illegalArgumentException2;
            StringBuffer stringBuffer = new StringBuffer().append("getFix, lp is ");
            String string = locationProvider == null ? "null" : "not null";
            IllegalArgumentException illegalArgumentException3 = illegalArgumentException2;
            illegalArgumentException3(stringBuffer.append(string).append(", status is ").append(this.a).toString());
            me.b("GPS", illegalArgumentException3);
            this.a(1);
            return;
        }
        catch (SecurityException securityException) {
            this.g();
            return;
        }
        catch (InterruptedException interruptedException) {
            this.a(1);
            return;
        }
    }
}

