Merge "[Bugfix][T106][bug-view-214]Fix the issue of GNSS getting stuck during deinit"
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/include/mbtk_gnss_internal.h b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/include/mbtk_gnss_internal.h
index acd1c04..5602ffe 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/include/mbtk_gnss_internal.h
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/include/mbtk_gnss_internal.h
@@ -234,11 +234,8 @@
         "QZSS L2C"
     };
 
-#ifdef DEBUG
-#define gnss_log(...)                    printf(__VA_ARGS__)
-#else
-#define gnss_log(...)
-#endif
+#define gnss_log ALOGD
+
 #endif
 #define LOGE printf
 #define LOGI printf
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/mbtk_gnss.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/mbtk_gnss.cpp
index 084dbae..59db5a0 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/mbtk_gnss.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-qser-gnss/src/mbtk_gnss.cpp
@@ -67,20 +67,20 @@
     //set system time to rtc.
     if ((srcid = sc_rtc_timer_init()) <= 0)
     {
-        gnss_log("%s %d error: sc_rtc_timer_init fail!\n", __func__, __LINE__);
+        ALOGE("%s %d error: sc_rtc_timer_init fail!\n", __func__, __LINE__);
         return -1;
     }
     ret = sc_rtc_time_set(srcid);
     if (ret != 0)
     {
-        gnss_log("%s %d error: sc_rtc_time_set fail!\n", __func__, __LINE__);
+        ALOGE("%s %d error: sc_rtc_time_set fail!\n", __func__, __LINE__);
         return -1;
     }
     ret = sc_rtc_timer_uninit();
     if (0 != ret)
     {
         LYERRLOG("uninit failed \n");
-        gnss_log("%s %d error: dc_rtc_timer_uninit fail!\n", __func__, __LINE__);
+        ALOGE("%s %d error: dc_rtc_timer_uninit fail!\n", __func__, __LINE__);
         return -1;
     }
     return ret;
@@ -226,7 +226,7 @@
         tmp = strstr_n(&data[n[0]], ",");
         if(0 == tmp) {
             gnss_log("%s %d : error\n", __func__, __LINE__);
-            gnss_log("error: [%d] %s\n", num, data);
+            ALOGE("error: [%d] %s\n", num, data);
             return -1;
         }
         n[0] += tmp;
@@ -237,7 +237,7 @@
         memcpy(out_data, &data[n[0]], n[1] - 1);
     } else {
         gnss_log("%s %d : error [%d]\n" , __func__, __LINE__, n[1]);
-        gnss_log("error: [%d] %s\n", num, data);
+        ALOGE("error: [%d] %s\n", num, data);
         return -1;
     }
 
@@ -937,7 +937,7 @@
 exit:
     pthread_exit(NULL);
 }
-
+int flag = 1;
 static void gnss_uart_pthread(void* hdl)
 {
     struct mbtk_gnss_handle_t *gnss_handle = (struct mbtk_gnss_handle_t *)hdl;
@@ -956,7 +956,10 @@
             nmea_reading = 1;
             ret = mopen_gnss_read(gnss_handle->dev_fd, buf, MBTK_UART_RECV_BUFFER_SIZE);
             nmea_reading = 0;
-
+            if(flag != 0)
+            {
+                flag = 0;
+            }
             if(ret > 0) {
                 ring_buffer_queue_arr(&gnss_handle->ring_buffer, buf, ret);
                 memset(buf, 0, sizeof(buf));
@@ -966,7 +969,6 @@
         }
         usleep(5000);
     }
-
     pthread_exit(NULL);
 }
 
@@ -1131,12 +1133,12 @@
 {
     int ret;
     if(ph_gnss == NULL) {
-        printf("ARG error or has inited.");
+        ALOGE("ARG error or has inited.");
         return -1;
     }
 
     if (mbtk_gnss_handle) {
-        printf("GNSS has inited.");
+        ALOGE("GNSS has inited.");
         *ph_gnss = (uint32)mbtk_gnss_handle;
         return 0;
     }
@@ -1144,7 +1146,7 @@
     mbtk_gnss_handle = (mbtk_gnss_handle_t*)malloc(sizeof(struct mbtk_gnss_handle_t));
     if(NULL == mbtk_gnss_handle)
     {
-        printf("malloc memory error\n");
+        ALOGE("malloc memory error\n");
         return -3;
     }
     memset(mbtk_gnss_handle, 0, sizeof(struct mbtk_gnss_handle_t));
@@ -1153,7 +1155,7 @@
     mbtk_gnss_handle->rb = (char*)malloc(MBTK_UART_RECV_BUFFER_SIZE);
     if(NULL == mbtk_gnss_handle->rb)
     {
-        printf("malloc memory error\n");
+        ALOGE("malloc memory error\n");
         return -1;
     }
 
@@ -1189,6 +1191,7 @@
     int ret;
 
     if (kill) {
+        ALOGE("GNSS hardware issues\n");
         ret = pthread_cancel(pid);
         pthread_join(pid, NULL);
     }
@@ -1200,6 +1203,7 @@
             gnss_log("Useless signal\n");
         else
             gnss_log("The thread exists\n");
+
         usleep(100000);
     }while(0 == ret);
 
@@ -1211,8 +1215,7 @@
     struct mbtk_gnss_handle_t *gnss_handle = (struct mbtk_gnss_handle_t *)h_gnss;
     if(h_gnss == NULL)
     {
-        gnss_log("ARG error or not inited.");
-        printf("ARG error or not inited.\n");
+        ALOGE("ARG error or not inited.");
         return -1;
     }
     gnss_handle->inited = 0;
@@ -1225,15 +1228,16 @@
         _kill_pthread(gnss_handle->ttff_pid, 1);
     }
 #endif
+    
     gnss_log("kill thread info 0.\n");
     _kill_pthread(gnss_handle->gnss_pthread, 0);
     gnss_log("kill thread uart.\n");
-    _kill_pthread(gnss_handle->uart_pthread, 0);
+    _kill_pthread(gnss_handle->uart_pthread, flag);
     mopen_gnss_close(gnss_handle->dev_fd);
     ret = lynq_open_gps(0);
     if(ret)
     {
-        printf("GNSS close init error\n");
+        ALOGE("GNSS close init error\n");
         return -1;
     }
     firmware_extren_state = 0;
@@ -1388,13 +1392,13 @@
 
     if(0 == h_gnss)
     {
-        printf("%s handler invalid.\n", __func__);
+        ALOGE("%s handler invalid.\n", __func__);
         return -1;
     }
     ret = lynq_gnss_send_cmd(h_gnss, send_buf, strlen(send_buf));
     if(ret < 0)
     {
-        gnss_log("%s FAIL. ret:%d\n", __func__, ret);
+        ALOGE("%s FAIL. ret:%d\n", __func__, ret);
         return -1;
     }
     return 0;
@@ -1751,20 +1755,20 @@
 
     if(0 == h_gnss)
     {
-        printf("%s handler invalid.\n", __func__);
+        ALOGE("%s handler invalid.\n", __func__);
         return -1;
     }
 
     agnss_fd = open(ephemeris_path, O_RDWR);
     if (agnss_fd <= 0)
     {
-        printf("%s open file FAIL. errno:%d\n", __FUNCTION__, errno);
+        ALOGE("%s open file FAIL. errno:%d\n", __FUNCTION__, errno);
         return -1;
     }
     char* databuf = (char*)malloc(128);
     if(databuf == NULL)
     {
-        gnss_log("%s malloc() fail.", __FUNCTION__);
+        ALOGE("%s malloc() fail.", __FUNCTION__);
         return -1;
     }
     memset(databuf, 0, 128);