apk(点击下载) / hi.java


package com.amap.api.col;

import android.annotation.SuppressLint;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.SystemClock;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import androidx.constraintlayout.core.motion.utils.TypedValues;
import androidx.lifecycle.CoroutineLiveDataKt;
import com.amap.api.col.hj;
import com.autonavi.aps.amapapi.model.AMapLocationServer;
import com.huawei.hms.framework.common.ContainerUtils;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.meizu.cloud.pushsdk.constants.PushConstants;
import com.netease.nim.uikit.business.contact.core.model.ContactGroupStrategy;
import com.netease.nim.uikit.business.session.constant.Extras;
import com.netease.nimlib.jsbridge.interfaces.IJavaReplyToJsFileInfo;
import com.xiaomi.mipush.sdk.Constants;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.TreeMap;
import org.json.JSONObject;

@SuppressLint({"NewApi"})
/* compiled from: APS */
public class hi {
    static long A = 0;
    static long B = 0;
    static int C = -1;
    private static long W = 0;
    private static volatile long X = 0;
    static boolean x = false;
    static int z = -1;
    StringBuilder D = null;
    private volatile Context E = null;
    private ConnectivityManager F = null;
    private volatile hr G = null;
    private volatile hq H = null;
    private ArrayList<ScanResult> I = new ArrayList<>();
    private volatile ArrayList<ScanResult> J = new ArrayList<>();
    private HashMap<String, ArrayList<ScanResult>> K = new HashMap<>();
    private ArrayList<a> L = new ArrayList<>();
    private ArrayList<a> M = new ArrayList<>();
    private d N = null;
    private volatile WifiInfo O = null;
    private JSONObject P = null;
    private volatile AMapLocationServer Q = null;
    private volatile long R = 0;
    private long S = 0;
    private long T = 0;
    private volatile boolean U = false;
    private boolean V = false;
    private int Y = 0;
    private volatile String Z = "00:00:00:00:00:00";
    Object a = new Object();
    private boolean aA = false;
    private Map<String, String> aB = new HashMap();
    private id aa = null;
    private volatile Timer ab = null;
    private volatile TimerTask ac = null;
    private int ad = 0;
    private Object ae = null;
    private volatile Object af = null;
    private boolean ag = false;
    private boolean ah = false;
    private String ai = null;
    private String aj = null;
    private long ak = 0;
    private volatile long al = 0;
    private volatile String am = null;
    private hp an = null;
    private ia ao = null;
    private StringBuilder ap = new StringBuilder();
    private boolean aq = true;
    private boolean ar = true;
    private volatile boolean as = true;
    private boolean at = false;
    private boolean au = false;
    private boolean av = false;
    private boolean aw = false;
    private boolean ax = false;
    private String ay = null;
    private String az = null;
    hj b;
    volatile int c = -1;

    /* renamed from: d  reason: collision with root package name */
    boolean f1041d = false;
    Object e = new Object();
    public boolean f = false;
    public String g = "com.data.carrier_v4.CollectorManager";
    public String h = "com.autonavi.aps.amapapi.offline.Off";
    BluetoothAdapter i = null;
    boolean j = false;
    c k = null;
    boolean l = false;
    volatile boolean m = false;
    int n = 12;
    boolean o = false;
    StringBuilder p = null;
    StringBuilder q = null;
    String r = null;
    TreeMap<Integer, ScanResult> s = null;
    boolean t = true;
    boolean u = true;
    boolean v = false;
    boolean w = true;
    b y = new b();

    /* compiled from: APS */
    public static class a implements Comparable<a> {
        public String a = null;
        public String b = null;
        public byte[] c = null;

        /* renamed from: d  reason: collision with root package name */
        public String f1042d = null;
        public String e = null;
        public int f = 0;
        public int g = 0;
        public String h = null;
        public long i = 0;
        public int j = 0;

        public a(String str, String str2, byte[] bArr, String str3, int i2, int i3, int i4, int i5, long j2) {
            this.a = str;
            this.b = str2;
            this.c = bArr;
            String upperCase = Integer.toHexString(i2).trim().toUpperCase(Locale.CHINA);
            this.f1042d = upperCase;
            if (upperCase.length() < 4) {
                String str4 = this.f1042d + "00000";
                this.f1042d = str4;
                this.f1042d = str4.substring(0, 4);
            }
            String upperCase2 = Integer.toHexString(i3).trim().toUpperCase(Locale.CHINA);
            this.e = upperCase2;
            if (upperCase2.length() < 4) {
                String str5 = this.e + "00000";
                this.e = str5;
                this.e = str5.substring(0, 4);
            }
            this.f = i4;
            this.g = i5;
            this.i = j2;
            this.h = str3;
        }

        /* renamed from: a */
        public int compareTo(a aVar) {
            int i2 = this.g;
            int i3 = aVar.g;
            if (i2 < i3) {
                return 1;
            }
            return (i2 != i3 && i2 > i3) ? -1 : 0;
        }

        public String toString() {
            return "name = " + this.b + ",uuid = " + this.a + ",major = " + this.f1042d + ",minor = " + this.e + ",TxPower = " + this.f + ",rssi = " + this.g + ",time = " + this.i;
        }
    }

    /* access modifiers changed from: package-private */
    /* compiled from: APS */
    public class b implements hj.a {
        b() {
        }

        @Override // com.amap.api.col.hj.a
        public void a(int i) {
            hi.this.c = i;
        }
    }

    /* access modifiers changed from: package-private */
    @SuppressLint({"NewApi"})
    /* compiled from: APS */
    public class c implements BluetoothAdapter.LeScanCallback {
        c() {
        }

        public void onLeScan(BluetoothDevice bluetoothDevice, int i, byte[] bArr) {
            try {
                a a2 = hi.this.a(bluetoothDevice, i, bArr);
                synchronized (hi.this.a) {
                    int i2 = 0;
                    while (i2 < hi.this.L.size()) {
                        a aVar = (a) hi.this.L.get(i2);
                        if (aVar.h.equals(a2.h)) {
                            hi.this.L.remove(aVar);
                            hi.this.L.add(a2);
                            return;
                        }
                        if (il.b() - aVar.i > 3000) {
                            hi.this.L.remove(aVar);
                            i2--;
                        }
                        i2++;
                    }
                    hi.this.L.add(a2);
                }
            } catch (Throwable th) {
                f.a(th, "APS", "onLeScan");
            }
        }
    }

    /* access modifiers changed from: private */
    /* compiled from: APS */
    public class d extends BroadcastReceiver {
        public void onReceive(Context context, Intent intent) {
            int i;
            if (context != null && intent != null) {
                try {
                    String action = intent.getAction();
                    if (!TextUtils.isEmpty(action)) {
                        hr hrVar = hi.this.G;
                        if (action.equals("android.net.wifi.SCAN_RESULTS")) {
                            if (hrVar != null && il.b() - hi.X > CoroutineLiveDataKt.DEFAULT_TIMEOUT) {
                                List<ScanResult> list = null;
                                try {
                                    list = hrVar.a();
                                } catch (Throwable th) {
                                    f.a(th, "APS", "onReceive part1");
                                }
                                if (list != null) {
                                    synchronized (hi.this.e) {
                                        hi.this.J.clear();
                                        hi.this.J.addAll(list);
                                        long unused = hi.X = il.b();
                                    }
                                    return;
                                }
                                synchronized (hi.this.e) {
                                    hi.this.J.clear();
                                }
                            }
                        } else if (action.equals("android.net.wifi.WIFI_STATE_CHANGED")) {
                            if (hi.this.G != null) {
                                try {
                                    i = hrVar.c();
                                } catch (Throwable th2) {
                                    f.a(th2, "APS", "onReceive part");
                                    i = 4;
                                }
                                if (hi.this.J == null) {
                                    hi.this.J = new ArrayList();
                                }
                                if (i == 0) {
                                    hi.this.w();
                                } else if (i == 1) {
                                    hi.this.w();
                                } else if (i == 4) {
                                    hi.this.w();
                                }
                            }
                        } else if (action.equals("android.intent.action.SCREEN_ON")) {
                            hi.this.u = true;
                        } else if (action.equals("android.intent.action.SCREEN_OFF")) {
                            hi hiVar = hi.this;
                            hiVar.u = false;
                            if (hiVar.ae != null) {
                                hi.this.D();
                            }
                        } else if (!action.equals("android.intent.action.AIRPLANE_MODE") && action.equals("android.net.conn.CONNECTIVITY_CHANGE") && hi.this.H()) {
                            hi.this.a((hi) true, true);
                        }
                    }
                } catch (Throwable th3) {
                    f.a(th3, "APS", "onReceive");
                }
            }
        }

        private d() {
        }
    }

    private boolean A() {
        try {
            return ((Boolean) ig.a(this.ae, "isStarted", new Object[0])).booleanValue();
        } catch (Throwable unused) {
            return false;
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:16:0x0035  */
    /* JADX WARNING: Removed duplicated region for block: B:18:0x0039  */
    private void B() {
        boolean z2;
        if (y()) {
            if (!ie.t()) {
                D();
                return;
            }
            if (il.a(this.P, "coll")) {
                try {
                    z2 = !this.P.getString("coll").equals(PushConstants.PUSH_TYPE_NOTIFY);
                } catch (Throwable th) {
                    f.a(th, "APS", "start3rdCM");
                }
                if (z2) {
                    D();
                    return;
                } else if (!z()) {
                    try {
                        C();
                        int i2 = 0;
                        try {
                            ig.a(this.ae, Extras.EXTRA_START, new Object[0]);
                            i2 = 1;
                        } catch (Throwable unused) {
                        }
                        if (this.E != null && !x) {
                            this.ax = true;
                            ii.b(this.E, "Collertor", i2);
                            return;
                        }
                        return;
                    } catch (Throwable th2) {
                        f.a(th2, "APS", "start3rdCM");
                        return;
                    }
                } else {
                    return;
                }
            }
            z2 = true;
            if (z2) {
            }
        }
    }

    private void C() {
        if (y() && y() && F() > 0) {
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void D() {
        if (y() && z()) {
            f.f = 20;
            try {
                ig.a(this.ae, "destroy", new Object[0]);
            } catch (Throwable th) {
                f.a(th, "APS", "stop3rdCM");
            }
        }
    }

    private void E() {
        if (this.E != null && !TextUtils.isEmpty(this.Z)) {
            SharedPreferences sharedPreferences = this.E.getSharedPreferences("pref", 0);
            String str = null;
            try {
                str = ew.a(this.Z.getBytes("UTF-8"));
            } catch (Throwable th) {
                f.a(th, "APS", "setSmac");
            }
            if (!TextUtils.isEmpty(str)) {
                sharedPreferences.edit().putString("smac", str).commit();
            }
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private int F() {
        try {
            return ((Integer) ig.a(this.ae, "getLeftUploadNum", new Object[0])).intValue();
        } catch (Throwable unused) {
            return 0;
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private synchronized void G() {
        if (this.ac != null) {
            this.ac.cancel();
            this.ac = null;
        }
        if (this.ab != null) {
            this.ab.cancel();
            this.ab.purge();
            this.ab = null;
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private boolean H() {
        if (this.G == null || this.F == null) {
            return false;
        }
        return this.G.a(this.F);
    }

    private String I() {
        try {
            Object obj = this.ae;
            if (obj == null) {
                return null;
            }
            return (String) ig.a(obj, "getInnerString", "version");
        } catch (Throwable th) {
            f.a(th, "APS", "getCollVer");
            return null;
        }
    }

    private void J() {
        if (this.G != null && this.E != null && this.ag) {
            this.G.a(this.ag);
        }
    }

    private void K() {
        try {
            this.am = null;
            this.Q = null;
            b((JSONObject) null);
            this.al = 0;
            this.R = 0;
            hl.a().b();
        } catch (Throwable th) {
            f.a(th, "APS", "cleanCache");
        }
    }

    private boolean L() {
        return ie.f() && this.af != null && ie.u();
    }

    private boolean m() {
        try {
            BluetoothAdapter bluetoothAdapter = this.i;
            return bluetoothAdapter != null && bluetoothAdapter.isEnabled() && ie.A() && il.c() >= 18;
        } catch (Throwable unused) {
            return false;
        }
    }

    private void n() {
        boolean z2;
        boolean z3;
        boolean z4;
        boolean z5 = true;
        try {
            z2 = il.a(this.P, "reversegeo") ? this.P.getBoolean("reversegeo") : true;
            try {
                z3 = il.a(this.P, "isOffset") ? this.P.getBoolean("isOffset") : true;
            } catch (Throwable unused) {
                z4 = true;
                z3 = z5;
                z5 = z4;
                this.ar = z3;
                this.aq = z2;
                this.as = z5;
                this.U = il.a(this.E);
            }
            try {
                if (il.a(this.P, "isLocationCacheEnable")) {
                    z5 = this.P.getBoolean("isLocationCacheEnable");
                }
            } catch (Throwable unused2) {
                z5 = z3;
                z4 = true;
                z3 = z5;
                z5 = z4;
                this.ar = z3;
                this.aq = z2;
                this.as = z5;
                this.U = il.a(this.E);
            }
            try {
                if (il.a(this.P, "isWifiPassiveScan")) {
                    this.w = this.P.getBoolean("isWifiPassiveScan");
                }
                if (il.a(this.P, "isMock")) {
                    this.l = this.P.getBoolean("isMock");
                }
                if (!(z3 == this.ar && z2 == this.aq && z5 == this.as)) {
                    K();
                }
                if (il.c() < 18 && il.c() > 3 && il.a(this.P, "wifiactivescan")) {
                    try {
                        this.v = "1".equals(this.P.getString("wifiactivescan"));
                    } catch (Throwable th) {
                        f.a(th, "APS", "updateWifi part1");
                    }
                }
            } catch (Throwable unused3) {
                z4 = z5;
                z5 = z3;
                z3 = z5;
                z5 = z4;
                this.ar = z3;
                this.aq = z2;
                this.as = z5;
                this.U = il.a(this.E);
            }
        } catch (Throwable unused4) {
            z4 = true;
            z2 = true;
            z3 = z5;
            z5 = z4;
            this.ar = z3;
            this.aq = z2;
            this.as = z5;
            this.U = il.a(this.E);
        }
        this.ar = z3;
        this.aq = z2;
        this.as = z5;
        this.U = il.a(this.E);
    }

    private void o() {
        try {
            if (il.c() >= 18 && this.i != null) {
                if (this.k == null) {
                    this.k = new c();
                }
                if (this.j) {
                    this.i.stopLeScan(this.k);
                }
                this.j = false;
                this.M.clear();
                this.L.clear();
            }
        } catch (Throwable unused) {
        }
    }

    private void p() {
        try {
            if (L()) {
                ig.a(this.af, "resetPureOfflineCache", new Object[0]);
            }
        } catch (Throwable unused) {
        }
    }

    private void q() {
        try {
            if (this.N == null) {
                this.N = new d();
            }
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction("android.net.wifi.WIFI_STATE_CHANGED");
            intentFilter.addAction("android.net.wifi.SCAN_RESULTS");
            intentFilter.addAction("android.intent.action.SCREEN_ON");
            intentFilter.addAction("android.intent.action.SCREEN_OFF");
            intentFilter.addAction("android.intent.action.AIRPLANE_MODE");
            intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
            this.E.registerReceiver(this.N, intentFilter);
            h();
        } catch (Throwable th) {
            f.a(th, "APS", "initBroadcastListener");
        }
    }

    private void r() {
        this.H.a();
    }

    /* JADX WARNING: Removed duplicated region for block: B:128:0x036d  */
    /* JADX WARNING: Removed duplicated region for block: B:129:0x0373  */
    /* JADX WARNING: Removed duplicated region for block: B:132:0x0382 A[SYNTHETIC, Splitter:B:132:0x0382] */
    /* JADX WARNING: Removed duplicated region for block: B:140:0x03aa  */
    /* JADX WARNING: Removed duplicated region for block: B:141:0x03ae  */
    /* JADX WARNING: Removed duplicated region for block: B:144:0x03f5  */
    /* JADX WARNING: Removed duplicated region for block: B:145:0x03f8  */
    /* JADX WARNING: Removed duplicated region for block: B:148:0x0471  */
    private void s() throws Throwable {
        hq hqVar;
        NetworkInfo networkInfo;
        String str;
        String str2;
        int i2;
        String str3;
        String str4;
        boolean z2;
        int i3;
        String str5 = PushConstants.PUSH_TYPE_NOTIFY;
        String f2 = er.f(this.E);
        int a2 = il.a(-32768, 32767);
        String str6 = "api_serverSDK_130905";
        String str7 = "S128DF1572465B890OE3F7A13167KLEI";
        if (this.aa == null) {
            this.aa = new id();
        }
        if (!this.ar) {
            str6 = "UC_nlp_20131029";
            str7 = "BKZCHMBBSSUK7U8GLUKHBB56CCFF78U";
        }
        StringBuilder sb = this.p;
        if (sb == null) {
            this.p = new StringBuilder();
        } else {
            sb.delete(0, sb.length());
        }
        StringBuilder sb2 = this.q;
        if (sb2 == null) {
            this.q = new StringBuilder();
        } else {
            sb2.delete(0, sb2.length());
        }
        hq hqVar2 = this.H;
        int d2 = hqVar2.d();
        int e2 = hqVar2.e();
        TelephonyManager g2 = hqVar2.g();
        ArrayList<hp> b2 = hqVar2.b();
        ArrayList<hp> n2 = hqVar2.n();
        if (e2 == 2) {
            str5 = "1";
        }
        if (g2 != null) {
            if (TextUtils.isEmpty(f.a)) {
                try {
                    f.a = ev.q(this.E);
                } catch (Throwable th) {
                    hqVar = hqVar2;
                    f.a(th, "APS", "getApsReq part4");
                }
            }
            hqVar = hqVar2;
            if (TextUtils.isEmpty(f.a)) {
                f.a = "888888888888888";
            }
            if (TextUtils.isEmpty(f.b)) {
                try {
                    f.b = g2.getSubscriberId();
                } catch (Throwable th2) {
                    f.a(th2, "APS", "getApsReq part2");
                }
            }
            if (TextUtils.isEmpty(f.b)) {
                f.b = "888888888888888";
            }
        } else {
            hqVar = hqVar2;
        }
        try {
            networkInfo = this.F.getActiveNetworkInfo();
        } catch (Throwable th3) {
            f.a(th3, "APS", "getApsReq part");
            networkInfo = null;
        }
        if (il.a(networkInfo) != -1) {
            String b3 = il.b(g2);
            str = (!this.t || !this.G.a(this.O)) ? "1" : PushConstants.PUSH_TYPE_UPLOAD_LOG;
            str2 = b3;
        } else {
            this.O = null;
            str2 = "";
            str = "";
        }
        if (!b2.isEmpty()) {
            StringBuilder sb3 = new StringBuilder();
            if (e2 == 1) {
                i2 = a2;
                str3 = str2;
                a("resetCdmaData");
                hp hpVar = b2.get(0);
                sb3.delete(0, sb3.length());
                sb3.append("<mcc>");
                sb3.append(hpVar.a);
                sb3.append("</mcc>");
                sb3.append("<mnc>");
                sb3.append(hpVar.b);
                sb3.append("</mnc>");
                sb3.append("<lac>");
                sb3.append(hpVar.c);
                sb3.append("</lac>");
                sb3.append("<cellid>");
                sb3.append(hpVar.f1047d);
                sb3.append("</cellid>");
                sb3.append("<signal>");
                sb3.append(hpVar.j);
                sb3.append("</signal>");
                str4 = sb3.toString();
                int i4 = 1;
                while (i4 < b2.size()) {
                    hp hpVar2 = b2.get(i4);
                    StringBuilder sb4 = this.p;
                    sb4.append(hpVar2.c);
                    sb4.append(Constants.ACCEPT_TIME_SEPARATOR_SP);
                    StringBuilder sb5 = this.p;
                    sb5.append(hpVar2.f1047d);
                    sb5.append(Constants.ACCEPT_TIME_SEPARATOR_SP);
                    this.p.append(hpVar2.j);
                    if (i4 < b2.size() - 1) {
                        this.p.append("*");
                    }
                    i4++;
                    str4 = str4;
                }
            } else if (e2 != 2) {
                a("resetCdmaData");
                i2 = a2;
                str3 = str2;
                str4 = "";
            } else {
                hp hpVar3 = b2.get(0);
                sb3.delete(0, sb3.length());
                sb3.append("<mcc>");
                sb3.append(hpVar3.a);
                sb3.append("</mcc>");
                sb3.append("<sid>");
                sb3.append(hpVar3.g);
                sb3.append("</sid>");
                sb3.append("<nid>");
                sb3.append(hpVar3.h);
                sb3.append("</nid>");
                sb3.append("<bid>");
                sb3.append(hpVar3.i);
                sb3.append("</bid>");
                if (hpVar3.f <= 0 || hpVar3.e <= 0) {
                    i2 = a2;
                    str3 = str2;
                    a("resetCdmaData");
                } else {
                    if (L()) {
                        i2 = a2;
                        str3 = str2;
                        ig.a(this.af, "setCdmaLatLon", Integer.valueOf(hpVar3.e), Integer.valueOf(hpVar3.f));
                    } else {
                        i2 = a2;
                        str3 = str2;
                    }
                    sb3.append("<lon>");
                    sb3.append(hpVar3.f);
                    sb3.append("</lon>");
                    sb3.append("<lat>");
                    sb3.append(hpVar3.e);
                    sb3.append("</lat>");
                }
                sb3.append("<signal>");
                sb3.append(hpVar3.j);
                sb3.append("</signal>");
                str4 = sb3.toString();
            }
            sb3.delete(0, sb3.length());
        } else {
            i2 = a2;
            str3 = str2;
            str4 = "";
        }
        if ((d2 & 4) != 4 || n2.isEmpty()) {
            this.aa.C.clear();
        } else {
            this.aa.C.clear();
            this.aa.C.addAll(n2);
        }
        if (x()) {
            if (this.G.a(this.O)) {
                StringBuilder sb6 = this.q;
                sb6.append(this.O.getBSSID());
                sb6.append(Constants.ACCEPT_TIME_SEPARATOR_SP);
                int rssi = this.O.getRssi();
                if (rssi < -128 || rssi > 127) {
                    rssi = 0;
                }
                StringBuilder sb7 = this.q;
                sb7.append(rssi);
                sb7.append(Constants.ACCEPT_TIME_SEPARATOR_SP);
                String ssid = this.O.getSSID();
                try {
                    i3 = this.O.getSSID().getBytes("UTF-8").length;
                } catch (Exception unused) {
                    i3 = 32;
                }
                if (i3 >= 32) {
                    ssid = "unkwn";
                }
                this.q.append(ssid.replace("*", "."));
            }
            if (this.I != null) {
                synchronized (this.e) {
                    ArrayList<ScanResult> arrayList = this.aa.F;
                    if (arrayList != null) {
                        arrayList.clear();
                        this.aa.F.addAll(this.I);
                    }
                }
            }
        } else {
            w();
            ArrayList<ScanResult> arrayList2 = this.aa.F;
            if (arrayList2 != null) {
                arrayList2.clear();
            }
        }
        if (il.a(this.P, "reversegeo")) {
            try {
                z2 = this.P.getBoolean("reversegeo");
            } catch (Throwable th4) {
                f.a(th4, "APS", "getApsReq part");
            }
            if (z2) {
                this.aa.b = 2;
            } else {
                this.aa.b = 0;
            }
            if (il.a(this.P, "multi")) {
                try {
                    if (this.P.getString("multi").equals("1")) {
                        id idVar = this.aa;
                        idVar.b = (short) (idVar.b + 1);
                    }
                } catch (Throwable th5) {
                    f.a(th5, "APS", "getApsReq");
                }
            }
            if (!m()) {
                f();
            } else {
                this.M.clear();
                this.aa.G.clear();
            }
            id idVar2 = this.aa;
            idVar2.c = str6;
            idVar2.f1055d = str7;
            idVar2.f = il.e();
            id idVar3 = this.aa;
            idVar3.g = "android" + il.f();
            this.aa.h = il.b(this.E);
            id idVar4 = this.aa;
            idVar4.i = str5;
            idVar4.j = PushConstants.PUSH_TYPE_NOTIFY;
            idVar4.k = !this.V ? "1" : PushConstants.PUSH_TYPE_NOTIFY;
            idVar4.l = PushConstants.PUSH_TYPE_NOTIFY;
            idVar4.m = PushConstants.PUSH_TYPE_NOTIFY;
            idVar4.n = PushConstants.PUSH_TYPE_NOTIFY;
            idVar4.o = f2;
            idVar4.p = f.a;
            idVar4.q = f.b;
            idVar4.s = String.valueOf(i2);
            this.aa.t = this.Z;
            this.aa.v = d();
            this.aa.w = I();
            id idVar5 = this.aa;
            idVar5.u = "";
            idVar5.x = str3;
            idVar5.y = str;
            idVar5.z = d2;
            idVar5.A = str4;
            idVar5.B = this.p.toString();
            this.aa.D = hqVar.m();
            this.aa.H = String.valueOf(il.b() - X);
            this.aa.E = this.q.toString();
            this.aa.G = this.M;
            if (TextUtils.isEmpty(this.r)) {
                this.r = ev.f(this.E);
            }
            this.aa.K = this.r;
            StringBuilder sb8 = this.p;
            sb8.delete(0, sb8.length());
            StringBuilder sb9 = this.q;
            sb9.delete(0, sb9.length());
        }
        z2 = true;
        if (z2) {
        }
        if (il.a(this.P, "multi")) {
        }
        if (!m()) {
        }
        id idVar22 = this.aa;
        idVar22.c = str6;
        idVar22.f1055d = str7;
        idVar22.f = il.e();
        id idVar32 = this.aa;
        idVar32.g = "android" + il.f();
        this.aa.h = il.b(this.E);
        id idVar42 = this.aa;
        idVar42.i = str5;
        idVar42.j = PushConstants.PUSH_TYPE_NOTIFY;
        idVar42.k = !this.V ? "1" : PushConstants.PUSH_TYPE_NOTIFY;
        idVar42.l = PushConstants.PUSH_TYPE_NOTIFY;
        idVar42.m = PushConstants.PUSH_TYPE_NOTIFY;
        idVar42.n = PushConstants.PUSH_TYPE_NOTIFY;
        idVar42.o = f2;
        idVar42.p = f.a;
        idVar42.q = f.b;
        idVar42.s = String.valueOf(i2);
        this.aa.t = this.Z;
        this.aa.v = d();
        this.aa.w = I();
        id idVar52 = this.aa;
        idVar52.u = "";
        idVar52.x = str3;
        idVar52.y = str;
        idVar52.z = d2;
        idVar52.A = str4;
        idVar52.B = this.p.toString();
        this.aa.D = hqVar.m();
        this.aa.H = String.valueOf(il.b() - X);
        this.aa.E = this.q.toString();
        this.aa.G = this.M;
        if (TextUtils.isEmpty(this.r)) {
        }
        this.aa.K = this.r;
        StringBuilder sb82 = this.p;
        sb82.delete(0, sb82.length());
        StringBuilder sb92 = this.q;
        sb92.delete(0, sb92.length());
    }

    private void t() {
        long b2 = il.b();
        if (u() || il.b() - X > CoroutineLiveDataKt.DEFAULT_TIMEOUT) {
            if (b2 - this.S >= 10000) {
                synchronized (this.e) {
                    this.J.clear();
                }
            }
            h();
            if (b2 - this.S >= 10000) {
                for (int i2 = 20; i2 > 0 && this.J.isEmpty(); i2--) {
                    try {
                        Thread.sleep(3000 / ((long) 20));
                    } catch (Throwable unused) {
                    }
                }
            }
            synchronized (this.e) {
            }
        }
        if (this.J.isEmpty() && this.G != null) {
            X = il.b();
            List<ScanResult> a2 = this.G.a();
            if (a2 != null) {
                synchronized (this.e) {
                    this.J.addAll(a2);
                }
            }
        }
    }

    private boolean u() {
        if (!x()) {
            this.t = false;
        } else if (W == 0) {
            return true;
        } else {
            if (il.b() - W >= CoroutineLiveDataKt.DEFAULT_TIMEOUT && il.b() - X >= 1500) {
                return true;
            }
        }
        return false;
    }

    private boolean v() {
        if (this.R != 0 && il.b() - this.R <= 20000) {
            return false;
        }
        return true;
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void w() {
        this.O = null;
        synchronized (this.e) {
            this.J.clear();
            this.K.clear();
        }
    }

    private boolean x() {
        if (this.G != null) {
            return this.G.f();
        }
        return false;
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private boolean y() {
        return this.ae != null;
    }

    private boolean z() {
        try {
            if (!y()) {
                return false;
            }
            return A();
        } catch (Throwable th) {
            f.a(th, "APS", "collStarted");
            return false;
        }
    }

    public String d() {
        return "3.2.1";
    }

    private void c(Context context) {
        try {
            if (this.E == null) {
                this.E = context.getApplicationContext();
                ie.e(this.E);
                il.b(this.E);
                if (this.G == null) {
                    this.G = new hr(this.E, (WifiManager) il.a(this.E, "wifi"), this.P);
                }
                if (this.H == null) {
                    this.H = new hq(this.E, this.P);
                }
            }
        } catch (Throwable th) {
            f.a(th, "APS", "initBase");
        }
    }

    private void d(Context context) {
        try {
            if (this.ae == null && !this.av) {
                fa a2 = f.a("Collection", "1.0.0");
                boolean a3 = ii.a(context, a2);
                this.av = a3;
                int i2 = 1;
                if (a3) {
                    try {
                        this.ae = gd.a(context, a2, this.g, null, new Class[]{Context.class}, new Object[]{context});
                    } catch (Throwable unused) {
                    }
                    if (this.ae == null) {
                        i2 = 0;
                    }
                    ii.a(context, "Collertor", i2);
                    return;
                }
                this.av = true;
            }
        } catch (Throwable th) {
            f.a(th, "APS", "initCollection");
        }
    }

    private void e(Context context) {
        try {
            if (ie.u() && this.af == null && !this.aw) {
                fa a2 = f.a("OfflineLocation", "1.0.0");
                boolean a3 = ii.a(context, a2);
                this.aw = a3;
                int i2 = 1;
                if (a3) {
                    try {
                        this.af = gd.a(context, a2, this.h, null, new Class[]{Context.class}, new Object[]{context});
                    } catch (Throwable unused) {
                    }
                    if (this.af == null) {
                        i2 = 0;
                    }
                    ii.a(context, "OffLocation", i2);
                    return;
                }
                this.aw = true;
            }
        } catch (Throwable th) {
            f.a(th, "APS", "initOffLocation");
        }
    }

    public void b() {
        try {
            a(this.E, this.P);
            a(a(true, true, true));
        } catch (Throwable th) {
            f.a(th, "APS", "doFusionLocation");
        }
    }

    public synchronized void f() {
        ArrayList<a> arrayList = this.M;
        ArrayList<a> arrayList2 = this.L;
        arrayList.clear();
        synchronized (this.a) {
            if (arrayList2 != null) {
                if (arrayList2.size() > 0) {
                    if (arrayList2.size() > 20) {
                        Collections.sort(arrayList2);
                    }
                    int i2 = 0;
                    while (true) {
                        if (i2 >= arrayList2.size()) {
                            break;
                        }
                        arrayList.add(arrayList2.get(i2));
                        if (i2 >= 30) {
                            break;
                        }
                        i2++;
                    }
                }
            }
        }
    }

    public synchronized void g() {
        int i2;
        ArrayList<ScanResult> arrayList = this.I;
        if (arrayList != null) {
            if (!arrayList.isEmpty()) {
                if (il.b() - X > 3600000) {
                    w();
                    this.I.clear();
                }
                boolean g2 = il.g();
                if (il.a(this.P, "nbssid")) {
                    try {
                        if (this.P.getString("nbssid").equals("1")) {
                            g2 = true;
                        } else if (this.P.getString("nbssid").equals(PushConstants.PUSH_TYPE_NOTIFY)) {
                            g2 = false;
                        }
                    } catch (Throwable th) {
                        f.a(th, "APS", "setWifiOrder part");
                    }
                }
                if (this.s == null) {
                    this.s = new TreeMap<>(Collections.reverseOrder());
                }
                this.s.clear();
                int size = this.I.size();
                for (int i3 = 0; i3 < size; i3++) {
                    ScanResult scanResult = this.I.get(i3);
                    if (il.b(scanResult != null ? scanResult.BSSID : "") && (size <= 20 || a(scanResult.level))) {
                        if (TextUtils.isEmpty(scanResult.SSID)) {
                            scanResult.SSID = "unkwn";
                        } else if (g2) {
                            String replace = scanResult.SSID.replace("*", ".");
                            scanResult.SSID = replace;
                            try {
                                i2 = replace.getBytes("UTF-8").length;
                            } catch (Throwable th2) {
                                f.a(th2, "APS", "setWifiOrder");
                                i2 = 32;
                            }
                            if (i2 >= 32 && !"<unknown ssid>".equals(scanResult.SSID)) {
                                scanResult.SSID = String.valueOf(i3);
                            }
                        } else if (!"<unknown ssid>".equals(scanResult.SSID)) {
                            scanResult.SSID = String.valueOf(i3);
                        }
                        this.s.put(Integer.valueOf((scanResult.level * 30) + i3), scanResult);
                    }
                }
                this.I.clear();
                for (ScanResult scanResult2 : this.s.values()) {
                    this.I.add(scanResult2);
                }
                this.s.clear();
            }
        }
    }

    public void h() {
        if (this.w) {
            boolean z2 = false;
            if (this.v) {
                try {
                    z2 = this.G.e();
                    if (z2) {
                        W = il.b();
                    }
                } catch (Throwable th) {
                    f.a(th, "APS", "updateWifi part");
                }
            }
            if (!z2) {
                try {
                    if (this.G.d()) {
                        W = il.b();
                    }
                } catch (Throwable th2) {
                    f.a(th2, "APS", "updateWifi");
                }
            }
        }
    }

    public boolean i() {
        try {
            if (this.E == null) {
                return false;
            }
            if (il.b() - A >= ((long) ie.y())) {
                A = il.b();
                if (il.e(this.E) > C) {
                    return true;
                }
            }
            if (il.b() - B >= ((long) ie.z())) {
                return true;
            }
            return false;
        } catch (Throwable th) {
            f.a(th, "APS", "isConfigNeedUpdate");
        }
    }

    public synchronized AMapLocationServer j() {
        AMapLocationServer aMapLocationServer;
        if (this.ap.length() > 0) {
            StringBuilder sb = this.ap;
            sb.delete(0, sb.length());
        }
        if (TextUtils.isEmpty(this.ay)) {
            aMapLocationServer = new AMapLocationServer("");
            aMapLocationServer.setErrorCode(this.n);
            aMapLocationServer.setLocationDetail(this.ap.toString());
        } else {
            if (!ht.a().d()) {
                ht.a().a(this.E, ht.a().a(this.az, this.D, this.E));
            }
            aMapLocationServer = ht.a().a(this.az, this.D, this.as);
            if (il.a(aMapLocationServer)) {
                this.al = 0;
                aMapLocationServer.setLocationType(4);
                this.Q = aMapLocationServer;
                b(aMapLocationServer.a(1));
                p();
                return aMapLocationServer;
            }
        }
        return aMapLocationServer;
    }

    public void k() {
        if (ie.t()) {
            d(this.E);
        }
        if (this.u && ie.t() && !z()) {
            B();
        }
    }

    private void b(JSONObject jSONObject) {
        try {
            if (L()) {
                ig.a(this.af, "setLastLoc", jSONObject);
            }
        } catch (Throwable unused) {
        }
    }

    public synchronized void a(Context context) {
        c(context);
        c(true);
        f.g = true;
        e(this.E);
        this.T = il.b();
        if (!this.at) {
            q();
            this.at = true;
        }
        r();
        this.H.f();
        ht.a().a(this.E, (String) null);
        hw.a().a(this.E);
        f(this.E);
        try {
            if (il.c() >= 18 && this.ah) {
                this.i = BluetoothAdapter.getDefaultAdapter();
            }
        } catch (Throwable unused) {
        }
        this.f = true;
    }

    private boolean b(long j2) {
        if (il.b() - j2 < 800) {
            long j3 = 0;
            if (il.a(this.Q)) {
                j3 = il.a() - this.Q.getTime();
            }
            return j3 <= 10000;
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    /* JADX WARNING: Removed duplicated region for block: B:25:0x0052  */
    /* JADX WARNING: Removed duplicated region for block: B:38:0x0098  */
    /* JADX WARNING: Removed duplicated region for block: B:43:? A[RETURN, SYNTHETIC] */
    private void b(int i2) {
        Object obj;
        if (y() && ie.t()) {
            int i3 = 674234367;
            if (i2 != 0) {
                if (i2 != 1) {
                    if (i2 == 2) {
                        try {
                            if (H()) {
                                i3 = 2083520511;
                            }
                        } catch (Throwable th) {
                            f.a(th, "APS", "up");
                            return;
                        }
                    }
                }
                ig.a(this.ae, "callBackWrapData", a(1, i3, 1));
                obj = ig.a(this.ae, "getReportDate", new Object[0]);
                if (obj != null) {
                    String a2 = this.ao.a((byte[]) obj, this.E, "http://cgicol.amap.com/collection/writedata?ver=v1.0_ali&", false);
                    if (y()) {
                        try {
                            this.ad = ((Integer) ig.a(this.ae, "setUploadResult", a2, Integer.valueOf(i3))).intValue();
                        } catch (Throwable unused) {
                            this.ad = 3;
                        }
                    }
                }
                C();
                if (!y() && F() == 0) {
                    G();
                    return;
                } else if (this.ad < 3) {
                    G();
                    return;
                } else {
                    return;
                }
            }
            i3 = 70254591;
            try {
                ig.a(this.ae, "callBackWrapData", a(1, i3, 1));
            } catch (Throwable th2) {
                th2.printStackTrace();
            }
            try {
                obj = ig.a(this.ae, "getReportDate", new Object[0]);
            } catch (Throwable unused2) {
                obj = null;
            }
            if (obj != null) {
            }
            C();
            if (!y()) {
            }
            if (this.ad < 3) {
            }
        }
    }

    public synchronized void e() {
        ArrayList<ScanResult> arrayList = this.I;
        ArrayList<ScanResult> arrayList2 = this.J;
        arrayList.clear();
        synchronized (this.e) {
            if (arrayList2 != null) {
                if (arrayList2.size() > 0) {
                    arrayList.addAll(arrayList2);
                }
            }
        }
    }

    private void c(boolean z2) {
        this.ao = ia.a(this.E, z2);
        if (this.F == null) {
            this.F = (ConnectivityManager) il.a(this.E, "connectivity");
        }
        this.aa = new id();
    }

    private void f(Context context) {
        try {
            if (context.checkCallingOrSelfPermission("android.permission.WRITE_SECURE_SETTINGS") == 0) {
                this.ag = true;
            }
            if (context.checkCallingOrSelfPermission("android.permission.BLUETOOTH_ADMIN") == 0 && context.checkCallingOrSelfPermission("android.permission.BLUETOOTH") == 0) {
                this.ah = true;
            }
        } catch (Throwable unused) {
        }
    }

    @SuppressLint({"NewApi"})
    public synchronized void c() {
        AMapLocationServer.I = null;
        this.aA = false;
        this.f = false;
        f.g = false;
        D();
        this.ae = null;
        this.am = null;
        p();
        hj hjVar = this.b;
        if (hjVar != null) {
            hjVar.a();
            this.b = null;
            this.f1041d = false;
            this.c = -1;
        }
        G();
        try {
            hv.a().a(this.E, 1);
        } catch (Throwable th) {
            f.a(th, "APS", "destroy part");
        }
        hl.a().b();
        il.h();
        try {
            if (!(this.E == null || this.N == null)) {
                this.E.unregisterReceiver(this.N);
            }
        } catch (Throwable th2) {
            this.N = null;
            throw th2;
        }
        this.N = null;
        this.at = false;
        if (this.H != null) {
            this.H.i();
        }
        hw.a().b();
        a("stopOff");
        a("destroy");
        this.m = false;
        this.ak = 0;
        w();
        ArrayList<ScanResult> arrayList = this.I;
        if (arrayList != null) {
            arrayList.clear();
        }
        this.Q = null;
        this.E = null;
        TreeMap<Integer, ScanResult> treeMap = this.s;
        if (treeMap != null) {
            treeMap.clear();
            this.s = null;
        }
        this.ae = null;
        this.af = null;
        this.D = null;
        this.p = null;
        this.q = null;
        o();
        this.i = null;
    }

    public void a(JSONObject jSONObject) {
        this.P = jSONObject;
        if (il.a(jSONObject, "collwifiscan")) {
            try {
                String string = this.P.getString("collwifiscan");
                if (TextUtils.isEmpty(string)) {
                    f.f = 20;
                } else {
                    f.f = Integer.parseInt(string) / 1000;
                }
            } catch (Throwable th) {
                f.a(th, "APS", "setExtra");
            }
        }
        n();
    }

    public synchronized void b(Context context) {
        try {
            if (z == -1 || i()) {
                z = 1;
                ie.a(context);
                int s2 = ie.s();
                C = s2;
                il.a(context, s2);
                B = il.b();
                A = il.b();
            }
        } catch (Throwable th) {
            f.a(th, "APS", "initAuth");
        }
        return;
    }

    /* JADX WARNING: Can't wrap try/catch for region: R(7:15|(2:17|18)|19|20|(1:22)(2:23|(1:25))|26|(1:29)) */
    /* JADX WARNING: Code restructure failed: missing block: B:93:0x0191, code lost:
        if ((com.amap.api.col.il.b() - r18.al) < 3000) goto L_0x019a;
     */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Missing exception handler attribute for start block: B:19:0x0056 */
    /* JADX WARNING: Removed duplicated region for block: B:104:0x01b9  */
    /* JADX WARNING: Removed duplicated region for block: B:105:0x01c0  */
    /* JADX WARNING: Removed duplicated region for block: B:116:0x01ed  */
    /* JADX WARNING: Removed duplicated region for block: B:117:0x01f8  */
    /* JADX WARNING: Removed duplicated region for block: B:132:0x026a  */
    /* JADX WARNING: Removed duplicated region for block: B:135:0x0287  */
    /* JADX WARNING: Removed duplicated region for block: B:138:0x02bd  */
    /* JADX WARNING: Removed duplicated region for block: B:22:0x005c A[Catch:{ all -> 0x0075 }] */
    /* JADX WARNING: Removed duplicated region for block: B:23:0x0066 A[Catch:{ all -> 0x0075 }] */
    /* JADX WARNING: Removed duplicated region for block: B:29:0x007d  */
    public synchronized AMapLocationServer a() throws Throwable {
        boolean z2;
        boolean z3;
        boolean z4;
        String str;
        boolean z5;
        hp hpVar;
        if (this.ap.length() > 0) {
            StringBuilder sb = this.ap;
            sb.delete(0, sb.length());
        }
        if (this.E == null) {
            this.ap.append("context is null");
            AMapLocationServer aMapLocationServer = new AMapLocationServer("");
            aMapLocationServer.setErrorCode(1);
            aMapLocationServer.setLocationDetail(this.ap.toString());
            return aMapLocationServer;
        }
        int i2 = this.Y + 1;
        this.Y = i2;
        if (i2 == 1) {
            C();
            J();
            if (this.E != null) {
                if (y()) {
                    ig.a(this.ae, "getColUpHist", new Object[0]);
                }
                if (!L()) {
                    ig.a(this.af, "getOffDlHist", new Object[0]);
                } else if (this.af != null) {
                    ig.a(this.af, "stopOff", new Object[0]);
                    this.m = false;
                }
                if (TextUtils.isEmpty(this.Z)) {
                    a(this.E.getSharedPreferences("pref", 0));
                }
            }
        }
        if (!b(this.R) || !il.a(this.Q)) {
            this.H.a(this.U, false);
            try {
                t();
                this.S = il.b();
                e();
                g();
            } catch (Throwable th) {
                f.a(th, "APS", "getLocation");
            }
            String a2 = a(false);
            this.ay = a2;
            if (!TextUtils.isEmpty(a2)) {
                try {
                    if (L() && !this.m) {
                        ig.a(this.af, "startOff", this.P, this.ay);
                        this.m = true;
                    }
                } catch (Throwable th2) {
                    f.a(th2, "APS", "getLocation:isOffLineLoc");
                }
                this.D = a(this.D, false);
                hp c2 = !this.U ? this.H.c() : null;
                boolean z6 = !(c2 == null && this.an == null) && ((hpVar = this.an) == null || !hpVar.a(c2));
                boolean v2 = v();
                if (this.Q != null) {
                    int size = this.I.size();
                    if (this.Q.getAccuracy() > 299.0f && size > 5) {
                        z2 = true;
                        if (this.Q != null || this.am == null || z2 || z6 || !this.as || !ie.b(this.Q.getTime())) {
                            z3 = z2;
                            z4 = false;
                        } else {
                            boolean a3 = ht.a().a(this.am, this.D.toString());
                            if (!a3) {
                                z5 = a3;
                                if (this.al != 0) {
                                    z3 = z2;
                                } else {
                                    z3 = z2;
                                }
                                z4 = z5;
                            } else {
                                z5 = a3;
                                z3 = z2;
                            }
                            if (il.a(this.Q)) {
                                this.Q.m("mem");
                                this.Q.setLocationType(2);
                                return this.Q;
                            }
                            z4 = z5;
                        }
                        if (z4) {
                            this.al = il.b();
                        } else {
                            this.al = 0;
                        }
                        str = this.aj;
                        if (str != null || this.ay.equals(str)) {
                            if (this.aj != null) {
                                this.ak = il.a();
                                this.aj = this.ay;
                            } else {
                                this.ak = il.a();
                            }
                        } else if (il.a() - this.ak < 3000) {
                            this.ay = this.aj;
                        } else {
                            this.ak = il.a();
                            this.aj = this.ay;
                        }
                        this.az = this.ay + ContainerUtils.FIELD_DELIMITER + this.ar + ContainerUtils.FIELD_DELIMITER + this.aq;
                        AMapLocationServer a4 = (this.as || z3 || v2) ? null : ht.a().a(this.az, this.D, this.as);
                        if ((v2 && !il.a(a4)) || z3) {
                            this.Q = a(false, false, true);
                            if (il.a(this.Q)) {
                                this.Q.m("new");
                                this.am = this.D.toString();
                                this.an = c2;
                                p();
                            }
                        } else if (!v2) {
                            this.Q = a(false, false, true);
                            if (il.a(this.Q)) {
                                this.am = this.D.toString();
                                this.an = c2;
                                p();
                            }
                        } else {
                            this.al = 0;
                            a4.setLocationType(4);
                            this.Q = a4;
                            b(a4.a(1));
                            p();
                        }
                        ht.a().a(this.az, this.D, this.Q, this.E, true);
                        hw.a().a(this.E, this.ay, this.Q);
                        if (!il.a(this.Q)) {
                            AMapLocationServer a5 = a(this.ay, this.D.toString(), this.P, this.E, a(false));
                            if (il.a(a5)) {
                                this.am = this.D.toString();
                                AMapLocationServer aMapLocationServer2 = this.Q;
                                this.Q = a5;
                                this.Q.setLocationType(8);
                                this.Q.setLocationDetail("离线定位,在线定位失败原因:" + aMapLocationServer2.getErrorInfo());
                            }
                        }
                        StringBuilder sb2 = this.D;
                        sb2.delete(0, sb2.length());
                        return this.Q;
                    }
                }
                z2 = false;
                if (this.Q != null) {
                }
                z3 = z2;
                z4 = false;
                if (z4) {
                }
                str = this.aj;
                if (str != null) {
                }
                if (this.aj != null) {
                }
                this.az = this.ay + ContainerUtils.FIELD_DELIMITER + this.ar + ContainerUtils.FIELD_DELIMITER + this.aq;
                if (this.as) {
                }
                if (v2) {
                }
                if (!v2) {
                }
                ht.a().a(this.az, this.D, this.Q, this.E, true);
                hw.a().a(this.E, this.ay, this.Q);
                if (!il.a(this.Q)) {
                }
                StringBuilder sb22 = this.D;
                sb22.delete(0, sb22.length());
                return this.Q;
            }
            if (!this.f1041d) {
                a(false, this.E);
            }
            for (int i3 = 4; i3 > 0 && this.c != 0; i3--) {
                SystemClock.sleep(500);
            }
            if (this.c == 0) {
                this.Q = this.b.e();
                if (this.Q != null) {
                    return this.Q;
                }
            }
            AMapLocationServer aMapLocationServer3 = new AMapLocationServer("");
            aMapLocationServer3.setErrorCode(this.n);
            aMapLocationServer3.setLocationDetail(this.ap.toString());
            return aMapLocationServer3;
        }
        if (this.as && ie.b(this.Q.getTime())) {
            this.Q.setLocationType(2);
        }
        return this.Q;
    }

    /* JADX WARNING: Removed duplicated region for block: B:13:0x0021  */
    /* JADX WARNING: Removed duplicated region for block: B:14:0x0038  */
    public synchronized AMapLocationServer b(boolean z2) {
        hp hpVar;
        AMapLocationServer aMapLocationServer;
        c(z2);
        AMapLocationServer aMapLocationServer2 = null;
        try {
            if (!this.U) {
                hpVar = this.H.c();
                if (!TextUtils.isEmpty(this.ay)) {
                    aMapLocationServer = new AMapLocationServer("");
                    aMapLocationServer.setErrorCode(this.n);
                    aMapLocationServer.setLocationDetail(this.ap.toString());
                } else {
                    try {
                        aMapLocationServer2 = a(false, true, z2);
                    } catch (Throwable unused) {
                    }
                    if (il.a(aMapLocationServer2)) {
                        aMapLocationServer2.m("new");
                        this.am = this.D.toString();
                        this.an = hpVar;
                        this.Q = aMapLocationServer2;
                        b(aMapLocationServer2.a(1));
                        p();
                        aMapLocationServer = aMapLocationServer2;
                    } else {
                        String sb = this.D.toString();
                        e(this.E);
                        AMapLocationServer a2 = a(this.ay, sb, this.P, this.E, a(false));
                        if (!il.a(a2)) {
                            return aMapLocationServer2;
                        }
                        this.am = sb;
                        a2.m(IJavaReplyToJsFileInfo.RESPONSE_FILE_INFO);
                        a2.setLocationType(8);
                        a2.setLocationDetail("离线定位结果,在线定位失败原因:" + aMapLocationServer2.getErrorInfo());
                        this.Q = a2;
                        b(a2.a(1));
                        aMapLocationServer = a2;
                    }
                }
                return aMapLocationServer;
            }
        } catch (Throwable th) {
            f.a(th, "APS", "doFirstNetLocate");
        }
        hpVar = null;
        if (!TextUtils.isEmpty(this.ay)) {
        }
        return aMapLocationServer;
    }

    private void c(final int i2) {
        if (!ie.t()) {
            G();
            return;
        }
        if (this.ac == null) {
            this.ac = new TimerTask() {
                /* class com.amap.api.col.hi.AnonymousClass1 */

                public void run() {
                    try {
                        Thread.currentThread().setPriority(1);
                        long b2 = il.b() - hi.this.T;
                        if (hi.this.y() && hi.this.F() == 0) {
                            hi.this.G();
                        }
                        if (b2 >= 10000) {
                            if (hi.this.H()) {
                                hi.this.b((hi) i2);
                            } else {
                                hi.this.G();
                            }
                        }
                    } catch (Throwable th) {
                        f.a(th, "APS", "timerTaskU run");
                    }
                }
            };
        }
        if (this.ab == null) {
            this.ab = new Timer("T-U", false);
            this.ab.schedule(this.ac, 2000, 2000);
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void a(boolean z2, int i2) {
        if (y()) {
            if (!z2) {
                G();
            } else {
                c(i2);
            }
        }
    }

    public AMapLocationServer a(AMapLocationServer aMapLocationServer, String... strArr) {
        hl.a().a(this.as);
        if (strArr == null || strArr.length == 0) {
            return hl.a().a(aMapLocationServer);
        }
        if (strArr[0].equals("shake")) {
            return hl.a().a(aMapLocationServer);
        }
        return strArr[0].equals("fusion") ? hl.a().b(aMapLocationServer) : aMapLocationServer;
    }

    private AMapLocationServer a(String str, String str2, JSONObject jSONObject, Context context, String str3) {
        Object obj;
        try {
            if (L()) {
                int i2 = 0;
                try {
                    obj = ig.a(this.af, "getPureOfflineLocation", str, str2, jSONObject, str3);
                    i2 = 1;
                } catch (Throwable unused) {
                    obj = null;
                }
                if (!this.ax) {
                    this.ax = true;
                    ii.b(context, "OffLocation", i2);
                }
                AMapLocationServer aMapLocationServer = new AMapLocationServer("");
                aMapLocationServer.i(new JSONObject((String) obj));
                return aMapLocationServer;
            }
        } catch (Throwable unused2) {
        }
        return null;
    }

    private void a(String str) {
        try {
            if (L()) {
                try {
                    ig.a(this.af, str, new Object[0]);
                } catch (Throwable unused) {
                }
                if (this.E != null) {
                }
            } else if (this.af != null) {
                ig.a(this.af, "stopOff", new Object[0]);
                this.m = false;
            }
        } catch (Throwable unused2) {
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:48:0x0138  */
    /* JADX WARNING: Removed duplicated region for block: B:64:0x019d  */
    /* JADX WARNING: Removed duplicated region for block: B:65:0x01af  */
    public synchronized String a(boolean z2) {
        boolean z3;
        String str;
        String str2;
        if (this.U) {
            this.H.h();
        } else {
            this.H.j();
        }
        String str3 = "";
        this.O = this.G.b();
        int e2 = this.H.e();
        ArrayList<hp> b2 = this.H.b();
        if (b2 == null || b2.isEmpty()) {
            ArrayList<ScanResult> arrayList = this.I;
            if (arrayList != null) {
                if (arrayList.isEmpty()) {
                }
            }
            String l2 = this.H.l();
            String g2 = this.G.g();
            if (l2 != null || g2 != null) {
                this.n = 12;
                StringBuilder sb = this.ap;
                if (l2 == null) {
                    l2 = g2;
                }
                sb.append(l2);
                return str3;
            } else if (!il.f(this.E)) {
                this.n = 12;
                return str3;
            } else {
                this.ap.append("⊗ lstCgi & ⊗ wifis");
                this.n = 13;
                return str3;
            }
        }
        if (e2 == 0) {
            if (this.I.isEmpty()) {
                if (!this.G.a(this.O)) {
                    z3 = false;
                    if (!z2) {
                        if (this.G.a(this.O) && this.I.isEmpty()) {
                            this.n = 2;
                            this.ap.append("⊗ around wifi(s) & has access wifi");
                        } else if (this.I.size() == 1) {
                            this.n = 2;
                            if (!this.G.a(this.O)) {
                                this.ap.append("⊗ access wifi & around wifi 1");
                            } else {
                                if (this.O.getBSSID().equals(this.I.get(0).BSSID)) {
                                    this.ap.append("same access wifi & around wifi 1");
                                }
                            }
                        }
                        z3 = false;
                    }
                    String format = String.format(Locale.US, "#%s#", "network");
                    if (!z3) {
                        str3 = format + "wifi";
                    } else {
                        str3 = "";
                        this.n = 2;
                        this.ap.append("is network & no wifi");
                    }
                }
            }
            z3 = true;
            if (!z2) {
            }
            String format2 = String.format(Locale.US, "#%s#", "network");
            if (!z3) {
            }
        } else if (e2 != 1) {
            if (e2 != 2) {
                this.n = 11;
                this.ap.append("get cgi failure");
            } else if (!b2.isEmpty()) {
                hp hpVar = b2.get(0);
                StringBuilder sb2 = new StringBuilder();
                sb2.append(hpVar.a);
                sb2.append(ContactGroupStrategy.GROUP_SHARP);
                sb2.append(hpVar.b);
                sb2.append(ContactGroupStrategy.GROUP_SHARP);
                sb2.append(hpVar.g);
                sb2.append(ContactGroupStrategy.GROUP_SHARP);
                sb2.append(hpVar.h);
                sb2.append(ContactGroupStrategy.GROUP_SHARP);
                sb2.append(hpVar.i);
                sb2.append(ContactGroupStrategy.GROUP_SHARP);
                sb2.append("network");
                sb2.append(ContactGroupStrategy.GROUP_SHARP);
                if (this.I.isEmpty()) {
                    if (!this.G.a(this.O)) {
                        str2 = "cgi";
                        sb2.append(str2);
                        str3 = sb2.toString();
                    }
                }
                str2 = "cgiwifi";
                sb2.append(str2);
                str3 = sb2.toString();
            }
        } else if (!b2.isEmpty()) {
            hp hpVar2 = b2.get(0);
            StringBuilder sb3 = new StringBuilder();
            sb3.append(hpVar2.a);
            sb3.append(ContactGroupStrategy.GROUP_SHARP);
            sb3.append(hpVar2.b);
            sb3.append(ContactGroupStrategy.GROUP_SHARP);
            sb3.append(hpVar2.c);
            sb3.append(ContactGroupStrategy.GROUP_SHARP);
            sb3.append(hpVar2.f1047d);
            sb3.append(ContactGroupStrategy.GROUP_SHARP);
            sb3.append("network");
            sb3.append(ContactGroupStrategy.GROUP_SHARP);
            if (this.I.isEmpty()) {
                if (!this.G.a(this.O)) {
                    str = "cgi";
                    sb3.append(str);
                    str3 = sb3.toString();
                }
            }
            str = "cgiwifi";
            sb3.append(str);
            str3 = sb3.toString();
        }
        if (!TextUtils.isEmpty(str3)) {
            if (!str3.startsWith(ContactGroupStrategy.GROUP_SHARP)) {
                str3 = ContactGroupStrategy.GROUP_SHARP + str3;
            }
            str3 = il.i() + str3;
        }
        return str3;
    }

    /* JADX WARNING: Removed duplicated region for block: B:71:0x014c  */
    public synchronized StringBuilder a(StringBuilder sb, boolean z2) {
        boolean z3;
        hq hqVar = this.H;
        if (this.U) {
            hqVar.h();
        }
        if (sb == null) {
            sb = new StringBuilder((int) TypedValues.TransitionType.TYPE_DURATION);
        } else {
            sb.delete(0, sb.length());
        }
        int e2 = hqVar.e();
        ArrayList<hp> b2 = hqVar.b();
        if (e2 == 1) {
            for (int i2 = 1; i2 < b2.size(); i2++) {
                sb.append(ContactGroupStrategy.GROUP_SHARP);
                sb.append(b2.get(i2).b);
                sb.append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR);
                sb.append(b2.get(i2).c);
                sb.append(HiAnalyticsConstant.REPORT_VAL_SEPARATOR);
                sb.append(b2.get(i2).f1047d);
            }
        }
        if (((!z2 && TextUtils.isEmpty(this.Z)) || this.Z.equals("00:00:00:00:00:00")) && this.O != null) {
            this.Z = this.O.getMacAddress();
            E();
            if (TextUtils.isEmpty(this.Z)) {
                this.Z = "00:00:00:00:00:00";
            }
        }
        String str = "";
        if (this.G.a(this.O)) {
            str = this.O.getBSSID();
        }
        this.o = false;
        int size = this.I.size();
        boolean z4 = false;
        boolean z5 = false;
        for (int i3 = 0; i3 < size; i3++) {
            String str2 = this.I.get(i3).BSSID;
            if (!this.l && !"<unknown ssid>".equals(this.I.get(i3).SSID)) {
                z4 = true;
            }
            String str3 = "nb";
            if (str.equals(str2)) {
                str3 = "access";
                z5 = true;
            }
            sb.append(String.format(Locale.US, "#%s,%s", str2, str3));
        }
        if (this.I.size() == 0) {
            z4 = true;
        }
        try {
            if (!this.l && !z4) {
                List<WifiConfiguration> h2 = this.G.h();
                int i4 = 0;
                z3 = false;
                while (h2 != null) {
                    try {
                        if (i4 >= h2.size()) {
                            break;
                        }
                        if (sb.toString().contains(h2.get(i4).BSSID)) {
                            z3 = true;
                        }
                        i4++;
                    } catch (Throwable unused) {
                    }
                }
                if (!this.l && !z4 && !z3) {
                    this.o = true;
                }
                if (!z5 && !TextUtils.isEmpty(str)) {
                    sb.append(ContactGroupStrategy.GROUP_SHARP);
                    sb.append(str);
                    sb.append(",access");
                }
                if (sb.length() > 0) {
                    sb.deleteCharAt(0);
                }
            }
        } catch (Throwable unused2) {
        }
        z3 = false;
        this.o = true;
        sb.append(ContactGroupStrategy.GROUP_SHARP);
        sb.append(str);
        sb.append(",access");
        if (sb.length() > 0) {
        }
        return sb;
    }

    private boolean a(int i2) {
        int i3 = 20;
        try {
            i3 = WifiManager.calculateSignalLevel(i2, 20);
        } catch (ArithmeticException e2) {
            f.a(e2, "APS", "wifiSigFine");
        }
        return i3 >= 1;
    }

    /* JADX WARNING: Removed duplicated region for block: B:64:0x0155  */
    /* JADX WARNING: Removed duplicated region for block: B:68:0x0175  */
    @SuppressLint({"NewApi"})
    private AMapLocationServer a(boolean z2, boolean z3, boolean z4) throws Exception {
        String str;
        AMapLocationServer aMapLocationServer = new AMapLocationServer("");
        if (this.o) {
            aMapLocationServer.setErrorCode(15);
            this.o = false;
            return aMapLocationServer;
        }
        if (!z2) {
            this.R = il.b();
            if (this.E == null) {
                this.ap.append("context is null");
                aMapLocationServer.setErrorCode(1);
                aMapLocationServer.setLocationDetail(this.ap.toString());
                return aMapLocationServer;
            }
        }
        try {
            s();
            ic icVar = new ic();
            byte[] bArr = null;
            try {
                try {
                    gz a2 = this.ao.a(this.E, this.P, this.aa.a(), f.a(), z4);
                    int a3 = this.ao.a();
                    if (a2 != null) {
                        bArr = a2.a;
                        str = a2.c;
                    } else {
                        str = "";
                    }
                    long j2 = (long) a3;
                    aMapLocationServer.c(j2);
                    if (!z2) {
                        if (bArr == null || bArr.length == 0) {
                            aMapLocationServer.setErrorCode(4);
                            this.ap.append("please check the network");
                            if (!TextUtils.isEmpty(str)) {
                                StringBuilder sb = this.ap;
                                sb.append(" #csid:" + str);
                            }
                            aMapLocationServer.t(this.D.toString());
                            aMapLocationServer.setLocationDetail(this.ap.toString());
                        } else {
                            String str2 = new String(bArr, "UTF-8");
                            if (str2.contains("\"status\":\"0\"")) {
                                AMapLocationServer a4 = icVar.a(str2, this.E, a2);
                                a4.t(this.D.toString());
                                a4.c(j2);
                                return a4;
                            }
                            byte[] a5 = hs.a(bArr);
                            if (a5 == null) {
                                aMapLocationServer.setErrorCode(5);
                                this.ap.append("decrypt response data error");
                                if (!TextUtils.isEmpty(str)) {
                                    StringBuilder sb2 = this.ap;
                                    sb2.append(" #csid:" + str);
                                }
                                aMapLocationServer.setLocationDetail(this.ap.toString());
                                return aMapLocationServer;
                            }
                            aMapLocationServer = icVar.a(a5);
                            if (aMapLocationServer == null) {
                                AMapLocationServer aMapLocationServer2 = new AMapLocationServer("");
                                aMapLocationServer2.setErrorCode(5);
                                this.ap.append("location is null");
                                if (!TextUtils.isEmpty(str)) {
                                    StringBuilder sb3 = this.ap;
                                    sb3.append(" #csid:" + str);
                                }
                                aMapLocationServer2.setLocationDetail(this.ap.toString());
                                return aMapLocationServer2;
                            }
                            aMapLocationServer.t(this.D.toString());
                            try {
                                if (!"-1".equals(aMapLocationServer.j()) || aMapLocationServer.getAccuracy() > 5.0f) {
                                    o();
                                    aMapLocationServer.c(j2);
                                    if (aMapLocationServer.getErrorCode() == 0) {
                                        if (!TextUtils.isEmpty(str)) {
                                            aMapLocationServer.setLocationDetail(aMapLocationServer.getLocationDetail() + " #csid:" + str);
                                        }
                                        return aMapLocationServer;
                                    } else if (il.a(aMapLocationServer)) {
                                        aMapLocationServer.n();
                                        if (aMapLocationServer.getErrorCode() == 0 && aMapLocationServer.getLocationType() == 0) {
                                            if ("-5".equals(aMapLocationServer.j()) || "1".equals(aMapLocationServer.j()) || PushConstants.PUSH_TYPE_UPLOAD_LOG.equals(aMapLocationServer.j()) || "14".equals(aMapLocationServer.j()) || "24".equals(aMapLocationServer.j()) || "-1".equals(aMapLocationServer.j())) {
                                                aMapLocationServer.setLocationType(5);
                                            } else {
                                                aMapLocationServer.setLocationType(6);
                                            }
                                            this.ap.append(aMapLocationServer.j());
                                            if (!TextUtils.isEmpty(str)) {
                                                StringBuilder sb4 = this.ap;
                                                sb4.append(" #csid:" + str);
                                            }
                                            aMapLocationServer.setLocationDetail(this.ap.toString());
                                        }
                                        aMapLocationServer.setOffset(this.ar);
                                        aMapLocationServer.f(this.aq);
                                    } else {
                                        this.ai = aMapLocationServer.b();
                                        aMapLocationServer.setErrorCode(6);
                                        StringBuilder sb5 = this.ap;
                                        StringBuilder sb6 = new StringBuilder();
                                        sb6.append("location faile retype:");
                                        sb6.append(aMapLocationServer.j());
                                        sb6.append(" rdesc:");
                                        String str3 = this.ai;
                                        if (str3 == null) {
                                            str3 = "null";
                                        }
                                        sb6.append(str3);
                                        sb5.append(sb6.toString());
                                        if (!TextUtils.isEmpty(str)) {
                                            StringBuilder sb7 = this.ap;
                                            sb7.append(" #csid:" + str);
                                        }
                                        aMapLocationServer.t(this.D.toString());
                                        aMapLocationServer.setLocationDetail(this.ap.toString());
                                        return aMapLocationServer;
                                    }
                                } else {
                                    if (!this.j && m()) {
                                        if (this.k == null) {
                                            this.k = new c();
                                        }
                                        this.i.startLeScan(this.k);
                                        this.j = true;
                                    }
                                    aMapLocationServer.c(j2);
                                    if (aMapLocationServer.getErrorCode() == 0) {
                                    }
                                }
                            } catch (Throwable unused) {
                            }
                        }
                    }
                    return aMapLocationServer;
                } catch (Throwable th) {
                    f.a(th, "APS", "getApsLoc req");
                    aMapLocationServer.setErrorCode(4);
                    aMapLocationServer.t(this.D.toString());
                    this.ap.append("please check the network");
                    aMapLocationServer.setLocationDetail(this.ap.toString());
                    return aMapLocationServer;
                }
            } catch (Throwable th2) {
                f.a(th2, "APS", "getApsLoc buildV4Dot2");
                aMapLocationServer.setErrorCode(3);
                StringBuilder sb8 = this.ap;
                sb8.append("buildV4Dot2 error " + th2.getMessage());
                aMapLocationServer.setLocationDetail(this.ap.toString());
                return aMapLocationServer;
            }
        } catch (Throwable th3) {
            StringBuilder sb9 = this.ap;
            sb9.append("get parames error:" + th3.getMessage());
            aMapLocationServer.setErrorCode(3);
            aMapLocationServer.setLocationDetail(this.ap.toString());
            aMapLocationServer.t(this.D.toString());
            return aMapLocationServer;
        }
    }

    private void a(SharedPreferences sharedPreferences) {
        if (this.E != null && sharedPreferences != null) {
            String str = null;
            if (sharedPreferences.contains("smac")) {
                try {
                    str = new String(ew.b(sharedPreferences.getString("smac", null)), "UTF-8");
                } catch (Throwable th) {
                    f.a(th, "APS", "getSmac");
                    sharedPreferences.edit().remove("smac").commit();
                }
            }
            if (!TextUtils.isEmpty(str) && !str.equals("00:00:00:00:00:00")) {
                this.Z = str;
            }
        }
    }

    private String a(int i2, int i3, int i4) throws Exception {
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("e", i2);
        jSONObject.put("d", i3);
        jSONObject.put("u", i4);
        return jSONObject.toString();
    }

    public synchronized void a(boolean z2, Context context) {
        if (!this.f1041d) {
            if (this.b == null) {
                hj hjVar = new hj(context.getApplicationContext());
                this.b = hjVar;
                hjVar.a(this.y);
            }
            try {
                hj hjVar2 = this.b;
                if (hjVar2 != null) {
                    if (z2) {
                        hjVar2.d();
                    } else {
                        hjVar2.b();
                    }
                }
                this.f1041d = true;
            } catch (Throwable th) {
                f.a(th, "APS", "bindService");
                this.f1041d = true;
            }
        }
    }

    public synchronized void a(Context context, JSONObject jSONObject) {
        try {
            if (!this.aA) {
                a(jSONObject);
                c(context);
                if (this.ay != null) {
                    this.ay = null;
                    this.az = null;
                    StringBuilder sb = this.D;
                    if (sb != null) {
                        sb.delete(0, sb.length());
                    }
                }
                if (!this.U) {
                    this.H.a(this.U, true);
                }
                boolean optBoolean = this.P.optBoolean("isOnceLocationLatest", false);
                this.au = optBoolean;
                if (optBoolean) {
                    if (!this.at) {
                        q();
                        this.at = true;
                    }
                    t();
                }
                e();
                ArrayList<ScanResult> arrayList = this.I;
                if (arrayList != null && arrayList.isEmpty()) {
                    X = il.b();
                    List<ScanResult> a2 = this.G.a();
                    if (a2 != null) {
                        this.I.addAll(a2);
                        synchronized (this.e) {
                            if (this.J != null && this.J.isEmpty()) {
                                this.J.addAll(a2);
                            }
                        }
                    }
                }
                g();
                String a3 = a(false);
                this.ay = a3;
                if (!TextUtils.isEmpty(a3)) {
                    this.az = this.ay + ContainerUtils.FIELD_DELIMITER + this.ar + ContainerUtils.FIELD_DELIMITER + this.aq;
                    this.D = a(this.D, true);
                }
                this.aA = true;
            }
        } catch (Throwable th) {
            f.a(th, "APS", "initFirstLocateParam");
        }
    }

    public synchronized void a(AMapLocationServer aMapLocationServer) {
        if (il.a(aMapLocationServer)) {
            ht.a().a(this.az, this.D, aMapLocationServer, this.E, true);
        }
    }

    public AMapLocationServer a(double d2, double d3) {
        try {
            String a2 = this.ao.a(("output=json&radius=1000&extensions=all&location=" + d3 + Constants.ACCEPT_TIME_SEPARATOR_SP + d2).getBytes("UTF-8"), this.E, "http://restapi.amap.com/v3/geocode/regeo", true);
            ic icVar = new ic();
            if (!a2.contains("\"status\":\"1\"")) {
                return null;
            }
            AMapLocationServer a3 = icVar.a(a2);
            a3.setLatitude(d2);
            a3.setLongitude(d3);
            return a3;
        } catch (Throwable unused) {
            return null;
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:23:0x00af A[Catch:{ all -> 0x00d9 }] */
    public a a(BluetoothDevice bluetoothDevice, int i2, byte[] bArr) {
        Throwable th;
        int i3;
        int i4;
        String str;
        String address;
        String str2;
        try {
            long b2 = il.b();
            try {
                String a2 = a(bArr);
                if (a2.length() == 16) {
                    str2 = a2 + "0000000000000000";
                } else if (a2.length() == 12) {
                    str2 = a2 + "00000000000000000000";
                } else {
                    byte[] bArr2 = new byte[16];
                    System.arraycopy(bArr, 9, bArr2, 0, 16);
                    String b3 = il.b(bArr2);
                    String upperCase = (b3.substring(0, 32)).toUpperCase(Locale.getDefault());
                    int i5 = ((bArr[25] & 255) * 256) + (bArr[26] & 255);
                    int i6 = ((bArr[27] & 255) * 256) + (bArr[28] & 255);
                    if (!(i6 == 11669 || i5 == 2080 || i5 == 1796)) {
                        if (bluetoothDevice != null) {
                            i4 = i5;
                            i3 = i6;
                            str = upperCase;
                            byte b4 = bArr[29];
                            address = bluetoothDevice.getAddress();
                            if (BluetoothAdapter.checkBluetoothAddress(address.toUpperCase(Locale.CHINA))) {
                                byte[] bArr3 = new byte[6];
                                int i7 = 0;
                                for (String str3 : address.split(Constants.COLON_SEPARATOR)) {
                                    bArr3[i7] = (byte) Integer.parseInt(str3, 16);
                                    i7++;
                                }
                                return new a(str, bluetoothDevice.getName(), bArr3, address, i4, i3, b4, i2, b2);
                            }
                        }
                    }
                    return null;
                }
                str = str2;
                i4 = 0;
                i3 = 0;
                byte b42 = bArr[29];
                address = bluetoothDevice.getAddress();
                if (BluetoothAdapter.checkBluetoothAddress(address.toUpperCase(Locale.CHINA))) {
                }
                return null;
            } catch (Throwable th2) {
                th = th2;
                f.a(th, "APS", "createFromScanData");
                return null;
            }
        } catch (Throwable th3) {
            th = th3;
            f.a(th, "APS", "createFromScanData");
            return null;
        }
    }

    private String a(byte[] bArr) {
        if (bArr != null && bArr.length > 24) {
            if (bArr[0] == 2 && bArr[1] == 1 && ((bArr[2] == 5 || bArr[2] == 6) && bArr[3] == 23)) {
                byte[] bArr2 = new byte[16];
                System.arraycopy(bArr, 9, bArr2, 0, 16);
                StringBuffer stringBuffer = new StringBuffer();
                for (int i2 = 0; i2 < 16; i2++) {
                    stringBuffer.append(String.format("%02X", Byte.valueOf(bArr2[i2])));
                }
                String stringBuffer2 = stringBuffer.toString();
                String str = this.aB.get(stringBuffer2);
                if (str != null) {
                    return str;
                }
                byte[] a2 = hs.a(il.c(bArr2), new BigInteger("8021267762677846189778330391499"), new BigInteger("49549924105414102803086139689747"));
                if (a2 == null || a2.length < 8) {
                    return "";
                }
                StringBuffer stringBuffer3 = new StringBuffer();
                for (int i3 = 6; i3 >= 1; i3--) {
                    stringBuffer3.append(String.format("%02X", Byte.valueOf(a2[i3])));
                }
                String stringBuffer4 = stringBuffer3.toString();
                this.aB.put(stringBuffer2, stringBuffer4);
                return stringBuffer4;
            } else if (bArr[0] == 2 && bArr[1] == 1 && bArr[2] == 6 && bArr[3] == 22 && bArr[5] == -88 && bArr[6] == 1 && bArr[7] == 32) {
                try {
                    byte[] b2 = hs.b(il.a(bArr, 10, 26), new byte[]{-1, -15, 55, 33, 4, 21, 16, 20, -85, 9, 0, 2, -91, -43, -59, -75});
                    if (b2 != null) {
                        StringBuffer stringBuffer5 = new StringBuffer();
                        for (int i4 = 0; i4 < 8; i4++) {
                            stringBuffer5.append(String.format("%02X", Byte.valueOf(b2[i4])));
                        }
                        return stringBuffer5.toString();
                    }
                } catch (Throwable unused) {
                }
            }
        }
        return "";
    }
}