Java Code Examples for com.tencent.tinker.loader.app.ApplicationLike#getApplication()

The following examples show how to use com.tencent.tinker.loader.app.ApplicationLike#getApplication() . 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: 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 3
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 4
Source File: SampleUncaughtExceptionHandler.java    From HotFixDemo with MIT License 5 votes vote down vote up
/**
 * if tinker is load, and it crash more than MAX_CRASH_COUNT, then we just clean patch.
 */
private boolean tinkerFastCrashProtect() {
    ApplicationLike applicationLike = TinkerManager.getTinkerApplicationLike();

    if (applicationLike == null || applicationLike.getApplication() == null) {
        return false;
    }
    if (!TinkerApplicationHelper.isTinkerLoadSuccess(applicationLike)) {
        return false;
    }

    final long elapsedTime = SystemClock.elapsedRealtime() - applicationLike.getApplicationStartElapsedTime();
    //this process may not install tinker, so we use TinkerApplicationHelper api
    if (elapsedTime < QUICK_CRASH_ELAPSE) {
        String currentVersion = TinkerApplicationHelper.getCurrentVersion(applicationLike);
        if (ShareTinkerInternals.isNullOrNil(currentVersion)) {
            return false;
        }

        SharedPreferences sp = applicationLike.getApplication().getSharedPreferences(ShareConstants.TINKER_SHARE_PREFERENCE_CONFIG, Context.MODE_MULTI_PROCESS);
        int fastCrashCount = sp.getInt(currentVersion, 0) + 1;
        if (fastCrashCount >= MAX_CRASH_COUNT) {
            SampleTinkerReport.onFastCrashProtect();
            TinkerApplicationHelper.cleanPatch(applicationLike);
            TinkerLog.e(TAG, "tinker has fast crash more than %d, we just clean patch!", fastCrashCount);
            return true;
        } else {
            sp.edit().putInt(currentVersion, fastCrashCount).commit();
            TinkerLog.e(TAG, "tinker has fast crash %d times", fastCrashCount);
        }
    }

    return false;
}
 
Example 5
Source File: SampleUncaughtExceptionHandler.java    From tinker-manager with Apache License 2.0 5 votes vote down vote up
/**
 * if com.dx168.patchsdk.sample is load, and it crash more than MAX_CRASH_COUNT, then we just clean patch.
 */
private boolean tinkerFastCrashProtect() {
    ApplicationLike applicationLike = SampleTinkerManager.getTinkerApplicationLike();

    if (applicationLike == null || applicationLike.getApplication() == null) {
        return false;
    }
    if (!TinkerApplicationHelper.isTinkerLoadSuccess(applicationLike)) {
        return false;
    }

    final long elapsedTime = SystemClock.elapsedRealtime() - applicationLike.getApplicationStartElapsedTime();
    //this process may not install com.dx168.patchsdk.sample, so we use TinkerApplicationHelper api
    if (elapsedTime < QUICK_CRASH_ELAPSE) {
        String currentVersion = TinkerApplicationHelper.getCurrentVersion(applicationLike);
        if (ShareTinkerInternals.isNullOrNil(currentVersion)) {
            return false;
        }

        SharedPreferences sp = applicationLike.getApplication().getSharedPreferences(ShareConstants.TINKER_SHARE_PREFERENCE_CONFIG, Context.MODE_MULTI_PROCESS);
        int fastCrashCount = sp.getInt(currentVersion, 0);
        if (fastCrashCount >= MAX_CRASH_COUNT) {
            SampleTinkerReport.onFastCrashProtect();
            TinkerApplicationHelper.cleanPatch(applicationLike);
            TinkerLog.e(TAG, "com.dx168.patchsdk.sample has fast crash more than %d, we just clean patch!", fastCrashCount);
            return true;
        } else {
            sp.edit().putInt(currentVersion, ++fastCrashCount).commit();
            TinkerLog.e(TAG, "com.dx168.patchsdk.sample has fast crash %d times", fastCrashCount);
        }
    }

    return false;
}
 
Example 6
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 7
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();
    }
}