Aqara Home v2.4.1版本的 MD5 值为:529779ac2bc0131db52a1fc3098d2b35

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


package com.loc;

import android.annotation.SuppressLint;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.Log;
import androidx.work.impl.background.systemalarm.CommandHandler;
import com.amap.api.fence.GeoFence;
import com.amap.api.fence.GeoFenceListener;
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.location.DPoint;
import com.lumiunited.aqara.ifttt.sceneeditpage.actionbuild.IFTTTDetailBuildActivity;
import com.taobao.accs.common.Constants;
import com.taobao.accs.utl.Utils;
import com.umeng.socialize.handler.UMSSOHandler;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.json.JSONObject;
@SuppressLint({"NewApi"})
public final class a {
    public static boolean A = false;
    public Context b;
    public er a = null;
    public PendingIntent c = null;
    public String d = null;
    public GeoFenceListener f5657e = null;
    public Object f5678z = new Object();
    public volatile int f5658f = 1;
    public ArrayList<GeoFence> f5659g = new ArrayList<>();
    public c f5660h = null;
    public Object f5661i = new Object();
    public Object f5662j = new Object();
    public HandlerC0086a f5663k = null;
    public b f5664l = null;
    public volatile boolean f5665m = false;
    public volatile boolean f5666n = false;
    public volatile boolean f5667o = false;
    public com.loc.b f5668p = null;
    public com.loc.c f5669q = null;
    public AMapLocationClient f5670r = null;
    public volatile AMapLocation f5671s = null;
    public long f5672t = 0;
    public AMapLocationClientOption f5673u = null;
    public int f5674v = 0;
    public AMapLocationListener f5675w = new AMapLocationListener() {
        @Override
        public final void onLocationChanged(AMapLocation aMapLocation) {
            boolean z2;
            int i2;
            try {
                if (!a.this.f5677y && a.this.f5667o) {
                    a.this.f5671s = aMapLocation;
                    if (aMapLocation != null) {
                        i2 = aMapLocation.getErrorCode();
                        if (aMapLocation.getErrorCode() == 0) {
                            a.this.f5672t = et.b();
                            a.this.a(5, (Bundle) null, 0L);
                            z2 = true;
                        } else {
                            a.a("定位失败", aMapLocation.getErrorCode(), aMapLocation.getErrorInfo(), "locationDetail:" + aMapLocation.getLocationDetail());
                            z2 = false;
                        }
                    } else {
                        z2 = false;
                        i2 = 8;
                    }
                    if (z2) {
                        a.this.f5674v = 0;
                        a.this.a(6, (Bundle) null, 0L);
                        return;
                    }
                    Bundle bundle = new Bundle();
                    if (!a.this.f5665m) {
                        a.this.b(7);
                        bundle.putLong(com.umeng.analytics.pro.ak.aT, 2000L);
                        a.this.a(8, bundle, 2000L);
                    }
                    a.this.f5674v++;
                    if (a.this.f5674v >= 3) {
                        bundle.putInt(GeoFence.BUNDLE_KEY_LOCERRORCODE, i2);
                        a.this.a(1002, bundle);
                    }
                }
            } catch (Throwable unused) {
            }
        }
    };
    public final int f5676x = 3;
    public volatile boolean f5677y = false;

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

        @Override
        public final void handleMessage(Message message) {
            String str;
            GeoFence a;
            try {
                String str2 = "";
                int i2 = 1;
                switch (message.what) {
                    case 0:
                        a aVar = a.this;
                        Bundle data = message.getData();
                        ArrayList<? extends Parcelable> arrayList = new ArrayList<>();
                        if (data != null && !data.isEmpty()) {
                            DPoint dPoint = (DPoint) data.getParcelable("centerPoint");
                            str = data.getString(GeoFence.BUNDLE_KEY_CUSTOMID);
                            if (dPoint != null) {
                                if (dPoint.getLatitude() <= 90.0d && dPoint.getLatitude() >= -90.0d && dPoint.getLongitude() <= 180.0d && dPoint.getLongitude() >= -180.0d) {
                                    GeoFence a2 = aVar.a(data, false);
                                    i2 = aVar.b(a2);
                                    if (i2 == 0) {
                                        arrayList.add(a2);
                                    }
                                    Bundle bundle = new Bundle();
                                    bundle.putInt(Constants.KEY_ERROR_CODE, i2);
                                    bundle.putParcelableArrayList("resultList", arrayList);
                                    bundle.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
                                    aVar.a(1000, bundle);
                                    return;
                                }
                                a.a("添加围栏失败", 1, "经纬度错误,传入的纬度:" + dPoint.getLatitude() + "传入的经度:" + dPoint.getLongitude(), new String[0]);
                                Bundle bundle2 = new Bundle();
                                bundle2.putInt(Constants.KEY_ERROR_CODE, i2);
                                bundle2.putParcelableArrayList("resultList", arrayList);
                                bundle2.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
                                aVar.a(1000, bundle2);
                                return;
                            }
                            str2 = str;
                        }
                        str = str2;
                        Bundle bundle22 = new Bundle();
                        bundle22.putInt(Constants.KEY_ERROR_CODE, i2);
                        bundle22.putParcelableArrayList("resultList", arrayList);
                        bundle22.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str);
                        aVar.a(1000, bundle22);
                        return;
                    case 1:
                        a aVar2 = a.this;
                        Bundle data2 = message.getData();
                        ArrayList<? extends Parcelable> arrayList2 = new ArrayList<>();
                        if (data2 != null && !data2.isEmpty()) {
                            ArrayList parcelableArrayList = data2.getParcelableArrayList("pointList");
                            String string = data2.getString(GeoFence.BUNDLE_KEY_CUSTOMID);
                            if (parcelableArrayList != null && parcelableArrayList.size() > 2 && (i2 = aVar2.b((a = aVar2.a(data2, true)))) == 0) {
                                arrayList2.add(a);
                            }
                            str2 = string;
                        }
                        Bundle bundle3 = new Bundle();
                        bundle3.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str2);
                        bundle3.putInt(Constants.KEY_ERROR_CODE, i2);
                        bundle3.putParcelableArrayList("resultList", arrayList2);
                        aVar2.a(1000, bundle3);
                        return;
                    case 2:
                        a.this.c(message.getData());
                        return;
                    case 3:
                        a.this.b(message.getData());
                        return;
                    case 4:
                        a.this.d(message.getData());
                        return;
                    case 5:
                        a.this.f();
                        return;
                    case 6:
                        a.this.a(a.this.f5671s);
                        return;
                    case 7:
                        a aVar3 = a.this;
                        if (aVar3.f5670r != null) {
                            aVar3.e();
                            aVar3.f5673u.setOnceLocation(true);
                            aVar3.f5670r.setLocationOption(aVar3.f5673u);
                            aVar3.f5670r.startLocation();
                            return;
                        }
                        return;
                    case 8:
                        a aVar4 = a.this;
                        Bundle data3 = message.getData();
                        if (aVar4.f5670r != null) {
                            long j2 = 2000;
                            if (data3 != null && !data3.isEmpty()) {
                                j2 = data3.getLong(com.umeng.analytics.pro.ak.aT, 2000L);
                            }
                            aVar4.f5673u.setOnceLocation(false);
                            aVar4.f5673u.setInterval(j2);
                            aVar4.f5670r.setLocationOption(aVar4.f5673u);
                            if (aVar4.f5665m) {
                                return;
                            }
                            aVar4.f5670r.stopLocation();
                            aVar4.f5670r.startLocation();
                            aVar4.f5665m = true;
                            return;
                        }
                        return;
                    case 9:
                        a.this.a(message.getData());
                        return;
                    case 10:
                        a.this.c();
                        return;
                    case 11:
                        a.this.f(message.getData());
                        return;
                    case 12:
                        a.this.e(message.getData());
                        return;
                    case 13:
                        a.this.h();
                        return;
                    default:
                        return;
                }
            } catch (Throwable unused) {
            }
        }
    }

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

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

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

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

        @Override
        public final void handleMessage(Message message) {
            try {
                Bundle data = message.getData();
                switch (message.what) {
                    case 1000:
                        a aVar = a.this;
                        if (data == null || data.isEmpty()) {
                            return;
                        }
                        int i2 = data.getInt(Constants.KEY_ERROR_CODE);
                        ArrayList parcelableArrayList = data.getParcelableArrayList("resultList");
                        if (parcelableArrayList == null) {
                            parcelableArrayList = new ArrayList();
                        }
                        String string = data.getString(GeoFence.BUNDLE_KEY_CUSTOMID);
                        if (string == null) {
                            string = "";
                        }
                        if (aVar.f5657e != null) {
                            aVar.f5657e.onGeoFenceCreateFinished((ArrayList) parcelableArrayList.clone(), i2, string);
                        }
                        if (i2 == 0) {
                            aVar.d();
                            return;
                        }
                        return;
                    case 1001:
                        a.this.c((GeoFence) data.getParcelable("geoFence"));
                        return;
                    case 1002:
                        a.this.c(data.getInt(GeoFence.BUNDLE_KEY_LOCERRORCODE));
                        return;
                    default:
                        return;
                }
            } catch (Throwable unused) {
            }
        }
    }

    public a(Context context) {
        this.b = null;
        try {
            this.b = context.getApplicationContext();
            k();
        } catch (Throwable th) {
            en.a(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, et.a(dPoint, dPoint2));
            }
        }
        return f2;
    }

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

    public static Bundle a(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("event", i2);
        bundle.putInt(GeoFence.BUNDLE_KEY_LOCERRORCODE, i3);
        bundle.putParcelable(GeoFence.BUNDLE_KEY_FENCE, geoFence);
        return bundle;
    }

    public static void a(String str, int i2, String str2, String... strArr) {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("===========================================\n");
        stringBuffer.append("              " + str + "                ");
        stringBuffer.append("\n");
        stringBuffer.append("-------------------------------------------\n");
        stringBuffer.append("errorCode:" + i2);
        stringBuffer.append("\n");
        stringBuffer.append("错误信息:" + str2);
        stringBuffer.append("\n");
        if (strArr.length > 0) {
            for (String str3 : strArr) {
                stringBuffer.append(str3);
                stringBuffer.append("\n");
            }
        }
        stringBuffer.append("===========================================\n");
        Log.i("fenceErrLog", stringBuffer.toString());
    }

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

    public static boolean a(AMapLocation aMapLocation, GeoFence geoFence) {
        boolean z2 = false;
        try {
            if (et.a(aMapLocation) && geoFence != null && geoFence.getPointList() != null && !geoFence.getPointList().isEmpty()) {
                int type = geoFence.getType();
                if (type != 0) {
                    if (type != 1) {
                        if (type != 2) {
                            if (type != 3) {
                            }
                        }
                    }
                    boolean z3 = false;
                    for (List<DPoint> list : geoFence.getPointList()) {
                        try {
                            if (list.size() < 3 ? false : en.a(new DPoint(aMapLocation.getLatitude(), aMapLocation.getLongitude()), list)) {
                                z3 = true;
                            }
                        } catch (Throwable th) {
                            th = th;
                            z2 = z3;
                            en.a(th, Utils.TAG, "isInGeoFence");
                            return z2;
                        }
                    }
                    z2 = z3;
                }
                DPoint center = geoFence.getCenter();
                if (et.a(new double[]{center.getLatitude(), center.getLongitude(), aMapLocation.getLatitude(), aMapLocation.getLongitude()}) <= geoFence.getRadius()) {
                    return true;
                }
            }
        } catch (Throwable th2) {
            th = th2;
        }
        return z2;
    }

    public static float b(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, et.a(dPoint, dPoint2));
            }
        }
        return f2;
    }

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

    private void b(int i2, Bundle bundle) {
        String str;
        int i3;
        String str2;
        boolean z2;
        boolean z3;
        String str3;
        String str4;
        int i4;
        String str5;
        String a;
        int i5;
        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 i6 = bundle.getInt("searchSize", 10);
                        float f2 = bundle.getFloat("aroundRadius", 3000.0f);
                        if (TextUtils.isEmpty(string2)) {
                            str2 = "添加围栏失败";
                            z3 = false;
                        } else {
                            if (i2 != 1) {
                                if (i2 == 2) {
                                    if (dPoint == null) {
                                        str2 = "添加围栏失败";
                                    } else {
                                        try {
                                            if (dPoint.getLatitude() > 90.0d || dPoint.getLatitude() < -90.0d || dPoint.getLongitude() > 180.0d || dPoint.getLongitude() < -180.0d) {
                                                str2 = "添加围栏失败";
                                                a(str2, 0, "经纬度错误,传入的纬度:" + dPoint.getLatitude() + "传入的经度:" + dPoint.getLongitude(), new String[0]);
                                            }
                                        } catch (Throwable th) {
                                            th = th;
                                            str = Constants.KEY_ERROR_CODE;
                                            i3 = 0;
                                            try {
                                                en.a(th, "GeoFenceManager", "doAddGeoFenceNearby");
                                                bundle2.putInt(str, 8);
                                                a(1000, bundle2);
                                                return;
                                            } catch (Throwable th2) {
                                                bundle2.putInt(str, i3);
                                                a(1000, bundle2);
                                                throw th2;
                                            }
                                        }
                                    }
                                }
                                str2 = "添加围栏失败";
                                z2 = true;
                            } else {
                                str2 = "添加围栏失败";
                                z2 = TextUtils.isEmpty(string4) ? false : false;
                                z2 = true;
                            }
                            z3 = z2;
                        }
                        if (z3) {
                            Bundle bundle3 = new Bundle();
                            bundle3.putString(GeoFence.BUNDLE_KEY_CUSTOMID, string);
                            bundle3.putString("pendingIntentAction", this.d);
                            str3 = GeoFence.BUNDLE_KEY_CUSTOMID;
                            str4 = Constants.KEY_ERROR_CODE;
                            try {
                                bundle3.putLong(UMSSOHandler.EXPIRATION, -1L);
                                bundle3.putInt("activatesAction", this.f5658f);
                            } catch (Throwable th3) {
                                th = th3;
                            }
                            try {
                                if (i2 == 1) {
                                    bundle3.putFloat("fenceRadius", 1000.0f);
                                    a = this.f5668p.a(this.b, "http://restapi.amap.com/v3/place/text?", string2, string4, string3, String.valueOf(i6));
                                } else if (i2 != 2) {
                                    a = i2 != 3 ? null : this.f5668p.a(this.b, "http://restapi.amap.com/v3/config/district?", string2);
                                } else {
                                    double b2 = et.b(dPoint.getLatitude());
                                    double b3 = et.b(dPoint.getLongitude());
                                    int intValue = Float.valueOf(f2).intValue();
                                    bundle3.putFloat("fenceRadius", 200.0f);
                                    a = this.f5668p.a(this.b, "http://restapi.amap.com/v3/place/around?", string2, string4, String.valueOf(i6), String.valueOf(b2), String.valueOf(b3), String.valueOf(intValue));
                                }
                                int i7 = 4;
                                if (a != null) {
                                    int a2 = 1 == i2 ? com.loc.c.a(a, arrayList2, bundle3) : 0;
                                    if (2 == i2) {
                                        a2 = com.loc.c.a(a, arrayList2, bundle3);
                                    }
                                    if (3 == i2) {
                                        a2 = this.f5669q.b(a, arrayList2, bundle3);
                                    }
                                    if (a2 != 10000) {
                                        if (a2 != 1 && a2 != 7 && a2 != 4 && a2 != 5 && a2 != 16 && a2 != 17) {
                                            switch (a2) {
                                                case 10000:
                                                    i5 = 0;
                                                    break;
                                                case 10001:
                                                case 10002:
                                                case 10007:
                                                case 10008:
                                                case 10009:
                                                case 10012:
                                                case 10013:
                                                    i5 = 7;
                                                    break;
                                                case 10003:
                                                case 10004:
                                                case 10005:
                                                case 10006:
                                                case 10010:
                                                case 10011:
                                                case IFTTTDetailBuildActivity.l7:
                                                case IFTTTDetailBuildActivity.m7:
                                                case 10016:
                                                case 10017:
                                                    i5 = 4;
                                                    break;
                                                default:
                                                    switch (a2) {
                                                        case 20000:
                                                        case 20001:
                                                        case 20002:
                                                            i5 = 1;
                                                            break;
                                                        case 20003:
                                                        default:
                                                            i5 = 8;
                                                            break;
                                                    }
                                            }
                                        } else {
                                            i5 = a2;
                                        }
                                        if (i5 != 0) {
                                            a(str2, i5, "searchErrCode is " + i5, new String[0]);
                                        }
                                        i3 = i5;
                                    } else if (arrayList2.isEmpty()) {
                                        i3 = 16;
                                    } else {
                                        i3 = a(arrayList2);
                                        if (i3 == 0) {
                                            try {
                                                arrayList.addAll(arrayList2);
                                            } catch (Throwable th4) {
                                                th = th4;
                                                str = str4;
                                                en.a(th, "GeoFenceManager", "doAddGeoFenceNearby");
                                                bundle2.putInt(str, 8);
                                                a(1000, bundle2);
                                                return;
                                            }
                                        } else {
                                            i7 = i3;
                                        }
                                    }
                                }
                                i3 = i7;
                            } catch (Throwable th5) {
                                th = th5;
                                str = str4;
                                i3 = 0;
                                en.a(th, "GeoFenceManager", "doAddGeoFenceNearby");
                                bundle2.putInt(str, 8);
                                a(1000, bundle2);
                                return;
                            }
                        } else {
                            str3 = GeoFence.BUNDLE_KEY_CUSTOMID;
                            str4 = Constants.KEY_ERROR_CODE;
                            i3 = 1;
                        }
                        bundle2.putString(str3, string);
                        bundle2.putParcelableArrayList("resultList", arrayList);
                        i4 = i3;
                        str5 = str4;
                        bundle2.putInt(str5, i4);
                        a(1000, bundle2);
                    }
                } catch (Throwable th6) {
                    th = th6;
                }
            }
            str5 = Constants.KEY_ERROR_CODE;
            i4 = 1;
            bundle2.putInt(str5, i4);
            a(1000, bundle2);
        } catch (Throwable th7) {
            th = th7;
            str = Constants.KEY_ERROR_CODE;
        }
    }

    public static boolean b(AMapLocation aMapLocation, GeoFence geoFence) {
        boolean z2 = true;
        try {
            if (!a(aMapLocation, geoFence)) {
                if (geoFence.getStatus() != 2) {
                    try {
                        geoFence.setStatus(2);
                        geoFence.setEnterTime(-1L);
                    } catch (Throwable th) {
                        th = th;
                        en.a(th, Utils.TAG, "isFenceStatusChanged");
                        return z2;
                    }
                }
                z2 = false;
            } else if (geoFence.getEnterTime() == -1) {
                if (geoFence.getStatus() != 1) {
                    geoFence.setEnterTime(et.b());
                    geoFence.setStatus(1);
                }
                z2 = false;
            } else {
                if (geoFence.getStatus() != 3 && et.b() - geoFence.getEnterTime() > CommandHandler.WORK_PROCESSING_TIME_IN_MS) {
                    geoFence.setStatus(3);
                }
                z2 = false;
            }
        } catch (Throwable th2) {
            th = th2;
            z2 = false;
        }
        return z2;
    }

    private void k() {
        if (!this.f5667o) {
            this.f5667o = true;
        }
        if (this.f5666n) {
            return;
        }
        try {
            this.f5660h = Looper.myLooper() == null ? new c(this.b.getMainLooper()) : new c();
        } catch (Throwable th) {
            en.a(th, "GeoFenceManger", "init 1");
        }
        try {
            b bVar = new b("fenceActionThread");
            this.f5664l = bVar;
            bVar.setPriority(5);
            this.f5664l.start();
            this.f5663k = new HandlerC0086a(this.f5664l.getLooper());
        } catch (Throwable th2) {
            en.a(th2, "GeoFenceManger", "init 2");
        }
        try {
            this.f5668p = new com.loc.b(this.b);
            this.f5669q = new com.loc.c();
            this.f5673u = new AMapLocationClientOption();
            this.f5670r = new AMapLocationClient(this.b);
            this.f5673u.setLocationCacheEnable(true);
            this.f5673u.setNeedAddress(false);
            this.f5670r.setLocationListener(this.f5675w);
            if (this.a == null) {
                this.a = new er();
            }
        } catch (Throwable th3) {
            en.a(th3, "GeoFenceManger", "initBase");
        }
        this.f5666n = true;
        try {
            if (this.d != null && this.c == null) {
                a(this.d);
            }
        } catch (Throwable th4) {
            en.a(th4, "GeoFenceManger", "init 4");
        }
        if (A) {
            return;
        }
        A = true;
        er.a(this.b, "O020", (JSONObject) null);
    }

    public final PendingIntent a(String str) {
        synchronized (this.f5678z) {
            try {
                Intent intent = new Intent(str);
                intent.setPackage(k.c(this.b));
                this.c = PendingIntent.getBroadcast(this.b, 0, intent, 0);
                this.d = str;
                if (this.f5659g != null && !this.f5659g.isEmpty()) {
                    Iterator<GeoFence> it = this.f5659g.iterator();
                    while (it.hasNext()) {
                        GeoFence next = it.next();
                        next.setPendingIntent(this.c);
                        next.setPendingIntentAction(this.d);
                    }
                }
            }
        }
        return this.c;
    }

    public final GeoFence a(Bundle bundle, boolean z2) {
        GeoFence geoFence = new GeoFence();
        ArrayList arrayList = new ArrayList();
        DPoint dPoint = new DPoint();
        if (z2) {
            geoFence.setType(1);
            arrayList = bundle.getParcelableArrayList("pointList");
            if (arrayList != null) {
                dPoint = b(arrayList);
            }
            geoFence.setMaxDis2Center(b(dPoint, arrayList));
            geoFence.setMinDis2Center(a(dPoint, arrayList));
        } else {
            geoFence.setType(0);
            dPoint = (DPoint) bundle.getParcelable("centerPoint");
            if (dPoint != null) {
                arrayList.add(dPoint);
            }
            float f2 = bundle.getFloat("fenceRadius", 1000.0f);
            float f3 = f2 > 0.0f ? f2 : 1000.0f;
            geoFence.setRadius(f3);
            geoFence.setMinDis2Center(f3);
            geoFence.setMaxDis2Center(f3);
        }
        geoFence.setActivatesAction(this.f5658f);
        geoFence.setCustomId(bundle.getString(GeoFence.BUNDLE_KEY_CUSTOMID));
        ArrayList arrayList2 = new ArrayList();
        arrayList2.add(arrayList);
        geoFence.setPointList(arrayList2);
        geoFence.setCenter(dPoint);
        geoFence.setPendingIntentAction(this.d);
        geoFence.setExpiration(-1L);
        geoFence.setPendingIntent(this.c);
        StringBuilder sb = new StringBuilder();
        sb.append(com.loc.c.a());
        geoFence.setFenceId(sb.toString());
        er erVar = this.a;
        if (erVar != null) {
            erVar.a(this.b, 2);
        }
        return geoFence;
    }

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

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

    public final void a(int i2, Bundle bundle) {
        try {
            synchronized (this.f5662j) {
                if (this.f5660h != null) {
                    Message obtainMessage = this.f5660h.obtainMessage();
                    obtainMessage.what = i2;
                    obtainMessage.setData(bundle);
                    this.f5660h.sendMessage(obtainMessage);
                }
            }
        } catch (Throwable th) {
            en.a(th, "GeoFenceManager", "sendResultHandlerMessage");
        }
    }

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

    public final void a(Bundle bundle) {
        int i2 = 1;
        if (bundle != null) {
            try {
                i2 = bundle.getInt("activatesAction", 1);
            } catch (Throwable th) {
                en.a(th, "GeoFenceManager", "doSetActivatesAction");
                return;
            }
        }
        if (this.f5658f != i2) {
            if (this.f5659g != null && !this.f5659g.isEmpty()) {
                Iterator<GeoFence> it = this.f5659g.iterator();
                while (it.hasNext()) {
                    GeoFence next = it.next();
                    next.setStatus(0);
                    next.setEnterTime(-1L);
                }
            }
            d();
        }
        this.f5658f = i2;
    }

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

    public final void a(AMapLocation aMapLocation) {
        try {
            if (this.f5677y || this.f5659g == null || this.f5659g.isEmpty() || aMapLocation == null || aMapLocation.getErrorCode() != 0) {
                return;
            }
            Iterator<GeoFence> it = this.f5659g.iterator();
            while (it.hasNext()) {
                GeoFence next = it.next();
                if (next.isAble() && b(aMapLocation, next) && a(next, this.f5658f)) {
                    next.setCurrentLocation(aMapLocation);
                    Bundle bundle = new Bundle();
                    bundle.putParcelable("geoFence", next);
                    a(1001, bundle);
                }
            }
        } catch (Throwable th) {
            en.a(th, "GeoFenceManager", "doCheckFence");
        }
    }

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

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

    public final void a(String str, String str2, DPoint dPoint, float f2, int i2, String str3) {
        try {
            k();
            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("keyWords", str);
            bundle.putString("poiType", str2);
            bundle.putParcelable("centerPoint", dPoint);
            bundle.putFloat("aroundRadius", f2);
            bundle.putInt("searchSize", i2);
            bundle.putString(GeoFence.BUNDLE_KEY_CUSTOMID, str3);
            a(3, bundle, 0L);
        } catch (Throwable th) {
            en.a(th, "GeoFenceManager", "addNearbyGeoFence");
        }
    }

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

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

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

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

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

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

    public final void b(int i2) {
        try {
            synchronized (this.f5661i) {
                if (this.f5663k != null) {
                    this.f5663k.removeMessages(i2);
                }
            }
        } catch (Throwable th) {
            en.a(th, "GeoFenceManager", "removeActionHandlerMessage");
        }
    }

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

    public final void c() {
        if (this.f5666n) {
            if (this.f5659g != null) {
                this.f5659g.clear();
                this.f5659g = null;
            }
            if (this.f5667o) {
                return;
            }
            synchronized (this.f5661i) {
                if (this.f5663k != null) {
                    this.f5663k.removeCallbacksAndMessages(null);
                }
                this.f5663k = null;
            }
            if (this.f5670r != null) {
                this.f5670r.stopLocation();
                this.f5670r.onDestroy();
            }
            this.f5670r = null;
            if (this.f5664l != null) {
                if (Build.VERSION.SDK_INT >= 18) {
                    this.f5664l.quitSafely();
                } else {
                    this.f5664l.quit();
                }
            }
            this.f5664l = null;
            this.f5668p = null;
            synchronized (this.f5678z) {
                if (this.c != null) {
                    this.c.cancel();
                }
                this.c = null;
            }
            synchronized (this.f5662j) {
                if (this.f5660h != null) {
                    this.f5660h.removeCallbacksAndMessages(null);
                }
                this.f5660h = null;
            }
            if (this.a != null) {
                this.a.b(this.b);
            }
            this.f5665m = false;
            this.f5666n = false;
        }
    }

    public final void c(int i2) {
        try {
            if (this.b != null) {
                synchronized (this.f5678z) {
                    if (this.c == null) {
                        return;
                    }
                    Intent intent = new Intent();
                    intent.putExtras(a((GeoFence) null, (String) null, (String) null, 4, i2));
                    this.c.send(this.b, 0, intent);
                }
            }
        } catch (Throwable th) {
            en.a(th, "GeoFenceManager", "resultRemindLocationError");
        }
    }

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

    public final void c(GeoFence geoFence) {
        PendingIntent pendingIntent;
        Context context;
        try {
            synchronized (this.f5678z) {
                if (this.b != null) {
                    if (this.c == null && geoFence.getPendingIntent() == null) {
                        return;
                    }
                    Intent intent = new Intent();
                    intent.putExtras(a(geoFence, geoFence.getFenceId(), geoFence.getCustomId(), geoFence.getStatus(), 0));
                    if (this.d != null) {
                        intent.setAction(this.d);
                    }
                    intent.setPackage(k.c(this.b));
                    if (geoFence.getPendingIntent() != null) {
                        pendingIntent = geoFence.getPendingIntent();
                        context = this.b;
                    } else {
                        pendingIntent = this.c;
                        context = this.b;
                    }
                    pendingIntent.send(context, 0, intent);
                }
            }
        } catch (Throwable th) {
            en.a(th, "GeoFenceManager", "resultTriggerGeoFence");
        }
    }

    public final void d() {
        if (this.f5677y || this.f5663k == null) {
            return;
        }
        boolean z2 = false;
        if (this.f5671s != null && et.a(this.f5671s) && et.b() - this.f5672t < 10000) {
            z2 = true;
        }
        if (z2) {
            a(6, (Bundle) null, 0L);
            a(5, (Bundle) null, 0L);
            return;
        }
        b(7);
        a(7, (Bundle) null, 0L);
    }

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

    public final void e() {
        try {
            if (this.f5665m) {
                b(8);
            }
            if (this.f5670r != null) {
                this.f5670r.stopLocation();
            }
            this.f5665m = false;
        } catch (Throwable unused) {
        }
    }

    public final void e(Bundle bundle) {
        if (bundle != null) {
            try {
                if (bundle.isEmpty()) {
                    return;
                }
                String string = bundle.getString("fid");
                if (TextUtils.isEmpty(string)) {
                    return;
                }
                boolean z2 = true;
                boolean z3 = bundle.getBoolean("ab", true);
                if (this.f5659g != null && !this.f5659g.isEmpty()) {
                    Iterator<GeoFence> it = this.f5659g.iterator();
                    while (true) {
                        if (!it.hasNext()) {
                            break;
                        }
                        GeoFence next = it.next();
                        if (next.getFenceId().equals(string)) {
                            next.setAble(z3);
                            break;
                        }
                    }
                }
                if (z3) {
                    d();
                    return;
                }
                if (this.f5659g != null && !this.f5659g.isEmpty()) {
                    Iterator<GeoFence> it2 = this.f5659g.iterator();
                    while (true) {
                        if (!it2.hasNext()) {
                            break;
                        } else if (it2.next().isAble()) {
                            z2 = false;
                            break;
                        }
                    }
                }
            } catch (Throwable th) {
                en.a(th, "GeoFenceManager", "doSetGeoFenceAble");
            }
        }
    }

    public final void f() {
        float f2;
        float f3;
        try {
            if (!this.f5677y && et.a(this.f5671s)) {
                AMapLocation aMapLocation = this.f5671s;
                ArrayList<GeoFence> arrayList = this.f5659g;
                if (aMapLocation == null || aMapLocation.getErrorCode() != 0 || arrayList == null || arrayList.isEmpty()) {
                    f2 = Float.MAX_VALUE;
                } else {
                    DPoint dPoint = new DPoint(aMapLocation.getLatitude(), aMapLocation.getLongitude());
                    f2 = Float.MAX_VALUE;
                    for (GeoFence geoFence : arrayList) {
                        if (geoFence.isAble()) {
                            float a = et.a(dPoint, geoFence.getCenter());
                            if (a > geoFence.getMinDis2Center() && a < geoFence.getMaxDis2Center()) {
                                f3 = 0.0f;
                                break;
                            }
                            if (a > geoFence.getMaxDis2Center()) {
                                f2 = Math.min(f2, a - geoFence.getMaxDis2Center());
                            }
                            if (a < geoFence.getMinDis2Center()) {
                                f2 = Math.min(f2, geoFence.getMinDis2Center() - a);
                            }
                        }
                    }
                }
                f3 = f2;
                if (f3 == Float.MAX_VALUE) {
                    return;
                }
                if (f3 < 1000.0f) {
                    b(7);
                    Bundle bundle = new Bundle();
                    bundle.putLong(com.umeng.analytics.pro.ak.aT, 2000L);
                    a(8, bundle, 500L);
                } else if (f3 < 5000.0f) {
                    e();
                    b(7);
                    a(7, (Bundle) null, 10000L);
                } else {
                    e();
                    b(7);
                    a(7, (Bundle) null, ((f3 - 4000.0f) / 100.0f) * 1000.0f);
                }
            }
        } catch (Throwable th) {
            en.a(th, "GeoFenceManager", "doCheckLocationPolicy");
        }
    }

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

    public final void g() {
        try {
            k();
            this.f5677y = true;
            a(13, (Bundle) null, 0L);
        } catch (Throwable th) {
            en.a(th, "GeoFenceManager", "pauseGeoFence");
        }
    }

    public final void h() {
        try {
            b(7);
            b(8);
            if (this.f5670r != null) {
                this.f5670r.stopLocation();
            }
            this.f5665m = false;
        } catch (Throwable th) {
            en.a(th, "GeoFenceManager", "doPauseGeoFence");
        }
    }

    public final void i() {
        try {
            k();
            if (this.f5677y) {
                this.f5677y = false;
                d();
            }
        } catch (Throwable th) {
            en.a(th, "GeoFenceManager", "resumeGeoFence");
        }
    }

    public final boolean j() {
        return this.f5677y;
    }
}