package com.baidu.techain.core; import android.content.ContentValues; import android.content.Context; import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.os.Build; import android.os.SystemClock; import android.text.TextUtils; import android.util.Base64; import android.util.Pair; import com.baidu.techain.ac.Callback; import com.baidu.techain.ac.U; import com.baidu.techain.b; import com.baidu.techain.h.a; import com.baidu.techain.i.n; import com.baidu.techain.i.o; import com.baidu.techain.i.s; import com.baidu.techain.i.v; import com.baidu.techain.rp.Report; import com.meizu.cloud.pushsdk.constants.PushConstants; import com.meizu.cloud.pushsdk.notification.model.NotifyType; import com.umeng.analytics.pro.ak; import com.xiaomi.mipush.sdk.Constants; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Timer; import java.util.TimerTask; import org.json.JSONArray; import org.json.JSONObject; /* compiled from: ForHostApp */ public final class c implements SharedPreferences.OnSharedPreferenceChangeListener { public static Context b = null; public static boolean c = false; public static List<Integer> d = new ArrayList(); private static c f; private static int g; public a a; private volatile boolean e = false; private com.baidu.techain.a.a h; public final void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String str) { if (str != null) { try { if (str.equals("xytk")) { d.a = this.a.E(); } if (str.equals("xyus")) { this.a.k(); } } catch (Throwable unused) { com.baidu.techain.i.c.a(); } } } private c(Context context) { Context applicationContext = context.getApplicationContext(); b = applicationContext; this.h = com.baidu.techain.a.a.a(applicationContext); a a2 = a.a(b); this.a = a2; SharedPreferences sharedPreferences = a2.c; if (sharedPreferences != null) { sharedPreferences.registerOnSharedPreferenceChangeListener(this); } } public static c a() { return f; } public static synchronized c a(Context context) { c cVar; synchronized (c.class) { if (f == null) { f = new c(context.getApplicationContext()); } cVar = f; } return cVar; } /* JADX WARNING: Code restructure failed: missing block: B:32:?, code lost: com.baidu.techain.i.c.a(); */ /* JADX WARNING: Code restructure failed: missing block: B:34:0x0106, code lost: return; */ /* JADX WARNING: Exception block dominator not found, dom blocks: [] */ /* JADX WARNING: Missing exception handler attribute for start block: B:31:0x0102 */ public final synchronized void b() { String str; if (!this.e) { this.e = true; s.a(b); com.baidu.techain.i.c.n(b); a aVar = this.a; aVar.b.putBoolean("s_c_c", true); if (Build.VERSION.SDK_INT >= 9) { aVar.b.apply(); } else { aVar.b.commit(); } com.baidu.techain.j.a.a().a(b, null); JSONObject o = com.baidu.techain.i.c.o(b); com.baidu.techain.i.c.d(b); a aVar2 = this.a; aVar2.b.putString("ssv", "3.5.9.0.1"); aVar2.b.commit(); Report.getInstance(b).n(); for (ApkInfo apkInfo : this.h.a()) { try { str = b.getFilesDir().getCanonicalPath(); } catch (IOException unused) { com.baidu.techain.i.c.a(); str = null; } if (str != null) { apkInfo.dataDir = str + "/.techain_" + apkInfo.key; StringBuilder sb = new StringBuilder(); sb.append(apkInfo.dataDir); sb.append("/lib"); com.baidu.techain.i.c.d(sb.toString()); } } this.h.d(); if (!this.a.a.getBoolean("iio", false)) { a aVar3 = this.a; aVar3.b.putBoolean("iio", true); aVar3.b.commit(); } else { com.baidu.techain.a.a aVar4 = this.h; ContentValues contentValues = new ContentValues(); contentValues.put("n", (Integer) 0); try { aVar4.c.update("pgntechain", contentValues, "n=-1", null); } catch (Throwable unused2) { com.baidu.techain.i.c.a(); } } v.a(b).b(new U(b, 1, false, o)); } } public final void c() { try { List<ApkInfo> a2 = this.h.a(); final List<Integer> q = this.a.q(); List<Integer> p = this.a.p(); for (int i = 0; i < p.size(); i++) { if (!q.contains(p.get(i))) { q.add(p.get(i)); } } Collections.sort(a2, new Comparator<ApkInfo>() { /* class com.baidu.techain.core.c.AnonymousClass1 */ /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object, java.lang.Object] */ @Override // java.util.Comparator public final /* synthetic */ int compare(ApkInfo apkInfo, ApkInfo apkInfo2) { ApkInfo apkInfo3 = apkInfo; ApkInfo apkInfo4 = apkInfo2; if (apkInfo3.priority == -1 && apkInfo4.priority != -1) { return 1; } if ((apkInfo3.priority != -1 && apkInfo4.priority == -1) || apkInfo3.priority < apkInfo4.priority) { return -1; } if (apkInfo3.priority > apkInfo4.priority) { return 1; } List list = q; int indexOf = (list == null || !list.contains(Integer.valueOf(apkInfo3.key))) ? -1 : q.indexOf(Integer.valueOf(apkInfo3.key)); List list2 = q; int indexOf2 = (list2 == null || !list2.contains(Integer.valueOf(apkInfo4.key))) ? -1 : q.indexOf(Integer.valueOf(apkInfo4.key)); if (indexOf != -1 && indexOf2 == -1) { return -1; } if ((indexOf == -1 && indexOf2 != -1) || indexOf > indexOf2) { return 1; } if (indexOf < indexOf2) { return -1; } return 0; } }); for (ApkInfo apkInfo : a2) { f a3 = f.a(); if ((a3 != null ? a3.d(apkInfo.packageName) : null) == null) { boolean z = this.h.g(apkInfo.key) != 3; if (!this.a.b() || !z) { File file = new File(b.getFilesDir(), ".b_techain"); if (file.exists()) { File file2 = new File(file, apkInfo.key + Constants.ACCEPT_TIME_SEPARATOR_SERVER + apkInfo.versionName); if (com.baidu.techain.i.c.a(file2)) { com.baidu.techain.c.a(file2); file2.delete(); } } } else { File file3 = new File(b.getFilesDir(), ".b_techain"); if (!file3.exists()) { file3.mkdir(); } File file4 = new File(apkInfo.pkgPath); File file5 = new File(file3, apkInfo.key + Constants.ACCEPT_TIME_SEPARATOR_SERVER + apkInfo.versionName); if (!com.baidu.techain.i.c.a(file5)) { com.baidu.techain.i.c.a(file4, file5); } com.baidu.techain.c.a(b, apkInfo.key, file4, file5); } a(apkInfo.key, apkInfo.versionName, null); } } } catch (Throwable unused) { com.baidu.techain.i.c.a(); } } public final void a(JSONObject jSONObject) { ApkInfo apkInfo; if (jSONObject != null) { try { JSONArray optJSONArray = jSONObject.optJSONArray("6"); if (optJSONArray != null) { int i = 0; while (true) { PackageInfo packageInfo = null; if (i >= optJSONArray.length()) { break; } JSONObject optJSONObject = optJSONArray.optJSONObject(i); int optInt = optJSONObject.optInt("errno"); int optInt2 = optJSONObject.optInt(NotifyType.LIGHTS); if (optInt == 1) { try { JSONObject optJSONObject2 = optJSONObject.optJSONObject("detail"); PackageInfo packageInfo2 = new PackageInfo(); packageInfo2.packageName = optJSONObject2.optString(ak.ax); packageInfo2.versionName = optJSONObject2.optString("v"); ApplicationInfo applicationInfo = new ApplicationInfo(); applicationInfo.className = optJSONObject2.optString("n"); if (!TextUtils.isEmpty(applicationInfo.className) && applicationInfo.className.startsWith(".")) { applicationInfo.className = packageInfo2.packageName + applicationInfo.className; } applicationInfo.theme = optJSONObject2.optInt(ak.aH); packageInfo2.applicationInfo = applicationInfo; JSONArray optJSONArray2 = optJSONObject2.optJSONArray(ak.av); if (optJSONArray2 != null && optJSONArray2.length() > 0) { ArrayList arrayList = new ArrayList(); for (int i2 = 0; i2 < optJSONArray2.length(); i2++) { try { JSONObject jSONObject2 = optJSONArray2.getJSONObject(i2); if (jSONObject2 != null) { ActivityInfo activityInfo = new ActivityInfo(); activityInfo.name = jSONObject2.optString("n"); if (!TextUtils.isEmpty(activityInfo.name) && activityInfo.name.startsWith(".")) { activityInfo.name = packageInfo2.packageName + activityInfo.name; } activityInfo.packageName = packageInfo2.packageName; activityInfo.theme = jSONObject2.optInt(ak.aH); activityInfo.labelRes = jSONObject2.optInt(NotifyType.LIGHTS); if (!TextUtils.isEmpty(activityInfo.name)) { arrayList.add(activityInfo); } } } catch (Throwable unused) { com.baidu.techain.i.c.a(); } } if (arrayList.size() > 0) { packageInfo2.activities = (ActivityInfo[]) arrayList.toArray(new ActivityInfo[arrayList.size()]); } } packageInfo = packageInfo2; } catch (Throwable unused2) { com.baidu.techain.i.c.a(); } if (!(com.baidu.techain.i.c.h == null || (apkInfo = com.baidu.techain.i.c.h.get(Integer.valueOf(optInt2))) == null || packageInfo == null || TextUtils.isEmpty(packageInfo.packageName))) { try { a(apkInfo.key, apkInfo.versionName, apkInfo.apkMD5, packageInfo); i++; } catch (Throwable unused3) { com.baidu.techain.i.c.a(); } } } i++; } if (com.baidu.techain.i.c.h != null) { com.baidu.techain.i.c.h.clear(); com.baidu.techain.i.c.h = null; } } } catch (Throwable unused4) { com.baidu.techain.i.c.a(); } } } /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r2v0, types: [java.io.FileOutputStream] */ /* JADX WARN: Type inference failed for: r2v1 */ /* JADX WARN: Type inference failed for: r2v16 */ /* JADX WARNING: Can't wrap try/catch for region: R(15:22|(1:24)|25|26|27|28|29|(2:30|(1:32)(1:128))|33|(2:35|(1:37)(5:38|(1:40)(1:41)|42|43|(2:53|(2:55|(1:57)))(5:46|(1:48)|49|(1:51)|52)))|58|(2:60|61)|62|63|129) */ /* JADX WARNING: Code restructure failed: missing block: B:130:?, code lost: return; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:62:0x0151 */ /* JADX WARNING: Removed duplicated region for block: B:111:0x01d8 A[SYNTHETIC, Splitter:B:111:0x01d8] */ /* JADX WARNING: Removed duplicated region for block: B:115:0x01df A[SYNTHETIC, Splitter:B:115:0x01df] */ /* JADX WARNING: Removed duplicated region for block: B:142:? A[RETURN, SYNTHETIC] */ /* JADX WARNING: Removed duplicated region for block: B:99:0x01b8 A[Catch:{ all -> 0x01e3 }] */ /* JADX WARNING: Unknown variable types count: 1 */ private void a(int i, String str, String str2, PackageInfo packageInfo) { InputStream inputStream; ?? r2; FileOutputStream fileOutputStream; FileOutputStream fileOutputStream2; boolean z; try { ApkInfo a2 = this.h.a(i); if (a2 != null) { if (com.baidu.techain.i.c.b(str, a2.versionName)) { try { ApkInfo a3 = this.h.a(i); if (a3 != null) { this.h.h(i); File file = new File(a3.pkgPath); if (file.exists()) { com.baidu.techain.c.a(file); file.delete(); } } } catch (Throwable unused) { com.baidu.techain.i.c.a(); } } else { return; } } } catch (Throwable unused2) { com.baidu.techain.i.c.a(); } File file2 = null; InputStream inputStream2 = null; try { if (!TextUtils.isEmpty(str)) { File file3 = new File(b.getFilesDir(), ".tmp_techain"); if (!file3.exists()) { file3.mkdir(); } File file4 = new File(file3, i + Constants.ACCEPT_TIME_SEPARATOR_SERVER + str + ".zip"); try { FileOutputStream fileOutputStream3 = new FileOutputStream(file4); try { inputStream2 = b.getAssets().open(String.valueOf(i)); byte[] bArr = new byte[8192]; while (true) { int read = inputStream2.read(bArr); z = false; if (read == -1) { break; } fileOutputStream3.write(bArr, 0, read); } fileOutputStream3.flush(); com.baidu.techain.i.c.a(file4.getAbsolutePath(), true); String a4 = n.a(file4); if (a4 != null) { if (a4.equalsIgnoreCase(str2)) { ApkInfo apkInfo = new ApkInfo(i, str, file4.getAbsolutePath()); apkInfo.apkMD5 = a4; apkInfo.priority = 1; this.h.a(apkInfo); if (this.h.g(i) != 3) { z = true; } if (!this.a.b() || !z) { File file5 = new File(b.getFilesDir(), ".b_techain"); fileOutputStream = fileOutputStream3; if (file5.exists()) { File file6 = new File(file5, i + Constants.ACCEPT_TIME_SEPARATOR_SERVER + str); fileOutputStream = fileOutputStream3; if (com.baidu.techain.i.c.a(file6)) { com.baidu.techain.c.a(file6); file6.delete(); fileOutputStream = fileOutputStream3; } } } else { File file7 = new File(b.getFilesDir(), ".b_techain"); if (!file7.exists()) { file7.mkdir(); } File file8 = new File(file7, i + Constants.ACCEPT_TIME_SEPARATOR_SERVER + str); if (!com.baidu.techain.i.c.a(file8)) { com.baidu.techain.i.c.a(file4, file8); } com.baidu.techain.c.a(b, i, file4, file8); fileOutputStream = fileOutputStream3; } } } file4.delete(); if (inputStream2 != null) { inputStream2.close(); } fileOutputStream3.close(); return; } catch (Throwable unused3) { inputStream = null; fileOutputStream2 = fileOutputStream3; file2 = file4; r2 = fileOutputStream2; try { com.baidu.techain.i.c.a(); if (file2 != null || !file2.exists()) { if (inputStream != null) { try { inputStream.close(); } catch (IOException unused4) { } } if (r2 != 0) { try { r2.close(); return; } catch (IOException unused5) { return; } } else { return; } } else { com.baidu.techain.c.a(file2); this.h.h(i); file2.delete(); if (r2 != 0) { try { return; } catch (IOException unused6) { return; } } else { return; } } } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException unused7) { } } if (r2 != 0) { try { r2.close(); } catch (IOException unused8) { } } } } } catch (Throwable unused9) { inputStream = null; fileOutputStream2 = inputStream; file2 = file4; r2 = fileOutputStream2; com.baidu.techain.i.c.a(); if (file2 != null) { } if (inputStream != null) { } if (r2 != 0) { } } } else { fileOutputStream = null; } ApkInfo a5 = this.h.a(i); if (a5 == null || !com.baidu.techain.i.c.c(a5.pkgPath)) { if (inputStream2 != null) { try { inputStream2.close(); } catch (IOException unused10) { } } if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException unused11) { } } } else { if (a(i, str, packageInfo)) { d.add(Integer.valueOf(i)); a aVar = this.a; aVar.b.putString("g_l_l_p_v_" + i, str); aVar.b.commit(); } if (inputStream2 != null) { try { inputStream2.close(); } catch (IOException unused12) { } } if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException unused13) { } } } } catch (Throwable unused14) { inputStream = null; r2 = inputStream; com.baidu.techain.i.c.a(); if (file2 != null) { } if (inputStream != null) { } if (r2 != 0) { } } } public final synchronized boolean a(int i, String str, PackageInfo packageInfo) { return a(i, str, false, packageInfo); } /* JADX WARNING: Code restructure failed: missing block: B:84:?, code lost: com.baidu.techain.i.c.a(); */ /* JADX WARNING: Code restructure failed: missing block: B:86:0x02a6, code lost: return false; */ /* JADX WARNING: Exception block dominator not found, dom blocks: [] */ /* JADX WARNING: Missing exception handler attribute for start block: B:83:0x02a2 */ private synchronized boolean a(int i, String str, boolean z, PackageInfo packageInfo) { String str2; String str3; if (z) { if (this.h.c(i) != 1) { return false; } } ApkInfo a2 = this.h.a(i); if (a2 == null) { HashMap hashMap = new HashMap(); hashMap.put(PushConstants.PUSH_TYPE_NOTIFY, 1); hashMap.put("1", String.valueOf(i)); hashMap.put(PushConstants.PUSH_TYPE_UPLOAD_LOG, str); if (!z) { com.baidu.techain.i.c.a(b, "1003105", (Map<String, Object>) hashMap, false); } return false; } else if (!com.baidu.techain.i.c.a(new File(a2.pkgPath))) { this.h.f(i); HashMap hashMap2 = new HashMap(); hashMap2.put(PushConstants.PUSH_TYPE_NOTIFY, 3); hashMap2.put("1", String.valueOf(i)); hashMap2.put(PushConstants.PUSH_TYPE_UPLOAD_LOG, str); if (!z) { com.baidu.techain.i.c.a(b, "1003105", (Map<String, Object>) hashMap2, false); } return false; } else { if (packageInfo != null) { a2.cloudPkgInfo = packageInfo; } f a3 = f.a(b.getApplicationContext()); if (!a3.a(a2, false)) { this.h.f(i); a3.a(a2.pkgPath); HashMap hashMap3 = new HashMap(); hashMap3.put(PushConstants.PUSH_TYPE_NOTIFY, 4); hashMap3.put("1", String.valueOf(i)); hashMap3.put(PushConstants.PUSH_TYPE_UPLOAD_LOG, str); if (!z) { com.baidu.techain.i.c.a(b, "1003105", (Map<String, Object>) hashMap3, false); } return false; } try { String[] g2 = com.baidu.techain.i.c.g(b); if (g2 == null || g2.length != 2 || TextUtils.isEmpty(g2[0]) || TextUtils.isEmpty(g2[1])) { str2 = com.baidu.techain.i.c.e; str3 = com.baidu.techain.i.c.f; } else { str2 = g2[0]; str3 = g2[1]; } ApkInfo c2 = a3.c(a2.pkgPath); e eVar = (e) c2.classLoader; Class<?> a4 = eVar.a("com.baidu.techain.engine.EngineImpl"); if (a4 == null) { Class<?> a5 = eVar.a("java.lang.String"); HashMap hashMap4 = new HashMap(); hashMap4.put(PushConstants.PUSH_TYPE_NOTIFY, 9); hashMap4.put("1", String.valueOf(i)); hashMap4.put(PushConstants.PUSH_TYPE_UPLOAD_LOG, str); hashMap4.put(PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, Base64.encodeToString(("classloader=" + eVar + ",StringClass=" + a5).getBytes(), 0).replace("\n", "").replace("\t", "").replace("\r", "")); if (!z) { com.baidu.techain.i.c.a(b, "1003105", (Map<String, Object>) hashMap4, false); } this.h.f(i); return false; } Object invoke = a4.getDeclaredMethod("getInstance", Context.class).invoke(a4, b); try { com.baidu.techain.i.c.a(invoke, "setSecurityVerifyInfo", new Class[]{String.class, String.class}, str2, str3); } catch (Throwable unused) { com.baidu.techain.i.c.a(); } if (!((Boolean) com.baidu.techain.i.c.a(invoke, "init", new Class[]{Integer.TYPE, Boolean.TYPE}, 0, true)).booleanValue()) { HashMap hashMap5 = new HashMap(); hashMap5.put(PushConstants.PUSH_TYPE_NOTIFY, 6); hashMap5.put("1", String.valueOf(i)); hashMap5.put(PushConstants.PUSH_TYPE_UPLOAD_LOG, str); if (!z) { com.baidu.techain.i.c.a(b, "1003105", (Map<String, Object>) hashMap5, false); } this.h.f(i); a3.a(c2.pkgPath); return false; } c2.initStatus = 1; c2.apkParseSuc = 1; this.h.a(c2); int g3 = this.h.g(c2.key); if (g3 < 3 && g3 != -1) { this.h.b(c2.key, g3 + 1); } o.a(this, c2.key); HashMap hashMap6 = new HashMap(); hashMap6.put(PushConstants.PUSH_TYPE_NOTIFY, 0); hashMap6.put("1", Integer.valueOf(i)); hashMap6.put(PushConstants.PUSH_TYPE_UPLOAD_LOG, str); if (!z) { com.baidu.techain.i.c.a(b, "1003105", (Map<String, Object>) hashMap6, false); } com.baidu.techain.i.c.c(b); return true; } catch (Throwable unused2) { com.baidu.techain.i.c.a(); } } return false; } public final void a(String str, String str2) { try { this.h.a(str); File file = new File(str2); if (file.exists()) { com.baidu.techain.c.a(file); file.delete(); } } catch (Throwable unused) { com.baidu.techain.i.c.a(); } } public final boolean a(ApkInfo apkInfo, String str) { Object obj; File file; Throwable th; String str2; String str3; File file2; int i; ApkInfo apkInfo2 = apkInfo; if (apkInfo2 == null) { return false; } File file3 = new File(apkInfo2.pkgPath); try { if (!com.baidu.techain.i.c.a(file3)) { try { HashMap hashMap = new HashMap(); hashMap.put(PushConstants.PUSH_TYPE_NOTIFY, 1); StringBuilder sb = new StringBuilder(); sb.append(apkInfo2.key); hashMap.put("1", sb.toString()); hashMap.put(PushConstants.PUSH_TYPE_UPLOAD_LOG, apkInfo2.versionName); StringBuilder sb2 = new StringBuilder("nowTime:"); file = file3; sb2.append(System.currentTimeMillis()); sb2.append(", nowFileInfo: path="); sb2.append(file.getAbsolutePath()); sb2.append(", exists="); sb2.append(file.exists()); sb2.append(", canRead="); sb2.append(file.canRead()); sb2.append(", isFile="); sb2.append(file.isFile()); sb2.append(",length"); sb2.append(file.length()); sb2.append(" - "); sb2.append(str); hashMap.put(PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, Base64.encodeToString(sb2.toString().getBytes(), 0).replace("\n", "").replace("\t", "").replace("\r", "")); com.baidu.techain.i.c.a(b, "1003106", (Map<String, Object>) hashMap, false); return false; } catch (Throwable th2) { th = th2; obj = PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START; com.baidu.techain.c.a(file); c(apkInfo2.packageName); file.delete(); a(apkInfo2.key, apkInfo2.versionName, true, (PackageInfo) null); this.h.a(apkInfo2.key, 0); HashMap hashMap2 = new HashMap(); hashMap2.put(PushConstants.PUSH_TYPE_NOTIFY, 5); StringBuilder sb3 = new StringBuilder(); sb3.append(apkInfo2.key); hashMap2.put("1", sb3.toString()); hashMap2.put(PushConstants.PUSH_TYPE_UPLOAD_LOG, apkInfo2.versionName); hashMap2.put(obj, Base64.encodeToString(b.a(th).getBytes(), 0).replace("\n", "").replace("\t", "").replace("\r", "")); com.baidu.techain.i.c.a(b, "1003106", (Map<String, Object>) hashMap2, false); return false; } } else { file = file3; if (!this.h.b(apkInfo2.key)) { this.h.a(apkInfo2); } f a2 = f.a(b.getApplicationContext()); this.h.a(apkInfo2.key, 1); c(apkInfo2.packageName); if (!a2.a(apkInfo2, true)) { HashMap hashMap3 = new HashMap(); hashMap3.put(PushConstants.PUSH_TYPE_NOTIFY, 2); StringBuilder sb4 = new StringBuilder(); sb4.append(apkInfo2.key); hashMap3.put("1", sb4.toString()); hashMap3.put(PushConstants.PUSH_TYPE_UPLOAD_LOG, apkInfo2.versionName); com.baidu.techain.i.c.a(b, "1003106", (Map<String, Object>) hashMap3, false); com.baidu.techain.c.a(file); file.delete(); a(apkInfo2.key, apkInfo2.versionName, true, (PackageInfo) null); this.h.a(apkInfo2.key, 0); return false; } String[] g2 = com.baidu.techain.i.c.g(b); if (g2 == null || g2.length != 2 || TextUtils.isEmpty(g2[0]) || TextUtils.isEmpty(g2[1])) { str2 = com.baidu.techain.i.c.e; str3 = com.baidu.techain.i.c.f; } else { str2 = g2[0]; str3 = g2[1]; } apkInfo2 = a2.c(apkInfo2.pkgPath); if (apkInfo2 == null) { return false; } e eVar = (e) apkInfo2.classLoader; Class<?> a3 = eVar.a("com.baidu.techain.engine.EngineImpl"); if (a3 == null) { Class<?> a4 = eVar.a("java.lang.String"); HashMap hashMap4 = new HashMap(); hashMap4.put(PushConstants.PUSH_TYPE_NOTIFY, 6); StringBuilder sb5 = new StringBuilder(); sb5.append(apkInfo2.key); hashMap4.put("1", sb5.toString()); hashMap4.put(PushConstants.PUSH_TYPE_UPLOAD_LOG, apkInfo2.versionName); hashMap4.put(PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, Base64.encodeToString(("classloader=" + eVar + ",StringClass=" + a4).getBytes(), 0).replace("\n", "").replace("\t", "").replace("\r", "")); com.baidu.techain.i.c.a(b, "1003106", (Map<String, Object>) hashMap4, false); com.baidu.techain.c.a(file); file.delete(); this.h.a(apkInfo2.key, 0); return false; } obj = PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START; try { Object invoke = a3.getDeclaredMethod("getInstance", Context.class).invoke(a3, b); try { com.baidu.techain.i.c.a(invoke, "setSecurityVerifyInfo", new Class[]{String.class, String.class}, str2, str3); } catch (Throwable unused) { com.baidu.techain.i.c.a(); } if (!((Boolean) com.baidu.techain.i.c.a(invoke, "init", new Class[]{Integer.TYPE, Boolean.TYPE}, 0, true)).booleanValue()) { com.baidu.techain.c.a(file); c(apkInfo2.packageName); file.delete(); a(apkInfo2.key, apkInfo2.versionName, true, (PackageInfo) null); this.h.a(apkInfo2.key, 0); HashMap hashMap5 = new HashMap(); hashMap5.put(PushConstants.PUSH_TYPE_NOTIFY, 4); StringBuilder sb6 = new StringBuilder(); sb6.append(apkInfo2.key); hashMap5.put("1", sb6.toString()); hashMap5.put(PushConstants.PUSH_TYPE_UPLOAD_LOG, apkInfo2.versionName); com.baidu.techain.i.c.a(b, "1003106", (Map<String, Object>) hashMap5, false); return false; } if (apkInfo2.isMem) { com.baidu.techain.c.a(file); file.delete(); com.baidu.techain.i.c.d(apkInfo2.dataDir); if (f.b != null) { f.b.add(Integer.valueOf(apkInfo2.key)); } } try { ApkInfo a5 = this.h.a(apkInfo2.key); if (a5 == null || a5.versionName.equals(apkInfo2.versionName)) { i = 1; file2 = null; } else { file2 = new File(a5.pkgPath); i = 1; } apkInfo2.initStatus = i; apkInfo2.apkParseSuc = i; if (this.h.a(apkInfo2) > 0 && file2 != null && file2.exists()) { com.baidu.techain.c.a(file2); file2.delete(); } this.h.a(apkInfo2.key, 0); o.a(this, apkInfo2.key); com.baidu.techain.i.c.c(b); HashMap hashMap6 = new HashMap(); hashMap6.put(PushConstants.PUSH_TYPE_NOTIFY, 0); StringBuilder sb7 = new StringBuilder(); sb7.append(apkInfo2.key); hashMap6.put("1", sb7.toString()); hashMap6.put(PushConstants.PUSH_TYPE_UPLOAD_LOG, apkInfo2.versionName); com.baidu.techain.i.c.a(b, "1003106", (Map<String, Object>) hashMap6, false); return true; } catch (Throwable unused2) { com.baidu.techain.i.c.a(); return true; } } catch (Throwable th3) { th = th3; com.baidu.techain.c.a(file); c(apkInfo2.packageName); file.delete(); a(apkInfo2.key, apkInfo2.versionName, true, (PackageInfo) null); this.h.a(apkInfo2.key, 0); HashMap hashMap22 = new HashMap(); hashMap22.put(PushConstants.PUSH_TYPE_NOTIFY, 5); StringBuilder sb32 = new StringBuilder(); sb32.append(apkInfo2.key); hashMap22.put("1", sb32.toString()); hashMap22.put(PushConstants.PUSH_TYPE_UPLOAD_LOG, apkInfo2.versionName); hashMap22.put(obj, Base64.encodeToString(b.a(th).getBytes(), 0).replace("\n", "").replace("\t", "").replace("\r", "")); com.baidu.techain.i.c.a(b, "1003106", (Map<String, Object>) hashMap22, false); return false; } } } catch (Throwable th4) { th = th4; obj = PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START; file = file3; com.baidu.techain.c.a(file); c(apkInfo2.packageName); file.delete(); a(apkInfo2.key, apkInfo2.versionName, true, (PackageInfo) null); this.h.a(apkInfo2.key, 0); HashMap hashMap222 = new HashMap(); hashMap222.put(PushConstants.PUSH_TYPE_NOTIFY, 5); StringBuilder sb322 = new StringBuilder(); sb322.append(apkInfo2.key); hashMap222.put("1", sb322.toString()); hashMap222.put(PushConstants.PUSH_TYPE_UPLOAD_LOG, apkInfo2.versionName); hashMap222.put(obj, Base64.encodeToString(b.a(th).getBytes(), 0).replace("\n", "").replace("\t", "").replace("\r", "")); com.baidu.techain.i.c.a(b, "1003106", (Map<String, Object>) hashMap222, false); return false; } } /* JADX WARNING: Code restructure failed: missing block: B:47:0x00ed, code lost: r0 = false; */ public final void a(int i, String str, Callback callback, Class<?>[] clsArr, Object... objArr) { int i2; boolean z; Throwable th; try { HashMap hashMap = new HashMap(); hashMap.put(PushConstants.PUSH_TYPE_NOTIFY, Integer.toString(i)); hashMap.put("1", !TextUtils.isEmpty(str) ? str : " "); hashMap.put(PushConstants.PUSH_TYPE_UPLOAD_LOG, PushConstants.PUSH_TYPE_NOTIFY); com.baidu.techain.i.c.a(b, "1003136", (Map<String, Object>) hashMap, false); if (TextUtils.isEmpty(str)) { if (callback != null) { callback.onError(1); } hashMap.put(PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, "11"); com.baidu.techain.i.c.a(b, "1003141", (Map<String, Object>) hashMap, false); return; } i2 = 18; if (callback != null) { try { callback.onBegin(new Object[0]); } catch (NoSuchMethodException unused) { if (callback != null) { callback.onError(2); } hashMap.put(PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, Integer.toString(14)); com.baidu.techain.i.c.a(b, "1003141", (Map<String, Object>) hashMap, false); return; } catch (InvocationTargetException unused2) { if (callback != null) { callback.onError(2); } hashMap.put(PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, Integer.toString(15)); com.baidu.techain.i.c.a(b, "1003141", (Map<String, Object>) hashMap, false); return; } catch (IllegalAccessException unused3) { if (callback != null) { callback.onError(2); } hashMap.put(PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, Integer.toString(16)); com.baidu.techain.i.c.a(b, "1003141", (Map<String, Object>) hashMap, false); return; } catch (IllegalArgumentException unused4) { if (callback != null) { callback.onError(2); } hashMap.put(PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, Integer.toString(17)); com.baidu.techain.i.c.a(b, "1003141", (Map<String, Object>) hashMap, false); return; } catch (Throwable unused5) { return; } } if (this.h.d(i)) { long currentTimeMillis = System.currentTimeMillis(); while (this.h.d(i) && System.currentTimeMillis() - currentTimeMillis < 10000) { SystemClock.sleep(300); } } if (this.h.d(i)) { if (callback != null) { callback.onError(3); } try { hashMap.put(PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, Integer.toString(12)); com.baidu.techain.i.c.a(b, "1003141", (Map<String, Object>) hashMap, false); return; } catch (Throwable unused6) { return; } } else { if (!this.e) { a(3); b(); } f a2 = f.a(b.getApplicationContext()); ApkInfo apkInfo = null; long currentTimeMillis2 = System.currentTimeMillis(); while (true) { if (System.currentTimeMillis() - currentTimeMillis2 > 15000) { break; } apkInfo = this.h.a(i); if (apkInfo != null) { if (a2.d(apkInfo.packageName) == null) { if (apkInfo.initStatus == -1) { break; } } else { z = true; break; } } SystemClock.sleep(1000); } if (!z) { if (callback != null) { callback.onError(4); } try { hashMap.put(PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, Integer.toString(13)); com.baidu.techain.i.c.a(b, "1003141", (Map<String, Object>) hashMap, false); return; } catch (Throwable unused7) { return; } } else { Class<?> a3 = ((e) a2.d(apkInfo.packageName).classLoader).a("com.baidu.techain.engine.EngineImpl"); Object a4 = com.baidu.techain.i.c.a(a3.getDeclaredMethod("getInstance", Context.class).invoke(a3, b), str, clsArr, objArr); if (callback != null) { callback.onEnd(a4); return; } return; } } throw th; if (i2 != 0) { try { hashMap.put(PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, Integer.toString(i2)); com.baidu.techain.i.c.a(b, "1003141", (Map<String, Object>) hashMap, false); } catch (Throwable unused8) { } } throw th; } catch (Throwable unused9) { com.baidu.techain.i.c.a(); } } /* JADX WARNING: Code restructure failed: missing block: B:46:?, code lost: r0 = new android.util.Pair<>(3, null); */ /* JADX WARNING: Code restructure failed: missing block: B:48:?, code lost: r2.put(com.meizu.cloud.pushsdk.constants.PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, java.lang.Integer.toString(10)); com.baidu.techain.i.c.a(com.baidu.techain.core.c.b, "1003141", (java.util.Map<java.lang.String, java.lang.Object>) r2, true); */ /* JADX WARNING: Code restructure failed: missing block: B:49:0x0125, code lost: return r0; */ /* JADX WARNING: Code restructure failed: missing block: B:51:0x0126, code lost: r0 = th; */ /* JADX WARNING: Code restructure failed: missing block: B:53:?, code lost: r0 = new android.util.Pair<>(2, null); */ /* JADX WARNING: Code restructure failed: missing block: B:55:?, code lost: r2.put(com.meizu.cloud.pushsdk.constants.PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, java.lang.Integer.toString(9)); com.baidu.techain.i.c.a(com.baidu.techain.core.c.b, "1003141", (java.util.Map<java.lang.String, java.lang.Object>) r2, true); */ /* JADX WARNING: Code restructure failed: missing block: B:56:0x013d, code lost: return r0; */ /* JADX WARNING: Code restructure failed: missing block: B:58:0x013e, code lost: r0 = th; */ /* JADX WARNING: Code restructure failed: missing block: B:59:0x013f, code lost: r3 = 9; */ /* JADX WARNING: Code restructure failed: missing block: B:61:?, code lost: r0 = new android.util.Pair<>(2, null); */ /* JADX WARNING: Code restructure failed: missing block: B:63:?, code lost: r2.put(com.meizu.cloud.pushsdk.constants.PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, java.lang.Integer.toString(8)); com.baidu.techain.i.c.a(com.baidu.techain.core.c.b, "1003141", (java.util.Map<java.lang.String, java.lang.Object>) r2, true); */ /* JADX WARNING: Code restructure failed: missing block: B:64:0x0157, code lost: return r0; */ /* JADX WARNING: Code restructure failed: missing block: B:66:0x0158, code lost: r0 = th; */ /* JADX WARNING: Code restructure failed: missing block: B:67:0x0159, code lost: r3 = 8; */ /* JADX WARNING: Code restructure failed: missing block: B:69:?, code lost: r0 = new android.util.Pair<>(2, null); */ /* JADX WARNING: Code restructure failed: missing block: B:72:?, code lost: r2.put(com.meizu.cloud.pushsdk.constants.PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, java.lang.Integer.toString(7)); com.baidu.techain.i.c.a(com.baidu.techain.core.c.b, "1003141", (java.util.Map<java.lang.String, java.lang.Object>) r2, true); */ /* JADX WARNING: Code restructure failed: missing block: B:73:0x0172, code lost: return r0; */ /* JADX WARNING: Code restructure failed: missing block: B:75:0x0173, code lost: r0 = th; */ /* JADX WARNING: Code restructure failed: missing block: B:76:0x0174, code lost: r3 = 7; */ /* JADX WARNING: Code restructure failed: missing block: B:78:?, code lost: r0 = new android.util.Pair<>(2, null); */ /* JADX WARNING: Code restructure failed: missing block: B:81:?, code lost: r2.put(com.meizu.cloud.pushsdk.constants.PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, java.lang.Integer.toString(6)); com.baidu.techain.i.c.a(com.baidu.techain.core.c.b, "1003141", (java.util.Map<java.lang.String, java.lang.Object>) r2, true); */ /* JADX WARNING: Code restructure failed: missing block: B:82:0x018c, code lost: return r0; */ /* JADX WARNING: Code restructure failed: missing block: B:84:0x018d, code lost: r0 = th; */ /* JADX WARNING: Code restructure failed: missing block: B:85:0x018e, code lost: r3 = 6; */ /* JADX WARNING: Code restructure failed: missing block: B:86:0x018f, code lost: if (r3 != 0) goto L_0x0191; */ /* JADX WARNING: Code restructure failed: missing block: B:88:?, code lost: r2.put(com.meizu.cloud.pushsdk.constants.PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, java.lang.Integer.toString(r3)); com.baidu.techain.i.c.a(com.baidu.techain.core.c.b, "1003141", (java.util.Map<java.lang.String, java.lang.Object>) r2, true); */ /* JADX WARNING: Code restructure failed: missing block: B:89:0x019d, code lost: throw r0; */ /* JADX WARNING: Exception block dominator not found, dom blocks: [B:45:0x0110, B:52:0x0128, B:60:0x0142, B:68:0x015c, B:77:0x0176] */ /* JADX WARNING: Missing exception handler attribute for start block: B:45:0x0110 */ /* JADX WARNING: Missing exception handler attribute for start block: B:52:0x0128 */ /* JADX WARNING: Missing exception handler attribute for start block: B:60:0x0142 */ /* JADX WARNING: Missing exception handler attribute for start block: B:68:0x015c */ /* JADX WARNING: Missing exception handler attribute for start block: B:77:0x0176 */ /* JADX WARNING: Removed duplicated region for block: B:87:0x0191 A[SYNTHETIC, Splitter:B:87:0x0191] */ public final Pair<Integer, Object> a(int i, String str, Class<?>[] clsArr, Object... objArr) { HashMap hashMap = new HashMap(); hashMap.put(PushConstants.PUSH_TYPE_NOTIFY, Integer.toString(i)); hashMap.put("1", !TextUtils.isEmpty(str) ? str : " "); hashMap.put(PushConstants.PUSH_TYPE_UPLOAD_LOG, "1"); com.baidu.techain.i.c.a(b, "1003136", (Map<String, Object>) hashMap, true); if (TextUtils.isEmpty(str)) { hashMap.put(PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, "1"); com.baidu.techain.i.c.a(b, "1003141", (Map<String, Object>) hashMap, true); return new Pair<>(1, null); } int i2 = 10; if (this.h.d(i)) { Pair<Integer, Object> pair = new Pair<>(3, null); try { hashMap.put(PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, Integer.toString(2)); com.baidu.techain.i.c.a(b, "1003141", (Map<String, Object>) hashMap, true); } catch (Throwable unused) { } return pair; } else if (!this.e) { Pair<Integer, Object> pair2 = new Pair<>(3, null); try { hashMap.put(PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, Integer.toString(3)); com.baidu.techain.i.c.a(b, "1003141", (Map<String, Object>) hashMap, true); } catch (Throwable unused2) { } return pair2; } else { f a2 = f.a(); if (a2 == null) { Pair<Integer, Object> pair3 = new Pair<>(3, null); try { hashMap.put(PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, Integer.toString(4)); com.baidu.techain.i.c.a(b, "1003141", (Map<String, Object>) hashMap, true); } catch (Throwable unused3) { } return pair3; } ApkInfo a3 = this.h.a(i); if (!((a3 == null || a2.d(a3.packageName) == null) ? false : true)) { Pair<Integer, Object> pair4 = new Pair<>(4, null); try { hashMap.put(PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, Integer.toString(5)); com.baidu.techain.i.c.a(b, "1003141", (Map<String, Object>) hashMap, true); } catch (Throwable unused4) { } return pair4; } Class<?> a4 = ((e) a2.d(a3.packageName).classLoader).a("com.baidu.techain.engine.EngineImpl"); return new Pair<>(0, com.baidu.techain.i.c.a(a4.getDeclaredMethod("getInstance", Context.class).invoke(a4, b), str, clsArr, objArr)); } } private static void c(String str) { f a2; ApkInfo d2; Class<?> a3; Object invoke; try { if (!TextUtils.isEmpty(str) && (a2 = f.a()) != null && (d2 = a2.d(str)) != null && (invoke = (a3 = ((e) d2.classLoader).a("com.baidu.techain.engine.EngineImpl")).getDeclaredMethod("getInstance", Context.class).invoke(a3, b)) != null) { com.baidu.techain.i.c.a(invoke, "unload", (Class<?>[]) null, new Object[0]); a2.b(str); } } catch (Throwable unused) { } } public final void a(final String str) { try { v.a(b).a(new Runnable() { /* class com.baidu.techain.core.c.AnonymousClass2 */ /* JADX WARNING: Code restructure failed: missing block: B:4:0x0009, code lost: r0 = com.baidu.techain.core.f.a(com.baidu.techain.core.c.b.getApplicationContext()); */ public final void run() { final f a2; try { if (!TextUtils.isEmpty(str) && a2 != null) { final File file = new File(c.b.getFilesDir(), ".b_techain"); final ApkInfo d = a2.d(str); if (d == null) { ApkInfo b2 = c.this.h.b(str); if (b2 != null) { c.this.a(str, b2.pkgPath); if (file.exists()) { File file2 = new File(file, b2.key + Constants.ACCEPT_TIME_SEPARATOR_SERVER + b2.versionName); if (com.baidu.techain.i.c.a(file2)) { file2.delete(); } } if (b2 != null) { String canonicalPath = c.b.getFilesDir().getCanonicalPath(); com.baidu.techain.i.c.d(canonicalPath + "/.techain_" + b2.key); com.baidu.techain.i.c.d(c.b.getFileStreamPath(b2.packageName).getAbsolutePath()); } String sb = new StringBuilder(str).reverse().toString(); ApkInfo b3 = c.this.h.b(sb); if (b3 != null) { c.this.a(sb, b3.pkgPath); return; } return; } return; } Class<?> a3 = ((e) d.classLoader).a("com.baidu.techain.engine.EngineImpl"); Object invoke = a3.getDeclaredMethod("getInstance", Context.class).invoke(a3, c.b); if (invoke != null) { new Timer().schedule(new TimerTask() { /* class com.baidu.techain.core.c.AnonymousClass2.AnonymousClass1 */ public final void run() { ApkInfo d2 = a2.d(str); if (d2 != null && d2.versionName != null && d2.versionName.equals(d.versionName)) { a2.b(str); c.this.h.a(str); com.baidu.techain.i.c.c(c.b); File file = new File(d.pkgPath); if (file.exists()) { com.baidu.techain.c.a(file); file.delete(); } if (file.exists()) { File file2 = file; File file3 = new File(file2, d.key + Constants.ACCEPT_TIME_SEPARATOR_SERVER + d.versionName); if (com.baidu.techain.i.c.a(file3)) { file3.delete(); } } String sb = new StringBuilder(str).reverse().toString(); ApkInfo b2 = c.this.h.b(sb); if (b2 != null) { c.this.a(sb, b2.pkgPath); } } } }, 600000); com.baidu.techain.i.c.a(invoke, "unload", (Class<?>[]) null, new Object[0]); a2.b(str); c.this.h.a(str); com.baidu.techain.i.c.c(c.b); File file3 = new File(d.pkgPath); if (file3.exists()) { com.baidu.techain.c.a(file3); file3.delete(); } if (file.exists()) { File file4 = new File(file, d.key + Constants.ACCEPT_TIME_SEPARATOR_SERVER + d.versionName); if (com.baidu.techain.i.c.a(file4)) { file4.delete(); } } String sb2 = new StringBuilder(str).reverse().toString(); ApkInfo b4 = c.this.h.b(sb2); if (b4 != null) { c.this.a(sb2, b4.pkgPath); } } } } catch (Throwable unused) { } } }); } catch (Throwable unused) { com.baidu.techain.i.c.a(); } } public static void a(int i) { if (g == 0) { g = i; } } public final boolean b(String str) { this.h.d(); this.e = true; return a(b, str); } private boolean a(Context context, String str) { try { f a2 = f.a(context); if (a2 == null) { return false; } if (a2.d(str) != null) { return true; } if (this.h == null) { this.h = com.baidu.techain.a.a.a(b); } ApkInfo b2 = this.h.b(str); if (b2 != null) { if (this.a.b()) { File file = new File(b.getFilesDir(), ".b_techain"); if (!file.exists()) { file.mkdir(); } File file2 = new File(b2.pkgPath); File file3 = new File(file, b2.key + Constants.ACCEPT_TIME_SEPARATOR_SERVER + b2.versionName); if (!com.baidu.techain.i.c.a(file3)) { com.baidu.techain.i.c.a(file2, file3); } com.baidu.techain.c.a(b, b2.key, file2, file3); } if (a(b2.key, b2.versionName, null)) { return true; } } if (a2.d(str) == null) { return false; } return true; } catch (Throwable unused) { com.baidu.techain.i.c.a(); return false; } } }