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
diff --git a/dexpreopt/dexpreopt.go b/dexpreopt/dexpreopt.go
index 903677f..3605d9d 100644
--- a/dexpreopt/dexpreopt.go
+++ b/dexpreopt/dexpreopt.go
@@ -312,8 +312,7 @@
 		}
 
 		// 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 @@
 		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])
 			}