package com.baidu.techain.ac; import android.accounts.NetworkErrorException; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.text.TextUtils; import com.baidu.techain.TechainReceiver; import com.baidu.techain.TechainService; import com.baidu.techain.a.a; import com.baidu.techain.b; import com.baidu.techain.core.ApkInfo; import com.baidu.techain.core.c; import com.baidu.techain.core.f; import com.baidu.techain.core.i; import com.baidu.techain.i.g; import com.baidu.techain.i.l; import com.baidu.techain.i.n; import com.baidu.techain.i.q; import com.baidu.techain.i.v; import com.baidu.techain.jni.Asc; import com.huawei.hms.framework.common.ExceptionCode; import com.huawei.hms.push.constant.RemoteMessageConst; import com.huawei.hms.push.e; 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.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Timer; import java.util.TimerTask; import org.json.JSONArray; import org.json.JSONObject; public class U implements Runnable { public static final int FROM_DAILY_ALARM = 6; public static final int FROM_DEFAULT = 0; public static final int FROM_HANDLE_REMOVE = 4; public static final int FROM_INIT = 1; public static final int FROM_INIT_ALARM = 2; public static final int FROM_NET_CHANGE = 3; public static final int FROM_OUT_FLASH = 5; public static final int MINUTE = 60000; public static final int NETWORK_TYPE_2G = 1; public static final int NETWORK_TYPE_3G = 2; public static final int NETWORK_TYPE_4G = 3; public static final int NETWORK_TYPE_MOBILE = 5; public static final int NETWORK_TYPE_UNCONNECTED = -1; public static final int NETWORK_TYPE_UNKNOWN = -2; public static final int NETWORK_TYPE_WIFI = 4; public static final int OUT_AES_FAIL = 8; public static final int OUT_FINISH = 1; public static final int OUT_NO_INTERNET = 3; public static final int OUT_NULL_APPKEY = 5; public static final int OUT_NULL_HOST_PKGINFO = 6; public static final int OUT_NULL_PLUGIN_JSON = 10; public static final int OUT_NULL_RESPONSE_JSON = 9; public static final int OUT_OTHER_THROWABLE = 11; public static final int OUT_PING_FAIL = 4; public static final int OUT_RESPONSE_EMPTY = 7; public static final int OUT_TIME_TOO_CLOSE = 2; public static final int OUT_UNSET = 0; public static final int TYPE_END = 1; public static final int TYPE_START = 0; public static final int UPGRADE_DECRYPT_FAIL = 7; public static final int UPGRADE_DOWNLOAD_FAIL = 4; public static final int UPGRADE_ERROR_CRASH_TIMES = 6; public static final int UPGRADE_LOAD_FAIL = 5; public static final int UPGRADE_MD5_FAIL = 8; public static final int UPGRADE_NETWORK_CHECK_FAIL = 3; public static final int UPGRADE_RESULT_EXCEPTION = 2; public static final int UPGRADE_RESULT_SUCCESS = 1; private static long sLastCheckTime = 0; public static boolean sMonitorNetworkWhenUpgradeNoNet = false; private static volatile boolean sOutGoing = false; public static Map<String, String> sRealtimeMd5Map = null; private static int sRetryDownoadHostCareApksTimesCount = 0; private static int sRetryPingTimesCount = 0; private static boolean sSetRetrmAlarm = false; private Context context; private c forHostAPP; private a loadedPluginDB; private Map<Integer, String> mCloudKeyMap = new HashMap(); List<Integer> mDownloadPluginsList = new ArrayList(); private int mEndReason = 0; private int mFrom = 0; private boolean mOut = false; private com.baidu.techain.h.a mPreferenceManager; private Map<Integer, String> mStartKeyMap; private int mStartNetwork = -2; List<Integer> mUnloadPluginsList = new ArrayList(); private Map<Integer, UpgradeResult> mUpgradeResultMap = new HashMap(); private JSONObject mWholeJson; private File tmpDir; /* access modifiers changed from: private */ public class UpgradeResult { int networkId; int resultId; public UpgradeResult(int i, int i2) { this.networkId = i; this.resultId = i2; } } public U(Context context2, int i, boolean z) { this.context = context2; this.loadedPluginDB = a.a(context2); this.mPreferenceManager = com.baidu.techain.h.a.a(context2); this.forHostAPP = c.a(context2); this.tmpDir = new File(context2.getFilesDir(), ".tmp_techain"); this.mFrom = i; this.mOut = z; } public U(Context context2, int i, boolean z, JSONObject jSONObject) { this.context = context2; this.loadedPluginDB = a.a(context2); this.mPreferenceManager = com.baidu.techain.h.a.a(context2); this.forHostAPP = c.a(context2); this.tmpDir = new File(context2.getFilesDir(), ".tmp_techain"); this.mFrom = i; this.mOut = z; this.mWholeJson = jSONObject; } public U() { } public void handleWork(Context context2, Intent intent) { this.context = context2; this.loadedPluginDB = a.a(context2); this.mPreferenceManager = com.baidu.techain.h.a.a(context2); this.tmpDir = new File(context2.getFilesDir(), ".tmp_techain"); this.forHostAPP = c.a(context2); this.mFrom = intent.getIntExtra(RemoteMessageConst.FROM, 0); v.a(context2).b(this); } /* JADX WARNING: Code restructure failed: missing block: B:12:?, code lost: com.baidu.techain.i.c.a(); */ /* JADX WARNING: Code restructure failed: missing block: B:331:0x0703, code lost: if (r29.mEndReason != 0) goto L_0x0708; */ /* JADX WARNING: Code restructure failed: missing block: B:332:0x0705, code lost: r29.mEndReason = 1; */ /* JADX WARNING: Code restructure failed: missing block: B:333:0x0708, code lost: handleThreadEnd(null); */ /* JADX WARNING: Code restructure failed: missing block: B:336:0x070e, code lost: if (r29.mOut == false) goto L_0x0717; */ /* JADX WARNING: Code restructure failed: missing block: B:338:0x0712, code lost: if (com.baidu.techain.ac.U.sOutGoing == false) goto L_0x0717; */ /* JADX WARNING: Code restructure failed: missing block: B:339:0x0714, code lost: com.baidu.techain.ac.U.sOutGoing = false; */ /* JADX WARNING: Code restructure failed: missing block: B:33:0x0048, code lost: if (r29.mOut == false) goto L_0x0050; */ /* JADX WARNING: Code restructure failed: missing block: B:341:0x0718, code lost: return; */ /* JADX WARNING: Code restructure failed: missing block: B:342:0x0719, code lost: com.baidu.techain.i.c.a(); */ /* JADX WARNING: Code restructure failed: missing block: B:345:0x071d, code lost: return; */ /* JADX WARNING: Code restructure failed: missing block: B:35:0x004c, code lost: if (com.baidu.techain.ac.U.sOutGoing == false) goto L_0x0050; */ /* JADX WARNING: Code restructure failed: missing block: B:36:0x004e, code lost: com.baidu.techain.ac.U.sOutGoing = false; */ /* JADX WARNING: Code restructure failed: missing block: B:38:0x0051, code lost: return; */ /* JADX WARNING: Code restructure failed: missing block: B:39:0x0052, code lost: com.baidu.techain.i.c.a(); */ /* JADX WARNING: Code restructure failed: missing block: B:42:0x0056, code lost: return; */ /* JADX WARNING: Exception block dominator not found, dom blocks: [] */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:11:0x0013 */ /* JADX WARNING: Missing exception handler attribute for start block: B:191:0x03d6 */ /* JADX WARNING: Missing exception handler attribute for start block: B:51:0x00e9 */ /* JADX WARNING: Removed duplicated region for block: B:204:0x0411 */ /* JADX WARNING: Removed duplicated region for block: B:205:0x0413 */ /* JADX WARNING: Removed duplicated region for block: B:213:0x042b */ /* JADX WARNING: Removed duplicated region for block: B:214:0x042d */ /* JADX WARNING: Removed duplicated region for block: B:217:0x0432 */ /* JADX WARNING: Removed duplicated region for block: B:220:0x043c */ /* JADX WARNING: Removed duplicated region for block: B:223:0x0454 */ /* JADX WARNING: Removed duplicated region for block: B:238:0x04a4 */ /* JADX WARNING: Removed duplicated region for block: B:241:0x04c0 */ /* JADX WARNING: Removed duplicated region for block: B:244:0x04d7 */ /* JADX WARNING: Removed duplicated region for block: B:246:0x04dc */ /* JADX WARNING: Removed duplicated region for block: B:271:0x0562 */ public synchronized void run() { JSONObject jSONObject; List<ApkInfo> list; ArrayList arrayList; ArrayList arrayList2; ArrayList arrayList3; ArrayList arrayList4; PackageInfo packageInfo; ApkInfo apkInfo; JSONObject optJSONObject; JSONObject optJSONObject2; boolean z; int indexOf; int indexOf2; ArrayList arrayList5; ArrayList arrayList6; ArrayList arrayList7; JSONArray jSONArray; if (this.mOut) { if (!sOutGoing) { sOutGoing = true; } else { return; } } try { synchronized (U.class) { handleThreadStart(); if (this.mFrom == 1 || this.mFrom == 2 || this.mFrom == 3 || this.mOut || System.currentTimeMillis() - sLastCheckTime >= 600000) { if (com.baidu.techain.i.c.f(this.context)) { sLastCheckTime = System.currentTimeMillis(); } Context context2 = this.context; try { com.baidu.techain.h.a a = com.baidu.techain.h.a.a(context2); AlarmManager alarmManager = (AlarmManager) context2.getSystemService("alarm"); Intent intent = new Intent("com.baidu.action.Techain.VIEW"); intent.setClass(context2, TechainService.class); intent.setPackage(context2.getPackageName()); intent.addCategory("com.baidu.category.techain"); intent.addCategory("android.intent.category.DEFAULT"); intent.putExtra("from_plugin_package", context2.getPackageName()); intent.putExtra("target_class", U.class.getCanonicalName()); intent.putExtra("target_method", "handleWork"); intent.putExtra(RemoteMessageConst.FROM, 6); PendingIntent service = PendingIntent.getService(context2, 1000, intent, 134217728); long currentTimeMillis = ((System.currentTimeMillis() + (((long) a.a.getInt("appal_te", 24)) * 3600000)) - 600000) + ((long) (Math.random() * 1200000.0d)); a.b.putLong("npuct", currentTimeMillis); a.b.commit(); alarmManager.cancel(service); try { alarmManager.set(1, currentTimeMillis, service); } catch (Throwable unused) { } } catch (Throwable unused2) { com.baidu.techain.i.c.a(); } i.a(this.context); if (this.mFrom == 1 || this.mFrom == 3) { sRetryPingTimesCount = 0; sRetryDownoadHostCareApksTimesCount = 0; com.baidu.techain.i.a.a(this.context, 0, true); sSetRetrmAlarm = false; } if (this.mFrom == 2) { sSetRetrmAlarm = false; } boolean z2 = "com.baidu.input_huawei".equals(this.context.getPackageName()) ? !this.mPreferenceManager.w() : false; if (!com.baidu.techain.i.c.f(this.context) || z2) { if (this.mFrom == 1 || this.mFrom == 2 || this.mFrom == 3) { sMonitorNetworkWhenUpgradeNoNet = true; IntentFilter intentFilter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"); if (com.baidu.techain.i.c.g == null) { com.baidu.techain.i.c.g = new TechainReceiver().a(); } com.baidu.techain.i.c.a(this.context, com.baidu.techain.i.c.g, intentFilter); } if (this.mEndReason == 0) { this.mEndReason = 3; } if (z2) { throw new NetworkErrorException("blocked by Huawei Input"); } throw new NetworkErrorException("no internet"); } sLastCheckTime = System.currentTimeMillis(); if (com.baidu.techain.i.c.g != null && (sMonitorNetworkWhenUpgradeNoNet || com.baidu.techain.i.c.a)) { try { this.context.getApplicationContext().unregisterReceiver(com.baidu.techain.i.c.g); } catch (Throwable unused3) { com.baidu.techain.i.c.a(); } } sMonitorNetworkWhenUpgradeNoNet = false; com.baidu.techain.i.c.a = false; if (this.mFrom != 1) { this.mWholeJson = com.baidu.techain.i.c.o(this.context); } if (this.mWholeJson == null) { if ((this.mFrom == 1 || this.mFrom == 2 || (this.mFrom == 3 && !sSetRetrmAlarm)) && this.mPreferenceManager.p().size() > 0) { sSetRetrmAlarm = true; com.baidu.techain.i.a.a(this.context, sRetryPingTimesCount, false); sRetryPingTimesCount++; } IntentFilter intentFilter2 = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"); if (com.baidu.techain.i.c.g == null) { com.baidu.techain.i.c.g = new TechainReceiver().a(); } else { com.baidu.techain.i.c.g.a(); } com.baidu.techain.i.c.a(this.context, com.baidu.techain.i.c.g, intentFilter2); sMonitorNetworkWhenUpgradeNoNet = true; if (this.mEndReason == 0) { if (com.baidu.techain.i.c.d != 0) { this.mEndReason = com.baidu.techain.i.c.d; } else { this.mEndReason = 4; } } throw new NetworkErrorException("ping faild"); } sRetryPingTimesCount = 0; this.forHostAPP.a(this.mWholeJson); this.loadedPluginDB.d(); com.baidu.techain.h.a aVar = this.mPreferenceManager; aVar.b.putInt("rtqe", this.mPreferenceManager.a.getInt("rtqe", 0) + 1); aVar.b.commit(); List<ApkInfo> a2 = this.loadedPluginDB.a(); ArrayList arrayList8 = new ArrayList(); ArrayList arrayList9 = new ArrayList(); ArrayList arrayList10 = new ArrayList(); final ArrayList arrayList11 = new ArrayList(); JSONObject optJSONObject3 = this.mWholeJson.optJSONObject("5"); if (optJSONObject3 == null) { if (this.mEndReason == 0) { this.mEndReason = 10; } throw new NetworkErrorException("plugin json is null"); } if (optJSONObject3 instanceof JSONObject) { Iterator<String> keys = optJSONObject3.keys(); while (keys.hasNext()) { String next = keys.next(); JSONObject optJSONObject4 = optJSONObject3.optJSONObject(next); int optInt = optJSONObject4.optInt(NotifyType.LIGHTS); String optString = optJSONObject4.optString("v"); if (this.mCloudKeyMap != null) { this.mCloudKeyMap.put(Integer.valueOf(optInt), optString); } String optString2 = optJSONObject4.optString(ak.aG); String optString3 = optJSONObject4.optString("m"); String optString4 = optJSONObject4.optString("sm"); if (optString3 != null) { optString3 = optString3.toLowerCase(); } String str = optInt + optString; if (sRealtimeMd5Map == null) { sRealtimeMd5Map = new HashMap(); } if (TextUtils.isEmpty(str) || TextUtils.isEmpty(optString3)) { jSONObject = optJSONObject3; } else { jSONObject = optJSONObject3; sRealtimeMd5Map.put(str, optString3); } if (optString4 != null) { optString4 = optString4.toLowerCase(); } boolean z3 = optJSONObject4.optInt("o") == 1; boolean z4 = optJSONObject4.optInt("d") == 1; int optInt2 = optJSONObject4.optInt("r"); if (z3) { arrayList3 = arrayList8; com.baidu.techain.h.a aVar2 = this.mPreferenceManager; arrayList2 = arrayList9; arrayList = arrayList11; list = a2; if (optInt2 > aVar2.a.getInt("opi", 0)) { aVar2.b.putInt("opi", optInt2); aVar2.b.commit(); } } else { list = a2; arrayList3 = arrayList8; arrayList2 = arrayList9; arrayList = arrayList11; } if (!z3 || !z4) { try { packageInfo = new PackageInfo(); packageInfo.packageName = optJSONObject4.optString(ak.ax); packageInfo.versionName = optString; ApplicationInfo applicationInfo = new ApplicationInfo(); applicationInfo.className = optJSONObject4.optString("n"); if (!TextUtils.isEmpty(applicationInfo.className) && applicationInfo.className.startsWith(".")) { applicationInfo.className = next + applicationInfo.className; } applicationInfo.theme = optJSONObject4.optInt(ak.aH); packageInfo.applicationInfo = applicationInfo; JSONArray optJSONArray = optJSONObject4.optJSONArray(ak.av); if (optJSONArray == null || optJSONArray.length() <= 0) { arrayList4 = arrayList10; apkInfo = new ApkInfo(optInt, next, optString, optString2, optString3); apkInfo.isOnce = !z3 ? 1 : 0; try { apkInfo.priority = optJSONObject4.getInt(ak.ay); } catch (Throwable unused4) { apkInfo.priority = -1; } apkInfo.isMem = optJSONObject4.optInt("mem") != 1; if (packageInfo != null) { apkInfo.cloudPkgInfo = packageInfo; } optJSONObject = optJSONObject4.optJSONObject(e.a); if (optJSONObject != null) { int optInt3 = optJSONObject.optInt("d"); int optInt4 = optJSONObject.optInt("n"); apkInfo.duration = optInt3; apkInfo.network = optInt4; } optJSONObject2 = optJSONObject4.optJSONObject("ext"); if (optJSONObject2 == null) { z = optJSONObject2.optInt("nl", 0) == 1; if (optJSONObject2.optInt(ak.av) == 1) { List<Integer> p = this.mPreferenceManager.p(); if (optInt > 0 && !p.contains(Integer.valueOf(optInt))) { p.add(Integer.valueOf(optInt)); int[] iArr = new int[p.size()]; for (int i = 0; i < p.size(); i++) { iArr[i] = p.get(i).intValue(); } this.mPreferenceManager.a(iArr); } } } else { z = false; } apkInfo.signMD5 = optString4; apkInfo.startTime = System.currentTimeMillis(); indexOf = list.indexOf(apkInfo); ApkInfo apkInfo2 = new ApkInfo(apkInfo); if (!TextUtils.isEmpty(apkInfo.packageName)) { apkInfo2.packageName = new StringBuilder(apkInfo2.packageName).reverse().toString(); } indexOf2 = list.indexOf(apkInfo2); if (indexOf2 >= 0) { list.remove(indexOf2); } if (indexOf < 0) { ApkInfo apkInfo3 = list.get(indexOf); if (com.baidu.techain.i.c.b(apkInfo.versionName, apkInfo3.versionName)) { if (apkInfo3.priority != apkInfo.priority) { this.loadedPluginDB.c(apkInfo.key, apkInfo.priority); } if (!this.loadedPluginDB.e(apkInfo3.key)) { if (z) { apkInfo.isNextLoad = true; } if (c.d == null || !c.d.contains(Integer.valueOf(apkInfo.key))) { arrayList7 = arrayList; arrayList6 = arrayList2; arrayList6.add(apkInfo); } else { arrayList7 = arrayList; arrayList7.add(apkInfo); arrayList6 = arrayList2; } if (this.mDownloadPluginsList != null) { this.mDownloadPluginsList.add(Integer.valueOf(apkInfo.key)); } } else { arrayList6 = arrayList2; arrayList7 = arrayList; } arrayList5 = arrayList3; } else { arrayList6 = arrayList2; arrayList7 = arrayList; if (apkInfo3.priority != apkInfo.priority) { apkInfo3.priority = apkInfo.priority; this.loadedPluginDB.c(apkInfo.key, apkInfo.priority); } arrayList5 = arrayList3; arrayList5.add(apkInfo3); } list.remove(indexOf); } else { arrayList5 = arrayList3; arrayList6 = arrayList2; arrayList7 = arrayList; arrayList6.add(apkInfo); if (this.mDownloadPluginsList != null) { this.mDownloadPluginsList.add(Integer.valueOf(apkInfo.key)); } } a2 = list; arrayList9 = arrayList6; arrayList8 = arrayList5; optJSONObject3 = jSONObject; keys = keys; arrayList10 = arrayList4; arrayList11 = arrayList7; } else { ArrayList arrayList12 = new ArrayList(); int i2 = 0; while (i2 < optJSONArray.length()) { try { JSONObject jSONObject2 = optJSONArray.getJSONObject(i2); if (jSONObject2 != null) { ActivityInfo activityInfo = new ActivityInfo(); jSONArray = optJSONArray; try { activityInfo.name = jSONObject2.optString("n"); if (!TextUtils.isEmpty(activityInfo.name)) { arrayList4 = arrayList10; if (activityInfo.name.startsWith(".")) { activityInfo.name = next + activityInfo.name; } } else { arrayList4 = arrayList10; } activityInfo.packageName = next; activityInfo.theme = jSONObject2.optInt(ak.aH); activityInfo.labelRes = jSONObject2.optInt(NotifyType.LIGHTS); if (!TextUtils.isEmpty(activityInfo.name)) { arrayList12.add(activityInfo); } } catch (Throwable unused5) { arrayList4 = arrayList10; try { com.baidu.techain.i.c.a(); i2++; optJSONArray = jSONArray; arrayList10 = arrayList4; } catch (Throwable unused6) { com.baidu.techain.i.c.a(); packageInfo = null; apkInfo = new ApkInfo(optInt, next, optString, optString2, optString3); apkInfo.isOnce = !z3 ? 1 : 0; apkInfo.priority = optJSONObject4.getInt(ak.ay); apkInfo.isMem = optJSONObject4.optInt("mem") != 1; if (packageInfo != null) { } optJSONObject = optJSONObject4.optJSONObject(e.a); if (optJSONObject != null) { } optJSONObject2 = optJSONObject4.optJSONObject("ext"); if (optJSONObject2 == null) { } apkInfo.signMD5 = optString4; apkInfo.startTime = System.currentTimeMillis(); indexOf = list.indexOf(apkInfo); ApkInfo apkInfo22 = new ApkInfo(apkInfo); if (!TextUtils.isEmpty(apkInfo.packageName)) { } indexOf2 = list.indexOf(apkInfo22); if (indexOf2 >= 0) { } if (indexOf < 0) { } a2 = list; arrayList9 = arrayList6; arrayList8 = arrayList5; optJSONObject3 = jSONObject; keys = keys; arrayList10 = arrayList4; arrayList11 = arrayList7; } } } else { jSONArray = optJSONArray; arrayList4 = arrayList10; } } catch (Throwable unused7) { jSONArray = optJSONArray; arrayList4 = arrayList10; com.baidu.techain.i.c.a(); i2++; optJSONArray = jSONArray; arrayList10 = arrayList4; } i2++; optJSONArray = jSONArray; arrayList10 = arrayList4; } arrayList4 = arrayList10; if (arrayList12.size() > 0) { packageInfo.activities = (ActivityInfo[]) arrayList12.toArray(new ActivityInfo[arrayList12.size()]); } apkInfo = new ApkInfo(optInt, next, optString, optString2, optString3); apkInfo.isOnce = !z3 ? 1 : 0; apkInfo.priority = optJSONObject4.getInt(ak.ay); apkInfo.isMem = optJSONObject4.optInt("mem") != 1; if (packageInfo != null) { } optJSONObject = optJSONObject4.optJSONObject(e.a); if (optJSONObject != null) { } optJSONObject2 = optJSONObject4.optJSONObject("ext"); if (optJSONObject2 == null) { } apkInfo.signMD5 = optString4; apkInfo.startTime = System.currentTimeMillis(); indexOf = list.indexOf(apkInfo); ApkInfo apkInfo222 = new ApkInfo(apkInfo); if (!TextUtils.isEmpty(apkInfo.packageName)) { } indexOf2 = list.indexOf(apkInfo222); if (indexOf2 >= 0) { } if (indexOf < 0) { } a2 = list; arrayList9 = arrayList6; arrayList8 = arrayList5; optJSONObject3 = jSONObject; keys = keys; arrayList10 = arrayList4; arrayList11 = arrayList7; } } catch (Throwable unused8) { arrayList4 = arrayList10; com.baidu.techain.i.c.a(); packageInfo = null; apkInfo = new ApkInfo(optInt, next, optString, optString2, optString3); apkInfo.isOnce = !z3 ? 1 : 0; apkInfo.priority = optJSONObject4.getInt(ak.ay); apkInfo.isMem = optJSONObject4.optInt("mem") != 1; if (packageInfo != null) { } optJSONObject = optJSONObject4.optJSONObject(e.a); if (optJSONObject != null) { } optJSONObject2 = optJSONObject4.optJSONObject("ext"); if (optJSONObject2 == null) { } apkInfo.signMD5 = optString4; apkInfo.startTime = System.currentTimeMillis(); indexOf = list.indexOf(apkInfo); ApkInfo apkInfo2222 = new ApkInfo(apkInfo); if (!TextUtils.isEmpty(apkInfo.packageName)) { } indexOf2 = list.indexOf(apkInfo2222); if (indexOf2 >= 0) { } if (indexOf < 0) { } a2 = list; arrayList9 = arrayList6; arrayList8 = arrayList5; optJSONObject3 = jSONObject; keys = keys; arrayList10 = arrayList4; arrayList11 = arrayList7; } } else { arrayList10.add(next); optJSONObject3 = jSONObject; keys = keys; arrayList8 = arrayList3; arrayList9 = arrayList2; arrayList11 = arrayList; a2 = list; } } } ArrayList arrayList13 = arrayList10; if (c.d != null) { c.d.clear(); } for (ApkInfo apkInfo4 : a2) { if (!arrayList13.contains(apkInfo4.packageName)) { if (this.mUnloadPluginsList != null) { this.mUnloadPluginsList.add(Integer.valueOf(apkInfo4.key)); } this.forHostAPP.a(apkInfo4.packageName); } arrayList13 = arrayList13; } com.baidu.techain.i.c.c(this.context); f a3 = f.a(this.context.getApplicationContext()); final List<Integer> q = this.mPreferenceManager.q(); List<Integer> p2 = this.mPreferenceManager.p(); for (int i3 = 0; i3 < p2.size(); i3++) { if (!q.contains(p2.get(i3))) { q.add(p2.get(i3)); } } ArrayList arrayList14 = new ArrayList(); arrayList14.addAll(arrayList8); arrayList14.addAll(arrayList9); Collections.sort(arrayList14, new Comparator<ApkInfo>() { /* class com.baidu.techain.ac.U.AnonymousClass1 */ public int compare(ApkInfo apkInfo, ApkInfo apkInfo2) { if (apkInfo.priority == -1 && apkInfo2.priority != -1) { return 1; } if ((apkInfo.priority != -1 && apkInfo2.priority == -1) || apkInfo.priority < apkInfo2.priority) { return -1; } if (apkInfo.priority > apkInfo2.priority) { return 1; } List list = q; int indexOf = (list == null || !list.contains(Integer.valueOf(apkInfo.key))) ? -1 : q.indexOf(Integer.valueOf(apkInfo.key)); List list2 = q; int indexOf2 = (list2 == null || !list2.contains(Integer.valueOf(apkInfo2.key))) ? -1 : q.indexOf(Integer.valueOf(apkInfo2.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 (int i4 = 0; i4 < arrayList14.size(); i4++) { ApkInfo apkInfo5 = (ApkInfo) arrayList14.get(i4); if (arrayList8.contains(apkInfo5)) { if (a3.d(apkInfo5.packageName) == null) { boolean z5 = this.loadedPluginDB.g(apkInfo5.key) != 3; if (!this.mPreferenceManager.b() || !z5) { File file = new File(this.context.getFilesDir(), ".b_techain"); if (file.exists()) { File file2 = new File(file, apkInfo5.key + Constants.ACCEPT_TIME_SEPARATOR_SERVER + apkInfo5.versionName); if (com.baidu.techain.i.c.a(file2)) { com.baidu.techain.c.a(file2); file2.delete(); } } } else { File file3 = new File(this.context.getFilesDir(), ".b_techain"); if (!file3.exists()) { file3.mkdir(); } File file4 = new File(apkInfo5.pkgPath); File file5 = new File(file3, apkInfo5.key + Constants.ACCEPT_TIME_SEPARATOR_SERVER + apkInfo5.versionName); if (!com.baidu.techain.i.c.a(file5)) { com.baidu.techain.i.c.a(file4, file5); } com.baidu.techain.c.a(this.context, apkInfo5.key, file4, file5); } this.forHostAPP.a(apkInfo5.key, apkInfo5.versionName, null); } } else if (arrayList9.contains(apkInfo5) && !this.loadedPluginDB.e(apkInfo5.key)) { handlePluginUpgrade(apkInfo5); } } new Timer().schedule(new TimerTask() { /* class com.baidu.techain.ac.U.AnonymousClass2 */ public void run() { List<ApkInfo> list = arrayList11; if (list != null) { for (ApkInfo apkInfo : list) { U.this.handlePluginUpgrade(apkInfo); } } } }, 120000); } else if (this.mEndReason == 0) { this.mEndReason = 2; handleThreadEnd(null); } } } catch (Throwable unused9) { com.baidu.techain.i.c.a(); return; } if (this.mEndReason == 0) { if (th.getMessage().contains("response is empty")) { this.mEndReason = 7; } else if (th.getMessage().contains("aes is fail")) { this.mEndReason = 8; } else { this.mEndReason = 11; } } handleThreadEnd(b.a(th)); if (this.mOut && sOutGoing) { sOutGoing = false; } sOutGoing = false; } private void handleThreadEnd(String str) { try { this.mPreferenceManager.g(this.mPreferenceManager.s() + 1); if (this.mEndReason != 0) { this.mPreferenceManager.a(1, this.mEndReason, this.mPreferenceManager.a(1, this.mEndReason) + 1); } } catch (Throwable unused) { com.baidu.techain.i.c.a(); } try { HashMap hashMap = new HashMap(); if (this.mStartKeyMap != null) { hashMap.put("1", this.mStartKeyMap.keySet()); hashMap.put(PushConstants.PUSH_TYPE_UPLOAD_LOG, this.mStartKeyMap.values()); } hashMap.put(PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, Integer.valueOf(this.mFrom)); if (this.mCloudKeyMap != null) { hashMap.put(PushConstants.PUSH_TYPE_WITHDRAW_NOTIFICATION, this.mCloudKeyMap.keySet()); hashMap.put("5", this.mCloudKeyMap.values()); } if (this.mUnloadPluginsList != null) { hashMap.put("6", this.mUnloadPluginsList); } if (this.mDownloadPluginsList != null) { hashMap.put("7", this.mDownloadPluginsList); } if (this.mUpgradeResultMap != null) { JSONObject jSONObject = new JSONObject(); for (Map.Entry<Integer, UpgradeResult> entry : this.mUpgradeResultMap.entrySet()) { JSONObject jSONObject2 = new JSONObject(); int intValue = entry.getKey().intValue(); UpgradeResult value = entry.getValue(); if (value != null) { jSONObject2.put("1", value.networkId); jSONObject2.put(PushConstants.PUSH_TYPE_NOTIFY, value.resultId); } jSONObject.put(String.valueOf(intValue), jSONObject2); } hashMap.put("8", jSONObject); } Map<Integer, String> b = this.loadedPluginDB.b(); hashMap.put("9", b.keySet()); hashMap.put("10", b.values()); hashMap.put("11", Integer.valueOf(this.mEndReason)); if (!TextUtils.isEmpty(str)) { hashMap.put("12", str.replace("\n", "").replace("\t", "").replace("\r", "")); } hashMap.put("13", Integer.valueOf(this.mStartNetwork)); hashMap.put("14", Integer.valueOf(com.baidu.techain.i.c.k(this.context))); com.baidu.techain.i.c.a(this.context, "1003129", (Map<String, Object>) hashMap, false); } catch (Throwable unused2) { com.baidu.techain.i.c.a(); } } /* JADX WARNING: Code restructure failed: missing block: B:17:?, code lost: r15.mPreferenceManager.f(0); r15.mPreferenceManager.g(0); r4 = 1; */ /* JADX WARNING: Code restructure failed: missing block: B:18:0x00b5, code lost: if (r4 <= 6) goto L_0x00b7; */ /* JADX WARNING: Code restructure failed: missing block: B:19:0x00b7, code lost: r15.mPreferenceManager.a(0, r4, 0); r4 = r4 + 1; */ /* JADX WARNING: Code restructure failed: missing block: B:20:0x00bf, code lost: r1 = 1; */ /* JADX WARNING: Code restructure failed: missing block: B:21:0x00c0, code lost: if (r1 <= 11) goto L_0x00c2; */ /* JADX WARNING: Code restructure failed: missing block: B:22:0x00c2, code lost: r15.mPreferenceManager.a(1, r1, 0); */ /* JADX WARNING: Code restructure failed: missing block: B:23:0x00c7, code lost: r1 = r1 + 1; */ /* JADX WARNING: Code restructure failed: missing block: B:24:0x00ca, code lost: com.baidu.techain.i.c.a(); */ /* JADX WARNING: Code restructure failed: missing block: B:26:0x00cd, code lost: com.baidu.techain.i.c.a(); */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:16:0x00aa */ /* JADX WARNING: Removed duplicated region for block: B:30:0x00e8 A[Catch:{ all -> 0x0101 }] */ private void handleThreadStart() { long j = this.mPreferenceManager.a.getLong("slruct", 0); long currentTimeMillis = System.currentTimeMillis(); if (j <= 0 || currentTimeMillis - j <= 86400000) { if (j == 0) { this.mPreferenceManager.a(currentTimeMillis); } try { this.mStartKeyMap = this.loadedPluginDB.b(); this.mPreferenceManager.f(this.mPreferenceManager.r() + 1); if (this.mFrom != 0) { this.mPreferenceManager.a(0, this.mFrom, this.mPreferenceManager.a(0, this.mFrom) + 1); } this.mStartNetwork = com.baidu.techain.i.c.k(this.context); } catch (Throwable unused) { com.baidu.techain.i.c.a(); } } else { HashMap hashMap = new HashMap(); hashMap.put("1", Integer.valueOf(this.mPreferenceManager.r())); this.mPreferenceManager.f(0); JSONObject jSONObject = new JSONObject(); for (int i = 1; i <= 6; i++) { jSONObject.put(String.valueOf(i), this.mPreferenceManager.a(0, i)); this.mPreferenceManager.a(0, i, 0); } hashMap.put(PushConstants.PUSH_TYPE_UPLOAD_LOG, jSONObject); hashMap.put(PushConstants.PUSH_FLYME_3_CHANGE_VERSION_START, Integer.valueOf(this.mPreferenceManager.s())); this.mPreferenceManager.g(0); JSONObject jSONObject2 = new JSONObject(); for (int i2 = 1; i2 <= 11; i2++) { jSONObject2.put(String.valueOf(i2), this.mPreferenceManager.a(1, i2)); this.mPreferenceManager.a(1, i2, 0); } hashMap.put(PushConstants.PUSH_TYPE_WITHDRAW_NOTIFICATION, jSONObject2); com.baidu.techain.i.c.a(this.context, "1003128", (Map<String, Object>) hashMap, false); this.mPreferenceManager.a(currentTimeMillis); this.mStartKeyMap = this.loadedPluginDB.b(); this.mPreferenceManager.f(this.mPreferenceManager.r() + 1); if (this.mFrom != 0) { } this.mStartNetwork = com.baidu.techain.i.c.k(this.context); } } private void pluginUpdate(File file, ApkInfo apkInfo, int i) { com.baidu.techain.i.c.a(file.getAbsolutePath(), true); if (this.mPreferenceManager.b()) { File file2 = new File(this.context.getFilesDir(), ".b_techain"); if (!file2.exists()) { file2.mkdir(); } File file3 = new File(file2, apkInfo.key + Constants.ACCEPT_TIME_SEPARATOR_SERVER + apkInfo.versionName); com.baidu.techain.i.c.a(file, file3); com.baidu.techain.c.a(this.context, apkInfo.key, file, file3); } apkInfo.pkgPath = file.getAbsolutePath(); String str = "before update, time=" + System.currentTimeMillis() + ", downloadAPK path:" + file.getAbsolutePath() + ", exists=" + file.exists() + ", canRead=" + file.canRead() + ", isFile=" + file.isFile() + ",length" + file.length(); StringBuilder sb = new StringBuilder("before update, time=" + System.currentTimeMillis() + ", "); ApkInfo a = this.loadedPluginDB.a(apkInfo.key); if (a == null) { sb.append("apkInDB == null"); } else { File file4 = new File(a.pkgPath); sb.append("origAPK path:" + file4.getAbsolutePath() + ", exists=" + file4.exists() + ", canRead=" + file4.canRead() + ", isFile=" + file4.isFile() + ",length" + file4.length()); } boolean a2 = this.forHostAPP.a(apkInfo, str); this.loadedPluginDB.a(apkInfo.key + ExceptionCode.CRASH_EXCEPTION, apkInfo.versionName); if (!a2) { Map<Integer, UpgradeResult> map = this.mUpgradeResultMap; if (map != null && !map.keySet().contains(Integer.valueOf(apkInfo.key))) { this.mUpgradeResultMap.put(Integer.valueOf(apkInfo.key), new UpgradeResult(i, 5)); return; } return; } int g = this.loadedPluginDB.g(apkInfo.key); if (g < 3 && g != -1) { this.loadedPluginDB.b(apkInfo.key, g + 1); } Map<Integer, UpgradeResult> map2 = this.mUpgradeResultMap; if (map2 != null) { map2.put(Integer.valueOf(apkInfo.key), new UpgradeResult(i, 1)); } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private boolean handlePluginDownload(ApkInfo apkInfo, File file, File file2, int i) { boolean z; try { if (file.exists()) { file.delete(); } if ("com.baidu.input_huawei".equals(this.context.getPackageName()) && !this.mPreferenceManager.w()) { return false; } if (q.a(this.context)) { z = new q(this.context).a(apkInfo.downloadURL, file); } else { z = new l(this.context).a(apkInfo.downloadURL, file); } if (z) { if (file2.exists()) { file2.delete(); } new Asc(); if (g.a(file, file2, apkInfo.signMD5.substring(0, apkInfo.signMD5.length() / 2).getBytes("utf-8")) != 0) { if (this.mUpgradeResultMap != null && !this.mUpgradeResultMap.keySet().contains(Integer.valueOf(apkInfo.key))) { this.mUpgradeResultMap.put(Integer.valueOf(apkInfo.key), new UpgradeResult(i, 7)); } z = false; } } else if (this.mUpgradeResultMap != null && !this.mUpgradeResultMap.keySet().contains(Integer.valueOf(apkInfo.key))) { this.mUpgradeResultMap.put(Integer.valueOf(apkInfo.key), new UpgradeResult(i, 4)); } String a = n.a(file2); file.delete(); if (!z || !apkInfo.apkMD5.equals(a)) { return false; } return true; } catch (Throwable unused) { com.baidu.techain.i.c.a(); } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void handlePluginDownError(ApkInfo apkInfo, File file, int i, List<Integer> list) { Map<Integer, UpgradeResult> map = this.mUpgradeResultMap; if (map != null && !map.keySet().contains(Integer.valueOf(apkInfo.key))) { this.mUpgradeResultMap.put(Integer.valueOf(apkInfo.key), new UpgradeResult(i, 8)); } int i2 = this.mFrom; if (i2 == 1 || i2 == 2 || i2 == 3) { if (list != null && list.contains(Integer.valueOf(apkInfo.key)) && !sSetRetrmAlarm) { sSetRetrmAlarm = true; com.baidu.techain.i.a.a(this.context, sRetryDownoadHostCareApksTimesCount, false); sRetryDownoadHostCareApksTimesCount++; } if (!sMonitorNetworkWhenUpgradeNoNet) { IntentFilter intentFilter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"); if (com.baidu.techain.i.c.g == null) { com.baidu.techain.i.c.g = new TechainReceiver().a(); } else { com.baidu.techain.i.c.g.a(); } com.baidu.techain.i.c.a(this.context, com.baidu.techain.i.c.g, intentFilter); sMonitorNetworkWhenUpgradeNoNet = true; } } long currentTimeMillis = System.currentTimeMillis(); com.baidu.techain.h.a aVar = this.mPreferenceManager; long j = aVar.a.getLong("pu_ap_fd", 0); if (j == 0) { j = System.currentTimeMillis(); aVar.c(); } if (currentTimeMillis - j > 86400000) { HashMap hashMap = new HashMap(); if (com.baidu.techain.i.c.e(this.context)) { hashMap.put(PushConstants.PUSH_TYPE_NOTIFY, Integer.valueOf(this.mPreferenceManager.d() + 1)); hashMap.put("1", Integer.valueOf(this.mPreferenceManager.e())); } else { hashMap.put(PushConstants.PUSH_TYPE_NOTIFY, Integer.valueOf(this.mPreferenceManager.d())); hashMap.put("1", Integer.valueOf(this.mPreferenceManager.e() + 1)); } this.mPreferenceManager.a(0); this.mPreferenceManager.b(0); this.mPreferenceManager.c(); com.baidu.techain.i.c.a(this.context, "1003116", (Map<String, Object>) hashMap, false); } else if (com.baidu.techain.i.c.e(this.context)) { com.baidu.techain.h.a aVar2 = this.mPreferenceManager; aVar2.a(aVar2.d() + 1); } else { com.baidu.techain.h.a aVar3 = this.mPreferenceManager; aVar3.b(aVar3.e() + 1); } file.delete(); } /* access modifiers changed from: private */ /* access modifiers changed from: public */ /* JADX WARNING: Removed duplicated region for block: B:107:? A[RETURN, SYNTHETIC] */ /* JADX WARNING: Removed duplicated region for block: B:21:0x00c8 A[Catch:{ all -> 0x01cc, all -> 0x01fd, all -> 0x025f }] */ /* JADX WARNING: Removed duplicated region for block: B:31:0x0110 A[Catch:{ all -> 0x01cc, all -> 0x01fd, all -> 0x025f }] */ /* JADX WARNING: Removed duplicated region for block: B:34:0x0114 A[Catch:{ all -> 0x01cc, all -> 0x01fd, all -> 0x025f }] */ /* JADX WARNING: Removed duplicated region for block: B:35:0x0119 A[Catch:{ all -> 0x01cc, all -> 0x01fd, all -> 0x025f }] */ /* JADX WARNING: Removed duplicated region for block: B:51:0x0159 A[Catch:{ all -> 0x01cc, all -> 0x01fd, all -> 0x025f }] */ /* JADX WARNING: Removed duplicated region for block: B:52:0x0161 A[Catch:{ all -> 0x01cc, all -> 0x01fd, all -> 0x025f }] */ /* JADX WARNING: Removed duplicated region for block: B:59:0x0178 A[Catch:{ all -> 0x01cc, all -> 0x01fd, all -> 0x025f }] */ /* JADX WARNING: Removed duplicated region for block: B:63:0x019b A[Catch:{ all -> 0x01cc, all -> 0x01fd, all -> 0x025f }] */ /* JADX WARNING: Removed duplicated region for block: B:70:0x01c8 A[Catch:{ all -> 0x01cc, all -> 0x01fd, all -> 0x025f }] */ private void handlePluginUpgrade(final ApkInfo apkInfo) { boolean z; boolean z2; File file; boolean z3; boolean z4; boolean z5; File file2; try { final int k = com.baidu.techain.i.c.k(this.context); final List<Integer> p = this.mPreferenceManager.p(); if (p.contains(Integer.valueOf(apkInfo.key)) || com.baidu.techain.i.c.a(this.context, apkInfo.network)) { if (!this.tmpDir.exists()) { this.tmpDir.mkdir(); } ApkInfo a = this.loadedPluginDB.a(apkInfo.key + ExceptionCode.CRASH_EXCEPTION); final File file3 = new File(this.tmpDir, apkInfo.key + Constants.ACCEPT_TIME_SEPARATOR_SERVER + apkInfo.versionName + ".tmp"); final File file4 = new File(this.tmpDir, apkInfo.key + Constants.ACCEPT_TIME_SEPARATOR_SERVER + apkInfo.versionName + ".zip"); if (file4.exists()) { if (apkInfo.apkMD5.equals(n.a(file4))) { z2 = false; z = true; if (z2) { file = file4; } else if (apkInfo.isNextLoad) { file = file4; v.a(this.context).a(new Runnable() { /* class com.baidu.techain.ac.U.AnonymousClass3 */ public void run() { try { if (!U.this.handlePluginDownload(apkInfo, file3, file4, k)) { U.this.handlePluginDownError(apkInfo, file4, k, p); return; } apkInfo.pkgPath = file4.getAbsolutePath(); ApkInfo apkInfo = new ApkInfo(apkInfo); apkInfo.key += ExceptionCode.CRASH_EXCEPTION; if (!TextUtils.isEmpty(apkInfo.packageName)) { apkInfo.packageName = new StringBuilder(apkInfo.packageName).reverse().toString(); } U.this.loadedPluginDB.a(apkInfo); } catch (Throwable unused) { com.baidu.techain.i.c.a(); } } }); } else { file = file4; z = handlePluginDownload(apkInfo, file3, file, k); z3 = !z; if (a != null) { this.loadedPluginDB.h(a.key + ExceptionCode.CRASH_EXCEPTION); if (!TextUtils.isEmpty(a.pkgPath)) { File file5 = new File(a.pkgPath); if (file5.exists()) { file5.delete(); } } } if (z) { pluginUpdate(file, apkInfo, k); } else { if (a != null) { ApkInfo a2 = this.loadedPluginDB.a(apkInfo.key); if (a2 != null) { if (!com.baidu.techain.i.c.b(a.versionName, a2.versionName)) { z5 = false; if (!TextUtils.isEmpty(a.versionName) && a.versionName.equals(apkInfo.versionName)) { this.loadedPluginDB.a(a.key + ExceptionCode.CRASH_EXCEPTION, a.versionName); z5 = false; } file2 = TextUtils.isEmpty(a.pkgPath) ? new File(a.pkgPath) : null; if (file2 != null && file2.exists() && z5) { if (!a.apkMD5.equals(n.a(file2))) { a.key -= ExceptionCode.CRASH_EXCEPTION; if (!TextUtils.isEmpty(a.packageName)) { a.packageName = new StringBuilder(a.packageName).reverse().toString(); } pluginUpdate(file2, a, k); z4 = true; if (!z4 && f.a(this.context.getApplicationContext()).d(apkInfo.packageName) == null) { this.forHostAPP.a(apkInfo.key, apkInfo.versionName, null); } } else { this.loadedPluginDB.a(a.key + ExceptionCode.CRASH_EXCEPTION, a.versionName); file2.delete(); } } } } z5 = true; this.loadedPluginDB.a(a.key + ExceptionCode.CRASH_EXCEPTION, a.versionName); z5 = false; if (TextUtils.isEmpty(a.pkgPath)) { } if (!a.apkMD5.equals(n.a(file2))) { } } z4 = false; this.forHostAPP.a(apkInfo.key, apkInfo.versionName, null); } if (z3) { handlePluginDownError(apkInfo, file, k, p); return; } return; } z3 = false; if (z) { } if (z3) { } } } z2 = true; z = false; if (z2) { } z3 = false; if (z) { } if (z3) { } } else if (this.mUpgradeResultMap != null && !this.mUpgradeResultMap.keySet().contains(Integer.valueOf(apkInfo.key))) { this.mUpgradeResultMap.put(Integer.valueOf(apkInfo.key), new UpgradeResult(k, 3)); return; } else { return; } } catch (Throwable unused) { com.baidu.techain.i.c.a(); return; } List<Integer> p2 = this.mPreferenceManager.p(); if (this.mFrom == 1 || this.mFrom == 2 || this.mFrom == 3) { if (p2.contains(Integer.valueOf(apkInfo.key)) && !sSetRetrmAlarm) { sSetRetrmAlarm = true; com.baidu.techain.i.a.a(this.context, sRetryDownoadHostCareApksTimesCount, false); sRetryDownoadHostCareApksTimesCount++; } if (!sMonitorNetworkWhenUpgradeNoNet) { IntentFilter intentFilter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"); if (com.baidu.techain.i.c.g == null) { com.baidu.techain.i.c.g = new TechainReceiver().a(); } else { com.baidu.techain.i.c.g.a(); } com.baidu.techain.i.c.a(this.context, com.baidu.techain.i.c.g, intentFilter); sMonitorNetworkWhenUpgradeNoNet = true; } } } }