鳯华 v4.0.0版本的 MD5 值为:e66eea5d0a772ef117f7e252dfbb1dfc

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


package h5;

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 cn.jiguang.api.utils.ByteBufferUtils;
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.faceunity.utils.MakeupParamHelper;
import com.tencent.imsdk.BaseConstants;
import com.yalantis.ucrop.view.CropImageView;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@SuppressLint({"NewApi"})
public class a implements GeoFenceManagerBase {
    Context f14503b;
    q2 f14502a = null;
    PendingIntent f14504c = null;
    String f14505d = null;
    GeoFenceListener f14506e = null;
    private Object f14507f = new Object();
    volatile int f14508g = 1;
    ArrayList<GeoFence> f14509h = new ArrayList<>();
    d f14510i = null;
    Object f14511j = new Object();
    Object f14512k = new Object();
    b f14513l = null;
    c f14514m = null;
    volatile boolean f14515n = false;
    volatile boolean f14516o = false;
    volatile boolean f14517p = false;
    b0 f14518q = null;
    b1 f14519r = null;
    AMapLocationClient f14520s = null;
    volatile AMapLocation f14521t = null;
    long f14522u = 0;
    AMapLocationClientOption f14523v = null;
    int f14524w = 0;
    AMapLocationListener f14525x = new C0168a();
    final int f14526y = 3;
    volatile boolean f14527z = false;

    final class C0168a implements AMapLocationListener {
        C0168a() {
        }

        @Override
        public final void onLocationChanged(AMapLocation aMapLocation) {
            int i9;
            boolean z9;
            try {
                if (a.this.f14527z || !a.this.f14517p) {
                    return;
                }
                a.this.f14521t = aMapLocation;
                if (aMapLocation != null) {
                    i9 = aMapLocation.getErrorCode();
                    if (aMapLocation.getErrorCode() == 0) {
                        a.this.f14522u = t2.y();
                        a.this.h(5, null, 0L);
                        z9 = true;
                        if (!z9) {
                            a aVar = a.this;
                            aVar.f14524w = 0;
                            aVar.h(6, null, 0L);
                            return;
                        }
                        Bundle bundle = new Bundle();
                        if (!a.this.f14515n) {
                            a.this.f(7);
                            bundle.putLong("interval", 2000L);
                            a.this.h(8, bundle, 2000L);
                        }
                        a aVar2 = a.this;
                        int i10 = aVar2.f14524w + 1;
                        aVar2.f14524w = i10;
                        if (i10 >= 3) {
                            bundle.putInt(GeoFence.BUNDLE_KEY_LOCERRORCODE, i9);
                            a.this.g(1002, bundle);
                            return;
                        }
                        return;
                    }
                    a.l("定位失败", aMapLocation.getErrorCode(), aMapLocation.getErrorInfo(), "locationDetail:" + aMapLocation.getLocationDetail());
                } else {
                    i9 = 8;
                }
                z9 = false;
                if (!z9) {
                }
            } catch (Throwable unused) {
            }
        }
    }

    public class b extends Handler {
        public b(Looper looper) {
            super(looper);
        }

        @Override
        public final void handleMessage(Message message) {
            try {
                switch (message.what) {
                    case 0:
                        a.this.u(message.getData());
                        return;
                    case 1:
                        a.this.x(message.getData());
                        return;
                    case 2:
                        a.this.B(message.getData());
                        return;
                    case 3:
                        a.this.z(message.getData());
                        return;
                    case 4:
                        a.this.D(message.getData());
                        return;
                    case 5:
                        a.this.w();
                        return;
                    case 6:
                        a aVar = a.this;
                        aVar.k(aVar.f14521t);
                        return;
                    case 7:
                        a.this.r();
                        return;
                    case 8:
                        a.this.I(message.getData());
                        return;
                    case 9:
                        a.this.i(message.getData());
                        return;
                    case 10:
                        a.this.e();
                        return;
                    case 11:
                        a.this.G(message.getData());
                        return;
                    case 12:
                        a.this.F(message.getData());
                        return;
                    case 13:
                        a.this.y();
                        return;
                    default:
                        return;
                }
            } catch (Throwable unused) {
            }
        }
    }

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

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

    public class d extends Handler {
        public d() {
        }

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

        @Override
        public final void handleMessage(Message message) {
            try {
                Bundle data = message.getData();
                switch (message.what) {
                    case 1000:
                        a.this.H(data);
                        return;
                    case 1001:
                        a.this.j((GeoFence) data.getParcelable("geoFence"));
                        return;
                    case 1002:
                        a.this.s(data.getInt(GeoFence.BUNDLE_KEY_LOCERRORCODE));
                        return;
                    default:
                        return;
                }
            } catch (Throwable unused) {
            }
        }
    }

    public a(Context context) {
        this.f14503b = null;
        try {
            this.f14503b = context.getApplicationContext();
            A();
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManger", "<init>");
        }
    }

    private void A() {
        if (!this.f14517p) {
            this.f14517p = true;
        }
        if (this.f14516o) {
            return;
        }
        try {
            this.f14510i = Looper.myLooper() == null ? new d(this.f14503b.getMainLooper()) : new d();
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManger", "init 1");
        }
        try {
            c cVar = new c("fenceActionThread");
            this.f14514m = cVar;
            cVar.setPriority(5);
            this.f14514m.start();
            this.f14513l = new b(this.f14514m.getLooper());
        } catch (Throwable th2) {
            l2.h(th2, "GeoFenceManger", "init 2");
        }
        try {
            this.f14518q = new b0(this.f14503b);
            this.f14519r = new b1();
            this.f14523v = new AMapLocationClientOption();
            this.f14520s = new AMapLocationClient(this.f14503b);
            this.f14523v.setLocationCacheEnable(true);
            this.f14523v.setNeedAddress(false);
            this.f14520s.setLocationListener(this.f14525x);
            if (this.f14502a == null) {
                this.f14502a = new q2();
            }
        } catch (Throwable th3) {
            l2.h(th3, "GeoFenceManger", "initBase");
        }
        this.f14516o = true;
        try {
            String str = this.f14505d;
            if (str == null || this.f14504c != null) {
                return;
            }
            createPendingIntent(str);
        } catch (Throwable th4) {
            l2.h(th4, "GeoFenceManger", "init 4");
        }
    }

    private void C() {
        if (this.f14527z || this.f14513l == null) {
            return;
        }
        boolean z9 = false;
        if (this.f14521t != null && t2.o(this.f14521t) && t2.y() - this.f14522u < 10000) {
            z9 = true;
        }
        if (z9) {
            h(6, null, 0L);
            h(5, null, 0L);
            return;
        }
        f(7);
        h(7, null, 0L);
    }

    private void E() {
        try {
            if (this.f14515n) {
                f(8);
            }
            AMapLocationClient aMapLocationClient = this.f14520s;
            if (aMapLocationClient != null) {
                aMapLocationClient.stopLocation();
            }
            this.f14515n = false;
        } catch (Throwable unused) {
        }
    }

    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, t2.d(dPoint, dPoint2));
            }
        }
        return f9;
    }

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

    private static Bundle c(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(GeoFence.BUNDLE_KEY_FENCESTATUS, i9);
        bundle.putInt(GeoFence.BUNDLE_KEY_LOCERRORCODE, i10);
        bundle.putParcelable(GeoFence.BUNDLE_KEY_FENCE, geoFence);
        return bundle;
    }

    private GeoFence d(Bundle bundle, boolean z9) {
        GeoFence geoFence = new GeoFence();
        ArrayList arrayList = new ArrayList();
        DPoint dPoint = new DPoint();
        if (z9) {
            geoFence.setType(1);
            arrayList = bundle.getParcelableArrayList("pointList");
            if (arrayList != null) {
                dPoint = q(arrayList);
            }
            geoFence.setMaxDis2Center(o(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 > CropImageView.DEFAULT_ASPECT_RATIO ? f9 : 1000.0f;
            geoFence.setRadius(f10);
            geoFence.setMinDis2Center(f10);
            geoFence.setMaxDis2Center(f10);
        }
        geoFence.setActivatesAction(this.f14508g);
        geoFence.setCustomId(bundle.getString(GeoFence.BUNDLE_KEY_CUSTOMID));
        ArrayList arrayList2 = new ArrayList();
        arrayList2.add(arrayList);
        geoFence.setPointList(arrayList2);
        geoFence.setCenter(dPoint);
        geoFence.setPendingIntentAction(this.f14505d);
        geoFence.setExpiration(-1L);
        geoFence.setPendingIntent(this.f14504c);
        StringBuilder sb = new StringBuilder();
        sb.append(b1.b());
        geoFence.setFenceId(sb.toString());
        q2 q2Var = this.f14502a;
        if (q2Var != null) {
            q2Var.b(this.f14503b, 2);
        }
        return geoFence;
    }

    static void l(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:" + i9);
        stringBuffer.append("\n");
        stringBuffer.append("错误信息:" + str2);
        stringBuffer.append("\n");
        if (strArr != null && strArr.length > 0) {
            for (String str3 : strArr) {
                stringBuffer.append(str3);
                stringBuffer.append("\n");
            }
        }
        stringBuffer.append("===========================================\n");
        Log.i("fenceErrLog", stringBuffer.toString());
    }

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

    private static boolean n(AMapLocation aMapLocation, GeoFence geoFence) {
        boolean z9 = false;
        try {
            if (t2.o(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 z10 = false;
                    for (List<DPoint> list : geoFence.getPointList()) {
                        try {
                            if (list.size() < 3 ? false : l2.k(new DPoint(aMapLocation.getLatitude(), aMapLocation.getLongitude()), list)) {
                                z10 = true;
                            }
                        } catch (Throwable th) {
                            th = th;
                            z9 = z10;
                            l2.h(th, "Utils", "isInGeoFence");
                            return z9;
                        }
                    }
                    z9 = z10;
                }
                DPoint center = geoFence.getCenter();
                if (t2.e(new double[]{center.getLatitude(), center.getLongitude(), aMapLocation.getLatitude(), aMapLocation.getLongitude()}) <= geoFence.getRadius()) {
                    return true;
                }
            }
        } catch (Throwable th2) {
            th = th2;
        }
        return z9;
    }

    public static float o(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, t2.d(dPoint, dPoint2));
            }
        }
        return f9;
    }

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

    private static DPoint q(List<DPoint> list) {
        DPoint dPoint = new DPoint();
        if (list != null) {
            try {
                double d10 = MakeupParamHelper.MakeupParams.BROW_WARP_TYPE_WILLOW;
                double d11 = 0.0d;
                for (DPoint dPoint2 : list) {
                    d10 += dPoint2.getLatitude();
                    d11 += dPoint2.getLongitude();
                }
                return new DPoint(t2.I(d10 / list.size()), t2.I(d11 / list.size()));
            } catch (Throwable th) {
                l2.h(th, "GeoFenceUtil", "getPolygonCenter");
                return dPoint;
            }
        }
        return dPoint;
    }

    private void t(int i9, Bundle bundle) {
        String str;
        int i10;
        String str2;
        boolean z9;
        boolean z10;
        String str3;
        String str4;
        int i11;
        int i12;
        String b10;
        int i13;
        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("city");
                        String string4 = bundle.getString("poiType");
                        DPoint dPoint = (DPoint) bundle.getParcelable("centerPoint");
                        int i14 = bundle.getInt("searchSize", 10);
                        float f9 = bundle.getFloat("aroundRadius", 3000.0f);
                        if (TextUtils.isEmpty(string2)) {
                            str2 = "添加围栏失败";
                            z10 = false;
                        } else {
                            if (i9 != 1) {
                                if (i9 == 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 = "添加围栏失败";
                                                l(str2, 0, "经纬度错误,传入的纬度:" + dPoint.getLatitude() + "传入的经度:" + dPoint.getLongitude(), new String[0]);
                                            }
                                        } catch (Throwable th) {
                                            th = th;
                                            str = "errorCode";
                                            i10 = 0;
                                            try {
                                                l2.h(th, "GeoFenceManager", "doAddGeoFenceNearby");
                                                bundle2.putInt(str, 8);
                                                g(1000, bundle2);
                                                return;
                                            } catch (Throwable th2) {
                                                bundle2.putInt(str, i10);
                                                g(1000, bundle2);
                                                throw th2;
                                            }
                                        }
                                    }
                                }
                                str2 = "添加围栏失败";
                                z9 = true;
                            } else {
                                str2 = "添加围栏失败";
                                z9 = TextUtils.isEmpty(string4) ? false : false;
                                z9 = true;
                            }
                            z10 = z9;
                        }
                        if (z10) {
                            Bundle bundle3 = new Bundle();
                            bundle3.putString(GeoFence.BUNDLE_KEY_CUSTOMID, string);
                            bundle3.putString("pendingIntentAction", this.f14505d);
                            str3 = GeoFence.BUNDLE_KEY_CUSTOMID;
                            str4 = "errorCode";
                            try {
                                bundle3.putLong("expiration", -1L);
                                bundle3.putInt("activatesAction", this.f14508g);
                                try {
                                    if (i9 == 1) {
                                        bundle3.putFloat("fenceRadius", 1000.0f);
                                        b10 = this.f14518q.b(this.f14503b, "http://restapi.amap.com/v3/place/text?", string2, string4, string3, String.valueOf(i14));
                                    } else if (i9 != 2) {
                                        b10 = i9 != 3 ? null : this.f14518q.a(this.f14503b, "http://restapi.amap.com/v3/config/district?", string2);
                                    } else {
                                        double I = t2.I(dPoint.getLatitude());
                                        double I2 = t2.I(dPoint.getLongitude());
                                        int intValue = Float.valueOf(f9).intValue();
                                        bundle3.putFloat("fenceRadius", 200.0f);
                                        b10 = this.f14518q.c(this.f14503b, "http://restapi.amap.com/v3/place/around?", string2, string4, String.valueOf(i14), String.valueOf(I), String.valueOf(I2), String.valueOf(intValue));
                                    }
                                    int i15 = 4;
                                    if (b10 != null) {
                                        int a10 = 1 == i9 ? b1.a(b10, arrayList2, bundle3) : 0;
                                        if (2 == i9) {
                                            a10 = b1.d(b10, arrayList2, bundle3);
                                        }
                                        if (3 == i9) {
                                            a10 = this.f14519r.e(b10, arrayList2, bundle3);
                                        }
                                        if (a10 != 10000) {
                                            if (a10 != 1 && a10 != 7 && a10 != 4 && a10 != 5 && a10 != 16 && a10 != 17) {
                                                switch (a10) {
                                                    case ByteBufferUtils.ERROR_CODE:
                                                        i13 = 0;
                                                        break;
                                                    case 10001:
                                                    case 10002:
                                                    case BaseConstants.ERR_SVR_GROUP_PERMISSION_DENY:
                                                    case BaseConstants.ERR_SVR_GROUP_INVALID_REQ:
                                                    case BaseConstants.ERR_SVR_GROUP_SUPER_NOT_ALLOW_QUIT:
                                                    case BaseConstants.ERR_SVR_GROUP_INVALID_ID:
                                                    case BaseConstants.ERR_SVR_GROUP_ALLREADY_MEMBER:
                                                        i13 = 7;
                                                        break;
                                                    case 10003:
                                                    case 10004:
                                                    case 10005:
                                                    case BaseConstants.ERR_SVR_GROUP_FREQ_LIMIT:
                                                    case BaseConstants.ERR_SVR_GROUP_NOT_FOUND:
                                                    case BaseConstants.ERR_SVR_GROUP_JSON_PARSE_FAILED:
                                                    case BaseConstants.ERR_SVR_GROUP_FULL_MEMBER_COUNT:
                                                    case BaseConstants.ERR_SVR_GROUP_INVALID_GROUPID:
                                                    case BaseConstants.ERR_SVR_GROUP_REJECT_FROM_THIRDPARTY:
                                                    case BaseConstants.ERR_SVR_GROUP_SHUTUP_DENY:
                                                        i13 = 4;
                                                        break;
                                                    default:
                                                        switch (a10) {
                                                            case 20000:
                                                            case 20001:
                                                            case 20002:
                                                                i13 = 1;
                                                                break;
                                                            case 20003:
                                                            default:
                                                                i13 = 8;
                                                                break;
                                                        }
                                                }
                                            } else {
                                                i13 = a10;
                                            }
                                            if (i13 != 0) {
                                                i12 = 0;
                                                try {
                                                    l(str2, i13, "searchErrCode is " + i13, new String[0]);
                                                } catch (Throwable th3) {
                                                    th = th3;
                                                    i10 = i12;
                                                    str = str4;
                                                    l2.h(th, "GeoFenceManager", "doAddGeoFenceNearby");
                                                    bundle2.putInt(str, 8);
                                                    g(1000, bundle2);
                                                    return;
                                                }
                                            }
                                            i10 = i13;
                                        } else if (arrayList2.isEmpty()) {
                                            i10 = 16;
                                        } else {
                                            i10 = b(arrayList2);
                                            if (i10 == 0) {
                                                try {
                                                    arrayList.addAll(arrayList2);
                                                } catch (Throwable th4) {
                                                    th = th4;
                                                    str = str4;
                                                    l2.h(th, "GeoFenceManager", "doAddGeoFenceNearby");
                                                    bundle2.putInt(str, 8);
                                                    g(1000, bundle2);
                                                    return;
                                                }
                                            } else {
                                                i15 = i10;
                                            }
                                        }
                                    }
                                    i10 = i15;
                                } catch (Throwable th5) {
                                    th = th5;
                                    str = str4;
                                    i10 = 0;
                                    l2.h(th, "GeoFenceManager", "doAddGeoFenceNearby");
                                    bundle2.putInt(str, 8);
                                    g(1000, bundle2);
                                    return;
                                }
                            } catch (Throwable th6) {
                                th = th6;
                                i12 = 0;
                            }
                        } else {
                            str3 = GeoFence.BUNDLE_KEY_CUSTOMID;
                            str4 = "errorCode";
                            i10 = 1;
                        }
                        bundle2.putString(str3, string);
                        bundle2.putParcelableArrayList("resultList", arrayList);
                        i11 = i10;
                        bundle2.putInt(str4, i11);
                        g(1000, bundle2);
                    }
                } catch (Throwable th7) {
                    th = th7;
                    i10 = 0;
                    str = "errorCode";
                }
            }
            str4 = "errorCode";
            i11 = 1;
            bundle2.putInt(str4, i11);
            g(1000, bundle2);
        } catch (Throwable th8) {
            th = th8;
            str = "errorCode";
            i10 = 0;
        }
    }

    private static boolean v(AMapLocation aMapLocation, GeoFence geoFence) {
        boolean z9 = true;
        try {
            if (!n(aMapLocation, geoFence)) {
                if (geoFence.getStatus() != 2) {
                    try {
                        geoFence.setStatus(2);
                        geoFence.setEnterTime(-1L);
                    } catch (Throwable th) {
                        th = th;
                        l2.h(th, "Utils", "isFenceStatusChanged");
                        return z9;
                    }
                }
                z9 = false;
            } else if (geoFence.getEnterTime() == -1) {
                if (geoFence.getStatus() != 1) {
                    geoFence.setEnterTime(t2.y());
                    geoFence.setStatus(1);
                }
                z9 = false;
            } else {
                if (geoFence.getStatus() != 3 && t2.y() - geoFence.getEnterTime() > 600000) {
                    geoFence.setStatus(3);
                }
                z9 = false;
            }
        } catch (Throwable th2) {
            th = th2;
            z9 = false;
        }
        return z9;
    }

    final void B(Bundle bundle) {
        t(1, bundle);
    }

    final void D(Bundle bundle) {
        t(3, bundle);
    }

    final void F(Bundle bundle) {
        if (bundle != null) {
            try {
                if (bundle.isEmpty()) {
                    return;
                }
                String string = bundle.getString("fid");
                if (TextUtils.isEmpty(string)) {
                    return;
                }
                boolean z9 = true;
                boolean z10 = bundle.getBoolean("ab", true);
                ArrayList<GeoFence> arrayList = this.f14509h;
                if (arrayList != null && !arrayList.isEmpty()) {
                    Iterator<GeoFence> it2 = this.f14509h.iterator();
                    while (true) {
                        if (!it2.hasNext()) {
                            break;
                        }
                        GeoFence next = it2.next();
                        if (next.getFenceId().equals(string)) {
                            next.setAble(z10);
                            break;
                        }
                    }
                }
                if (z10) {
                    C();
                    return;
                }
                ArrayList<GeoFence> arrayList2 = this.f14509h;
                if (arrayList2 != null && !arrayList2.isEmpty()) {
                    Iterator<GeoFence> it3 = this.f14509h.iterator();
                    while (true) {
                        if (!it3.hasNext()) {
                            break;
                        } else if (it3.next().isAble()) {
                            z9 = false;
                            break;
                        }
                    }
                }
            } catch (Throwable th) {
                l2.h(th, "GeoFenceManager", "doSetGeoFenceAble");
            }
        }
    }

    final void G(Bundle bundle) {
        try {
            if (this.f14509h != null) {
                GeoFence geoFence = (GeoFence) bundle.getParcelable("fc");
                if (this.f14509h.contains(geoFence)) {
                    this.f14509h.remove(geoFence);
                }
                if (this.f14509h.size() <= 0) {
                    e();
                } else {
                    C();
                }
            }
        } catch (Throwable unused) {
        }
    }

    final void H(Bundle bundle) {
        if (bundle != null) {
            try {
                if (bundle.isEmpty()) {
                    return;
                }
                int i9 = bundle.getInt("errorCode");
                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.f14506e;
                if (geoFenceListener != null) {
                    geoFenceListener.onGeoFenceCreateFinished((ArrayList) parcelableArrayList.clone(), i9, string);
                }
                if (i9 == 0) {
                    C();
                }
            } catch (Throwable th) {
                l2.h(th, "GeoFenceManager", "resultAddGeoFenceFinished");
            }
        }
    }

    final void I(Bundle bundle) {
        try {
            if (this.f14520s != null) {
                long j9 = 2000;
                if (bundle != null && !bundle.isEmpty()) {
                    j9 = bundle.getLong("interval", 2000L);
                }
                this.f14523v.setOnceLocation(false);
                this.f14523v.setInterval(j9);
                this.f14520s.setLocationOption(this.f14523v);
                if (this.f14515n) {
                    return;
                }
                this.f14520s.stopLocation();
                this.f14520s.startLocation();
                this.f14515n = true;
            }
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManager", "doStartContinueLocation");
        }
    }

    @Override
    public void addDistrictGeoFence(String str, String str2) {
        try {
            A();
            Bundle bundle = new Bundle();
            bundle.putString("keyWords", str);
            bundle.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str2);
            h(4, bundle, 0L);
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManager", "addDistricetGeoFence");
        }
    }

    @Override
    public void addKeywordGeoFence(String str, String str2, String str3, int i9, String str4) {
        try {
            A();
            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);
            h(2, bundle, 0L);
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManager", "addKeywordGeoFence");
        }
    }

    @Override
    public void addNearbyGeoFence(String str, String str2, DPoint dPoint, float f9, int i9, String str3) {
        try {
            A();
            f9 = (f9 <= CropImageView.DEFAULT_ASPECT_RATIO || 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);
            h(3, bundle, 0L);
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManager", "addNearbyGeoFence");
        }
    }

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

    @Override
    public void addRoundGeoFence(DPoint dPoint, float f9, String str) {
        try {
            A();
            Bundle bundle = new Bundle();
            bundle.putParcelable("centerPoint", dPoint);
            bundle.putFloat("fenceRadius", f9);
            bundle.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
            h(0, bundle, 0L);
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManager", "addRoundGeoFence");
        }
    }

    @Override
    public PendingIntent createPendingIntent(String str) {
        synchronized (this.f14507f) {
            try {
                Intent intent = new Intent(str);
                intent.setPackage(c3.g(this.f14503b));
                this.f14504c = PendingIntent.getBroadcast(this.f14503b, 0, intent, 0);
                this.f14505d = str;
                ArrayList<GeoFence> arrayList = this.f14509h;
                if (arrayList != null && !arrayList.isEmpty()) {
                    Iterator<GeoFence> it2 = this.f14509h.iterator();
                    while (it2.hasNext()) {
                        GeoFence next = it2.next();
                        next.setPendingIntent(this.f14504c);
                        next.setPendingIntentAction(this.f14505d);
                    }
                }
            }
        }
        return this.f14504c;
    }

    final void e() {
        if (this.f14516o) {
            ArrayList<GeoFence> arrayList = this.f14509h;
            if (arrayList != null) {
                arrayList.clear();
                this.f14509h = null;
            }
            if (this.f14517p) {
                return;
            }
            synchronized (this.f14511j) {
                b bVar = this.f14513l;
                if (bVar != null) {
                    bVar.removeCallbacksAndMessages(null);
                }
                this.f14513l = null;
            }
            AMapLocationClient aMapLocationClient = this.f14520s;
            if (aMapLocationClient != null) {
                aMapLocationClient.stopLocation();
                this.f14520s.onDestroy();
            }
            this.f14520s = null;
            c cVar = this.f14514m;
            if (cVar != null) {
                if (Build.VERSION.SDK_INT >= 18) {
                    cVar.quitSafely();
                } else {
                    cVar.quit();
                }
            }
            this.f14514m = null;
            this.f14518q = null;
            synchronized (this.f14507f) {
                PendingIntent pendingIntent = this.f14504c;
                if (pendingIntent != null) {
                    pendingIntent.cancel();
                }
                this.f14504c = null;
            }
            synchronized (this.f14512k) {
                d dVar = this.f14510i;
                if (dVar != null) {
                    dVar.removeCallbacksAndMessages(null);
                }
                this.f14510i = null;
            }
            q2 q2Var = this.f14502a;
            if (q2Var != null) {
                q2Var.s(this.f14503b);
            }
            this.f14515n = false;
            this.f14516o = false;
        }
    }

    final void f(int i9) {
        try {
            synchronized (this.f14511j) {
                b bVar = this.f14513l;
                if (bVar != null) {
                    bVar.removeMessages(i9);
                }
            }
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManager", "removeActionHandlerMessage");
        }
    }

    final void g(int i9, Bundle bundle) {
        try {
            synchronized (this.f14512k) {
                d dVar = this.f14510i;
                if (dVar != null) {
                    Message obtainMessage = dVar.obtainMessage();
                    obtainMessage.what = i9;
                    obtainMessage.setData(bundle);
                    this.f14510i.sendMessage(obtainMessage);
                }
            }
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManager", "sendResultHandlerMessage");
        }
    }

    @Override
    public List<GeoFence> getAllGeoFence() {
        try {
            if (this.f14509h == null) {
                this.f14509h = new ArrayList<>();
            }
            return (ArrayList) this.f14509h.clone();
        } catch (Throwable unused) {
            return new ArrayList();
        }
    }

    final void h(int i9, Bundle bundle, long j9) {
        try {
            synchronized (this.f14511j) {
                b bVar = this.f14513l;
                if (bVar != null) {
                    Message obtainMessage = bVar.obtainMessage();
                    obtainMessage.what = i9;
                    obtainMessage.setData(bundle);
                    this.f14513l.sendMessageDelayed(obtainMessage, j9);
                }
            }
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManager", "sendActionHandlerMessage");
        }
    }

    final void i(Bundle bundle) {
        int i9 = 1;
        if (bundle != null) {
            try {
                i9 = bundle.getInt("activatesAction", 1);
            } catch (Throwable th) {
                l2.h(th, "GeoFenceManager", "doSetActivatesAction");
                return;
            }
        }
        if (this.f14508g != i9) {
            ArrayList<GeoFence> arrayList = this.f14509h;
            if (arrayList != null && !arrayList.isEmpty()) {
                Iterator<GeoFence> it2 = this.f14509h.iterator();
                while (it2.hasNext()) {
                    GeoFence next = it2.next();
                    next.setStatus(0);
                    next.setEnterTime(-1L);
                }
            }
            C();
        }
        this.f14508g = i9;
    }

    @Override
    public boolean isPause() {
        return this.f14527z;
    }

    final void j(GeoFence geoFence) {
        PendingIntent pendingIntent;
        Context context;
        try {
            synchronized (this.f14507f) {
                if (this.f14503b != null) {
                    if (this.f14504c == null && geoFence.getPendingIntent() == null) {
                        return;
                    }
                    Intent intent = new Intent();
                    intent.putExtras(c(geoFence, geoFence.getFenceId(), geoFence.getCustomId(), geoFence.getStatus(), 0));
                    String str = this.f14505d;
                    if (str != null) {
                        intent.setAction(str);
                    }
                    intent.setPackage(c3.g(this.f14503b));
                    if (geoFence.getPendingIntent() != null) {
                        pendingIntent = geoFence.getPendingIntent();
                        context = this.f14503b;
                    } else {
                        pendingIntent = this.f14504c;
                        context = this.f14503b;
                    }
                    pendingIntent.send(context, 0, intent);
                }
            }
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManager", "resultTriggerGeoFence");
        }
    }

    final void k(AMapLocation aMapLocation) {
        ArrayList<GeoFence> arrayList;
        try {
            if (this.f14527z || (arrayList = this.f14509h) == null || arrayList.isEmpty() || aMapLocation == null || aMapLocation.getErrorCode() != 0) {
                return;
            }
            Iterator<GeoFence> it2 = this.f14509h.iterator();
            while (it2.hasNext()) {
                GeoFence next = it2.next();
                if (next.isAble() && v(aMapLocation, next) && m(next, this.f14508g)) {
                    next.setCurrentLocation(aMapLocation);
                    Bundle bundle = new Bundle();
                    bundle.putParcelable("geoFence", next);
                    g(1001, bundle);
                }
            }
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManager", "doCheckFence");
        }
    }

    @Override
    public void pauseGeoFence() {
        try {
            A();
            this.f14527z = true;
            h(13, null, 0L);
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManager", "pauseGeoFence");
        }
    }

    final void r() {
        try {
            if (this.f14520s != null) {
                E();
                this.f14523v.setOnceLocation(true);
                this.f14520s.setLocationOption(this.f14523v);
                this.f14520s.startLocation();
            }
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManager", "doStartOnceLocation");
        }
    }

    @Override
    public void removeGeoFence() {
        try {
            this.f14517p = false;
            h(10, null, 0L);
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManager", "removeGeoFence");
        }
    }

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

    @Override
    public void resumeGeoFence() {
        try {
            A();
            if (this.f14527z) {
                this.f14527z = false;
                C();
            }
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManager", "resumeGeoFence");
        }
    }

    final void s(int i9) {
        try {
            if (this.f14503b != null) {
                synchronized (this.f14507f) {
                    if (this.f14504c == null) {
                        return;
                    }
                    Intent intent = new Intent();
                    intent.putExtras(c(null, null, null, 4, i9));
                    this.f14504c.send(this.f14503b, 0, intent);
                }
            }
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManager", "resultRemindLocationError");
        }
    }

    @Override
    public void setActivateAction(int i9) {
        try {
            A();
            i9 = (i9 > 7 || i9 <= 0) ? 1 : 1;
            Bundle bundle = new Bundle();
            bundle.putInt("activatesAction", i9);
            h(9, bundle, 0L);
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManager", "setActivateAction");
        }
    }

    @Override
    public void setGeoFenceAble(String str, boolean z9) {
        try {
            A();
            Bundle bundle = new Bundle();
            bundle.putString("fid", str);
            bundle.putBoolean("ab", z9);
            h(12, bundle, 0L);
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManager", "setGeoFenceAble");
        }
    }

    @Override
    public void setGeoFenceListener(GeoFenceListener geoFenceListener) {
        try {
            this.f14506e = geoFenceListener;
        } catch (Throwable unused) {
        }
    }

    final void u(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 d10 = d(bundle, false);
                        i9 = p(d10);
                        if (i9 == 0) {
                            arrayList.add(d10);
                        }
                        Bundle bundle2 = new Bundle();
                        bundle2.putInt("errorCode", i9);
                        bundle2.putParcelableArrayList("resultList", arrayList);
                        bundle2.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
                        g(1000, bundle2);
                    }
                    l("添加围栏失败", 1, "经纬度错误,传入的纬度:" + dPoint.getLatitude() + "传入的经度:" + dPoint.getLongitude(), new String[0]);
                    Bundle bundle22 = new Bundle();
                    bundle22.putInt("errorCode", i9);
                    bundle22.putParcelableArrayList("resultList", arrayList);
                    bundle22.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
                    g(1000, bundle22);
                }
                str2 = str;
            }
            str = str2;
            Bundle bundle222 = new Bundle();
            bundle222.putInt("errorCode", i9);
            bundle222.putParcelableArrayList("resultList", arrayList);
            bundle222.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
            g(1000, bundle222);
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManager", "doAddGeoFenceRound");
        }
    }

    final void w() {
        float f9;
        float f10;
        try {
            if (!this.f14527z && t2.o(this.f14521t)) {
                AMapLocation aMapLocation = this.f14521t;
                ArrayList<GeoFence> arrayList = this.f14509h;
                if (aMapLocation == null || aMapLocation.getErrorCode() != 0 || arrayList == null || arrayList.isEmpty()) {
                    f9 = Float.MAX_VALUE;
                } else {
                    DPoint dPoint = new DPoint(aMapLocation.getLatitude(), aMapLocation.getLongitude());
                    f9 = Float.MAX_VALUE;
                    for (GeoFence geoFence : arrayList) {
                        if (geoFence.isAble()) {
                            float d10 = t2.d(dPoint, geoFence.getCenter());
                            if (d10 > geoFence.getMinDis2Center() && d10 < geoFence.getMaxDis2Center()) {
                                f10 = CropImageView.DEFAULT_ASPECT_RATIO;
                                break;
                            }
                            if (d10 > geoFence.getMaxDis2Center()) {
                                f9 = Math.min(f9, d10 - geoFence.getMaxDis2Center());
                            }
                            if (d10 < geoFence.getMinDis2Center()) {
                                f9 = Math.min(f9, geoFence.getMinDis2Center() - d10);
                            }
                        }
                    }
                }
                f10 = f9;
                if (f10 == Float.MAX_VALUE) {
                    return;
                }
                if (f10 < 1000.0f) {
                    f(7);
                    Bundle bundle = new Bundle();
                    bundle.putLong("interval", 2000L);
                    h(8, bundle, 500L);
                } else if (f10 < 5000.0f) {
                    E();
                    f(7);
                    h(7, null, 10000L);
                } else {
                    E();
                    f(7);
                    h(7, null, ((f10 - 4000.0f) / 100.0f) * 1000.0f);
                }
            }
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManager", "doCheckLocationPolicy");
        }
    }

    final void x(Bundle bundle) {
        GeoFence d10;
        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 = p((d10 = d(bundle, true)))) == 0) {
                    arrayList.add(d10);
                }
                str = string;
            }
            Bundle bundle2 = new Bundle();
            bundle2.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
            bundle2.putInt("errorCode", i9);
            bundle2.putParcelableArrayList("resultList", arrayList);
            g(1000, bundle2);
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManager", "doAddGeoFencePolygon");
        }
    }

    final void y() {
        try {
            f(7);
            f(8);
            AMapLocationClient aMapLocationClient = this.f14520s;
            if (aMapLocationClient != null) {
                aMapLocationClient.stopLocation();
            }
            this.f14515n = false;
        } catch (Throwable th) {
            l2.h(th, "GeoFenceManager", "doPauseGeoFence");
        }
    }

    final void z(Bundle bundle) {
        t(2, bundle);
    }
}