Fix handling of "android.test.mock" in class loader context.
Mimick the way PackageManager handles it at runtime: do add it to class loader context for apps with targetSdkVersion < 30, but only if "android.test.runner" is used. Previously it was not added at all. Test: lunch aosp_cf_x86_phone-userdebug && m Bug: 132357300 Change-Id: I4c06635277ab13e21069b9fa0b46eb6a2547dfdd
This commit is contained in:
parent
24813e1d80
commit
46b3d5bd05
2 changed files with 8 additions and 3 deletions
|
@ -312,8 +312,7 @@ func genClassLoaderContext(ctx android.PathContext, global *GlobalConfig, module
|
|||
}
|
||||
|
||||
// Conditional class loader context for API version < 30.
|
||||
const testBase = "android.test.base"
|
||||
if !classLoaderContexts.addLibs(ctx, 30, module, testBase) {
|
||||
if !classLoaderContexts.addLibs(ctx, 30, module, OptionalCompatUsesLibs30...) {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -343,6 +342,9 @@ func fixConditionalClassLoaderContext(clcMap classLoaderContextMap) {
|
|||
for i, lib := range clc.Names {
|
||||
if android.InList(lib, usesLibs) {
|
||||
// skip compatibility libraries that are already included in unconditional context
|
||||
} else if lib == AndroidTestMock && !android.InList("android.test.runner", usesLibs) {
|
||||
// android.test.mock is only needed as a compatibility library (in conditional class
|
||||
// loader context) if android.test.runner is used, otherwise skip it
|
||||
} else {
|
||||
clcMap[sdkVer].addLib(lib, clc.Host[i], clc.Target[i])
|
||||
}
|
||||
|
|
|
@ -2838,6 +2838,7 @@ func TestUsesLibraries(t *testing.T) {
|
|||
}
|
||||
|
||||
// Test conditional context for target SDK version 30.
|
||||
// "android.test.mock" is absent because "android.test.runner" is not used.
|
||||
if w := `--target-classpath-for-sdk 30` +
|
||||
` /system/framework/android.test.base.jar `; !strings.Contains(cmd, w) {
|
||||
t.Errorf("wanted %q in %q", w, cmd)
|
||||
|
@ -2852,8 +2853,10 @@ func TestUsesLibraries(t *testing.T) {
|
|||
}
|
||||
|
||||
// Test conditional context for target SDK version 30.
|
||||
// "android.test.mock" is present because "android.test.runner" is used.
|
||||
if w := `--target-classpath-for-sdk 30` +
|
||||
` /system/framework/android.test.base.jar `; !strings.Contains(cmd, w) {
|
||||
` /system/framework/android.test.base.jar` +
|
||||
`:/system/framework/android.test.mock.jar `; !strings.Contains(cmd, w) {
|
||||
t.Errorf("wanted %q in %q", w, cmd)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue