Search in sources :

Example 1 with ShareElfFile

use of com.tencent.tinker.loader.shareutil.ShareElfFile in project tinker by Tencent.

the class DexDiffPatchInternal method waitAndCheckDexOptFile.

protected static boolean waitAndCheckDexOptFile(File patchFile, Tinker manager) {
    if (optFiles.isEmpty()) {
        return true;
    }
    // should use patch list size
    int size = patchList.size() * 30;
    if (size > MAX_WAIT_COUNT) {
        size = MAX_WAIT_COUNT;
    }
    ShareTinkerLog.i(TAG, "raw dex count: %d, dex opt dex count: %d, final wait times: %d", patchList.size(), optFiles.size(), size);
    for (int i = 0; i < size; i++) {
        if (!checkAllDexOptFile(optFiles, i + 1)) {
            try {
                Thread.sleep(WAIT_ASYN_OAT_TIME);
            } catch (InterruptedException e) {
                ShareTinkerLog.e(TAG, "thread sleep InterruptedException e:" + e);
            }
        }
    }
    List<File> failDexFiles = new ArrayList<>();
    // check again, if still can't be found, just return
    for (File file : optFiles) {
        ShareTinkerLog.i(TAG, "check dex optimizer file exist: %s, size %d", file.getPath(), file.length());
        if (!SharePatchFileUtil.isLegalFile(file) && !SharePatchFileUtil.shouldAcceptEvenIfIllegal(file)) {
            ShareTinkerLog.e(TAG, "final parallel dex optimizer file %s is not exist, return false", file.getName());
            failDexFiles.add(file);
        }
    }
    if (!failDexFiles.isEmpty()) {
        manager.getPatchReporter().onPatchDexOptFail(patchFile, failDexFiles, new TinkerRuntimeException(ShareConstants.CHECK_DEX_OAT_EXIST_FAIL));
        return false;
    }
    if (Build.VERSION.SDK_INT >= 21) {
        Throwable lastThrowable = null;
        for (File file : optFiles) {
            if (SharePatchFileUtil.shouldAcceptEvenIfIllegal(file)) {
                continue;
            }
            ShareTinkerLog.i(TAG, "check dex optimizer file format: %s, size %d", file.getName(), file.length());
            int returnType;
            try {
                returnType = ShareElfFile.getFileTypeByMagic(file);
            } catch (IOException e) {
                // read error just continue
                continue;
            }
            if (returnType == ShareElfFile.FILE_TYPE_ELF) {
                ShareElfFile elfFile = null;
                try {
                    elfFile = new ShareElfFile(file);
                } catch (Throwable e) {
                    ShareTinkerLog.e(TAG, "final parallel dex optimizer file %s is not elf format, return false", file.getName());
                    failDexFiles.add(file);
                    lastThrowable = e;
                } finally {
                    IOHelper.closeQuietly(elfFile);
                }
            }
        }
        if (!failDexFiles.isEmpty()) {
            Throwable returnThrowable = lastThrowable == null ? new TinkerRuntimeException(ShareConstants.CHECK_DEX_OAT_FORMAT_FAIL) : new TinkerRuntimeException(ShareConstants.CHECK_DEX_OAT_FORMAT_FAIL, lastThrowable);
            manager.getPatchReporter().onPatchDexOptFail(patchFile, failDexFiles, returnThrowable);
            return false;
        }
    }
    return true;
}
Also used : TinkerRuntimeException(com.tencent.tinker.loader.TinkerRuntimeException) ShareElfFile(com.tencent.tinker.loader.shareutil.ShareElfFile) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) ShareElfFile(com.tencent.tinker.loader.shareutil.ShareElfFile) File(java.io.File)

Aggregations

TinkerRuntimeException (com.tencent.tinker.loader.TinkerRuntimeException)1 ShareElfFile (com.tencent.tinker.loader.shareutil.ShareElfFile)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ZipFile (java.util.zip.ZipFile)1