[systime]Bug 86213 && 86214

Change-Id: I62075eb6802cf4f382a5dc87779fe73da89524fc
diff --git a/mbtk/liblynq_lib/src/lynq_time.c b/mbtk/liblynq_lib/src/lynq_time.c
index 8427174..71fd9e3 100644
--- a/mbtk/liblynq_lib/src/lynq_time.c
+++ b/mbtk/liblynq_lib/src/lynq_time.c
@@ -54,8 +54,6 @@
 
 
 
-
-
 //int req_time_set(int type, char *time, int *cme_err);
 static int metis_strptime(char *str_time)
 {
@@ -83,11 +81,15 @@
 
 
 
-static void* ntp_pthread_run()
+static void* ntp_pthread_run(int* ntp_flag)
 {
     if (mbtk_net_state_get() == MBTK_NET_STATE_OFF) 
     {
         printf("Network is disconnected. Set time fail.");
+        if(NULL != ntp_flag)
+       {
+            *ntp_flag = -1;
+       }
         return NULL;
     }
     printf("Network is connected.");
@@ -103,6 +105,10 @@
             if((time = (time_t)mbtk_at_systime()) == 0) 
             {
                 printf("NTP client fail!\n");
+                if(NULL != ntp_flag)
+                {
+                     *ntp_flag = -1;
+                }
                 return NULL;
             }
             struct tm *tm_t;
@@ -118,6 +124,10 @@
 
         sleep(64); // Sleep 64s.
     }
+    if(NULL != ntp_flag)
+    {
+         *ntp_flag = 0;
+    }
     return NULL;
 }
 
@@ -153,10 +163,18 @@
 int ntp_sync_time(int enable)
 {
     UNUSED(enable);
+    int ntp_status = 0;
     if(enable)
     {
-        set_time_type(LYNQ_TIME_TYPE_NTP);
-        ntp_pthread_run();
+        ntp_pthread_run(&ntp_status);
+        if(ntp_status == 0)
+        {
+            set_time_type(LYNQ_TIME_TYPE_NTP);
+        }
+        else
+        {
+            set_time_type(LYNQ_TIME_TYPE_UNUSE);
+        }
     }
     else
     {
@@ -243,19 +261,31 @@
 
     type = atoi(time_type);
     printf("time_type :%d", type);
-    if(type == LYNQ_TIME_TYPE_NTP){
+    if(type == LYNQ_TIME_TYPE_NTP)
+    {
         time_src->ntp = 1;
-    }else if(type == LYNQ_TIME_TYPE_CELL){
+        time_src->nitz = 0;
+        time_src->gnss = 0;
+    }
+    else if(type == LYNQ_TIME_TYPE_CELL)
+    {
+        time_src->ntp = 0;
         time_src->nitz = 1;
-    }else if(type == LYNQ_TIME_TYPE_GNSS){
+        time_src->gnss = 0;
+    }
+    else if(type == LYNQ_TIME_TYPE_GNSS)
+    {
+        time_src->ntp = 0;
+        time_src->nitz = 0;
         time_src->gnss = 1;
-    }else if(type == LYNQ_TIME_TYPE_UNUSE){
+    }
+    else if(type == LYNQ_TIME_TYPE_UNUSE)
+    {
         time_src->ntp = 0;
         time_src->nitz = 0;
         time_src->gnss = 0;
-    }else{
-
     }
+
     return 0;
 }