Search in sources :

Example 1 with MethodDiffInfo

use of com.taobao.android.object.MethodDiffInfo in project atlas by alibaba.

the class AndFixFilterImpl method filterClass.

@Override
public boolean filterClass(ClassDiffInfo classDiffInfo) throws PatchException {
    boolean isInnerclass = false;
    DexBackedClassDef dexBackedClassDef = classDiffInfo.getClassDef();
    if (classDiffInfo.getType().equals(DiffType.ADD)) {
        return false;
    //            if (dexBackedClassDef.getAnnotations().size() > 0) {
    //                Set<? extends Annotation> annotations = dexBackedClassDef.getAnnotations();
    //                for (Annotation dexBackedAnnotation : annotations) {
    //                    if (dexBackedAnnotation.getType().equals("dalvik/annotation/EnclosingClass;"))
    //                        throw new PatchException("can't add member class:" + dexBackedClassDef.getType());
    //                }
    //            }
    //            String className = DexDiffer.getDalvikClassName(dexBackedClassDef.getType());
    //            MappingParser mappingParser = new MappingParser(APatchTool.mappingFile);
    //            String outterClassName = mappingParser.getOuterClass(className);
    //            if (!className.equals(outterClassName)) {
    //                isInnerclass = true;
    //                if (SmaliDiffUtils.diff(diffInfo, outterClassName, className, outFile)) {
    //                    classDiffInfo.setType(DiffType.NONE);
    //                    return true;
    //                } else {
    //                    throw new PatchException("can't add anonymous class;" + dexBackedClassDef.getType());
    //                }
    //            }
    //            throw new PatchException("can't add class:" + dexBackedClassDef.getType());
    } else if (classDiffInfo.getType().equals(DiffType.MODIFY)) {
        if (classDiffInfo.getName().endsWith(".R") || classDiffInfo.getName().contains(".R$")) {
            return true;
        }
        Set<MethodDiffInfo> needFilterMethod = new HashSet<MethodDiffInfo>();
        Set<FieldDiffInfo> needFilterField = new HashSet<FieldDiffInfo>();
        if (classDiffInfo.getModifyMethods().size() > 0) {
            for (MethodDiffInfo methodDiffInfo : classDiffInfo.getModifyMethods()) {
                if (filterMethod(methodDiffInfo)) {
                    System.out.println(methodDiffInfo.getBackedMethod().getDefiningClass() + ":" + methodDiffInfo.getBackedMethod().getName() + " is filtered!");
                    needFilterMethod.add(methodDiffInfo);
                }
            }
        }
        classDiffInfo.getModifyMethods().removeAll(needFilterMethod);
        if (classDiffInfo.getModifyFields().size() > 0) {
            for (FieldDiffInfo fieldDiffInfo : classDiffInfo.getModifyFields()) {
                if (filterField(fieldDiffInfo)) {
                    needFilterField.add(fieldDiffInfo);
                }
            }
        }
        classDiffInfo.getModifyFields().removeAll(needFilterField);
        if (classDiffInfo.getModifyFields().size() == 0 && classDiffInfo.getModifyMethods().size() == 0) {
            classDiffInfo.setType(DiffType.NONE);
            return true;
        }
    }
    return false;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) FieldDiffInfo(com.taobao.android.object.FieldDiffInfo) MethodDiffInfo(com.taobao.android.object.MethodDiffInfo) DexBackedClassDef(org.jf.dexlib2.dexbacked.DexBackedClassDef)

Aggregations

FieldDiffInfo (com.taobao.android.object.FieldDiffInfo)1 MethodDiffInfo (com.taobao.android.object.MethodDiffInfo)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 DexBackedClassDef (org.jf.dexlib2.dexbacked.DexBackedClassDef)1