盛康基办.apk(点击下载) / a.java


package com.baidu.location.c;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Base64;
import androidx.exifinterface.media.ExifInterface;
import com.baidu.location.BDLocation;
import com.baidu.location.Jni;
import com.baidu.location.b.v;
import com.baidu.location.g.b;
import com.baidu.location.g.e;
import com.baidu.location.g.k;
import com.google.android.exoplayer2.text.ttml.TtmlNode;
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
import com.google.firebase.remoteconfig.RemoteConfigConstants;
import com.king.zxing.util.LogUtils;
import java.io.File;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.json.JSONObject;

public class a {
    private static Object b = new Object();
    private static a c = null;
    private static final String d = (k.j() + "/gal.db");
    private static Lock f = new ReentrantLock();
    C0003a a = null;
    private SQLiteDatabase e = null;
    private boolean g = false;
    private Map<String, Integer> h = new HashMap();
    private String i = null;
    private int j = -1;
    private String k = null;
    private double l = Double.MAX_VALUE;
    private double m = Double.MAX_VALUE;

    /* access modifiers changed from: package-private */
    /* renamed from: com.baidu.location.c.a$a  reason: collision with other inner class name */
    public class C0003a extends e {
        int a;
        int b;
        int c;
        int d;
        double e;

        C0003a() {
            this.k = new HashMap();
        }

        @Override // com.baidu.location.g.e
        public void a() {
            String str;
            Map map;
            this.h = "http://loc.map.baidu.com/gpsz";
            String format = String.format(Locale.CHINESE, "&is_vdr=1&x=%d&y=%d%s", Integer.valueOf(this.a), Integer.valueOf(this.b), b.a().c());
            String encode = Jni.encode(format);
            if (encode.contains("err!")) {
                try {
                    encode = new String(Base64.encode(format.getBytes(), 0), "UTF-8");
                } catch (Exception unused) {
                    encode = "err2!";
                }
                map = this.k;
                str = "gpszb";
            } else {
                map = this.k;
                str = "gpsz";
            }
            map.put(str, encode);
        }

        public void a(double d2, double d3, double d4) {
            if (!a.this.g) {
                double[] coorEncrypt = Jni.coorEncrypt(d2, d3, "gcj2wgs");
                this.a = (int) Math.floor(coorEncrypt[0] * 100.0d);
                this.b = (int) Math.floor(coorEncrypt[1] * 100.0d);
                this.c = (int) Math.floor(d2 * 100.0d);
                this.d = (int) Math.floor(d3 * 100.0d);
                this.e = d4;
                a.this.g = true;
                if (!k.b()) {
                    b(v.a().c());
                }
            }
        }

        /* JADX WARNING: Removed duplicated region for block: B:32:0x012b A[Catch:{ Exception -> 0x0137 }] */
        /* JADX WARNING: Removed duplicated region for block: B:41:0x0171  */
        /* JADX WARNING: Removed duplicated region for block: B:77:0x0137 A[SYNTHETIC] */
        @Override // com.baidu.location.g.e
        public void a(boolean z) {
            String str;
            String str2;
            JSONObject jSONObject;
            String str3;
            String[] strArr;
            String str4;
            String format;
            Double valueOf;
            String str5 = LogUtils.COLON;
            String str6 = "info";
            if (z && this.j != null) {
                a.f.lock();
                try {
                    JSONObject jSONObject2 = new JSONObject(this.j);
                    boolean has = jSONObject2.has("height");
                    String str7 = ExifInterface.LONGITUDE_EAST;
                    String str8 = ",";
                    if (has) {
                        String string = jSONObject2.getString("height");
                        if (string.contains(str8)) {
                            String[] split = string.trim().split(str8);
                            int length = split.length;
                            jSONObject = jSONObject2;
                            int sqrt = (int) Math.sqrt((double) length);
                            if (sqrt * sqrt == length) {
                                int i = sqrt - 1;
                                int i2 = this.c - (i / 2);
                                str2 = "locStateData";
                                int i3 = this.d - (i / 2);
                                for (int i4 = 0; i4 < sqrt; i4++) {
                                    int i5 = 0;
                                    while (i5 < sqrt) {
                                        ContentValues contentValues = new ContentValues();
                                        int i6 = (i4 * sqrt) + i5;
                                        if (split[i6].contains(str7)) {
                                            contentValues.put("aldata", Double.valueOf(10000.0d));
                                            valueOf = Double.valueOf(10000.0d);
                                        } else if (!split[i6].contains(str5)) {
                                            contentValues.put("aldata", Double.valueOf(split[i6]));
                                            valueOf = Double.valueOf(10000.0d);
                                        } else {
                                            String[] split2 = split[i6].split(str5);
                                            str4 = str5;
                                            strArr = split;
                                            if (split2.length == 2) {
                                                contentValues.put("aldata", Double.valueOf(split2[0]));
                                                contentValues.put("sigma", split2[1]);
                                            } else {
                                                contentValues.put("aldata", Double.valueOf(10000.0d));
                                                contentValues.put("sigma", Double.valueOf(10000.0d));
                                            }
                                            contentValues.put(TtmlNode.TAG_TT, Integer.valueOf((int) (System.currentTimeMillis() / 1000)));
                                            format = String.format(Locale.CHINESE, "%d,%d", Integer.valueOf(i2 + i5), Integer.valueOf(i3 + i4));
                                            if (a.this.e.update("galdata_new", contentValues, "id = \"" + format + "\"", null) > 0) {
                                                contentValues.put(TtmlNode.ATTR_ID, format);
                                                a.this.e.insert("galdata_new", null, contentValues);
                                            }
                                            i5++;
                                            str8 = str8;
                                            str5 = str4;
                                            sqrt = sqrt;
                                            str7 = str7;
                                            str6 = str6;
                                            split = strArr;
                                        }
                                        contentValues.put("sigma", valueOf);
                                        str4 = str5;
                                        strArr = split;
                                        contentValues.put(TtmlNode.TAG_TT, Integer.valueOf((int) (System.currentTimeMillis() / 1000)));
                                        format = String.format(Locale.CHINESE, "%d,%d", Integer.valueOf(i2 + i5), Integer.valueOf(i3 + i4));
                                        try {
                                            if (a.this.e.update("galdata_new", contentValues, "id = \"" + format + "\"", null) > 0) {
                                            }
                                        } catch (Exception unused) {
                                        }
                                        i5++;
                                        str8 = str8;
                                        str5 = str4;
                                        sqrt = sqrt;
                                        str7 = str7;
                                        str6 = str6;
                                        split = strArr;
                                    }
                                }
                            } else {
                                str2 = "locStateData";
                            }
                            str = str6;
                            String str9 = str7;
                            if (jSONObject.has(str)) {
                                String string2 = jSONObject.getString(str);
                                if (string2.contains(str8)) {
                                    String[] split3 = string2.trim().split(str8);
                                    int length2 = split3.length;
                                    int sqrt2 = (int) Math.sqrt((double) length2);
                                    if (sqrt2 * sqrt2 == length2) {
                                        int i7 = sqrt2 - 1;
                                        int i8 = this.c - (i7 / 2);
                                        int i9 = this.d - (i7 / 2);
                                        int i10 = 0;
                                        while (i10 < sqrt2) {
                                            int i11 = 0;
                                            while (i11 < sqrt2) {
                                                ContentValues contentValues2 = new ContentValues();
                                                int i12 = (i10 * sqrt2) + i11;
                                                contentValues2.put(RemoteConfigConstants.ResponseFieldKey.STATE, split3[i12].contains(str9) ? -1 : Integer.valueOf(Integer.valueOf(split3[i12]).intValue()));
                                                String format2 = String.format(Locale.CHINESE, "%d,%d", Integer.valueOf(i8 + i11), Integer.valueOf(i9 + i10));
                                                try {
                                                    str3 = str2;
                                                    try {
                                                        if (a.this.e.update(str3, contentValues2, "id = \"" + format2 + "\"", null) <= 0) {
                                                            contentValues2.put(TtmlNode.ATTR_ID, format2);
                                                            a.this.e.insert(str3, null, contentValues2);
                                                        }
                                                    } catch (Exception unused2) {
                                                    }
                                                } catch (Exception unused3) {
                                                    str3 = str2;
                                                }
                                                i11++;
                                                str9 = str9;
                                                str2 = str3;
                                                split3 = split3;
                                                i8 = i8;
                                            }
                                            i10++;
                                            split3 = split3;
                                        }
                                    }
                                }
                            }
                            a.f.unlock();
                        }
                    }
                    str2 = "locStateData";
                    str = str6;
                    jSONObject = jSONObject2;
                    String str92 = str7;
                    if (jSONObject.has(str)) {
                    }
                } catch (Exception unused4) {
                }
                a.f.unlock();
            }
            if (this.k != null) {
                this.k.clear();
            }
            a.this.g = false;
        }
    }

    public static a a() {
        a aVar;
        synchronized (b) {
            if (c == null) {
                c = new a();
            }
            aVar = c;
        }
        return aVar;
    }

    private void a(double d2, double d3, double d4) {
        if (this.a == null) {
            this.a = new C0003a();
        }
        this.a.a(d2, d3, d4);
    }

    public int a(BDLocation bDLocation) {
        double d2;
        float f2;
        if (bDLocation != null) {
            f2 = bDLocation.getRadius();
            d2 = bDLocation.getAltitude();
        } else {
            d2 = 0.0d;
            f2 = 0.0f;
        }
        if (this.e == null || f2 <= 0.0f || d2 <= FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE || bDLocation == null) {
            return 0;
        }
        double d3 = a(bDLocation.getLongitude(), bDLocation.getLatitude())[0];
        if (d3 == Double.MAX_VALUE) {
            return 0;
        }
        double gpsSwiftRadius = Jni.getGpsSwiftRadius(f2, d2, d3);
        if (gpsSwiftRadius > 50.0d) {
            return 3;
        }
        return gpsSwiftRadius > 20.0d ? 2 : 1;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:45:0x00da, code lost:
        r18 = r7;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:47:0x00dd, code lost:
        r18 = r7;
        r3 = Double.MAX_VALUE;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:49:0x00e0, code lost:
        r12 = r1;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:50:0x00e2, code lost:
        r0 = th;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:51:0x00e3, code lost:
        r18 = r7;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:52:0x00e6, code lost:
        r18 = r7;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:63:0x0104, code lost:
        r0 = th;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:64:0x0105, code lost:
        r1 = r18;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:65:0x0108, code lost:
        r3 = Double.MAX_VALUE;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:71:?, code lost:
        r1.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:78:?, code lost:
        r1.close();
     */
    /* JADX WARNING: Exception block dominator not found, dom blocks: [B:36:0x00c3, B:55:0x00eb] */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Removed duplicated region for block: B:50:0x00e2 A[ExcHandler: all (th java.lang.Throwable), Splitter:B:15:0x007d] */
    /* JADX WARNING: Removed duplicated region for block: B:61:0x0100 A[SYNTHETIC, Splitter:B:61:0x0100] */
    /* JADX WARNING: Removed duplicated region for block: B:63:0x0104 A[ExcHandler: all (th java.lang.Throwable), PHI: r18 
      PHI: (r18v3 android.database.Cursor) = (r18v5 android.database.Cursor), (r18v15 android.database.Cursor) binds: [B:55:0x00eb, B:36:0x00c3] A[DONT_GENERATE, DONT_INLINE], Splitter:B:36:0x00c3] */
    /* JADX WARNING: Removed duplicated region for block: B:70:0x010f A[SYNTHETIC, Splitter:B:70:0x010f] */
    /* JADX WARNING: Removed duplicated region for block: B:77:0x0116 A[SYNTHETIC, Splitter:B:77:0x0116] */
    /* JADX WARNING: Removed duplicated region for block: B:87:0x012a  */
    /* JADX WARNING: Removed duplicated region for block: B:88:0x012e  */
    /* JADX WARNING: Removed duplicated region for block: B:91:0x0135  */
    /* JADX WARNING: Removed duplicated region for block: B:92:0x0139  */
    public double[] a(double d2, double d3) {
        double d4;
        double d5;
        double d6;
        Cursor cursor;
        double d7;
        double d8;
        String str;
        double[] dArr = new double[2];
        double d9 = Double.MAX_VALUE;
        if (this.e == null || d2 <= 0.1d || d3 <= 0.1d) {
            d5 = Double.MAX_VALUE;
        } else {
            String format = String.format(Locale.CHINESE, "%d,%d", Integer.valueOf((int) Math.floor(d2 * 100.0d)), Integer.valueOf((int) Math.floor(100.0d * d3)));
            String str2 = this.k;
            if (str2 == null || !str2.equals(format)) {
                f.lock();
                Cursor cursor2 = null;
                try {
                    Cursor rawQuery = this.e.rawQuery("select * from galdata_new where id = \"" + format + "\";", null);
                    if (rawQuery != null) {
                        try {
                            if (rawQuery.moveToFirst()) {
                                d7 = rawQuery.getDouble(1);
                                d6 = rawQuery.getDouble(2);
                                int i2 = rawQuery.getInt(3);
                                if (d7 == 10000.0d) {
                                    d7 = Double.MAX_VALUE;
                                }
                                if (d6 > FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE) {
                                    d9 = d6;
                                }
                                long currentTimeMillis = (System.currentTimeMillis() / 1000) - ((long) i2);
                                if (this.g || currentTimeMillis <= 604800) {
                                    d8 = d7;
                                    str = format;
                                    cursor = rawQuery;
                                } else {
                                    d8 = d7;
                                    str = format;
                                    cursor = rawQuery;
                                    try {
                                        a(d2, d3, 8.220000267028809d);
                                    } catch (Exception unused) {
                                        d6 = d9;
                                        d9 = d8;
                                        cursor2 = cursor;
                                        if (cursor2 != null) {
                                        }
                                        d5 = d6;
                                        f.unlock();
                                        d4 = 10000.0d;
                                        if (d9 > d4) {
                                        }
                                        if (d5 > d4) {
                                        }
                                        return dArr;
                                    } catch (Throwable th) {
                                    }
                                }
                                this.k = str;
                                this.l = d8;
                                this.m = d9;
                                d5 = d9;
                                d9 = d8;
                                if (cursor != null) {
                                    try {
                                        cursor.close();
                                    } catch (Exception unused2) {
                                    }
                                }
                                f.unlock();
                            }
                        } catch (Exception unused3) {
                            d8 = d7;
                            cursor = rawQuery;
                            d6 = d9;
                            d9 = d8;
                            cursor2 = cursor;
                            if (cursor2 != null) {
                            }
                            d5 = d6;
                            f.unlock();
                            d4 = 10000.0d;
                            if (d9 > d4) {
                            }
                            if (d5 > d4) {
                            }
                            return dArr;
                        } catch (Throwable th2) {
                        }
                    }
                    cursor = rawQuery;
                    if (!this.g) {
                        a(d2, d3, 8.220000267028809d);
                    }
                    d5 = Double.MAX_VALUE;
                    if (cursor != null) {
                    }
                } catch (Exception unused4) {
                    d6 = Double.MAX_VALUE;
                    if (cursor2 != null) {
                    }
                    d5 = d6;
                    f.unlock();
                    d4 = 10000.0d;
                    if (d9 > d4) {
                    }
                    if (d5 > d4) {
                    }
                    return dArr;
                } catch (Throwable th3) {
                    Throwable th4 = th3;
                    if (cursor2 != null) {
                    }
                    throw th4;
                }
                f.unlock();
            } else {
                d9 = this.l;
                d5 = this.m;
                d4 = 10000.0d;
                if (d9 > d4) {
                    dArr[0] = d4;
                } else {
                    dArr[0] = d9;
                }
                if (d5 > d4) {
                    dArr[1] = d4;
                } else {
                    dArr[1] = d5;
                }
                return dArr;
            }
        }
        d4 = 10000.0d;
        if (d9 > d4) {
        }
        if (d5 > d4) {
        }
        return dArr;
    }

    public void b() {
        try {
            File file = new File(d);
            if (!file.exists()) {
                file.createNewFile();
            }
            if (file.exists()) {
                SQLiteDatabase openOrCreateDatabase = SQLiteDatabase.openOrCreateDatabase(file, (SQLiteDatabase.CursorFactory) null);
                this.e = openOrCreateDatabase;
                Cursor rawQuery = openOrCreateDatabase.rawQuery("SELECT count(*) FROM sqlite_master WHERE type='table' AND name='galdata'", null);
                if (rawQuery.moveToFirst()) {
                    if (rawQuery.getInt(0) == 0) {
                        this.e.execSQL("CREATE TABLE IF NOT EXISTS galdata_new(id CHAR(40) PRIMARY KEY,aldata DOUBLE, sigma DOUBLE,tt INT);");
                    } else {
                        this.e.execSQL("DROP TABLE galdata");
                        this.e.execSQL("CREATE TABLE galdata_new(id CHAR(40) PRIMARY KEY,aldata DOUBLE, sigma DOUBLE,tt INT);");
                    }
                    this.e.execSQL("CREATE TABLE IF NOT EXISTS locStateData(id CHAR(40) PRIMARY KEY,state INT);");
                }
                this.e.setVersion(1);
                rawQuery.close();
            }
        } catch (Exception unused) {
            this.e = null;
        }
    }

    public void c() {
        SQLiteDatabase sQLiteDatabase = this.e;
        if (sQLiteDatabase != null) {
            try {
                sQLiteDatabase.close();
            } catch (Exception unused) {
            } catch (Throwable th) {
                this.e = null;
                throw th;
            }
            this.e = null;
        }
    }
}