public void onPatchServiceStart(Intent intent) { if (!isRetryEnable) { TinkerLog.w(TAG, "onPatchServiceStart retry disabled, just return"); return; } if (intent == null) { TinkerLog.e(TAG, "onPatchServiceStart intent is null, just return"); return; } boolean isUpgrade = TinkerPatchService.getPatchUpgradeExtra(intent); if (!isUpgrade) { TinkerLog.w(TAG, "onPatchServiceStart is not upgrade patch, just return"); return; } String path = TinkerPatchService.getPatchPathExtra(intent); if (path == null) { TinkerLog.w(TAG, "onPatchServiceStart patch path is null, just return"); return; } RetryInfo retryInfo; File patchFile = new File(path); String patchMd5 = SharePatchFileUtil.getMD5(patchFile); if (patchMd5 == null) { TinkerLog.w(TAG, "onPatchServiceStart patch md5 is null, just return"); return; } if (retryInfoFile.exists()) { retryInfo = RetryInfo.readRetryProperty(retryInfoFile); if (retryInfo.md5 == null || retryInfo.times == null || !patchMd5.equals(retryInfo.md5)) { copyToTempFile(patchFile); retryInfo.md5 = patchMd5; retryInfo.times = "1"; } else { int nowTimes = Integer.parseInt(retryInfo.times); if (nowTimes >= RETRY_MAX_COUNT) { SharePatchFileUtil.safeDeleteFile(retryInfoFile); SharePatchFileUtil.safeDeleteFile(tempPatchFile); TinkerLog.w( TAG, "onPatchServiceStart retry more than max count, delete retry info file!"); return; } else { retryInfo.times = String.valueOf(nowTimes + 1); } } } else { copyToTempFile(patchFile); retryInfo = new RetryInfo(patchMd5, "1"); } RetryInfo.writeRetryProperty(retryInfoFile, retryInfo); }
/** * if we receive any result, we can delete the temp retry info file * * @param isUpgradePatch */ public void onPatchServiceResult(boolean isUpgradePatch) { if (!isRetryEnable) { TinkerLog.w(TAG, "onPatchServiceResult retry disabled, just return"); return; } if (!isUpgradePatch) { TinkerLog.w(TAG, "onPatchServiceResult is not upgrade patch, just return"); return; } // delete info file if (retryInfoFile.exists()) { SharePatchFileUtil.safeDeleteFile(retryInfoFile); } // delete temp patch file if (tempPatchFile.exists()) { SharePatchFileUtil.safeDeleteFile(tempPatchFile); } }