米多多 v3.0.1版本的 MD5 值为:f69e79dbe1787218a397ad907fb8f3ab

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


package c.i;

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 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 java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@SuppressLint({"NewApi"})
public class a implements GeoFenceManagerBase {
    public Context f5136b;
    public x1 f5135a = null;
    public PendingIntent f5137c = null;
    public String f5138d = null;
    public GeoFenceListener f5139e = null;
    public volatile int f5140f = 1;
    public ArrayList<GeoFence> f5141g = new ArrayList<>();
    public d f5142h = null;
    public Object f5143i = new Object();
    public b f5144j = null;
    public c f5145k = null;
    public volatile boolean l = false;
    public volatile boolean m = false;
    public b0 n = null;
    public c1 o = null;
    public AMapLocationClient p = null;
    public volatile AMapLocation q = null;
    public long r = 0;
    public AMapLocationClientOption s = null;
    public int t = 0;
    public AMapLocationListener u = new C0134a();

    public class C0134a implements AMapLocationListener {
        public C0134a() {
        }

        @Override
        public final void onLocationChanged(AMapLocation aMapLocation) {
            boolean z;
            int i2;
            try {
                a.this.q = aMapLocation;
                if (aMapLocation != null) {
                    i2 = aMapLocation.getErrorCode();
                    if (aMapLocation.getErrorCode() == 0) {
                        a.this.r = a2.z();
                        a.this.h(5, null, 0L);
                        z = true;
                    } else {
                        a.l("定位失败", aMapLocation.getErrorCode(), aMapLocation.getErrorInfo(), "locationDetail:" + aMapLocation.getLocationDetail());
                        z = false;
                    }
                } else {
                    z = false;
                    i2 = 8;
                }
                if (z) {
                    a.this.t = 0;
                    a.this.h(6, null, 0L);
                    return;
                }
                Bundle bundle = new Bundle();
                if (!a.this.l) {
                    a.this.f(7);
                    bundle.putLong("interval", 2000L);
                    a.this.h(8, bundle, 2000L);
                }
                a.this.t++;
                if (a.this.t >= 3) {
                    bundle.putInt(GeoFence.BUNDLE_KEY_LOCERRORCODE, i2);
                    a.this.g(1002, bundle);
                }
            } 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.y(message.getData());
                        return;
                    case 2:
                        a.this.B(message.getData());
                        return;
                    case 3:
                        a.this.A(message.getData());
                        return;
                    case 4:
                        a.this.D(message.getData());
                        return;
                    case 5:
                        a.this.s();
                        return;
                    case 6:
                        a.this.k(a.this.q);
                        return;
                    case 7:
                        a.this.e();
                        return;
                    case 8:
                        a.this.F(message.getData());
                        return;
                    case 9:
                        a.this.i(message.getData());
                        return;
                    default:
                        return;
                }
            } catch (Throwable unused) {
            }
        }
    }

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

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

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

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

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

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

    public static Bundle c(GeoFence geoFence, String str, String str2, int i2, int i3) {
        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, i2);
        bundle.putInt(GeoFence.BUNDLE_KEY_LOCERRORCODE, i3);
        bundle.putParcelable(GeoFence.BUNDLE_KEY_FENCE, geoFence);
        return bundle;
    }

    public static void l(String str, int i2, String str2, String... strArr) {
        Log.i("fenceErrLog", "===========================================");
        Log.i("fenceErrLog", "              " + str + "                ");
        Log.i("fenceErrLog", "===========================================");
        Log.i("fenceErrLog", "errorCode:" + i2);
        Log.i("fenceErrLog", "错误信息:" + str2);
        if (strArr != null && strArr.length > 0) {
            for (String str3 : strArr) {
                Log.i("fenceErrLog", str3);
            }
        }
        Log.i("fenceErrLog", "===========================================");
    }

    public static boolean m(double d2, double d3, double d4, double d5, double d6, double d7) {
        return Math.abs(((d4 - d2) * (d7 - d3)) - ((d6 - d2) * (d5 - d3))) < 1.0E-9d && (d2 - d4) * (d2 - d6) <= 0.0d && (d3 - d5) * (d3 - d7) <= 0.0d;
    }

    public static boolean n(GeoFence geoFence, int i2) {
        boolean z = true;
        boolean z2 = false;
        if ((i2 & 1) == 1) {
            try {
                if (geoFence.getStatus() == 1) {
                    z2 = true;
                }
            } catch (Throwable th) {
                e2.h(th, "Utils", "remindStatus");
                return z2;
            }
        }
        if ((i2 & 2) == 2 && geoFence.getStatus() == 2) {
            z2 = true;
        }
        if ((i2 & 4) == 4) {
        }
        z = z2;
        return z;
    }

    public static boolean o(AMapLocation aMapLocation, GeoFence geoFence) {
        boolean z;
        boolean z2;
        boolean z3 = false;
        try {
            if (a2.q(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 z4 = false;
                    for (List<DPoint> list : geoFence.getPointList()) {
                        try {
                            double longitude = aMapLocation.getLongitude();
                            double latitude = aMapLocation.getLatitude();
                            double latitude2 = aMapLocation.getLatitude();
                            if (list.size() >= 3) {
                                if (!list.get(0).equals(list.get(list.size() - 1))) {
                                    list.add(list.get(0));
                                }
                                int i2 = 0;
                                int i3 = 0;
                                while (true) {
                                    if (i2 < list.size() - 1) {
                                        double longitude2 = list.get(i2).getLongitude();
                                        double latitude3 = list.get(i2).getLatitude();
                                        int i4 = i2 + 1;
                                        double longitude3 = list.get(i4).getLongitude();
                                        double latitude4 = list.get(i4).getLatitude();
                                        if (m(longitude, latitude, longitude2, latitude3, longitude3, latitude4)) {
                                            break;
                                        }
                                        double d2 = latitude4 - latitude3;
                                        if (Math.abs(d2) >= 1.0E-9d) {
                                            if (m(longitude2, latitude3, longitude, latitude, 180.0d, latitude2)) {
                                                if (latitude3 <= latitude4) {
                                                }
                                                i3++;
                                            } else if (!m(longitude3, latitude4, longitude, latitude, 180.0d, latitude2)) {
                                                double d3 = longitude3 - longitude2;
                                                double d4 = latitude2 - latitude;
                                                double d5 = 180.0d - longitude;
                                                double d6 = (d3 * d4) - (d2 * d5);
                                                if (d6 != 0.0d) {
                                                    double d7 = latitude3 - latitude;
                                                    double d8 = longitude2 - longitude;
                                                    double d9 = ((d5 * d7) - (d4 * d8)) / d6;
                                                    double d10 = ((d7 * d3) - (d8 * d2)) / d6;
                                                    if (d9 >= 0.0d && d9 <= 1.0d && d10 >= 0.0d && d10 <= 1.0d) {
                                                        z2 = true;
                                                        if (!z2) {
                                                            i3++;
                                                        }
                                                    }
                                                }
                                                z2 = false;
                                                if (!z2) {
                                                }
                                            } else if (latitude4 > latitude3) {
                                                i3++;
                                            }
                                        }
                                        i2 = i4;
                                    }
                                }
                                z = true;
                                if (!z) {
                                    z4 = true;
                                }
                            }
                            z = false;
                            if (!z) {
                            }
                        } catch (Throwable th) {
                            th = th;
                            z3 = z4;
                            e2.h(th, "Utils", "isInGeoFence");
                            return z3;
                        }
                    }
                    z3 = z4;
                }
                DPoint center = geoFence.getCenter();
                if (a2.e(new double[]{center.getLatitude(), center.getLongitude(), aMapLocation.getLatitude(), aMapLocation.getLongitude()}) <= geoFence.getRadius()) {
                    return true;
                }
            }
        } catch (Throwable th2) {
            th = th2;
        }
        return z3;
    }

    public static float p(DPoint dPoint, List<DPoint> list) {
        float f2 = Float.MIN_VALUE;
        if (dPoint != null && list != null && !list.isEmpty()) {
            for (DPoint dPoint2 : list) {
                f2 = Math.max(f2, a2.d(dPoint, dPoint2));
            }
        }
        return f2;
    }

    public static DPoint r(List<DPoint> list) {
        DPoint dPoint = new DPoint();
        if (list != null) {
            try {
                double d2 = 0.0d;
                double d3 = 0.0d;
                for (DPoint dPoint2 : list) {
                    d2 += dPoint2.getLatitude();
                    d3 += dPoint2.getLongitude();
                }
                return new DPoint(a2.J(d2 / list.size()), a2.J(d3 / list.size()));
            } catch (Throwable th) {
                e2.h(th, "GeoFenceUtil", "getPolygonCenter");
                return dPoint;
            }
        }
        return dPoint;
    }

    public static boolean v(AMapLocation aMapLocation, GeoFence geoFence) {
        boolean z = true;
        try {
            if (!o(aMapLocation, geoFence)) {
                if (geoFence.getStatus() != 2) {
                    try {
                        geoFence.setStatus(2);
                        geoFence.setEnterTime(-1L);
                    } catch (Throwable th) {
                        th = th;
                        e2.h(th, "Utils", "isFenceStatusChanged");
                        return z;
                    }
                }
                z = false;
            } else if (geoFence.getEnterTime() == -1) {
                if (geoFence.getStatus() != 1) {
                    geoFence.setEnterTime(a2.z());
                    geoFence.setStatus(1);
                }
                z = false;
            } else {
                if (geoFence.getStatus() != 3 && a2.z() - geoFence.getEnterTime() > 600000) {
                    geoFence.setStatus(3);
                }
                z = false;
            }
        } catch (Throwable th2) {
            th = th2;
            z = false;
        }
        return z;
    }

    public static int w(int i2) {
        int i3 = 8;
        switch (i2) {
            case 10000:
                i3 = 0;
                break;
            case 10001:
            case 10002:
            case 10007:
            case 10008:
            case 10009:
            case 10012:
            case 10013:
                i3 = 7;
                break;
            case 10003:
            case 10004:
            case 10005:
            case 10006:
            case 10010:
            case 10011:
            case 10014:
            case 10015:
            case 10016:
            case 10017:
                i3 = 4;
                break;
            default:
                switch (i2) {
                    case 20000:
                    case 20001:
                    case 20002:
                        i3 = 1;
                        break;
                }
        }
        if (i3 != 0) {
            l("添加围栏失败", i3, "searchErrCode is " + i3, new String[0]);
        }
        return i3;
    }

    public final void A(Bundle bundle) {
        int w;
        try {
            String str = "";
            ArrayList<? extends Parcelable> arrayList = new ArrayList<>();
            int i2 = 1;
            if (bundle != null && !bundle.isEmpty()) {
                String string = bundle.getString("keyword");
                String string2 = bundle.getString("poiType");
                DPoint dPoint = (DPoint) bundle.getParcelable("centerPoint");
                float f2 = bundle.getFloat("aroundRadius", 3000.0f);
                int i3 = bundle.getInt("size", 10);
                String string3 = bundle.getString(GeoFence.BUNDLE_KEY_CUSTOMID);
                if (dPoint != null && !TextUtils.isEmpty(string)) {
                    if (dPoint.getLatitude() <= 90.0d && dPoint.getLatitude() >= -90.0d && dPoint.getLongitude() <= 180.0d && dPoint.getLongitude() >= -180.0d) {
                        String c2 = this.n.c(this.f5136b, "http://restapi.amap.com/v3/place/around?", string, string2, String.valueOf(i3), String.valueOf(a2.J(dPoint.getLatitude())), String.valueOf(a2.J(dPoint.getLongitude())), String.valueOf(Float.valueOf(f2).intValue()));
                        if (c2 != null) {
                            List<GeoFence> arrayList2 = new ArrayList<>();
                            Bundle bundle2 = new Bundle();
                            bundle2.putString(GeoFence.BUNDLE_KEY_CUSTOMID, string3);
                            bundle2.putString("pendingIntentAction", this.f5138d);
                            bundle2.putLong("expiration", -1L);
                            bundle2.putInt("activatesAction", this.f5140f);
                            bundle2.putFloat("geoRadius", 200.0f);
                            int d2 = c1.d(c2, arrayList2, bundle2);
                            if (d2 != 10000) {
                                w = w(d2);
                            } else if (arrayList2.isEmpty()) {
                                i2 = 16;
                            } else {
                                w = b(arrayList2);
                                if (w == 0) {
                                    arrayList.addAll(arrayList2);
                                }
                            }
                            i2 = w;
                        } else {
                            i2 = 4;
                        }
                    }
                    l("添加围栏失败", 1, "经纬度错误,传入的纬度:" + dPoint.getLatitude() + "传入的经度:" + dPoint.getLongitude(), new String[0]);
                }
                str = string3;
            }
            Bundle bundle3 = new Bundle();
            bundle3.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
            bundle3.putInt("errorCode", i2);
            bundle3.putParcelableArrayList("resultList", arrayList);
            g(1000, bundle3);
        } catch (Throwable th) {
            e2.h(th, "GeoFenceManager", "doAddGeoFence_nearby");
        }
    }

    public final void B(Bundle bundle) {
        try {
            String str = "";
            ArrayList<? extends Parcelable> arrayList = new ArrayList<>();
            int i2 = 1;
            if (bundle != null && !bundle.isEmpty()) {
                String string = bundle.getString("keyword");
                String string2 = bundle.getString("poiType");
                String string3 = bundle.getString("city");
                int i3 = bundle.getInt("size", 10);
                String string4 = bundle.getString(GeoFence.BUNDLE_KEY_CUSTOMID);
                Bundle bundle2 = new Bundle();
                bundle2.putString(GeoFence.BUNDLE_KEY_CUSTOMID, string4);
                bundle2.putString("pendingIntentAction", this.f5138d);
                bundle2.putLong("expiration", -1L);
                bundle2.putInt("activatesAction", this.f5140f);
                bundle2.putFloat("geoRadius", 1000.0f);
                String b2 = this.n.b(this.f5136b, "http://restapi.amap.com/v3/place/text?", string, string2, string3, String.valueOf(i3));
                if (!TextUtils.isEmpty(string) && !TextUtils.isEmpty(string2)) {
                    if (b2 != null) {
                        List<GeoFence> arrayList2 = new ArrayList<>();
                        int a2 = c1.a(b2, arrayList2, bundle2);
                        if (a2 != 10000) {
                            i2 = w(a2);
                        } else if (arrayList2.isEmpty()) {
                            i2 = 16;
                        } else {
                            i2 = b(arrayList2);
                            if (i2 == 0) {
                                arrayList.addAll(arrayList2);
                            }
                        }
                    } else {
                        i2 = 4;
                    }
                }
                str = string4;
            }
            Bundle bundle3 = new Bundle();
            bundle3.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
            bundle3.putInt("errorCode", i2);
            bundle3.putParcelableArrayList("resultList", arrayList);
            g(1000, bundle3);
        } catch (Throwable th) {
            e2.h(th, "GeoFenceManager", "doAddGeoFence_Keyword");
        }
    }

    public final boolean C() {
        return this.q != null && a2.q(this.q) && a2.z() - this.r < 10000;
    }

    public final void D(Bundle bundle) {
        String str;
        int i2;
        try {
            ArrayList<? extends Parcelable> arrayList = new ArrayList<>();
            String str2 = "";
            if (bundle != null && !bundle.isEmpty()) {
                String string = bundle.getString("keyword");
                str = bundle.getString(GeoFence.BUNDLE_KEY_CUSTOMID);
                String a2 = this.n.a(this.f5136b, "http://restapi.amap.com/v3/config/district?", string);
                if (!TextUtils.isEmpty(string)) {
                    if (a2 != null) {
                        Bundle bundle2 = new Bundle();
                        bundle2.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
                        bundle2.putString("pendingIntentAction", this.f5138d);
                        bundle2.putLong("expiration", -1L);
                        bundle2.putInt("activatesAction", this.f5140f);
                        ArrayList arrayList2 = new ArrayList();
                        int e2 = this.o.e(a2, arrayList2, bundle2);
                        if (e2 != 10000) {
                            i2 = w(e2);
                        } else if (arrayList2.isEmpty()) {
                            i2 = 16;
                        } else {
                            i2 = b(arrayList2);
                            if (i2 == 0) {
                                arrayList.addAll(arrayList2);
                            }
                        }
                    } else {
                        i2 = 4;
                    }
                    Bundle bundle3 = new Bundle();
                    bundle3.putInt("errorCode", i2);
                    bundle3.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
                    bundle3.putParcelableArrayList("resultList", arrayList);
                    g(1000, bundle3);
                }
                str2 = str;
            }
            str = str2;
            i2 = 1;
            Bundle bundle32 = new Bundle();
            bundle32.putInt("errorCode", i2);
            bundle32.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
            bundle32.putParcelableArrayList("resultList", arrayList);
            g(1000, bundle32);
        } catch (Throwable th) {
            e2.h(th, "GeoFenceManager", "doAddGeoFence_district");
        }
    }

    public final void E(Bundle bundle) {
        if (bundle != null) {
            try {
                if (bundle.isEmpty()) {
                    return;
                }
                int i2 = bundle.getInt("errorCode");
                ArrayList parcelableArrayList = bundle.getParcelableArrayList("resultList");
                String string = bundle.getString(GeoFence.BUNDLE_KEY_CUSTOMID);
                if (string == null) {
                    string = "";
                }
                if (this.f5139e != null) {
                    this.f5139e.onGeoFenceCreateFinished(parcelableArrayList, i2, string);
                }
                if (i2 != 0 || this.f5144j == null) {
                    return;
                }
                if (!C()) {
                    f(7);
                    h(7, null, 1000L);
                    return;
                }
                new Bundle().putParcelable("loc", this.q);
                h(6, null, 0L);
                h(5, bundle, 0L);
            } catch (Throwable th) {
                e2.h(th, "GeoFenceManager", "resultAddGeoFenceFinished");
            }
        }
    }

    public final void F(Bundle bundle) {
        try {
            if (this.p != null) {
                long j2 = 2000;
                if (bundle != null && !bundle.isEmpty()) {
                    j2 = bundle.getLong("interval");
                }
                this.s.setOnceLocation(false);
                this.s.setInterval(j2);
                this.p.setLocationOption(this.s);
                if (this.l) {
                    return;
                }
                this.p.stopLocation();
                this.p.startLocation();
                this.l = true;
            }
        } catch (Throwable th) {
            e2.h(th, "GeoFenceManager", "doStartContinueLocation");
        }
    }

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

    @Override
    public void addKeywordGeoFence(String str, String str2, String str3, int i2, String str4) {
        try {
            x();
            if (i2 <= 0) {
                i2 = 10;
            }
            if (i2 > 25) {
                i2 = 25;
            }
            Bundle bundle = new Bundle();
            bundle.putString("keyword", str);
            bundle.putString("poiType", str2);
            bundle.putString("city", str3);
            bundle.putInt("size", i2);
            bundle.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str4);
            h(2, bundle, 0L);
        } catch (Throwable th) {
            e2.h(th, "GeoFenceManager", "addKeywordGeoFence");
        }
    }

    @Override
    public void addNearbyGeoFence(String str, String str2, DPoint dPoint, float f2, int i2, String str3) {
        try {
            x();
            f2 = (f2 <= 0.0f || f2 > 50000.0f) ? 3000.0f : 3000.0f;
            if (i2 <= 0) {
                i2 = 10;
            }
            if (i2 > 25) {
                i2 = 25;
            }
            Bundle bundle = new Bundle();
            bundle.putString("keyword", str);
            bundle.putString("poiType", str2);
            bundle.putParcelable("centerPoint", dPoint);
            bundle.putFloat("aroundRadius", f2);
            bundle.putInt("size", i2);
            bundle.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str3);
            h(3, bundle, 0L);
        } catch (Throwable th) {
            e2.h(th, "GeoFenceManager", "addNearbyGeoFence");
        }
    }

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

    @Override
    public void addRoundGeoFence(DPoint dPoint, float f2, String str, String str2, long j2, PendingIntent pendingIntent) {
        try {
            x();
            if (f2 <= 0.0f) {
                f2 = 1000.0f;
            }
            Bundle bundle = new Bundle();
            bundle.putParcelable("point", dPoint);
            bundle.putFloat("radius", f2);
            bundle.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
            bundle.putString(GeoFence.BUNDLE_KEY_FENCEID, str2);
            bundle.putLong("expiration", j2);
            bundle.putParcelable("pIntent", pendingIntent);
            h(0, bundle, 0L);
        } catch (Throwable th) {
            e2.h(th, "GeoFenceManager", "addRoundGeoFence");
        }
    }

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

    @Override
    public PendingIntent createPendingIntent(String str) {
        try {
            x();
            Intent intent = new Intent();
            intent.setPackage(i2.e(this.f5136b));
            intent.setAction(str);
            this.f5137c = PendingIntent.getBroadcast(this.f5136b, 0, intent, 0);
            this.f5138d = str;
            if (this.f5141g != null && !this.f5141g.isEmpty()) {
                Iterator<GeoFence> it = this.f5141g.iterator();
                while (it.hasNext()) {
                    GeoFence next = it.next();
                    next.setPendingIntent(this.f5137c);
                    next.setPendingIntentAction(this.f5138d);
                }
            }
        } catch (Throwable th) {
            e2.h(th, "GeoFenceManager", "createPendingIntent");
        }
        return this.f5137c;
    }

    public final GeoFence d(Bundle bundle, boolean z) {
        String str;
        GeoFence geoFence = new GeoFence();
        ArrayList arrayList = new ArrayList();
        DPoint dPoint = new DPoint();
        if (z) {
            geoFence.setType(1);
            arrayList = bundle.getParcelableArrayList("points");
            if (arrayList != null) {
                dPoint = r(arrayList);
            }
            geoFence.setMaxDis2Center(p(dPoint, arrayList));
            geoFence.setMinDis2Center(a(dPoint, arrayList));
        } else {
            geoFence.setType(0);
            dPoint = (DPoint) bundle.getParcelable("point");
            if (dPoint != null) {
                arrayList.add(dPoint);
            }
            float f2 = bundle.getFloat("radius", 1000.0f);
            geoFence.setRadius(f2);
            geoFence.setMinDis2Center(f2);
            geoFence.setMaxDis2Center(f2);
        }
        geoFence.setActivatesAction(this.f5140f);
        geoFence.setCustomId(bundle.getString(GeoFence.BUNDLE_KEY_CUSTOMID));
        ArrayList arrayList2 = new ArrayList();
        arrayList2.add(arrayList);
        geoFence.setPointList(arrayList2);
        geoFence.setCenter(dPoint);
        long j2 = -1;
        PendingIntent pendingIntent = null;
        try {
            str = bundle.getString(GeoFence.BUNDLE_KEY_FENCEID);
            try {
                j2 = bundle.getLong("expiration", -1L);
                pendingIntent = (PendingIntent) bundle.getParcelable("pIntent");
            } catch (Throwable unused) {
            }
        } catch (Throwable unused2) {
            str = null;
        }
        if (TextUtils.isEmpty(str)) {
            StringBuilder sb = new StringBuilder();
            sb.append(c1.b());
            geoFence.setFenceId(sb.toString());
        } else {
            geoFence.setFenceId(str);
        }
        geoFence.setPendingIntentAction(this.f5138d);
        geoFence.setExpiration(j2);
        if (pendingIntent != null) {
            geoFence.setPendingIntent(pendingIntent);
        } else {
            geoFence.setPendingIntent(this.f5137c);
        }
        x1 x1Var = this.f5135a;
        if (x1Var != null) {
            x1Var.b(this.f5136b, 2);
        }
        return geoFence;
    }

    public final void e() {
        try {
            if (this.p != null) {
                try {
                    if (this.l) {
                        f(8);
                    }
                    if (this.p != null) {
                        this.p.stopLocation();
                    }
                    this.l = false;
                } catch (Throwable unused) {
                }
                this.s.setOnceLocation(true);
                this.p.setLocationOption(this.s);
                this.p.startLocation();
            }
        } catch (Throwable th) {
            e2.h(th, "GeoFenceManager", "doStartOnceLocation");
        }
    }

    public final void f(int i2) {
        try {
            synchronized (this.f5143i) {
                if (this.f5144j != null) {
                    this.f5144j.removeMessages(i2);
                }
            }
        } catch (Throwable th) {
            e2.h(th, "GeoFenceManager", "removeActionHandlerMessage");
        }
    }

    public final void g(int i2, Bundle bundle) {
        try {
            if (this.f5142h != null) {
                Message obtainMessage = this.f5142h.obtainMessage();
                obtainMessage.what = i2;
                obtainMessage.setData(bundle);
                this.f5142h.sendMessage(obtainMessage);
            }
        } catch (Throwable th) {
            e2.h(th, "GeoFenceManager", "sendResultHandlerMessage");
        }
    }

    @Override
    public List<GeoFence> getAllGeoFence() {
        if (this.f5141g == null) {
            this.f5141g = new ArrayList<>();
        }
        return (ArrayList) this.f5141g.clone();
    }

    public final void h(int i2, Bundle bundle, long j2) {
        try {
            synchronized (this.f5143i) {
                if (this.f5144j != null) {
                    Message obtainMessage = this.f5144j.obtainMessage();
                    obtainMessage.what = i2;
                    obtainMessage.setData(bundle);
                    this.f5144j.sendMessageDelayed(obtainMessage, j2);
                }
            }
        } catch (Throwable th) {
            e2.h(th, "GeoFenceManager", "sendActionHandlerMessage");
        }
    }

    public final void i(Bundle bundle) {
        int i2 = 1;
        if (bundle != null) {
            try {
                i2 = bundle.getInt("activatesAction", 1);
            } catch (Throwable th) {
                e2.h(th, "GeoFenceManager", "doSetActivatesAction");
                return;
            }
        }
        if (this.f5140f != i2) {
            if (this.f5141g != null && !this.f5141g.isEmpty()) {
                Iterator<GeoFence> it = this.f5141g.iterator();
                while (it.hasNext()) {
                    GeoFence next = it.next();
                    next.setStatus(0);
                    next.setEnterTime(-1L);
                }
            }
            if (this.f5144j != null) {
                if (C()) {
                    h(6, null, 0L);
                } else {
                    f(7);
                    h(7, null, 1000L);
                }
            }
        }
        this.f5140f = i2;
    }

    public final void j(GeoFence geoFence) {
        try {
            if (this.f5136b != null) {
                if (this.f5137c == null && geoFence.getPendingIntent() == null) {
                    return;
                }
                Intent intent = new Intent();
                intent.putExtras(c(geoFence, geoFence.getFenceId(), geoFence.getCustomId(), geoFence.getStatus(), 0));
                if (this.f5138d != null) {
                    intent.setAction(this.f5138d);
                }
                intent.setPackage(i2.e(this.f5136b));
                if (geoFence.getPendingIntent() != null) {
                    geoFence.getPendingIntent().send(this.f5136b, 0, intent);
                } else {
                    this.f5137c.send(this.f5136b, 0, intent);
                }
            }
        } catch (Throwable th) {
            e2.h(th, "GeoFenceManager", "resultTriggerGeoFence");
        }
    }

    public final void k(AMapLocation aMapLocation) {
        try {
            if (this.f5141g == null || this.f5141g.isEmpty() || aMapLocation == null || aMapLocation.getErrorCode() != 0) {
                return;
            }
            Iterator<GeoFence> it = this.f5141g.iterator();
            while (it.hasNext()) {
                GeoFence next = it.next();
                if (v(aMapLocation, next) && n(next, this.f5140f)) {
                    Bundle bundle = new Bundle();
                    bundle.putParcelable("geoFence", next);
                    g(1001, bundle);
                }
            }
        } catch (Throwable th) {
            e2.h(th, "GeoFenceManager", "doCheckFence");
        }
    }

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

    @Override
    public void removeGeoFence() {
        z();
    }

    @Override
    public boolean removeGeoFence(GeoFence geoFence) {
        boolean z = false;
        try {
            if (this.f5141g != null) {
                x();
                z = this.f5141g.remove(geoFence);
                if (z && this.f5141g.size() == 0) {
                    z();
                }
            }
        } catch (Throwable th) {
            e2.h(th, "GeoFenceManager", "removeGeoFence(GeoFence)");
        }
        return z;
    }

    public final void s() {
        float f2;
        try {
            if (a2.q(this.q)) {
                AMapLocation aMapLocation = this.q;
                ArrayList<GeoFence> arrayList = this.f5141g;
                float f3 = Float.MAX_VALUE;
                if (aMapLocation != null && aMapLocation.getErrorCode() == 0 && arrayList != null && !arrayList.isEmpty()) {
                    DPoint dPoint = new DPoint(aMapLocation.getLatitude(), aMapLocation.getLongitude());
                    for (GeoFence geoFence : arrayList) {
                        float d2 = a2.d(dPoint, geoFence.getCenter());
                        if (d2 > geoFence.getMinDis2Center() && d2 < geoFence.getMaxDis2Center()) {
                            f2 = 0.0f;
                            break;
                        }
                        if (d2 > geoFence.getMaxDis2Center()) {
                            f3 = Math.min(f3, d2 - geoFence.getMaxDis2Center());
                        }
                        if (d2 < geoFence.getMinDis2Center()) {
                            f3 = Math.min(f3, geoFence.getMinDis2Center() - d2);
                        }
                    }
                }
                f2 = f3;
                if (f2 < 1000.0f) {
                    f(7);
                    Bundle bundle = new Bundle();
                    bundle.putLong("interval", 2000L);
                    h(8, bundle, 1000L);
                } else if (f2 < 5000.0f) {
                    f(7);
                    h(7, null, 10000L);
                } else {
                    f(7);
                    h(7, null, ((f2 - 4000.0f) / 100.0f) * 1000.0f);
                }
            }
        } catch (Throwable th) {
            e2.h(th, "GeoFenceManager", "doCheckLocationPolicy");
        }
    }

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

    @Override
    public void setGeoFenceListener(GeoFenceListener geoFenceListener) {
        this.f5139e = geoFenceListener;
    }

    public final void t(int i2) {
        try {
            if (this.f5136b == null || this.f5137c == null) {
                return;
            }
            Intent intent = new Intent();
            intent.putExtras(c(null, null, null, 4, i2));
            this.f5137c.send(this.f5136b, 0, intent);
        } catch (Throwable th) {
            e2.h(th, "GeoFenceManager", "resultRemindLocationError");
        }
    }

    public final void u(Bundle bundle) {
        String str;
        try {
            ArrayList<? extends Parcelable> arrayList = new ArrayList<>();
            String str2 = "";
            int i2 = 1;
            if (bundle != null && !bundle.isEmpty()) {
                DPoint dPoint = (DPoint) bundle.getParcelable("point");
                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 d2 = d(bundle, false);
                        i2 = q(d2);
                        if (i2 == 0) {
                            arrayList.add(d2);
                        }
                        Bundle bundle2 = new Bundle();
                        bundle2.putInt("errorCode", i2);
                        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", i2);
                    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", i2);
            bundle222.putParcelableArrayList("resultList", arrayList);
            bundle222.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
            g(1000, bundle222);
        } catch (Throwable th) {
            e2.h(th, "GeoFenceManager", "doAddGeoFence_round");
        }
    }

    public final void x() {
        if (this.m) {
            return;
        }
        try {
            this.f5142h = Looper.myLooper() == null ? new d(this.f5136b.getMainLooper()) : new d();
        } catch (Throwable th) {
            e2.h(th, "GeoFenceManger", "init 1");
        }
        try {
            c cVar = new c("fenceActionThread");
            this.f5145k = cVar;
            cVar.setPriority(5);
            this.f5145k.start();
            this.f5144j = new b(this.f5145k.getLooper());
        } catch (Throwable th2) {
            e2.h(th2, "GeoFenceManger", "init 2");
        }
        try {
            this.n = new b0();
            this.o = new c1();
            this.s = new AMapLocationClientOption();
            this.p = new AMapLocationClient(this.f5136b);
            this.s.setLocationCacheEnable(false);
            this.p.setLocationListener(this.u);
            if (this.f5135a == null) {
                this.f5135a = new x1();
            }
        } catch (Throwable th3) {
            e2.h(th3, "GeoFenceManger", "init 3");
        }
        this.m = true;
        try {
            if (this.f5138d == null || this.f5137c != null) {
                return;
            }
            createPendingIntent(this.f5138d);
        } catch (Throwable th4) {
            e2.h(th4, "GeoFenceManger", "init 4");
        }
    }

    public final void y(Bundle bundle) {
        GeoFence d2;
        try {
            ArrayList<? extends Parcelable> arrayList = new ArrayList<>();
            String str = "";
            int i2 = 1;
            if (bundle != null && !bundle.isEmpty()) {
                ArrayList parcelableArrayList = bundle.getParcelableArrayList("points");
                String string = bundle.getString(GeoFence.BUNDLE_KEY_CUSTOMID);
                if (parcelableArrayList != null && parcelableArrayList.size() > 2 && (i2 = q((d2 = d(bundle, true)))) == 0) {
                    arrayList.add(d2);
                }
                str = string;
            }
            Bundle bundle2 = new Bundle();
            bundle2.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
            bundle2.putInt("errorCode", i2);
            bundle2.putParcelableArrayList("resultList", arrayList);
            g(1000, bundle2);
        } catch (Throwable th) {
            e2.h(th, "GeoFenceManager", "doAddGeoFence_polygon");
        }
    }

    public final void z() {
        if (this.m) {
            synchronized (this.f5143i) {
                if (this.f5144j != null) {
                    this.f5144j.removeCallbacksAndMessages(null);
                }
                this.f5144j = null;
            }
            if (this.p != null) {
                this.p.stopLocation();
                this.p.onDestroy();
            }
            this.p = null;
            if (this.f5145k != null) {
                if (Build.VERSION.SDK_INT >= 18) {
                    this.f5145k.quitSafely();
                } else {
                    this.f5145k.quit();
                }
            }
            this.f5145k = null;
            if (this.f5141g != null) {
                this.f5141g.clear();
                this.f5141g = null;
            }
            this.n = null;
            if (this.f5137c != null) {
                this.f5137c.cancel();
            }
            this.f5137c = null;
            if (this.f5135a != null) {
                this.f5135a.m(this.f5136b);
            }
            this.m = false;
        }
    }
}