From 91f015e73e6260b10f055972dd9f6bca9ca30f9d Mon Sep 17 00:00:00 2001 From: Ulya Trafimovich Date: Wed, 27 Apr 2022 17:51:49 +0100 Subject: [PATCH] Correctly serialize class loader context for "any" SDK version to JSON. Previously "any" was serialized as its numeric value, 10000. But other code in makefiles and scripts expects string "any", and dexpreopt.config files generated by Make (for Android.mk modules) have "any" not 10000. Bug: 214255490 Test: lunch aosp_cf_x86_64_phone-userdebug && m && launch_cvd \ && adb wait-for-device && adb root \ && adb logcat | grep -E 'ClassLoaderContext [a-z ]+ mismatch' # empty output, no errors at boot Change-Id: Id5e80eb8a90d9786b5cb999c172aaecb44952f76 --- dexpreopt/class_loader_context.go | 3 +++ dexpreopt/class_loader_context_test.go | 32 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/dexpreopt/class_loader_context.go b/dexpreopt/class_loader_context.go index 36513b64b..d0a6a39df 100644 --- a/dexpreopt/class_loader_context.go +++ b/dexpreopt/class_loader_context.go @@ -678,6 +678,9 @@ func toJsonClassLoaderContext(clcMap ClassLoaderContextMap) jsonClassLoaderConte jClcMap := make(jsonClassLoaderContextMap) for sdkVer, clcs := range clcMap { sdkVerStr := fmt.Sprintf("%d", sdkVer) + if sdkVer == AnySdkVersion { + sdkVerStr = "any" + } jClcMap[sdkVerStr] = toJsonClassLoaderContextRec(clcs) } return jClcMap diff --git a/dexpreopt/class_loader_context_test.go b/dexpreopt/class_loader_context_test.go index 5d3a9d943..614681f50 100644 --- a/dexpreopt/class_loader_context_test.go +++ b/dexpreopt/class_loader_context_test.go @@ -389,6 +389,38 @@ func TestCLCMExcludeLibs(t *testing.T) { }) } +// Test that CLC is correctly serialized to JSON. +func TestCLCtoJSON(t *testing.T) { + ctx := testContext() + optional := false + implicit := true + m := make(ClassLoaderContextMap) + m.AddContext(ctx, 28, "a", optional, implicit, buildPath(ctx, "a"), installPath(ctx, "a"), nil) + m.AddContext(ctx, AnySdkVersion, "b", optional, implicit, buildPath(ctx, "b"), installPath(ctx, "b"), nil) + android.AssertStringEquals(t, "output CLCM ", `{ + "28": [ + { + "Name": "a", + "Optional": false, + "Implicit": true, + "Host": "out/soong/a.jar", + "Device": "/system/a.jar", + "Subcontexts": [] + } + ], + "any": [ + { + "Name": "b", + "Optional": false, + "Implicit": true, + "Host": "out/soong/b.jar", + "Device": "/system/b.jar", + "Subcontexts": [] + } + ] +}`, m.Dump()) +} + func checkError(t *testing.T, have error, want string) { if have == nil { t.Errorf("\nwant error: '%s'\nhave: none", want)