Search in sources :

Example 21 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);
        CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
        stream = new ByteArrayInputStream(packageInfo.signatures[0].toByteArray());
        X509Certificate cert = (X509Certificate) certFactory.generateCertificate(stream);
        mPublicKey = cert.getPublicKey();
    } 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) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) IOException(java.io.IOException) TinkerRuntimeException(com.tencent.tinker.loader.TinkerRuntimeException) SuppressLint(android.annotation.SuppressLint)

Aggregations

TinkerRuntimeException (com.tencent.tinker.loader.TinkerRuntimeException)21 File (java.io.File)9 Tinker (com.tencent.tinker.lib.tinker.Tinker)8 Intent (android.content.Intent)6 ZipFile (java.util.zip.ZipFile)5 IOException (java.io.IOException)4 ZipEntry (java.util.zip.ZipEntry)4 ApplicationInfo (android.content.pm.ApplicationInfo)3 InputStream (java.io.InputStream)3 TinkerZipEntry (com.tencent.tinker.commons.ziputil.TinkerZipEntry)2 TinkerZipFile (com.tencent.tinker.commons.ziputil.TinkerZipFile)2 ShareResPatchInfo (com.tencent.tinker.loader.shareutil.ShareResPatchInfo)2 DexFile (dalvik.system.DexFile)2 BufferedOutputStream (java.io.BufferedOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 X509Certificate (java.security.cert.X509Certificate)2 ArrayList (java.util.ArrayList)2 SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 PackageInfo (android.content.pm.PackageInfo)1