Search in sources :

Example 26 with TinkerRuntimeException

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);
}
Also used : TinkerRuntimeException(com.tencent.tinker.loader.TinkerRuntimeException) Tinker(com.tencent.tinker.lib.tinker.Tinker)

Example 27 with TinkerRuntimeException

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);
    }
}
Also used : TinkerRuntimeException(com.tencent.tinker.loader.TinkerRuntimeException) PackageManager(android.content.pm.PackageManager) ByteArrayInputStream(java.io.ByteArrayInputStream) PackageInfo(android.content.pm.PackageInfo) IOException(java.io.IOException) TinkerRuntimeException(com.tencent.tinker.loader.TinkerRuntimeException) SuppressLint(android.annotation.SuppressLint)

Example 28 with TinkerRuntimeException

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);
    }
}
Also used : TinkerRuntimeException(com.tencent.tinker.loader.TinkerRuntimeException) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 29 with TinkerRuntimeException

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);
    }
}
Also used : TinkerRuntimeException(com.tencent.tinker.loader.TinkerRuntimeException) TinkerUncaughtHandler(com.tencent.tinker.loader.TinkerUncaughtHandler) Handler(android.os.Handler)

Example 30 with TinkerRuntimeException

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();
}
Also used : TinkerRuntimeException(com.tencent.tinker.loader.TinkerRuntimeException) JarFile(java.util.jar.JarFile) File(java.io.File) ZipFile(java.util.zip.ZipFile) IOException(java.io.IOException) TinkerRuntimeException(com.tencent.tinker.loader.TinkerRuntimeException) SuppressLint(android.annotation.SuppressLint)

Aggregations

TinkerRuntimeException (com.tencent.tinker.loader.TinkerRuntimeException)31 File (java.io.File)14 Tinker (com.tencent.tinker.lib.tinker.Tinker)10 ZipFile (java.util.zip.ZipFile)9 IOException (java.io.IOException)7 Intent (android.content.Intent)6 ZipEntry (java.util.zip.ZipEntry)5 ApplicationInfo (android.content.pm.ApplicationInfo)3 InputStream (java.io.InputStream)3 SuppressLint (android.annotation.SuppressLint)2 ShareElfFile (com.tencent.tinker.loader.shareutil.ShareElfFile)2 ShareResPatchInfo (com.tencent.tinker.loader.shareutil.ShareResPatchInfo)2 TinkerZipEntry (com.tencent.tinker.ziputils.ziputil.TinkerZipEntry)2 TinkerZipFile (com.tencent.tinker.ziputils.ziputil.TinkerZipFile)2 BufferedOutputStream (java.io.BufferedOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 Field (java.lang.reflect.Field)2 ArrayList (java.util.ArrayList)2 JarFile (java.util.jar.JarFile)2 Instrumentation (android.app.Instrumentation)1