package com.tencent.luggage.f.a;

import android.annotation.SuppressLint;
import android.os.Bundle;
import com.tencent.map.geolocation.TencentLocation;
import com.tencent.map.geolocation.TencentLocationListener;
import com.tencent.map.geolocation.TencentLocationManager;
import com.tencent.map.geolocation.TencentLocationRequest;
import com.tencent.map.geolocation.TencentLocationUtils;
import com.tencent.map.geolocation.internal.TencentExtraKeys;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.plugin.appbrand.r.m;
import com.tencent.mm.plugin.appbrand.s.b.a.b;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ah;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.ytcommon.BuildConfig;
import java.io.File;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;

public class a implements com.tencent.mm.plugin.appbrand.s.b.a {
    private volatile TencentLocationManager bRp;
    @SuppressLint({"NewApi"})
    private final List<b> bRq = new CopyOnWriteArrayList();
    @SuppressLint({"NewApi"})
    private final List<b> bRr = new CopyOnWriteArrayList();
    @SuppressLint({"NewApi"})
    private final List<b> bRs = new CopyOnWriteArrayList();
    @SuppressLint({"NewApi"})
    private final List<b> bRt = new CopyOnWriteArrayList();
    TencentLocationListener bRu = new TencentLocationListener() {
        public final void onLocationChanged(TencentLocation tencentLocation, int i, String str) {
            AppMethodBeat.i(51135);
            ab.v("MicroMsg.DefaultTencentLocationManager", "[mlocationListener]error:%d, reason:%s", new Object[]{Integer.valueOf(i), str});
            if (i != 0) {
                ab.e("MicroMsg.DefaultTencentLocationManager", "[mlocationListener]error:%d, reason:%s", new Object[]{Integer.valueOf(i), str});
            }
            if (a.this.bRr != null && a.this.bRr.size() > 0) {
                a.a(a.this.bRr, i, str, a.a(tencentLocation, false));
                a.this.bRr.clear();
            }
            if (a.this.bRq != null && a.this.bRq.size() > 0) {
                a.a(a.this.bRq, i, str, a.a(tencentLocation, true));
                a.this.bRq.clear();
            }
            if (a.this.bRt != null && a.this.bRt.size() > 0) {
                a.a(a.this.bRt, i, str, a.a(tencentLocation, false));
            }
            if (a.this.bRs != null && a.this.bRs.size() > 0) {
                a.a(a.this.bRs, i, str, a.a(tencentLocation, true));
            }
            a.e(a.this);
            AppMethodBeat.o(51135);
        }

        public final void onStatusUpdate(String str, int i, String str2) {
            AppMethodBeat.i(51136);
            ab.i("MicroMsg.DefaultTencentLocationManager", "[mlocationListener]name:%s, status:%d, desc:%s", new Object[]{str, Integer.valueOf(i), str2});
            AppMethodBeat.o(51136);
        }
    };
    private Set<String> bRv = new HashSet();
    private Runnable bRw = new 3(this);

    static /* synthetic */ void e(a aVar) {
        AppMethodBeat.i(51146);
        aVar.yi();
        AppMethodBeat.o(51146);
    }

    public a() {
        AppMethodBeat.i(51138);
        ab.i("MicroMsg.DefaultTencentLocationManager", "DefaultTencentLocationManager() construct in process %s", new Object[]{ah.getProcessName()});
        AppMethodBeat.o(51138);
    }

    private TencentLocationManager yg() {
        AppMethodBeat.i(51139);
        if (this.bRp == null) {
            synchronized (this) {
                if (this.bRp == null) {
                    if (yh()) {
                        try {
                            TencentExtraKeys.setTencentLog(ah.getContext(), new File(com.tencent.mm.loader.j.b.eSn + "/lbs" + ah.getProcessName().substring(ah.getPackageName().length() + 1)));
                        } catch (Exception e) {
                            ab.c("MicroMsg.DefaultTencentLocationManager", BuildConfig.FLAVOR, new Object[]{e});
                        } catch (Throwable th) {
                            AppMethodBeat.o(51139);
                        }
                    }
                    this.bRp = TencentLocationManager.getInstance(ah.getContext());
                    this.bRp.setCoordinateType(0);
                    TencentExtraKeys.setContext(ah.getContext());
                    try {
                        TencentExtraKeys.setTencentLogCallback(new 1(this));
                    } catch (Exception e2) {
                        ab.c("MicroMsg.DefaultTencentLocationManager", BuildConfig.FLAVOR, new Object[]{e2});
                    }
                }
            }
        }
        TencentLocationManager tencentLocationManager = this.bRp;
        AppMethodBeat.o(51139);
        return tencentLocationManager;
    }

    /* Access modifiers changed, original: protected */
    public boolean yh() {
        return false;
    }

    public final void a(String str, b bVar, Bundle bundle) {
        AppMethodBeat.i(51140);
        if ("wgs84".equals(str)) {
            this.bRq.add(bVar);
        } else {
            this.bRr.add(bVar);
        }
        m.aNS().doN().removeCallbacks(this.bRw);
        m.aNS().m(this.bRw, 20000);
        boolean z = bundle.getBoolean("enableIndoor");
        TencentLocationRequest create = TencentLocationRequest.create();
        create.setInterval(2000);
        create.setIndoorLocationMode(z);
        create.setSmallAppKey(bundle.getString("smallAppKey"));
        int requestSingleFreshLocation = yg().requestSingleFreshLocation(create, this.bRu, m.aNS().oAl.getLooper());
        ab.d("MicroMsg.DefaultTencentLocationManager", "MapReport:%s getLocation", new Object[]{bundle.getString("smallAppKey")});
        ab.i("MicroMsg.DefaultTencentLocationManager", "requestCode %d", new Object[]{Integer.valueOf(requestSingleFreshLocation)});
        AppMethodBeat.o(51140);
    }

    /* JADX WARNING: Removed duplicated region for block: B:19:0x0053  */
    /* JADX WARNING: Removed duplicated region for block: B:53:0x00e5  */
    /* JADX WARNING: Removed duplicated region for block: B:28:0x0080  */
    /* JADX WARNING: Removed duplicated region for block: B:54:0x00e7  */
    /* JADX WARNING: Removed duplicated region for block: B:33:0x008e  */
    /* JADX WARNING: Removed duplicated region for block: B:37:0x00a4  */
    public final synchronized boolean b(java.lang.String r9, com.tencent.mm.plugin.appbrand.s.b.a.b r10, android.os.Bundle r11) {
        /*
        r8 = this;
        r1 = 1;
        r2 = 0;
        monitor-enter(r8);
        r0 = 51141; // 0xc7c5 float:7.1664E-41 double:2.5267E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.i(r0);	 Catch:{ all -> 0x00ae }
        r0 = "MicroMsg.DefaultTencentLocationManager";
        r3 = "[registerLocation]type:%s";
        r4 = 1;
        r4 = new java.lang.Object[r4];	 Catch:{ all -> 0x00ae }
        r5 = 0;
        r4[r5] = r9;	 Catch:{ all -> 0x00ae }
        com.tencent.mm.sdk.platformtools.ab.i(r0, r3, r4);	 Catch:{ all -> 0x00ae }
        r0 = "wgs84";
        r0 = r0.equals(r9);	 Catch:{ all -> 0x00ae }
        if (r0 == 0) goto L_0x00b1;
    L_0x0021:
        r0 = r8.bRs;	 Catch:{ all -> 0x00ae }
        r3 = r0.iterator();	 Catch:{ all -> 0x00ae }
    L_0x0027:
        r0 = r3.hasNext();	 Catch:{ all -> 0x00ae }
        if (r0 == 0) goto L_0x004c;
    L_0x002d:
        r0 = r3.next();	 Catch:{ all -> 0x00ae }
        r0 = (com.tencent.mm.plugin.appbrand.s.b.a.b) r0;	 Catch:{ all -> 0x00ae }
        if (r0 == 0) goto L_0x0027;
    L_0x0035:
        r0 = r0.equals(r10);	 Catch:{ all -> 0x00ae }
        if (r0 == 0) goto L_0x0027;
    L_0x003b:
        r0 = "MicroMsg.DefaultTencentLocationManager";
        r1 = "already register";
        com.tencent.mm.sdk.platformtools.ab.w(r0, r1);	 Catch:{ all -> 0x00ae }
        r0 = 51141; // 0xc7c5 float:7.1664E-41 double:2.5267E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r0);	 Catch:{ all -> 0x00ae }
    L_0x004a:
        monitor-exit(r8);
        return r2;
    L_0x004c:
        r0 = r8.bRs;	 Catch:{ all -> 0x00ae }
        r0.add(r10);	 Catch:{ all -> 0x00ae }
    L_0x0051:
        if (r11 == 0) goto L_0x0065;
    L_0x0053:
        r0 = "smallAppKey";
        r0 = r11.getString(r0);	 Catch:{ all -> 0x00ae }
        r3 = com.tencent.mm.sdk.platformtools.bo.isNullOrNil(r0);	 Catch:{ all -> 0x00ae }
        if (r3 != 0) goto L_0x0065;
    L_0x0060:
        r3 = r8.bRv;	 Catch:{ all -> 0x00ae }
        r3.add(r0);	 Catch:{ all -> 0x00ae }
    L_0x0065:
        if (r11 == 0) goto L_0x00e3;
    L_0x0067:
        r0 = "enableIndoor";
        r0 = r11.getBoolean(r0);	 Catch:{ all -> 0x00ae }
        if (r0 == 0) goto L_0x00e3;
    L_0x0070:
        r3 = r1;
    L_0x0071:
        r0 = r8.bRs;	 Catch:{ all -> 0x00ae }
        r0 = r0.size();	 Catch:{ all -> 0x00ae }
        r4 = r8.bRt;	 Catch:{ all -> 0x00ae }
        r4 = r4.size();	 Catch:{ all -> 0x00ae }
        r0 = r0 + r4;
        if (r0 != r1) goto L_0x00e5;
    L_0x0080:
        r0 = r1;
    L_0x0081:
        if (r0 != 0) goto L_0x0085;
    L_0x0083:
        if (r3 == 0) goto L_0x012b;
    L_0x0085:
        r4 = com.tencent.map.geolocation.TencentLocationRequest.create();	 Catch:{ all -> 0x00ae }
        r4.setIndoorLocationMode(r3);	 Catch:{ all -> 0x00ae }
        if (r3 == 0) goto L_0x00e7;
    L_0x008e:
        r0 = 1000; // 0x3e8 float:1.401E-42 double:4.94E-321;
    L_0x0090:
        r4.setInterval(r0);	 Catch:{ all -> 0x00ae }
        r1 = new java.lang.StringBuilder;	 Catch:{ all -> 0x00ae }
        r1.<init>();	 Catch:{ all -> 0x00ae }
        r0 = r8.bRv;	 Catch:{ all -> 0x00ae }
        r3 = r0.iterator();	 Catch:{ all -> 0x00ae }
    L_0x009e:
        r0 = r3.hasNext();	 Catch:{ all -> 0x00ae }
        if (r0 == 0) goto L_0x00ea;
    L_0x00a4:
        r0 = r3.next();	 Catch:{ all -> 0x00ae }
        r0 = (java.lang.String) r0;	 Catch:{ all -> 0x00ae }
        r1.append(r0);	 Catch:{ all -> 0x00ae }
        goto L_0x009e;
    L_0x00ae:
        r0 = move-exception;
        monitor-exit(r8);
        throw r0;
    L_0x00b1:
        r0 = r8.bRt;	 Catch:{ all -> 0x00ae }
        r3 = r0.iterator();	 Catch:{ all -> 0x00ae }
    L_0x00b7:
        r0 = r3.hasNext();	 Catch:{ all -> 0x00ae }
        if (r0 == 0) goto L_0x00dc;
    L_0x00bd:
        r0 = r3.next();	 Catch:{ all -> 0x00ae }
        r0 = (com.tencent.mm.plugin.appbrand.s.b.a.b) r0;	 Catch:{ all -> 0x00ae }
        if (r0 == 0) goto L_0x00b7;
    L_0x00c5:
        r0 = r0.equals(r10);	 Catch:{ all -> 0x00ae }
        if (r0 == 0) goto L_0x00b7;
    L_0x00cb:
        r0 = "MicroMsg.DefaultTencentLocationManager";
        r1 = "already register";
        com.tencent.mm.sdk.platformtools.ab.w(r0, r1);	 Catch:{ all -> 0x00ae }
        r0 = 51141; // 0xc7c5 float:7.1664E-41 double:2.5267E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r0);	 Catch:{ all -> 0x00ae }
        goto L_0x004a;
    L_0x00dc:
        r0 = r8.bRt;	 Catch:{ all -> 0x00ae }
        r0.add(r10);	 Catch:{ all -> 0x00ae }
        goto L_0x0051;
    L_0x00e3:
        r3 = r2;
        goto L_0x0071;
    L_0x00e5:
        r0 = r2;
        goto L_0x0081;
    L_0x00e7:
        r0 = 2000; // 0x7d0 float:2.803E-42 double:9.88E-321;
        goto L_0x0090;
    L_0x00ea:
        r0 = "MicroMsg.DefaultTencentLocationManager";
        r3 = "MapReport reportMsg:%s";
        r5 = 1;
        r5 = new java.lang.Object[r5];	 Catch:{ all -> 0x00ae }
        r6 = 0;
        r7 = r1.toString();	 Catch:{ all -> 0x00ae }
        r5[r6] = r7;	 Catch:{ all -> 0x00ae }
        com.tencent.mm.sdk.platformtools.ab.d(r0, r3, r5);	 Catch:{ all -> 0x00ae }
        r0 = r1.toString();	 Catch:{ all -> 0x00ae }
        r4.setSmallAppKey(r0);	 Catch:{ all -> 0x00ae }
        r0 = r8.yg();	 Catch:{ all -> 0x00ae }
        r1 = r8.bRu;	 Catch:{ all -> 0x00ae }
        r3 = com.tencent.mm.plugin.appbrand.r.m.aNS();	 Catch:{ all -> 0x00ae }
        r3 = r3.oAl;	 Catch:{ all -> 0x00ae }
        r3 = r3.getLooper();	 Catch:{ all -> 0x00ae }
        r0 = r0.requestLocationUpdates(r4, r1, r3);	 Catch:{ all -> 0x00ae }
        r1 = "MicroMsg.DefaultTencentLocationManager";
        r3 = "requestCode %d";
        r4 = 1;
        r4 = new java.lang.Object[r4];	 Catch:{ all -> 0x00ae }
        r5 = 0;
        r0 = java.lang.Integer.valueOf(r0);	 Catch:{ all -> 0x00ae }
        r4[r5] = r0;	 Catch:{ all -> 0x00ae }
        com.tencent.mm.sdk.platformtools.ab.i(r1, r3, r4);	 Catch:{ all -> 0x00ae }
    L_0x012b:
        r0 = 51141; // 0xc7c5 float:7.1664E-41 double:2.5267E-319;
        com.tencent.matrix.trace.core.AppMethodBeat.o(r0);	 Catch:{ all -> 0x00ae }
        goto L_0x004a;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tencent.luggage.f.a.a.b(java.lang.String, com.tencent.mm.plugin.appbrand.s.b.a$b, android.os.Bundle):boolean");
    }

    public final synchronized boolean c(String str, b bVar, Bundle bundle) {
        AppMethodBeat.i(51142);
        ab.i("MicroMsg.DefaultTencentLocationManager", "[unregisterLocation]type:%s", new Object[]{str});
        if ("wgs84".equals(str)) {
            this.bRs.remove(bVar);
        } else {
            this.bRt.remove(bVar);
        }
        if (bundle != null) {
            this.bRv.remove(bundle.getString("smallAppKey"));
        }
        yi();
        AppMethodBeat.o(51142);
        return false;
    }

    private void yi() {
        AppMethodBeat.i(51143);
        if (this.bRr.size() <= 0 && this.bRq.size() <= 0 && this.bRs.size() <= 0 && this.bRt.size() <= 0) {
            ab.i("MicroMsg.DefaultTencentLocationManager", "releaseLocationManager");
            yg().removeUpdates(null);
        }
        AppMethodBeat.o(51143);
    }

    static /* synthetic */ com.tencent.mm.plugin.appbrand.s.b.a.a a(TencentLocation tencentLocation, boolean z) {
        String str;
        AppMethodBeat.i(51144);
        com.tencent.mm.plugin.appbrand.s.b.a.a aVar = new com.tencent.mm.plugin.appbrand.s.b.a.a();
        if (z) {
            aVar.latitude = tencentLocation.getLatitude();
            aVar.longitude = tencentLocation.getLongitude();
        } else {
            double[] dArr = new double[2];
            TencentLocationUtils.wgs84ToGcj02(new double[]{tencentLocation.getLatitude(), tencentLocation.getLongitude()}, dArr);
            aVar.latitude = dArr[0];
            aVar.longitude = dArr[1];
        }
        if ("gps".equals(tencentLocation.getProvider())) {
            str = "gps";
        } else {
            str = "network";
        }
        aVar.bIy = str;
        aVar.iSf = (double) tencentLocation.getSpeed();
        aVar.iSg = (double) tencentLocation.getAccuracy();
        aVar.altitude = tencentLocation.getAltitude();
        ab.v("MicroMsg.DefaultTencentLocationManager", "buildingId:%s floorName:%s", new Object[]{tencentLocation.getIndoorBuildingId(), tencentLocation.getIndoorBuildingFloor()});
        if (bo.isNullOrNil(tencentLocation.getIndoorBuildingId())) {
            aVar.buildingId = BuildConfig.FLAVOR;
            aVar.floorName = BuildConfig.FLAVOR;
        } else {
            aVar.buildingId = tencentLocation.getIndoorBuildingId();
            aVar.floorName = tencentLocation.getIndoorBuildingFloor();
        }
        AppMethodBeat.o(51144);
        return aVar;
    }

    static /* synthetic */ void a(List list, int i, String str, com.tencent.mm.plugin.appbrand.s.b.a.a aVar) {
        AppMethodBeat.i(51145);
        for (b bVar : list) {
            if (bVar != null) {
                bVar.a(i, str, aVar);
            }
        }
        AppMethodBeat.o(51145);
    }
}
