com.tencent.tinker.lib.service.PatchResult Java Examples

The following examples show how to use com.tencent.tinker.lib.service.PatchResult. 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: TinkerServerManager.java    From tinkerpatch-sdk with MIT License 5 votes vote down vote up
/**
 * 上报补丁合成情况
 * @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
    );
}
 
Example #2
Source File: SampleApplication.java    From tinkerpatch-andresguard-sample with MIT License 4 votes vote down vote up
/**
 * 在这里给出TinkerPatch的所有接口解释
 * 更详细的解释请参考:http://tinkerpatch.com/Docs/api
 */
private void useSample() {
    TinkerPatch.init(tinkerApplicationLike)
        //是否自动反射Library路径,无须手动加载补丁中的So文件
        //注意,调用在反射接口之后才能生效,你也可以使用Tinker的方式加载Library
        .reflectPatchLibrary()
        //向后台获取是否有补丁包更新,默认的访问间隔为3个小时
        //若参数为true,即每次调用都会真正的访问后台配置
        .fetchPatchUpdate(false)
        //设置访问后台补丁包更新配置的时间间隔,默认为3个小时
        .setFetchPatchIntervalByHours(3)
        //向后台获得动态配置,默认的访问间隔为3个小时
        //若参数为true,即每次调用都会真正的访问后台配置
        .fetchDynamicConfig(new ConfigRequestCallback() {
            @Override
            public void onSuccess(HashMap<String, String> hashMap) {

            }

            @Override
            public void onFail(Exception e) {

            }
        }, false)
        //设置访问后台动态配置的时间间隔,默认为3个小时
        .setFetchDynamicConfigIntervalByHours(3)
        //设置当前渠道号,对于某些渠道我们可能会想屏蔽补丁功能
        //设置渠道后,我们就可以使用后台的条件控制渠道更新
        .setAppChannel("default")
        //屏蔽部分渠道的补丁功能
        .addIgnoreAppChannel("googleplay")
        //设置tinkerpatch平台的条件下发参数
        .setPatchCondition("test", "1")
        //设置补丁合成成功后,锁屏重启程序
        //默认是等应用自然重启
        .setPatchRestartOnSrceenOff(true)
        //我们可以通过ResultCallBack设置对合成后的回调
        //例如弹框什么
        .setPatchResultCallback(new ResultCallBack() {
            @Override
            public void onPatchResult(PatchResult patchResult) {
                Log.i(TAG, "onPatchResult callback here");
            }
        })
        //设置收到后台回退要求时,锁屏清除补丁
        //默认是等主进程重启时自动清除
        .setPatchRollbackOnScreenOff(true)
        //我们可以通过RollbackCallBack设置对回退时的回调
        .setPatchRollBackCallback(new RollbackCallBack() {
            @Override
            public void onPatchRollback() {
                Log.i(TAG, "onPatchRollback callback here");
            }
        });
}
 
Example #3
Source File: SampleResultService.java    From HotFixDemo with MIT License 4 votes vote down vote up
@Override
public void onPatchResult(final PatchResult result) {
    if (result == null) {
        TinkerLog.e(TAG, "SampleResultService received null result!!!!");
        return;
    }
    TinkerLog.i(TAG, "SampleResultService receive result: %s", result.toString());

    //first, we want to kill the recover process
    TinkerServiceInternals.killTinkerPatchServiceProcess(getApplicationContext());

    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            if (result.isSuccess) {
                Toast.makeText(getApplicationContext(), "patch success, please restart process", Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(getApplicationContext(), "patch fail, please check reason", Toast.LENGTH_LONG).show();
            }
        }
    });
    // is success and newPatch, it is nice to delete the raw file, and restart at once
    // for old patch, you can't delete the patch file
    if (result.isSuccess) {
        deleteRawPatchFile(new File(result.rawPatchFilePath));

        //not like TinkerResultService, I want to restart just when I am at background!
        //if you have not install tinker this moment, you can use TinkerApplicationHelper api
        if (checkIfNeedKill(result)) {
            if (TinkerUtils.isBackground()) {
                TinkerLog.i(TAG, "it is in background, just restart process");
                restartProcess();
            } else {
                //we can wait process at background, such as onAppBackground
                //or we can restart when the screen off
                TinkerLog.i(TAG, "tinker wait screen to restart process");
                new TinkerUtils.ScreenState(getApplicationContext(), new TinkerUtils.ScreenState.IOnScreenOff() {
                    @Override
                    public void onScreenOff() {
                        restartProcess();
                    }
                });
            }
        } else {
            TinkerLog.i(TAG, "I have already install the newly patch version!");
        }
    }
}
 
Example #4
Source File: SampleResultService.java    From tinker-manager with Apache License 2.0 4 votes vote down vote up
@Override
public void onPatchResult(final PatchResult result) {
    if (result == null) {
        TinkerLog.e(TAG, "SampleResultService received null result!!!!");
        return;
    }
    TinkerLog.i(TAG, "SampleResultService receive result: %s", result.toString());

    //first, we want to kill the recover process
    TinkerServiceInternals.killTinkerPatchServiceProcess(getApplicationContext());

    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            if (result.isSuccess) {
                TinkerLog.i(TAG, "patch success, please restart process");
            } else {
                TinkerLog.e(TAG, "patch fail, please check reason");
            }
        }
    });
    // is success and newPatch, it is nice to delete the raw file, and restart at once
    // for old patch, you can't delete the patch file
    if (!result.isSuccess) {
        //补丁合成异常
        PatchManager.getInstance().onPatchFailure(result.rawPatchFilePath, PatchManager.ERROR_CODE_PATCH_RESULT + PatchManager.ERROR_PATCH_FAIL);
        return;
    }
    //deleteRawPatchFile(new File(result.rawPatchFilePath));

    PatchManager.getInstance().onPatchSuccess(result.rawPatchFilePath);

    //not like TinkerResultService, I want to restart just when I am at background!
    //if you have not install tinker this moment, you can use TinkerApplicationHelper api
    if (checkIfNeedKill(result)) {
        if (SampleUtils.isBackground()) {
            TinkerLog.i(TAG, "it is in background, just restart process");
            restartProcess();
        } else {
            //we can wait process at background, such as onAppBackground
            //or we can restart when the screen off
            TinkerLog.i(TAG, "tinker wait screen to restart process");
            new SampleUtils.ScreenState(getApplicationContext(), new SampleUtils.ScreenState.IOnScreenOff() {
                @Override
                public void onScreenOff() {
                    restartProcess();
                }
            });
        }
    } else {
        TinkerLog.i(TAG, "I have already install the newly patch version!");
    }
}
 
Example #5
Source File: TinkerServerResultService.java    From tinkerpatch-sdk with MIT License 4 votes vote down vote up
@Override
public void onPatchResult(final PatchResult result) {
    if (result == null) {
        TinkerLog.e(TAG, "received null result!!!!");
        return;
    }
    TinkerLog.i(TAG, "receive result: %s", result.toString());

    //first, we want to kill the recover process
    TinkerServiceInternals.killTinkerPatchServiceProcess(getApplicationContext());
    TinkerServerManager.reportTinkerPatchFail(result);

    if (result.isSuccess) {
        TinkerLog.i(TAG, "patch success, please restart process");
        File rawFile = new File(result.rawPatchFilePath);
        if (rawFile.exists()) {
            TinkerLog.i(TAG, "save delete raw patch file");
            SharePatchFileUtil.safeDeleteFile(rawFile);
        }
        //not like TinkerResultService, I want to restart just when I am at background!
        //if you have not install tinker this moment, you can use TinkerApplicationHelper api
        if (checkIfNeedKill(result)) {
            if (TinkerServerUtils.isBackground()) {
                TinkerLog.i(TAG, "it is in background, just restart process");
                restartProcess();
            } else {
                //we can wait process at background, such as onAppBackground
                //or we can restart when the screen off
                TinkerLog.i(TAG, "tinker wait screen to restart process");
                new TinkerServerUtils.ScreenState(
                    getApplicationContext(), new TinkerServerUtils.IOnScreenOff() {
                    @Override
                    public void onScreenOff() {
                        restartProcess();
                    }
                });
            }
        } else {
            TinkerLog.i(TAG, "I have already install the newly patch version!");
        }
    } else {
        TinkerLog.i(TAG, "patch fail, please check reason");
    }

    //repair current patch fail, just clean!
    if (!result.isSuccess) {
        //if you have not install tinker this moment, you can use TinkerApplicationHelper api
        Tinker.with(getApplicationContext()).cleanPatch();
    }
}
 
Example #6
Source File: SampleApplicationLike.java    From tinkerpatch-sample with MIT License 4 votes vote down vote up
/**
 * 在这里给出TinkerPatch的所有接口解释
 * 更详细的解释请参考:http://tinkerpatch.com/Docs/api
 */
private void useSample() {
    TinkerPatch.init(this)
        //是否自动反射Library路径,无须手动加载补丁中的So文件
        //注意,调用在反射接口之后才能生效,你也可以使用Tinker的方式加载Library
        .reflectPatchLibrary()
        //向后台获取是否有补丁包更新,默认的访问间隔为3个小时
        //若参数为true,即每次调用都会真正的访问后台配置
        .fetchPatchUpdate(false)
        //设置访问后台补丁包更新配置的时间间隔,默认为3个小时
        .setFetchPatchIntervalByHours(3)
        //向后台获得动态配置,默认的访问间隔为3个小时
        //若参数为true,即每次调用都会真正的访问后台配置
        .fetchDynamicConfig(new ConfigRequestCallback() {
            @Override
            public void onSuccess(HashMap<String, String> hashMap) {

            }

            @Override
            public void onFail(Exception e) {

            }
        }, false)
        //设置访问后台动态配置的时间间隔,默认为3个小时
        .setFetchDynamicConfigIntervalByHours(3)
        //设置当前渠道号,对于某些渠道我们可能会想屏蔽补丁功能
        //设置渠道后,我们就可以使用后台的条件控制渠道更新
        .setAppChannel("default")
        //屏蔽部分渠道的补丁功能
        .addIgnoreAppChannel("googleplay")
        //设置tinkerpatch平台的条件下发参数
        .setPatchCondition("test", "1")
        //设置补丁合成成功后,锁屏重启程序
        //默认是等应用自然重启
        .setPatchRestartOnSrceenOff(true)
        //我们可以通过ResultCallBack设置对合成后的回调
        //例如弹框什么
        .setPatchResultCallback(new ResultCallBack() {
            @Override
            public void onPatchResult(PatchResult patchResult) {
                Log.i(TAG, "onPatchResult callback here");
            }
        })
        //设置收到后台回退要求时,锁屏清除补丁
        //默认是等主进程重启时自动清除
        .setPatchRollbackOnScreenOff(true)
        //我们可以通过RollbackCallBack设置对回退时的回调
        .setPatchRollBackCallback(new RollbackCallBack() {
            @Override
            public void onPatchRollback() {
                Log.i(TAG, "onPatchRollback callback here");
            }
        });
}
 
Example #7
Source File: ResultCallBack.java    From tinkerpatch-sdk with MIT License votes vote down vote up
void onPatchResult(final PatchResult result);