Snap for 10453563 from 4ab9225ca482d85ba3f823ec85b04f078865838f to mainline-configinfrastructure-release

Change-Id: I80f25fb8ce0a6f6bb600cdd5020a4b6213def63d
diff --git a/TEST_MAPPING b/TEST_MAPPING
index 22c9d36..733e1b7 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -11,7 +11,9 @@
     },
     {
       "name": "hidl_lazy_test"
+    },
+    {
+      "name": "vts_ibase_test"
     }
   ]
 }
-
diff --git a/base/include/hidl/TaskRunner.h b/base/include/hidl/TaskRunner.h
index 6a79ebf..f3ea92f 100644
--- a/base/include/hidl/TaskRunner.h
+++ b/base/include/hidl/TaskRunner.h
@@ -16,6 +16,7 @@
 #ifndef ANDROID_HIDL_TASK_RUNNER_H
 #define ANDROID_HIDL_TASK_RUNNER_H
 
+#include <functional>
 #include <memory>
 #include <thread>
 
diff --git a/transport/base/1.0/vts/functional/Android.bp b/transport/base/1.0/vts/functional/Android.bp
index f25aaaa..a2a3484 100644
--- a/transport/base/1.0/vts/functional/Android.bp
+++ b/transport/base/1.0/vts/functional/Android.bp
@@ -37,9 +37,9 @@
         "liblog",
         "libutils",
         "libprotobuf-cpp-lite",
-        "libhidl-gen-utils",
     ],
     static_libs: [
+        "libhidl-gen-utils",
         "libinit_test_utils",
     ],
     test_suites: [
diff --git a/transport/base/1.0/vts/functional/vts_ibase_test.cpp b/transport/base/1.0/vts/functional/vts_ibase_test.cpp
index 6372631..96125d0 100644
--- a/transport/base/1.0/vts/functional/vts_ibase_test.cpp
+++ b/transport/base/1.0/vts/functional/vts_ibase_test.cpp
@@ -81,7 +81,7 @@
 std::map<std::string, std::vector<Hal>> gDeclaredServiceHalMap;
 std::mutex gDeclaredServiceHalMapMutex;
 
-void GetHal(const std::string& service, const FqInstance& instance) {
+void GetHal(const sp<IServiceManager> &manager, const std::string& service, const FqInstance& instance) {
     if (instance.getFqName().string() == IBase::descriptor) {
         return;
     }
@@ -89,6 +89,23 @@
     sp<IBase> hal = android::hardware::details::getRawServiceInternal(
             instance.getFqName().string(), instance.getInstance(), true /*retry*/,
             false /*getStub*/);
+
+    // Check transport of manifest to support hardware SKU:
+    // Don't add service to gDeclaredServiceHalMap if hal instance is null and
+    // the transport of the declared interface is not present in manifest. Because
+    // manufacturer may disable this hal service in the current hardware SKU,
+    // but enable it in the other hardware SKU.
+    if (hal == nullptr && manager != nullptr) {
+        auto transport = manager->getTransport(instance.getFqName().string(),
+            instance.getInstance());
+        if(transport == IServiceManager::Transport::EMPTY){
+            LOG(WARNING)
+                << "Ignore, because Service '" << service << "' is not running,"
+                << " its interface '" << instance.string() << "' is not present in manifest.";
+            return;
+        }
+    }
+
     // Add to gDeclaredServiceHalMap if getRawServiceInternal() returns (even if
     // the returned HAL is null). getRawServiceInternal() won't return if the
     // HAL is in the VINTF but unable to start.
@@ -235,6 +252,7 @@
     const Result<ServiceInterfacesMap> service_interfaces_map =
             android::init::GetOnDeviceServiceInterfacesMap();
     ASSERT_RESULT_OK(service_interfaces_map);
+    auto service_manager = ::android::hardware::defaultServiceManager();
 
     std::map<std::string, std::set<FqInstance>> hidl_interfaces_map;
 
@@ -253,7 +271,7 @@
                 ASSERT_TRUE(fqInstance.setTo(interface))
                         << "Unable to parse interface: '" << interface << "'";
 
-                std::thread(GetHal, service, fqInstance).detach();
+                std::thread(GetHal, service_manager, service, fqInstance).detach();
                 hidl_interfaces_map[service].insert(fqInstance);
             }
         }
diff --git a/vintfdata/frozen/8.xml b/vintfdata/frozen/8.xml
new file mode 100644
index 0000000..db34f63
--- /dev/null
+++ b/vintfdata/frozen/8.xml
@@ -0,0 +1,101 @@
+<compatibility-matrix version="7.0" type="device">
+    <hal format="aidl" optional="false">
+        <name>android.frameworks.cameraservice.service</name>
+        <interface>
+            <name>ICameraService</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
+    <hal format="aidl" optional="false">
+        <name>android.frameworks.location.altitude</name>
+        <interface>
+            <name>IAltitudeService</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
+    <hal format="aidl" optional="false">
+        <name>android.frameworks.sensorservice</name>
+        <interface>
+            <name>ISensorManager</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
+    <hal format="hidl" optional="false">
+        <name>android.frameworks.sensorservice</name>
+        <version>1.0</version>
+        <interface>
+            <name>ISensorManager</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
+    <hal format="aidl" optional="false">
+        <name>android.frameworks.stats</name>
+        <version>2</version>
+        <interface>
+            <name>IStats</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
+    <hal format="hidl" optional="false">
+        <name>android.hardware.media.c2</name>
+        <version>1.2</version>
+        <interface>
+            <name>IComponentStore</name>
+            <instance>software</instance>
+        </interface>
+    </hal>
+    <hal format="hidl" optional="false">
+        <name>android.hidl.allocator</name>
+        <version>1.0</version>
+        <interface>
+            <name>IAllocator</name>
+            <instance>ashmem</instance>
+        </interface>
+    </hal>
+    <hal format="hidl" optional="false">
+        <name>android.hidl.manager</name>
+        <version>1.2</version>
+        <interface>
+            <name>IServiceManager</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
+    <hal format="hidl" optional="false">
+        <name>android.hidl.memory</name>
+        <version>1.0</version>
+        <interface>
+            <name>IMapper</name>
+            <instance>ashmem</instance>
+        </interface>
+    </hal>
+    <hal format="hidl" optional="false">
+        <name>android.hidl.token</name>
+        <version>1.0</version>
+        <interface>
+            <name>ITokenManager</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
+    <hal format="aidl" optional="false">
+        <name>android.system.keystore2</name>
+        <version>3</version>
+        <interface>
+            <name>IKeystoreService</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
+    <hal format="aidl" optional="false">
+        <name>android.system.net.netd</name>
+        <interface>
+            <name>INetd</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
+    <hal format="aidl" optional="false">
+        <name>android.system.suspend</name>
+        <interface>
+            <name>ISystemSuspend</name>
+            <instance>default</instance>
+        </interface>
+    </hal>
+</compatibility-matrix>