RbChat v4.56630229版本的 MD5 值为:d137f4b55d6b64b50641a810905f5957
以下内容为反编译后的 a.java 源代码,内容仅作参考
package com.loc;
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.os.Parcelable;
import android.text.TextUtils;
import android.util.Log;
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.maps.model.MyLocationStyle;
import com.amap.api.services.district.DistrictSearchQuery;
import io.agora.rtm2.RtmConstants;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.json.JSONObject;
public class a implements GeoFenceManagerBase {
private static boolean A;
Context b;
dk a = null;
PendingIntent c = null;
String d = null;
GeoFenceListener e = null;
private Object z = new Object();
volatile int f = 1;
ArrayList<GeoFence> g = new ArrayList<>();
c h = null;
Object i = new Object();
Object j = new Object();
HandlerC0022a k = null;
b l = null;
volatile boolean m = false;
volatile boolean n = false;
volatile boolean o = false;
com.loc.b p = null;
com.loc.c q = null;
AMapLocationClient r = null;
volatile AMapLocation s = null;
long t = 0;
AMapLocationClientOption u = null;
int v = 0;
AMapLocationListener w = new AMapLocationListener() {
@Override
public final void onLocationChanged(AMapLocation aMapLocation) {
boolean z;
int i;
try {
if (!a.this.y && a.this.o) {
a.this.s = aMapLocation;
if (aMapLocation != null) {
i = aMapLocation.getErrorCode();
if (aMapLocation.getErrorCode() == 0) {
a.this.t = dn.b();
a.this.a(5, null, 0L);
z = true;
} else {
a.a("定位失败", aMapLocation.getErrorCode(), aMapLocation.getErrorInfo(), "locationDetail:" + aMapLocation.getLocationDetail());
z = false;
}
} else {
z = false;
i = 8;
}
if (z) {
a.this.v = 0;
a.this.a(6, null, 0L);
return;
}
Bundle bundle = new Bundle();
if (!a.this.m) {
a.this.a(7);
bundle.putLong("interval", 2000L);
a.this.a(8, bundle, 2000L);
}
a.this.v++;
if (a.this.v >= 3) {
bundle.putInt(GeoFence.BUNDLE_KEY_LOCERRORCODE, i);
a.this.a(1002, bundle);
}
}
} catch (Throwable unused) {
}
}
};
final int x = 3;
volatile boolean y = false;
public class HandlerC0022a extends Handler {
public HandlerC0022a(Looper looper) {
super(looper);
}
@Override
public final void handleMessage(Message message) {
String str;
GeoFence a;
try {
String str2 = "";
int i = 1;
switch (message.what) {
case 0:
a aVar = a.this;
Bundle data = message.getData();
ArrayList<? extends Parcelable> arrayList = new ArrayList<>();
if (data != null && !data.isEmpty()) {
DPoint dPoint = (DPoint) data.getParcelable("centerPoint");
str = data.getString(GeoFence.BUNDLE_KEY_CUSTOMID);
if (dPoint != null) {
if (dPoint.getLatitude() <= 90.0d && dPoint.getLatitude() >= -90.0d && dPoint.getLongitude() <= 180.0d && dPoint.getLongitude() >= -180.0d) {
GeoFence a2 = aVar.a(data, false);
i = aVar.a(a2);
if (i == 0) {
arrayList.add(a2);
}
Bundle bundle = new Bundle();
bundle.putInt(MyLocationStyle.ERROR_CODE, i);
bundle.putParcelableArrayList("resultList", arrayList);
bundle.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
aVar.a(1000, bundle);
return;
}
a.a("添加围栏失败", 1, "经纬度错误,传入的纬度:" + dPoint.getLatitude() + "传入的经度:" + dPoint.getLongitude(), new String[0]);
Bundle bundle2 = new Bundle();
bundle2.putInt(MyLocationStyle.ERROR_CODE, i);
bundle2.putParcelableArrayList("resultList", arrayList);
bundle2.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
aVar.a(1000, bundle2);
return;
}
str2 = str;
}
str = str2;
Bundle bundle22 = new Bundle();
bundle22.putInt(MyLocationStyle.ERROR_CODE, i);
bundle22.putParcelableArrayList("resultList", arrayList);
bundle22.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
aVar.a(1000, bundle22);
return;
case 1:
a aVar2 = a.this;
Bundle data2 = message.getData();
ArrayList<? extends Parcelable> arrayList2 = new ArrayList<>();
if (data2 != null && !data2.isEmpty()) {
ArrayList parcelableArrayList = data2.getParcelableArrayList("pointList");
String string = data2.getString(GeoFence.BUNDLE_KEY_CUSTOMID);
if (parcelableArrayList != null && parcelableArrayList.size() > 2 && (i = aVar2.a((a = aVar2.a(data2, true)))) == 0) {
arrayList2.add(a);
}
str2 = string;
}
Bundle bundle3 = new Bundle();
bundle3.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str2);
bundle3.putInt(MyLocationStyle.ERROR_CODE, i);
bundle3.putParcelableArrayList("resultList", arrayList2);
aVar2.a(1000, bundle3);
return;
case 2:
a.this.c(message.getData());
return;
case 3:
a.this.b(message.getData());
return;
case 4:
a.this.d(message.getData());
return;
case 5:
a.this.d();
return;
case 6:
a aVar3 = a.this;
aVar3.a(aVar3.s);
return;
case 7:
a aVar4 = a.this;
if (aVar4.r != null) {
aVar4.c();
aVar4.u.setOnceLocation(true);
aVar4.r.setLocationOption(aVar4.u);
aVar4.r.startLocation();
return;
}
return;
case 8:
a aVar5 = a.this;
Bundle data3 = message.getData();
if (aVar5.r != null) {
long j = 2000;
if (data3 != null && !data3.isEmpty()) {
j = data3.getLong("interval", 2000L);
}
aVar5.u.setOnceLocation(false);
aVar5.u.setInterval(j);
aVar5.r.setLocationOption(aVar5.u);
if (aVar5.m) {
return;
}
aVar5.r.stopLocation();
aVar5.r.startLocation();
aVar5.m = true;
return;
}
return;
case 9:
a.this.a(message.getData());
return;
case 10:
a.this.a();
return;
case 11:
a.this.f(message.getData());
return;
case 12:
a.this.e(message.getData());
return;
case 13:
a.this.e();
return;
default:
return;
}
} catch (Throwable unused) {
}
}
}
public static class b extends HandlerThread {
public b(String str) {
super(str);
}
@Override
public final void run() {
try {
super.run();
} catch (Throwable unused) {
}
}
}
public class c extends Handler {
public c() {
}
public c(Looper looper) {
super(looper);
}
@Override
public final void handleMessage(Message message) {
try {
Bundle data = message.getData();
switch (message.what) {
case 1000:
a aVar = a.this;
if (data == null || data.isEmpty()) {
return;
}
int i = data.getInt(MyLocationStyle.ERROR_CODE);
ArrayList parcelableArrayList = data.getParcelableArrayList("resultList");
if (parcelableArrayList == null) {
parcelableArrayList = new ArrayList();
}
String string = data.getString(GeoFence.BUNDLE_KEY_CUSTOMID);
if (string == null) {
string = "";
}
if (aVar.e != null) {
aVar.e.onGeoFenceCreateFinished((ArrayList) parcelableArrayList.clone(), i, string);
}
if (i == 0) {
aVar.b();
return;
}
return;
case 1001:
a.this.b((GeoFence) data.getParcelable("geoFence"));
return;
case 1002:
a.this.b(data.getInt(GeoFence.BUNDLE_KEY_LOCERRORCODE));
return;
default:
return;
}
} catch (Throwable unused) {
}
}
}
public a(Context context) {
this.b = null;
try {
this.b = context.getApplicationContext();
f();
} catch (Throwable th) {
dg.a(th, "GeoFenceManger", "<init>");
}
}
public static float a(DPoint dPoint, List<DPoint> list) {
float f = Float.MAX_VALUE;
if (dPoint != null && list != null && !list.isEmpty()) {
for (DPoint dPoint2 : list) {
f = Math.min(f, dn.a(dPoint, dPoint2));
}
}
return f;
}
private 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) {
dg.a(th, "GeoFenceManager", "addGeoFenceList");
a("添加围栏失败", 8, th.getMessage(), new String[0]);
return 8;
}
}
private static Bundle a(GeoFence geoFence, String str, String str2, int i, int i2) {
Bundle bundle = new Bundle();
if (str == null) {
str = "";
}
bundle.putString(GeoFence.BUNDLE_KEY_FENCEID, str);
bundle.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str2);
bundle.putInt("event", i);
bundle.putInt(GeoFence.BUNDLE_KEY_LOCERRORCODE, i2);
bundle.putParcelable(GeoFence.BUNDLE_KEY_FENCE, geoFence);
return bundle;
}
static void a(String str, int i, String str2, String... strArr) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("===========================================\n");
stringBuffer.append(" " + str + " ");
stringBuffer.append("\n");
stringBuffer.append("-------------------------------------------\n");
stringBuffer.append("errorCode:" + i);
stringBuffer.append("\n");
stringBuffer.append("错误信息:" + str2);
stringBuffer.append("\n");
if (strArr.length > 0) {
for (String str3 : strArr) {
stringBuffer.append(str3);
stringBuffer.append("\n");
}
}
stringBuffer.append("===========================================\n");
Log.i("fenceErrLog", stringBuffer.toString());
}
private static boolean a(GeoFence geoFence, int i) {
boolean z = true;
boolean z2 = false;
if ((i & 1) == 1) {
try {
if (geoFence.getStatus() == 1) {
z2 = true;
}
} catch (Throwable th) {
dg.a(th, "Utils", "remindStatus");
return z2;
}
}
if ((i & 2) == 2 && geoFence.getStatus() == 2) {
z2 = true;
}
if ((i & 4) == 4) {
}
z = z2;
return z;
}
private static boolean a(AMapLocation aMapLocation, GeoFence geoFence) {
boolean z = false;
try {
if (dn.a(aMapLocation) && geoFence != null && geoFence.getPointList() != null && !geoFence.getPointList().isEmpty()) {
int type = geoFence.getType();
if (type != 0) {
if (type != 1) {
if (type != 2) {
if (type != 3) {
}
}
}
boolean z2 = false;
for (List<DPoint> list : geoFence.getPointList()) {
try {
if (list.size() < 3 ? false : dg.a(new DPoint(aMapLocation.getLatitude(), aMapLocation.getLongitude()), list)) {
z2 = true;
}
} catch (Throwable th) {
th = th;
z = z2;
dg.a(th, "Utils", "isInGeoFence");
return z;
}
}
z = z2;
}
DPoint center = geoFence.getCenter();
if (dn.a(new double[]{center.getLatitude(), center.getLongitude(), aMapLocation.getLatitude(), aMapLocation.getLongitude()}) <= geoFence.getRadius()) {
return true;
}
}
} catch (Throwable th2) {
th = th2;
}
return z;
}
public static float b(DPoint dPoint, List<DPoint> list) {
float f = Float.MIN_VALUE;
if (dPoint != null && list != null && !list.isEmpty()) {
for (DPoint dPoint2 : list) {
f = Math.max(f, dn.a(dPoint, dPoint2));
}
}
return f;
}
private static DPoint b(List<DPoint> list) {
DPoint dPoint = new DPoint();
if (list != null) {
try {
double d = 0.0d;
double d2 = 0.0d;
for (DPoint dPoint2 : list) {
d += dPoint2.getLatitude();
d2 += dPoint2.getLongitude();
}
return new DPoint(dn.b(d / list.size()), dn.b(d2 / list.size()));
} catch (Throwable th) {
dg.a(th, "GeoFenceUtil", "getPolygonCenter");
return dPoint;
}
}
return dPoint;
}
private void b(int i, Bundle bundle) {
String str;
int i2;
String str2;
boolean z;
boolean z2;
String str3;
String str4;
int i3;
String str5;
String a;
int i4;
Bundle bundle2 = new Bundle();
try {
ArrayList<? extends Parcelable> arrayList = new ArrayList<>();
if (bundle != null) {
try {
if (!bundle.isEmpty()) {
List<GeoFence> arrayList2 = new ArrayList<>();
String string = bundle.getString(GeoFence.BUNDLE_KEY_CUSTOMID);
String string2 = bundle.getString("keyWords");
String string3 = bundle.getString(DistrictSearchQuery.KEYWORDS_CITY);
String string4 = bundle.getString("poiType");
DPoint dPoint = (DPoint) bundle.getParcelable("centerPoint");
int i5 = bundle.getInt("searchSize", 10);
float f = bundle.getFloat("aroundRadius", 3000.0f);
if (TextUtils.isEmpty(string2)) {
str2 = "添加围栏失败";
z2 = false;
} else {
if (i != 1) {
if (i == 2) {
if (dPoint == null) {
str2 = "添加围栏失败";
} else {
try {
if (dPoint.getLatitude() > 90.0d || dPoint.getLatitude() < -90.0d || dPoint.getLongitude() > 180.0d || dPoint.getLongitude() < -180.0d) {
str2 = "添加围栏失败";
a(str2, 0, "经纬度错误,传入的纬度:" + dPoint.getLatitude() + "传入的经度:" + dPoint.getLongitude(), new String[0]);
}
} catch (Throwable th) {
th = th;
str = MyLocationStyle.ERROR_CODE;
i2 = 0;
try {
dg.a(th, "GeoFenceManager", "doAddGeoFenceNearby");
bundle2.putInt(str, 8);
a(1000, bundle2);
return;
} catch (Throwable th2) {
bundle2.putInt(str, i2);
a(1000, bundle2);
throw th2;
}
}
}
}
str2 = "添加围栏失败";
z = true;
} else {
str2 = "添加围栏失败";
z = TextUtils.isEmpty(string4) ? false : false;
z = true;
}
z2 = z;
}
if (z2) {
Bundle bundle3 = new Bundle();
bundle3.putString(GeoFence.BUNDLE_KEY_CUSTOMID, string);
bundle3.putString("pendingIntentAction", this.d);
str3 = GeoFence.BUNDLE_KEY_CUSTOMID;
str4 = MyLocationStyle.ERROR_CODE;
try {
bundle3.putLong("expiration", -1L);
bundle3.putInt("activatesAction", this.f);
} catch (Throwable th3) {
th = th3;
}
try {
if (i == 1) {
bundle3.putFloat("fenceRadius", 1000.0f);
a = com.loc.b.a(this.b, "http://restapi.amap.com/v3/place/text?", string2, string4, string3, String.valueOf(i5));
} else if (i != 2) {
a = i != 3 ? null : com.loc.b.a(this.b, "http://restapi.amap.com/v3/config/district?", string2);
} else {
double b2 = dn.b(dPoint.getLatitude());
double b3 = dn.b(dPoint.getLongitude());
int intValue = Float.valueOf(f).intValue();
bundle3.putFloat("fenceRadius", 200.0f);
a = com.loc.b.a(this.b, "http://restapi.amap.com/v3/place/around?", string2, string4, String.valueOf(i5), String.valueOf(b2), String.valueOf(b3), String.valueOf(intValue));
}
int i6 = 4;
if (a != null) {
int a2 = 1 == i ? com.loc.c.a(a, arrayList2, bundle3) : 0;
if (2 == i) {
a2 = com.loc.c.a(a, arrayList2, bundle3);
}
if (3 == i) {
a2 = this.q.b(a, arrayList2, bundle3);
}
if (a2 != 10000) {
if (a2 != 1 && a2 != 7 && a2 != 4 && a2 != 5 && a2 != 16 && a2 != 17) {
switch (a2) {
case 10000:
i4 = 0;
break;
case 10001:
case 10002:
case RtmConstants.RTM_ERR_EXCEED_CHANNEL_LIMITATION:
case RtmConstants.RTM_ERR_ALREADY_JOIN_CHANNEL:
case RtmConstants.RTM_ERR_NOT_JOIN_CHANNEL:
case 10012:
case 10013:
i4 = 7;
break;
case 10003:
case RtmConstants.RTM_ERR_PUBLISH_TOPIC_MESSAGE_FAILED:
case RtmConstants.RTM_ERR_EXCEED_SUBSCRIBE_TOPIC_LIMITATION:
case RtmConstants.RTM_ERR_EXCEED_USER_LIMITATION:
case 10010:
case 10011:
case 10014:
case 10015:
case 10016:
case 10017:
i4 = 4;
break;
default:
switch (a2) {
case 20000:
case 20001:
case 20002:
i4 = 1;
break;
case 20003:
default:
i4 = 8;
break;
}
}
} else {
i4 = a2;
}
if (i4 != 0) {
a(str2, i4, "searchErrCode is " + i4, new String[0]);
}
i2 = i4;
} else if (arrayList2.isEmpty()) {
i2 = 16;
} else {
i2 = a(arrayList2);
if (i2 == 0) {
try {
arrayList.addAll(arrayList2);
} catch (Throwable th4) {
th = th4;
str = str4;
dg.a(th, "GeoFenceManager", "doAddGeoFenceNearby");
bundle2.putInt(str, 8);
a(1000, bundle2);
return;
}
} else {
i6 = i2;
}
}
}
i2 = i6;
} catch (Throwable th5) {
th = th5;
str = str4;
i2 = 0;
dg.a(th, "GeoFenceManager", "doAddGeoFenceNearby");
bundle2.putInt(str, 8);
a(1000, bundle2);
return;
}
} else {
str3 = GeoFence.BUNDLE_KEY_CUSTOMID;
str4 = MyLocationStyle.ERROR_CODE;
i2 = 1;
}
bundle2.putString(str3, string);
bundle2.putParcelableArrayList("resultList", arrayList);
i3 = i2;
str5 = str4;
bundle2.putInt(str5, i3);
a(1000, bundle2);
}
} catch (Throwable th6) {
th = th6;
}
}
str5 = MyLocationStyle.ERROR_CODE;
i3 = 1;
bundle2.putInt(str5, i3);
a(1000, bundle2);
} catch (Throwable th7) {
th = th7;
str = MyLocationStyle.ERROR_CODE;
}
}
private static boolean b(AMapLocation aMapLocation, GeoFence geoFence) {
boolean z = true;
try {
if (!a(aMapLocation, geoFence)) {
if (geoFence.getStatus() != 2) {
try {
geoFence.setStatus(2);
geoFence.setEnterTime(-1L);
} catch (Throwable th) {
th = th;
dg.a(th, "Utils", "isFenceStatusChanged");
return z;
}
}
z = false;
} else if (geoFence.getEnterTime() == -1) {
if (geoFence.getStatus() != 1) {
geoFence.setEnterTime(dn.b());
geoFence.setStatus(1);
}
z = false;
} else {
if (geoFence.getStatus() != 3 && dn.b() - geoFence.getEnterTime() > 600000) {
geoFence.setStatus(3);
}
z = false;
}
} catch (Throwable th2) {
th = th2;
z = false;
}
return z;
}
private void f() {
if (!this.o) {
this.o = true;
}
if (this.n) {
return;
}
try {
this.h = Looper.myLooper() == null ? new c(this.b.getMainLooper()) : new c();
} catch (Throwable th) {
dg.a(th, "GeoFenceManger", "init 1");
}
try {
b bVar = new b("fenceActionThread");
this.l = bVar;
bVar.setPriority(5);
this.l.start();
this.k = new HandlerC0022a(this.l.getLooper());
} catch (Throwable th2) {
dg.a(th2, "GeoFenceManger", "init 2");
}
try {
this.p = new com.loc.b(this.b);
this.q = new com.loc.c();
this.u = new AMapLocationClientOption();
this.r = new AMapLocationClient(this.b);
this.u.setLocationCacheEnable(true);
this.u.setNeedAddress(false);
this.r.setLocationListener(this.w);
if (this.a == null) {
this.a = new dk();
}
} catch (Throwable th3) {
dg.a(th3, "GeoFenceManger", "initBase");
}
this.n = true;
try {
String str = this.d;
if (str != null && this.c == null) {
createPendingIntent(str);
}
} catch (Throwable th4) {
dg.a(th4, "GeoFenceManger", "init 4");
}
if (A) {
return;
}
A = true;
dk.a(this.b, "O020", (JSONObject) null);
}
final int a(GeoFence geoFence) {
try {
if (this.g == null) {
this.g = new ArrayList<>();
}
if (this.g.contains(geoFence)) {
return 17;
}
this.g.add(geoFence);
return 0;
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "addGeoFence2List");
a("添加围栏失败", 8, th.getMessage(), new String[0]);
return 8;
}
}
final GeoFence a(Bundle bundle, boolean z) {
GeoFence geoFence = new GeoFence();
ArrayList arrayList = new ArrayList();
DPoint dPoint = new DPoint();
if (z) {
geoFence.setType(1);
arrayList = bundle.getParcelableArrayList("pointList");
if (arrayList != null) {
dPoint = b(arrayList);
}
geoFence.setMaxDis2Center(b(dPoint, arrayList));
geoFence.setMinDis2Center(a(dPoint, arrayList));
} else {
geoFence.setType(0);
dPoint = (DPoint) bundle.getParcelable("centerPoint");
if (dPoint != null) {
arrayList.add(dPoint);
}
float f = bundle.getFloat("fenceRadius", 1000.0f);
float f2 = f > 0.0f ? f : 1000.0f;
geoFence.setRadius(f2);
geoFence.setMinDis2Center(f2);
geoFence.setMaxDis2Center(f2);
}
geoFence.setActivatesAction(this.f);
geoFence.setCustomId(bundle.getString(GeoFence.BUNDLE_KEY_CUSTOMID));
ArrayList arrayList2 = new ArrayList();
arrayList2.add(arrayList);
geoFence.setPointList(arrayList2);
geoFence.setCenter(dPoint);
geoFence.setPendingIntentAction(this.d);
geoFence.setExpiration(-1L);
geoFence.setPendingIntent(this.c);
StringBuilder sb = new StringBuilder();
sb.append(com.loc.c.a());
geoFence.setFenceId(sb.toString());
dk dkVar = this.a;
if (dkVar != null) {
dkVar.a(this.b, 2);
}
return geoFence;
}
final void a() {
if (this.n) {
ArrayList<GeoFence> arrayList = this.g;
if (arrayList != null) {
arrayList.clear();
this.g = null;
}
if (this.o) {
return;
}
synchronized (this.i) {
HandlerC0022a handlerC0022a = this.k;
if (handlerC0022a != null) {
handlerC0022a.removeCallbacksAndMessages(null);
}
this.k = null;
}
AMapLocationClient aMapLocationClient = this.r;
if (aMapLocationClient != null) {
aMapLocationClient.stopLocation();
this.r.onDestroy();
}
this.r = null;
if (this.l != null) {
if (Build.VERSION.SDK_INT >= 18) {
this.l.quitSafely();
} else {
this.l.quit();
}
}
this.l = null;
this.p = null;
synchronized (this.z) {
PendingIntent pendingIntent = this.c;
if (pendingIntent != null) {
pendingIntent.cancel();
}
this.c = null;
}
synchronized (this.j) {
c cVar = this.h;
if (cVar != null) {
cVar.removeCallbacksAndMessages(null);
}
this.h = null;
}
dk dkVar = this.a;
if (dkVar != null) {
dkVar.b(this.b);
}
this.m = false;
this.n = false;
}
}
final void a(int i) {
try {
synchronized (this.i) {
HandlerC0022a handlerC0022a = this.k;
if (handlerC0022a != null) {
handlerC0022a.removeMessages(i);
}
}
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "removeActionHandlerMessage");
}
}
final void a(int i, Bundle bundle) {
try {
synchronized (this.j) {
c cVar = this.h;
if (cVar != null) {
Message obtainMessage = cVar.obtainMessage();
obtainMessage.what = i;
obtainMessage.setData(bundle);
this.h.sendMessage(obtainMessage);
}
}
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "sendResultHandlerMessage");
}
}
final void a(int i, Bundle bundle, long j) {
try {
synchronized (this.i) {
HandlerC0022a handlerC0022a = this.k;
if (handlerC0022a != null) {
Message obtainMessage = handlerC0022a.obtainMessage();
obtainMessage.what = i;
obtainMessage.setData(bundle);
this.k.sendMessageDelayed(obtainMessage, j);
}
}
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "sendActionHandlerMessage");
}
}
final void a(Bundle bundle) {
int i = 1;
if (bundle != null) {
try {
i = bundle.getInt("activatesAction", 1);
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "doSetActivatesAction");
return;
}
}
if (this.f != i) {
ArrayList<GeoFence> arrayList = this.g;
if (arrayList != null && !arrayList.isEmpty()) {
Iterator<GeoFence> it = this.g.iterator();
while (it.hasNext()) {
GeoFence next = it.next();
next.setStatus(0);
next.setEnterTime(-1L);
}
}
b();
}
this.f = i;
}
final void a(AMapLocation aMapLocation) {
ArrayList<GeoFence> arrayList;
try {
if (this.y || (arrayList = this.g) == null || arrayList.isEmpty() || aMapLocation == null || aMapLocation.getErrorCode() != 0) {
return;
}
Iterator<GeoFence> it = this.g.iterator();
while (it.hasNext()) {
GeoFence next = it.next();
if (next.isAble() && b(aMapLocation, next) && a(next, this.f)) {
next.setCurrentLocation(aMapLocation);
Bundle bundle = new Bundle();
bundle.putParcelable("geoFence", next);
a(1001, bundle);
}
}
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "doCheckFence");
}
}
@Override
public void addDistrictGeoFence(String str, String str2) {
try {
f();
Bundle bundle = new Bundle();
bundle.putString("keyWords", str);
bundle.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str2);
a(4, bundle, 0L);
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "addDistricetGeoFence");
}
}
@Override
public void addKeywordGeoFence(String str, String str2, String str3, int i, String str4) {
try {
f();
if (i <= 0) {
i = 10;
}
if (i > 25) {
i = 25;
}
Bundle bundle = new Bundle();
bundle.putString("keyWords", str);
bundle.putString("poiType", str2);
bundle.putString(DistrictSearchQuery.KEYWORDS_CITY, str3);
bundle.putInt("searchSize", i);
bundle.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str4);
a(2, bundle, 0L);
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "addKeywordGeoFence");
}
}
@Override
public void addNearbyGeoFence(String str, String str2, DPoint dPoint, float f, int i, String str3) {
try {
f();
f = (f <= 0.0f || f > 50000.0f) ? 3000.0f : 3000.0f;
if (i <= 0) {
i = 10;
}
if (i > 25) {
i = 25;
}
Bundle bundle = new Bundle();
bundle.putString("keyWords", str);
bundle.putString("poiType", str2);
bundle.putParcelable("centerPoint", dPoint);
bundle.putFloat("aroundRadius", f);
bundle.putInt("searchSize", i);
bundle.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str3);
a(3, bundle, 0L);
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "addNearbyGeoFence");
}
}
@Override
public void addPolygonGeoFence(List<DPoint> list, String str) {
try {
f();
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("pointList", new ArrayList<>(list));
bundle.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
a(1, bundle, 0L);
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "addPolygonGeoFence");
}
}
@Override
public void addRoundGeoFence(DPoint dPoint, float f, String str) {
try {
f();
Bundle bundle = new Bundle();
bundle.putParcelable("centerPoint", dPoint);
bundle.putFloat("fenceRadius", f);
bundle.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
a(0, bundle, 0L);
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "addRoundGeoFence");
}
}
final void b() {
if (this.y || this.k == null) {
return;
}
boolean z = false;
if (this.s != null && dn.a(this.s) && dn.b() - this.t < 10000) {
z = true;
}
if (z) {
a(6, null, 0L);
a(5, null, 0L);
return;
}
a(7);
a(7, null, 0L);
}
final void b(int i) {
try {
if (this.b != null) {
synchronized (this.z) {
if (this.c == null) {
return;
}
Intent intent = new Intent();
intent.putExtras(a(null, null, null, 4, i));
this.c.send(this.b, 0, intent);
}
}
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "resultRemindLocationError");
}
}
final void b(Bundle bundle) {
b(2, bundle);
}
final void b(GeoFence geoFence) {
PendingIntent pendingIntent;
Context context;
try {
synchronized (this.z) {
if (this.b != null) {
if (this.c == null && geoFence.getPendingIntent() == null) {
return;
}
Intent intent = new Intent();
intent.putExtras(a(geoFence, geoFence.getFenceId(), geoFence.getCustomId(), geoFence.getStatus(), 0));
String str = this.d;
if (str != null) {
intent.setAction(str);
}
intent.setPackage(l.c(this.b));
if (geoFence.getPendingIntent() != null) {
pendingIntent = geoFence.getPendingIntent();
context = this.b;
} else {
pendingIntent = this.c;
context = this.b;
}
pendingIntent.send(context, 0, intent);
}
}
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "resultTriggerGeoFence");
}
}
final void c() {
try {
if (this.m) {
a(8);
}
AMapLocationClient aMapLocationClient = this.r;
if (aMapLocationClient != null) {
aMapLocationClient.stopLocation();
}
this.m = false;
} catch (Throwable unused) {
}
}
final void c(Bundle bundle) {
b(1, bundle);
}
@Override
public PendingIntent createPendingIntent(String str) {
synchronized (this.z) {
try {
Intent intent = new Intent(str);
intent.setPackage(l.c(this.b));
this.c = PendingIntent.getBroadcast(this.b, 0, intent, 0);
this.d = str;
ArrayList<GeoFence> arrayList = this.g;
if (arrayList != null && !arrayList.isEmpty()) {
Iterator<GeoFence> it = this.g.iterator();
while (it.hasNext()) {
GeoFence next = it.next();
next.setPendingIntent(this.c);
next.setPendingIntentAction(this.d);
}
}
}
}
return this.c;
}
final void d() {
float f;
float f2;
try {
if (!this.y && dn.a(this.s)) {
AMapLocation aMapLocation = this.s;
ArrayList<GeoFence> arrayList = this.g;
if (aMapLocation == null || aMapLocation.getErrorCode() != 0 || arrayList == null || arrayList.isEmpty()) {
f = Float.MAX_VALUE;
} else {
DPoint dPoint = new DPoint(aMapLocation.getLatitude(), aMapLocation.getLongitude());
f = Float.MAX_VALUE;
for (GeoFence geoFence : arrayList) {
if (geoFence.isAble()) {
float a = dn.a(dPoint, geoFence.getCenter());
if (a > geoFence.getMinDis2Center() && a < geoFence.getMaxDis2Center()) {
f2 = 0.0f;
break;
}
if (a > geoFence.getMaxDis2Center()) {
f = Math.min(f, a - geoFence.getMaxDis2Center());
}
if (a < geoFence.getMinDis2Center()) {
f = Math.min(f, geoFence.getMinDis2Center() - a);
}
}
}
}
f2 = f;
if (f2 == Float.MAX_VALUE) {
return;
}
if (f2 < 1000.0f) {
a(7);
Bundle bundle = new Bundle();
bundle.putLong("interval", 2000L);
a(8, bundle, 500L);
} else if (f2 < 5000.0f) {
c();
a(7);
a(7, null, 10000L);
} else {
c();
a(7);
a(7, null, ((f2 - 4000.0f) / 100.0f) * 1000.0f);
}
}
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "doCheckLocationPolicy");
}
}
final void d(Bundle bundle) {
b(3, bundle);
}
final void e() {
try {
a(7);
a(8);
AMapLocationClient aMapLocationClient = this.r;
if (aMapLocationClient != null) {
aMapLocationClient.stopLocation();
}
this.m = false;
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "doPauseGeoFence");
}
}
final void e(Bundle bundle) {
if (bundle != null) {
try {
if (bundle.isEmpty()) {
return;
}
String string = bundle.getString("fid");
if (TextUtils.isEmpty(string)) {
return;
}
boolean z = true;
boolean z2 = bundle.getBoolean("ab", true);
ArrayList<GeoFence> arrayList = this.g;
if (arrayList != null && !arrayList.isEmpty()) {
Iterator<GeoFence> it = this.g.iterator();
while (true) {
if (!it.hasNext()) {
break;
}
GeoFence next = it.next();
if (next.getFenceId().equals(string)) {
next.setAble(z2);
break;
}
}
}
if (z2) {
b();
return;
}
ArrayList<GeoFence> arrayList2 = this.g;
if (arrayList2 != null && !arrayList2.isEmpty()) {
Iterator<GeoFence> it2 = this.g.iterator();
while (true) {
if (!it2.hasNext()) {
break;
} else if (it2.next().isAble()) {
z = false;
break;
}
}
}
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "doSetGeoFenceAble");
}
}
}
final void f(Bundle bundle) {
try {
if (this.g != null) {
GeoFence geoFence = (GeoFence) bundle.getParcelable("fc");
if (this.g.contains(geoFence)) {
this.g.remove(geoFence);
}
if (this.g.size() <= 0) {
a();
} else {
b();
}
}
} catch (Throwable unused) {
}
}
@Override
public List<GeoFence> getAllGeoFence() {
try {
if (this.g == null) {
this.g = new ArrayList<>();
}
return (ArrayList) this.g.clone();
} catch (Throwable unused) {
return new ArrayList();
}
}
@Override
public boolean isPause() {
return this.y;
}
@Override
public void pauseGeoFence() {
try {
f();
this.y = true;
a(13, null, 0L);
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "pauseGeoFence");
}
}
@Override
public void removeGeoFence() {
try {
this.o = false;
a(10, null, 0L);
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "removeGeoFence");
}
}
@Override
public boolean removeGeoFence(GeoFence geoFence) {
try {
ArrayList<GeoFence> arrayList = this.g;
if (arrayList != null && !arrayList.isEmpty()) {
if (this.g.contains(geoFence)) {
if (this.g.size() == 1) {
this.o = false;
}
Bundle bundle = new Bundle();
bundle.putParcelable("fc", geoFence);
a(11, bundle, 0L);
return true;
}
return false;
}
this.o = false;
a(10, null, 0L);
return true;
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "removeGeoFence(GeoFence)");
return false;
}
}
@Override
public void resumeGeoFence() {
try {
f();
if (this.y) {
this.y = false;
b();
}
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "resumeGeoFence");
}
}
@Override
public void setActivateAction(int i) {
try {
f();
i = (i > 7 || i <= 0) ? 1 : 1;
Bundle bundle = new Bundle();
bundle.putInt("activatesAction", i);
a(9, bundle, 0L);
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "setActivateAction");
}
}
@Override
public void setGeoFenceAble(String str, boolean z) {
try {
f();
Bundle bundle = new Bundle();
bundle.putString("fid", str);
bundle.putBoolean("ab", z);
a(12, bundle, 0L);
} catch (Throwable th) {
dg.a(th, "GeoFenceManager", "setGeoFenceAble");
}
}
@Override
public void setGeoFenceListener(GeoFenceListener geoFenceListener) {
try {
this.e = geoFenceListener;
} catch (Throwable unused) {
}
}
}