use of com.tencent.tinker.loader.TinkerRuntimeException in project tinker by Tencent.
the class TinkerLoadLibrary method loadArmV7Library.
/**
* you can use TinkerInstaller.loadArmV7Library replace your System.loadLibrary for auto update library!
* only support auto load lib/armeabi-v7a library from patch.
* for other library in lib/* or assets,
* you can load through {@code TinkerInstaller#loadLibraryFromTinker}
*/
public static void loadArmV7Library(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-v7a", libName)) {
return;
}
}
System.loadLibrary(libName);
}
use of com.tencent.tinker.loader.TinkerRuntimeException in project tinker by Tencent.
the class ShareSecurityCheck method init.
@SuppressLint("PackageManagerGetSignatures")
private void init(Context context) {
ByteArrayInputStream stream = null;
try {
PackageManager pm = context.getPackageManager();
String packageName = context.getPackageName();
PackageInfo packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
mPublicKeyMd5 = SharePatchFileUtil.getMD5(packageInfo.signatures[0].toByteArray());
if (mPublicKeyMd5 == null) {
throw new TinkerRuntimeException("get public key md5 is null");
}
} catch (Exception e) {
throw new TinkerRuntimeException("ShareSecurityCheck init public key fail", e);
} finally {
SharePatchFileUtil.closeQuietly(stream);
}
}
use of com.tencent.tinker.loader.TinkerRuntimeException in project tinker by Tencent.
the class ShareTinkerInternals method cleanPatch.
public static void cleanPatch(Application app) {
if (app == null) {
throw new TinkerRuntimeException("app is null");
}
final File tinkerDir = SharePatchFileUtil.getPatchDirectory(app);
if (!tinkerDir.exists()) {
ShareTinkerLog.printErrStackTrace(TAG, new Throwable(), "try to clean patch while there're not any applied patches.");
return;
}
final File patchInfoFile = SharePatchFileUtil.getPatchInfoFile(tinkerDir.getAbsolutePath());
if (!patchInfoFile.exists()) {
ShareTinkerLog.printErrStackTrace(TAG, new Throwable(), "try to clean patch while patch info file does not exist.");
return;
}
final File patchInfoLockFile = SharePatchFileUtil.getPatchInfoLockFile(tinkerDir.getAbsolutePath());
final SharePatchInfo patchInfo = SharePatchInfo.readAndCheckPropertyWithLock(patchInfoFile, patchInfoLockFile);
if (patchInfo != null) {
patchInfo.isRemoveNewVersion = true;
SharePatchInfo.rewritePatchInfoFileWithLock(patchInfoFile, patchInfo, patchInfoLockFile);
}
}
use of com.tencent.tinker.loader.TinkerRuntimeException in project tinker by Tencent.
the class TinkerApplication method createInlineFence.
private Handler createInlineFence(Application app, int tinkerFlags, String delegateClassName, boolean tinkerLoadVerifyFlag, long applicationStartElapsedTime, long applicationStartMillisTime, Intent resultIntent) {
try {
// Use reflection to create the delegate so it doesn't need to go into the primary dex.
// And we can also patch it
final Class<?> delegateClass = Class.forName(delegateClassName, false, mCurrentClassLoader);
final Constructor<?> constructor = delegateClass.getConstructor(Application.class, int.class, boolean.class, long.class, long.class, Intent.class);
final Object appLike = constructor.newInstance(app, tinkerFlags, tinkerLoadVerifyFlag, applicationStartElapsedTime, applicationStartMillisTime, resultIntent);
final Class<?> inlineFenceClass = Class.forName("com.tencent.tinker.entry.TinkerApplicationInlineFence", false, mCurrentClassLoader);
final Class<?> appLikeClass = Class.forName("com.tencent.tinker.entry.ApplicationLike", false, mCurrentClassLoader);
final Constructor<?> inlineFenceCtor = inlineFenceClass.getConstructor(appLikeClass);
inlineFenceCtor.setAccessible(true);
return (Handler) inlineFenceCtor.newInstance(appLike);
} catch (Throwable thr) {
throw new TinkerRuntimeException("createInlineFence failed", thr);
}
}
use of com.tencent.tinker.loader.TinkerRuntimeException in project tinker by Tencent.
the class SharePatchFileUtil method optimizedPathFor.
/**
* change the jar file path as the makeDexElements do
* Android O change its path
*
* @param path
* @param optimizedDirectory
* @return
*/
public static String optimizedPathFor(File path, File optimizedDirectory) {
if (ShareTinkerInternals.isAfterAndroidO()) {
// dex_location = /foo/bar/baz.jar
// odex_location = /foo/bar/oat/<isa>/baz.odex
String currentInstructionSet;
try {
currentInstructionSet = ShareTinkerInternals.getCurrentInstructionSet();
} catch (Exception e) {
throw new TinkerRuntimeException("getCurrentInstructionSet fail:", e);
}
File parentFile = path.getParentFile();
String fileName = path.getName();
int index = fileName.lastIndexOf('.');
if (index > 0) {
fileName = fileName.substring(0, index);
}
String result = parentFile.getAbsolutePath() + "/oat/" + currentInstructionSet + "/" + fileName + ShareConstants.ODEX_SUFFIX;
return result;
}
String fileName = path.getName();
if (!fileName.endsWith(ShareConstants.DEX_SUFFIX)) {
int lastDot = fileName.lastIndexOf(".");
if (lastDot < 0) {
fileName += ShareConstants.DEX_SUFFIX;
} else {
StringBuilder sb = new StringBuilder(lastDot + 4);
sb.append(fileName, 0, lastDot);
sb.append(ShareConstants.DEX_SUFFIX);
fileName = sb.toString();
}
}
File result = new File(optimizedDirectory, fileName);
return result.getPath();
}
Aggregations