[Bugfix][T106BUG-313][autosuspend]fix lock is not error when name is null

Only Configure:No
Affected branch:master
Affected module:autosuspend
Is it affected on both ZXIC and MTK:only ZXIC,
Self-test:Yes,
Doc Update:NO.

Change-Id: Ib4f74af4ba7411a9b0caec027e602857842cbad2
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-autosuspend/lynq-autosuspend.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-autosuspend/lynq-autosuspend.cpp
old mode 100644
new mode 100755
index ced8635..09160b7
--- a/cap/zx297520v3/src/lynq/lib/liblynq-autosuspend/lynq-autosuspend.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-autosuspend/lynq-autosuspend.cpp
@@ -10,6 +10,8 @@
 #include <pthread.h>
 #include <stdbool.h>
 #include <time.h>
+#include <liblog/lynq_deflog.h>
+
 #include "include/libauto/lynq_autosuspend.h"
 #ifdef MOBILETEK_TARGET_PLATFORM_T106
 #include <sc_bsp.h>
@@ -19,10 +21,11 @@
 extern "C" {
 #endif
 
+#define USER_LOG_TAG "LIBLYNQ_AUTOSUSPEND"
 
-#define LOG_TAG "libautosuspend"
-// #include <liblog/lynq_deflog.h>
-#include <log/log.h>
+
+
+
 #define SERVER_CMD_PATH "/tmp/autosuspend.cmd.server"
 #define SERVER_DATA_PATH "/tmp/autosuspend.data.server"
 // #define CLIENT_PATH "/tmp/autosuspend.client"
@@ -45,25 +48,25 @@
     
     while((n = read(fd, ptr, nbytes)) == -1)
     {
-       //printf("READ,%d\n",fd);
+       //LYINFLOG("READ,%d\n",fd);
         if (errno == EINTR)
         {    
-            printf("read error eintr\n");
+            LYINFLOG("read error eintr\n");
             continue;
         }
         else if(errno == EAGAIN || errno == EWOULDBLOCK)
         {
-            printf("read time out\n");
+            LYINFLOG("read time out\n");
             return -2;
         }
         else
         {
-            printf("read error\n");
+            LYINFLOG("read error\n");
             return -1;
         }
     }
     //sleep(2);
-    //printf("READ1,%d\n", fd);
+    //LYINFLOG("READ1,%d\n", fd);
     return n;
 }
 static ssize_t Write(int fd, const void *ptr, size_t nbytes)
@@ -75,7 +78,7 @@
             continue;
         else if(errno == EPIPE)
         {
-            printf("write error epipe\n");
+            LYINFLOG("write error epipe\n");
             return -1;
         }  
         else
@@ -87,7 +90,7 @@
 {
     if (Close(fd) == -1)
     {
-        printf("Close error\n");
+        LYINFLOG("Close error\n");
         return -1;
     }
     return 0;
@@ -97,13 +100,13 @@
     int rc;
     struct sockaddr_un server_sockaddr; 
     struct sockaddr_un client_sockaddr; 
-    printf("Start bind and connect to the service.\n");
+    LYINFLOG("Start bind and connect to the service.\n");
     /**************************************/
     /* Create a UNIX domain stream socket */
     /**************************************/
     *cfd = socket(AF_UNIX, SOCK_STREAM, 0);
     if (*cfd == -1) {
-        printf("SOCKET ERROR ");
+        LYINFLOG("SOCKET ERROR ");
         return -1;
     }
     /***************************************/
@@ -120,7 +123,7 @@
     unlink(client_sockaddr.sun_path);
     rc = bind(*cfd, (struct sockaddr *) &client_sockaddr, sizeof(client_sockaddr));
     if (rc == -1){
-        printf("BIND ERROR ");
+        LYINFLOG("BIND ERROR ");
         Close(*cfd);
         return -1;
     }
@@ -135,7 +138,7 @@
     strcpy(server_sockaddr.sun_path, server_path);
     rc = connect(*cfd, (struct sockaddr *) &server_sockaddr, sizeof(client_sockaddr));
     if(rc == -1){
-        printf("CONNECT ERROR ");
+        LYINFLOG("CONNECT ERROR ");
         Close(*cfd);
         return -3;
     }
@@ -150,27 +153,27 @@
     
     while (1)
     {
-        // printf("deal_get_feedback thread wait.\n");
+        // LYINFLOG("deal_get_feedback thread wait.\n");
         // pthread_cond_wait(&get_feedback_cond,&get_feedback_mutex);
-        printf("start get feedback from the service.\n");
+        LYINFLOG("start get feedback from the service.\n");
         pthread_mutex_lock(&feedback_got_mutex);
         memset(&time_info_client,0,sizeof(struct time_info_t));
         rc = Read(client_sock,&time_info_client,sizeof(struct time_info_t));
         if(rc == -1)
         {           
-            printf("client read wakeup_feedback struct fail.\n");
+            LYINFLOG("client read wakeup_feedback struct fail.\n");
             Close(client_sock);
             pthread_mutex_unlock(&feedback_got_mutex);
             break ;
         }
         else if(rc == -2)
         {
-            printf("client read wakeup_feedback struct timeout.\n");
+            LYINFLOG("client read wakeup_feedback struct timeout.\n");
             pthread_mutex_unlock(&feedback_got_mutex);
             continue;
         }
-        printf("system sleep_start timestamps : %ld ms\n",time_info_client.sleep_start_time);
-        printf("system wakeup timestamps : %ld ms\n",time_info_client.wakeup_time);
+        LYINFLOG("system sleep_start timestamps : %ld ms\n",time_info_client.sleep_start_time);
+        LYINFLOG("system wakeup timestamps : %ld ms\n",time_info_client.wakeup_time);
         // pthread_cond_broadcast(&feedback_got_cond);
         pthread_mutex_unlock(&feedback_got_mutex);
         usleep(10000);  //给libautosuspend_get_feedback函数时间进入wait,不可删除,但可以减少
@@ -186,7 +189,7 @@
     {
         return 0;
     }
-    printf("Start libautosuspend_init.\n");
+    LYINFLOG("Start libautosuspend_init.\n");
     char client_cmd_path[40];
     char client_data_path[40];
     sprintf(client_cmd_path,"/tmp/autosuspend.%d.cmd.client",(int)getpid());
@@ -194,13 +197,13 @@
     pthread_mutex_lock(&client_fd_mutex);
     if(connect_to_server(&client_sock_fd,client_cmd_path,SERVER_CMD_PATH) < 0)
     {
-        printf("cmd channel connect error.\n");
+        LYINFLOG("cmd channel connect error.\n");
         pthread_mutex_unlock(&client_fd_mutex);
         return -1;
     }
     if(connect_to_server(&client_data_sock_fd,client_data_path,SERVER_DATA_PATH) < 0)
     {
-        printf("data channel connect error.\n");
+        LYINFLOG("data channel connect error.\n");
         pthread_mutex_unlock(&client_fd_mutex);
         return -1;
     }
@@ -226,15 +229,15 @@
     /* send it to the server socket.    */
     /************************************/
     // strcpy(buf, DATA);
-    printf("Sending data...\n");
+    LYINFLOG("Sending data...\n");
     rc = send(client_sock_fd, value, len, 0);
     if (rc == -1) {
-        printf("SEND ERROR ");
+        LYINFLOG("SEND ERROR ");
         Close(client_sock_fd);
         return -2;
     }   
     else {
-        printf("Data sent: %s\n",value);
+        LYINFLOG("Data sent: %s\n",value);
     }
     // Close(client_sock);
     return rc;
@@ -243,6 +246,9 @@
 {
     char value[15]="enable";
     char res[15];
+    LYLOGSET(LOG_INFO);
+    LYLOGEINIT(USER_LOG_TAG);
+
     if(libautosuspend_init() != 0)
     {
         return -1;
@@ -255,17 +261,17 @@
     int rc = send_cmd(value,strlen(value));
     if(rc < 0)
     {
-        printf("libautosuspend send enable cmd fail.\n");
+        LYINFLOG("libautosuspend send enable cmd fail.\n");
         pthread_mutex_unlock(&client_fd_mutex);
         return -1;
     }
     // if(Read(client_sock_fd,res,sizeof(res)) <= 0)
     // {
-    //     printf("libautosuspend get respond fail.\n");
+    //     LYINFLOG("libautosuspend get respond fail.\n");
     //     pthread_mutex_unlock(&client_fd_mutex);
     //     return -1;
     // }
-    // printf("libautosuspend get respond : %s.\n",res);
+    // LYINFLOG("libautosuspend get respond : %s.\n",res);
     // if(strcmp(res,"enabled") != 0)
     // {
     //     pthread_mutex_unlock(&client_fd_mutex);
@@ -292,17 +298,17 @@
     int rc = send_cmd(value,strlen(value));
     if(rc < 0)
     {
-        printf("libautosuspend send disable cmd fail.\n");
+        LYINFLOG("libautosuspend send disable cmd fail.\n");
         pthread_mutex_unlock(&client_fd_mutex);
         return -1;
     }
     // if(Read(client_sock_fd,res,sizeof(res)) <= 0)
     // {
-    //     printf("libautosuspend get respond fail.\n");
+    //     LYINFLOG("libautosuspend get respond fail.\n");
     //     pthread_mutex_unlock(&client_fd_mutex);
     //     return -1;
     // }
-    // printf("libautosuspend get respond : %s.\n",res);
+    // LYINFLOG("libautosuspend get respond : %s.\n",res);
     // if(strcmp(res,"disabled") != 0)
     // {
     //     pthread_mutex_unlock(&client_fd_mutex);
@@ -318,14 +324,14 @@
     // char res[15];    
     // if(!libautosuspend_enabled)
     // {
-    //     printf("system autosuspend disabled, can not get wakeup feedback.\n");
+    //     LYINFLOG("system autosuspend disabled, can not get wakeup feedback.\n");
     //     return -1;
     // }
-    printf("start get feedback from the service.\n");
+    LYINFLOG("start get feedback from the service.\n");
     memset(time_info,0,sizeof(struct time_info_t));
     // if(timeout == NULL)
     // {
-    //     printf("client set timeout for receiving wakeup_feedback: NULL.\n");
+    //     LYINFLOG("client set timeout for receiving wakeup_feedback: NULL.\n");
     // }
     // else
     // {
@@ -333,36 +339,36 @@
     //     pthread_mutex_lock(&client_data_fd_mutex);
     //     if(setsockopt(client_data_sock_fd,SOL_SOCKET,SO_RCVTIMEO,(char*)&recv_timeout,sizeof(struct timeval)) == -1)
     //     {
-    //         printf("client set timeout for receiving wakeup_feedback: error.\n");
+    //         LYINFLOG("client set timeout for receiving wakeup_feedback: error.\n");
     //         pthread_mutex_unlock(&client_data_fd_mutex);
     //         return -1;
     //     }
             
-    //     printf("client set timeout for receiving wakeup_feedback: %d s.\n",(*timeout));
+    //     LYINFLOG("client set timeout for receiving wakeup_feedback: %d s.\n",(*timeout));
     //     pthread_mutex_unlock(&client_data_fd_mutex);
         
     // }
     // int rc = send_cmd(value,strlen(value));
     // if(rc < 0)
     // {
-    //     printf("libautosuspend send feedback cmd fail.\n");
+    //     LYINFLOG("libautosuspend send feedback cmd fail.\n");
     //     pthread_mutex_unlock(&client_fd_mutex);
     //     return -1;
     // }
     // if(Read(client_data_sock_fd,time_info,sizeof(struct time_info_t)) <= 0)
     // {
-    //     printf("libautosuspend_get_feedback fail.\n");
+    //     LYINFLOG("libautosuspend_get_feedback fail.\n");
     //     pthread_mutex_unlock(&client_fd_mutex);
     //     return -1;
     // }
-    printf("libautosuspend_get_feedback wait.\n");
+    LYINFLOG("libautosuspend_get_feedback wait.\n");
     pthread_mutex_lock(&feedback_got_mutex);
     pthread_cond_wait(&feedback_got_cond,&feedback_got_mutex);
     memcpy(time_info,&time_info_client,sizeof(struct time_info_t));
-    printf("libautosuspend_get_feedback success.\n");
+    LYINFLOG("libautosuspend_get_feedback success.\n");
     pthread_mutex_unlock(&feedback_got_mutex);
-    // printf("[client] system sleep_start timestamps : %ld ms\n",time_info.sleep_start_time);
-    // printf("[client] system wakeup timestamps : %ld ms\n",time_info.wakeup_time);
+    // LYINFLOG("[client] system sleep_start timestamps : %ld ms\n",time_info.sleep_start_time);
+    // LYINFLOG("[client] system wakeup timestamps : %ld ms\n",time_info.wakeup_time);
     return 0;
 }
 int lynq_wait_wakeup_event(long *sleep_start_time, long * wakeup_time)
@@ -383,7 +389,7 @@
    memset(&time_info,0,sizeof(struct time_info_t));
    if(sleep_start_time == NULL || wakeup_time == NULL )
    {
-      printf("lynq_wait_wakeup_event input errors.\n");
+      LYINFLOG("lynq_wait_wakeup_event input errors.\n");
       return -1;
    }
    ret=libautosuspend_get_feedback(&time_info);
@@ -403,44 +409,64 @@
 int acquire_wake_lock(int lock, char *name)
 {
     int ret;
-    printf("Get param:%s \n", name);
+    LYLOGSET(LOG_INFO);
+    LYLOGEINIT(USER_LOG_TAG);
+
+    if(strlen(name) == 0)
+    {
+        return -1;
+    }
+    LYINFLOG("Get param:%s \n", name);
     ret = sc_pm_wakelock_lock(name);
     if (ret != 0)
     {
-        printf("do_wakelock failed, err:%d", ret);
+        LYINFLOG("do_wakelock failed, err:%d", ret);
         return -1;
     }
 
-    printf("do_wakelock succeed\n");
+    LYINFLOG("do_wakelock succeed\n");
     return 1;
 }
 int release_wake_lock(char *name)
 {
     int ret;
-    printf("Get param:%s \n", name);
+
+    if(strlen(name) == 0)
+    {
+        return -1;
+    }
+    LYLOGSET(LOG_INFO);
+    LYLOGEINIT(USER_LOG_TAG);
+
+    LYINFLOG("Get param:%s \n", name);
     ret = sc_pm_wakelock_unlock(name);
     if (ret != 0)
     {
-        printf("do_wakeunlock failed, err:%d", ret);
+        LYINFLOG("do_wakeunlock failed, err:%d", ret);
         return -1;
     }
-    printf("do_wakeunlock succeed\n");
+    LYINFLOG("do_wakeunlock succeed\n");
     return 1;
 }
 int lynq_set_lpmode(int lp_mode)
 {
     int ret;
-    printf("Get param:%d \n", lp_mode);
+    LYLOGSET(LOG_INFO);
+    LYLOGEINIT(USER_LOG_TAG);
+
+    LYINFLOG("Get param:%d \n", lp_mode);
     ret = sc_pm_set_lp_mode(lp_mode);
     if (ret) {
-        printf("do_set_lpmode failed, err:%d", ret);
+        LYINFLOG("do_set_lpmode failed, err:%d", ret);
         exit(1);
     }
-    printf("do_set_lpmode succeed\n");
+    LYINFLOG("do_set_lpmode succeed\n");
     return ret;
 }
 #endif
 
+DEFINE_LYNQ_LIB_LOG(LIBLYNQ_AUTOSUSPEND)
+
 #ifdef __cplusplus
 }
 #endif