Java Code Examples for com.tencent.tinker.lib.util.TinkerLog#i()

The following examples show how to use com.tencent.tinker.lib.util.TinkerLog#i() . 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: SampleBsDiffPatchInternal.java    From tinker-manager with Apache License 2.0 6 votes vote down vote up
public static boolean tryRecoverLibraryFiles(Tinker manager, ShareSecurityCheck checker, Context context,
                                                String patchVersionDirectory, File patchFile) {

    if (!manager.isEnabledForNativeLib()) {
        TinkerLog.w(TAG, "patch recover, library is not enabled");
        return true;
    }
    String libMeta = checker.getMetaContentMap().get(SO_META_FILE);

    if (libMeta == null) {
        TinkerLog.w(TAG, "patch recover, library is not contained");
        return true;
    }
    long begin = SystemClock.elapsedRealtime();
    boolean result = patchLibraryExtractViaBsDiff(context, patchVersionDirectory, libMeta, patchFile);
    long cost = SystemClock.elapsedRealtime() - begin;
    TinkerLog.i(TAG, "recover lib result:%b, cost:%d", result, cost);
    return result;
}
 
Example 2
Source File: SampleDexDiffPatchInternal.java    From tinker-manager with Apache License 2.0 6 votes vote down vote up
public static boolean tryRecoverDexFiles(Tinker manager, ShareSecurityCheck checker, Context context,
                                            String patchVersionDirectory, File patchFile) {
    if (!manager.isEnabledForDex()) {
        TinkerLog.w(TAG, "patch recover, dex is not enabled");
        return true;
    }
    String dexMeta = checker.getMetaContentMap().get(DEX_META_FILE);

    if (dexMeta == null) {
        TinkerLog.w(TAG, "patch recover, dex is not contained");
        return true;
    }

    long begin = SystemClock.elapsedRealtime();
    boolean result = patchDexExtractViaDexDiff(context, patchVersionDirectory, dexMeta, patchFile);
    long cost = SystemClock.elapsedRealtime() - begin;
    TinkerLog.i(TAG, "recover dex result:%b, cost:%d", result, cost);
    return result;
}
 
Example 3
Source File: DefaultPatchRequestCallback.java    From tinkerpatch-sdk with MIT License 6 votes vote down vote up
@Override
public boolean onPatchUpgrade(File file, Integer newVersion, Integer currentVersion) {
    TinkerLog.i(TAG, "onPatchUpgrade, file:%s, newVersion:%d, currentVersion:%d",
        file.getPath(), newVersion, currentVersion);
    TinkerServerClient client = TinkerServerClient.get();
    Context context = client.getContext();
    client.reportPatchDownloadSuccess(newVersion);

    ShareSecurityCheck securityCheck = new ShareSecurityCheck(context);
    if (!securityCheck.verifyPatchMetaSignature(file)) {
        TinkerLog.e(TAG, "onPatchUpgrade, signature check fail. file: %s, version:%d", file.getPath(), newVersion);
        //treat it as download fail
        if (increaseDownloadError(context)) {
            //update tinker version also, don't request again
            client.updateTinkerVersion(newVersion, SharePatchFileUtil.getMD5(file));
            client.reportPatchFail(newVersion, ERROR_DOWNLOAD_CHECK_FAIL);
        }
        SharePatchFileUtil.safeDeleteFile(file);
        return false;
    }
    tryPatchFile(file, newVersion);
    return true;
}
 
Example 4
Source File: SampleTinkerReport.java    From HotFixDemo with MIT License 5 votes vote down vote up
public static void onApplyPackageCheckFail(int errorCode) {
    if (reporter == null) {
        return;
    }
    TinkerLog.i(TAG, "hp_report package check failed, error = %d", errorCode);

    switch (errorCode) {
        case ShareConstants.ERROR_PACKAGE_CHECK_SIGNATURE_FAIL:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_SIGNATURE);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_DEX_META_CORRUPTED:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_DEX_META);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_LIB_META_CORRUPTED:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_LIB_META);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_PATCH_TINKER_ID_NOT_FOUND:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_PATCH_TINKER_ID_NOT_FOUND);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_APK_TINKER_ID_NOT_FOUND:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_APK_TINKER_ID_NOT_FOUND);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_TINKER_ID_NOT_EQUAL:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_TINKER_ID_NOT_EQUAL);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_PACKAGE_META_NOT_FOUND:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_META_NOT_FOUND);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_RESOURCE_META_CORRUPTED:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_RES_META);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_TINKERFLAG_NOT_SUPPORT:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_TINKERFLAG_NOT_SUPPORT);
            break;
    }
}
 
Example 5
Source File: TinkerServerPatchListener.java    From tinkerpatch-sdk with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 6
Source File: TinkerServerManager.java    From tinkerpatch-sdk with MIT License 5 votes vote down vote up
/**
 * 初始化 TinkerServer 实例
 * @param context context
 * @param tinker {@link Tinker} 实例
 * @param hours  访问服务器的时间间隔, 单位为小时, 应为 >= 0
 * @param appKey 从Tinkerpatch中得到的appKey
 * @param appVersion 在Tinkerpatch中填写的appVersion
 * @param channel 发布的渠道名称,由于GooglePlay渠道的政策限制,我们会停止所有channel中含有google关键字的动态下发功能。
 * @param patchRequestCallback {@link PatchRequestCallback} patch请求的callback
 */
public static void installTinkerServer(
    Context context,
    Tinker tinker,
    int hours,
    String appKey,
    String appVersion,
    String channel,
    PatchRequestCallback patchRequestCallback
) {
    final boolean debug = Debugger.getInstance(context).isDebug();
    TinkerLog.i(TAG, String.format("installTinkerServer, debug value: %s appVersion: %s, channel: %s",
        String.valueOf(debug), appVersion, channel)
    );
    sTinkerServerClient = TinkerServerClient.init(
        context,
        tinker,
        appKey,
        appVersion,
        debug,
        patchRequestCallback
    );
    // add channel condition
    sTinkerServerClient.updateTinkerCondition(CONDITION_CHANNEL, channel);
    sTinkerServerClient.setCheckIntervalByHours(hours);
    TinkerServerManager.channel = channel;
}
 
Example 7
Source File: DefaultPatchRequestCallback.java    From tinkerpatch-sdk with MIT License 5 votes vote down vote up
public boolean increaseDownloadError(Context context) {
    SharedPreferences sp = context.getSharedPreferences(
        TinkerServerClient.SHARE_SERVER_PREFERENCE_CONFIG, Context.MODE_PRIVATE
    );
    int currentCount = sp.getInt(TINKER_DOWNLOAD_FAIL_TIMES, 0);
    TinkerLog.i(TAG, "increaseDownloadError, current count:%d", currentCount);

    if (currentCount >= TINKER_DOWNLOAD_FAIL_MAX_TIMES) {
        sp.edit().putInt(TINKER_DOWNLOAD_FAIL_TIMES, 0).commit();
        return true;
    } else {
        sp.edit().putInt(TINKER_DOWNLOAD_FAIL_TIMES, ++currentCount).commit();
    }
    return false;
}
 
Example 8
Source File: TinkerServerClient.java    From tinkerpatch-sdk with MIT License 5 votes vote down vote up
/**
 * 上报补丁应用成功
 * @param patchVersion 补丁包版本号
 */
public void reportPatchApplySuccess(Integer patchVersion) {
    if (!checkParameter()) {
        TinkerLog.e(TAG, "check parameter fail, appKey or appVersion is null, "
            + "reportPatchApplySuccess just return");
        return;
    }
    TinkerLog.i(TAG, "tinker server report patch apply success, patchVersion:%d", patchVersion);
    clientAPI.reportApplySuccess(patchVersion);
}
 
Example 9
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 10
Source File: SampleTinkerReport.java    From tinker-manager with Apache License 2.0 5 votes vote down vote up
public static void onApplyPackageCheckFail(int errorCode) {
    if (reporter == null) {
        return;
    }
    TinkerLog.i(TAG, "hp_report package check failed, error = %d", errorCode);

    switch (errorCode) {
        case ShareConstants.ERROR_PACKAGE_CHECK_SIGNATURE_FAIL:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_SIGNATURE);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_DEX_META_CORRUPTED:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_DEX_META);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_LIB_META_CORRUPTED:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_LIB_META);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_PATCH_TINKER_ID_NOT_FOUND:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_PATCH_TINKER_ID_NOT_FOUND);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_APK_TINKER_ID_NOT_FOUND:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_APK_TINKER_ID_NOT_FOUND);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_TINKER_ID_NOT_EQUAL:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_TINKER_ID_NOT_EQUAL);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_PACKAGE_META_NOT_FOUND:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_META_NOT_FOUND);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_RESOURCE_META_CORRUPTED:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_RES_META);
            break;
        case ShareConstants.ERROR_PACKAGE_CHECK_TINKERFLAG_NOT_SUPPORT:
            reporter.onReport(KEY_APPLIED_PACKAGE_CHECK_TINKERFLAG_NOT_SUPPORT);
            break;
    }
}
 
Example 11
Source File: TinkerServerClient.java    From tinkerpatch-sdk with MIT License 5 votes vote down vote up
/**
 * 获取后台在线参数信息
 * @param callback    回调
 * @param immediately 是否忽略时间间隔
 */
public void getDynamicConfig(final ConfigRequestCallback callback, boolean immediately) {
    SharedPreferences sp = context.getSharedPreferences(
        SHARE_SERVER_PREFERENCE_CONFIG, Context.MODE_PRIVATE
    );
    long last = sp.getLong(TINKER_CONFIG_LAST_CHECK, 0);
    if (last == NEVER_CHECK_UPDATE) {
        TinkerLog.i(TAG, "tinker get config is disabled, with never check flag!");
        return;
    }

    long interval = System.currentTimeMillis() - last;
    if (immediately || clientAPI.isDebug() || interval >= checkConfigInterval) {
        sp.edit().putLong(TINKER_CONFIG_LAST_CHECK, System.currentTimeMillis()).commit();
        clientAPI.getDynamicConfig(new DataFetcher.DataCallback<String>() {
            @Override
            public void onDataReady(String data) {
                if (callback != null) {
                    callback.onSuccess(data);
                }
            }

            @Override
            public void onLoadFailed(Exception e) {
                if (callback != null) {
                    callback.onFail(e);
                }
            }
        });
    } else {
        TinkerLog.i(TAG, "tinker get dynamic config should wait interval %ss",
            (checkConfigInterval - interval) / 1000);
    }
}
 
Example 12
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 13
Source File: TinkerServerClient.java    From tinkerpatch-sdk with MIT License 5 votes vote down vote up
/**
 * 上报补丁下载成功
 * @param patchVersion 补丁包版本号
 */
public void reportPatchDownloadSuccess(Integer patchVersion) {
    if (!checkParameter()) {
        TinkerLog.e(TAG, "check parameter fail, appKey or appVersion is null, "
            + "reportPatchDownloadSuccess just return");
        return;
    }
    TinkerLog.i(TAG, "tinker server report patch download success, patchVersion:%d", patchVersion);
    clientAPI.reportDownloadSuccess(patchVersion);
}
 
Example 14
Source File: SamplePatchListener.java    From HotFixDemo with MIT License 5 votes vote down vote up
/**
 * 若检查成功,我们会调用TinkerPatchService.runPatchService唤起:patch进程,去尝试完成补丁合成操作。反之,会回调检验失败的接口。
 * 若检查失败,会在LoadReporter的onLoadPatchListenerReceiveFail中回调。
 * <p>
 * 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, String patchMd5) {
    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, patchMd5);

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

    if (returnCode == ShareConstants.ERROR_PATCH_OK) {
        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 = TinkerUtils.ERROR_PATCH_CRASH_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 = TinkerUtils.ERROR_PATCH_CONDITION_NOT_SATISFIED;
        } else {
            String platform = properties.getProperty(TinkerUtils.PLATFORM);
            TinkerLog.i(TAG, "get platform:" + platform);
            // check patch platform require
            if (platform == null || !platform.equals("all")) {
                returnCode = TinkerUtils.ERROR_PATCH_CONDITION_NOT_SATISFIED;
            }
        }
    }

    SampleTinkerReport.onTryApply(returnCode == ShareConstants.ERROR_PATCH_OK);
    return returnCode;
}
 
Example 15
Source File: Debugger.java    From tinkerpatch-sdk with MIT License 5 votes vote down vote up
private Debugger(final Context context) {
    final ContentResolver cr = context.getContentResolver();
    Cursor cu;
    try {
        cu = cr.query(CONTENT_URI, columns, null, null, null);
    } catch (Exception e) {
        TinkerLog.e(TAG, "Get contentProvider error", e);
        cu = null;
    }

    if (cu == null || cu.getCount() <= 0) {
        TinkerLog.w(TAG, "debugger not attached cu == null");
        if (cu != null) {
            cu.close();
        }
        return;
    }

    TinkerLog.i(TAG, "debugger attached");

    final int keyIdx = cu.getColumnIndex("key");
    final int typeIdx = cu.getColumnIndex("type");
    final int valueIdx = cu.getColumnIndex("value");

    while (cu.moveToNext()) {
        final Object obj = Resolver.resolveObj(cu.getInt(typeIdx), cu.getString(valueIdx));
        values.put(cu.getString(keyIdx), obj);
    }
    cu.close();
}
 
Example 16
Source File: SamplePatchReporter.java    From tinker-manager with Apache License 2.0 4 votes vote down vote up
@Override
public void onPatchServiceStart(Intent intent) {
    super.onPatchServiceStart(intent);
    SampleTinkerReport.onApplyPatchServiceStart();
    TinkerLog.i(TAG, "patch进程启动.intent==" + intent);
}
 
Example 17
Source File: UrlConnectionUrlLoader.java    From tinkerpatch-sdk with MIT License 4 votes vote down vote up
public DataFetcher<InputStream> buildLoadData(TinkerClientUrl url) {
    TinkerLog.i(TAG, "loadData from: %s", url.toStringUrl());
    return new UrlConnectionStreamFetcher(executor, url);
}
 
Example 18
Source File: SampleResultService.java    From HotFixDemo with MIT License 4 votes vote down vote up
/**
 * you can restart your process through service or broadcast
 */
private void restartProcess() {
    TinkerLog.i(TAG, "app is background now, i can kill quietly");
    //you can send service or broadcast intent to restart your process
    android.os.Process.killProcess(android.os.Process.myPid());
}
 
Example 19
Source File: SamplePatchListener.java    From HotFixDemo with MIT License 4 votes vote down vote up
public SamplePatchListener(Context context) {
    super(context);
    maxMemory = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();
    TinkerLog.i(TAG, "application maxMemory:" + maxMemory);
}
 
Example 20
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();
    }
}