Add aconfig flag support for android_library

This change adds the support that was added to android_app in
https://r.android.com/2854663 for android_library modules.

Implementation details:
- Move `Flags_packages` to aaptProperties, so that it can be utilized
  for both android_app and android_library.
- Wrap `VisitDirectDeps` of aconfig_declarations to a function that
  takes a ModuleContext as an input, so that it can be utilized in the
  `GenerateAndroidBuildActions` of both android_app and android_library.

Test: m nothing --no-skip-soong-tests
Bug: 330222981
Change-Id: I8a755f5ca615c8a1651afcd2ec441fc9fbd82c61
diff --git a/java/aar.go b/java/aar.go
index 27dd38b..d29c2fb 100644
--- a/java/aar.go
+++ b/java/aar.go
@@ -104,6 +104,9 @@
 
 	// Filter only specified product and ignore other products
 	Filter_product *string `blueprint:"mutated"`
+
+	// Names of aconfig_declarations modules that specify aconfig flags that the module depends on.
+	Flags_packages []string
 }
 
 type aapt struct {
@@ -804,6 +807,10 @@
 		a.aapt.deps(ctx, sdkDep)
 	}
 	a.usesLibrary.deps(ctx, false)
+
+	for _, aconfig_declaration := range a.aaptProperties.Flags_packages {
+		ctx.AddDependency(ctx.Module(), aconfigDeclarationTag, aconfig_declaration)
+	}
 }
 
 func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext) {
@@ -817,6 +824,7 @@
 			sdkContext:                     android.SdkContext(a),
 			classLoaderContexts:            a.classLoaderContexts,
 			enforceDefaultTargetSdkVersion: false,
+			aconfigTextFiles:               getAconfigFilePaths(ctx),
 		},
 	)