package cn.jiguang.ad; import android.annotation.SuppressLint; import android.content.Context; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.os.Handler; import android.os.HandlerThread; import android.os.Looper; import android.os.Message; import cn.jiguang.ae.b; import cn.jiguang.o.d; @SuppressLint({"MissingPermission"}) class c { private static final Object e = new Object(); private static c h = null; protected Handler a; private Context b; private LocationManager c; private b d; private boolean f; private String g; private LocationListener i = new LocationListener() { /* class cn.jiguang.ad.c.AnonymousClass1 */ public void onLocationChanged(Location location) { try { cn.jiguang.af.a.a("JLocationGps", "onLocationChanged:" + location + ",provider:" + c.this.g); c.this.a((c) location); c.this.h(); } catch (Throwable th) { cn.jiguang.af.a.d("JLocationGps", "onLocationChanged failed:" + th.getMessage()); } } public void onProviderDisabled(String str) { cn.jiguang.af.a.a("JLocationGps", "onProviderDisabled:" + str); c.this.h(); } public void onProviderEnabled(String str) { cn.jiguang.af.a.a("JLocationGps", "onProviderEnabled:" + str); } public void onStatusChanged(String str, int i, Bundle bundle) { cn.jiguang.af.a.a("JLocationGps", "onStatusChanged status:" + i); if (i == 0) { c.this.h(); } } }; /* access modifiers changed from: package-private */ public class a extends Handler { public a(Looper looper) { super(looper); } public void handleMessage(Message message) { String str; String str2; int i = 1001; switch (message.what) { case 1001: try { if (c.this.g == null || !c.this.g.equals("network")) { cn.jiguang.af.a.d("JLocationGps", "get " + c.this.g + " time out "); c.this.h(); return; } cn.jiguang.af.a.d("JLocationGps", "get gps with network time out "); c.this.g = "gps"; c.this.g(); c.this.c.requestLocationUpdates(c.this.g, 2000, 0.0f, c.this.i); cn.jiguang.af.a.a("JLocationGps", "request " + c.this.g + " location"); c.this.a.sendEmptyMessageDelayed(1001, 10000); return; } catch (Throwable th) { cn.jiguang.af.a.d("JLocationGps", "when location time out " + th.getMessage()); break; } case 1002: default: return; case 1003: try { c.this.c.requestLocationUpdates(c.this.g, 2000, 0.0f, c.this.i); cn.jiguang.af.a.a("JLocationGps", "request " + c.this.g + " location"); c.this.a.sendEmptyMessageDelayed(i, 20000); return; } catch (SecurityException unused) { str = "JLocationGps"; str2 = "No suitable permission when get last known location!"; break; } catch (Throwable unused2) { str = "JLocationGps"; str2 = "The provider is illegal argument!"; break; } case 1004: cn.jiguang.af.a.a("JLocationGps", "LOAD_GPS_ACTION_REQUEST_ONLY_NETWORK"); i = 1005; c.this.c.requestLocationUpdates(c.this.g, 2000, 0.0f, c.this.i); cn.jiguang.af.a.a("JLocationGps", "request " + c.this.g + " location"); c.this.a.sendEmptyMessageDelayed(i, 20000); return; case 1005: str = "JLocationGps"; str2 = "get only network " + c.this.g + " time out "; cn.jiguang.af.a.d(str, str2); c.this.h(); return; } } } private c(Context context) { this.b = context; this.c = (LocationManager) context.getSystemService("location"); } public static c a(Context context) { if (h == null) { synchronized (e) { if (h == null) { h = new c(context); } } } return h; } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void a(Location location) { if (location != null) { cn.jiguang.af.a.a("JLocationGps", "updateGpsInfo location time:" + location.getTime()); if (this.d == null) { this.d = new b(); } this.d.a = d.a(this.b, location.getTime()); this.d.b = location.getProvider(); this.d.c = location.getLatitude(); this.d.d = location.getLongitude(); this.d.f = (double) location.getBearing(); this.d.g = (double) location.getAccuracy(); return; } this.d = null; } private boolean a(Location location, Location location2) { if (location == null) { return false; } if (location2 == null) { return true; } long time = location.getTime() - location2.getTime(); boolean z = time > 120000; boolean z2 = time < -120000; boolean z3 = time > 0; if (z) { return true; } if (z2) { return false; } int accuracy = (int) (location.getAccuracy() - location2.getAccuracy()); boolean z4 = accuracy > 0; boolean z5 = accuracy < 0; boolean z6 = accuracy > 200; boolean a2 = a(location.getProvider(), location2.getProvider()); if (z5) { return true; } if (!z3 || z4) { return z3 && !z6 && a2; } return true; } private boolean a(String str, String str2) { return str == null ? str2 == null : str.equals(str2); } private void f() { try { if (this.a == null) { HandlerThread handlerThread = new HandlerThread("jg_lcn_thread"); handlerThread.start(); this.a = new a(handlerThread.getLooper()); } } catch (Throwable th) { cn.jiguang.af.a.f("JLocationGps", "start load loc-info failed - error:" + th); } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void g() { String str; String str2; try { if (this.i == null) { str = "JLocationGps"; str2 = "Location listener is null , do nothing!"; } else if (this.c != null) { this.c.removeUpdates(this.i); return; } else { str = "JLocationGps"; str2 = "locationManager is null , do nothing!"; } cn.jiguang.af.a.d(str, str2); } catch (Throwable th) { cn.jiguang.af.a.d("JLocationGps", "remove location listener failed e:" + th.getMessage()); } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void h() { cn.jiguang.af.a.a("JLocationGps", "gps will done"); this.f = true; g(); Handler handler = this.a; if (handler != null) { if (handler.hasMessages(1004)) { this.a.removeMessages(1004); } if (this.a.hasMessages(1003)) { this.a.removeMessages(1003); } if (this.a.hasMessages(1001)) { this.a.removeMessages(1001); } if (this.a.hasMessages(1005)) { this.a.removeMessages(1005); } try { this.a.getLooper().quit(); } catch (Throwable th) { this.a = null; throw th; } this.a = null; return; } cn.jiguang.af.a.e("JLocationGps", "cellLocationManager is null,please check it"); } /* access modifiers changed from: package-private */ public b a() { return this.d; } /* access modifiers changed from: package-private */ public boolean b() { return this.f; } /* access modifiers changed from: package-private */ public void c() { Handler handler; String str; String str2; String str3; this.f = false; this.d = null; if (this.c == null) { str2 = "JLocationGps"; str3 = "get locationManager failed"; } else { f(); if (this.a == null) { str2 = "JLocationGps"; str3 = " mAsyncHandler is empty"; } else { int i2 = 1003; if (this.c.isProviderEnabled("network")) { str = "network"; } else if (this.c.isProviderEnabled("gps")) { str = "gps"; } else { this.g = "network"; handler = this.a; i2 = 1004; handler.sendEmptyMessage(i2); return; } this.g = str; handler = this.a; handler.sendEmptyMessage(i2); return; } } cn.jiguang.af.a.d(str2, str3); this.f = true; } /* JADX WARNING: Removed duplicated region for block: B:11:0x0030 A[Catch:{ Throwable -> 0x0069 }] */ /* JADX WARNING: Removed duplicated region for block: B:18:? A[ADDED_TO_REGION, RETURN, SYNTHETIC] */ public b d() { try { Location lastKnownLocation = this.c.getLastKnownLocation("gps"); Location lastKnownLocation2 = this.c.getLastKnownLocation("network"); Location lastKnownLocation3 = this.c.getLastKnownLocation("passive"); if (a(lastKnownLocation, lastKnownLocation2)) { if (a(lastKnownLocation, lastKnownLocation3)) { if (lastKnownLocation != null && System.currentTimeMillis() - lastKnownLocation.getTime() < 30000) { a(lastKnownLocation); cn.jiguang.af.a.a("JLocationGps", "bestLocation:" + this.d + ",curTime:" + System.currentTimeMillis()); return this.d; } } } else if (a(lastKnownLocation2, lastKnownLocation3)) { lastKnownLocation = lastKnownLocation2; return lastKnownLocation != null ? null : null; } lastKnownLocation = lastKnownLocation3; if (lastKnownLocation != null) { } } catch (Throwable th) { cn.jiguang.af.a.d("JLocationGps", "loadLastGpsInfo failed: " + th.getMessage()); return null; } } public boolean e() { String str; String str2; try { if (this.c != null) { return this.c.isProviderEnabled("gps") || this.c.isProviderEnabled("network") || this.c.isProviderEnabled("passive"); } return false; } catch (SecurityException unused) { str = "JLocationGps"; str2 = "No suitable permission is present when get GPS_PROVIDER!"; cn.jiguang.af.a.d(str, str2); return false; } catch (IllegalArgumentException unused2) { str = "JLocationGps"; str2 = "The provider [gps] is illegal argument!"; cn.jiguang.af.a.d(str, str2); return false; } catch (Exception unused3) { str = "JLocationGps"; str2 = "The ILocationManager is null!"; cn.jiguang.af.a.d(str, str2); return false; } } }