Cleanup global FileFetcher

This global instance is modifiable everywhere and
is hard to maintain. It also contains references as
out-variables, which is not the standard.

Clean it up by refactoring it into a public (i.e.
not in details namespace) class, FileSystem.

Introduce VintfObject::InitFileSystem that allows
the behavior to be changed before any files are read.

Bug: 37999212
Test: host and target libvintf_test, vintf_object_test

Change-Id: I1c64b31fd37119450be89dfd1d2bfe76a71ccf3d
Merged-In: I1c64b31fd37119450be89dfd1d2bfe76a71ccf3d
diff --git a/VintfObject.cpp b/VintfObject.cpp
index 38ef0df..0e757ca 100644
--- a/VintfObject.cpp
+++ b/VintfObject.cpp
@@ -165,7 +165,7 @@
 status_t VintfObject::AddDirectoryManifests(const std::string& directory, HalManifest* manifest,
                                             std::string* error) {
     std::vector<std::string> fileNames;
-    status_t err = details::gFetcher->listFiles(directory, &fileNames, error);
+    status_t err = details::getFileSystem().listFiles(directory, &fileNames, error);
     // if the directory isn't there, that's okay
     if (err == NAME_NOT_FOUND) return OK;
     if (err != OK) return err;
@@ -304,7 +304,7 @@
     std::vector<std::string> fileNames;
     std::vector<Named<CompatibilityMatrix>> results;
 
-    if (details::gFetcher->listFiles(kSystemVintfDir, &fileNames, error) != OK) {
+    if (details::getFileSystem().listFiles(kSystemVintfDir, &fileNames, error) != OK) {
         return {};
     }
     for (const std::string& fileName : fileNames) {
@@ -312,7 +312,7 @@
 
         std::string content;
         std::string fetchError;
-        status_t status = details::gFetcher->fetch(path, content, &fetchError);
+        status_t status = details::getFileSystem().fetch(path, &content, &fetchError);
         if (status != OK) {
             if (error) {
                 *error += "Framework Matrix: Ignore file " + path + ": " + fetchError + "\n";
@@ -753,5 +753,9 @@
     return CheckDeprecation(inManifest, error);
 }
 
+bool VintfObject::InitFileSystem(std::unique_ptr<FileSystem>&& fileSystem) {
+    return details::initFileSystem(std::move(fileSystem));
+}
+
 } // namespace vintf
 } // namespace android