[Feature] add power management codes for autosuspend.service autosuspend_lib

Change-Id: I367a67e940dcbbfffeeadd25d23b47db23edbf83
diff --git a/src/lynq/lib/libautosuspend/libautosuspend.c b/src/lynq/lib/libautosuspend/libautosuspend.c
new file mode 100644
index 0000000..a933e9c
--- /dev/null
+++ b/src/lynq/lib/libautosuspend/libautosuspend.c
@@ -0,0 +1,125 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <unistd.h>
+#include <dlfcn.h>
+
+#define LOG_TAG "libautosuspend"
+
+// #include <liblog/lynq_deflog.h>
+#include <log/log.h>
+
+#define SERVER_PATH "/tmp/autosuspend.server"
+// #define CLIENT_PATH "/tmp/autosuspend.client"
+
+
+static int send_cmd(char * value,int len)
+{
+    int client_sock, rc;
+    struct sockaddr_un server_sockaddr; 
+    struct sockaddr_un client_sockaddr; 
+
+
+
+    if(value == NULL)
+    {
+       return -1;
+    }
+
+    /**************************************/
+    /* Create a UNIX domain stream socket */
+    /**************************************/
+    client_sock = socket(AF_UNIX, SOCK_STREAM, 0);
+    if (client_sock == -1) {
+        ALOGI("SOCKET ERROR ");
+        return -5;
+    }
+
+    /***************************************/
+    /* Set up the UNIX sockaddr structure  */
+    /* by using AF_UNIX for the family and */
+    /* giving it a filepath to bind to.    */
+    /*                                     */
+    /* Unlink the file so the bind will    */
+    /* succeed, then bind to that file.    */
+    /***************************************/
+    client_sockaddr.sun_family = AF_UNIX;   
+    // strcpy(client_sockaddr.sun_path, CLIENT_PATH); 
+    sprintf(client_sockaddr.sun_path,"/tmp/suspend.%d.client",(int)getpid());
+    len = sizeof(client_sockaddr);
+    
+    unlink(client_sockaddr.sun_path);
+    rc = bind(client_sock, (struct sockaddr *) &client_sockaddr, len);
+    if (rc == -1){
+        ALOGI("BIND ERROR ");
+        close(client_sock);
+        return -4;
+    }
+        
+    /***************************************/
+    /* Set up the UNIX sockaddr structure  */
+    /* for the server socket and connect   */
+    /* to it.                              */
+    /***************************************/
+    server_sockaddr.sun_family = AF_UNIX;
+    strcpy(server_sockaddr.sun_path, SERVER_PATH);
+    rc = connect(client_sock, (struct sockaddr *) &server_sockaddr, len);
+    if(rc == -1){
+        ALOGI("CONNECT ERROR ");
+        close(client_sock);
+        return -3;
+    }
+    
+    /************************************/
+    /* Copy the data to the buffer and  */
+    /* send it to the server socket.    */
+    /************************************/
+    // strcpy(buf, DATA);                 
+    printf("Sending data...\n");
+    rc = send(client_sock, value, len, 0);
+    if (rc == -1) {
+        ALOGI("SEND ERROR ");
+        close(client_sock);
+        return -2;
+    }   
+    else {
+        ALOGI("Data sent: %s\n",value);
+    }
+
+    close(client_sock);
+
+    return rc;
+
+}
+
+int lynq_autosleep_enable(void)
+{
+  char value[15]="enable";
+  int rc = send_cmd(value,strlen(value));
+  if(rc < 0)
+  {
+      ALOGI("libautosleep_enable ret %d\n",rc);
+  }
+  return rc;
+}
+
+int lynq_autosleep_disable(void)
+{
+  char value[15]="disable";
+  int rc = send_cmd(value,strlen(value));
+  if(rc < 0)
+  {
+      ALOGI("libautosleep_disable ret %d\n",rc);
+  }
+  return rc;
+
+}
+
+
+
+