VintfObject::Get*: move logging logic

... from fetchAllInformation to Get() functions, because logging
logic in headers may cause problems.

Test: manual
Bug: 71504062
Change-Id: I99d6e2728b24b4e40959a6cece71bd9b4625711f
diff --git a/utils.h b/utils.h
index c08a22e..dce03b3 100644
--- a/utils.h
+++ b/utils.h
@@ -21,7 +21,6 @@
 #include <iostream>
 #include <sstream>
 
-#include <android-base/logging.h>
 #include <utils/Errors.h>
 #include <vintf/RuntimeInfo.h>
 #include <vintf/parse_xml.h>
@@ -36,12 +35,14 @@
 class FileFetcher {
    public:
     virtual ~FileFetcher() {}
-    virtual status_t fetch(const std::string& path, std::string& fetched) {
+    status_t fetchInternal(const std::string& path, std::string& fetched, std::string* error) {
         std::ifstream in;
 
         in.open(path);
         if (!in.is_open()) {
-            LOG(WARNING) << "Cannot open " << path;
+            if (error) {
+                *error = "Cannot open " + path;
+            }
             return INVALID_OPERATION;
         }
 
@@ -51,6 +52,12 @@
 
         return OK;
     }
+    virtual status_t fetch(const std::string& path, std::string& fetched, std::string* error) {
+        return fetchInternal(path, fetched, error);
+    }
+    virtual status_t fetch(const std::string& path, std::string& fetched) {
+        return fetchInternal(path, fetched, nullptr);
+    }
 };
 
 extern FileFetcher* gFetcher;
@@ -68,7 +75,7 @@
 
 template <typename T>
 status_t fetchAllInformation(const std::string& path, const XmlConverter<T>& converter,
-                             T* outObject) {
+                             T* outObject, std::string* error = nullptr) {
     std::string info;
 
     if (gFetcher == nullptr) {
@@ -76,7 +83,7 @@
         return NO_INIT;
     }
 
-    status_t result = gFetcher->fetch(path, info);
+    status_t result = gFetcher->fetch(path, info, error);
 
     if (result != OK) {
         return result;
@@ -84,8 +91,9 @@
 
     bool success = converter(outObject, info);
     if (!success) {
-        LOG(ERROR) << "Illformed file: " << path << ": "
-                   << converter.lastError();
+        if (error) {
+            *error = "Illformed file: " + path + ": " + converter.lastError();
+        }
         return BAD_VALUE;
     }
     return OK;