VintfObject now provides instance methods.

VintfObject used to only contain static methods. It now
contains instance methods, and the static methods are
delegates to the instance methods. For example:

GetDeviceHalManifest calls GetInstance()->getDeviceHalManifest()
getDeviceHalManifest does the actual job.

The static dependencies (FileSystem, PropertyFetcher, PartitionMounter,
ObjectFactory<RuntimeInfo> are also moved from utils.cpp to the
static VintfObject instance.

Tests are updated to create a test VintfObject instance with
the mocked dependencies, and run test on the test object.

As a result, utils.cpp is now empty and removed, and
libvintf_common is the same as libvintf. Hence libvintf_common is also
removed.

This allows:
- Allows better mocking in tests. Tests are now independent of
  each other because a new VintfObject is created for every test.
  (Previously this is done very badly by clearing the global states,
  which is error prone)
  - A bug in VintfObjectTest.FrameworkCompatibilityMatrixCombine
    is discovered because it depends on setting global states in
    previous test cases. This is also fixed in this CL.
- In recovery, two VintfObject is required; one for XMLs in the
  recovery image (under /) and one for XMLs in system/vendor image
  (under /mnt). HIDL HAL getService in recovery depends on the former,
  and OTA depends on the latter. This CL prepares recovery to work.
  (A follow-up CL is needed to update VintfObjectRecovery to use
  /mnt for getService).

Some other notable changes in the CL:
- CompatibilityMatrix/HalManifest fetchAllInformation now takes
  a FileSystem argument to fetch files correctly, because the global
  FileSystem object is removed.
- Globals in utils.cpp / utils-fake.cpp is removed
- DevicePropertyFetcher is moved from utils.cpp to PropertyFetcher.cpp
  and is always built (for both host and target); but host VintfObject
  uses dummy PropertyFetcher by default. (See
  createDefaultPropertyFetcher in VintfObject.cpp).

Bug: 110855270
Bug: 80132328
Bug: 111372832

Test: vintf_object_test
Test: livintf_test

Change-Id: I24320662191b977c0e562129e49b33e80de727cc
diff --git a/check_vintf.cpp b/check_vintf.cpp
index c85cbe3..e4941bd 100644
--- a/check_vintf.cpp
+++ b/check_vintf.cpp
@@ -107,24 +107,13 @@
     std::map<std::string, std::string> mProps;
 };
 
-// globals
-static PartitionMounter partitionMounter;
-PartitionMounter* gPartitionMounter = &partitionMounter;
-
-static ObjectFactory<RuntimeInfo> runtimeInfoFactory;
-ObjectFactory<RuntimeInfo>* gRuntimeInfoFactory = &runtimeInfoFactory;
-
-static PresetPropertyFetcher hostPropertyFetcher;
-const PropertyFetcher& getPropertyFetcher() {
-    return hostPropertyFetcher;
-}
-
 // helper functions
 template <typename T>
-std::unique_ptr<T> readObject(const std::string& path, const XmlConverter<T>& converter) {
+std::unique_ptr<T> readObject(FileSystem* fileSystem, const std::string& path,
+                              const XmlConverter<T>& converter) {
     std::string xml;
     std::string error;
-    status_t err = details::getFileSystem().fetch(path, &xml, &error);
+    status_t err = fileSystem->fetch(path, &xml, &error);
     if (err != OK) {
         std::cerr << "Error: Cannot read '" << path << "' (" << strerror(-err) << "): " << error
                   << std::endl;
@@ -139,13 +128,9 @@
 }
 
 int checkCompatibilityForFiles(const std::string& manifestPath, const std::string& matrixPath) {
-    if (!VintfObject::InitFileSystem(std::make_unique<FileSystemImpl>())) {
-        std::cerr << "Cannot initialize FileSystem object." << std::endl;
-        return NO_INIT;
-    }
-
-    auto manifest = readObject(manifestPath, gHalManifestConverter);
-    auto matrix = readObject(matrixPath, gCompatibilityMatrixConverter);
+    auto fileSystem = std::make_unique<FileSystemImpl>();
+    auto manifest = readObject(fileSystem.get(), manifestPath, gHalManifestConverter);
+    auto matrix = readObject(fileSystem.get(), matrixPath, gCompatibilityMatrixConverter);
     if (manifest == nullptr || matrix == nullptr) {
         return -1;
     }
@@ -240,13 +225,12 @@
 }
 
 int checkAllFiles(const std::string& rootdir, const Properties& props, std::string* error) {
-    if (!VintfObject::InitFileSystem(std::make_unique<HostFileSystem>(rootdir))) {
-        std::cerr << "Cannot initialize FileSystem object." << std::endl;
-        return NO_INIT;
-    }
-    hostPropertyFetcher.setProperties(props);
-
-    return VintfObject::CheckCompatibility({} /* packageInfo */, error, DISABLE_RUNTIME_INFO);
+    auto hostPropertyFetcher = std::make_unique<PresetPropertyFetcher>();
+    hostPropertyFetcher->setProperties(props);
+    VintfObject vintfObject(std::make_unique<HostFileSystem>(rootdir),
+                            nullptr /* partition mounter */, nullptr /* runtime info factory */,
+                            std::move(hostPropertyFetcher));
+    return vintfObject.checkCompatibility({} /* packageInfo */, error, DISABLE_RUNTIME_INFO);
 }
 
 }  // namespace details