Complete support for Compressed APEXes in ART APEX test scripts.

Also fix some checks in script `build/apex/art_apex_test.py`.

(cherry picked from commit 2af026df0beca1fe51d58e1d3163ee7678e6078b)

Test: env OVERRIDE_TARGET_FLATTEN_APEX=false \
          OVERRIDE_PRODUCT_COMPRESSED_APEX=false \
        art/build/apex/runtests.sh
Test: env OVERRIDE_TARGET_FLATTEN_APEX=true \
          OVERRIDE_PRODUCT_COMPRESSED_APEX=false \
        art/build/apex/runtests.sh
Test: env OVERRIDE_TARGET_FLATTEN_APEX=false \
          OVERRIDE_PRODUCT_COMPRESSED_APEX=true \
        art/build/apex/runtests.sh
Test: env OVERRIDE_TARGET_FLATTEN_APEX=true \
          OVERRIDE_PRODUCT_COMPRESSED_APEX=true \
        art/build/apex/runtests.sh
Bug: 188809029
Change-Id: Ida714cef146c9318429e30503912511d23a3891a
Merged-In: Ida714cef146c9318429e30503912511d23a3891a
diff --git a/build/apex/art_apex_test.py b/build/apex/art_apex_test.py
index bb97416..d3ccd8d 100755
--- a/build/apex/art_apex_test.py
+++ b/build/apex/art_apex_test.py
@@ -481,7 +481,7 @@
     self._checker.check_native_library('libprofile')
     self._checker.check_native_library('libsigchain')
 
-    # Check java libraries for Managed Core Library.
+    # Check Java libraries for Managed Core Library.
     self._checker.check_java_library('apache-xml')
     self._checker.check_java_library('bouncycastle')
     self._checker.check_java_library('core-libart')
@@ -903,7 +903,7 @@
       for flavor in [ FLAVOR_DEBUG, FLAVOR_TESTING, FLAVOR_RELEASE ]:
         flavor_tag = flavor
         # Special handling for the release flavor, whose name is no longer part of the Release ART
-        # APEX file name (`com.android.art.apex` / `com.android.art`).
+        # APEX file name (`com.android.art.capex` / `com.android.art`).
         if flavor == FLAVOR_RELEASE:
           flavor_tag = ''
         flavor_pattern = '*.%s*' % flavor_tag
@@ -1025,15 +1025,16 @@
   # TODO: Add host support.
   # TODO: Add support for flattened APEX packages.
   configs = [
-    {'name': 'com.android.art',         'flavor': FLAVOR_RELEASE, 'host': False},
-    {'name': 'com.android.art.debug',   'flavor': FLAVOR_DEBUG,   'host': False},
-    {'name': 'com.android.art.testing', 'flavor': FLAVOR_TESTING, 'host': False},
+    {'name': 'com.android.art.capex',         'flavor': FLAVOR_RELEASE, 'host': False},
+    {'name': 'com.android.art.debug.capex',   'flavor': FLAVOR_DEBUG,   'host': False},
+    # Note: The Testing ART APEX is not a Compressed APEX.
+    {'name': 'com.android.art.testing.apex',  'flavor': FLAVOR_TESTING, 'host': False},
   ]
 
   for config in configs:
     logging.info(config['name'])
     # TODO: Host will need different path.
-    test_args.apex = '%s/system/apex/%s.apex' % (product_out, config['name'])
+    test_args.apex = '%s/system/apex/%s' % (product_out, config['name'])
     if not os.path.exists(test_args.apex):
       failed = True
       logging.error("Cannot find APEX %s. Please build it first.", test_args.apex)
diff --git a/build/apex/runtests.sh b/build/apex/runtests.sh
index 5911288..232daa3 100755
--- a/build/apex/runtests.sh
+++ b/build/apex/runtests.sh
@@ -41,7 +41,12 @@
 [[ -n "$ANDROID_PRODUCT_OUT" ]] || setup_die
 [[ -n "$ANDROID_HOST_OUT" ]] || setup_die
 
-flattened_apex_p=$($ANDROID_BUILD_TOP/build/soong/soong_ui.bash --dumpvar-mode TARGET_FLATTEN_APEX)\
+flattened_apex_p=$($ANDROID_BUILD_TOP/build/soong/soong_ui.bash \
+    --dumpvar-mode TARGET_FLATTEN_APEX) \
+  || setup_die
+
+compressed_apex_p=$($ANDROID_BUILD_TOP/build/soong/soong_ui.bash \
+    --dumpvar-mode PRODUCT_COMPRESSED_APEX) \
   || setup_die
 
 # Switch the build system to unbundled mode in the reduced manifest branch.
@@ -180,7 +185,12 @@
       apex_path="$ANDROID_PRODUCT_OUT/system/apex/${apex_module}"
       art_apex_test_args="$art_apex_test_args --flattened"
     else
-      apex_path="$ANDROID_PRODUCT_OUT/system/apex/${apex_module}.apex"
+      # Note: The Testing ART APEX is never built as a Compressed APEX.
+      if $compressed_apex_p && [[ $apex_module != *.testing ]]; then
+        apex_path="$ANDROID_PRODUCT_OUT/system/apex/${apex_module}.capex"
+      else
+        apex_path="$ANDROID_PRODUCT_OUT/system/apex/${apex_module}.apex"
+      fi
     fi
     if $have_deapexer_p; then
       art_apex_test_args="$art_apex_test_args --deapexer $ANDROID_HOST_OUT/bin/deapexer"