package com.baidu.location.b; import android.app.ActivityManager; import android.content.Context; import android.location.Location; import android.os.Handler; import com.baidu.location.Jni; import com.baidu.location.e.b; import com.baidu.location.e.e; import com.baidu.location.e.j; import com.baidu.location.e.k; import com.baidu.location.f; import com.tencent.qcloud.core.http.HttpConstants; import com.tencent.smtt.sdk.WebView; import java.io.BufferedOutputStream; import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.RandomAccessFile; import java.net.MalformedURLException; import java.net.URL; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; import java.util.ArrayList; import java.util.Calendar; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Random; import java.util.UUID; import javax.net.ssl.HttpsURLConnection; import kotlin.jvm.internal.ByteCompanionObject; import n02.c; import org.json.JSONException; import org.json.JSONObject; public class d { /* renamed from: f reason: collision with root package name */ public static String f18823f = "0"; /* renamed from: j reason: collision with root package name */ private static d f18824j; private a A; private boolean B; private boolean C; private int D; private float E; private float F; private long G; private int H; private Handler I; /* renamed from: J reason: collision with root package name */ private byte[] f18825J; private byte[] K; private int L; private List<Byte> M; private boolean N; /* renamed from: a reason: collision with root package name */ public long f18826a; /* renamed from: b reason: collision with root package name */ public Location f18827b; /* renamed from: c reason: collision with root package name */ public Location f18828c; /* renamed from: d reason: collision with root package name */ public StringBuilder f18829d; /* renamed from: e reason: collision with root package name */ public long f18830e; /* renamed from: g reason: collision with root package name */ public int f18831g; /* renamed from: h reason: collision with root package name */ public double f18832h; /* renamed from: i reason: collision with root package name */ public double f18833i; /* renamed from: k reason: collision with root package name */ private int f18834k; /* renamed from: l reason: collision with root package name */ private double f18835l; /* renamed from: m reason: collision with root package name */ private String f18836m; /* renamed from: n reason: collision with root package name */ private int f18837n; /* renamed from: o reason: collision with root package name */ private int f18838o; /* renamed from: p reason: collision with root package name */ private int f18839p; /* renamed from: q reason: collision with root package name */ private int f18840q; /* renamed from: r reason: collision with root package name */ private double f18841r; /* renamed from: s reason: collision with root package name */ private double f18842s; /* renamed from: t reason: collision with root package name */ private double f18843t; /* renamed from: u reason: collision with root package name */ private int f18844u; /* renamed from: v reason: collision with root package name */ private int f18845v; /* renamed from: w reason: collision with root package name */ private int f18846w; /* renamed from: x reason: collision with root package name */ private int f18847x; /* renamed from: y reason: collision with root package name */ private int f18848y; /* renamed from: z reason: collision with root package name */ private long f18849z; public class a extends e { /* renamed from: a reason: collision with root package name */ public String f18850a = null; public a() { this.f19172k = new HashMap(); } @Override // com.baidu.location.e.e public void a() { this.f19169h = "http://loc.map.baidu.com/cc.php"; String encode = Jni.encode(this.f18850a); this.f18850a = null; this.f19172k.put("q", encode); } public void a(String str) { this.f18850a = str; b(v.a().c()); } @Override // com.baidu.location.e.e public void a(boolean z14) { String str; if (z14 && (str = this.f19171j) != null) { try { JSONObject jSONObject = new JSONObject(str); jSONObject.put("prod", b.f19135e); jSONObject.put("uptime", System.currentTimeMillis()); d.this.e((d) jSONObject.toString()); } catch (Exception unused) { } } Map<String, Object> map = this.f19172k; if (map != null) { map.clear(); } } } private d() { this.f18834k = 1; this.f18835l = 0.699999988079071d; this.f18836m = "3G|4G"; this.f18837n = 1; this.f18838o = 307200; this.f18839p = 15; this.f18840q = 1; this.f18841r = 3.5d; this.f18842s = 3.0d; this.f18843t = 0.5d; this.f18844u = 300; this.f18845v = 60; this.f18846w = 0; this.f18847x = 60; this.f18848y = 0; this.f18849z = 0; this.A = null; this.B = false; this.C = false; this.D = 0; this.E = 0.0f; this.F = 0.0f; this.G = 0; this.H = 500; this.f18826a = 0; this.f18827b = null; this.f18828c = null; this.f18829d = null; this.f18830e = 0; this.I = null; this.f18825J = new byte[4]; this.K = null; this.L = 0; this.M = null; this.N = false; this.f18831g = 0; this.f18832h = 116.22345545d; this.f18833i = 40.245667323d; this.I = new Handler(); } public static d a() { if (f18824j == null) { f18824j = new d(); } return f18824j; } /* access modifiers changed from: private */ public String a(File file, String str) { String uuid = UUID.randomUUID().toString(); try { HttpsURLConnection httpsURLConnection = (HttpsURLConnection) new URL(str).openConnection(); httpsURLConnection.setReadTimeout(10000); httpsURLConnection.setConnectTimeout(10000); httpsURLConnection.setDoInput(true); httpsURLConnection.setDoOutput(true); httpsURLConnection.setUseCaches(false); httpsURLConnection.setRequestMethod("POST"); httpsURLConnection.setRequestProperty("Charset", "utf-8"); httpsURLConnection.setRequestProperty(dh2.b.f68849i, "close"); httpsURLConnection.setRequestProperty("Content-Type", HttpConstants.ContentType.MULTIPART_FORM_DATA + ";boundary=" + uuid); if (file == null || !file.exists()) { return "0"; } OutputStream outputStream = httpsURLConnection.getOutputStream(); DataOutputStream dataOutputStream = new DataOutputStream(outputStream); StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append("--"); stringBuffer.append(uuid); stringBuffer.append("\r\n"); stringBuffer.append("Content-Disposition: form-data; name=\"location_dat\"; filename=\"" + file.getName() + "\"" + "\r\n"); StringBuilder sb3 = new StringBuilder(); sb3.append("Content-Type: application/octet-stream; charset=utf-8"); sb3.append("\r\n"); stringBuffer.append(sb3.toString()); stringBuffer.append("\r\n"); dataOutputStream.write(stringBuffer.toString().getBytes()); FileInputStream fileInputStream = new FileInputStream(file); byte[] bArr = new byte[1024]; while (true) { int read = fileInputStream.read(bArr); if (read == -1) { break; } dataOutputStream.write(bArr, 0, read); } fileInputStream.close(); dataOutputStream.write("\r\n".getBytes()); dataOutputStream.write(("--" + uuid + "--" + "\r\n").getBytes()); dataOutputStream.flush(); dataOutputStream.close(); int responseCode = httpsURLConnection.getResponseCode(); outputStream.close(); httpsURLConnection.disconnect(); int i10 = this.f18848y + 400; this.f18848y = i10; c(i10); return responseCode == 200 ? "1" : "0"; } catch (IOException | MalformedURLException unused) { return "0"; } } private boolean a(String str, Context context) { boolean z14 = false; try { List<ActivityManager.RunningAppProcessInfo> runningAppProcesses = ((ActivityManager) context.getSystemService("activity")).getRunningAppProcesses(); if (runningAppProcesses != null) { for (ActivityManager.RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) { if (runningAppProcessInfo.processName.equals(str)) { int i10 = runningAppProcessInfo.importance; if (i10 == 200 || i10 == 100) { z14 = true; } } } } } catch (Exception unused) { } return z14; } private byte[] a(int i10) { return new byte[]{(byte) (i10 & 255), (byte) ((65280 & i10) >> 8), (byte) ((16711680 & i10) >> 16), (byte) ((i10 & WebView.NIGHT_MODE_COLOR) >> 24)}; } private byte[] a(String str) { if (str == null) { return null; } byte[] bytes = str.getBytes(); byte nextInt = (byte) new Random().nextInt(255); byte nextInt2 = (byte) new Random().nextInt(255); byte[] bArr = new byte[(bytes.length + 2)]; int length = bytes.length; int i10 = 0; int i14 = 0; while (i10 < length) { bArr[i14] = (byte) (bytes[i10] ^ nextInt); i10++; i14++; } bArr[i14] = nextInt; bArr[i14 + 1] = nextInt2; return bArr; } private String b(String str) { Calendar instance = Calendar.getInstance(); return String.format(str, Integer.valueOf(instance.get(1)), Integer.valueOf(instance.get(2) + 1), Integer.valueOf(instance.get(5))); } private void b(int i10) { byte[] a14 = a(i10); for (int i14 = 0; i14 < 4; i14++) { this.M.add(Byte.valueOf(a14[i14])); } } /* access modifiers changed from: private */ public void b(Location location) { c(location); h(); } private void c() { if (!this.N) { this.N = true; d(b.f19135e); j(); d(); } } private void c(int i10) { if (i10 != 0) { try { File file = new File(j.f19185a + "/grtcf.dat"); if (!file.exists()) { File file2 = new File(j.f19185a); if (!file2.exists()) { file2.mkdirs(); } if (file.createNewFile()) { RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw"); randomAccessFile.seek(2); randomAccessFile.writeInt(0); randomAccessFile.seek(8); byte[] bytes = "1980_01_01:0".getBytes(); randomAccessFile.writeInt(bytes.length); randomAccessFile.write(bytes); randomAccessFile.seek(200); randomAccessFile.writeBoolean(false); randomAccessFile.seek(800); randomAccessFile.writeBoolean(false); randomAccessFile.close(); } else { return; } } RandomAccessFile randomAccessFile2 = new RandomAccessFile(file, "rw"); randomAccessFile2.seek(8); byte[] bytes2 = (b("%d_%02d_%02d") + ":" + i10).getBytes(); randomAccessFile2.writeInt(bytes2.length); randomAccessFile2.write(bytes2); randomAccessFile2.close(); } catch (Exception unused) { } } } private void c(Location location) { if (System.currentTimeMillis() - this.f18826a >= ((long) this.H) && location != null) { if (location.hasSpeed() && location.getSpeed() > this.E) { this.E = location.getSpeed(); } try { if (this.M == null) { this.M = new ArrayList(); i(); d(location); } else { e(location); } } catch (Exception unused) { } this.L++; } } private void c(String str) { if (str != null) { try { JSONObject jSONObject = new JSONObject(str); if (jSONObject.has("on")) { this.f18834k = jSONObject.getInt("on"); } if (jSONObject.has("bash")) { this.f18835l = jSONObject.getDouble("bash"); } if (jSONObject.has(com.alipay.sdk.app.statistic.b.f18036a)) { this.f18836m = jSONObject.getString(com.alipay.sdk.app.statistic.b.f18036a); } if (jSONObject.has("tcon")) { this.f18837n = jSONObject.getInt("tcon"); } if (jSONObject.has("tcsh")) { this.f18838o = jSONObject.getInt("tcsh"); } if (jSONObject.has("per")) { this.f18839p = jSONObject.getInt("per"); } if (jSONObject.has("chdron")) { this.f18840q = jSONObject.getInt("chdron"); } if (jSONObject.has("spsh")) { this.f18841r = jSONObject.getDouble("spsh"); } if (jSONObject.has("acsh")) { this.f18842s = jSONObject.getDouble("acsh"); } if (jSONObject.has("stspsh")) { this.f18843t = jSONObject.getDouble("stspsh"); } if (jSONObject.has("drstsh")) { this.f18844u = jSONObject.getInt("drstsh"); } if (jSONObject.has("stper")) { this.f18845v = jSONObject.getInt("stper"); } if (jSONObject.has("nondron")) { this.f18846w = jSONObject.getInt("nondron"); } if (jSONObject.has("nondrper")) { this.f18847x = jSONObject.getInt("nondrper"); } if (jSONObject.has("uptime")) { this.f18849z = jSONObject.getLong("uptime"); } k(); } catch (JSONException unused) { } } } private void d() { String[] split = "7.9.3".split("\\."); int length = split.length; byte[] bArr = this.f18825J; bArr[0] = 0; bArr[1] = 0; bArr[2] = 0; bArr[3] = 0; if (length >= 4) { length = 4; } for (int i10 = 0; i10 < length; i10++) { try { this.f18825J[i10] = (byte) (Integer.valueOf(split[i10]).intValue() & 255); } catch (Exception unused) { } } this.K = a(b.f19135e + ":" + b.a().f19143c); } private void d(Location location) { this.f18830e = System.currentTimeMillis(); b((int) (location.getTime() / 1000)); b((int) (c.i(location) * 1000000.0d)); b((int) (c.h(location) * 1000000.0d)); int i10 = !location.hasBearing(); int i14 = !location.hasSpeed(); this.M.add(Byte.valueOf(i10 > 0 ? 32 : (byte) (((byte) (((int) (location.getBearing() / 15.0f)) & 255)) & -33))); this.M.add(Byte.valueOf(i14 > 0 ? Byte.MIN_VALUE : (byte) (((byte) (((int) ((((double) location.getSpeed()) * 3.6d) / 4.0d)) & 255)) & ByteCompanionObject.MAX_VALUE))); this.f18827b = location; } private void d(String str) { try { File file = new File(j.f19185a + "/grtcf.dat"); if (file.exists()) { RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw"); randomAccessFile.seek(2); int readInt = randomAccessFile.readInt(); randomAccessFile.seek(8); int readInt2 = randomAccessFile.readInt(); byte[] bArr = new byte[readInt2]; randomAccessFile.read(bArr, 0, readInt2); String str2 = new String(bArr); int i10 = 1; if (str2.contains(b("%d_%02d_%02d")) && str2.contains(":")) { try { String[] split = str2.split(":"); if (split.length > 1) { this.f18848y = Integer.valueOf(split[1]).intValue(); } } catch (Exception unused) { } } while (true) { if (i10 > readInt) { break; } randomAccessFile.seek((long) (i10 * 2048)); int readInt3 = randomAccessFile.readInt(); byte[] bArr2 = new byte[readInt3]; randomAccessFile.read(bArr2, 0, readInt3); String str3 = new String(bArr2); if (str != null && str3.contains(str)) { c(str3); break; } i10++; } randomAccessFile.close(); } } catch (Exception unused2) { } } /* JADX WARNING: Code restructure failed: missing block: B:28:0x0102, code lost: if (r8 > 0) goto L_0x011a; */ /* JADX WARNING: Code restructure failed: missing block: B:32:0x0118, code lost: if (r8 > 0) goto L_0x011a; */ private void e(Location location) { byte b14; if (location != null) { int i10 = (int) ((c.i(location) - c.i(this.f18827b)) * 1000000.0d); int h10 = (int) ((c.h(location) - c.h(this.f18827b)) * 1000000.0d); int i14 = !location.hasBearing(); int i15 = !location.hasSpeed(); char c14 = i10 > 0 ? (char) 0 : 1; int abs = Math.abs(i10); char c15 = h10 > 0 ? (char) 0 : 1; int abs2 = Math.abs(h10); if (this.L > 1) { this.f18828c = null; this.f18828c = this.f18827b; } this.f18827b = location; if (this.f18828c != null && location.getTime() > this.f18828c.getTime() && this.f18827b.getTime() - this.f18828c.getTime() < com.igexin.push.config.c.f25230t) { long time = this.f18827b.getTime() - this.f18828c.getTime(); float[] fArr = new float[2]; Location.distanceBetween(c.c(this.f18827b), c.i(this.f18827b), c.h(this.f18828c), c.i(this.f18828c), fArr); double speed = (double) (((fArr[0] - (this.f18828c.getSpeed() * ((float) time))) * 2.0f) / ((float) (time * time))); if (speed > ((double) this.F)) { this.F = (float) speed; } } this.M.add(Byte.valueOf((byte) (abs & 255))); this.M.add(Byte.valueOf((byte) ((abs & 65280) >> 8))); this.M.add(Byte.valueOf((byte) (abs2 & 255))); this.M.add(Byte.valueOf((byte) ((abs2 & 65280) >> 8))); if (i14 > 0) { b14 = 32; if (c15 > 0) { b14 = (byte) 96; } } else { b14 = (byte) (((byte) (((int) (location.getBearing() / 15.0f)) & 255)) & 31); if (c15 > 0) { b14 = (byte) (b14 | 64); } } b14 = (byte) (b14 | Byte.MIN_VALUE); this.M.add(Byte.valueOf(b14)); if (i15 > 0) { this.M.add(Byte.MIN_VALUE); } else { this.M.add(Byte.valueOf((byte) (((byte) (((int) ((((double) location.getSpeed()) * 3.6d) / 4.0d)) & 255)) & ByteCompanionObject.MAX_VALUE))); } } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void e(String str) { try { File file = new File(j.f19185a + "/grtcf.dat"); if (!file.exists()) { File file2 = new File(j.f19185a); if (!file2.exists()) { file2.mkdirs(); } if (file.createNewFile()) { RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw"); randomAccessFile.seek(2); randomAccessFile.writeInt(0); randomAccessFile.seek(8); byte[] bytes = "1980_01_01:0".getBytes(); randomAccessFile.writeInt(bytes.length); randomAccessFile.write(bytes); randomAccessFile.seek(200); randomAccessFile.writeBoolean(false); randomAccessFile.seek(800); randomAccessFile.writeBoolean(false); randomAccessFile.close(); } else { return; } } RandomAccessFile randomAccessFile2 = new RandomAccessFile(file, "rw"); randomAccessFile2.seek(2); int readInt = randomAccessFile2.readInt(); int i10 = 1; while (i10 <= readInt) { randomAccessFile2.seek((long) (i10 * 2048)); int readInt2 = randomAccessFile2.readInt(); byte[] bArr = new byte[readInt2]; randomAccessFile2.read(bArr, 0, readInt2); if (new String(bArr).contains(b.f19135e)) { break; } i10++; } if (i10 >= readInt) { randomAccessFile2.seek(2); randomAccessFile2.writeInt(i10); } randomAccessFile2.seek((long) (i10 * 2048)); byte[] bytes2 = str.getBytes(); randomAccessFile2.writeInt(bytes2.length); randomAccessFile2.write(bytes2); randomAccessFile2.close(); } catch (Exception unused) { } } /* JADX WARNING: Removed duplicated region for block: B:26:0x0054 A[SYNTHETIC, Splitter:B:26:0x0054] */ /* JADX WARNING: Removed duplicated region for block: B:29:0x0059 A[Catch:{ Exception -> 0x005c }] */ /* JADX WARNING: Removed duplicated region for block: B:34:0x005f */ private boolean e() { RandomAccessFile randomAccessFile; Throwable th3; RandomAccessFile randomAccessFile2 = null; FileLock fileLock = null; r0 = null; FileChannel fileChannel = null; boolean z14 = false; try { File file = new File(k.i() + File.separator + "gflk.dat"); if (!file.exists()) { file.createNewFile(); } randomAccessFile = new RandomAccessFile(file, "rw"); try { FileChannel channel = randomAccessFile.getChannel(); try { fileLock = channel.tryLock(); } catch (Exception unused) { z14 = true; } catch (Throwable th4) { th3 = th4; fileChannel = channel; if (fileChannel != null) { try { fileChannel.close(); } catch (Exception unused2) { throw th3; } } if (randomAccessFile != null) { randomAccessFile.close(); } throw th3; } if (fileLock != null) { try { fileLock.release(); } catch (Exception unused3) { } } if (channel != null) { channel.close(); } randomAccessFile.close(); } catch (Exception unused4) { randomAccessFile2 = randomAccessFile; if (randomAccessFile2 != null) { randomAccessFile2.close(); } return z14; } catch (Throwable th5) { th3 = th5; if (fileChannel != null) { } if (randomAccessFile != null) { } throw th3; } } catch (Exception unused5) { if (randomAccessFile2 != null) { } return z14; } catch (Throwable th6) { th3 = th6; randomAccessFile = null; if (fileChannel != null) { } if (randomAccessFile != null) { } throw th3; } return z14; } private boolean f() { if (this.B) { if (this.C) { if (((double) this.E) < this.f18843t) { int i10 = this.D + this.f18839p; this.D = i10; return i10 <= this.f18844u || System.currentTimeMillis() - this.G > ((long) (this.f18845v * 1000)); } this.D = 0; this.C = false; } else if (((double) this.E) < this.f18843t) { this.C = true; this.D = 0; this.D = 0 + this.f18839p; } } else if (((double) this.E) >= this.f18841r || ((double) this.F) >= this.f18842s) { this.B = true; } else if (this.f18846w != 1 || System.currentTimeMillis() - this.G <= ((long) (this.f18847x * 1000))) { return false; } } private void g() { this.M = null; this.f18830e = 0; this.L = 0; this.f18827b = null; this.f18828c = null; this.E = 0.0f; this.F = 0.0f; } private void h() { if (this.f18830e != 0 && System.currentTimeMillis() - this.f18830e >= ((long) (this.f18839p * 1000))) { if (f.getServiceContext().getSharedPreferences("loc_navi_mode", 4).getBoolean("is_navi_on", false)) { g(); } else if (this.f18837n != 1 || f()) { if (!b.f19135e.equals("com.ubercab.driver")) { if (!a(b.f19135e, f.getServiceContext())) { g(); return; } } else if (e()) { g(); return; } List<Byte> list = this.M; if (list != null) { int size = list.size(); this.M.set(0, Byte.valueOf((byte) (size & 255))); this.M.set(1, Byte.valueOf((byte) ((65280 & size) >> 8))); this.M.set(3, Byte.valueOf((byte) (this.L & 255))); byte[] bArr = new byte[size]; for (int i10 = 0; i10 < size; i10++) { bArr[i10] = this.M.get(i10).byteValue(); } File file = new File(k.k(), "baidu/tempdata"); if (!file.exists()) { file.mkdirs(); } if (file.exists()) { File file2 = new File(file, "intime.dat"); if (file2.exists()) { file2.delete(); } try { BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file2)); bufferedOutputStream.write(bArr); bufferedOutputStream.flush(); bufferedOutputStream.close(); new f(this).start(); } catch (Exception unused) { } } g(); this.G = System.currentTimeMillis(); } } else { g(); } } } private void i() { byte b14; List<Byte> list; this.M.add((byte) 0); this.M.add((byte) 0); if (f18823f.equals("0")) { list = this.M; b14 = -82; } else { list = this.M; b14 = -66; } list.add(Byte.valueOf(b14)); this.M.add((byte) 0); this.M.add(Byte.valueOf(this.f18825J[0])); this.M.add(Byte.valueOf(this.f18825J[1])); this.M.add(Byte.valueOf(this.f18825J[2])); this.M.add(Byte.valueOf(this.f18825J[3])); int length = this.K.length; this.M.add(Byte.valueOf((byte) ((length + 1) & 255))); for (int i10 = 0; i10 < length; i10++) { this.M.add(Byte.valueOf(this.K[i10])); } } private void j() { if (System.currentTimeMillis() - this.f18849z > 86400000) { if (this.A == null) { this.A = new a(); } StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(b.a().a(false)); stringBuffer.append(a.a().c()); this.A.a(stringBuffer.toString()); } k(); } private void k() { } public void a(Location location) { if (!this.N) { c(); } if (this.f18834k == 1 && this.f18836m.contains(com.baidu.location.c.d.a(com.baidu.location.c.b.a().e()))) { if (this.f18837n != 1 || this.f18848y <= this.f18838o) { this.I.post(new e(this, location)); } } } public void b() { if (this.N) { this.N = false; g(); } } }