Complete support for Compressed APEXes in ART APEX test scripts.

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

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
diff --git a/build/apex/art_apex_test.py b/build/apex/art_apex_test.py
index 889f1d8..2f5e20d 100755
--- a/build/apex/art_apex_test.py
+++ b/build/apex/art_apex_test.py
@@ -454,7 +454,6 @@
     self._checker.check_file('apex_manifest.pb')
 
     # Check binaries for ART.
-    self._checker.check_executable('artd')
     self._checker.check_first_executable('dex2oat')
     self._checker.check_executable('dexdump')
     self._checker.check_executable('dexlist')
@@ -484,10 +483,7 @@
     self._checker.check_native_library('libprofile')
     self._checker.check_native_library('libsigchain')
 
-    # Check internal Java libraries
-    self._checker.check_java_library("service-art")
-
-    # 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')
@@ -552,6 +548,7 @@
     # removed in Android R.
 
     # Check binaries for ART.
+    self._checker.check_executable('artd')
     self._checker.check_multilib_executable('dex2oat')
     self._checker.check_executable('oatdump')
     self._checker.check_executable("odrefresh")
@@ -559,6 +556,9 @@
     # Check internal libraries for ART.
     self._checker.check_native_library('libperfetto_hprof')
 
+    # Check internal Java libraries
+    self._checker.check_java_library("service-art")
+
     # Check exported native libraries for Managed Core Library.
     self._checker.check_native_library('libandroidio')
 
@@ -911,7 +911,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
@@ -1033,15 +1033,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"