同程有借 v1.0.0版本的 MD5 值为:e33397cdbab33543d0c134ec96d77fb8

以下内容为反编译后的 a.java 源代码,内容仅作参考


package com.loc;

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.os.Parcelable;
import android.text.TextUtils;
import android.util.Log;
import androidx.camera.camera2.internal.compat.CameraAccessExceptionCompat;
import com.amap.api.fence.GeoFence;
import com.amap.api.fence.GeoFenceListener;
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.bonree.sdk.agent.engine.external.AsynchronousInstrumentation;
import com.bonree.sdk.agent.engine.external.Instrumented;
import com.huawei.hms.common.internal.RequestManager;
import com.sensorsdata.analytics.android.sdk.aop.push.PushAutoTrackHelper;
import com.taobao.accs.common.Constants;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.json.JSONObject;
@SuppressLint({"NewApi"})
public final class a {
    private static boolean A = false;
    Context f9005b;
    fw f9004a = null;
    PendingIntent f9006c = null;
    String f9007d = null;
    GeoFenceListener f9008e = null;
    private Object f9029z = new Object();
    volatile int f9009f = 1;
    ArrayList<GeoFence> f9010g = new ArrayList<>();
    c f9011h = null;
    Object f9012i = new Object();
    Object f9013j = new Object();
    HandlerC0095a f9014k = null;
    b f9015l = null;
    volatile boolean f9016m = false;
    volatile boolean f9017n = false;
    volatile boolean f9018o = false;
    com.loc.b f9019p = null;
    com.loc.c f9020q = null;
    AMapLocationClient f9021r = null;
    volatile AMapLocation f9022s = null;
    long f9023t = 0;
    AMapLocationClientOption f9024u = null;
    int f9025v = 0;
    AMapLocationListener f9026w = new AMapLocationListener() {
        @Override
        public final void onLocationChanged(AMapLocation aMapLocation) {
            boolean z8;
            int i9;
            try {
                if (!a.this.f9028y && a.this.f9018o) {
                    a.this.f9022s = aMapLocation;
                    if (aMapLocation != null) {
                        i9 = aMapLocation.getErrorCode();
                        if (aMapLocation.getErrorCode() == 0) {
                            a.this.f9023t = fy.b();
                            a.this.a(5, (Bundle) null, 0L);
                            z8 = true;
                        } else {
                            int errorCode = aMapLocation.getErrorCode();
                            String errorInfo = aMapLocation.getErrorInfo();
                            a.a("定位失败", errorCode, errorInfo, "locationDetail:" + aMapLocation.getLocationDetail());
                            z8 = false;
                        }
                    } else {
                        z8 = false;
                        i9 = 8;
                    }
                    if (z8) {
                        a aVar = a.this;
                        aVar.f9025v = 0;
                        aVar.a(6, (Bundle) null, 0L);
                        return;
                    }
                    Bundle bundle = new Bundle();
                    if (!a.this.f9016m) {
                        a.this.b(7);
                        bundle.putLong(com.umeng.analytics.pro.bh.aX, 2000L);
                        a.this.a(8, bundle, 2000L);
                    }
                    a aVar2 = a.this;
                    int i10 = aVar2.f9025v + 1;
                    aVar2.f9025v = i10;
                    if (i10 >= 3) {
                        bundle.putInt(GeoFence.BUNDLE_KEY_LOCERRORCODE, i9);
                        a.this.a(1002, bundle);
                    }
                }
            } catch (Throwable unused) {
            }
        }
    };
    final int f9027x = 3;
    volatile boolean f9028y = false;

    @Instrumented
    public class HandlerC0095a extends Handler {
        public HandlerC0095a(Looper looper) {
            super(looper);
        }

        @Override
        public final void handleMessage(Message message) {
            AsynchronousInstrumentation.handlerMessageBegin(this, message);
            try {
                switch (message.what) {
                    case 0:
                        a.this.b(message.getData());
                        AsynchronousInstrumentation.handlerMessageEnd();
                        return;
                    case 1:
                        a.this.c(message.getData());
                        AsynchronousInstrumentation.handlerMessageEnd();
                        return;
                    case 2:
                        a.this.e(message.getData());
                        AsynchronousInstrumentation.handlerMessageEnd();
                        return;
                    case 3:
                        a.this.d(message.getData());
                        AsynchronousInstrumentation.handlerMessageEnd();
                        return;
                    case 4:
                        a.this.f(message.getData());
                        AsynchronousInstrumentation.handlerMessageEnd();
                        return;
                    case 5:
                        a.this.e();
                        AsynchronousInstrumentation.handlerMessageEnd();
                        return;
                    case 6:
                        a aVar = a.this;
                        aVar.a(aVar.f9022s);
                        AsynchronousInstrumentation.handlerMessageEnd();
                        return;
                    case 7:
                        a.this.d();
                        AsynchronousInstrumentation.handlerMessageEnd();
                        return;
                    case 8:
                        a.this.j(message.getData());
                        AsynchronousInstrumentation.handlerMessageEnd();
                        return;
                    case 9:
                        a.this.a(message.getData());
                        AsynchronousInstrumentation.handlerMessageEnd();
                        return;
                    case 10:
                        a.this.c();
                        AsynchronousInstrumentation.handlerMessageEnd();
                        return;
                    case 11:
                        a.this.h(message.getData());
                        AsynchronousInstrumentation.handlerMessageEnd();
                        return;
                    case 12:
                        a.this.g(message.getData());
                        AsynchronousInstrumentation.handlerMessageEnd();
                        return;
                    case 13:
                        a.this.g();
                        break;
                }
                AsynchronousInstrumentation.handlerMessageEnd();
            } catch (Throwable unused) {
                AsynchronousInstrumentation.handlerMessageEnd();
            }
        }
    }

    public static class b extends HandlerThread {
        public b(String str) {
            super(str);
        }

        @Override
        public final void run() {
            try {
                super.run();
            } catch (Throwable unused) {
            }
        }
    }

    @Instrumented
    public class c extends Handler {
        public c() {
        }

        public c(Looper looper) {
            super(looper);
        }

        @Override
        public final void handleMessage(Message message) {
            AsynchronousInstrumentation.handlerMessageBegin(this, message);
            try {
                Bundle data = message.getData();
                switch (message.what) {
                    case 1000:
                        a.this.i(data);
                        AsynchronousInstrumentation.handlerMessageEnd();
                        return;
                    case 1001:
                        a.this.b((GeoFence) data.getParcelable("geoFence"));
                        AsynchronousInstrumentation.handlerMessageEnd();
                        return;
                    case 1002:
                        a.this.c(data.getInt(GeoFence.BUNDLE_KEY_LOCERRORCODE));
                        AsynchronousInstrumentation.handlerMessageEnd();
                        return;
                    default:
                        AsynchronousInstrumentation.handlerMessageEnd();
                        return;
                }
            } catch (Throwable unused) {
                AsynchronousInstrumentation.handlerMessageEnd();
            }
        }
    }

    public a(Context context) {
        this.f9005b = null;
        try {
            this.f9005b = context.getApplicationContext();
            j();
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManger", "<init>");
        }
    }

    private static float a(AMapLocation aMapLocation, List<GeoFence> list) {
        float f9 = Float.MAX_VALUE;
        if (aMapLocation != null && aMapLocation.getErrorCode() == 0 && list != null && !list.isEmpty()) {
            DPoint dPoint = new DPoint(aMapLocation.getLatitude(), aMapLocation.getLongitude());
            for (GeoFence geoFence : list) {
                if (geoFence.isAble()) {
                    float a9 = fy.a(dPoint, geoFence.getCenter());
                    if (a9 > geoFence.getMinDis2Center() && a9 < geoFence.getMaxDis2Center()) {
                        return 0.0f;
                    }
                    if (a9 > geoFence.getMaxDis2Center()) {
                        f9 = Math.min(f9, a9 - geoFence.getMaxDis2Center());
                    }
                    if (a9 < geoFence.getMinDis2Center()) {
                        f9 = Math.min(f9, geoFence.getMinDis2Center() - a9);
                    }
                }
            }
        }
        return f9;
    }

    public static float a(DPoint dPoint, List<DPoint> list) {
        float f9 = Float.MAX_VALUE;
        if (dPoint != null && list != null && !list.isEmpty()) {
            for (DPoint dPoint2 : list) {
                f9 = Math.min(f9, fy.a(dPoint, dPoint2));
            }
        }
        return f9;
    }

    private int a(List<GeoFence> list) {
        try {
            if (this.f9010g == null) {
                this.f9010g = new ArrayList<>();
            }
            for (GeoFence geoFence : list) {
                c(geoFence);
            }
            return 0;
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "addGeoFenceList");
            a("添加围栏失败", 8, th.getMessage(), new String[0]);
            return 8;
        }
    }

    private static Bundle a(GeoFence geoFence, String str, String str2, int i9, int i10) {
        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", i9);
        bundle.putInt(GeoFence.BUNDLE_KEY_LOCERRORCODE, i10);
        bundle.putParcelable(GeoFence.BUNDLE_KEY_FENCE, geoFence);
        return bundle;
    }

    private GeoFence a(Bundle bundle, boolean z8) {
        GeoFence geoFence = new GeoFence();
        ArrayList arrayList = new ArrayList();
        DPoint dPoint = new DPoint();
        if (z8) {
            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 f9 = bundle.getFloat("fenceRadius", 1000.0f);
            float f10 = f9 > 0.0f ? f9 : 1000.0f;
            geoFence.setRadius(f10);
            geoFence.setMinDis2Center(f10);
            geoFence.setMaxDis2Center(f10);
        }
        geoFence.setActivatesAction(this.f9009f);
        geoFence.setCustomId(bundle.getString(GeoFence.BUNDLE_KEY_CUSTOMID));
        ArrayList arrayList2 = new ArrayList();
        arrayList2.add(arrayList);
        geoFence.setPointList(arrayList2);
        geoFence.setCenter(dPoint);
        geoFence.setPendingIntentAction(this.f9007d);
        geoFence.setExpiration(-1L);
        geoFence.setPendingIntent(this.f9006c);
        StringBuilder sb = new StringBuilder();
        sb.append(com.loc.c.a());
        geoFence.setFenceId(sb.toString());
        fw fwVar = this.f9004a;
        if (fwVar != null) {
            fwVar.a(this.f9005b, 2);
        }
        return geoFence;
    }

    static void a(String str, int i9, String str2, String... strArr) {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("===========================================\n");
        stringBuffer.append("              " + str + "                ");
        stringBuffer.append("\n");
        stringBuffer.append("-------------------------------------------\n");
        stringBuffer.append("errorCode:".concat(String.valueOf(i9)));
        stringBuffer.append("\n");
        stringBuffer.append("错误信息:".concat(String.valueOf(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(int i9, String str, String str2, DPoint dPoint) {
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        if (i9 != 1) {
            if (i9 == 2) {
                if (dPoint == null) {
                    return false;
                }
                if (dPoint.getLatitude() > 90.0d || dPoint.getLatitude() < -90.0d || dPoint.getLongitude() > 180.0d || dPoint.getLongitude() < -180.0d) {
                    a("添加围栏失败", 0, "经纬度错误,传入的纬度:" + dPoint.getLatitude() + "传入的经度:" + dPoint.getLongitude(), new String[0]);
                    return false;
                }
            }
        } else if (TextUtils.isEmpty(str2)) {
            return false;
        }
        return true;
    }

    private static boolean a(GeoFence geoFence, int i9) {
        boolean z8 = true;
        boolean z9 = false;
        if ((i9 & 1) == 1) {
            try {
                if (geoFence.getStatus() == 1) {
                    z9 = true;
                }
            } catch (Throwable th) {
                fr.a(th, "Utils", "remindStatus");
                return z9;
            }
        }
        if ((i9 & 2) == 2 && geoFence.getStatus() == 2) {
            z9 = true;
        }
        if ((i9 & 4) == 4) {
        }
        z8 = z9;
        return z8;
    }

    private static boolean a(AMapLocation aMapLocation, GeoFence geoFence) {
        boolean z8 = true;
        boolean z9 = false;
        try {
        } catch (Throwable th) {
            th = th;
            z8 = false;
        }
        if (fy.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) {
                        }
                    }
                }
                for (List<DPoint> list : geoFence.getPointList()) {
                    try {
                        if (b(aMapLocation, list)) {
                            z9 = true;
                        }
                    } catch (Throwable th2) {
                        th = th2;
                        z8 = z9;
                        fr.a(th, "Utils", "isInGeoFence");
                        return z8;
                    }
                }
                z8 = z9;
                return z8;
            }
        }
        z8 = false;
        return z8;
    }

    private static boolean a(AMapLocation aMapLocation, DPoint dPoint, float f9) {
        return fy.a(new double[]{dPoint.getLatitude(), dPoint.getLongitude(), aMapLocation.getLatitude(), aMapLocation.getLongitude()}) <= f9;
    }

    public static float b(DPoint dPoint, List<DPoint> list) {
        float f9 = Float.MIN_VALUE;
        if (dPoint != null && list != null && !list.isEmpty()) {
            for (DPoint dPoint2 : list) {
                f9 = Math.max(f9, fy.a(dPoint, dPoint2));
            }
        }
        return f9;
    }

    private static DPoint b(List<DPoint> list) {
        DPoint dPoint = new DPoint();
        if (list != null) {
            try {
                double d9 = 0.0d;
                double d10 = 0.0d;
                for (DPoint dPoint2 : list) {
                    d9 += dPoint2.getLatitude();
                    d10 += dPoint2.getLongitude();
                }
                return new DPoint(fy.b(d9 / list.size()), fy.b(d10 / list.size()));
            } catch (Throwable th) {
                fr.a(th, "GeoFenceUtil", "getPolygonCenter");
                return dPoint;
            }
        }
        return dPoint;
    }

    private void b(int i9, Bundle bundle) {
        String str;
        int i10;
        String str2;
        int i11;
        String str3;
        String str4;
        String a9;
        Bundle bundle2 = new Bundle();
        try {
            ArrayList<? extends Parcelable> arrayList = new ArrayList<>();
            if (bundle == null || bundle.isEmpty()) {
                str2 = Constants.KEY_ERROR_CODE;
                i11 = 1;
            } else {
                List<GeoFence> arrayList2 = new ArrayList<>();
                String string = bundle.getString(GeoFence.BUNDLE_KEY_CUSTOMID);
                String string2 = bundle.getString("keyWords");
                String string3 = bundle.getString("city");
                String string4 = bundle.getString("poiType");
                DPoint dPoint = (DPoint) bundle.getParcelable("centerPoint");
                int i12 = bundle.getInt("searchSize", 10);
                float f9 = bundle.getFloat("aroundRadius", 3000.0f);
                if (a(i9, string2, string4, dPoint)) {
                    Bundle bundle3 = new Bundle();
                    bundle3.putString(GeoFence.BUNDLE_KEY_CUSTOMID, string);
                    bundle3.putString("pendingIntentAction", this.f9007d);
                    str3 = GeoFence.BUNDLE_KEY_CUSTOMID;
                    str4 = Constants.KEY_ERROR_CODE;
                    try {
                        bundle3.putLong("expiration", -1L);
                        bundle3.putInt("activatesAction", this.f9009f);
                        if (i9 == 1) {
                            bundle3.putFloat("fenceRadius", 1000.0f);
                            a9 = this.f9019p.a(this.f9005b, "http://restsdk.amap.com/v3/place/text?", string2, string4, string3, String.valueOf(i12));
                        } else if (i9 != 2) {
                            a9 = i9 != 3 ? null : this.f9019p.a(this.f9005b, "http://restsdk.amap.com/v3/config/district?", string2);
                        } else {
                            double b9 = fy.b(dPoint.getLatitude());
                            double b10 = fy.b(dPoint.getLongitude());
                            int intValue = Float.valueOf(f9).intValue();
                            bundle3.putFloat("fenceRadius", 200.0f);
                            a9 = this.f9019p.a(this.f9005b, "http://restsdk.amap.com/v3/place/around?", string2, string4, String.valueOf(i12), String.valueOf(b9), String.valueOf(b10), String.valueOf(intValue));
                        }
                        if (a9 != null) {
                            int a10 = 1 == i9 ? com.loc.c.a(a9, arrayList2, bundle3) : 0;
                            if (2 == i9) {
                                a10 = com.loc.c.b(a9, arrayList2, bundle3);
                            }
                            if (3 == i9) {
                                a10 = this.f9020q.c(a9, arrayList2, bundle3);
                            }
                            if (a10 != 10000) {
                                i10 = d(a10);
                            } else if (arrayList2.isEmpty()) {
                                i10 = 16;
                            } else {
                                i10 = a(arrayList2);
                                if (i10 == 0) {
                                    try {
                                        arrayList.addAll(arrayList2);
                                    } catch (Throwable th) {
                                        th = th;
                                        str = str4;
                                        try {
                                            fr.a(th, "GeoFenceManager", "doAddGeoFenceNearby");
                                            bundle2.putInt(str, 8);
                                            a(1000, bundle2);
                                            return;
                                        } catch (Throwable th2) {
                                            bundle2.putInt(str, i10);
                                            a(1000, bundle2);
                                            throw th2;
                                        }
                                    }
                                }
                            }
                        } else {
                            i10 = 4;
                        }
                    } catch (Throwable th3) {
                        th = th3;
                        str = str4;
                        i10 = 0;
                        fr.a(th, "GeoFenceManager", "doAddGeoFenceNearby");
                        bundle2.putInt(str, 8);
                        a(1000, bundle2);
                        return;
                    }
                } else {
                    str3 = GeoFence.BUNDLE_KEY_CUSTOMID;
                    str4 = Constants.KEY_ERROR_CODE;
                    i10 = 1;
                }
                bundle2.putString(str3, string);
                bundle2.putParcelableArrayList("resultList", arrayList);
                i11 = i10;
                str2 = str4;
            }
            bundle2.putInt(str2, i11);
            a(1000, bundle2);
        } catch (Throwable th4) {
            th = th4;
            str = Constants.KEY_ERROR_CODE;
        }
    }

    private static boolean b(AMapLocation aMapLocation, GeoFence geoFence) {
        boolean z8 = true;
        try {
            if (!a(aMapLocation, geoFence)) {
                if (geoFence.getStatus() != 2) {
                    try {
                        geoFence.setStatus(2);
                        geoFence.setEnterTime(-1L);
                    } catch (Throwable th) {
                        th = th;
                        fr.a(th, "Utils", "isFenceStatusChanged");
                        return z8;
                    }
                }
                z8 = false;
            } else if (geoFence.getEnterTime() == -1) {
                if (geoFence.getStatus() != 1) {
                    geoFence.setEnterTime(fy.b());
                    geoFence.setStatus(1);
                }
                z8 = false;
            } else {
                if (geoFence.getStatus() != 3 && fy.b() - geoFence.getEnterTime() > 600000) {
                    geoFence.setStatus(3);
                }
                z8 = false;
            }
        } catch (Throwable th2) {
            th = th2;
            z8 = false;
        }
        return z8;
    }

    private static boolean b(AMapLocation aMapLocation, List<DPoint> list) {
        if (list.size() < 3) {
            return false;
        }
        return fr.a(new DPoint(aMapLocation.getLatitude(), aMapLocation.getLongitude()), list);
    }

    private int c(GeoFence geoFence) {
        try {
            if (this.f9010g == null) {
                this.f9010g = new ArrayList<>();
            }
            if (this.f9010g.contains(geoFence)) {
                return 17;
            }
            this.f9010g.add(geoFence);
            return 0;
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "addGeoFence2List");
            a("添加围栏失败", 8, th.getMessage(), new String[0]);
            return 8;
        }
    }

    private static int d(int i9) {
        if (i9 != 1 && i9 != 7 && i9 != 4 && i9 != 5 && i9 != 16 && i9 != 17) {
            switch (i9) {
                case 10000:
                    i9 = 0;
                    break;
                case CameraAccessExceptionCompat.CAMERA_UNAVAILABLE_DO_NOT_DISTURB:
                case CameraAccessExceptionCompat.CAMERA_CHARACTERISTICS_CREATION_ERROR:
                case 10007:
                case 10008:
                case 10009:
                case RequestManager.NOTIFY_CONNECT_FAILED:
                case RequestManager.NOTIFY_CONNECT_SUSPENDED:
                    i9 = 7;
                    break;
                case 10003:
                case 10004:
                case 10005:
                case 10006:
                case 10010:
                case RequestManager.NOTIFY_CONNECT_SUCCESS:
                case 10014:
                case 10015:
                case 10016:
                case 10017:
                    i9 = 4;
                    break;
                default:
                    switch (i9) {
                        case 20000:
                        case 20001:
                        case 20002:
                            i9 = 1;
                            break;
                        case 20003:
                        default:
                            i9 = 8;
                            break;
                    }
            }
        }
        if (i9 != 0) {
            a("添加围栏失败", i9, "searchErrCode is ".concat(String.valueOf(i9)), new String[0]);
        }
        return i9;
    }

    private void d(GeoFence geoFence) {
        Bundle bundle = new Bundle();
        bundle.putParcelable("geoFence", geoFence);
        a(1001, bundle);
    }

    private void j() {
        if (!this.f9018o) {
            this.f9018o = true;
        }
        if (this.f9017n) {
            return;
        }
        try {
            this.f9011h = Looper.myLooper() == null ? new c(this.f9005b.getMainLooper()) : new c();
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManger", "init 1");
        }
        try {
            b bVar = new b("fenceActionThread");
            this.f9015l = bVar;
            bVar.setPriority(5);
            this.f9015l.start();
            this.f9014k = new HandlerC0095a(this.f9015l.getLooper());
        } catch (Throwable th2) {
            fr.a(th2, "GeoFenceManger", "init 2");
        }
        try {
            this.f9019p = new com.loc.b(this.f9005b);
            this.f9020q = new com.loc.c();
            this.f9024u = new AMapLocationClientOption();
            this.f9021r = new AMapLocationClient(this.f9005b);
            this.f9024u.setLocationCacheEnable(true);
            this.f9024u.setNeedAddress(false);
            this.f9021r.setLocationListener(this.f9026w);
            if (this.f9004a == null) {
                this.f9004a = new fw();
            }
        } catch (Throwable th3) {
            fr.a(th3, "GeoFenceManger", "initBase");
        }
        this.f9017n = true;
        try {
            String str = this.f9007d;
            if (str != null && this.f9006c == null) {
                a(str);
            }
        } catch (Throwable th4) {
            fr.a(th4, "GeoFenceManger", "init 4");
        }
        if (A) {
            return;
        }
        A = true;
        fw.a(this.f9005b, "O020", (JSONObject) null);
    }

    private boolean k() {
        ArrayList<GeoFence> arrayList = this.f9010g;
        if (arrayList == null || arrayList.isEmpty()) {
            return true;
        }
        Iterator<GeoFence> it = this.f9010g.iterator();
        while (it.hasNext()) {
            if (it.next().isAble()) {
                return false;
            }
        }
        return true;
    }

    private void l() {
        try {
            synchronized (this.f9013j) {
                c cVar = this.f9011h;
                if (cVar != null) {
                    cVar.removeCallbacksAndMessages(null);
                }
                this.f9011h = null;
            }
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "destroyResultHandler");
        }
    }

    private void m() {
        try {
            synchronized (this.f9012i) {
                HandlerC0095a handlerC0095a = this.f9014k;
                if (handlerC0095a != null) {
                    handlerC0095a.removeCallbacksAndMessages(null);
                }
                this.f9014k = null;
            }
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "destroyActionHandler");
        }
    }

    private void n() {
        if (this.f9028y || this.f9014k == null) {
            return;
        }
        if (p()) {
            a(6, (Bundle) null, 0L);
            a(5, (Bundle) null, 0L);
            return;
        }
        b(7);
        a(7, (Bundle) null, 0L);
    }

    private void o() {
        try {
            if (this.f9016m) {
                b(8);
            }
            AMapLocationClient aMapLocationClient = this.f9021r;
            if (aMapLocationClient != null) {
                aMapLocationClient.stopLocation();
            }
            this.f9016m = false;
        } catch (Throwable unused) {
        }
    }

    private boolean p() {
        return this.f9022s != null && fy.a(this.f9022s) && fy.b() - this.f9023t < 10000;
    }

    public final PendingIntent a(String str) {
        synchronized (this.f9029z) {
            try {
                Intent intent = new Intent(str);
                intent.setPackage(l.c(this.f9005b));
                if (Build.VERSION.SDK_INT < 31 || this.f9005b.getApplicationInfo().targetSdkVersion < 31) {
                    Context context = this.f9005b;
                    PushAutoTrackHelper.hookIntentGetBroadcast(context, 0, intent, 0);
                    PendingIntent broadcast = PendingIntent.getBroadcast(context, 0, intent, 0);
                    PushAutoTrackHelper.hookPendingIntentGetBroadcast(broadcast, context, 0, intent, 0);
                    this.f9006c = broadcast;
                } else {
                    Context context2 = this.f9005b;
                    PushAutoTrackHelper.hookIntentGetBroadcast(context2, 0, intent, 33554432);
                    PendingIntent broadcast2 = PendingIntent.getBroadcast(context2, 0, intent, 33554432);
                    PushAutoTrackHelper.hookPendingIntentGetBroadcast(broadcast2, context2, 0, intent, 33554432);
                    this.f9006c = broadcast2;
                }
                this.f9007d = str;
                ArrayList<GeoFence> arrayList = this.f9010g;
                if (arrayList != null && !arrayList.isEmpty()) {
                    Iterator<GeoFence> it = this.f9010g.iterator();
                    while (it.hasNext()) {
                        GeoFence next = it.next();
                        next.setPendingIntent(this.f9006c);
                        next.setPendingIntentAction(this.f9007d);
                    }
                }
            }
        }
        return this.f9006c;
    }

    public final void a() {
        try {
            this.f9018o = false;
            a(10, (Bundle) null, 0L);
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "removeGeoFence");
        }
    }

    public final void a(int i9) {
        try {
            j();
            i9 = (i9 > 7 || i9 <= 0) ? 1 : 1;
            Bundle bundle = new Bundle();
            bundle.putInt("activatesAction", i9);
            a(9, bundle, 0L);
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "setActivateAction");
        }
    }

    final void a(int i9, Bundle bundle) {
        try {
            synchronized (this.f9013j) {
                c cVar = this.f9011h;
                if (cVar != null) {
                    Message obtainMessage = cVar.obtainMessage();
                    obtainMessage.what = i9;
                    obtainMessage.setData(bundle);
                    this.f9011h.sendMessage(obtainMessage);
                }
            }
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "sendResultHandlerMessage");
        }
    }

    final void a(int i9, Bundle bundle, long j9) {
        try {
            synchronized (this.f9012i) {
                HandlerC0095a handlerC0095a = this.f9014k;
                if (handlerC0095a != null) {
                    Message obtainMessage = handlerC0095a.obtainMessage();
                    obtainMessage.what = i9;
                    obtainMessage.setData(bundle);
                    this.f9014k.sendMessageDelayed(obtainMessage, j9);
                }
            }
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "sendActionHandlerMessage");
        }
    }

    final void a(Bundle bundle) {
        int i9 = 1;
        if (bundle != null) {
            try {
                i9 = bundle.getInt("activatesAction", 1);
            } catch (Throwable th) {
                fr.a(th, "GeoFenceManager", "doSetActivatesAction");
                return;
            }
        }
        if (this.f9009f != i9) {
            ArrayList<GeoFence> arrayList = this.f9010g;
            if (arrayList != null && !arrayList.isEmpty()) {
                Iterator<GeoFence> it = this.f9010g.iterator();
                while (it.hasNext()) {
                    GeoFence next = it.next();
                    next.setStatus(0);
                    next.setEnterTime(-1L);
                }
            }
            n();
        }
        this.f9009f = i9;
    }

    public final void a(GeoFenceListener geoFenceListener) {
        try {
            this.f9008e = geoFenceListener;
        } catch (Throwable unused) {
        }
    }

    final void a(AMapLocation aMapLocation) {
        ArrayList<GeoFence> arrayList;
        try {
            if (this.f9028y || (arrayList = this.f9010g) == null || arrayList.isEmpty() || aMapLocation == null || aMapLocation.getErrorCode() != 0) {
                return;
            }
            Iterator<GeoFence> it = this.f9010g.iterator();
            while (it.hasNext()) {
                GeoFence next = it.next();
                if (next.isAble() && b(aMapLocation, next) && a(next, this.f9009f)) {
                    next.setCurrentLocation(aMapLocation);
                    d(next);
                }
            }
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "doCheckFence");
        }
    }

    public final void a(DPoint dPoint, float f9, String str) {
        try {
            j();
            Bundle bundle = new Bundle();
            bundle.putParcelable("centerPoint", dPoint);
            bundle.putFloat("fenceRadius", f9);
            bundle.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
            a(0, bundle, 0L);
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "addRoundGeoFence");
        }
    }

    public final void a(String str, String str2) {
        try {
            j();
            Bundle bundle = new Bundle();
            bundle.putString("keyWords", str);
            bundle.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str2);
            a(4, bundle, 0L);
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "addDistricetGeoFence");
        }
    }

    public final void a(String str, String str2, DPoint dPoint, float f9, int i9, String str3) {
        try {
            j();
            f9 = (f9 <= 0.0f || f9 > 50000.0f) ? 3000.0f : 3000.0f;
            if (i9 <= 0) {
                i9 = 10;
            }
            if (i9 > 25) {
                i9 = 25;
            }
            Bundle bundle = new Bundle();
            bundle.putString("keyWords", str);
            bundle.putString("poiType", str2);
            bundle.putParcelable("centerPoint", dPoint);
            bundle.putFloat("aroundRadius", f9);
            bundle.putInt("searchSize", i9);
            bundle.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str3);
            a(3, bundle, 0L);
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "addNearbyGeoFence");
        }
    }

    public final void a(String str, String str2, String str3, int i9, String str4) {
        try {
            j();
            if (i9 <= 0) {
                i9 = 10;
            }
            if (i9 > 25) {
                i9 = 25;
            }
            Bundle bundle = new Bundle();
            bundle.putString("keyWords", str);
            bundle.putString("poiType", str2);
            bundle.putString("city", str3);
            bundle.putInt("searchSize", i9);
            bundle.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str4);
            a(2, bundle, 0L);
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "addKeywordGeoFence");
        }
    }

    public final void a(String str, boolean z8) {
        try {
            j();
            Bundle bundle = new Bundle();
            bundle.putString("fid", str);
            bundle.putBoolean("ab", z8);
            a(12, bundle, 0L);
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "setGeoFenceAble");
        }
    }

    public final void a(List<DPoint> list, String str) {
        try {
            j();
            Bundle bundle = new Bundle();
            bundle.putParcelableArrayList("pointList", new ArrayList<>(list));
            bundle.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
            a(1, bundle, 0L);
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "addPolygonGeoFence");
        }
    }

    public final boolean a(GeoFence geoFence) {
        try {
            ArrayList<GeoFence> arrayList = this.f9010g;
            if (arrayList != null && !arrayList.isEmpty()) {
                if (this.f9010g.contains(geoFence)) {
                    if (this.f9010g.size() == 1) {
                        this.f9018o = false;
                    }
                    Bundle bundle = new Bundle();
                    bundle.putParcelable("fc", geoFence);
                    a(11, bundle, 0L);
                    return true;
                }
                return false;
            }
            this.f9018o = false;
            a(10, (Bundle) null, 0L);
            return true;
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "removeGeoFence(GeoFence)");
            return false;
        }
    }

    public final List<GeoFence> b() {
        try {
            if (this.f9010g == null) {
                this.f9010g = new ArrayList<>();
            }
            return (ArrayList) this.f9010g.clone();
        } catch (Throwable unused) {
            return new ArrayList();
        }
    }

    final void b(int i9) {
        try {
            synchronized (this.f9012i) {
                HandlerC0095a handlerC0095a = this.f9014k;
                if (handlerC0095a != null) {
                    handlerC0095a.removeMessages(i9);
                }
            }
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "removeActionHandlerMessage");
        }
    }

    final void b(Bundle bundle) {
        String str;
        try {
            ArrayList<? extends Parcelable> arrayList = new ArrayList<>();
            String str2 = "";
            int i9 = 1;
            if (bundle != null && !bundle.isEmpty()) {
                DPoint dPoint = (DPoint) bundle.getParcelable("centerPoint");
                str = bundle.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 a9 = a(bundle, false);
                        i9 = c(a9);
                        if (i9 == 0) {
                            arrayList.add(a9);
                        }
                        Bundle bundle2 = new Bundle();
                        bundle2.putInt(Constants.KEY_ERROR_CODE, i9);
                        bundle2.putParcelableArrayList("resultList", arrayList);
                        bundle2.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
                        a(1000, bundle2);
                    }
                    a("添加围栏失败", 1, "经纬度错误,传入的纬度:" + dPoint.getLatitude() + "传入的经度:" + dPoint.getLongitude(), new String[0]);
                    Bundle bundle22 = new Bundle();
                    bundle22.putInt(Constants.KEY_ERROR_CODE, i9);
                    bundle22.putParcelableArrayList("resultList", arrayList);
                    bundle22.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
                    a(1000, bundle22);
                }
                str2 = str;
            }
            str = str2;
            Bundle bundle222 = new Bundle();
            bundle222.putInt(Constants.KEY_ERROR_CODE, i9);
            bundle222.putParcelableArrayList("resultList", arrayList);
            bundle222.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
            a(1000, bundle222);
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "doAddGeoFenceRound");
        }
    }

    final void b(GeoFence geoFence) {
        PendingIntent pendingIntent;
        Context context;
        try {
            synchronized (this.f9029z) {
                if (this.f9005b != null) {
                    if (this.f9006c == null && geoFence.getPendingIntent() == null) {
                        return;
                    }
                    Intent intent = new Intent();
                    intent.putExtras(a(geoFence, geoFence.getFenceId(), geoFence.getCustomId(), geoFence.getStatus(), 0));
                    String str = this.f9007d;
                    if (str != null) {
                        intent.setAction(str);
                    }
                    intent.setPackage(l.c(this.f9005b));
                    if (geoFence.getPendingIntent() != null) {
                        pendingIntent = geoFence.getPendingIntent();
                        context = this.f9005b;
                    } else {
                        pendingIntent = this.f9006c;
                        context = this.f9005b;
                    }
                    pendingIntent.send(context, 0, intent);
                }
            }
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "resultTriggerGeoFence");
        }
    }

    final void c() {
        if (this.f9017n) {
            ArrayList<GeoFence> arrayList = this.f9010g;
            if (arrayList != null) {
                arrayList.clear();
                this.f9010g = null;
            }
            if (this.f9018o) {
                return;
            }
            m();
            AMapLocationClient aMapLocationClient = this.f9021r;
            if (aMapLocationClient != null) {
                aMapLocationClient.stopLocation();
                this.f9021r.onDestroy();
            }
            this.f9021r = null;
            b bVar = this.f9015l;
            if (bVar != null) {
                if (Build.VERSION.SDK_INT >= 18) {
                    bVar.quitSafely();
                } else {
                    bVar.quit();
                }
            }
            this.f9015l = null;
            this.f9019p = null;
            synchronized (this.f9029z) {
                PendingIntent pendingIntent = this.f9006c;
                if (pendingIntent != null) {
                    pendingIntent.cancel();
                }
                this.f9006c = null;
            }
            l();
            fw fwVar = this.f9004a;
            if (fwVar != null) {
                fwVar.b(this.f9005b);
            }
            this.f9016m = false;
            this.f9017n = false;
        }
    }

    final void c(int i9) {
        try {
            if (this.f9005b != null) {
                synchronized (this.f9029z) {
                    if (this.f9006c == null) {
                        return;
                    }
                    Intent intent = new Intent();
                    intent.putExtras(a((GeoFence) null, (String) null, (String) null, 4, i9));
                    this.f9006c.send(this.f9005b, 0, intent);
                }
            }
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "resultRemindLocationError");
        }
    }

    final void c(Bundle bundle) {
        GeoFence a9;
        try {
            ArrayList<? extends Parcelable> arrayList = new ArrayList<>();
            String str = "";
            int i9 = 1;
            if (bundle != null && !bundle.isEmpty()) {
                ArrayList parcelableArrayList = bundle.getParcelableArrayList("pointList");
                String string = bundle.getString(GeoFence.BUNDLE_KEY_CUSTOMID);
                if (parcelableArrayList != null && parcelableArrayList.size() > 2 && (i9 = c((a9 = a(bundle, true)))) == 0) {
                    arrayList.add(a9);
                }
                str = string;
            }
            Bundle bundle2 = new Bundle();
            bundle2.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
            bundle2.putInt(Constants.KEY_ERROR_CODE, i9);
            bundle2.putParcelableArrayList("resultList", arrayList);
            a(1000, bundle2);
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "doAddGeoFencePolygon");
        }
    }

    final void d() {
        try {
            if (this.f9021r != null) {
                o();
                this.f9024u.setOnceLocation(true);
                this.f9021r.setLocationOption(this.f9024u);
                this.f9021r.startLocation();
            }
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "doStartOnceLocation");
        }
    }

    final void d(Bundle bundle) {
        b(2, bundle);
    }

    final void e() {
        try {
            if (!this.f9028y && fy.a(this.f9022s)) {
                float a9 = a(this.f9022s, this.f9010g);
                if (a9 == Float.MAX_VALUE) {
                    return;
                }
                if (a9 < 1000.0f) {
                    b(7);
                    Bundle bundle = new Bundle();
                    bundle.putLong(com.umeng.analytics.pro.bh.aX, 2000L);
                    a(8, bundle, 500L);
                } else if (a9 < 5000.0f) {
                    o();
                    b(7);
                    a(7, (Bundle) null, 10000L);
                } else {
                    o();
                    b(7);
                    a(7, (Bundle) null, ((a9 - 4000.0f) / 100.0f) * 1000.0f);
                }
            }
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "doCheckLocationPolicy");
        }
    }

    final void e(Bundle bundle) {
        b(1, bundle);
    }

    public final void f() {
        try {
            j();
            this.f9028y = true;
            a(13, (Bundle) null, 0L);
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "pauseGeoFence");
        }
    }

    final void f(Bundle bundle) {
        b(3, bundle);
    }

    final void g() {
        try {
            b(7);
            b(8);
            AMapLocationClient aMapLocationClient = this.f9021r;
            if (aMapLocationClient != null) {
                aMapLocationClient.stopLocation();
            }
            this.f9016m = false;
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "doPauseGeoFence");
        }
    }

    final void g(Bundle bundle) {
        if (bundle != null) {
            try {
                if (bundle.isEmpty()) {
                    return;
                }
                String string = bundle.getString("fid");
                if (TextUtils.isEmpty(string)) {
                    return;
                }
                boolean z8 = bundle.getBoolean("ab", true);
                ArrayList<GeoFence> arrayList = this.f9010g;
                if (arrayList != null && !arrayList.isEmpty()) {
                    Iterator<GeoFence> it = this.f9010g.iterator();
                    while (true) {
                        if (!it.hasNext()) {
                            break;
                        }
                        GeoFence next = it.next();
                        if (next.getFenceId().equals(string)) {
                            next.setAble(z8);
                            break;
                        }
                    }
                }
                if (z8) {
                    n();
                } else if (k()) {
                    g();
                }
            } catch (Throwable th) {
                fr.a(th, "GeoFenceManager", "doSetGeoFenceAble");
            }
        }
    }

    public final void h() {
        try {
            j();
            if (this.f9028y) {
                this.f9028y = false;
                n();
            }
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "resumeGeoFence");
        }
    }

    final void h(Bundle bundle) {
        try {
            if (this.f9010g != null) {
                GeoFence geoFence = (GeoFence) bundle.getParcelable("fc");
                if (this.f9010g.contains(geoFence)) {
                    this.f9010g.remove(geoFence);
                }
                if (this.f9010g.size() <= 0) {
                    c();
                } else {
                    n();
                }
            }
        } catch (Throwable unused) {
        }
    }

    final void i(Bundle bundle) {
        if (bundle != null) {
            try {
                if (bundle.isEmpty()) {
                    return;
                }
                int i9 = bundle.getInt(Constants.KEY_ERROR_CODE);
                ArrayList parcelableArrayList = bundle.getParcelableArrayList("resultList");
                if (parcelableArrayList == null) {
                    parcelableArrayList = new ArrayList();
                }
                String string = bundle.getString(GeoFence.BUNDLE_KEY_CUSTOMID);
                if (string == null) {
                    string = "";
                }
                GeoFenceListener geoFenceListener = this.f9008e;
                if (geoFenceListener != null) {
                    geoFenceListener.onGeoFenceCreateFinished((ArrayList) parcelableArrayList.clone(), i9, string);
                }
                if (i9 == 0) {
                    n();
                }
            } catch (Throwable th) {
                fr.a(th, "GeoFenceManager", "resultAddGeoFenceFinished");
            }
        }
    }

    public final boolean i() {
        return this.f9028y;
    }

    final void j(Bundle bundle) {
        try {
            if (this.f9021r != null) {
                long j9 = 2000;
                if (bundle != null && !bundle.isEmpty()) {
                    j9 = bundle.getLong(com.umeng.analytics.pro.bh.aX, 2000L);
                }
                this.f9024u.setOnceLocation(false);
                this.f9024u.setInterval(j9);
                this.f9021r.setLocationOption(this.f9024u);
                if (this.f9016m) {
                    return;
                }
                this.f9021r.stopLocation();
                this.f9021r.startLocation();
                this.f9016m = true;
            }
        } catch (Throwable th) {
            fr.a(th, "GeoFenceManager", "doStartContinueLocation");
        }
    }
}