[Bugfix][T800][task-view-188][NETWORK] lyng_query_available_network,
NetStatus sometims is forbidden or prefer

    Only Configure: No
    Affected branch: unknown
    Affected module: network
    Is it affected on both ZXIC and MTK: both
    Self-test: yes
    Doc Update: no

Change-Id: I4275a40e73b68fd12e8bda13b17b4e491860d6ed
diff --git a/common_src/lib/liblynq-network/lynq_network.cpp b/common_src/lib/liblynq-network/lynq_network.cpp
index bf5f29d..525a74c 100755
--- a/common_src/lib/liblynq-network/lynq_network.cpp
+++ b/common_src/lib/liblynq-network/lynq_network.cpp
@@ -408,6 +408,25 @@
     return RESULT_OK;  

 }

 

+int is_network_registed(char* network_status)

+{

+    if(strcmp(network_status , "registered") != 0 && strcmp(network_status , "current") !=0)  // add by hq on 18/09/2024 for bug-188, registered is for T800, current is for T106

+    {

+        return false;

+    }

+    return true;

+}

+

+int is_network_available(char* network_status)

+{

+    if(strcmp(network_status , "visible") != 0 && strcmp(network_status , "available") !=0)  // add by hq on 18/09/2024 for bug-188, visible is for T800, available is for T106

+    {

+        return false;

+    }

+    return true;

+}

+

+

 int lynq_query_available_network(char *OperatorFN,char *OperatorSH,char *MccMnc,char * NetStatus)

 {

     if(g_module_init_flag != MODULE_RUNNING)

@@ -432,34 +451,59 @@
 

     int num =p->readInt32();

     char *resp[LYNQ_RESP_STRING_MAX_NUM];

+    ret=RESULT_OK;

     if(num == 0 || num > LYNQ_RESP_STRING_MAX_NUM)

     {

-        LYERRLOG("no paramters or num %d too great",num);        

-        delete p;      

-        return LYNQ_E_INNER_ERROR;    

+        LYERRLOG("%s no paramters or num %d too great",__func__,num);              

+        ret=LYNQ_E_INNER_ERROR;    

     }else{

+        int string_index;

+        int network_index=-1;

         int i;

-        for(i = 0; i<num;i++)

+        for(string_index = 0; string_index<num;string_index++)

         {

-            resp[i] = lynqStrdupReadString(p);

+            resp[string_index] = lynqStrdupReadString(p);

+            if(string_index%4==3) // netstatus is the third word

+            {       

+                /*add by hq on 22/04/2024 for API-1575 */         

+                if(is_network_registed(resp[string_index])) 

+                {   

+                    network_index=string_index/4;                    

+                    break;

+                }  

+                else if(is_network_available(resp[string_index]))

+                {

+                    network_index=string_index/4;

+                }

+            }            

         }

-        if(NULL != resp[0])

+        if(network_index!=-1)

         {

-            strcpy(OperatorFN,resp[0]);

+            int start_index=network_index*4;

+            if(NULL != resp[start_index])

+            {

+                strcpy(OperatorFN,resp[start_index]);

+            }

+            if(NULL != resp[start_index+1])

+            {

+                strcpy(OperatorSH,resp[start_index+1]);

+            }

+            if(NULL != resp[start_index+2])

+            {

+                strcpy(MccMnc,resp[start_index+2]);

+            }

+            if(NULL != resp[start_index+3])

+            {

+                strcpy(NetStatus,resp[start_index+3]);

+            }

         }

-        if(NULL != resp[1])

+        else

         {

-            strcpy(OperatorSH,resp[1]);

+            LYERRLOG("%s no find available network after search %d information element",__func__,string_index);                    

+            ret=LYNQ_E_INNER_ERROR;    

         }

-        if(NULL != resp[2])

-        {

-            strcpy(MccMnc,resp[2]);

-        }

-        if(NULL != resp[3])

-        {

-            strcpy(NetStatus,resp[3]);

-        }

-        for(i = 0; i<num;i++)

+        

+        for(i = 0; i<=string_index;i++)

         {

             if(resp[i]!=NULL)

             {

@@ -467,9 +511,13 @@
             }            

         }

     }

-    delete p;

-    LYINFLOG("%s suc",__func__);   

-    return RESULT_OK;  

+    

+    delete p;    

+    if(ret==RESULT_OK)

+    {

+        LYINFLOG("%s suc",__func__);   

+    }    

+    return ret;  

 }

 

 int lynq_query_registration_state_from_parcel(Parcel* p, int num,int reject_index, int* regState,char * LAC,char * CID,int *netType,int *netRejected)