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

The following examples show how to use com.tencent.tinker.lib.util.TinkerLog#w() . 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: TinkerManager.java    From HotFixDemo with MIT License 6 votes vote down vote up
/**
 * 自定义安装Tinker(使用你自定义的reporter类:SampleLoadReporter、SamplePatchReporter、SamplePatchListener、SampleResultService)
 * you can specify all class you want.
 * sometimes, you can only install tinker in some process you want!
 */
public static void installTinker(ApplicationLike appLike) {
    if (isInstalled) {
        TinkerLog.w(TAG, "install tinker, but has installed, ignore");
        return;
    }
    //or you can just use DefaultLoadReporter
    LoadReporter loadReporter = new SampleLoadReporter(appLike.getApplication());
    //or you can just use DefaultPatchReporter
    PatchReporter patchReporter = new SamplePatchReporter(appLike.getApplication());
    //or you can just use DefaultPatchListener
    PatchListener patchListener = new SamplePatchListener(appLike.getApplication());
    //you can set your own upgrade patch if you need
    AbstractPatch upgradePatchProcessor = new UpgradePatch();

    TinkerInstaller.install(appLike,
            loadReporter, patchReporter, patchListener,
            SampleResultService.class, upgradePatchProcessor);

    isInstalled = true;
}
 
Example 2
Source File: DefaultPatchRequestCallback.java    From tinkerpatch-sdk with MIT License 6 votes vote down vote up
@Override
public void onPatchDownloadFail(Exception e, Integer newVersion, Integer currentVersion) {
    TinkerLog.w(TAG, "onPatchDownloadFail e:" + e);
    //check network
    TinkerServerClient client = TinkerServerClient.get();
    //due to network, just return
    if (!NetStatusUtil.isConnected(client.getContext())) {
        TinkerLog.e(TAG, "onPatchDownloadFail, not connect to internet just return");
        return;
    }
    Context context = client.getContext();
    if (increaseDownloadError(context)) {
        client.reportPatchFail(newVersion, ERROR_DOWNLOAD_FAIL);
    }

}
 
Example 3
Source File: TinkerServerPatchRequestCallback.java    From tinkerpatch-sdk with MIT License 6 votes vote down vote up
@Override
public void onPatchRollback() {
    TinkerLog.w(TAG, "onPatchRollback");
    TinkerServerClient client = TinkerServerClient.get();

    if (!client.getTinker().isTinkerLoaded()) {
        TinkerLog.w(TAG, "onPatchRollback, tinker is not loaded, just return");
        return;
    }

    if (TinkerServerUtils.isBackground()) {
        TinkerLog.i(TAG, "onPatchRollback, it is in background, just clean patch and kill all process");
        rollbackPatchDirectly();
    } 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 clean patch and kill all process");
        new TinkerServerUtils.ScreenState(client.getContext(), new TinkerServerUtils.IOnScreenOff() {
            @Override
            public void onScreenOff() {
                rollbackPatchDirectly();
            }
        });
    }
}
 
Example 4
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 5
Source File: TinkerManager.java    From tinkerpatch-sdk with MIT License 6 votes vote down vote up
/**
 * you can specify all class you want.
 * sometimes, you can only install tinker in some process you want!
 *
 * @param appLike ApplicationLike
 */
public static void installTinker(ApplicationLike appLike) {
    if (isInstalled) {
        TinkerLog.w(TAG, "install tinker, but has installed, ignore");
        return;
    }
    //or you can just use DefaultLoadReporter
    LoadReporter loadReporter = new TinkerServerLoadReporter(appLike.getApplication());
    //or you can just use DefaultPatchReporter
    PatchReporter patchReporter = new DefaultPatchReporter(appLike.getApplication());
    //or you can just use DefaultPatchListener
    PatchListener patchListener = new TinkerServerPatchListener(appLike.getApplication());
    //you can set your own upgrade patch if you need
    AbstractPatch upgradePatchProcessor = new UpgradePatch();
    TinkerInstaller.install(appLike,
        loadReporter, patchReporter, patchListener,
        TinkerServerResultService.class, upgradePatchProcessor
    );

    isInstalled = true;
}
 
Example 6
Source File: SampleResDiffPatchInternal.java    From tinker-manager with Apache License 2.0 6 votes vote down vote up
public static boolean tryRecoverResourceFiles(Tinker manager, ShareSecurityCheck checker, Context context,
                                                 String patchVersionDirectory, File patchFile) {

    if (!manager.isEnabledForResource()) {
        TinkerLog.w(TAG, "patch recover, resource is not enabled");
        return true;
    }
    String resourceMeta = checker.getMetaContentMap().get(RES_META_FILE);

    if (resourceMeta == null || resourceMeta.length() == 0) {
        TinkerLog.w(TAG, "patch recover, resource is not contained");
        return true;
    }

    long begin = SystemClock.elapsedRealtime();
    boolean result = patchResourceExtractViaResourceDiff(context, patchVersionDirectory, resourceMeta, patchFile);
    long cost = SystemClock.elapsedRealtime() - begin;
    TinkerLog.i(TAG, "recover resource result:%b, cost:%d", result, cost);
    return result;
}
 
Example 7
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 8
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 9
Source File: SampleTinkerManager.java    From tinker-manager with Apache License 2.0 6 votes vote down vote up
/**
     * you can specify all class you want.
     * sometimes, you can only install com.dx168.patchsdk.sample in some process you want!
     *
     * @param appLike
     */
    public static void installTinker(ApplicationLike appLike) {
        if (isInstalled) {
            TinkerLog.w(TAG, "install com.dx168.patchsdk.sample, but has installed, ignore");
            return;
        }
        //or you can just use DefaultLoadReporter
        LoadReporter loadReporter = new SampleLoadReporter(appLike.getApplication());
        //or you can just use DefaultPatchReporter
        PatchReporter patchReporter = new SamplePatchReporter(appLike.getApplication());
        //or you can just use DefaultPatchListener
        PatchListener patchListener = new SamplePatchListener(appLike.getApplication());
        //you can set your own upgrade patch if you need
//        AbstractPatch upgradePatchProcessor = new SampleUpgradePatch();
        AbstractPatch upgradePatchProcessor = new UpgradePatch();

        TinkerInstaller.install(appLike, loadReporter, patchReporter, patchListener, SampleResultService.class,
                upgradePatchProcessor);

        isInstalled = true;
    }
 
Example 10
Source File: SampleResDiffPatchInternal.java    From tinker-manager with Apache License 2.0 5 votes vote down vote up
private static boolean patchResourceExtractViaResourceDiff(Context context, String patchVersionDirectory,
                                                           String meta, File patchFile) {
    String dir = patchVersionDirectory + "/" + ShareConstants.RES_PATH + "/";

    if (!extractResourceDiffInternals(context, dir, meta, patchFile, TYPE_RESOURCE)) {
        TinkerLog.w(TAG, "patch recover, extractDiffInternals fail");
        return false;
    }
    return true;
}
 
Example 11
Source File: SampleTinkerManager.java    From tinker-manager with Apache License 2.0 5 votes vote down vote up
/**
 * all use default class, simply Tinker install method
 */
public static void sampleInstallTinker(ApplicationLike appLike) {
    if (isInstalled) {
        TinkerLog.w(TAG, "install com.dx168.patchsdk.sample, but has installed, ignore");
        return;
    }
    TinkerInstaller.install(appLike);
    isInstalled = true;

}
 
Example 12
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 13
Source File: TinkerManager.java    From HotFixDemo with MIT License 5 votes vote down vote up
/**
 * 默认安装Tinker(使用默认的reporter类:DefaultLoadReporter、DefaultPatchReporter、DefaultPatchListener、DefaultTinkerResultService)
 * 如果你不需要对监听app打补丁的情况(如:当打补丁失败时上传失败信息),则使用该方法
 */
public static void sampleInstallTinker(ApplicationLike appLike) {
    if (isInstalled) {
        TinkerLog.w(TAG, "install tinker, but has installed, ignore");
        return;
    }
    TinkerInstaller.install(appLike);
    isInstalled = true;

}
 
Example 14
Source File: SampleUncaughtExceptionHandler.java    From tinker-manager with Apache License 2.0 4 votes vote down vote up
/**
 * Such as Xposed, if it try to load some class before we load from patch files.
 * With dalvik, it will crash with "Class ref in pre-verified class resolved to unexpected implementation".
 * With art, it may crash at some times. But we can't know the actual crash type.
 * If it use Xposed, we can just clean patch or mention user to uninstall it.
 */
private void tinkerPreVerifiedCrashHandler(Throwable ex) {
    ApplicationLike applicationLike = SampleTinkerManager.getTinkerApplicationLike();
    if (applicationLike == null || applicationLike.getApplication() == null) {
        TinkerLog.w(TAG, "applicationlike is null");
        return;
    }

    if (!TinkerApplicationHelper.isTinkerLoadSuccess(applicationLike)) {
        TinkerLog.w(TAG, "tinker is not loaded");
        return;
    }

    Throwable throwable = ex;
    boolean isXposed = false;
    while (throwable != null) {
        if (!isXposed) {
            isXposed = SampleUtils.isXposedExists(throwable);
        }

        // xposed?
        if (isXposed) {
            boolean isCausedByXposed = false;
            //for art, we can't know the actually crash type
            //just ignore art
            if (throwable instanceof IllegalAccessError && throwable.getMessage().contains(DALVIK_XPOSED_CRASH)) {
                //for dalvik, we know the actual crash type
                isCausedByXposed = true;
            }

            if (isCausedByXposed) {
                SampleTinkerReport.onXposedCrash();
                TinkerLog.e(TAG, "have xposed: just clean tinker");
                //kill all other process to ensure that all process's code is the same.
                ShareTinkerInternals.killAllOtherProcess(applicationLike.getApplication());

                TinkerApplicationHelper.cleanPatch(applicationLike);
                ShareTinkerInternals.setTinkerDisableWithSharedPreferences(applicationLike.getApplication());
                return;
            }
        }
        throwable = throwable.getCause();
    }
}
 
Example 15
Source File: SampleUncaughtExceptionHandler.java    From HotFixDemo with MIT License 4 votes vote down vote up
/**
 * Such as Xposed, if it try to load some class before we load from patch files.
 * With dalvik, it will crash with "Class ref in pre-verified class resolved to unexpected implementation".
 * With art, it may crash at some times. But we can't know the actual crash type.
 * If it use Xposed, we can just clean patch or mention user to uninstall it.
 */
private void tinkerPreVerifiedCrashHandler(Throwable ex) {
    ApplicationLike applicationLike = TinkerManager.getTinkerApplicationLike();
    if (applicationLike == null || applicationLike.getApplication() == null) {
        TinkerLog.w(TAG, "applicationlike is null");
        return;
    }

    if (!TinkerApplicationHelper.isTinkerLoadSuccess(applicationLike)) {
        TinkerLog.w(TAG, "tinker is not loaded");
        return;
    }

    Throwable throwable = ex;
    boolean isXposed = false;
    while (throwable != null) {
        if (!isXposed) {
            isXposed = TinkerUtils.isXposedExists(throwable);
        }

        // xposed?
        if (isXposed) {
            boolean isCausedByXposed = false;
            //for art, we can't know the actually crash type
            //just ignore art
            if (throwable instanceof IllegalAccessError && throwable.getMessage().contains(DALVIK_XPOSED_CRASH)) {
                //for dalvik, we know the actual crash type
                isCausedByXposed = true;
            }

            if (isCausedByXposed) {
                SampleTinkerReport.onXposedCrash();
                TinkerLog.e(TAG, "have xposed: just clean tinker");
                //kill all other process to ensure that all process's code is the same.
                ShareTinkerInternals.killAllOtherProcess(applicationLike.getApplication());

                TinkerApplicationHelper.cleanPatch(applicationLike);
                ShareTinkerInternals.setTinkerDisableWithSharedPreferences(applicationLike.getApplication());
                return;
            }
        }
        throwable = throwable.getCause();
    }
}
 
Example 16
Source File: DefaultPatchRequestCallback.java    From tinkerpatch-sdk with MIT License 4 votes vote down vote up
@Override
public void onPatchSyncFail(Exception e) {
    TinkerLog.w(TAG, "onPatchSyncFail error:" + e);
    TinkerLog.printErrStackTrace(TAG, e, "onPatchSyncFail stack:");
}
 
Example 17
Source File: DefaultPatchRequestCallback.java    From tinkerpatch-sdk with MIT License 4 votes vote down vote up
@Override
public void onPatchRollback() {
    TinkerLog.w(TAG, "onPatchRollback");
    rollbackPatchDirectly();
}