Expose flags for collapse resource name to 'convert' command.

To achieve this ParseResourceConfig is extracted to Utils.cpp and tests
are moved from Optimize_test.cpp to Util_test.cpp.

Bug: b/249793372
Test: Util_test, Convert_test
Change-Id: I5a0458e3834d5ea62c96013abc14527285e895e0
diff --git a/tools/aapt2/cmd/Convert.h b/tools/aapt2/cmd/Convert.h
index 6c09649..15fe11f 100644
--- a/tools/aapt2/cmd/Convert.h
+++ b/tools/aapt2/cmd/Convert.h
@@ -50,6 +50,25 @@
         android::base::StringPrintf("Preserve raw attribute values in xml files when using the"
             " '%s' output format", kOutputFormatBinary),
         &xml_flattener_options_.keep_raw_values);
+    AddOptionalFlag("--resources-config-path",
+                    "Path to the resources.cfg file containing the list of resources and \n"
+                    "directives to each resource. \n"
+                    "Format: type/resource_name#[directive][,directive]",
+                    &resources_config_path_);
+    AddOptionalSwitch(
+        "--collapse-resource-names",
+        "Collapses resource names to a single value in the key string pool. Resources can \n"
+        "be exempted using the \"no_collapse\" directive in a file specified by "
+        "--resources-config-path.",
+        &table_flattener_options_.collapse_key_stringpool);
+    AddOptionalSwitch(
+        "--deduplicate-entry-values",
+        "Whether to deduplicate pairs of resource entry and value for simple resources.\n"
+        "This is recommended to be used together with '--collapse-resource-names' flag or for\n"
+        "APKs where resource names are manually collapsed. For such APKs this flag allows to\n"
+        "store the same resource value only once in resource table which decreases APK size.\n"
+        "Has no effect on APKs where resource names are kept.",
+        &table_flattener_options_.deduplicate_entry_values);
     AddOptionalSwitch("-v", "Enables verbose logging", &verbose_);
   }
 
@@ -66,6 +85,7 @@
   bool verbose_ = false;
   bool enable_sparse_encoding_ = false;
   bool force_sparse_encoding_ = false;
+  std::optional<std::string> resources_config_path_;
 };
 
 int Convert(IAaptContext* context, LoadedApk* input, IArchiveWriter* output_writer,