Add support for coverage flushing.

Register a callback to allow for coverage flushing on the HAL server.
The callback is tied to the property "hal.coverage.enable" and should
execute whenever the property has value "true".

Test: vts_sancov_configure
Bug: 64019182
Change-Id: I08f19ce84a1307dfb321ce2d46cafcf095643c5c
diff --git a/base/HidlInternal.cpp b/base/HidlInternal.cpp
index 3bb27f8..843fcad 100644
--- a/base/HidlInternal.cpp
+++ b/base/HidlInternal.cpp
@@ -25,13 +25,16 @@
 #include <dirent.h>
 #include <dlfcn.h>
 #include <regex>
+#include <utils/misc.h>
+
+extern "C" __attribute__((weak)) void __sanitizer_cov_dump();
 #endif
 
 namespace android {
 namespace hardware {
 namespace details {
 
-void logAlwaysFatal(const char *message) {
+void logAlwaysFatal(const char* message) {
     LOG(FATAL) << message;
 }
 
@@ -42,9 +45,21 @@
         const std::string &interface)
         : mInstrumentationLibPackage(package), mInterfaceName(interface) {
     configureInstrumentation(false);
+#ifdef LIBHIDL_TARGET_DEBUGGABLE
+    if (__sanitizer_cov_dump != nullptr) {
+        ::android::add_sysprop_change_callback(
+            []() {
+                bool enableCoverage = property_get_bool("hal.coverage.enable", false);
+                if (enableCoverage) {
+                    __sanitizer_cov_dump();
+                }
+            },
+            0);
+    }
+#endif
 }
 
-HidlInstrumentor:: ~HidlInstrumentor() {}
+HidlInstrumentor::~HidlInstrumentor() {}
 
 void HidlInstrumentor::configureInstrumentation(bool log) {
     bool enable_instrumentation = property_get_bool(