package com.baidu.location.b; import com.baidu.location.Jni; import com.baidu.location.e.d; import java.io.File; import java.io.RandomAccessFile; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; import org.json.JSONArray; import org.json.JSONObject; public class o implements f { private static final String e3 = (e.f17int + "/llg.dat"); private static o e4 = null; private static final int e6 = 128; private static String e7 = "LogSDK"; private static int e8 = 1024; private static final int e9 = 32; private static int fc = 5; private static final int fd = 1040; private static final String ff = (e.f17int + "/ller.dat"); private static final int fg = 1000; public static final String fh = (e.f17int + "/llin.dat"); private l e5 = null; private long fa = 0; private SimpleDateFormat fb = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private a fe = null; class a extends m { private String dp = null; private boolean dq = false; a() { this.db = new ArrayList(); } @Override // com.baidu.location.b.m public void at() { this.db.clear(); this.db.add(new BasicNameValuePair("qt", "stat")); this.db.add(new BasicNameValuePair("req", this.dp)); this.c9 = "http://loc.map.baidu.com/statloc"; } public boolean ax() { return this.dq; } /* renamed from: goto reason: not valid java name */ public void m109goto(String str) { this.dp = str; if (this.dp != null) { an(); this.dq = true; } } @Override // com.baidu.location.b.m /* renamed from: int reason: not valid java name */ public void m110int(boolean z) { this.dq = false; if (!z || this.da == null) { o.this.fa = System.currentTimeMillis(); return; } try { EntityUtils.toString(this.da, "utf-8"); } catch (Exception e2) { } } } private o() { if (this.e5 == null) { this.e5 = new l(); } } public static o aX() { if (e4 == null) { synchronized (o.class) { if (e4 == null) { e4 = new o(); } } } return e4; } /* renamed from: for reason: not valid java name */ public static synchronized void m105for(String str, String str2) { int i; synchronized (o.class) { File file = new File(str); if (!file.exists()) { i(str); } try { RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw"); randomAccessFile.seek(4); int readInt = randomAccessFile.readInt(); int readInt2 = randomAccessFile.readInt(); int readInt3 = randomAccessFile.readInt(); int readInt4 = randomAccessFile.readInt(); int readInt5 = randomAccessFile.readInt(); if (readInt3 < readInt) { randomAccessFile.seek((long) ((readInt2 * readInt3) + 128)); byte[] bytes = (str2 + (char) 0).getBytes(); randomAccessFile.writeInt(bytes.length); randomAccessFile.write(bytes, 0, bytes.length); i = readInt3 + 1; } else { randomAccessFile.seek((long) ((readInt4 * readInt2) + 128)); byte[] bytes2 = (str2 + (char) 0).getBytes(); randomAccessFile.writeInt(bytes2.length); randomAccessFile.write(bytes2, 0, bytes2.length); readInt4++; if (readInt4 > readInt3) { readInt4 = 0; i = readInt3; } else { i = readInt3; } } randomAccessFile.seek(12); randomAccessFile.writeInt(i); randomAccessFile.writeInt(readInt4); randomAccessFile.writeInt(readInt5); randomAccessFile.close(); } catch (Exception e2) { } } } private static void i(String str) { try { File file = new File(str); if (!file.exists()) { File file2 = new File(e.f17int); if (!file2.exists()) { file2.mkdirs(); } if (!file.createNewFile()) { file = null; } RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw"); randomAccessFile.seek(0); randomAccessFile.writeInt(32); randomAccessFile.writeInt(1000); randomAccessFile.writeInt(fd); randomAccessFile.writeInt(0); randomAccessFile.writeInt(0); randomAccessFile.writeInt(0); randomAccessFile.close(); } } catch (Exception e2) { } } /* renamed from: if reason: not valid java name */ public static boolean m107if(String str, List list) { File file = new File(str); if (!file.exists()) { return false; } try { RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw"); randomAccessFile.seek(8); int readInt = randomAccessFile.readInt(); int readInt2 = randomAccessFile.readInt(); int readInt3 = randomAccessFile.readInt(); byte[] bArr = new byte[e8]; int i = readInt2; int i2 = fc + 1; boolean z = false; while (i2 > 0 && i > 0) { if (i < readInt3) { readInt3 = 0; } try { randomAccessFile.seek((long) (((i - 1) * readInt) + 128)); int readInt4 = randomAccessFile.readInt(); if (readInt4 > 0 && readInt4 < readInt) { randomAccessFile.read(bArr, 0, readInt4); if (bArr[readInt4 - 1] == 0) { list.add(0, new String(bArr, 0, readInt4 - 1)); z = true; } } i2--; i--; } catch (Exception e2) { return z; } } randomAccessFile.seek(12); randomAccessFile.writeInt(i); randomAccessFile.writeInt(readInt3); randomAccessFile.close(); return z; } catch (Exception e10) { return false; } } public l aU() { return this.e5; } public void aV() { boolean z; boolean z2; if (this.fe == null) { this.fe = new a(); } if (System.currentTimeMillis() - this.fa >= com.umeng.analytics.a.h && !this.fe.ax()) { try { ArrayList arrayList = new ArrayList(); m107if(ff, arrayList); if (arrayList.size() > 0) { z = false; z2 = true; } else { m107if(e3, arrayList); if (arrayList.size() == 0) { m107if(fh, arrayList); z = true; z2 = false; } else { z = false; z2 = false; } } JSONArray jSONArray = new JSONArray(); JSONObject jSONObject = new JSONObject(); if (arrayList.size() > 0) { int size = arrayList.size(); for (int i = 0; i < size; i++) { jSONArray.put((String) arrayList.get(i)); } if (z2) { jSONObject.put("locpt", jSONArray); } else if (z) { jSONObject.put("locup", jSONArray); } else { jSONObject.put("loctc", jSONArray); } this.fe.m109goto(jSONObject.toString()); } } catch (Exception e2) { } } } public void aW() { if (this.e5 != null) { m105for(e3, Jni.H(this.e5.aj())); this.e5.ai(); } } /* renamed from: if reason: not valid java name */ public void m108if(l lVar) { if (lVar != null) { m105for(e3, Jni.H(lVar.aj())); } } public void j(String str) { if (str != null) { try { StringBuffer stringBuffer = new StringBuffer(); String format = this.fb.format(new Date()); stringBuffer.append("&time="); stringBuffer.append(format); stringBuffer.append("&err="); stringBuffer.append(str); stringBuffer.append(c.M().m53do(false)); stringBuffer.append(d.bv().by()); m105for(ff, Jni.H(stringBuffer.toString())); } catch (Exception e2) { } } } }