Expose "full" dexpreopt.config

1. Instead of 'slim' config, use full config even for libs
2. Define moduleJSONConfig for fields which cannot be converted to JSON
field directly(Path type field, ProfileBootListing,
DexPreoptImagesDeps are added in this CL) and exclude fields which is
convertible(DexPreoptImageLocations)

Bug: 158843648
Test: m dist
Change-Id: I3f9192ab5292bd079be1b686bb3b25735a836cbc
diff --git a/java/dexpreopt.go b/java/dexpreopt.go
index 3571590..d00d74b 100644
--- a/java/dexpreopt.go
+++ b/java/dexpreopt.go
@@ -41,9 +41,12 @@
 
 	builtInstalled string
 
-	// A path to a dexpreopt.config file generated by Soong for libraries that may be used as a
-	// <uses-library> by Make modules. The path is passed to Make via LOCAL_SOONG_DEXPREOPT_CONFIG
-	// variable. If the path is nil, no config is generated (which is the case for apps and tests).
+	// The config is used for two purposes:
+	// - Passing dexpreopt information about libraries from Soong to Make. This is needed when
+	//   a <uses-library> is defined in Android.bp, but used in Android.mk (see dex_preopt_config_merger.py).
+	//   Note that dexpreopt.config might be needed even if dexpreopt is disabled for the library itself.
+	// - Dexpreopt post-processing (using dexpreopt artifacts from a prebuilt system image to incrementally
+	//   dexpreopt another partition).
 	configPath android.WritablePath
 }
 
@@ -138,27 +141,13 @@
 		}
 	}
 
-	if !d.isApp && !d.isTest {
-		// Slim dexpreopt config is serialized to dexpreopt.config files and used by
-		// dex_preopt_config_merger.py to get information about <uses-library> dependencies.
-		// Note that it might be needed even if dexpreopt is disabled for this module.
-		slimDexpreoptConfig := &dexpreopt.ModuleConfig{
-			Name:                 ctx.ModuleName(),
-			DexLocation:          dexLocation,
-			EnforceUsesLibraries: d.enforceUsesLibs,
-			ProvidesUsesLibrary:  providesUsesLib,
-			ClassLoaderContexts:  d.classLoaderContexts,
-			// The rest of the fields are not needed.
-		}
-		d.configPath = android.PathForModuleOut(ctx, "dexpreopt", "dexpreopt.config")
-		dexpreopt.WriteSlimModuleConfigForMake(ctx, slimDexpreoptConfig, d.configPath)
-	}
-
-	if d.dexpreoptDisabled(ctx) {
+	// If it is neither app nor test, make config files regardless of its dexpreopt setting.
+	// The config files are required for apps defined in make which depend on the lib.
+	// TODO(b/158843648): The config for apps should be generated as well regardless of setting.
+	if (d.isApp || d.isTest) && d.dexpreoptDisabled(ctx) {
 		return
 	}
 
-	globalSoong := dexpreopt.GetGlobalSoongConfig(ctx)
 	global := dexpreopt.GetGlobalConfig(ctx)
 
 	isSystemServerJar := inList(ctx.ModuleName(), global.SystemServerJars)
@@ -251,6 +240,15 @@
 		PresignedPrebuilt: d.isPresignedPrebuilt,
 	}
 
+	d.configPath = android.PathForModuleOut(ctx, "dexpreopt", "dexpreopt.config")
+	dexpreopt.WriteModuleConfig(ctx, dexpreoptConfig, d.configPath)
+
+	if d.dexpreoptDisabled(ctx) {
+		return
+	}
+
+	globalSoong := dexpreopt.GetGlobalSoongConfig(ctx)
+
 	dexpreoptRule, err := dexpreopt.GenerateDexpreoptRule(ctx, globalSoong, global, dexpreoptConfig)
 	if err != nil {
 		ctx.ModuleErrorf("error generating dexpreopt rule: %s", err.Error())