vts: Add util api checkSubstringInCommandOutput which accept specific cmd.

Bug: 140172237
Test: make vts
Test: atest VtsHalWifiHostapdV1_2TargetTest (Test for new
deviceSupportsFeature with specific command)
Test: atest VtsHalWifiSupplicantP2pV1_0TargetTest (Test for old
deviceSupportsFeature with pm command)
Change-Id: Ia657570ccda656270af75760a28ce30e803a04ba
diff --git a/runners/target/vts_hal_hidl_target/VtsCoreUtil.cpp b/runners/target/vts_hal_hidl_target/VtsCoreUtil.cpp
index bf785fb..ce063fa 100644
--- a/runners/target/vts_hal_hidl_target/VtsCoreUtil.cpp
+++ b/runners/target/vts_hal_hidl_target/VtsCoreUtil.cpp
@@ -21,17 +21,21 @@
 
 namespace testing {
 
-// Runs "pm list features" and attempts to find the specified feature in its
+// Runs "cmd" and attempts to find the specified feature in its
 // output.
-bool deviceSupportsFeature(const char* feature) {
+bool checkSubstringInCommandOutput(const char* cmd, const char* feature) {
   bool hasFeature = false;
   // This is one of the best stable native interface. Calling AIDL directly
   // would be problematic if the binder interface changes.
-  FILE* p = popen("/system/bin/pm list features", "re");
+  FILE* p = popen(cmd, "re");
   if (p) {
     char* line = NULL;
     size_t len = 0;
+    __android_log_print(ANDROID_LOG_FATAL, LOG_TAG,
+                        "checkSubstringInCommandOutput check with cmd: %s",
+                        cmd);
     while (getline(&line, &len, p) > 0) {
+      // TODO: b/148904287, check if we should match the whole line
       if (strstr(line, feature)) {
         hasFeature = true;
         break;
@@ -47,4 +51,10 @@
   return hasFeature;
 }
 
-}  // namespace testing
\ No newline at end of file
+// Runs "pm list features" and attempts to find the specified feature in its
+// output.
+bool deviceSupportsFeature(const char* feature) {
+  return checkSubstringInCommandOutput("/system/bin/pm list features", feature);
+}
+
+}  // namespace testing
diff --git a/runners/target/vts_hal_hidl_target/VtsCoreUtil.h b/runners/target/vts_hal_hidl_target/VtsCoreUtil.h
index d97c78f..a8dacfa 100644
--- a/runners/target/vts_hal_hidl_target/VtsCoreUtil.h
+++ b/runners/target/vts_hal_hidl_target/VtsCoreUtil.h
@@ -18,6 +18,7 @@
 
 namespace testing {
 
+bool checkSubstringInCommandOutput(const char* cmd, const char* feature);
 bool deviceSupportsFeature(const char* feature);
 
-}  // namespace testing
\ No newline at end of file
+}  // namespace testing