package com.baidu.location.indoor; import android.content.Context; import android.os.Build; import android.os.Handler; import android.util.Base64; 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.upstream.DefaultLoadErrorHandlingPolicy; import io.reactivex.annotations.SchedulerSupport; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import org.json.JSONObject; public class a extends e { private static HashMap<String, Long> a = new HashMap<>(); private static Object v = new Object(); private static a w = null; private String b = "http://loc.map.baidu.com/indoorlocbuildinginfo.php"; private final SimpleDateFormat c = new SimpleDateFormat("yyyyMM"); private Context d; private boolean e; private String f; private HashSet<String> q; private AbstractC0007a r; private String s = null; private Handler t; private Runnable u; /* renamed from: com.baidu.location.indoor.a$a */ public interface AbstractC0007a { void a(boolean z); } public a(Context context) { this.d = context; this.q = new HashSet<>(); this.e = false; this.k = new HashMap(); this.t = new Handler(); this.u = new b(this); } private String a(Date date) { File file = new File(this.d.getCacheDir(), k.a((this.f + this.c.format(date)).getBytes(), false)); if (!file.isFile()) { return null; } try { BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); String str = ""; while (true) { String readLine = bufferedReader.readLine(); if (readLine == null) { break; } str = str + readLine + "\n"; } bufferedReader.close(); if (!str.equals("")) { return new String(Base64.decode(str.getBytes(), 0)); } } catch (Exception unused) { } return null; } private Date d() { Calendar instance = Calendar.getInstance(); instance.add(2, -1); return instance.getTime(); } private void d(String str) { for (String str2 : str.split(",")) { this.q.add(str2.toLowerCase()); } } private void e() { try { Date d2 = d(); File file = new File(this.d.getCacheDir(), k.a((this.f + this.c.format(d2)).getBytes(), false)); if (file.isFile()) { file.delete(); } } catch (Exception unused) { } } private void e(String str) { try { FileWriter fileWriter = new FileWriter(new File(this.d.getCacheDir(), k.a((this.f + this.c.format(new Date())).getBytes(), false))); fileWriter.write(new String(Base64.encode(str.getBytes(), 0), "UTF-8")); fileWriter.flush(); fileWriter.close(); } catch (IOException unused) { } } private void f(String str) { try { FileWriter fileWriter = new FileWriter(new File(this.d.getCacheDir(), "buildings"), true); fileWriter.write(str + "\n"); fileWriter.flush(); fileWriter.close(); } catch (IOException e2) { e2.printStackTrace(); } } @Override // com.baidu.location.g.e public void a() { this.h = this.b; this.k.clear(); this.k.put("bid", SchedulerSupport.NONE); this.k.put("bldg", this.f); this.k.put("mb", Build.MODEL); this.k.put("msdk", "2.0"); this.k.put("cuid", b.a().c); this.k.put("anchors", "v1"); } /* JADX WARNING: Removed duplicated region for block: B:24:0x005b */ /* JADX WARNING: Removed duplicated region for block: B:25:0x005e */ /* JADX WARNING: Removed duplicated region for block: B:32:0x007f */ /* JADX WARNING: Removed duplicated region for block: B:34:? A[RETURN, SYNTHETIC] */ @Override // com.baidu.location.g.e public void a(boolean z) { boolean z2; AbstractC0007a aVar; String optString; if (z && this.j != null) { try { JSONObject jSONObject = new JSONObject(new String(Base64.decode(this.j.getBytes(), 0))); if (jSONObject.has("anchorinfo") && (optString = jSONObject.optString("anchorinfo")) != null && !optString.equals("")) { this.q.clear(); d(optString); e(optString); try { e(); } catch (Exception unused) { } z2 = true; if (z2 && this.s == null) { this.s = this.f; this.t.postDelayed(this.u, DefaultLoadErrorHandlingPolicy.DEFAULT_TRACK_BLACKLIST_MS); } else if (!z2) { this.s = null; } else { f(this.s); this.s = null; String a2 = a(d()); if (a2 != null) { d(a2); AbstractC0007a aVar2 = this.r; if (aVar2 != null) { aVar2.a(true); } } } this.e = false; aVar = this.r; if (aVar == null) { aVar.a(z2); return; } return; } } catch (Exception unused2) { } } z2 = false; if (z2) { } if (!z2) { } this.e = false; aVar = this.r; if (aVar == null) { } } public boolean a(String str) { String str2 = this.f; return str2 != null && str2.equalsIgnoreCase(str) && !this.q.isEmpty(); } public boolean a(String str, AbstractC0007a aVar) { if (!this.e) { this.r = aVar; this.e = true; this.f = str; try { String a2 = a(new Date()); if (a2 == null) { long currentTimeMillis = System.currentTimeMillis(); if (a.get(str) == null || currentTimeMillis - a.get(str).longValue() > 86400000) { a.put(str, Long.valueOf(currentTimeMillis)); b(v.a().c()); } } else { d(a2); if (this.r != null) { this.r.a(true); } this.e = false; } } catch (Exception unused) { this.e = false; } } return false; } public boolean b() { HashSet<String> hashSet = this.q; return hashSet != null && !hashSet.isEmpty(); } public boolean b(String str) { HashSet<String> hashSet; return this.f != null && (hashSet = this.q) != null && !hashSet.isEmpty() && this.q.contains(str); } public void c() { this.f = null; this.q.clear(); } }