Move hiddenapi singleton rules to Soong

Move the rules that build hiddenapi-stubs-flags.txt,
hiddenapi-flags.csv and hiddenapi-greylist.csv into Soong.

Bug: 123645297
Test: m checkbuild
Test: m UNSAFE_DISABLE_HIDDEN_API_FLAGS=true
Change-Id: I90bf58710f6153ee8565994f799d3ec5699bc7fa
diff --git a/java/java.go b/java/java.go
index d51420c..22829e4 100644
--- a/java/java.go
+++ b/java/java.go
@@ -313,6 +313,7 @@
 	// expanded Jarjar_rules
 	expandJarjarRules android.Path
 
+	hiddenAPI
 	dexpreopter
 }
 
@@ -331,6 +332,7 @@
 	ImplementationJars() android.Paths
 	ResourceJars() android.Paths
 	ImplementationAndResourcesJars() android.Paths
+	DexJar() android.Path
 	AidlIncludeDirs() android.Paths
 	ExportedSdkLibs() []string
 }
@@ -1216,18 +1218,8 @@
 		}
 
 		// Hidden API CSV generation and dex encoding
-		if !ctx.Config().IsEnvTrue("UNSAFE_DISABLE_HIDDENAPI_FLAGS") {
-			isBootJar := inList(ctx.ModuleName(), ctx.Config().BootJars())
-			if isBootJar || inList(ctx.ModuleName(), ctx.Config().HiddenAPIExtraAppUsageJars()) {
-				// Derive the greylist from classes jar.
-				hiddenAPIGenerateCSV(ctx, j.implementationJarFile)
-			}
-			if isBootJar {
-				hiddenAPIJar := android.PathForModuleOut(ctx, "hiddenapi", jarName)
-				hiddenAPIEncodeDex(ctx, hiddenAPIJar, dexOutputFile, j.deviceProperties.UncompressDex)
-				dexOutputFile = hiddenAPIJar
-			}
-		}
+		dexOutputFile = j.hiddenAPI.hiddenAPI(ctx, dexOutputFile, j.implementationJarFile,
+			j.deviceProperties.UncompressDex)
 
 		// merge dex jar with resources if necessary
 		if j.resourceJar != nil {
@@ -1365,6 +1357,10 @@
 	return android.Paths{j.implementationJarFile}
 }
 
+func (j *Module) DexJar() android.Path {
+	return j.dexJarFile
+}
+
 func (j *Module) ResourceJars() android.Paths {
 	if j.resourceJar == nil {
 		return nil
@@ -1775,6 +1771,10 @@
 	return android.Paths{j.combinedClasspathFile}
 }
 
+func (j *Import) DexJar() android.Path {
+	return nil
+}
+
 func (j *Import) AidlIncludeDirs() android.Paths {
 	return nil
 }