package com.amap.api.col; import android.annotation.SuppressLint; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.HandlerThread; import android.os.Looper; import android.os.Message; import android.text.TextUtils; import com.amap.api.fence.GeoFence; import com.amap.api.fence.GeoFenceListener; import com.amap.api.fence.GeoFenceManagerBase; import com.amap.api.location.AMapLocation; import com.amap.api.location.AMapLocationClient; import com.amap.api.location.AMapLocationClientOption; import com.amap.api.location.AMapLocationListener; import com.amap.api.location.DPoint; import com.amap.api.services.district.DistrictSearchQuery; import com.netease.nim.uikit.common.media.model.GLImage; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @SuppressLint({"NewApi"}) /* compiled from: GeoFenceManager */ public class a implements GeoFenceManagerBase { Context a = null; PendingIntent b = null; String c = null; /* renamed from: d reason: collision with root package name */ String f952d = null; GeoFenceListener e = null; volatile int f = 1; ArrayList<GeoFence> g = new ArrayList<>(); c h = null; Object i = new Object(); HandlerC0000a j = null; b k = null; volatile boolean l = false; b m = null; c n = null; AMapLocationClient o = null; volatile AMapLocation p = null; long q = 0; AMapLocationClientOption r = null; int s = 0; AMapLocationListener t = new AMapLocationListener() { /* class com.amap.api.col.a.AnonymousClass1 */ /* JADX WARNING: Removed duplicated region for block: B:10:0x004b A[Catch:{ all -> 0x007f }] */ /* JADX WARNING: Removed duplicated region for block: B:11:0x0053 A[Catch:{ all -> 0x007f }] */ @Override // com.amap.api.location.AMapLocationListener public void onLocationChanged(AMapLocation aMapLocation) { boolean z; try { a.this.p = aMapLocation; if (aMapLocation != null) { if (aMapLocation.getErrorCode() == 0) { a.this.q = il.b(); a.this.a(5, (Bundle) null, 0); z = true; if (!z) { a aVar = a.this; aVar.s = 0; aVar.a(6, (Bundle) null, 0); return; } if (!a.this.l) { a.this.a(7); Bundle bundle = new Bundle(); bundle.putLong("interval", 2000); a.this.a(8, bundle, 2000); } a aVar2 = a.this; int i = aVar2.s + 1; aVar2.s = i; if (i >= 3) { aVar2.a(6, (Bundle) null, 0); return; } return; } int errorCode = aMapLocation.getErrorCode(); String errorInfo = aMapLocation.getErrorInfo(); il.a("定位失败", errorCode, errorInfo, "locationDetail:" + aMapLocation.getLocationDetail()); } z = false; if (!z) { } } catch (Throwable unused) { } } }; /* access modifiers changed from: package-private */ /* renamed from: com.amap.api.col.a$a reason: collision with other inner class name */ /* compiled from: GeoFenceManager */ public class HandlerC0000a extends Handler { public HandlerC0000a(Looper looper) { super(looper); } public void handleMessage(Message message) { try { switch (message.what) { case 0: a.this.b(message.getData()); return; case 1: a.this.c(message.getData()); return; case 2: a.this.e(message.getData()); return; case 3: a.this.d(message.getData()); return; case 4: a.this.f(message.getData()); return; case 5: a.this.g(); return; case 6: a aVar = a.this; aVar.a(aVar.p); return; case 7: a.this.d(); return; case 8: a.this.h(message.getData()); return; case 9: a.this.a(message.getData()); return; default: return; } } catch (Throwable unused) { } } } /* access modifiers changed from: package-private */ /* compiled from: GeoFenceManager */ public static class b extends HandlerThread { public b(String str) { super(str); } } public a(Context context) { this.a = context.getApplicationContext(); a(); } /* access modifiers changed from: package-private */ public void a() { try { if (Looper.myLooper() == null) { this.h = new c(this.a.getMainLooper()); } else { this.h = new c(); } } catch (Throwable th) { f.a(th, "AMapLocationManager", "init 1"); } try { b bVar = new b("fenceActionThread"); this.k = bVar; bVar.setPriority(5); this.k.start(); this.j = new HandlerC0000a(this.k.getLooper()); } catch (Throwable th2) { f.a(th2, "AMapLocationManager", "init 2"); } try { this.m = new b(this.a); this.n = new c(); this.r = new AMapLocationClientOption(); AMapLocationClient aMapLocationClient = new AMapLocationClient(this.a.getApplicationContext()); this.o = aMapLocationClient; aMapLocationClient.setLocationListener(this.t); } catch (Throwable th3) { f.a(th3, "AMapLocationManager", "init 3"); } } @Override // com.amap.api.fence.GeoFenceManagerBase public void addDistricetGeoFence(String str, String str2) { try { Bundle bundle = new Bundle(); bundle.putString("keyword", str); bundle.putString("customerId", str2); a(4, bundle, 0); } catch (Throwable th) { f.a(th, "GeoFenceManager", "addDistricetGeoFence"); } } @Override // com.amap.api.fence.GeoFenceManagerBase public void addKeywordGeoFence(String str, String str2, String str3, int i2, String str4) { if (i2 <= 0) { i2 = 10; } if (i2 > 25) { i2 = 25; } try { Bundle bundle = new Bundle(); bundle.putString("keyword", str); bundle.putString("poiType", str2); bundle.putString(DistrictSearchQuery.KEYWORDS_CITY, str3); bundle.putInt(GLImage.KEY_SIZE, i2); bundle.putString("customerId", str4); a(2, bundle, 0); } catch (Throwable th) { f.a(th, "GeoFenceManager", "addKeywordGeoFence"); } } @Override // com.amap.api.fence.GeoFenceManagerBase public void addNearbyGeoFence(String str, String str2, DPoint dPoint, float f2, int i2, String str3) { if (f2 <= 0.0f || f2 > 50000.0f) { f2 = 3000.0f; } if (i2 <= 0) { i2 = 10; } if (i2 > 25) { i2 = 25; } try { Bundle bundle = new Bundle(); bundle.putString("keyword", str); bundle.putString("poiType", str2); bundle.putParcelable("centerPoint", dPoint); bundle.putFloat("aroundRadius", f2); bundle.putInt(GLImage.KEY_SIZE, i2); bundle.putString("customerId", str3); a(3, bundle, 0); } catch (Throwable th) { f.a(th, "GeoFenceManager", "addNearbyGeoFence"); } } @Override // com.amap.api.fence.GeoFenceManagerBase public void addPolygonGeoFence(List<DPoint> list, String str) { try { Bundle bundle = new Bundle(); bundle.putParcelableArrayList("points", new ArrayList<>(list)); bundle.putString("customerId", str); a(1, bundle, 0); } catch (Throwable th) { f.a(th, "GeoFenceManager", "addPolygonGeoFence"); } } @Override // com.amap.api.fence.GeoFenceManagerBase public void addRoundGeoFence(DPoint dPoint, float f2, String str) { if (f2 <= 0.0f) { f2 = 1000.0f; } try { Bundle bundle = new Bundle(); bundle.putParcelable("point", dPoint); bundle.putFloat("radius", f2); bundle.putString("customerId", str); a(0, bundle, 0); } catch (Throwable th) { f.a(th, "GeoFenceManager", "addRoundGeoFence"); } } /* access modifiers changed from: package-private */ public void b(Bundle bundle) { if (bundle != null) { try { if (!bundle.isEmpty()) { DPoint dPoint = (DPoint) bundle.getParcelable("point"); String string = bundle.getString("customerId"); Bundle bundle2 = new Bundle(); int i2 = 1; if (dPoint != null) { if (!TextUtils.isEmpty(string)) { if (dPoint.getLatitude() <= 90.0d && dPoint.getLatitude() >= -90.0d && dPoint.getLongitude() <= 180.0d) { if (dPoint.getLongitude() >= -180.0d) { i2 = a(a(bundle, false, this.b)); } } il.a("添加围栏失败", 1, "经纬度错误,传入的纬度:" + dPoint.getLatitude() + "传入的经度:" + dPoint.getLongitude(), new String[0]); } } bundle2.putInt("errorCode", i2); a(1000, bundle2); } } catch (Throwable th) { f.a(th, "GeoFenceManager", "doAddGeoFence_round"); } } } /* access modifiers changed from: package-private */ public void c(Bundle bundle) { if (bundle != null) { try { if (!bundle.isEmpty()) { ArrayList parcelableArrayList = bundle.getParcelableArrayList("points"); String string = bundle.getString("customerId"); int i2 = 1; if (parcelableArrayList != null && parcelableArrayList.size() > 2) { if (!TextUtils.isEmpty(string)) { i2 = a(a(bundle, true, this.b)); } } Bundle bundle2 = new Bundle(); bundle2.putInt("errorCode", i2); a(1000, bundle2); } } catch (Throwable th) { f.a(th, "GeoFenceManager", "doAddGeoFence_polygon"); } } } @Override // com.amap.api.fence.GeoFenceManagerBase public PendingIntent createPendingIntent(String str) { try { this.f952d = str; this.b = PendingIntent.getBroadcast(this.a, 0, new Intent(str), 0); this.c = str; } catch (Throwable th) { f.a(th, "GeoFenceManager", "createPendingIntent"); } return this.b; } /* access modifiers changed from: package-private */ public void d(Bundle bundle) { int i2; if (bundle != null) { try { if (!bundle.isEmpty()) { String string = bundle.getString("keyword"); String string2 = bundle.getString("poiType"); DPoint dPoint = (DPoint) bundle.getParcelable("centerPoint"); float f2 = bundle.getFloat("aroundRadius", 3000.0f); int i3 = bundle.getInt(GLImage.KEY_SIZE, 10); String string3 = bundle.getString("customerId"); int i4 = 1; if (!TextUtils.isEmpty(string3) && dPoint != null) { if (!TextUtils.isEmpty(string)) { if (dPoint.getLatitude() <= 90.0d && dPoint.getLatitude() >= -90.0d && dPoint.getLongitude() <= 180.0d) { if (dPoint.getLongitude() >= -180.0d) { String a2 = this.m.a(this.a, "http://restapi.amap.com/v3/place/around?", string, string2, String.valueOf(i3), String.valueOf(il.c(dPoint.getLatitude())), String.valueOf(il.c(dPoint.getLongitude())), String.valueOf(Float.valueOf(f2).intValue())); if (a2 != null) { ArrayList arrayList = new ArrayList(); Bundle bundle2 = new Bundle(); bundle2.putString("customerId", string3); bundle2.putString("pendingIntentAction", this.c); bundle2.putLong("expiration", -1); bundle2.putInt("activatesAction", this.f); bundle2.putFloat("geoRadius", 200.0f); int b2 = this.n.b(a2, arrayList, bundle2); if (b2 != 10000) { i2 = il.c(b2); } else if (arrayList.isEmpty()) { i4 = 16; } else { i2 = a(arrayList); } i4 = i2; } else { i4 = 4; } } } il.a("添加围栏失败", 1, "经纬度错误,传入的纬度:" + dPoint.getLatitude() + "传入的经度:" + dPoint.getLongitude(), new String[0]); } } Bundle bundle3 = new Bundle(); bundle3.putInt("errorCode", i4); a(1000, bundle3); } } catch (Throwable th) { f.a(th, "GeoFenceManager", "doAddGeoFence_nearby"); } } } /* access modifiers changed from: package-private */ public void e(Bundle bundle) { int i2; if (bundle != null) { try { if (!bundle.isEmpty()) { String string = bundle.getString("keyword"); String string2 = bundle.getString("poiType"); String string3 = bundle.getString(DistrictSearchQuery.KEYWORDS_CITY); int i3 = bundle.getInt(GLImage.KEY_SIZE, 10); String string4 = bundle.getString("customerId"); Bundle bundle2 = new Bundle(); bundle2.putString("customerId", string4); bundle2.putString("pendingIntentAction", this.c); bundle2.putLong("expiration", -1); bundle2.putInt("activatesAction", this.f); bundle2.putFloat("geoRadius", 1000.0f); String a2 = this.m.a(this.a, "http://restapi.amap.com/v3/place/text?", string, string2, string3, String.valueOf(i3)); if (!TextUtils.isEmpty(string4) && !TextUtils.isEmpty(string)) { if (!TextUtils.isEmpty(string2)) { if (a2 != null) { ArrayList arrayList = new ArrayList(); int a3 = this.n.a(a2, arrayList, bundle2); i2 = a3 == 10000 ? arrayList.isEmpty() ? 16 : a(arrayList) : il.c(a3); } else { i2 = 4; } Bundle bundle3 = new Bundle(); bundle3.putInt("errorCode", i2); a(1000, bundle3); } } i2 = 1; Bundle bundle32 = new Bundle(); bundle32.putInt("errorCode", i2); a(1000, bundle32); } } catch (Throwable th) { f.a(th, "GeoFenceManager", "doAddGeoFence_Keyword"); } } } /* access modifiers changed from: package-private */ public void f(Bundle bundle) { int i2; if (bundle != null) { try { if (!bundle.isEmpty()) { String string = bundle.getString("keyword"); String string2 = bundle.getString("customerId"); String a2 = this.m.a(this.a, "http://restapi.amap.com/v3/config/district?", string); if (!TextUtils.isEmpty(string2)) { if (!TextUtils.isEmpty(string)) { if (a2 != null) { Bundle bundle2 = new Bundle(); bundle2.putString("customerId", string2); bundle2.putString("pendingIntentAction", this.c); bundle2.putLong("expiration", -1); bundle2.putInt("activatesAction", this.f); ArrayList arrayList = new ArrayList(); int c2 = this.n.c(a2, arrayList, bundle2); i2 = c2 == 10000 ? arrayList.isEmpty() ? 16 : a(arrayList) : il.c(c2); } else { i2 = 4; } Bundle bundle3 = new Bundle(); bundle3.putInt("errorCode", i2); a(1000, bundle3); } } i2 = 1; Bundle bundle32 = new Bundle(); bundle32.putInt("errorCode", i2); a(1000, bundle32); } } catch (Throwable th) { f.a(th, "GeoFenceManager", "doAddGeoFence_district"); } } } /* access modifiers changed from: package-private */ public void g(Bundle bundle) { try { if (this.e != null && bundle != null && !bundle.isEmpty()) { int i2 = bundle.getInt("errorCode"); this.e.onGeoFenceCreateFinished((ArrayList) this.g.clone(), i2); if (i2 == 0 && this.j != null) { if (f()) { new Bundle().putParcelable("loc", this.p); a(6, (Bundle) null, 0); a(5, bundle, 0); return; } a(7); a(7, (Bundle) null, 1000); } } } catch (Throwable th) { f.a(th, "GeoFenceManager", "resultAddGeoFenceFinished"); } } /* access modifiers changed from: package-private */ public void h(Bundle bundle) { try { if (this.o != null && bundle != null && !bundle.isEmpty()) { long j2 = bundle.getLong("interval"); this.r.setOnceLocation(false); this.r.setInterval(j2); this.o.setLocationOption(this.r); if (!this.l) { this.o.startLocation(); this.l = true; } } } catch (Throwable th) { f.a(th, "GeoFenceManager", "doStartContinueLocation"); } } @Override // com.amap.api.fence.GeoFenceManagerBase public void removeGeoFence() { b(); } @Override // com.amap.api.fence.GeoFenceManagerBase public void setActivateAction(int i2) { if (i2 > 7 || i2 < 1) { i2 = 1; } Bundle bundle = new Bundle(); bundle.putInt("activatesAction", i2); a(9, bundle, 0); } @Override // com.amap.api.fence.GeoFenceManagerBase public void setGeoFenceListener(GeoFenceListener geoFenceListener) { this.e = geoFenceListener; } /* access modifiers changed from: package-private */ /* compiled from: GeoFenceManager */ public class c extends Handler { public c(Looper looper) { super(looper); } public void handleMessage(Message message) { Bundle data = message.getData(); int i = message.what; if (i == 1000) { a.this.g(data); } else if (i == 1001) { try { a.this.b((GeoFence) data.getParcelable("geoFence")); } catch (Throwable th) { th.printStackTrace(); } } } public c() { } } /* access modifiers changed from: package-private */ public void c() { try { synchronized (this.i) { HandlerC0000a aVar = this.j; if (aVar != null) { aVar.removeCallbacksAndMessages(null); } this.j = null; } } catch (Throwable unused) { } } /* access modifiers changed from: package-private */ public void g() { try { if (il.a(this.p)) { float a2 = il.a(this.p, this.g); if (a2 < 1000.0f) { a(7); Bundle bundle = new Bundle(); bundle.putLong("interval", 2000); a(8, bundle, 0); } else if (a2 < 5000.0f) { a(7); a(7, (Bundle) null, 10000); } else { a(7); a(7, (Bundle) null, (long) (((a2 - 4000.0f) / 100.0f) * 1000.0f)); } } } catch (Throwable th) { f.a(th, "GeoFenceManager", "doCheckLocationPolicy"); } } /* access modifiers changed from: package-private */ public void a(Bundle bundle) { int i2 = bundle.getInt("activatesAction", 1); if (this.f != i2) { ArrayList<GeoFence> arrayList = this.g; if (arrayList != null && !arrayList.isEmpty()) { Iterator<GeoFence> it = this.g.iterator(); while (it.hasNext()) { it.next().setStatus(0); } } if (this.j != null) { if (f()) { a(6, (Bundle) null, 0); } else { a(7); a(7, (Bundle) null, 1000); } } } this.f = i2; } /* access modifiers changed from: package-private */ public void c(GeoFence geoFence) { Bundle bundle = new Bundle(); bundle.putParcelable("geoFence", geoFence); a(1001, bundle); } public void b() { try { AMapLocationClient aMapLocationClient = this.o; if (aMapLocationClient != null) { aMapLocationClient.stopLocation(); this.o.onDestroy(); this.o = null; } c(); b bVar = this.k; if (bVar != null) { if (Build.VERSION.SDK_INT >= 18) { bVar.quitSafely(); } else { bVar.quit(); } } this.k = null; ArrayList<GeoFence> arrayList = this.g; if (arrayList != null) { arrayList.clear(); this.g = null; } this.m = null; PendingIntent pendingIntent = this.b; if (pendingIntent != null) { pendingIntent.cancel(); } this.b = null; this.i = null; } catch (Throwable th) { f.a(th, "GeoFenceManager", "destroy"); } } /* access modifiers changed from: package-private */ public boolean f() { return this.p != null && il.a(this.p) && il.b() - this.q < 10000; } /* access modifiers changed from: package-private */ public GeoFence a(Bundle bundle, boolean z, PendingIntent pendingIntent) { GeoFence geoFence = new GeoFence(); ArrayList arrayList = new ArrayList(); DPoint dPoint = new DPoint(); if (z) { geoFence.setType(1); arrayList = bundle.getParcelableArrayList("points"); if (arrayList != null) { dPoint = il.a(arrayList); } geoFence.setMaxDis2Center(il.b(dPoint, arrayList)); geoFence.setMinDis2Center(il.a(dPoint, arrayList)); } else { geoFence.setType(0); dPoint = (DPoint) bundle.getParcelable("point"); if (dPoint != null) { arrayList.add(dPoint); } float f2 = bundle.getFloat("radius", 1000.0f); geoFence.setRadius(f2); geoFence.setMinDis2Center(f2); geoFence.setMaxDis2Center(f2); } geoFence.setFenceId(String.valueOf(il.b())); geoFence.setActivatesAction(this.f); geoFence.setCustomId(bundle.getString("customerId")); ArrayList arrayList2 = new ArrayList(); arrayList2.add(arrayList); geoFence.setPointList(arrayList2); geoFence.setCenter(dPoint); geoFence.setPendingIntentAction(this.c); geoFence.setExpiration(bundle.getLong("expiration", -1)); if (pendingIntent != null) { geoFence.setPendingIntent(pendingIntent); } return geoFence; } /* access modifiers changed from: package-private */ public void e() { try { if (this.l) { a(8); AMapLocationClient aMapLocationClient = this.o; if (aMapLocationClient != null) { aMapLocationClient.stopLocation(); } this.l = false; } } catch (Throwable unused) { } } /* access modifiers changed from: package-private */ public void b(GeoFence geoFence) { try { if (this.a == null) { return; } if (this.b != null || geoFence.getPendingIntent() != null) { Intent intent = new Intent(); Bundle bundle = new Bundle(); bundle.putString(GeoFence.BUNDLE_KEY_FENCEID, geoFence.getFenceId()); bundle.putString(GeoFence.BUNDLE_KEY_CUSTOMID, geoFence.getCustomId()); bundle.putInt("event", geoFence.getStatus()); bundle.putParcelable(GeoFence.BUNDLE_KEY_FENCE, geoFence); intent.putExtras(bundle); if (geoFence.getPendingIntent() != null) { geoFence.getPendingIntent().send(this.a, 0, intent); } else { this.b.send(this.a, 0, intent); } } } catch (Throwable th) { f.a(th, "GeoFenceManager", "resultTriggerGeoFence"); } } /* access modifiers changed from: package-private */ public void d() { try { if (this.o != null) { e(); this.r.setOnceLocation(true); this.o.setLocationOption(this.r); this.o.startLocation(); } } catch (Throwable th) { f.a(th, "GeoFenceManager", "doStartOnceLocation"); } } /* access modifiers changed from: package-private */ public int a(GeoFence geoFence) { try { if (this.g == null) { this.g = new ArrayList<>(); } if (this.g.contains(geoFence)) { return 0; } this.g.add(geoFence); return 0; } catch (Throwable th) { f.a(th, "GeoFenceManager", "addGeoFence2List"); il.a("添加围栏失败", 8, th.getMessage(), new String[0]); return 8; } } /* access modifiers changed from: package-private */ public int a(List<GeoFence> list) { try { if (this.g == null) { this.g = new ArrayList<>(); } for (GeoFence geoFence : list) { a(geoFence); } return 0; } catch (Throwable th) { f.a(th, "GeoFenceManager", "addGeoFenceList"); il.a("添加围栏失败", 8, th.getMessage(), new String[0]); return 8; } } /* access modifiers changed from: package-private */ public void a(int i2, Bundle bundle, long j2) { try { synchronized (this.i) { HandlerC0000a aVar = this.j; if (aVar != null) { Message obtainMessage = aVar.obtainMessage(); obtainMessage.what = i2; obtainMessage.setData(bundle); this.j.sendMessageDelayed(obtainMessage, j2); } } } catch (Throwable unused) { } } /* access modifiers changed from: package-private */ public void a(int i2) { try { synchronized (this.i) { HandlerC0000a aVar = this.j; if (aVar != null) { aVar.removeMessages(i2); } } } catch (Throwable unused) { } } /* access modifiers changed from: package-private */ public void a(int i2, Bundle bundle) { try { c cVar = this.h; if (cVar != null) { Message obtainMessage = cVar.obtainMessage(); obtainMessage.what = i2; obtainMessage.setData(bundle); this.h.sendMessage(obtainMessage); } } catch (Throwable unused) { } } /* access modifiers changed from: package-private */ public void a(AMapLocation aMapLocation) { try { ArrayList<GeoFence> arrayList = this.g; if (arrayList == null) { return; } if (!arrayList.isEmpty()) { if (aMapLocation == null || aMapLocation.getErrorCode() != 0) { Iterator<GeoFence> it = this.g.iterator(); while (it.hasNext()) { GeoFence next = it.next(); try { next.setStatus(4); c(next); } catch (Throwable unused) { } } return; } Iterator<GeoFence> it2 = this.g.iterator(); while (it2.hasNext()) { GeoFence next2 = it2.next(); if (il.b(aMapLocation, next2) && il.a(next2, this.f)) { c(next2); } } } } catch (Throwable th) { f.a(th, "GeoFenceManager", "doCheckFence"); } } }