TWRP: Enable qti input haptics vibrators support

 * these type of vibrators are present in newer devices based on
   board sm8150 & above. Like Oneplus 7 series, Redmi K20 Pro, etc.
 * to enable it add TW_SUPPORT_INPUT_1_2_HAPTICS := true in Boardconfig.mk
 * you will need to add the vendor vibrator service to init and run it in your device tree
Change-Id: I0fe6612def149e70808ca41829b6f7ba0b23cd62
Signed-off-by: Mohd Faraz <androiabledroid@gmail.com>
diff --git a/minuitwrp/Android.mk b/minuitwrp/Android.mk
index 7e5ddd8..b1fb26a 100644
--- a/minuitwrp/Android.mk
+++ b/minuitwrp/Android.mk
@@ -10,6 +10,13 @@
     graphics_utils.cpp \
     events.cpp
 
+ifeq ($(TW_SUPPORT_INPUT_1_2_HAPTICS),true)
+    ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 28; echo $$?),0)
+        LOCAL_SHARED_LIBRARIES += android.hardware.vibrator@1.2 libhidlbase
+        LOCAL_CFLAGS += -DUSE_QTI_HAPTICS
+    endif
+endif
+
 ifneq ($(TW_BOARD_CUSTOM_GRAPHICS),)
     $(warning ****************************************************************************)
     $(warning * TW_BOARD_CUSTOM_GRAPHICS support has been deprecated in TWRP.            *)
diff --git a/minuitwrp/events.cpp b/minuitwrp/events.cpp
index a2a3d16..955acf3 100755
--- a/minuitwrp/events.cpp
+++ b/minuitwrp/events.cpp
@@ -28,6 +28,10 @@
 #include <string.h>
 #include <fstream>
 
+#ifdef USE_QTI_HAPTICS
+#include <android/hardware/vibrator/1.2/IVibrator.h>
+#endif
+
 #include "../common.h"
 
 #include "minui.h"
@@ -130,12 +134,18 @@
     char tout[6];
     sprintf(tout, "%i", timeout_ms);
 
+#ifdef USE_QTI_HAPTICS
+    android::sp<android::hardware::vibrator::V1_2::IVibrator> vib = android::hardware::vibrator::V1_2::IVibrator::getService();
+    if (vib != nullptr) {
+        vib->on((uint32_t)timeout_ms);
+    }
+#else
     if (std::ifstream(LEDS_HAPTICS_ACTIVATE_FILE).good()) {
         write_to_file(LEDS_HAPTICS_DURATION_FILE, tout);
         write_to_file(LEDS_HAPTICS_ACTIVATE_FILE, "1");
     } else
         write_to_file(VIBRATOR_TIMEOUT_FILE, tout);
-
+#endif
     return 0;
 }
 #endif
diff --git a/prebuilt/Android.mk b/prebuilt/Android.mk
index ae5b4be..2935113 100644
--- a/prebuilt/Android.mk
+++ b/prebuilt/Android.mk
@@ -226,6 +226,12 @@
             RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/keystore_cli
             RELINK_SOURCE_FILES += $(TARGET_OUT_EXECUTABLES)/servicemanager
             RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/android.system.wifi.keystore@1.0.so
+            ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 28; echo $$?),0)
+                RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/android.hardware.vibrator@1.0.so
+                RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/android.hardware.vibrator@1.1.so
+                RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/android.hardware.vibrator@1.2.so
+            endif
+
             ifneq ($(wildcard system/keymaster/keymaster_stl.cpp),)
                 RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libkeymaster_portable.so
                 RELINK_SOURCE_FILES += $(TARGET_OUT_SHARED_LIBRARIES)/libkeymaster_staging.so