Java Code Examples for com.tencent.tinker.lib.tinker.TinkerInstaller#onReceiveUpgradePatch()

The following examples show how to use com.tencent.tinker.lib.tinker.TinkerInstaller#onReceiveUpgradePatch() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TinkerServerPatchRequestCallback.java    From tinkerpatch-sdk with MIT License 6 votes vote down vote up
private boolean handlePatchFile(Context context, Integer version, File patchFile) {
    SharedPreferences sp = context.getSharedPreferences(
        TinkerServerClient.SHARE_SERVER_PREFERENCE_CONFIG, Context.MODE_PRIVATE
    );
    int current = sp.getInt(TINKER_RETRY_PATCH, 0);
    if (current >= TINKER_MAX_RETRY_COUNT) {
        SharePatchFileUtil.safeDeleteFile(patchFile);
        sp.edit().putInt(TINKER_RETRY_PATCH, 0).commit();
        TinkerLog.w(TAG,
            "beforePatchRequest, retry patch install more than %d times, version: %d, patch:%s",
            current, version, patchFile.getPath()
        );
    } else {
        TinkerLog.w(TAG, "beforePatchRequest, have pending patch to install, version: %d, patch:%s",
            version, patchFile.getPath()
        );

        sp.edit().putInt(TINKER_RETRY_PATCH, ++current).commit();
        TinkerInstaller.onReceiveUpgradePatch(context, patchFile.getAbsolutePath());
        return true;
    }
    return false;
}
 
Example 2
Source File: DefaultPatchRequestCallback.java    From tinkerpatch-sdk with MIT License 6 votes vote down vote up
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());
    }
}
 
Example 3
Source File: SampleLoadReporter.java    From tinker-manager with Apache License 2.0 5 votes vote down vote up
/**
 * try to recover patch oat file
 * @param file
 * @param fileType
 * @param isDirectory
 */
@Override
public void onLoadFileNotFound(File file, int fileType, boolean isDirectory) {
    TinkerLog.i(TAG, "patch loadReporter onLoadFileNotFound: patch file not found: %s, fileType:%d, isDirectory:%b",
            file.getAbsolutePath(), fileType, isDirectory);

    // only try to recover opt file
    // check dex opt file at last, some phone such as VIVO/OPPO like to change dex2oat to interpreted
    if (fileType == ShareConstants.TYPE_DEX_OPT) {
        Tinker tinker = Tinker.with(context);
        //we can recover at any process except recover process
        if (tinker.isMainProcess()) {
            File patchVersionFile = tinker.getTinkerLoadResultIfPresent().patchVersionFile;
            if (patchVersionFile != null) {
                if (UpgradePatchRetry.getInstance(context).onPatchListenerCheck(SharePatchFileUtil.getMD5(patchVersionFile))) {
                    TinkerLog.i(TAG, "try to repair oat file on patch process");
                    TinkerInstaller.onReceiveUpgradePatch(context, patchVersionFile.getAbsolutePath());
                } else {
                    TinkerLog.i(TAG, "repair retry exceed must max time, just clean");
                    checkAndCleanPatch();
                }
            }
        }
    } else {
        checkAndCleanPatch();
    }
    SampleTinkerReport.onLoadFileNotFound(fileType);
}
 
Example 4
Source File: MainActivity.java    From HotFixDemo with MIT License 4 votes vote down vote up
public void install_patch(View view) {
        TinkerInstaller.onReceiveUpgradePatch(getApplicationContext(), Environment.getExternalStorageDirectory().getAbsolutePath() + "/patch_signed_7zip.apk");
//        TinkerInstaller.onReceiveUpgradePatch(getApplicationContext(), getCacheDir().getAbsolutePath() + "/patch_signed_7zip.apk");
    }