Add support for AW8695 vibrator

Issue: FP4-INT#6
Issue: ALM:10923711
Change-Id: I19233a33132004ee9fb1472c10513b9773b0c6ad
(cherry picked from commit 981c9491193617bb216a78545f3590fd9bc02912)
diff --git a/aidl/Vibrator.cpp b/aidl/Vibrator.cpp
index 01dbd03..fd78145 100644
--- a/aidl/Vibrator.cpp
+++ b/aidl/Vibrator.cpp
@@ -55,9 +55,15 @@
 #define CUSTOM_DATA_LEN         3
 #define NAME_BUF_SIZE           32
 
+#define VIB_LED  0x01
+#define VIB_AW   0x02
+
+#define VIB_ALL (VIB_LED|VIB_AW)
+
 #define test_bit(bit, array)    ((array)[(bit)/8] & (1<<((bit)%8)))
 
 static const char LED_DEVICE[] = "/sys/class/leds/vibrator";
+static const char AW_DEVICE[] = "/sys/class/leds/vibrator_aw8695";
 
 InputFFDevice::InputFFDevice()
 {
@@ -312,14 +318,26 @@
     int fd;
 
     mDetected = false;
+    vibrator_dev = VIB_ALL;
 
     snprintf(devicename, sizeof(devicename), "%s/%s", LED_DEVICE, "activate");
     fd = TEMP_FAILURE_RETRY(open(devicename, O_RDWR));
     if (fd < 0) {
         ALOGE("open %s failed, errno = %d", devicename, errno);
-        return;
+        vibrator_dev &= ~VIB_LED;
     }
 
+    snprintf(devicename, sizeof(devicename), "%s/%s", AW_DEVICE, "activate");
+    fd = TEMP_FAILURE_RETRY(open(devicename, O_RDWR));
+    if (fd < 0) {
+        ALOGE("open %s failed, errno = %d", devicename, errno);
+        vibrator_dev &= ~VIB_AW;
+    }
+
+    ALOGI("vibrator device = %d", vibrator_dev);
+    if (!vibrator_dev)
+        return;
+
     mDetected = true;
 }
 
@@ -357,6 +375,28 @@
     char value[32];
     int ret;
 
+    if (vibrator_dev & VIB_AW) {
+        ALOGI("AwVibrator time = %d", timeoutMs);
+
+        snprintf(file, sizeof(file), "%s/%s", AW_DEVICE, "activate_mode");
+        ret = write_value(file, "0");
+        if (ret < 0)
+            goto error;
+
+        snprintf(file, sizeof(file), "%s/%s", AW_DEVICE, "duration");
+        snprintf(value, sizeof(value), "%u\n", timeoutMs);
+        ret = write_value(file, value);
+        if (ret < 0)
+            goto error;
+
+        snprintf(file, sizeof(file), "%s/%s", AW_DEVICE, "activate");
+        ret = write_value(file, "1");
+        if (ret < 0)
+            goto error;
+
+        return 0;
+    }
+
     snprintf(file, sizeof(file), "%s/%s", LED_DEVICE, "state");
     ret = write_value(file, "1");
     if (ret < 0)
@@ -385,6 +425,13 @@
     char file[PATH_MAX];
     int ret;
 
+    ALOGI("LedVibrator device = %d", vibrator_dev);
+    if (vibrator_dev & VIB_AW) {
+        snprintf(file, sizeof(file), "%s/%s", AW_DEVICE, "activate");
+        ret = write_value(file, "0");
+        return ret;
+    }
+
     snprintf(file, sizeof(file), "%s/%s", LED_DEVICE, "activate");
     ret = write_value(file, "0");
     return ret;
diff --git a/aidl/include/Vibrator.h b/aidl/include/Vibrator.h
index e0694ca..210c76f 100644
--- a/aidl/include/Vibrator.h
+++ b/aidl/include/Vibrator.h
@@ -60,6 +60,7 @@
     int on(int32_t timeoutMs);
     int off();
     bool mDetected;
+    uint8_t vibrator_dev;
 private:
     int write_value(const char *file, const char *value);
 };