Exit if HIDL isn't supported am: 523130f03f am: a0bc77968e

Original change: https://android-review.googlesource.com/c/platform/system/hwservicemanager/+/2847715

Change-Id: I365d1dd5708f4d022f72c207a44a18541853c550
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/hwservicemanager.rc b/hwservicemanager.rc
index 7ad492b..ce4db63 100644
--- a/hwservicemanager.rc
+++ b/hwservicemanager.rc
@@ -10,3 +10,6 @@
     task_profiles ServiceCapacityLow HighPerformance
     class animation
     shutdown critical
+
+on property:hwservicemanager.disabled=true
+    stop hwservicemanager
diff --git a/service.cpp b/service.cpp
index 3fc1391..3766bc5 100644
--- a/service.cpp
+++ b/service.cpp
@@ -26,6 +26,7 @@
 #include <cutils/properties.h>
 #include <hidl/HidlBinderSupport.h>
 #include <hidl/HidlTransportSupport.h>
+#include <hidl/ServiceManagement.h>
 #include <hidl/Status.h>
 #include <hwbinder/IPCThreadState.h>
 #include <hwbinder/ProcessState.h>
@@ -145,6 +146,18 @@
 
     // TODO(b/36424585): make fatal
     ProcessState::self()->setCallRestriction(ProcessState::CallRestriction::ERROR_IF_NOT_ONEWAY);
+    if (!android::hardware::isHidlSupported()) {
+        ALOGI("HIDL is not supported on this device so hwservicemanager is not needed");
+        int rc = property_set("hwservicemanager.disabled", "true");
+        if (rc) {
+            LOG_ALWAYS_FATAL("Failed to set \"hwservicemanager.disabled\" (error %d).\"", rc);
+        }
+        // wait here for init to see the proprty and shut us down
+        while (true) {
+            ALOGW("Waiting on init to shut this process down.");
+            sleep(10);
+        }
+    }
 
     sp<ServiceManager> manager = new ServiceManager();
     setRequestingSid(manager, true);