本文整理汇总了Java中com.tencent.tinker.lib.tinker.Tinker.with方法的典型用法代码示例。如果您正苦于以下问题:Java Tinker.with方法的具体用法?Java Tinker.with怎么用?Java Tinker.with使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.tencent.tinker.lib.tinker.Tinker
的用法示例。
在下文中一共展示了Tinker.with方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onBaseContextAttached
import com.tencent.tinker.lib.tinker.Tinker; //导入方法依赖的package包/类
/**
* install multiDex before install tinker
* so we don't need to put the tinker lib classes in the main dex
*
* @param base
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
public void onBaseContextAttached(Context base) {
super.onBaseContextAttached(base);
sContext = getApplication();
//you must install multiDex whatever tinker is installed!
MultiDex.install(base);
TinkerManager.setTinkerApplicationLike(this);
TinkerManager.initFastCrashProtect();
//should set before tinker is installed
TinkerManager.setUpgradeRetryEnable(true);
//optional set logIml, or you can use default debug log
TinkerInstaller.setLogIml(new MyLogImp());
//installTinker after load multiDex
//or you can put com.tencent.tinker.** to main dex
TinkerManager.installTinker(this);
Tinker tinker = Tinker.with(getApplication());
}
示例2: checkAndCleanPatch
import com.tencent.tinker.lib.tinker.Tinker; //导入方法依赖的package包/类
/**
* other process may have installed old patch version,
* if we try to clean patch, we should kill other process first
*/
public void checkAndCleanPatch() {
Tinker tinker = Tinker.with(context);
//only main process can load a new patch
if (tinker.isMainProcess()) {
TinkerLoadResult tinkerLoadResult = tinker.getTinkerLoadResultIfPresent();
//if versionChange and the old patch version is not ""
if (tinkerLoadResult.versionChanged) {
SharePatchInfo sharePatchInfo = tinkerLoadResult.patchInfo;
if (sharePatchInfo != null && !ShareTinkerInternals.isNullOrNil(sharePatchInfo.oldVersion)) {
TinkerLog.w(TAG, "checkAndCleanPatch, oldVersion %s is not null, try kill all other process",
sharePatchInfo.oldVersion);
ShareTinkerInternals.killAllOtherProcess(context);
}
}
}
tinker.cleanPatch();
}
示例3: retryPatch
import com.tencent.tinker.lib.tinker.Tinker; //导入方法依赖的package包/类
public boolean retryPatch() {
final Tinker tinker = Tinker.with(context);
if (!tinker.isMainProcess()) {
return false;
}
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());
return true;
}
// else {
// TinkerLog.i(TAG, "repair retry exceed must max time, just clean");
// checkAndCleanPatch();
// }
}
return false;
}
示例4: installNavitveLibraryABI
import com.tencent.tinker.lib.tinker.Tinker; //导入方法依赖的package包/类
/**
* you can reflect your current abi to classloader library path
* as you don't need to use load*Library method above
* @param context
* @param currentABI
*/
public static void installNavitveLibraryABI(Context context, String currentABI) {
Tinker tinker = Tinker.with(context);
if (!tinker.isTinkerLoaded()) {
TinkerLog.i(TAG, "tinker is not loaded, just return");
return;
}
TinkerLoadResult loadResult = tinker.getTinkerLoadResultIfPresent();
if (loadResult.libs == null) {
TinkerLog.i(TAG, "tinker libs is null, just return");
return;
}
File soDir = new File(loadResult.libraryDirectory, "lib/" + currentABI);
if (!soDir.exists()) {
TinkerLog.e(TAG, "current libraryABI folder is not exist, path: %s", soDir.getPath());
return;
}
ClassLoader classLoader = context.getClassLoader();
if (classLoader == null) {
TinkerLog.e(TAG, "classloader is null");
return;
}
TinkerLog.i(TAG, "before hack classloader:" + classLoader.toString());
try {
installNativeLibraryPath(classLoader, soDir);
} catch (Throwable throwable) {
TinkerLog.e(TAG, "installNativeLibraryPath fail:" + throwable);
}
TinkerLog.i(TAG, "after hack classloader:" + classLoader.toString());
}
示例5: onLoadFileNotFound
import com.tencent.tinker.lib.tinker.Tinker; //导入方法依赖的package包/类
public void onLoadFileNotFound(File file, int fileType, boolean isDirectory) {
TinkerLog.i(TAG, "patch file not found: %s, fileType:%d, isDirectory:%b", file
.getAbsolutePath(), Integer.valueOf(fileType), Boolean.valueOf(isDirectory));
if (fileType == 3 || fileType == 5 || fileType == 6 || fileType == 7) {
Tinker tinker = Tinker.with(this.context);
if (!tinker.isPatchProcess()) {
File patchVersionFile = tinker.getTinkerLoadResultIfPresent().patchVersionFile;
if (patchVersionFile != null) {
TinkerInstaller.onReceiveRepairPatch(this.context, patchVersionFile
.getAbsolutePath());
}
}
} else if (fileType == 1 || fileType == 2) {
Tinker.with(this.context).cleanPatch();
}
}
示例6: patchCheck
import com.tencent.tinker.lib.tinker.Tinker; //导入方法依赖的package包/类
protected int patchCheck(String path, boolean isUpgrade) {
Tinker manager = Tinker.with(this.context);
if (!manager.isTinkerEnabled() || !ShareTinkerInternals
.isTinkerEnableWithSharedPreferences(this.context)) {
return -1;
}
File file = new File(path);
if (!file.isFile() || !file.exists() || file.length() == 0) {
return -2;
}
if (manager.isPatchProcess()) {
return -4;
}
if (TinkerServiceInternals.isTinkerPatchServiceRunning(this.context)) {
return -3;
}
return 0;
}
示例7: onLoadFileNotFound
import com.tencent.tinker.lib.tinker.Tinker; //导入方法依赖的package包/类
/**
* 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);
}
示例8: onPatchRetryLoad
import com.tencent.tinker.lib.tinker.Tinker; //导入方法依赖的package包/类
public void onPatchRetryLoad() {
if (!isRetryEnable) {
TinkerLog.w(TAG, "onPatchRetryLoad retry disabled, just return");
return;
}
Tinker tinker = Tinker.with(context);
//only retry on main process
if (!tinker.isMainProcess()) {
TinkerLog.w(TAG, "onPatchRetryLoad retry is not main process, just return");
return;
}
if (!retryInfoFile.exists()) {
TinkerLog.w(TAG, "onPatchRetryLoad retry info not exist, just return");
return;
}
if (TinkerServiceInternals.isTinkerPatchServiceRunning(context)) {
TinkerLog.w(TAG, "onPatchRetryLoad tinker service is running, just return");
return;
}
//must use temp file
String path = tempPatchFile.getAbsolutePath();
if (path == null || !new File(path).exists()) {
TinkerLog.w(TAG, "onPatchRetryLoad patch file: %s is not exist, just return", path);
return;
}
TinkerLog.w(TAG, "onPatchRetryLoad patch file: %s is exist, retry to patch", path);
TinkerInstaller.onReceiveUpgradePatch(context, path);
SampleTinkerReport.onReportRetryPatch();
}
示例9: show_info
import com.tencent.tinker.lib.tinker.Tinker; //导入方法依赖的package包/类
public void show_info(View view) {
// add more Build Info
final StringBuilder sb = new StringBuilder();
Tinker tinker = Tinker.with(getApplicationContext());
if (tinker.isTinkerLoaded()) {
sb.append(String.format("[patch is loaded] \n"));
sb.append(String.format("[buildConfig TINKER_ID] %s \n", BuildInfo.TINKER_ID));
sb.append(String.format("[buildConfig BASE_TINKER_ID] %s \n", BaseBuildInfo.BASE_TINKER_ID));
sb.append(String.format("[buildConfig MESSSAGE] %s \n", BuildInfo.MESSAGE));
sb.append(String.format("[TINKER_ID] %s \n", tinker.getTinkerLoadResultIfPresent().getPackageConfigByName(ShareConstants.TINKER_ID)));
sb.append(String.format("[packageConfig patchMessage] %s \n", tinker.getTinkerLoadResultIfPresent().getPackageConfigByName("patchMessage")));
sb.append(String.format("[TINKER_ID Rom Space] %d k \n", tinker.getTinkerRomSpace()));
} else {
sb.append(String.format("[patch is not loaded] \n"));
sb.append(String.format("[buildConfig TINKER_ID] %s \n", BuildInfo.TINKER_ID));
sb.append(String.format("[buildConfig BASE_TINKER_ID] %s \n", BaseBuildInfo.BASE_TINKER_ID));
sb.append(String.format("[buildConfig MESSSAGE] %s \n", BuildInfo.MESSAGE));
sb.append(String.format("[TINKER_ID] %s \n", ShareTinkerInternals.getManifestTinkerID(getApplicationContext())));
}
sb.append(String.format("[BaseBuildInfo Message] %s \n", BaseBuildInfo.TEST_MESSAGE));
final TextView v = new TextView(this);
v.setText(sb);
v.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
v.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
v.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
v.setTextColor(0xFF000000);
v.setTypeface(Typeface.MONOSPACE);
final int padding = 16;
v.setPadding(padding, padding, padding, padding);
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(true);
builder.setView(v);
final AlertDialog alert = builder.create();
alert.show();
}
示例10: onPatchRetryLoad
import com.tencent.tinker.lib.tinker.Tinker; //导入方法依赖的package包/类
public boolean onPatchRetryLoad() {
if (!isRetryEnable) {
TinkerLog.w(TAG, "onPatchRetryLoad retry disabled, just return");
return false;
}
Tinker tinker = Tinker.with(context);
//only retry on main process
if (!tinker.isMainProcess()) {
TinkerLog.w(TAG, "onPatchRetryLoad retry is not main process, just return");
return false;
}
if (!retryInfoFile.exists()) {
TinkerLog.w(TAG, "onPatchRetryLoad retry info not exist, just return");
return false;
}
if (TinkerServiceInternals.isTinkerPatchServiceRunning(context)) {
TinkerLog.w(TAG, "onPatchRetryLoad tinker service is running, just return");
return false;
}
//must use temp file
String path = tempPatchFile.getAbsolutePath();
if (path == null || !new File(path).exists()) {
TinkerLog.w(TAG, "onPatchRetryLoad patch file: %s is not exist, just return", path);
return false;
}
TinkerLog.w(TAG, "onPatchRetryLoad patch file: %s is exist, retry to patch", path);
TinkerInstaller.onReceiveUpgradePatch(context, path);
return true;
}
示例11: loadArmLibrary
import com.tencent.tinker.lib.tinker.Tinker; //导入方法依赖的package包/类
/**
* you can use TinkerInstaller.loadLibrary replace your System.loadLibrary for auto update library!
* only support auto load lib/armeabi library from patch.
* for other library in lib/* or assets,
* you can load through {@code TinkerInstaller#loadLibraryFromTinker}
*/
public static void loadArmLibrary(Context context, String libName) {
if (libName == null || libName.isEmpty() || context == null) {
throw new TinkerRuntimeException("libName or context is null!");
}
Tinker tinker = Tinker.with(context);
if (tinker.isEnabledForNativeLib()) {
if (TinkerLoadLibrary.loadLibraryFromTinker(context, "lib/armeabi", libName)) {
return;
}
}
System.loadLibrary(libName);
}
示例12: initTinker
import com.tencent.tinker.lib.tinker.Tinker; //导入方法依赖的package包/类
private void initTinker(Context base) {
// tinker需要你开启MultiDex
MultiDex.install(base);
TinkerManager.setTinkerApplicationLike(this);
// 设置全局异常捕获
TinkerManager.initFastCrashProtect();
//开启升级重试功能(在安装Tinker之前设置)
TinkerManager.setUpgradeRetryEnable(true);
//设置Tinker日志输出类
TinkerInstaller.setLogIml(new MyLogImp());
//安装Tinker(在加载完multiDex之后,否则你需要将com.tencent.tinker.**手动放到main dex中)
TinkerManager.installTinker(this);
mTinker = Tinker.with(getApplication());
}
示例13: loadLibraryFromTinker
import com.tencent.tinker.lib.tinker.Tinker; //导入方法依赖的package包/类
/**
* sample usage for native library
*
* @param context
* @param relativePath such as lib/armeabi
* @param libName for the lib libTest.so, you can pass Test or libTest, or libTest.so
* @return boolean
* @throws UnsatisfiedLinkError
*/
public static boolean loadLibraryFromTinker(Context context, String relativePath, String libName) throws UnsatisfiedLinkError {
final Tinker tinker = Tinker.with(context);
libName = libName.startsWith("lib") ? libName : "lib" + libName;
libName = libName.endsWith(".so") ? libName : libName + ".so";
String relativeLibPath = relativePath + "/" + libName;
//TODO we should add cpu abi, and the real path later
if (tinker.isEnabledForNativeLib() && tinker.isTinkerLoaded()) {
TinkerLoadResult loadResult = tinker.getTinkerLoadResultIfPresent();
if (loadResult.libs != null) {
for (String name : loadResult.libs.keySet()) {
if (name.equals(relativeLibPath)) {
String patchLibraryPath = loadResult.libraryDirectory + "/" + name;
File library = new File(patchLibraryPath);
if (library.exists()) {
//whether we check md5 when load
boolean verifyMd5 = tinker.isTinkerLoadVerify();
if (verifyMd5 && !SharePatchFileUtil.verifyFileMd5(library, loadResult.libs.get(name))) {
tinker.getLoadReporter().onLoadFileMd5Mismatch(library, ShareConstants.TYPE_LIBRARY);
} else {
System.load(patchLibraryPath);
TinkerLog.i(TAG, "loadLibraryFromTinker success:" + patchLibraryPath);
return true;
}
}
}
}
}
}
return false;
}
示例14: patchDexExtractViaDexDiff
import com.tencent.tinker.lib.tinker.Tinker; //导入方法依赖的package包/类
private static boolean patchDexExtractViaDexDiff(Context context, String
patchVersionDirectory, String meta, File patchFile, boolean isUpgradePatch) {
String dir = patchVersionDirectory + "/" + ShareConstants.DEX_PATH + "/";
if (extractDexDiffInternals(context, dir, meta, patchFile, ShareTinkerInternals.isVmArt()
? 4 : 3, isUpgradePatch)) {
Tinker manager = Tinker.with(context);
File[] files = new File(dir).listFiles();
if (files != null) {
String optimizeDexDirectory = patchVersionDirectory + "/" + ShareConstants
.DEX_OPTIMIZE_PATH + "/";
File file = new File(optimizeDexDirectory);
if (!file.exists()) {
file.mkdirs();
}
int length = files.length;
int i = 0;
while (i < length) {
File file2 = files[i];
try {
String outputPathName = SharePatchFileUtil.optimizedPathFor(file2, file);
long start = System.currentTimeMillis();
DexFile.loadDex(file2.getAbsolutePath(), outputPathName, 0);
TinkerLog.i(TAG, "success dex optimize file, path: %s, use time: %d",
file2.getPath(), Long.valueOf(System.currentTimeMillis() - start));
i++;
} catch (Throwable e) {
TinkerLog.e(TAG, "dex optimize or load failed, path:" + file2.getPath(),
new Object[0]);
SharePatchFileUtil.safeDeleteFile(file2);
manager.getPatchReporter().onPatchDexOptFail(patchFile, file2,
optimizeDexDirectory, file2.getName(), e, isUpgradePatch);
return false;
}
}
}
return true;
}
TinkerLog.w(TAG, "patch recover, extractDiffInternals fail", new Object[0]);
return false;
}
示例15: onLoadFileNotFound
import com.tencent.tinker.lib.tinker.Tinker; //导入方法依赖的package包/类
/**
* 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);
}