Revert "Ensure sscp jars get copied to $OUT/soong/system_server_dexjars"

This reverts commit 0b7089f13420061c8f1732fe6e2e56f1e9cdb21e.

Reason for revert: Breaks auto builds https://groups.google.com/a/google.com/g/android-build-police/c/DfXeyxkyfYk/m/4SvZa-jkAAAJ

Change-Id: Ia6ebdf64d03284d2318978c35cb87fd4f0b79531
diff --git a/apex/apex_test.go b/apex/apex_test.go
index b58441a..7e67c0f 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -11537,17 +11537,6 @@
 		android.AssertStringMatches(t, "Could not find the correct boot dex jar in monolithic hiddenapi flags generation command", monolithicHiddenapiFlagsCmd, "--boot-dex="+expectedBootJar)
 	}
 
-	// Check that system server jars is copied to out/soong/system_server_dexjars. This hardcoded location is used by dexpreopt
-	checkSystemServerJarOnHost := func(t *testing.T, ctx *android.TestContext, m, libName, expectedSystemServerJarPath string) {
-		variation := "android_common_com.android.foo"
-		if m == "com.android.foo" {
-			m = libName // for source builds, the cp rule is still generated by the java_library module
-			variation = "android_common_apex10000"
-		}
-		output := ctx.ModuleForTests(m, variation).MaybeOutput("system_server_dexjars/" + libName + ".jar")
-		android.AssertStringListContains(t, libName+" is expected to be copied to out/soong/system_server_dexjars/ from ", output.Implicits.Strings(), expectedSystemServerJarPath)
-	}
-
 	bp := `
 		// Source APEX.
 
@@ -11571,24 +11560,6 @@
 			},
 		}
 
-		java_library {
-			name: "service-foo",
-			srcs: ["foo.java"],
-			installable: true,
-			apex_available: [
-				"com.android.foo",
-			],
-		}
-
-		systemserverclasspath_fragment {
-			name: "foo-systemserverclasspath-fragment",
-			contents: ["service-foo"],
-			apex_available: [
-				"com.android.foo",
-			],
-		}
-
-
 		apex_key {
 			name: "com.android.foo.key",
 			public_key: "com.android.foo.avbpubkey",
@@ -11599,16 +11570,18 @@
 			name: "com.android.foo",
 			key: "com.android.foo.key",
 			bootclasspath_fragments: ["foo-bootclasspath-fragment"],
-			systemserverclasspath_fragments: ["foo-systemserverclasspath-fragment"],
 			updatable: false,
 		}
 
 		// Prebuilt APEX.
 
-		java_import {
+		java_sdk_library_import {
 			name: "framework-foo",
-			jars: ["foo.jar"],
+			public: {
+				jars: ["foo.jar"],
+			},
 			apex_available: ["com.android.foo"],
+			shared_library: false,
 		}
 
 		prebuilt_bootclasspath_fragment {
@@ -11626,27 +11599,11 @@
 			],
 		}
 
-		java_import {
-			name: "service-foo",
-			jars: ["foo.jar"],
-			apex_available: ["com.android.foo"],
-		}
-
-		prebuilt_systemserverclasspath_fragment {
-			name: "foo-systemserverclasspath-fragment",
-			contents: ["service-foo"],
-			apex_available: [
-				"com.android.foo",
-			],
-		}
-
-
 		prebuilt_apex {
 			name: "com.android.foo",
 			apex_name: "com.android.foo",
 			src: "com.android.foo-arm.apex",
 			exported_bootclasspath_fragments: ["foo-bootclasspath-fragment"],
-			exported_systemserverclasspath_fragments: ["foo-systemserverclasspath-fragment"],
 		}
 
 		// Another Prebuilt ART APEX
@@ -11655,41 +11612,48 @@
 			apex_name: "com.android.foo", // Used to determine the API domain
 			src: "com.android.foo-arm.apex",
 			exported_bootclasspath_fragments: ["foo-bootclasspath-fragment"],
-			exported_systemserverclasspath_fragments: ["foo-systemserverclasspath-fragment"],
 		}
 
 		// APEX contribution modules
 
 		apex_contributions {
-			name: "foo.contributions",
+			name: "foo.source.contributions",
 			api_domain: "com.android.foo",
-			contents: ["%v"],
+			contents: ["com.android.foo"],
+		}
+
+		apex_contributions {
+			name: "foo.prebuilt.contributions",
+			api_domain: "com.android.foo",
+			contents: ["prebuilt_com.android.foo"],
+		}
+
+		apex_contributions {
+			name: "foo.prebuilt.v2.contributions",
+			api_domain: "com.android.foo",
+			contents: ["com.android.foo.v2"], // prebuilt_ prefix is missing because of prebuilt_rename mutator
 		}
 	`
 
 	testCases := []struct {
-		desc                    string
-		selectedApex            string
-		expectedBootJar         string
-		expectedSystemServerJar string
+		desc                      string
+		selectedApexContributions string
+		expectedBootJar           string
 	}{
 		{
-			desc:                    "Source apex com.android.foo is selected, bootjar should come from source java library",
-			selectedApex:            "com.android.foo",
-			expectedBootJar:         "out/soong/.intermediates/foo-bootclasspath-fragment/android_common_apex10000/hiddenapi-modular/encoded/framework-foo.jar",
-			expectedSystemServerJar: "out/soong/.intermediates/service-foo/android_common_apex10000/aligned/service-foo.jar",
+			desc:                      "Source apex com.android.foo is selected, bootjar should come from source java library",
+			selectedApexContributions: "foo.source.contributions",
+			expectedBootJar:           "out/soong/.intermediates/foo-bootclasspath-fragment/android_common_apex10000/hiddenapi-modular/encoded/framework-foo.jar",
 		},
 		{
-			desc:                    "Prebuilt apex prebuilt_com.android.foo is selected, profile should come from .prof deapexed from the prebuilt",
-			selectedApex:            "prebuilt_com.android.foo",
-			expectedBootJar:         "out/soong/.intermediates/prebuilt_com.android.foo.deapexer/android_common/deapexer/javalib/framework-foo.jar",
-			expectedSystemServerJar: "out/soong/.intermediates/prebuilt_com.android.foo.deapexer/android_common/deapexer/javalib/service-foo.jar",
+			desc:                      "Prebuilt apex prebuilt_com.android.foo is selected, profile should come from .prof deapexed from the prebuilt",
+			selectedApexContributions: "foo.prebuilt.contributions",
+			expectedBootJar:           "out/soong/.intermediates/prebuilt_com.android.foo.deapexer/android_common/deapexer/javalib/framework-foo.jar",
 		},
 		{
-			desc:                    "Prebuilt apex prebuilt_com.android.foo.v2 is selected, profile should come from .prof deapexed from the prebuilt",
-			selectedApex:            "com.android.foo.v2",
-			expectedBootJar:         "out/soong/.intermediates/prebuilt_com.android.foo.v2.deapexer/android_common/deapexer/javalib/framework-foo.jar",
-			expectedSystemServerJar: "out/soong/.intermediates/prebuilt_com.android.foo.v2.deapexer/android_common/deapexer/javalib/service-foo.jar",
+			desc:                      "Prebuilt apex prebuilt_com.android.foo.v2 is selected, profile should come from .prof deapexed from the prebuilt",
+			selectedApexContributions: "foo.prebuilt.v2.contributions",
+			expectedBootJar:           "out/soong/.intermediates/prebuilt_com.android.foo.v2.deapexer/android_common/deapexer/javalib/framework-foo.jar",
 		},
 	}
 
@@ -11701,21 +11665,19 @@
 	for _, tc := range testCases {
 		preparer := android.GroupFixturePreparers(
 			java.FixtureConfigureApexBootJars("com.android.foo:framework-foo"),
-			dexpreopt.FixtureSetApexSystemServerJars("com.android.foo:service-foo"),
 			android.FixtureMergeMockFs(map[string][]byte{
 				"system/sepolicy/apex/com.android.foo-file_contexts": nil,
 			}),
 			android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
 				variables.BuildFlags = map[string]string{
-					"RELEASE_APEX_CONTRIBUTIONS_ADSERVICES": "foo.contributions",
+					"RELEASE_APEX_CONTRIBUTIONS_ADSERVICES": tc.selectedApexContributions,
 				}
 			}),
 		)
-		ctx := testDexpreoptWithApexes(t, fmt.Sprintf(bp, tc.selectedApex), "", preparer, fragment)
+		ctx := testDexpreoptWithApexes(t, bp, "", preparer, fragment)
 		checkBootDexJarPath(t, ctx, "framework-foo", tc.expectedBootJar)
 		checkBootJarsPackageCheck(t, ctx, tc.expectedBootJar)
 		checkBootJarsForMonolithicHiddenapi(t, ctx, tc.expectedBootJar)
-		checkSystemServerJarOnHost(t, ctx, tc.selectedApex, "service-foo", tc.expectedSystemServerJar)
 	}
 }
 
diff --git a/apex/prebuilt.go b/apex/prebuilt.go
index dcf0fe2..1ec38eb 100644
--- a/apex/prebuilt.go
+++ b/apex/prebuilt.go
@@ -201,10 +201,6 @@
 	if !p.hasExportedDeps() {
 		return
 	}
-	// If this prebuilt apex has not been selected, return
-	if p.IsHideFromMake() {
-		return
-	}
 	// Use apex_name to determine the api domain of this prebuilt apex
 	apexName := p.ApexVariationName()
 	di, err := android.FindDeapexerProviderForModule(ctx)
diff --git a/dexpreopt/dexpreopt.go b/dexpreopt/dexpreopt.go
index 37b7f34..94707ba 100644
--- a/dexpreopt/dexpreopt.go
+++ b/dexpreopt/dexpreopt.go
@@ -229,30 +229,6 @@
 		pathtools.ReplaceExtension(filepath.Base(path), "odex"))
 }
 
-// Copy the dex'd system server to a predefined location in out/soong/system_server_dexjars
-// dex2oat will use this predefined location to generate the dexpreopt artifacts.
-func CopySystemServerJarsToPredefinedLocations(ctx android.BuilderContext, libName string, libDexPath android.Path) {
-	allSystemServerJars := GetGlobalConfig(ctx).AllSystemServerJars(ctx)
-	if !allSystemServerJars.ContainsJar(libName) {
-		// This is not a system server jar
-		return
-	}
-	if DexpreoptRunningInSoong {
-		// Copy the system server jar to a predefined location where dex2oat will find it.
-		rule := android.NewRuleBuilder(pctx, ctx)
-		dexPathHost := SystemServerDexJarHostPath(ctx, libName)
-		rule.Command().Text("mkdir -p").Flag(filepath.Dir(dexPathHost.String()))
-		rule.Command().Text("cp -f").Input(libDexPath).Output(dexPathHost)
-		rule.Build("copy "+libName+" to soong/system_server_dexjars/", "system_server_dexjars")
-	} else {
-		// For Make modules the copy rule is generated in the makefiles, not in dexpreopt.sh.
-		// This is necessary to expose the rule to Ninja, otherwise it has rules that depend on
-		// the jar (namely, dexpreopt commands for all subsequent system server jars that have
-		// this one in their class loader context), but no rule that creates it (because Ninja
-		// cannot see the rule in the generated dexpreopt.sh script).
-	}
-}
-
 func dexpreoptCommand(ctx android.BuilderContext, globalSoong *GlobalSoongConfig,
 	global *GlobalConfig, module *ModuleConfig, rule *android.RuleBuilder, archIdx int,
 	profile android.WritablePath, appImage bool, generateDM bool, productPackages android.Path) {
@@ -301,6 +277,19 @@
 			clcTarget = append(clcTarget, GetSystemServerDexLocation(ctx, global, lib))
 		}
 
+		if DexpreoptRunningInSoong {
+			// Copy the system server jar to a predefined location where dex2oat will find it.
+			dexPathHost := SystemServerDexJarHostPath(ctx, module.Name)
+			rule.Command().Text("mkdir -p").Flag(filepath.Dir(dexPathHost.String()))
+			rule.Command().Text("cp -f").Input(module.DexPath).Output(dexPathHost)
+		} else {
+			// For Make modules the copy rule is generated in the makefiles, not in dexpreopt.sh.
+			// This is necessary to expose the rule to Ninja, otherwise it has rules that depend on
+			// the jar (namely, dexpreopt commands for all subsequent system server jars that have
+			// this one in their class loader context), but no rule that creates it (because Ninja
+			// cannot see the rule in the generated dexpreopt.sh script).
+		}
+
 		clcHostString := "PCL[" + strings.Join(clcHost.Strings(), ":") + "]"
 		clcTargetString := "PCL[" + strings.Join(clcTarget, ":") + "]"
 
diff --git a/java/base.go b/java/base.go
index 71c02d2..1ac3d30 100644
--- a/java/base.go
+++ b/java/base.go
@@ -1627,9 +1627,6 @@
 
 			// Dexpreopting
 			j.dexpreopt(ctx, dexOutputFile)
-			if !j.IsHideFromMake() {
-				dexpreopt.CopySystemServerJarsToPredefinedLocations(ctx, j.Name(), dexOutputFile)
-			}
 
 			outputFile = dexOutputFile
 		} else {
diff --git a/java/dexpreopt.go b/java/dexpreopt.go
index fe573cc..bd3cce4 100644
--- a/java/dexpreopt.go
+++ b/java/dexpreopt.go
@@ -274,8 +274,6 @@
 	// generate the rules for creating the .odex and .vdex files for this system server jar
 	dexJarFile := di.PrebuiltExportPath(ApexRootRelativePathToJavaLib(libraryName))
 	d.dexpreopt(ctx, dexJarFile)
-
-	dexpreopt.CopySystemServerJarsToPredefinedLocations(ctx, libraryName, dexJarFile)
 }
 
 func (d *dexpreopter) dexpreopt(ctx android.ModuleContext, dexJarFile android.WritablePath) {
@@ -372,7 +370,7 @@
 
 	// Full dexpreopt config, used to create dexpreopt build rules.
 	dexpreoptConfig := &dexpreopt.ModuleConfig{
-		Name:            dexJarStem, // use dexJarStem as the name of the library so that this function can be called from an apex.
+		Name:            moduleName(ctx),
 		DexLocation:     dexLocation,
 		BuildPath:       android.PathForModuleOut(ctx, "dexpreopt", dexJarStem, moduleName(ctx)+".jar").OutputPath,
 		DexPath:         dexJarFile,