com.tencent.tinker.loader.app.ApplicationLike Java Examples
The following examples show how to use
com.tencent.tinker.loader.app.ApplicationLike.
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 |
/** * 自定义安装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 |
/** * 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 |
/** * 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: TinkerManager.java From HotFixDemo with MIT License | 5 votes |
/** * 默认安装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 #5
Source File: SampleUncaughtExceptionHandler.java From HotFixDemo with MIT License | 5 votes |
/** * 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 #6
Source File: SampleUncaughtExceptionHandler.java From tinker-manager with Apache License 2.0 | 5 votes |
/** * 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 #7
Source File: SampleTinkerManager.java From tinker-manager with Apache License 2.0 | 5 votes |
/** * 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 #8
Source File: TinkerManager.java From HotFixDemo with MIT License | 4 votes |
public static void setTinkerApplicationLike(ApplicationLike appLike) { applicationLike = appLike; }
Example #9
Source File: TinkerManager.java From HotFixDemo with MIT License | 4 votes |
public static ApplicationLike getTinkerApplicationLike() { return applicationLike; }
Example #10
Source File: SampleUncaughtExceptionHandler.java From HotFixDemo with MIT License | 4 votes |
/** * 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 #11
Source File: SampleUncaughtExceptionHandler.java From tinker-manager with Apache License 2.0 | 4 votes |
/** * 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 #12
Source File: SampleTinkerManager.java From tinker-manager with Apache License 2.0 | 4 votes |
public static void setTinkerApplicationLike(ApplicationLike appLike) { applicationLike = appLike; }
Example #13
Source File: SampleTinkerManager.java From tinker-manager with Apache License 2.0 | 4 votes |
public static ApplicationLike getTinkerApplicationLike() { return applicationLike; }
Example #14
Source File: TinkerPatch.java From tinkerpatch-sdk with MIT License | 2 votes |
/** * 用默认的构造参数初始化TinkerPatch的SDK * @param applicationLike * @return */ public static TinkerPatch init(ApplicationLike applicationLike) { return null; }
Example #15
Source File: TinkerPatch.java From tinkerpatch-sdk with MIT License | 2 votes |
/** * 获得ApplicationLike的实例 * @return */ public abstract ApplicationLike getApplcationLike();