Don't call into apexservice if device uses flattened apexes

If device doesn't support updatable apexes (a.k.a. uses flattened
apexes), then it won't have compressed apexes, so there is no need
calling into apexd.

Test: atest update_engine_unittests:ApexHandlerAndroidTest
Test: build and flash aosp_cf_x86_phone_noapex-userdebug
Test: m dist
Test: python3 system/update_engine/scripts/update_device.py --file out/target/product/vsoc_x86_noapex/aosp_cf_x86_phone_noapex-ota-eng.ioffe.zip
Test: checked OTA was successfully staged
Bug: 185862111
Change-Id: Ibf9db757f3af37d23fb8248108b2b6d22c95dec7
diff --git a/aosp/apex_handler_android_unittest.cc b/aosp/apex_handler_android_unittest.cc
index 981ae9d..847ccaa 100644
--- a/aosp/apex_handler_android_unittest.cc
+++ b/aosp/apex_handler_android_unittest.cc
@@ -41,7 +41,7 @@
   return std::move(result);
 }
 
-TEST(ApexHandlerAndroidTest, CalculateSize) {
+TEST(ApexHandlerAndroidTest, CalculateSizeUpdatableApex) {
   ApexHandlerAndroid apex_handler;
   std::vector<ApexInfo> apex_infos;
   ApexInfo compressed_apex_1 = CreateApexInfo("sample1", 1, true, 1);
@@ -52,10 +52,10 @@
   apex_infos.push_back(uncompressed_apex);
   auto result = apex_handler.CalculateSize(apex_infos);
   ASSERT_TRUE(result.ok());
-  EXPECT_EQ(*result, 3u);
+  ASSERT_EQ(*result, 3u);
 }
 
-TEST(ApexHandlerAndroidTest, AllocateSpace) {
+TEST(ApexHandlerAndroidTest, AllocateSpaceUpdatableApex) {
   ApexHandlerAndroid apex_handler;
   std::vector<ApexInfo> apex_infos;
   ApexInfo compressed_apex_1 = CreateApexInfo("sample1", 1, true, 1);
@@ -64,10 +64,39 @@
   apex_infos.push_back(compressed_apex_1);
   apex_infos.push_back(compressed_apex_2);
   apex_infos.push_back(uncompressed_apex);
-  EXPECT_TRUE(apex_handler.AllocateSpace(apex_infos));
+  ASSERT_TRUE(apex_handler.AllocateSpace(apex_infos));
 
   // Should be able to pass empty list
-  EXPECT_TRUE(apex_handler.AllocateSpace({}));
+  ASSERT_TRUE(apex_handler.AllocateSpace({}));
+}
+
+TEST(ApexHandlerAndroidTest, CalculateSizeFlattenedApex) {
+  FlattenedApexHandlerAndroid apex_handler;
+  std::vector<ApexInfo> apex_infos;
+  ApexInfo compressed_apex_1 = CreateApexInfo("sample1", 1, true, 1);
+  ApexInfo compressed_apex_2 = CreateApexInfo("sample2", 2, true, 2);
+  ApexInfo uncompressed_apex = CreateApexInfo("uncompressed", 1, false, 4);
+  apex_infos.push_back(compressed_apex_1);
+  apex_infos.push_back(compressed_apex_2);
+  apex_infos.push_back(uncompressed_apex);
+  auto result = apex_handler.CalculateSize(apex_infos);
+  ASSERT_TRUE(result.ok());
+  ASSERT_EQ(*result, 0u);
+}
+
+TEST(ApexHandlerAndroidTest, AllocateSpaceFlattenedApex) {
+  FlattenedApexHandlerAndroid apex_handler;
+  std::vector<ApexInfo> apex_infos;
+  ApexInfo compressed_apex_1 = CreateApexInfo("sample1", 1, true, 1);
+  ApexInfo compressed_apex_2 = CreateApexInfo("sample2", 2, true, 2);
+  ApexInfo uncompressed_apex = CreateApexInfo("uncompressed", 1, false, 4);
+  apex_infos.push_back(compressed_apex_1);
+  apex_infos.push_back(compressed_apex_2);
+  apex_infos.push_back(uncompressed_apex);
+  ASSERT_TRUE(apex_handler.AllocateSpace(apex_infos));
+
+  // Should be able to pass empty list
+  ASSERT_TRUE(apex_handler.AllocateSpace({}));
 }
 
 }  // namespace chromeos_update_engine