Refactor the hiddenAPI() method for reusability

A follow up change needs to be able to contribute to the information
the hiddenapi process collates without having a dex file encoded. This
change pushes all the functionality related to information gathering
into the hiddenAPIGenerateCSV() method and then renames it and the
hiddenAPI() method to make it clearer what they do.

Bug: 178361284
Test: m droid
      Verified that hiddenapi files (both aggregated ones and for the
      individual modules) are not affected by this change.
Change-Id: I04417720216a0fbadcd88e6185e7de6570af6216
diff --git a/apex/apex_test.go b/apex/apex_test.go
index 05ad79b..12201a3 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -4495,6 +4495,12 @@
 		}
 	}
 
+	checkHiddenAPIIndexInputs := func(t *testing.T, ctx *android.TestContext, expectedInputs string) {
+		hiddenAPIIndex := ctx.SingletonForTests("hiddenapi_index")
+		indexRule := hiddenAPIIndex.Rule("singleton-merged-hiddenapi-index")
+		java.CheckHiddenAPIRuleInputs(t, expectedInputs, indexRule)
+	}
+
 	t.Run("prebuilt only", func(t *testing.T) {
 		bp := `
 		prebuilt_apex {
@@ -4519,6 +4525,10 @@
 
 		ctx := testDexpreoptWithApexes(t, bp, "", transform)
 		checkBootDexJarPath(t, ctx, ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
+
+		// Make sure that the dex file from the prebuilt_apex does NOT contribute to the hiddenapi index
+		// file.
+		checkHiddenAPIIndexInputs(t, ctx, ``)
 	})
 
 	t.Run("prebuilt with source library preferred", func(t *testing.T) {
@@ -4588,6 +4598,10 @@
 
 		ctx := testDexpreoptWithApexes(t, bp, "", transform)
 		checkBootDexJarPath(t, ctx, ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
+
+		// Make sure that the dex file from the prebuilt_apex does NOT contribute to the hiddenapi index
+		// file.
+		checkHiddenAPIIndexInputs(t, ctx, ``)
 	})
 
 	t.Run("prebuilt with source apex preferred", func(t *testing.T) {
@@ -4632,6 +4646,11 @@
 
 		ctx := testDexpreoptWithApexes(t, bp, "", transform)
 		checkBootDexJarPath(t, ctx, ".intermediates/libfoo/android_common_apex10000/hiddenapi/libfoo.jar")
+
+		// Make sure that the dex file from the prebuilt_apex contributes to the hiddenapi index file.
+		checkHiddenAPIIndexInputs(t, ctx, `
+.intermediates/libfoo/android_common_apex10000/hiddenapi/index.csv
+`)
 	})
 
 	t.Run("prebuilt preferred with source apex disabled", func(t *testing.T) {
@@ -4678,6 +4697,10 @@
 
 		ctx := testDexpreoptWithApexes(t, bp, "", transform)
 		checkBootDexJarPath(t, ctx, ".intermediates/myapex.deapexer/android_common/deapexer/javalib/libfoo.jar")
+
+		// Make sure that the dex file from the prebuilt_apex does NOT contribute to the hiddenapi index
+		// file.
+		checkHiddenAPIIndexInputs(t, ctx, ``)
 	})
 }
 
@@ -6317,7 +6340,7 @@
 	dexpreopt.SetTestGlobalConfig(config, dexpreoptConfig)
 
 	// Make sure that any changes to these dexpreopt properties are mirrored in the corresponding
-	// product variables that are used by hiddenapi.
+	// product variables.
 	config.TestProductVariables.BootJars = dexpreoptConfig.BootJars
 	config.TestProductVariables.UpdatableBootJars = dexpreoptConfig.UpdatableBootJars