vibrator: fix issue with ledtrig-transient support

There's a problem with enabling the transient trigger in the HAL, that is
the trigger function exports tree properties - activate, state, and
duration which require to be chown'd to system:system during the init
process. Hence, the trigger will be now enabled in the init process and
the HAL will use the "activate" property to determine if the device has
vibrator support via ledtrig-transient.

Test: device vibrates with the driver supports ledtrig-transient

Change-Id: Ieb195ddc199c6372f5dcf3ca1b2be4fd59724717
Signed-off-by: David Lin <dtwlin@google.com>
diff --git a/modules/vibrator/vibrator.c b/modules/vibrator/vibrator.c
index c3c2951..92c46e2 100644
--- a/modules/vibrator/vibrator.c
+++ b/modules/vibrator/vibrator.c
@@ -32,16 +32,20 @@
 
 static const char THE_DEVICE[] = "/sys/class/timed_output/vibrator/enable";
 
-static int vibra_exists() {
+static bool device_exists(const char *file) {
     int fd;
 
-    fd = TEMP_FAILURE_RETRY(open(THE_DEVICE, O_RDWR));
+    fd = TEMP_FAILURE_RETRY(open(file, O_RDWR));
     if(fd < 0) {
-        return 0;
+        return false;
     }
 
     close(fd);
-    return 1;
+    return true;
+}
+
+static bool vibra_exists() {
+    return device_exists(THE_DEVICE);
 }
 
 static int write_value(const char *file, const char *value)
@@ -102,9 +106,13 @@
     return write_value(file_str, value);
 }
 
-static int vibra_led_exists()
+static bool vibra_led_exists()
 {
-    return !write_led_file("trigger", "transient");
+    int fd;
+    char file_str[50];
+
+    snprintf(file_str, sizeof(file_str), "%s/%s", LED_DEVICE, "activate");
+    return device_exists(file_str);
 }
 
 static int vibra_led_on(vibrator_device_t* vibradev __unused, unsigned int timeout_ms)