package com.jddj.weaver.lib.reporter; import android.content.Context; import com.jddj.weaver.lib.util.UpgradePatchRetry; import com.jddj.weaver.lib.util.WeaverLog; import com.jddj.weaver.lib.weaver.Weaver; import com.jddj.weaver.lib.weaver.WeaverInstaller; import com.jddj.weaver.lib.weaver.WeaverLoadResult; import com.jddj.weaver.loader.shareutil.ShareConstants; import com.jddj.weaver.loader.shareutil.SharePatchFileUtil; import com.jddj.weaver.loader.shareutil.SharePatchInfo; import com.jddj.weaver.loader.shareutil.ShareWeaverInternals; import java.io.File; public class DefaultLoadReporter implements LoadReporter { private static final String TAG = "Weaver.DefaultLoadReporter"; protected final Context context; public DefaultLoadReporter(Context context2) { this.context = context2; } @Override // com.jddj.weaver.lib.reporter.LoadReporter public void onLoadPatchListenerReceiveFail(File file, int i) { WeaverLog.i(TAG, "patch loadReporter onLoadPatchListenerReceiveFail: patch receive fail: %s, code: %d", file.getAbsolutePath(), Integer.valueOf(i)); } @Override // com.jddj.weaver.lib.reporter.LoadReporter public void onLoadPatchVersionChanged(String str, String str2, File file, String str3) { WeaverLog.i(TAG, "patch loadReporter onLoadPatchVersionChanged: patch version change from " + str + " to " + str2, new Object[0]); if (!(str == null || str2 == null || str.equals(str2) || !Weaver.with(this.context).isMainProcess())) { UpgradePatchRetry.getInstance(this.context).onPatchResetMaxCheck(str2); File[] listFiles = file.listFiles(); if (listFiles != null) { for (File file2 : listFiles) { String name = file2.getName(); if (file2.isDirectory() && !name.equals(str3)) { SharePatchFileUtil.deleteDir(file2); } } } } } @Override // com.jddj.weaver.lib.reporter.LoadReporter public void onLoadInterpret(int i, Throwable th) { WeaverLog.i(TAG, "patch loadReporter onLoadInterpret: type: %d, throwable: %s", Integer.valueOf(i), th); switch (i) { case 0: WeaverLog.i(TAG, "patch loadReporter onLoadInterpret ok", new Object[0]); break; case 1: WeaverLog.e(TAG, "patch loadReporter onLoadInterpret fail, can get instruction set from existed oat file", new Object[0]); break; case 2: WeaverLog.e(TAG, "patch loadReporter onLoadInterpret fail, command line to interpret return error", new Object[0]); break; } retryPatch(); } @Override // com.jddj.weaver.lib.reporter.LoadReporter public void onLoadFileNotFound(File file, int i, boolean z) { WeaverLog.i(TAG, "patch loadReporter onLoadFileNotFound: patch file not found: %s, fileType: %d, isDirectory: %b", file.getAbsolutePath(), Integer.valueOf(i), Boolean.valueOf(z)); if (i == 4) { retryPatch(); } else { checkAndCleanPatch(); } } @Override // com.jddj.weaver.lib.reporter.LoadReporter public void onLoadFileMd5Mismatch(File file, int i) { WeaverLog.i(TAG, "patch load Reporter onLoadFileMd5Mismatch: patch file md5 mismatch file: %s, fileType: %d", file.getAbsolutePath(), Integer.valueOf(i)); checkAndCleanPatch(); } @Override // com.jddj.weaver.lib.reporter.LoadReporter public void onLoadPatchInfoCorrupted(String str, String str2, File file) { WeaverLog.i(TAG, "patch loadReporter onLoadPatchInfoCorrupted: patch info file damage: %s, from version: %s to version: %s", file.getAbsolutePath(), str, str2); checkAndCleanPatch(); } @Override // com.jddj.weaver.lib.reporter.LoadReporter public void onLoadResult(File file, int i, long j) { WeaverLog.i(TAG, "patch loadReporter onLoadResult: patch load result, path:%s, code: %d, cost: %dms", file.getAbsolutePath(), Integer.valueOf(i), Long.valueOf(j)); } @Override // com.jddj.weaver.lib.reporter.LoadReporter public void onLoadException(Throwable th, int i) { switch (i) { case -4: WeaverLog.i(TAG, "patch loadReporter onLoadException: patch load unCatch exception: %s", th); ShareWeaverInternals.setWeaverDisableWithSharedPreferences(this.context); WeaverLog.i(TAG, "unCaught exception disable weaver forever with sp", new Object[0]); String checkWeaverLastUncaughtCrash = SharePatchFileUtil.checkWeaverLastUncaughtCrash(this.context); if (!ShareWeaverInternals.isNullOrNil(checkWeaverLastUncaughtCrash)) { SharePatchFileUtil.safeDeleteFile(SharePatchFileUtil.getPatchLastCrashFile(this.context)); WeaverLog.e(TAG, "weaver uncaught real exception:" + checkWeaverLastUncaughtCrash, new Object[0]); break; } break; case -3: if (th.getMessage().contains(ShareConstants.CHECK_RES_INSTALL_FAIL)) { WeaverLog.e(TAG, "patch loadReporter onLoadException: weaver res check fail:" + th.getMessage(), new Object[0]); } else { WeaverLog.i(TAG, "patch loadReporter onLoadException: patch load resource exception: %s", th); } ShareWeaverInternals.setWeaverDisableWithSharedPreferences(this.context); WeaverLog.i(TAG, "res exception disable weaver forever with sp", new Object[0]); break; case -2: if (th.getMessage().contains(ShareConstants.CHECK_DEX_INSTALL_FAIL)) { WeaverLog.e(TAG, "patch loadReporter onLoadException: weaver dex check fail:" + th.getMessage(), new Object[0]); } else { WeaverLog.i(TAG, "patch loadReporter onLoadException: patch load dex exception: %s", th); } ShareWeaverInternals.setWeaverDisableWithSharedPreferences(this.context); WeaverLog.i(TAG, "dex exception disable weaver forever with sp", new Object[0]); break; case -1: WeaverLog.i(TAG, "patch loadReporter onLoadException: patch load unknown exception: %s", th); break; } WeaverLog.e(TAG, "weaver load exception, welcome to submit issue to us: https://github.com/Tencent/weaver/issues", new Object[0]); WeaverLog.printErrStackTrace(TAG, th, "weaver load exception", new Object[0]); Weaver.with(this.context).setWeaverDisable(); checkAndCleanPatch(); } @Override // com.jddj.weaver.lib.reporter.LoadReporter public void onLoadPackageCheckFail(File file, int i) { WeaverLog.i(TAG, "patch loadReporter onLoadPackageCheckFail: load patch package check fail file path: %s, errorCode: %d", file.getAbsolutePath(), Integer.valueOf(i)); checkAndCleanPatch(); } public void checkAndCleanPatch() { SharePatchInfo sharePatchInfo; Weaver with = Weaver.with(this.context); if (with.isMainProcess()) { WeaverLoadResult weaverLoadResultIfPresent = with.getWeaverLoadResultIfPresent(); if (weaverLoadResultIfPresent.versionChanged && (sharePatchInfo = weaverLoadResultIfPresent.patchInfo) != null && !ShareWeaverInternals.isNullOrNil(sharePatchInfo.oldVersion)) { WeaverLog.w(TAG, "checkAndCleanPatch, oldVersion %s is not null, try kill all other process", sharePatchInfo.oldVersion); ShareWeaverInternals.killAllOtherProcess(this.context); } } with.cleanPatch(); } public boolean retryPatch() { File file; Weaver with = Weaver.with(this.context); if (!with.isMainProcess() || (file = with.getWeaverLoadResultIfPresent().patchVersionFile) == null || !UpgradePatchRetry.getInstance(this.context).onPatchListenerCheck(SharePatchFileUtil.getMD5(file))) { return false; } WeaverLog.i(TAG, "try to repair oat file on patch process", new Object[0]); WeaverInstaller.onReceiveUpgradePatch(this.context, file.getAbsolutePath()); return true; } }