Merge "[Bugfix][API-1374][API-1379][data]Fix sometimes does not retry the PDN activation operation" into GSW3.0-No-Connman
diff --git a/src/connectivity/gps/2.0/gps_hal/mnldinf/src/mnldinf_utility.c b/src/connectivity/gps/2.0/gps_hal/mnldinf/src/mnldinf_utility.c
old mode 100644
new mode 100755
index 3141c69..f6dd4b5
--- a/src/connectivity/gps/2.0/gps_hal/mnldinf/src/mnldinf_utility.c
+++ b/src/connectivity/gps/2.0/gps_hal/mnldinf/src/mnldinf_utility.c
@@ -720,19 +720,24 @@
 void mnldinf_wake_lock_take() {
 #if !defined(__LIBMNL_SIMULATOR__)    //no permission to open wake_lock on Linux
     time_t time_cur = 0;
+    int timer_ret;
+    int mutex_ret = 0;
+
+    mutex_ret = mnldinf_wakeup_mutex_lock();
     time_cur = mnldinf_get_time_in_millisecond();
 
     if(time_cur > (wlock_ctx.time_last_refresh + MNLDINF_WAKE_LOCK_LATENCY)) {
-        int mutex_ret = 0;
-        mnldinf_stop_timer(wlock_ctx.unlock_timer);
-        mutex_ret = mnldinf_wakeup_mutex_lock();
+        timer_ret = mnldinf_stop_timer(wlock_ctx.unlock_timer);
+        LOGD("hal stop unlock_timer, ret=%d", timer_ret);
         if(wlock_ctx.wake_lock_acquired == false) {
             wlock_ctx.wake_lock_acquired = true;
             mnldinf_wake_lock();
+            LOGD("mnldinf_wake_lock");
         }
-        if(mutex_ret == 0) {
-            mnldinf_wakeup_mutex_unlock();
-        }
+    }
+
+    if(mutex_ret == 0) {
+        mnldinf_wakeup_mutex_unlock();
     }
 #endif
 }
@@ -740,12 +745,22 @@
 void mnldinf_wake_lock_give() {
 #if !defined(__LIBMNL_SIMULATOR__)    //no permission to open wake_lock on Linux
     time_t time_cur = 0;
+    int timer_ret;
+    int mutex_ret = 0;
+
+    mutex_ret = mnldinf_wakeup_mutex_lock();
+
     //delay to do wake_unlock to ensure the msg can be deliveried to other process
     time_cur = mnldinf_get_time_in_millisecond();
     if(time_cur > (wlock_ctx.time_last_refresh + MNLDINF_WAKE_LOCK_LATENCY)) {  //Only refresh timer when over latency time
-        mnldinf_start_timer(wlock_ctx.unlock_timer, MNLDINF_WAKE_LOCK_TIMEOUT);
+        timer_ret = mnldinf_start_timer(wlock_ctx.unlock_timer, MNLDINF_WAKE_LOCK_TIMEOUT);
+        LOGD("hal start unlock_timer, ret=%d", timer_ret);
         wlock_ctx.time_last_refresh = mnldinf_get_time_in_millisecond();
     }
+
+    if(mutex_ret == 0) {
+        mnldinf_wakeup_mutex_unlock();
+    }
 #endif
 }
 
@@ -757,6 +772,7 @@
     if(wlock_ctx.wake_lock_acquired == true) {
         wlock_ctx.wake_lock_acquired = false;
         mnldinf_wake_unlock();
+        LOGD("mnldinf_wake_unlock");
     }
     if(mutex_ret == 0) {
         mnldinf_wakeup_mutex_unlock();
@@ -819,10 +835,10 @@
     }
     LOGD("wake_lock:[%s]", buff_read);
     close(fd);
-    retry_timer = wlock_ctx.unlock_timer;
-    wlock_ctx.unlock_timer = INVALID_TIMERID;
-    mnldinf_deinit_timer(retry_timer);
-    pthread_mutex_destroy(&wlock_ctx.mutex);
+    // retry_timer = wlock_ctx.unlock_timer;
+    // wlock_ctx.unlock_timer = INVALID_TIMERID;
+    // mnldinf_deinit_timer(retry_timer);
+    // pthread_mutex_destroy(&wlock_ctx.mutex);
 #endif
 }
 
diff --git a/src/connectivity/gps/2.0/gps_hal/src/gpshal.c b/src/connectivity/gps/2.0/gps_hal/src/gpshal.c
index 9ddfa3d..3240013 100644
--- a/src/connectivity/gps/2.0/gps_hal/src/gpshal.c
+++ b/src/connectivity/gps/2.0/gps_hal/src/gpshal.c
@@ -86,7 +86,7 @@
     .vzw_debug_cbs     = NULL,
     .gps_name          = "MTK_MNLD_default,MNL_VER_default",
     .proxy_apps        = {0},
-    .mnl_retry_timer   = NULL,
+    .mnl_retry_timer   = INVALID_TIMERID,
 };
 
 #ifdef FREQUENCE_START
diff --git a/src/connectivity/gps/2.0/gps_hal/src/gpshal_worker.c b/src/connectivity/gps/2.0/gps_hal/src/gpshal_worker.c
index 8b07e58..bd2b62b 100644
--- a/src/connectivity/gps/2.0/gps_hal/src/gpshal_worker.c
+++ b/src/connectivity/gps/2.0/gps_hal/src/gpshal_worker.c
@@ -639,6 +639,7 @@
    // GPSHAL_DEBUG_FUNC_SCOPE;
     struct epoll_event events[MAX_EPOLL_EVENT];
     UNUSED(arg);
+    mnldinf_wake_lock_init();
 
     while (true) {
         int i;
diff --git a/src/connectivity/gps/2.0/gps_hal/src/gpsinf.c b/src/connectivity/gps/2.0/gps_hal/src/gpsinf.c
index 4de9894..88e1b2b 100644
--- a/src/connectivity/gps/2.0/gps_hal/src/gpsinf.c
+++ b/src/connectivity/gps/2.0/gps_hal/src/gpsinf.c
@@ -323,7 +323,7 @@
 static int gpsinf_init(GpsCallbacks_ext* callbacks) {
     // GPSHAL_DEBUG_FUNC_SCOPE2(g_gpshal_ctx.mutex_gps_state_intent);
 
-    mnldinf_wake_lock_init();
+    // mnldinf_wake_lock_init();
 
     if (gpshal_gpscbs_save(callbacks) != 0) {
         return -1;    //  error
diff --git a/src/connectivity/gps/2.0/mtk_mnld/utility/src/mtk_lbs_utility.c b/src/connectivity/gps/2.0/mtk_mnld/utility/src/mtk_lbs_utility.c
old mode 100644
new mode 100755
index 790982e..1921c42
--- a/src/connectivity/gps/2.0/mtk_mnld/utility/src/mtk_lbs_utility.c
+++ b/src/connectivity/gps/2.0/mtk_mnld/utility/src/mtk_lbs_utility.c
@@ -1254,19 +1254,24 @@
 void mnld_wake_lock_take() {
 #if !defined(__LIBMNL_SIMULATOR__)    //no permission to open wake_lock on Linux
     UINT64 time_cur = 0;
+    int timer_ret;
+    int mutex_ret = 0;
+
+    mutex_ret = mnld_wakeup_mutex_lock();
     time_cur = get_time_in_millisecond();
 
     if(time_cur > (wlock_ctx.time_last_refresh + MNLD_WAKE_LOCK_LATENCY)) {
-        int mutex_ret = 0;
-        stop_timer(wlock_ctx.unlock_timer);
-        mutex_ret = mnld_wakeup_mutex_lock();
+        timer_ret = stop_timer(wlock_ctx.unlock_timer);
+        LOGD("stop unlock_timer, ret=%d", timer_ret);
         if(wlock_ctx.wake_lock_acquired == false) {
             wlock_ctx.wake_lock_acquired = true;
             mnld_wake_lock();
+            LOGD("mnld_wake_lock");
         }
-        if(mutex_ret == 0) {
-            mnld_wakeup_mutex_unlock();
-        }
+    }
+
+    if(mutex_ret == 0) {
+        mnld_wakeup_mutex_unlock();
     }
 #endif
 }
@@ -1274,12 +1279,21 @@
 void mnld_wake_lock_give() {
 #if !defined(__LIBMNL_SIMULATOR__)    //no permission to open wake_lock on Linux
     UINT64 time_cur = 0;
+    int timer_ret;
+    int mutex_ret = 0;
+
+    mutex_ret = mnld_wakeup_mutex_lock();
     //delay to do wake_unlock to ensure the msg can be deliveried to other process
     time_cur = get_time_in_millisecond();
     if(time_cur > (wlock_ctx.time_last_refresh + MNLD_WAKE_LOCK_LATENCY)) {  //Only refresh timer when over latency time
-        start_timer(wlock_ctx.unlock_timer, MNLD_WAKE_LOCK_TIMEOUT);
+        timer_ret = start_timer(wlock_ctx.unlock_timer, MNLD_WAKE_LOCK_TIMEOUT);
+        LOGD("start unlock_timer, ret=%d", timer_ret);
         wlock_ctx.time_last_refresh = get_time_in_millisecond();
     }
+
+    if(mutex_ret == 0) {
+        mnld_wakeup_mutex_unlock();
+    }
 #endif
 }
 
@@ -1291,6 +1305,7 @@
     if(wlock_ctx.wake_lock_acquired == true) {
         wlock_ctx.wake_lock_acquired = false;
         mnld_wake_unlock();
+        LOGD("mnld_wake_unlock");
     }
     if(mutex_ret == 0) {
         mnld_wakeup_mutex_unlock();
diff --git a/src/lynq/framework/lynq-ril-service/src/mtk_ril_unsol_commands.h b/src/lynq/framework/lynq-ril-service/src/mtk_ril_unsol_commands.h
index 5c461f4..bdd73e2 100755
--- a/src/lynq/framework/lynq-ril-service/src/mtk_ril_unsol_commands.h
+++ b/src/lynq/framework/lynq-ril-service/src/mtk_ril_unsol_commands.h
@@ -50,3 +50,4 @@
 { RIL_UNSOL_ECC_NUM,responseString, WAKE_PARTIAL},
 {RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR, responseStrings, WAKE_PARTIAL},
 {RIL_UNSOL_CALL_INFO_INDICATION, responseStrings, WAKE_PARTIAL},
+{RIL_UNSOL_TELEPHONY_RESTART, responseVoid, WAKE_PARTIAL}
diff --git a/src/lynq/framework/lynq-ril-service/src/ril.cpp b/src/lynq/framework/lynq-ril-service/src/ril.cpp
index ccd0e01..20fcf22 100755
--- a/src/lynq/framework/lynq-ril-service/src/ril.cpp
+++ b/src/lynq/framework/lynq-ril-service/src/ril.cpp
@@ -26,6 +26,7 @@
 #include <hardware_legacy/power.h>
 #include <vendor-ril/telephony/ril.h>
 #include <telephony/ril_cdma_sms.h>
+#include <telephony/mtk_ril_sp.h>
 #include <cutils/jstring.h>
 #include <telephony/record_stream.h>
 #include <utils/SystemClock.h>
@@ -5396,6 +5397,7 @@
         case LYNQ_REQUEST_SET_DEFAULT_SIM_ALL:return "SET_DEFAULT_SIM_ALL";
         case LYNQ_REQUEST_CHANGE_SCREEN_STATE:return "LYNQ_REQUEST_CHANGE_SCREEN_STATE";/*jb.qi add for two sim sleep 2022/9/19*/
         case LYNQ_REQUEST_CHANGE_RADIO:return "LYNQ_REQUEST_CHANGE_RADIO";/*lei add for factory test of sleep 2022/9/19*/
+        case RIL_UNSOL_TELEPHONY_RESTART:return "RIL_UNSOL_TELEPHONY_RESTART";/*xy.he add for t800 ril service 2023/10/23*/
         /*warren add for t800 ril service 2022/1/22 end*/
         default: return "<unknown request>";
     }
@@ -5694,6 +5696,7 @@
         case RIL_UNSOL_ECALL_MSDHACK: return 1;
         case RIL_UNSOL_TX_POWER: return 1;
         case RIL_UNSOL_NETWORK_INFO: return 1;
+        case RIL_UNSOL_TELEPHONY_RESTART: return 1;
 #ifdef ECALL_SUPPORT
         case RIL_UNSOL_ECALL_INDICATIONS: return 1;
 #endif /*ECALL_SUPPORT*/
diff --git a/src/lynq/lib/liblynq-data/lynq_data.cpp b/src/lynq/lib/liblynq-data/lynq_data.cpp
index b7498a6..def2a32 100755
--- a/src/lynq/lib/liblynq-data/lynq_data.cpp
+++ b/src/lynq/lib/liblynq-data/lynq_data.cpp
@@ -26,6 +26,7 @@
 
 #define LYNQ_DATA_UCI_BUF 258
 #define LYNQ_DATA_TIME_OUT 1000*120
+#define TELEPHONY_RESTART 10
 
 
 using ::android::Parcel;
@@ -65,6 +66,7 @@
 int lynq_data_socket_server_addr_len;
 
 int lynq_data_call_change_id = -1;
+int lynq_telephony_restart_g = 0;
 pthread_t lynq_data_tid =-1;
 static pthread_mutex_t s_data_call_state_change_mutex = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t s_data_call_state_change_cond = PTHREAD_COND_INITIALIZER;
@@ -115,6 +117,8 @@
 lynq_data_call_response_v11_t lynq_data_call_lists[LYNQ_APN_CHANNEL_MAX] = {};
 int lynq_data_call = 0;
 
+int radio_switch(int status);
+
 int getLynqApnID(char apnType[])
 {
     int ret = 0;
@@ -560,6 +564,7 @@
 
         case LYNQ_URC_MODIFY_APNDB:
         case LYNQ_URC_RESET_APNDB:
+        case LYNQ_TELEPHONY_RESTART:
             return true;                
         default:
             return false;
@@ -796,6 +801,23 @@
                 }
                 free(urc_msg);
             }
+        case LYNQ_TELEPHONY_RESTART:
+            {
+                if(slot_id == 0)
+                {
+                    RLOGI("data has received telephony has restart");
+                    RLOGI("handle set to 10");
+                    lynq_telephony_restart_g = 1;
+                    pthread_mutex_lock(&s_lynq_urc_vector_mutex);
+                    s_data_urc_wait_list.push_back(TELEPHONY_RESTART);
+                    pthread_mutex_unlock(&s_lynq_urc_vector_mutex);
+                    radio_switch(0);
+                    sleep(1);
+                    radio_switch(1);
+                    sleep(1);
+                    sendSignalPdnChange();
+                }
+            }
         default:
             break;
     }
@@ -813,7 +835,7 @@
 }
 int get_imsi();
 int check_apn_status();
-int radio_switch(int status);
+
 int lynq_init_data(int uToken)
 {
     if (g_lynq_data_init_flag == 1)
diff --git a/src/lynq/lib/liblynq-data/lynq_data_urc.h b/src/lynq/lib/liblynq-data/lynq_data_urc.h
index 7ac4f75..59f9f9d 100755
--- a/src/lynq/lib/liblynq-data/lynq_data_urc.h
+++ b/src/lynq/lib/liblynq-data/lynq_data_urc.h
@@ -16,6 +16,7 @@
 #define LYNQ_REQUEST_SET_DTMF_VOLUME (LYNQ_REQUEST_VENDOR_BASE +3)
 #define LYNQ_URC_MODIFY_APNDB (LYNQ_URC_VENDOR_BASE+4)
 #define LYNQ_URC_RESET_APNDB (LYNQ_URC_VENDOR_BASE+5)
+#define LYNQ_TELEPHONY_RESTART 3113
 
 typedef struct{
     int resp_type;
diff --git a/src/lynq/lib/liblynq-wifi6/scripts/start_stop_ap.sh b/src/lynq/lib/liblynq-wifi6/scripts/start_stop_ap.sh
index ff0c59c..441a0ee 100755
--- a/src/lynq/lib/liblynq-wifi6/scripts/start_stop_ap.sh
+++ b/src/lynq/lib/liblynq-wifi6/scripts/start_stop_ap.sh
@@ -17,12 +17,12 @@
         echo "dhcp-authoritative" >> $conf_file
 	echo "dhcp-range=192.168.15.2,192.168.15.14,255.255.255.240,1h"  >> $conf_file
 	echo "dhcp-option=3,192.168.15.1"  >> $conf_file
-	echo "dhcp-option=6,192.168.15.1"  >> $conf_file
+	echo "dhcp-option=6,192.168.15.1,114.114.114.114"  >> $conf_file
 	echo "dhcp-range=192.168.15.2,192.168.15.14,255.255.255.240,1h"  >> $conf_file
 	echo "dhcp-leasefile=/run/wg870/ap0.lease" >> $conf_file
 	ps -eo "%p %a" | grep "/usr/bin/dnsmasq -x /run/wg870/dnsmasq.pid" | grep -v grep 
 	if [ $? != 0 ]; then
-		/usr/bin/dnsmasq -x /run/wg870/dnsmasq.pid -7 /run/wg870/dnsmasq.d --local-service -C $conf_file -r /run/wg870
+		/usr/bin/dnsmasq -x /run/wg870/dnsmasq.pid -7 /run/wg870/dnsmasq.d --local-service -C $conf_file -r /run/wg870 --dhcp-broadcast
 	fi
 
 elif [ "$1" == "stop" ]; then
diff --git a/src/telephonyware/3.0/libvendor-ril/mtk-rilproxy/socket_channel.cpp b/src/telephonyware/3.0/libvendor-ril/mtk-rilproxy/socket_channel.cpp
index 15a17ab..dca7898 100755
--- a/src/telephonyware/3.0/libvendor-ril/mtk-rilproxy/socket_channel.cpp
+++ b/src/telephonyware/3.0/libvendor-ril/mtk-rilproxy/socket_channel.cpp
@@ -647,7 +647,11 @@
 #if defined(TELEPHONYWARE)
 static void send_restart_unsol(RIL_SOCKET_ID slot){
 #if defined(ANDROID_MULTI_SIM) && !defined(MODE_DSSS)
+    RLOGI("start send RIL_UNSOL_TELEPHONY_RESTART111111");
     RFX_onUnsolicitedResponse(RIL_UNSOL_TELEPHONY_RESTART, NULL, 0, slot);
+#else
+    //RFX_onUnsolicitedResponse(RIL_UNSOL_TELEPHONY_RESTART, NULL, 0, slot);
+    RLOGI("don't defined ANDROID_MULIT_SIM and MODE_DSSS");
 #endif
     return;
 }
@@ -657,6 +661,11 @@
 void *ril_socket_reader_looper(void *arg) {
     while (1) {
         RilpSocket *socket = (RilpSocket *)arg;
+    #if defined(TELEPHONYWARE)
+        RLOGI("[ril_socket_reader_looper]TELEPHONY HAS RESTART");
+        RLOGI("has defined TELEPHONYWARE");
+        send_restart_unsol(socket->id);
+    #endif
         socket->readerLooper();
         rfx_close_socket(socket->group, socket->id);