Add AAPT flags to optimize the set of resources in the RRO apk.

The solution is based on adding flags in build/soong/java/app.go.
It will reduce the amount of resources in RRO. Also, it solves the problem of extra locales
 in the Setting and TvSettings applications (see AssetManager2.h, GetResourceLocales()).

Add 3 flags:
1. "--product" - specifies a list of product names to keep.
2. "-c" - provides a list of configurations.
For example, if you have dependencies on the support library, which contains translations for multiple languages, you can filter resources just for the given language configuration, like English or Spanish.
3. "--preferred-density" - allows AAPT2 to select the closest matching density and strip out all others.

Change-Id: I0da8bc05f349553188264824bfa5b53c27882ee3
Signed-off-by: Artem Anashkin <asanashkin@salutedevices.com>
diff --git a/java/rro.go b/java/rro.go
index ab4fafa..44d5564 100644
--- a/java/rro.go
+++ b/java/rro.go
@@ -139,6 +139,25 @@
 	r.aapt.hasNoCode = true
 	// Do not remove resources without default values nor dedupe resource configurations with the same value
 	aaptLinkFlags := []string{"--no-resource-deduping", "--no-resource-removal"}
+
+	// Add TARGET_AAPT_CHARACTERISTICS values to AAPT link flags if they exist and --product flags were not provided.
+	hasProduct := android.PrefixInList(r.aaptProperties.Aaptflags, "--product")
+	if !hasProduct && len(ctx.Config().ProductAAPTCharacteristics()) > 0 {
+		aaptLinkFlags = append(aaptLinkFlags, "--product", ctx.Config().ProductAAPTCharacteristics())
+	}
+
+	if !Bool(r.aaptProperties.Aapt_include_all_resources) {
+		// Product AAPT config
+		for _, aaptConfig := range ctx.Config().ProductAAPTConfig() {
+			aaptLinkFlags = append(aaptLinkFlags, "-c", aaptConfig)
+		}
+
+		// Product AAPT preferred config
+		if len(ctx.Config().ProductAAPTPreferredConfig()) > 0 {
+			aaptLinkFlags = append(aaptLinkFlags, "--preferred-density", ctx.Config().ProductAAPTPreferredConfig())
+		}
+	}
+
 	// Allow the override of "package name" and "overlay target package name"
 	manifestPackageName, overridden := ctx.DeviceConfig().OverrideManifestPackageNameFor(ctx.ModuleName())
 	if overridden || r.overridableProperties.Package_name != nil {