Remove VintfObject::checkCompatibility(vector<string>)

Remove the variant of checkCompatibility that takes VINTF metadata
from an update package. This operation is deprecated.

Test: libvintf_test
Test: vintf_object_test
Bug: 139300422

Change-Id: I16d01a266266d108dbe24715f7b9b342804f9837
diff --git a/VintfObject.cpp b/VintfObject.cpp
index 15ea4d2..0030b4f 100644
--- a/VintfObject.cpp
+++ b/VintfObject.cpp
@@ -25,7 +25,6 @@
 #include <android-base/logging.h>
 
 #include "CompatibilityMatrix.h"
-#include "VintfObjectAfterUpdate.h"
 #include "parse_string.h"
 #include "parse_xml.h"
 #include "utils.h"
@@ -486,77 +485,6 @@
     return mDeviceRuntimeInfo.object;
 }
 
-namespace details {
-
-enum class ParseStatus {
-    OK,
-    PARSE_ERROR,
-    DUPLICATED_FWK_ENTRY,
-    DUPLICATED_DEV_ENTRY,
-};
-
-static std::string toString(ParseStatus status) {
-    switch(status) {
-        case ParseStatus::OK:                   return "OK";
-        case ParseStatus::PARSE_ERROR:          return "parse error";
-        case ParseStatus::DUPLICATED_FWK_ENTRY: return "duplicated framework";
-        case ParseStatus::DUPLICATED_DEV_ENTRY: return "duplicated device";
-    }
-    return "";
-}
-
-template <typename T>
-static ParseStatus tryParse(const std::string& xml, const XmlConverter<T>& parse,
-                            VintfObjectAfterUpdate* afterUpdate) {
-    std::shared_ptr<T> ret = std::make_shared<T>();
-    if (!parse(ret.get(), xml, nullptr /* error */)) {
-        return ParseStatus::PARSE_ERROR;
-    }
-    if (!afterUpdate->set(ret)) {
-        if (ret->type() == SchemaType::FRAMEWORK) {
-            return ParseStatus::DUPLICATED_FWK_ENTRY;
-        } else if (ret->type() == SchemaType::DEVICE) {
-            return ParseStatus::DUPLICATED_DEV_ENTRY;
-        }
-        LOG(FATAL) << "unknown SchemaType: "
-                   << static_cast<std::underlying_type_t<SchemaType>>(ret->type());
-    }
-    return ParseStatus::OK;
-}
-
-}  // namespace details
-
-// Simulate applying xmls to VintfObject, then checkCompatibility as usual.
-int32_t VintfObject::checkCompatibility(const std::vector<std::string>& xmls, std::string* error,
-                                        CheckFlags::Type flags) {
-    VintfObjectAfterUpdate afterUpdate(this);
-    ParseStatus parseStatus = ParseStatus::OK;
-
-    // parse all information from package
-    for (const auto &xml : xmls) {
-        parseStatus = tryParse(xml, gHalManifestConverter, &afterUpdate);
-        if (parseStatus == ParseStatus::OK) {
-            continue; // work on next one
-        }
-        if (parseStatus != ParseStatus::PARSE_ERROR) {
-            appendLine(error, toString(parseStatus) + " manifest");
-            return ALREADY_EXISTS;
-        }
-        parseStatus = tryParse(xml, gCompatibilityMatrixConverter, &afterUpdate);
-        if (parseStatus == ParseStatus::OK) {
-            continue; // work on next one
-        }
-        if (parseStatus != ParseStatus::PARSE_ERROR) {
-            appendLine(error, toString(parseStatus) + " matrix");
-            return ALREADY_EXISTS;
-        }
-        appendLine(error, toString(parseStatus));  // parse error
-        return BAD_VALUE;
-    }
-
-    return afterUpdate.checkCompatibility(error, flags);
-}
-
 int32_t VintfObject::checkCompatibility(std::string* error, CheckFlags::Type flags) {
     status_t status = OK;
     // null checks for files and runtime info
@@ -601,15 +529,9 @@
         return INCOMPATIBLE;
     }
 
-    CheckFlags::Type runtimeInfoCheckFlags = flags;
-    if (getDeviceHalManifest()->shouldCheckKernelCompatibility()) {
-        // Use kernel from incoming OTA package, but not on the device.
-        runtimeInfoCheckFlags = runtimeInfoCheckFlags.disableKernel();
-    }
-
     if (flags.isRuntimeInfoEnabled()) {
         if (!getRuntimeInfo()->checkCompatibility(*getFrameworkCompatibilityMatrix(), error,
-                                                  runtimeInfoCheckFlags)) {
+                                                  flags)) {
             if (error) {
                 error->insert(0,
                               "Runtime info and framework compatibility matrix are incompatible: ");
@@ -665,11 +587,6 @@
 
 }  // namespace details
 
-int32_t VintfObject::CheckCompatibility(const std::vector<std::string>& xmls, std::string* error,
-                                        CheckFlags::Type flags) {
-    return GetInstance()->checkCompatibility(xmls, error, flags);
-}
-
 bool VintfObject::IsHalDeprecated(const MatrixHal& oldMatrixHal,
                                   const CompatibilityMatrix& targetMatrix,
                                   const ListInstances& listInstances, std::string* error) {
diff --git a/VintfObjectAfterUpdate.h b/VintfObjectAfterUpdate.h
deleted file mode 100644
index fbe5291..0000000
--- a/VintfObjectAfterUpdate.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <memory>
-
-#include "SchemaType.h"
-#include "VintfObject.h"
-
-namespace android {
-namespace vintf {
-namespace details {
-/**
- * Simulate the state of VintfObject after an update.
- *
- * - Old metadata is stored in parent VintfObject.
- * - New (updated) metadata is stored in this VintfObjectAfterUpdate
- * - Dependencies are from the given VintfObject (dep) before construction.
- */
-class VintfObjectAfterUpdate : public VintfObject {
-   public:
-    /* Use dependencies from the object dep. */
-    VintfObjectAfterUpdate(VintfObject* dep) : mDependency(dep) {}
-
-    std::shared_ptr<const HalManifest> getDeviceHalManifest(bool skipCache = false) override {
-        if (mDeviceManifest != nullptr) return mDeviceManifest;
-        return VintfObject::getDeviceHalManifest(skipCache);
-    }
-
-    std::shared_ptr<const HalManifest> getFrameworkHalManifest(bool skipCache = false) override {
-        if (mFrameworkManifest != nullptr) return mFrameworkManifest;
-        return VintfObject::getFrameworkHalManifest(skipCache);
-    }
-
-    std::shared_ptr<const CompatibilityMatrix> getDeviceCompatibilityMatrix(
-        bool skipCache = false) override {
-        if (mDeviceMatrix != nullptr) return mDeviceMatrix;
-        return VintfObject::getDeviceCompatibilityMatrix(skipCache);
-    }
-
-    std::shared_ptr<const CompatibilityMatrix> getFrameworkCompatibilityMatrix(
-        bool skipCache = false) override {
-        if (mFrameworkMatrix != nullptr) return mFrameworkMatrix;
-        return VintfObject::getFrameworkCompatibilityMatrix(skipCache);
-    }
-
-    const std::unique_ptr<FileSystem>& getFileSystem() override {
-        return mDependency->getFileSystem();
-    }
-
-    const std::unique_ptr<PropertyFetcher>& getPropertyFetcher() override {
-        return mDependency->getPropertyFetcher();
-    }
-
-    const std::unique_ptr<ObjectFactory<RuntimeInfo>>& getRuntimeInfoFactory() override {
-        return mDependency->getRuntimeInfoFactory();
-    }
-
-    bool set(const std::shared_ptr<HalManifest>& o) {
-        return set(o, &mDeviceManifest, &mFrameworkManifest);
-    }
-
-    bool set(const std::shared_ptr<CompatibilityMatrix>& o) {
-        return set(o, &mDeviceMatrix, &mFrameworkMatrix);
-    }
-
-   private:
-    VintfObject* mDependency = nullptr;
-    std::shared_ptr<HalManifest> mDeviceManifest;
-    std::shared_ptr<HalManifest> mFrameworkManifest;
-    std::shared_ptr<CompatibilityMatrix> mDeviceMatrix;
-    std::shared_ptr<CompatibilityMatrix> mFrameworkMatrix;
-
-    template <typename T>
-    bool set(const std::shared_ptr<T>& o, std::shared_ptr<T>* dev, std::shared_ptr<T>* fwk) {
-        if (o->type() == SchemaType::DEVICE) {
-            if (*dev != nullptr) return false;
-            *dev = o;
-            return true;
-        } else if (o->type() == SchemaType::FRAMEWORK) {
-            if (*fwk != nullptr) return false;
-            *fwk = o;
-            return true;
-        }
-        return false;
-    }
-};
-
-}  // namespace details
-}  // namespace vintf
-}  // namespace android
diff --git a/include/vintf/VintfObject.h b/include/vintf/VintfObject.h
index 88c312d..a3a7241 100644
--- a/include/vintf/VintfObject.h
+++ b/include/vintf/VintfObject.h
@@ -128,8 +128,7 @@
         bool skipCache = false, RuntimeInfo::FetchFlags flags = RuntimeInfo::FetchFlag::ALL);
 
     /**
-     * Check compatibility, given a set of manifests / matrices in packageInfo.
-     * They will be checked against the manifests / matrices on the device.
+     * Check compatibility on the device.
      *
      * @param error error message
      * @param flags flags to disable certain checks. See CheckFlags.
@@ -266,23 +265,6 @@
         bool skipCache = false, RuntimeInfo::FetchFlags flags = RuntimeInfo::FetchFlag::ALL);
 
     /**
-     * Check compatibility, given a set of manifests / matrices in packageInfo.
-     * They will be checked against the manifests / matrices on the device.
-     *
-     * @param packageInfo a list of XMLs of HalManifest /
-     * CompatibilityMatrix objects.
-     * @param error error message
-     * @param flags flags to disable certain checks. See CheckFlags.
-     *
-     * @return = 0 if success (compatible)
-     *         > 0 if incompatible
-     *         < 0 if any error (mount partition fails, illformed XML, etc.)
-     */
-    static int32_t CheckCompatibility(const std::vector<std::string>& packageInfo,
-                                      std::string* error = nullptr,
-                                      CheckFlags::Type flags = CheckFlags::DEFAULT);
-
-    /**
      * Check deprecation on framework matrices with a provided predicate.
      *
      * @param listInstances predicate that takes parameter in this format:
@@ -324,10 +306,6 @@
     status_t fetchOneHalManifest(const std::string& path, HalManifest* out,
                                  std::string* error = nullptr);
     status_t fetchFrameworkHalManifest(HalManifest* out, std::string* error = nullptr);
-    // Helper to CheckCompatibility with dependency injection.
-    int32_t checkCompatibility(const std::vector<std::string>& packageInfo,
-                               std::string* error = nullptr,
-                               CheckFlags::Type flags = CheckFlags::DEFAULT);
 
     static bool IsHalDeprecated(const MatrixHal& oldMatrixHal,
                                 const CompatibilityMatrix& targetMatrix,
diff --git a/main.cpp b/main.cpp
index 95bc042..70433b9 100644
--- a/main.cpp
+++ b/main.cpp
@@ -313,8 +313,8 @@
     }
 
     {
-        auto compatible = VintfObject::CheckCompatibility({}, &error);
-        std::cout << "VintfObject::CheckCompatibility?                         "
+        auto compatible = VintfObject::GetInstance()->checkCompatibility(&error);
+        std::cout << "VintfObject::checkCompatibility?                         "
                   << compatibleString(compatible);
         if (compatible != COMPATIBLE) std::cout << ", " << error;
         std::cout << std::endl;
diff --git a/test/vintf_object_tests.cpp b/test/vintf_object_tests.cpp
index f92db0e..f43f94c 100644
--- a/test/vintf_object_tests.cpp
+++ b/test/vintf_object_tests.cpp
@@ -509,11 +509,6 @@
             .WillRepeatedly(Return(::android::NAME_NOT_FOUND));
     }
 
-    // Access to private method.
-    int checkCompatibility(const std::vector<std::string>& xmls, std::string* error) {
-        return vintfObject->checkCompatibility(xmls, error);
-    }
-
     MockRuntimeInfoFactory& runtimeInfoFactory() {
         return static_cast<MockRuntimeInfoFactory&>(*vintfObject->getRuntimeInfoFactory());
     }
@@ -536,115 +531,19 @@
 // Tests that local info is checked.
 TEST_F(VintfObjectCompatibleTest, TestDeviceCompatibility) {
     std::string error;
-    std::vector<std::string> packageInfo;
 
     expectVendorManifest();
     expectSystemManifest();
     expectVendorMatrix();
     expectSystemMatrix();
 
-    int result = checkCompatibility(packageInfo, &error);
+    int result = vintfObject->checkCompatibility(&error);
 
     ASSERT_EQ(result, 0) << "Fail message:" << error.c_str();
     // Check that nothing was ignored.
     ASSERT_STREQ(error.c_str(), "");
 }
 
-// Tests that input info is checked against device and passes.
-TEST_F(VintfObjectCompatibleTest, TestInputVsDeviceSuccess) {
-    std::string error;
-    std::vector<std::string> packageInfo = {systemMatrixXml1};
-
-    expectVendorManifest();
-    expectSystemManifest();
-    expectVendorMatrix();
-    expectSystemMatrix(0);
-
-    int result = checkCompatibility(packageInfo, &error);
-
-    ASSERT_EQ(result, 0) << "Fail message:" << error.c_str();
-    ASSERT_STREQ(error.c_str(), "");
-}
-
-// Tests that input info is checked against device and fails.
-TEST_F(VintfObjectCompatibleTest, TestInputVsDeviceFail) {
-    std::string error;
-    std::vector<std::string> packageInfo = {systemMatrixXml2};
-
-    int result = checkCompatibility(packageInfo, &error);
-
-    ASSERT_EQ(result, 1) << "Should have failed:" << error.c_str();
-    EXPECT_IN(
-        "Device manifest and framework compatibility matrix are incompatible: HALs "
-        "incompatible.",
-        error);
-    EXPECT_IN("android.hardware.foo", error);
-}
-
-// Tests that complementary info is checked against itself.
-TEST_F(VintfObjectCompatibleTest, TestInputSuccess) {
-    std::string error;
-    std::vector<std::string> packageInfo = {systemMatrixXml2, vendorManifestXml2};
-
-    int result = checkCompatibility(packageInfo, &error);
-
-    ASSERT_EQ(result, 0) << "Failed message:" << error.c_str();
-    ASSERT_STREQ(error.c_str(), "");
-}
-
-TEST_F(VintfObjectCompatibleTest, TestFrameworkOnlyOta) {
-    std::string error;
-    std::vector<std::string> packageInfo = {systemMatrixXml1, systemManifestXml1};
-
-    expectVendorManifest();
-    expectSystemManifest(0);
-    expectVendorMatrix();
-    expectSystemMatrix(0);
-
-    int result = checkCompatibility(packageInfo, &error);
-
-    ASSERT_EQ(result, 0) << "Fail message:" << error.c_str();
-    ASSERT_STREQ(error.c_str(), "");
-}
-
-TEST_F(VintfObjectCompatibleTest, TestFullOta) {
-    std::string error;
-    std::vector<std::string> packageInfo = {systemMatrixXml1, systemManifestXml1,
-            vendorMatrixXml1, vendorManifestXml1};
-
-    expectVendorManifest(0);
-    expectSystemManifest(0);
-    expectVendorMatrix(0);
-    expectSystemMatrix(0);
-
-    int result = checkCompatibility(packageInfo, &error);
-
-    ASSERT_EQ(result, 0) << "Fail message:" << error.c_str();
-    ASSERT_STREQ(error.c_str(), "");
-}
-
-// Test that framework-only OTA fails when kernel is not compatible with incoming system.
-TEST_F(VintfObjectCompatibleTest, KernelInfoIncompatible) {
-    std::string error;
-    std::vector<std::string> packageInfo = {systemMatrixKernel318};
-
-    int result = checkCompatibility(packageInfo, &error);
-
-    ASSERT_EQ(result, INCOMPATIBLE) << "Should have failed.";
-    EXPECT_IN("Framework is incompatible with kernel version 3.18.31", error);
-}
-
-// Test that full OTA is successful when the OTA package provides a compatible kernel.
-TEST_F(VintfObjectCompatibleTest, UpdateKernel) {
-    std::string error;
-    std::vector<std::string> packageInfo = {vendorManifestKernel318, systemMatrixKernel318};
-
-    int result = checkCompatibility(packageInfo, &error);
-
-    ASSERT_EQ(result, COMPATIBLE) << "Fail message:" << error;
-    ASSERT_STREQ(error.c_str(), "");
-}
-
 // Test fixture that provides incompatible metadata from the mock device.
 class VintfObjectIncompatibleTest : public VintfObjectTestBase {
    protected:
@@ -659,34 +558,17 @@
 // Fetch all metadata from device and ensure that it fails.
 TEST_F(VintfObjectIncompatibleTest, TestDeviceCompatibility) {
     std::string error;
-    std::vector<std::string> packageInfo;
 
     expectVendorManifest();
     expectSystemManifest();
     expectVendorMatrix();
     expectSystemMatrix();
 
-    int result = checkCompatibility(packageInfo, &error);
+    int result = vintfObject->checkCompatibility(&error);
 
     ASSERT_EQ(result, 1) << "Should have failed:" << error.c_str();
 }
 
-// Pass in new metadata that fixes the incompatibility.
-TEST_F(VintfObjectIncompatibleTest, TestInputVsDeviceSuccess) {
-    std::string error;
-    std::vector<std::string> packageInfo = {systemMatrixXml1};
-
-    expectVendorManifest();
-    expectSystemManifest();
-    expectVendorMatrix();
-    expectSystemMatrix(0);
-
-    int result = checkCompatibility(packageInfo, &error);
-
-    ASSERT_EQ(result, 0) << "Failed message:" << error.c_str();
-    ASSERT_STREQ(error.c_str(), "");
-}
-
 const std::string vendorManifestKernelFcm =
         "<manifest " + kMetaVersionStr + " type=\"device\">\n"
         "    <kernel version=\"3.18.999\" target-level=\"92\"/>\n"
@@ -1618,20 +1500,7 @@
     expectVendorManifest();
 
     std::string error;
-    EXPECT_TRUE(checkCompatibility({}, &error)) << error;
-}
-
-TEST_F(VintfObjectPartialUpdateTest, VendorOnlyCompatible) {
-    setupMockFetcher("", "", systemManifestXml1, vendorMatrixXml1, productModel);
-    SetUpMockSystemMatrices(systemMatrixRequire);
-
-    expectSystemManifest();
-    expectVendorMatrix();
-    // Should not load vendor manifest from device
-    expectVendorManifest(0);
-
-    std::string error;
-    EXPECT_TRUE(checkCompatibility({vendorManifestRequire2}, &error)) << error;
+    EXPECT_TRUE(vintfObject->checkCompatibility(&error)) << error;
 }
 
 const std::string systemEtcManifest =