Bug87690[fota]升级时不能睡眠模式

Change-Id: I3c731ed4c3b5cb7414931142d753751af6905d85
diff --git a/mbtk/libmbtk_fota/mbtk_fota.c b/mbtk/libmbtk_fota/mbtk_fota.c
index bc8a399..6e67569 100755
--- a/mbtk/libmbtk_fota/mbtk_fota.c
+++ b/mbtk/libmbtk_fota/mbtk_fota.c
@@ -12,6 +12,8 @@
 #include <semaphore.h>

 #include <cutils/properties.h>

 

+#include "mbtk_log.h"

+

 

 #ifdef DEBUG

     #define fota_log(...)                    printf(__VA_ARGS__)

@@ -97,7 +99,7 @@
 

 	notify_str = blobmsg_get_string(tb[ATTR_SMSGPS]);

     len = strlen(notify_str);

-    fota_log("%s : %s\r\n", __FUNCTION__, notify_str);

+    LOGE("%s : %s\r\n", __FUNCTION__, notify_str);

 //    printf("L11111%s : %s\r\n", __FUNCTION__, notify_str);

     if (strstr_n(notify_str, "start")) {

         fota_cb(0, 0);

@@ -105,12 +107,12 @@
         fota_cb(0, 100);

         fota_dowload_flag = 4;

 //        sem_post(&sem);

-        printf("download firmware success!\r\n");

+        LOGE("download firmware success!\r\n");

     } else if (strstr_n(notify_str, "end[0]")) {

         fota_cb(1, 100);

         fota_dowload_flag = 5;

 //        sem_post(&sem);

-        printf("download firmware fail!\r\n");

+        LOGE("download firmware fail!\r\n");

     }

     ret = strstr_n(notify_str, "progress");

     if (ret) {

@@ -126,7 +128,7 @@
     UNUSEDPARAM(ctx);

     UNUSEDPARAM(obj);

     UNUSEDPARAM(id);

-    fota_log("%s,%d\n", __FUNCTION__, __LINE__);

+    LOGE("%s,%d\n", __FUNCTION__, __LINE__);

 }

 

 

@@ -143,11 +145,23 @@
 int mbtk_fota_fw_write(char* fname, int segment_size)

 {

     fota_dowload_flag =  3;

-    printf("mbtk_fota_fw_write start2\n");

-    int L = 1;

+    LOGE("mbtk_fota_fw_write start3\n");

     int ret = -1;

     static struct ubus_request req;

     int _segment_size;

+    char cmd[128]={0};

+

+    if(!access("/sys/power/wake_lock", W_OK))

+    {

+        sprintf(cmd, "echo %s > /sys/power/wake_lock", "ota_lock");

+        system(cmd);

+        LOGE("/sys/power/wake_lock success\n");

+    }

+    else

+    {

+        LOGE("/sys/power/wake_lock can not write.\n");

+    }

+

     blob_buf_init(&b, 0);

     blobmsg_add_string(&b, "url", fname);

     blobmsg_add_u32(&b, "type", 2);

@@ -159,15 +173,10 @@
     blobmsg_add_u32(&b, "sync", 1);

     ubus_invoke_async(fota_ubus_ctx, fota_request_id, "download", b.head, &req);

     ubus_complete_request_async(fota_ubus_ctx, &req);

-#if 1

+

     while(1)

     {

-        if(L == 1)

-        {

-         //   printf("%s, L:%d", __FUNCTION__,L);

-            L++;

-        }

-        /* V2¨´¡Á¡Â */

+        /* V2������ */

 //        sem_wait(&sem);

 //        break;

 

@@ -176,11 +185,21 @@
        //     printf("break while(), fota_dowload_flag:%d", fota_dowload_flag);

             break;

         }

-	sleep(1);

+        sleep(1);

     }

-#endif

-//    printf("%s, L:%d, fota_dowload_flag = :%d", __FUNCTION__,L, fota_dowload_flag);

-//    printf("mbtk_fota_fw_write end \n");

+

+    if(!access("/sys/power/wake_unlock", W_OK))

+    {

+        char cmd[128]={0};

+        sprintf(cmd, "echo %s > /sys/power/wake_unlock", "ota_lock");

+        system(cmd);

+        LOGE("/sys/power/wake_unlock success\n");

+    }

+    else

+    {

+        LOGE("/sys/power/wake_unlock can not write.\n");

+    }

+    LOGE("%s, fota_dowload_flag = :%d", __FUNCTION__, fota_dowload_flag);

     if(fota_dowload_flag == 4)

     {

         ret = 0;

@@ -207,11 +226,24 @@
 int mbtk_fota_fw_write_by_url(char* url, int segment_size,

                             int conn_timeout, int download_timeout)

 {

-    printf("mbtk_fota_fw_write_by_url start2\n");

-    int ret = -1, L = 1;

+    LOGE("mbtk_fota_fw_write_by_url start2\n");

+    int ret = -1;

     fota_dowload_flag =  3;

     static struct ubus_request req;

     int _segment_size;

+    char cmd[128]={0};

+

+    if(!access("/sys/power/wake_lock", W_OK))

+    {

+        sprintf(cmd, "echo %s > /sys/power/wake_lock", "ota_lock");

+        system(cmd);

+        LOGE("/sys/power/wake_lock success\n");

+    }

+    else

+    {

+        LOGE("/sys/power/wake_lock can not write.\n");

+    }

+    

     blob_buf_init(&b, 0);

     blobmsg_add_string(&b, "url", url);

     blobmsg_add_string(&b, "username", "user name");

@@ -227,12 +259,7 @@
 

     while(1)

     {

-        if(L == 1)

-        {

-      //      printf("%s, L:%d", __FUNCTION__,L);

-            L++;

-        }

-        /* V2¨´¡Á¡Â */

+        /* V2������ */

 //        sem_wait(&sem);

 //        break;

 

@@ -241,11 +268,22 @@
        //     printf("break while(), fota_dowload_flag:%d", fota_dowload_flag);

             break;

         }

-	sleep(1);

+        sleep(1);

     }

 

- //   printf("%s, L:%d, fota_dowload_flag = :%d", __FUNCTION__,L, fota_dowload_flag);

- //   printf("mbtk_fota_fw_write_by_url end \n");

+    if(!access("/sys/power/wake_unlock", W_OK))

+    {

+        char cmd[128]={0};

+        sprintf(cmd, "echo %s > /sys/power/wake_unlock", "ota_lock");

+        system(cmd);

+        LOGE("/sys/power/wake_unlock success\n");

+    }

+    else

+    {

+        LOGE("/sys/power/wake_unlock can not write.\n");

+    }

+

+    LOGE("%s, fota_dowload_flag = :%d", __FUNCTION__, fota_dowload_flag);

     if(fota_dowload_flag == 4)

     {

         ret = 0;

@@ -265,17 +303,17 @@
     int ret;

 

     ret = pthread_cancel(fota_status_pthread);

-    fota_log("kill pthread : %d \n", ret);

+    LOGE("kill pthread : %d \n", ret);

     pthread_join(fota_status_pthread, NULL);

     do {

         ret = pthread_kill(fota_status_pthread, 0);

-        fota_log("kill pthread: %d \n", ret);

+        LOGE("kill pthread: %d \n", ret);

         if (ret == ESRCH) {

-            fota_log("The specified thread does not exist or has terminated\n");

+            LOGE("The specified thread does not exist or has terminated\n");

         } else if (ret == EINVAL) {

-            fota_log("Useless signal\n");

+            LOGE("Useless signal\n");

         } else {

-            fota_log("The thread exists\n");

+            LOGE("The thread exists\n");

         }

         usleep(100000);

     } while (0 == ret);

@@ -313,7 +351,7 @@
     //register for ril indication

     ret = ubus_register_subscriber(fota_ubus_ctx, &notification_event);

     if (ret) {

-        fota_log("%s,%d\n", __FUNCTION__, __LINE__);

+        LOGE("%s,%d\n", __FUNCTION__, __LINE__);

         pthread_exit(NULL);

     }

     notification_event.cb = otad_notify;

@@ -337,7 +375,7 @@
     uloop_init();

     fota_ubus_ctx = ubus_connect(NULL);

     if (!fota_ubus_ctx) {

-        fota_log("%s,%d\n", __FUNCTION__, __LINE__);

+        LOGE("%s,%d\n", __FUNCTION__, __LINE__);

         uloop_done();

         return 0;

     }

@@ -348,14 +386,14 @@
         //register for ril request

         retries = 0;

         if (ubus_lookup_id(fota_ubus_ctx, "ota", &fota_request_id)) {

-            fota_log("%s,%d\n", __FUNCTION__, __LINE__);

+            LOGE("%s,%d\n", __FUNCTION__, __LINE__);

             sleep(1);

         } else {

             break;

         }

     } while (retries++ < 20);

     if (retries >= 20) {

-        printf("%s,%d\n", __FUNCTION__, __LINE__);

+        LOGE("%s,%d\n", __FUNCTION__, __LINE__);

         goto fail1;

     }

     pthread_create(&fota_status_pthread, NULL, (void*)mbtk_fota_thread, NULL);

@@ -383,3 +421,7 @@
 }

 

 

+

+

+

+