Pass `-Othroughput` for android_binary targets built without `-opt`

The new `-Othroughput` aapt2 option uses faster level 1 zlib compression
instead of level 9. This is faster when building transient android binaries
for instrumentation tests or for local development.

PiperOrigin-RevId: 960082841
Change-Id: I0a6ebe1f0aafba19fe1062833ac741369ee0615a
diff --git a/rules/resources.bzl b/rules/resources.bzl
index 75ad9b6..c547ffd 100644
--- a/rules/resources.bzl
+++ b/rules/resources.bzl
@@ -481,7 +481,7 @@
         densities = [],
         resource_files = [],
         nocompress_extensions = [],
-        optimize_throughput = False,
+        optimize_throughput = None,
         java_package = None,
         package_id = None,
         use_r_package = False,
@@ -534,6 +534,7 @@
       nocompress_extensions: sequence of Strings. File extension to leave uncompressed
         in the apk.
       optimize_throughput: A boolean. Whether to disable APK size optimizations in favor of a faster execution time.
+        Defaults to None, which enables it when compilation_mode is not opt.
       java_package: String. Java package for which java sources will be
         generated. By default the package is inferred from the directory where
         the BUILD file containing the rule is.
@@ -774,7 +775,9 @@
         resource_configs = resource_configs,
         densities = densities,
         nocompress_extensions = nocompress_extensions,
-        optimize_throughput = optimize_throughput,
+        optimize_throughput = (
+            optimize_throughput if optimize_throughput != None else compilation_mode != _compilation_mode.OPT
+        ),
         java_package = java_package,
         shrink_resource_cycles = shrink_resource_cycles,
         version_name = manifest_values[_VERSION_NAME] if _VERSION_NAME in manifest_values else None,