[Bugfix][T800][task-view-167][NETWORK] in DSDS senario, sometimes ims
registration fail

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

Change-Id: I199abb6d73347f47d1f2c3c1e741a8226aa3de8b
diff --git a/IC_src/mtk/telephonyware/3.0/hardware/ril/fusion/libril/rilmipc/mipc_adapter.cpp b/IC_src/mtk/telephonyware/3.0/hardware/ril/fusion/libril/rilmipc/mipc_adapter.cpp
old mode 100644
new mode 100755
index 76f822a..5d128f4
--- a/IC_src/mtk/telephonyware/3.0/hardware/ril/fusion/libril/rilmipc/mipc_adapter.cpp
+++ b/IC_src/mtk/telephonyware/3.0/hardware/ril/fusion/libril/rilmipc/mipc_adapter.cpp
@@ -60,12 +60,14 @@
 static const struct RIL_Env *s_rilenv;
 static RIL_RadioState s_radio_state[MAX_SIM_COUNT];
 static pthread_mutex_t s_state_mutex[MAX_SIM_COUNT];
+#if 0 //add by hq at 20240930 for bug 167 sometimes ims registration fail  and mtk cr AUTO00283236 AUTO00329655 AUTO00329686 begin
 static const char PROPERTY_VOLTE_ENABLE[4][30] = {
     "persist.mtk.volte.enable1",
     "persist.mtk.volte.enable2",
     "persist.mtk.volte.enable3",
     "persist.mtk.volte.enable4"
 };
+#endif //add by hq at 20240930 for bug 167 sometimes ims registration fail  and mtk cr AUTO00283236 AUTO00329655 AUTO00329686 end
 
 static void
 onFakeRequest (int request, void *data, size_t datalen, RIL_Token t, RIL_SOCKET_ID socket_id){
@@ -82,8 +84,8 @@
     if (*pState != newState) {
         *pState = newState;
     }
-    pthread_mutex_unlock(&s_state_mutex[rid]);
-#if 0
+    pthread_mutex_unlock(&s_state_mutex[rid]);	
+#if 0  //add by hq at 20240930 for bug 167 sometimes ims registration fail  and mtk cr AUTO00283236 AUTO00329655 AUTO00329686 begin
     if((*pState != oldState) && (*pState == RADIO_STATE_ON)) {
         char prop_value[MTK_PROPERTY_VALUE_MAX] = { 0 };
         mtk_property_get(PROPERTY_VOLTE_ENABLE[rid], prop_value, "0");
@@ -95,7 +97,7 @@
         parcel->writeInt32(volte_enable); //1:VoLTE only, 2:VoNR only, 3: VoLTE+VoNR
         Rfx_issueLocalRequest(RIL_REQUEST_SET_IMS_ENABLE,parcel,rid);
     }
-#endif
+#endif //add by hq at 20240930 for bug 167 sometimes ims registration fail  and mtk cr AUTO00283236 AUTO00329655 AUTO00329686 end
 }
 
 RIL_RadioState getRadioState(RIL_SOCKET_ID rid)
diff --git a/IC_src/mtk/telephonyware/3.0/hardware/ril/fusion/libril/rilmipc/telephony/network/RpNwController.cpp b/IC_src/mtk/telephonyware/3.0/hardware/ril/fusion/libril/rilmipc/telephony/network/RpNwController.cpp
index 4c37289..fc2eb35 100755
--- a/IC_src/mtk/telephonyware/3.0/hardware/ril/fusion/libril/rilmipc/telephony/network/RpNwController.cpp
+++ b/IC_src/mtk/telephonyware/3.0/hardware/ril/fusion/libril/rilmipc/telephony/network/RpNwController.cpp
@@ -626,7 +626,7 @@
 
 void mipc_unsol_nw_ps_ind_cb(mipc_msg_t *msg_ptr, void *cb_priv_ptr) {
     mipc_sim_ps_id_enum sim_ps_id;
-    static uint8_t old_attach_state = MIPC_NW_PS_DETACH;
+    static uint8_t old_attach_state[4] = {MIPC_NW_PS_DETACH, MIPC_NW_PS_DETACH, MIPC_NW_PS_DETACH, MIPC_NW_PS_DETACH};//add by hq at 20240930 for bug 167 sometimes ims registration fail  and mtk cr AUTO00283236 AUTO00329655 AUTO00329686
     uint8_t attach_state;
     mipc_nw_ps_reg_info_struct4 *reg_info;
 
@@ -642,7 +642,8 @@
         }
         string mccMncKey("");
         mccMncKey.append("vendor.ril.data.gsm_mcc_mnc");
-        mccMncKey.append(to_string(mipc_sim_id_to_slot_id(sim_ps_id)));
+        RIL_SOCKET_ID rid = mipc_sim_id_to_slot_id(sim_ps_id);
+        mccMncKey.append(to_string(rid));
         char value[RFX_PROPERTY_VALUE_MAX] = {0};
         int ret = 0;
         rfx_property_get(mccMncKey.c_str(), value, "");
@@ -650,26 +651,26 @@
         p->writeInt32(attach_state);
         p->writeInt32(atoi(value));
         p->writeInt32(reg_info->rat);
-        RFX_LOG_D(RFX_LOG_TAG,"mipc_unsol_nw_ps_ind_cb attach_state[%d], old_attach_state[%d],mccmnc[%d-%s],rat[%d]\n",
-            attach_state,old_attach_state,atoi(value),value,reg_info->rat);
-        rfx_enqueue_urc_message(RIL_UNSOL_RESPONSE_PS_NETWORK_STATE_CHANGED,p,mipc_sim_id_to_slot_id(sim_ps_id),RIL_E_SUCCESS);
-        isNeedNotifyStateChanged(mipc_sim_id_to_slot_id(sim_ps_id));
-
-        if ((attach_state == MIPC_NW_PS_ATTACH) && (old_attach_state != attach_state))
+        RFX_LOG_D(RFX_LOG_TAG,"%s attach_state[%d], old_attach_state[%d], mccmnc[%d-%s], rat[%d]\n", __FUNCTION__,
+            attach_state, old_attach_state[rid], atoi(value),value,reg_info->rat);
+        rfx_enqueue_urc_message(RIL_UNSOL_RESPONSE_PS_NETWORK_STATE_CHANGED,p,rid,RIL_E_SUCCESS);
+        isNeedNotifyStateChanged(rid);
+        /*add by hq at 20240930 for bug 167 sometimes ims registration fail  and mtk cr AUTO00283236 AUTO00329655 AUTO00329686 begin*/
+        if ((attach_state == MIPC_NW_PS_ATTACH) && (old_attach_state[rid] != attach_state))
         {
             RFX_LOG_D(RFX_LOG_TAG,"%s try to SET_IMS_ENABLE\n", __FUNCTION__);
             char prop_value[MTK_PROPERTY_VALUE_MAX] = { 0 };
-            mtk_property_get(PROPERTY_VOLTE_ENABLE[mipc_sim_id_to_slot_id(sim_ps_id)], prop_value, "0");
-            int volte_enable = atoi(prop_value);
-            RIL_SOCKET_ID rid = mipc_sim_id_to_slot_id(sim_ps_id);
+            mtk_property_get(PROPERTY_VOLTE_ENABLE[rid], prop_value, "0");
+            int volte_enable = atoi(prop_value);            
             Parcel *parcel = new Parcel();
             parcel->writeInt32(RIL_REQUEST_SET_IMS_ENABLE);
             parcel->writeInt32(0xffffffff);
             parcel->writeInt32(1);//count
             parcel->writeInt32(volte_enable); //1:VoLTE only, 2:VoNR only, 3: VoLTE+VoNR
             Rfx_issueLocalRequest(RIL_REQUEST_SET_IMS_ENABLE,parcel, rid);
-        }
-        old_attach_state = attach_state;
+        }		
+        old_attach_state[rid] = attach_state;
+        /*add by hq at 20240930 for bug 167 sometimes ims registration fail  and mtk cr AUTO00283236 AUTO00329655 AUTO00329686 end*/
     }
 }