当前位置: 首页>>代码示例>>Java>>正文


Java SharePatchFileUtil.getMD5方法代码示例

本文整理汇总了Java中com.tencent.tinker.loader.shareutil.SharePatchFileUtil.getMD5方法的典型用法代码示例。如果您正苦于以下问题:Java SharePatchFileUtil.getMD5方法的具体用法?Java SharePatchFileUtil.getMD5怎么用?Java SharePatchFileUtil.getMD5使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.tencent.tinker.loader.shareutil.SharePatchFileUtil的用法示例。


在下文中一共展示了SharePatchFileUtil.getMD5方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: tryPatchFile

import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
private void tryPatchFile(File patchFile, Integer newVersion) {
    TinkerServerClient client = TinkerServerClient.get();
    Context context = client.getContext();
    //In order to calculate the user number, just report success here
    String patchMd5 = SharePatchFileUtil.getMD5(patchFile);
    //update version
    client.updateTinkerVersion(newVersion, patchMd5);
    //delete old patch sever file
    File serverDir = ServerUtils.getServerDirectory(context);
    if (serverDir != null) {
        File[] files = serverDir.listFiles();
        if (files != null) {
            String currentName = patchFile.getName();
            for (File file : files) {
                String fileName = file.getName();
                if (fileName.equals(currentName) || fileName.equals(ServerUtils.TINKER_VERSION_FILE)) {
                    continue;
                }
                SharePatchFileUtil.safeDeleteFile(file);
            }
        }
        client.reportPatchApplySuccess(newVersion);
        //try install
        TinkerInstaller.onReceiveUpgradePatch(context, patchFile.getAbsolutePath());
    }
}
 
开发者ID:TinkerPatch,项目名称:tinkerpatch-sdk,代码行数:27,代码来源:DefaultPatchRequestCallback.java

示例2: patchCheck

import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
/**
 * because we use the defaultCheckPatchReceived method
 * the error code define by myself should after {@code ShareConstants.ERROR_RECOVER_INSERVICE
 *
 * @param path
 * @param newPatch
 * @return
 */
@Override
public int patchCheck(String path) {
    File patchFile = new File(path);
    TinkerLog.i(TAG, "receive a patch file: %s, file size:%d",
        path, SharePatchFileUtil.getFileOrDirectorySize(patchFile)
    );
    int returnCode = super.patchCheck(path);

    //把这个添加到你的PatchListener实现中
    String patchMd5 = SharePatchFileUtil.getMD5(patchFile);
    TinkerServerManager.reportTinkerPatchListenerFail(returnCode, patchMd5);
    return returnCode;
}
 
开发者ID:TinkerPatch,项目名称:tinkerpatch-sdk,代码行数:22,代码来源:TinkerServerPatchListener.java

示例3: reportTinkerPatchFail

import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
/**
 * 上报补丁合成情况
 * @param patchResult
 */
public static void reportTinkerPatchFail(PatchResult patchResult) {
    if (sTinkerServerClient == null) {
        TinkerLog.e(TAG, "reportTinkerPatchFail, sTinkerServerClient == null");
        return;
    }
    if (patchResult == null) {
        TinkerLog.e(TAG, "reportTinkerPatchFail, patchResult == null");
        return;
    }

    if (patchResult.isSuccess) {
        TinkerLog.i(TAG, "reportTinkerPatchFail, patch success, just return");
        return;
    }
    String patchMd5 = (patchResult.patchVersion != null)
        ? patchResult.patchVersion : SharePatchFileUtil.getMD5(new File(patchResult.rawPatchFilePath));

    if (!patchMd5.equals(sTinkerServerClient.getCurrentPatchMd5())) {
        TinkerLog.e(TAG, "reportTinkerPatchFail, md5 not equal, patchMd5:%s, currentPatchMd5:%s",
            patchMd5, sTinkerServerClient.getCurrentPatchMd5()
        );
        return;
    }
    sTinkerServerClient.reportPatchFail(
        sTinkerServerClient.getCurrentPatchVersion(),
        DefaultPatchRequestCallback.ERROR_PATCH_FAIL
    );
}
 
开发者ID:TinkerPatch,项目名称:tinkerpatch-sdk,代码行数:33,代码来源:TinkerServerManager.java

示例4: patchCheck

import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
/**
 * because we use the defaultCheckPatchReceived method
 * the error code define by myself should after {@code ShareConstants.ERROR_RECOVER_INSERVICE
 *
 * @param path
 * @param newPatch
 * @return
 */
@Override
public int patchCheck(String path) {
    File patchFile = new File(path);
    TinkerLog.i(TAG, "receive a patch file: %s, file size:%d", path, SharePatchFileUtil.getFileOrDirectorySize(patchFile));
    int returnCode = super.patchCheck(path);

    if (returnCode == ShareConstants.ERROR_PATCH_OK) {
        returnCode = Utils.checkForPatchRecover(NEW_PATCH_RESTRICTION_SPACE_SIZE_MIN, maxMemory);
    }

    if (returnCode == ShareConstants.ERROR_PATCH_OK) {
        String patchMd5 = SharePatchFileUtil.getMD5(patchFile);
        SharedPreferences sp = context.getSharedPreferences(ShareConstants.TINKER_SHARE_PREFERENCE_CONFIG, Context.MODE_MULTI_PROCESS);
        //optional, only disable this patch file with md5
        int fastCrashCount = sp.getInt(patchMd5, 0);
        if (fastCrashCount >= SampleUncaughtExceptionHandler.MAX_CRASH_COUNT) {
            returnCode = Utils.ERROR_PATCH_CRASH_LIMIT;
        } else {
            //for upgrade patch, version must be not the same
            //for repair patch, we won't has the tinker load flag
            Tinker tinker = Tinker.with(context);

            if (tinker.isTinkerLoaded()) {
                TinkerLoadResult tinkerLoadResult = tinker.getTinkerLoadResultIfPresent();
                if (tinkerLoadResult != null) {
                    String currentVersion = tinkerLoadResult.currentVersion;
                    if (patchMd5.equals(currentVersion)) {
                        returnCode = Utils.ERROR_PATCH_ALREADY_APPLY;
                    }
                }
            }
        }
        //check whether retry so many times
        if (returnCode == ShareConstants.ERROR_PATCH_OK) {
            returnCode = UpgradePatchRetry.getInstance(context).onPatchListenerCheck(patchMd5)
                ? ShareConstants.ERROR_PATCH_OK : Utils.ERROR_PATCH_RETRY_COUNT_LIMIT;
        }
    }
    // Warning, it is just a sample case, you don't need to copy all of these
    // Interception some of the request
    if (returnCode == ShareConstants.ERROR_PATCH_OK) {
        Properties properties = ShareTinkerInternals.fastGetPatchPackageMeta(patchFile);
        if (properties == null) {
            returnCode = Utils.ERROR_PATCH_CONDITION_NOT_SATISFIED;
        } else {
            String platform = properties.getProperty(Utils.PLATFORM);
            TinkerLog.i(TAG, "get platform:" + platform);
            // check patch platform require
            if (platform == null) {
                returnCode = Utils.ERROR_PATCH_CONDITION_NOT_SATISFIED;
            }
        }
    }

    SampleTinkerReport.onTryApply(returnCode == ShareConstants.ERROR_PATCH_OK);
    return returnCode;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:66,代码来源:SamplePatchListener.java

示例5: onPatchServiceStart

import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
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;
    }

    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(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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:52,代码来源:UpgradePatchRetry.java

示例6: onPatchServiceStart

import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
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;
    }

    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 >= maxRetryCount) {
                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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:52,代码来源:UpgradePatchRetry.java

示例7: patchCheck

import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
/**
     * because we use the defaultCheckPatchReceived method
     * the error code define by myself should after {@code ShareConstants.ERROR_RECOVER_INSERVICE
     *
     * @param path
     * @param newPatch
     * @return
     */
    @Override
    public int patchCheck(String path) {
        File patchFile = new File(path);
        TinkerLog.i(TAG, "receive a patch file: %s, file size:%d", path, SharePatchFileUtil.getFileOrDirectorySize(patchFile));
        int returnCode = super.patchCheck(path);

        if (returnCode == ShareConstants.ERROR_PATCH_OK) {
            returnCode = Utils.checkForPatchRecover(NEW_PATCH_RESTRICTION_SPACE_SIZE_MIN, maxMemory);
        }

        if (returnCode == ShareConstants.ERROR_PATCH_OK) {
            String patchMd5 = SharePatchFileUtil.getMD5(patchFile);
            SharedPreferences sp = context.getSharedPreferences(ShareConstants.TINKER_SHARE_PREFERENCE_CONFIG, Context.MODE_MULTI_PROCESS);
            //optional, only disable this patch file with md5
            int fastCrashCount = sp.getInt(patchMd5, 0);
            if (fastCrashCount >= SampleUncaughtExceptionHandler.MAX_CRASH_COUNT) {
                returnCode = Utils.ERROR_PATCH_CRASH_LIMIT;
            } else {
                //for upgrade patch, version must be not the same
                //for repair patch, we won't has the tinker load flag
                Tinker tinker = Tinker.with(context);

                if (tinker.isTinkerLoaded()) {
                    TinkerLoadResult tinkerLoadResult = tinker.getTinkerLoadResultIfPresent();
                    if (tinkerLoadResult != null && !tinkerLoadResult.useInterpretMode) {
                        String currentVersion = tinkerLoadResult.currentVersion;
                        if (patchMd5.equals(currentVersion)) {
                            returnCode = Utils.ERROR_PATCH_ALREADY_APPLY;
                        }
                    }
                }
            }
            //check whether retry so many times
            if (returnCode == ShareConstants.ERROR_PATCH_OK) {
                returnCode = UpgradePatchRetry.getInstance(context).onPatchListenerCheck(patchMd5)
                    ? ShareConstants.ERROR_PATCH_OK : Utils.ERROR_PATCH_RETRY_COUNT_LIMIT;
            }
        }
        // Warning, it is just a sample case, you don't need to copy all of these
        // Interception some of the request
        if (returnCode == ShareConstants.ERROR_PATCH_OK) {
            Properties properties = ShareTinkerInternals.fastGetPatchPackageMeta(patchFile);
            if (properties == null) {
                returnCode = Utils.ERROR_PATCH_CONDITION_NOT_SATISFIED;
            } else {
                String platform = properties.getProperty(Utils.PLATFORM);
                TinkerLog.i(TAG, "get platform:" + platform);
//                // check patch platform require
//                if (platform == null || !platform.equals(BuildInfo.PLATFORM)) {
//                    returnCode = Utils.ERROR_PATCH_CONDITION_NOT_SATISFIED;
//                }
            }
        }

        SampleTinkerReport.onTryApply(returnCode == ShareConstants.ERROR_PATCH_OK);
        return returnCode;
    }
 
开发者ID:xingstarx,项目名称:TinkerDemo,代码行数:66,代码来源:SamplePatchListener.java

示例8: tryPatch

import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
public boolean tryPatch(Context context, String tempPatchPath, PatchResult patchResult) {
    Tinker manager = Tinker.with(context);
    File patchFile = new File(tempPatchPath);
    if (!manager.isTinkerEnabled() || !ShareTinkerInternals
            .isTinkerEnableWithSharedPreferences(context)) {
        TinkerLog.e(TAG, "RepairPatch tryPatch:patch is disabled, just return", new Object[0]);
        return false;
    } else if (patchFile.isFile() && patchFile.exists()) {
        ShareSecurityCheck signatureCheck = new ShareSecurityCheck(context);
        int returnCode = ShareTinkerInternals.checkSignatureAndTinkerID(context, patchFile,
                signatureCheck);
        if (returnCode != 0) {
            TinkerLog.e(TAG, "RepairPatch tryPatch:onPatchPackageCheckFail", new Object[0]);
            manager.getPatchReporter().onPatchPackageCheckFail(patchFile, false, returnCode);
            return false;
        }
        patchResult.patchTinkerID = signatureCheck.getNewTinkerID();
        patchResult.baseTinkerID = signatureCheck.getTinkerID();
        SharePatchInfo oldInfo = manager.getTinkerLoadResultIfPresent().patchInfo;
        String patchMd5 = SharePatchFileUtil.getMD5(patchFile);
        patchResult.patchVersion = patchMd5;
        if (oldInfo == null) {
            TinkerLog.e(TAG, "OldPatchProcessor tryPatch:onPatchVersionCheckFail, oldInfo is " +
                    "null", new Object[0]);
            manager.getPatchReporter().onPatchVersionCheckFail(patchFile, oldInfo, patchMd5,
                    false);
            return false;
        } else if (oldInfo.oldVersion == null || oldInfo.newVersion == null) {
            TinkerLog.e(TAG, "RepairPatch tryPatch:onPatchInfoCorrupted", new Object[0]);
            manager.getPatchReporter().onPatchInfoCorrupted(patchFile, oldInfo.oldVersion,
                    oldInfo.newVersion, false);
            return false;
        } else if (oldInfo.oldVersion.equals(patchMd5) && oldInfo.newVersion.equals(patchMd5)) {
            String patchDirectory = manager.getPatchDirectory().getAbsolutePath();
            String patchVersionDirectory = patchDirectory + "/" + SharePatchFileUtil
                    .getPatchVersionDirectory(patchMd5);
            if (!DexDiffPatchInternal.tryRecoverDexFiles(manager, signatureCheck, context,
                    patchVersionDirectory, patchFile, false)) {
                TinkerLog.e(TAG, "RepairPatch tryPatch:try patch dex failed", new Object[0]);
                return false;
            } else if (!BsDiffPatchInternal.tryRecoverLibraryFiles(manager, signatureCheck,
                    context, patchVersionDirectory, patchFile, false)) {
                TinkerLog.e(TAG, "RepairPatch tryPatch:try patch library failed", new
                        Object[0]);
                return false;
            } else if (ResDiffPatchInternal.tryRecoverResourceFiles(manager, signatureCheck,
                    context, patchVersionDirectory, patchFile, false)) {
                return true;
            } else {
                TinkerLog.e(TAG, "RepairPatch tryPatch:try patch resource failed", new
                        Object[0]);
                return false;
            }
        } else {
            TinkerLog.e(TAG, "RepairPatch tryPatch:onPatchVersionCheckFail", new Object[0]);
            manager.getPatchReporter().onPatchVersionCheckFail(patchFile, oldInfo, patchMd5,
                    false);
            return false;
        }
    } else {
        TinkerLog.e(TAG, "RepairPatch tryPatch:patch file is not found, just return", new
                Object[0]);
        return false;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:66,代码来源:RepairPatch.java

示例9: patchCheck

import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
public int patchCheck(String path, boolean isUpgrade) {
    File patchFile = new File(path);
    TinkerLog.i(TAG, "receive a patch file: %s, isUpgrade:%b, file size:%d", path, Boolean
            .valueOf(isUpgrade), Long.valueOf(SharePatchFileUtil.getFileOrDirectorySize
            (patchFile)));
    int returnCode = super.patchCheck(path, isUpgrade);
    if (returnCode == 0) {
        if (isUpgrade) {
            returnCode = Utils.checkForPatchRecover(NEW_PATCH_RESTRICTION_SPACE_SIZE_MIN,
                    this.maxMemory);
        } else {
            returnCode = Utils.checkForPatchRecover(OLD_PATCH_RESTRICTION_SPACE_SIZE_MIN,
                    this.maxMemory);
        }
    }
    if (returnCode == 0) {
        String patchMd5 = SharePatchFileUtil.getMD5(patchFile);
        if (this.context.getSharedPreferences(ShareConstants.TINKER_SHARE_PREFERENCE_CONFIG,
                4).getInt(patchMd5, 0) >= 3) {
            returnCode = -9;
        } else {
            Tinker tinker = Tinker.with(this.context);
            if (tinker.isTinkerLoaded()) {
                TinkerLoadResult tinkerLoadResult = tinker.getTinkerLoadResultIfPresent();
                if (tinkerLoadResult != null && patchMd5.equals(tinkerLoadResult
                        .currentVersion)) {
                    returnCode = -8;
                }
            }
        }
    }
    if (returnCode == 0) {
        Properties properties = ShareTinkerInternals.fastGetPatchPackageMeta(patchFile);
        if (properties == null) {
            returnCode = -10;
        } else {
            String platform = properties.getProperty("platform");
            TinkerLog.i(TAG, "get platform:" + platform, new Object[0]);
            if (platform == null || !platform.equals(BuildInfo.PLATFORM)) {
                returnCode = -10;
            }
        }
    }
    SampleTinkerReport.onTryApply(isUpgrade, returnCode == 0);
    return returnCode;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:47,代码来源:SamplePatchListener.java

示例10: onPatchServiceStart

import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
public void onPatchServiceStart(Intent intent) {
    if (!this.isRetryEnable) {
        TinkerLog.w(TAG, "onPatchServiceStart retry disabled, just return", new Object[0]);
    } else if (intent == null) {
        TinkerLog.e(TAG, "onPatchServiceStart intent is null, just return", new Object[0]);
    } else if (TinkerPatchService.getPatchUpgradeExtra(intent)) {
        String path = TinkerPatchService.getPatchPathExtra(intent);
        if (path == null) {
            TinkerLog.w(TAG, "onPatchServiceStart patch path is null, just return", new
                    Object[0]);
            return;
        }
        RetryInfo retryInfo;
        File patchFile = new File(path);
        String patchMd5 = SharePatchFileUtil.getMD5(patchFile);
        if (this.retryInfoFile.exists()) {
            retryInfo = RetryInfo.readRetryProperty(this.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 >= 2) {
                    SharePatchFileUtil.safeDeleteFile(this.retryInfoFile);
                    SharePatchFileUtil.safeDeleteFile(this.tempPatchFile);
                    TinkerLog.w(TAG, "onPatchServiceStart retry more than max count, delete " +
                            "retry info file!", new Object[0]);
                    return;
                }
                retryInfo.times = String.valueOf(nowTimes + 1);
            }
        } else {
            copyToTempFile(patchFile);
            retryInfo = new RetryInfo(patchMd5, "1");
        }
        RetryInfo.writeRetryProperty(this.retryInfoFile, retryInfo);
    } else {
        TinkerLog.w(TAG, "onPatchServiceStart is not upgrade patch, just return", new
                Object[0]);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:44,代码来源:UpgradePatchRetry.java


注:本文中的com.tencent.tinker.loader.shareutil.SharePatchFileUtil.getMD5方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。