package com.iflytek.idata.extension; import android.content.Context; import android.content.SharedPreferences; import android.os.SystemClock; import android.text.TextUtils; import android.util.Base64; import com.iflytek.idata.extension.b; import java.io.BufferedOutputStream; import java.io.Closeable; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import org.json.JSONObject; public class a implements Runnable { /* renamed from: a reason: collision with root package name */ private b.a f18636a = new C0202a(); /* renamed from: b reason: collision with root package name */ public Context f18637b; private boolean c; public a(Context context, boolean z) { this.f18637b = context; this.c = z; } private boolean b() { SharedPreferences b2; if (this.c || (b2 = com.iflytek.idata.extension.d.b.b(this.f18637b)) == null) { return true; } if (System.currentTimeMillis() - b2.getLong("last_check_time", 0) > 604800000) { return true; } return false; } public void run() { a(); } private void a() { try { SystemClock.sleep(10000); if (b() && com.iflytek.idata.extension.d.b.a(this.f18637b)) { b bVar = new b(); bVar.b(20000); bVar.a(1); JSONObject jSONObject = new JSONObject(); jSONObject.put("appid", IFlyCollectorExt.getInstance(this.f18637b).getAppId()); jSONObject.put("ver", IFlyCollectorExt.getInstance(this.f18637b).a()); jSONObject.put("impl", 2); jSONObject.put("pkg", this.f18637b.getPackageName()); bVar.a("https://logconf.iflytek.com/hotupdate", null, jSONObject.toString().getBytes("utf-8")); bVar.b(this.f18636a); } } catch (Throwable unused) { com.iflytek.idata.extension.d.a.c("Collector", "exception occur while update"); } } /* renamed from: com.iflytek.idata.extension.a$a reason: collision with other inner class name */ public class C0202a implements b.a { public C0202a() { } @Override // com.iflytek.idata.extension.b.a public void a(b bVar, byte[] bArr) { if (bArr != null) { try { a.this.a((a) new JSONObject(new String(bArr, "utf-8"))); } catch (Exception e) { a(e); } } } @Override // com.iflytek.idata.extension.b.a public void a(Exception exc) { com.iflytek.idata.extension.d.a.b("Collector", "update error:" + exc); } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void a(JSONObject jSONObject) { if ("yes".equalsIgnoreCase(jSONObject.optString("update"))) { String optString = jSONObject.optString("msg"); if (!TextUtils.isEmpty(optString)) { a(Base64.decode(optString, 0)); } } else { com.iflytek.idata.extension.d.a.a("Collector", "no need to update"); } SharedPreferences.Editor edit = com.iflytek.idata.extension.d.b.b(this.f18637b).edit(); edit.putLong("last_check_time", System.currentTimeMillis()); edit.apply(); } /* JADX DEBUG: Multi-variable search result rejected for r1v5, resolved type: java.io.BufferedOutputStream */ /* JADX WARN: Multi-variable type inference failed */ private void a(byte[] bArr) { Throwable th; FileOutputStream fileOutputStream; FileOutputStream fileOutputStream2; BufferedOutputStream bufferedOutputStream; IFlyCollectorExt instance = IFlyCollectorExt.getInstance(this.f18637b); instance.c(); File file = new File(instance.b(), com.iflytek.idata.extension.d.b.a()); FileOutputStream fileOutputStream3 = null; try { FileOutputStream fileOutputStream4 = new FileOutputStream(file); try { bufferedOutputStream = new BufferedOutputStream(fileOutputStream4); } catch (Throwable th2) { th = th2; fileOutputStream2 = fileOutputStream3; fileOutputStream3 = fileOutputStream4; fileOutputStream = fileOutputStream2; try { th.printStackTrace(); } finally { a(fileOutputStream); a(fileOutputStream3); } } try { bufferedOutputStream.write(bArr); a(bufferedOutputStream); a(fileOutputStream4); } catch (Throwable th3) { th = th3; fileOutputStream2 = bufferedOutputStream; fileOutputStream3 = fileOutputStream4; fileOutputStream = fileOutputStream2; th.printStackTrace(); } } catch (Throwable th4) { th = th4; fileOutputStream = fileOutputStream3; th.printStackTrace(); } } private static void a(Closeable closeable) { if (closeable != null) { try { closeable.close(); } catch (IOException unused) { } } } }