当前位置:网站首页>[andoid][step pit]cts 11_ Testbootclasspathandsystemserverclasspath at the beginning of R3_ Analysis of nonduplicateclasses fail

[andoid][step pit]cts 11_ Testbootclasspathandsystemserverclasspath at the beginning of R3_ Analysis of nonduplicateclasses fail

2022-06-13 01:31:00 Ryan ZHENG

[Andoid][ Step on the pit ]CTS 11_r3 The beginning of testBootClassPathAndSystemServerClasspath_nonDuplicateClasses FAIL Problem analysis

The problem background

from CTS The test results can be clearly seen leading to FAIL Class ; I added this class myself , In order to be in Installd And system_server Between registered callbacks ;
Due to the tight schedule of the project , The project that initially reported the problem adopted the method of code fallback , Guarantee CTS The test results are normal ;
In passing nearly 2 Days of analysis , Gradually clarify the cause of the problem and the solution , It is summarized as follows :

Cause of the problem

According to the problem description , Use CTS 11_r3 During the test FAIL, While using 11_r2 The result of the test is PASS;
The test instruction is :

run cts -m  CtsStrictJavaPackagesTestCases -t android.compat.sjp.cts.StrictJavaPackagesTest#testBootClassPathAndSystemServerClasspath_nonDuplicateClasses

Check the code according to , The logic and purpose of the test item are as follows :

  1. Get environment variables BOOTCLASSPATH And SYSTEMSERVERCLASSPATH Value ;
  2. take BOOTCLASSPATH And SYSTEMSERVERCLASSPATH The value of corresponds to jar Pull the package to the host ;
  3. Use dexlib2 For these jar The package is decompiled , Get one of them dex file ;
  4. be based on dex File to get the classes contained in it ;
  5. Double check all classes ;
  6. The duplicate classes are filtered in the white list ;
  7. Finally, record the list of all duplicate classes by comparison , If it's not empty , Then test FAIL, whereas PASS;

It is not difficult to see from logic , This is a Google Want to protect system_server And framework Does not contain a means of repeating classes ;

But why 11_r2 Sure PASS, here we are 11_r3 Not anymore ?
According to the comparison of baseline code and AOSP After the latest code, you can find ;
Google stay 18-Nov-2020 The test item has been updated once , There are two main areas for improvement :

  1. Increase the number of classes in the whitelist ;
  2. modify getDuplicateClasses Method implementation , To support the multi-dex Of jar package ;

thus it can be seen ,11_r2 Sure PASS It is completely drilled the loophole of the test item , Because we added ICallback Just packed into a non first classes.dex It's in ; And in the 11_r3 Chinese vs multi-dex Supported , This problem was exposed ;

But here's a line ,Google I also know my own IInstalld It's also FAIL Of , So I updated my white list IInstalld Exclude , This operation can only be said to be admiration …

Problem solving ideas

Okay , No matter Google How about this manual operation , We are always trying to solve this problem . But after further analysis, it is found that , This problem is more troublesome than I thought .

The picture below is AOSP Original design structure , You can see :installd_aidl This filegroup Be separated by services And framework Two modules are imported 、 Compile the ;

 The original architecture

And the one I added to register callbacks AIDL file ( Let's call it ICallback.aidl, The same below ), Needed ICallback.aidl It is also added here :

filegroup {
    
    name: "installd_aidl",
    srcs: [
        "binder/android/os/IInstalld.aidl",
        "binder/android/os/storage/CrateMetadata.aidl",
        "binder/android/os/ICallback.aidl", //Added
    ],
    path: "binder",
}

Which leads to ICallback And its inner classes and IInstalld equally , Has been compiled twice , They have entered services.jar And framework.jar It's in ;

Come here , The solution should be clear :

Give Way ICallback Compile into only framework.jar, Instead of compiling into services.jar in ;

Solution steps

  1. First, we need to ICallback from installd_aidl This filegroup Split in , And control it separately ; meanwhile , We need to define the rules to put this ICallback export , Make globally visible :
filegroup {
    
    name: "installd_aidl_ext",
    srcs: [
        "binder/android/os/ICallback.aidl",
    ],
    path: "binder",
    visibility: ["//visibility:public"],
}

cc_defaults {
    
    name: "installd_aidl_ext_cc_defaults",
    aidl: {
    
        //Note, this path should vary according to current location
        include_dirs: ["xxx( Current directory )/binder/"],
        export_aidl_headers: true,
    },
    export_include_dirs : ["."],
    srcs: [
        ":installd_aidl_ext",
    ],
}

java_defaults {
    
    name: "installd_aidl_ext_java_defaults",
    aidl: {
    
        //Note, this path should vary according to current location
        include_dirs: ["xxx( Current directory )/binder/"],
    },
}

  1. And then in installd In the Compilation Rules of :
cc_defaults {
    
    name: "installd_defaults",
    defaults: ["installd_aidl_ext_cc_defaults"],//Added
    ...
        srcs: [
        ...
        "InstalldNativeService.cpp",
        ...
        ":installd_aidl",
    ],
    ...
}
  1. and frameworks/base The next is the most troublesome , Based on the principle of minimum change , I combine the above structure diagram , Decided to framework-non-updatable-sources Of filegroup in ( With the original :installd_aidl Put together ):
filegroup {
    
    name: "framework-non-updatable-sources",
    srcs: [
        ...
        ":installd_aidl",
        ...
        ":installd_aidl_ext",//Added
    ],
}
  1. At the same time, it is necessary to make services Compiling installd_aidl From time to tome ICallback This class can reference , stay services.core.unboosted Add :
java_library_static {
    
    name: "services.core.unboosted",
    defaults: ["installd_aidl_ext_java_defaults"],//Added
    srcs: [
        ...
        ":installd_aidl",
        ...
    ],
    ...
}
  1. Replace after compilation system.img To test CTS FAIL term , result PASS;

The structure diagram after modification is as follows :( In fact, it's just a separate one installd_aidl_ext)

 Modified structure

Postscript

The above is only the final result , The frustrations of the middle exploration have not been mentioned ;
The whole process is the most difficult 、 It is also the place that impressed me most , is “ How to let aidl analysis AIDL File can be found ICallback, But don't compile it into services”
And I can finally determine the above plan , To a large extent, it depends on here The means mentioned : By locating the compiled parameters , And then turn it upside down Android.bp Supported options , To use minimal changes , Solve this problem ;

原网站

版权声明
本文为[Ryan ZHENG]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/164/202206130125211995.html