[API-1054][T8TSK-214][DATA]after flash with ā€œ-sā€, the first data call fail, and cannot recover

Change-Id: Ie2ced17f361d59c3d71c69f7b0cff0b3ac7fbfd7
diff --git a/src/lynq/lib/liblynq-data/lynq_data.cpp b/src/lynq/lib/liblynq-data/lynq_data.cpp
index dfee4e0..03df681 100755
--- a/src/lynq/lib/liblynq-data/lynq_data.cpp
+++ b/src/lynq/lib/liblynq-data/lynq_data.cpp
@@ -25,6 +25,8 @@
 #define USER_LOG_TAG "LYNQ_DATA"
 
 #define LYNQ_DATA_UCI_BUF 258
+#define LYNQ_DATA_TIME_OUT 1000*180
+
 
 using ::android::Parcel;
 typedef struct{
@@ -225,14 +227,15 @@
 
 int handleCheck(int handle)
 {
-    if (lynq_apn_table[handle].hasUsed == 1)
+    if ((handle >= 0) && (handle  <= 6))
     {
-        return 0;
-    }
-    else 
-    {
+        if (lynq_apn_table[handle].hasUsed == 1)
+        {
+            return 0;
+        }
         return -1;
     }
+    return -1;
 }
 int waitApnResult()
 {
@@ -767,7 +770,7 @@
     if(error==0)
     {
         data_timelimit = 1;
-        if (waitDataCallstateChange(60000) == ETIMEDOUT) // 60s
+        if (waitDataCallstateChange(LYNQ_DATA_TIME_OUT) == ETIMEDOUT)
         {
             error = LYNQ_E_TIME_OUT;
             LYERRLOG("timeout:wait data Call state fail!!!");
@@ -942,7 +945,7 @@
     if(error==0)
     {
         data_timelimit = 1;
-        if(waitDataCallstateChange(60000)==ETIMEDOUT)//60s
+        if(waitDataCallstateChange(LYNQ_DATA_TIME_OUT)==ETIMEDOUT)
         {
             error = LYNQ_E_TIME_OUT;
             LYERRLOG("timeout:wait data Call state fail!!!");
@@ -1095,6 +1098,27 @@
     }
     return error;
 }
+
+int lynq_get_apn_msg(int handle,lynq_apn_msg_t *apn_msg)
+{
+    LYINFLOG("[lynq_get_apn_msg] enter,handle:%d",handle);
+    if((handle < 0) || (handle > 6) || (NULL == apn_msg))
+    {
+        LYERRLOG("handle value error,or apn_msg is null");
+        return LYNQ_E_NULL_ANONALY;
+    }
+    apn_msg->handle = handle;
+    if(apn_msg->apn!=NULL)
+    {
+        memcpy(apn_msg->apn,lynq_apn_table[handle].apn,LYNQ_APN_MAX_LEN);
+    }
+    if(apn_msg->apnType!=NULL)
+    {
+        memcpy(apn_msg->apnType,lynq_apn_table[handle].apnType,LYNQ_APN_TYPE_MAX_LEN);
+    }
+    return 0;
+}
+
 int lynq_get_data_call_list(int *handle,lynq_data_call_response_v11_t *dataCallList)
 {
     lynq_data_call_response_v11_t interDataCallList[LYNQ_APN_CHANNEL_MAX]={};
@@ -1102,16 +1126,17 @@
     int lynq_data_call_id = 0;
     int error = 0;
     lynq_data_call_id = *handle;
-    if(handle==NULL)
+    if((handle==NULL) || (dataCallList==NULL))
     {
-        LYERRLOG("handle is NULL");
+        LYERRLOG("[lynq_get_data_call_list] handle or datacalllist is NULL");
         return LYNQ_E_NULL_ANONALY;
     }
-    if (*handle<0 && handle>8)
+    if ((*handle < 0) || (*handle > 6))
     {
-        LYERRLOG("handle value error");
+        LYERRLOG("[lynq_get_data_call_list] handle value error");
+        return LYNQ_E_NULL_ANONALY;
     }
-    LYINFLOG("incoming handle value: %d",*handle);
+    LYINFLOG("[lynq_get_data_call_list] incoming handle value: %d",*handle);
     memset(interDataCallList,0,sizeof(interDataCallList));
     error = getDataCallLists(interDataCallList,&number);
     if(error == 0)
@@ -1441,7 +1466,58 @@
     s16 = p.readString16Inplace(&stringlen);
     return strndup16to8(s16, stringlen);
 }
-
+int get_imsi()
+{
+    Parcel p;
+    lynq_client_t client;
+    int resp_type = -1;
+    int token;
+    int request = -1;
+    int slot_id = -1;
+    int error = -1;
+    int version =0;
+    int num = 0;
+    char *temp_char = NULL;
+    char mccmnc[32] = {0};
+    char mccmnckey[64] = {0};
+    client.uToken = Global_uToken;
+    client.request = 11;//RIL_REQUEST_GET_IMSI 11
+    client.paramLen = 0;
+    bzero(client.param,LYNQ_REQUEST_PARAM_BUF);
+    LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
+    pthread_mutex_lock(&g_lynq_data_sendto_mutex);
+    if(send_request(lynq_client_sockfd,&client)==-1)
+    {
+        LYERRLOG("send request fail");
+        perror("[LYNQ_DATA] send request fail:");
+        return -1;
+    }
+    get_response(lynq_client_sockfd,p);
+    pthread_mutex_unlock(&g_lynq_data_sendto_mutex);
+    if(p.dataAvail() > 0)
+    {
+        p.readInt32(&resp_type);
+        p.readInt32(&token);
+        p.readInt32(&request);
+        p.readInt32(&slot_id);
+        p.readInt32(&error);
+        LYINFLOG("resp_type=%d,uToken=%d,request=%d,slot_id=%d,error_code=%d",resp_type,token,request,slot_id,error);
+        if(!error)
+        {
+            char * test = lynqStrdupReadString(p);
+            memcpy(mccmnc, test,5);
+            mccmnc[5]='\0';
+            free(test);
+            sprintf(mccmnckey,"uci set radio_property.property.vendor_ril_data_gsm_mcc_mnc0=%s",mccmnc);
+            system(mccmnckey);
+        }
+        return error;
+    }
+    else
+    {
+        return -1;
+    }
+}
 int lynq_modify_apn_db(const int cmd, char *id, char *mcc, char *mnc, char *apn, char *apntype, char *user, char *password, char *normalprotocol, char *roamingprotocol, char *carrier, char *out)
 {
     if (NULL == id && NULL == mcc && NULL == mnc && NULL == apn && NULL == apntype && NULL == user && NULL == password && NULL == normalprotocol && NULL == roamingprotocol && NULL == carrier)
@@ -1451,7 +1527,19 @@
     }
     lynq_client_t client;
     char argc[512];
-    int res = 0;
+    int res = -1;
+    int count = 0;
+    while(count < 10)
+    {
+        res =  get_imsi();
+        if(res==0)
+        {
+            break;
+        }
+        sleep(1);
+        count++;
+    }
+    LYINFLOG("[%s] count is %d",__FUNCTION__,count);
     Parcel p;
     if (cmd == 0) // insert apn db
     {
@@ -1501,6 +1589,8 @@
     }
     LYINFLOG("uToken=%d,request=%d,paralen=%d,param=%s",client.uToken,client.request,client.paramLen,client.param);
     pthread_mutex_lock(&g_lynq_data_sendto_mutex);
+    LYINFLOG("[%s] wait 4s",__FUNCTION__);
+    sleep(4);
     if(send_request(lynq_client_sockfd,&client)==-1)
     {
         LYERRLOG("send request fail");