[Bugfix][T106BUG-489][AUTOSUSPEND]add sleep notice to lynq-ril-service

Only Configure :No
Affected branch: master
Affected module: AUTOSUSPEND
Is it affected on both ZXIC and MTK:only ZXIC
Self-test: Yes
Doc Update: No

Change-Id: I93653174a68c86fdaa1e0ba494dfc875657478a4
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend_wakeup_count.c b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend_wakeup_count.c
index 3f01e93..c5ac426 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend_wakeup_count.c
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/autosuspend_wakeup_count.c
@@ -28,6 +28,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/time.h>
+#include <include/lynq_sim.h>
 
 #include <unistd.h>
 #include <dlfcn.h>
@@ -152,7 +153,6 @@
   return;
 }
 
-
  void init_sim_func()
 {
     int res;
@@ -314,7 +314,11 @@
 int t106_early_suspend(void)
 {
     int ret;
+
     RLOGD("t106_early_suspend start\n");
+    ret=lynq_sleep_status(0);
+    RLOGD("lynq_get_sleep_status ret=%d\n", ret);
+
     system("zlog_nvctrl -m 1");
     ret = t106_set_whitelist();
     if(ret)
@@ -347,6 +351,9 @@
     }
     system("zlog_nvctrl -m 0");
 
+    ret=lynq_sleep_status(1);
+    RLOGD("lynq_get_sleep_status ret=%d\n", ret);
+
     return NULL;
 }
 #endif
@@ -650,7 +657,7 @@
     int ret;
     char buf[80];
     char timeout_str[100]="100000";
-
+    pid = getpid();
     //if (property_get("sys.autosuspend.timeout", timeout_str, NULL))
     {
         possible_max_sleep_time = atoi(timeout_str);
@@ -693,6 +700,15 @@
         ALOGD("sc_mnet_whitelist_init failed.\n");
         return NULL;
     }
+    ret = lynq_sim_init((int)pid);
+    if(ret == 0)
+    {
+        ALOGD("Run lynq_sim_init\n");
+    }
+    else
+    {
+        return NULL;
+    }
     ret = pthread_create(&suspend_thread, NULL, suspend_thread_func, NULL);
     if (ret) {
         strerror_r(ret, buf, sizeof(buf));
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/makefile b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/makefile
index a2eba39..ca263bf 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/makefile
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/files/makefile
@@ -50,7 +50,7 @@
     -lsctel \
     -latutils \
     -latreg \
-    
+    -llynq-sim \
 
 
 SOURCES = $(wildcard *.c )
diff --git a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/lynq-autosuspend.bb b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/lynq-autosuspend.bb
index 96c90de..a3df67f 100755
--- a/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/lynq-autosuspend.bb
+++ b/cap/zx297520v3/sources/meta-zxic-custom/recipes-lynq/lynq-autosuspend/lynq-autosuspend.bb
@@ -22,7 +22,7 @@
 LOCAL_C_INCLUDES = "-I. "
 
 DEPENDS = "liblynq-log liblynq-uci"
-DEPENDS += "${@bb.utils.contains('TARGET_PLATFORM', 'mt2735', 'audio-mixer-ctrl streamer1.0', '', d)} liblynq-log liblynq-uci libbsp libsctel libatutils libatreg"
+DEPENDS += "${@bb.utils.contains('TARGET_PLATFORM', 'mt2735', 'audio-mixer-ctrl streamer1.0', '', d)} liblynq-log liblynq-uci libbsp libsctel libatutils libatreg liblynq-sim"
 LOCAL_LIBS = "-L. -ldl -lstdc++ -lpthread -llog"
 SOURCES = "$(wildcard *.c )"
 
diff --git a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/commands.h b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/commands.h
index 384f916..168d776 100755
--- a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/commands.h
+++ b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/commands.h
@@ -205,6 +205,7 @@
     {"LYNQ_REQUEST_LIST_SMS_FROM_MEMORY",listSmsToMemory, "write sms to memory",LYNQ_REQUEST_LIST_SMS_FROM_MEMORY},
     {"LYNQ_REQUEST_CHANGE_SCREEN_STATE",getScreenState,"lynq get Screen State",LYNQ_REQUEST_CHANGE_SCREEN_STATE},/*jb.qi change for two sim suspend 2022/9/19 */
     {"LYNQ_REQUEST_CHANGE_RADIO",setRadioPower,"setRadioPower",LYNQ_REQUEST_CHANGE_RADIO},/*lei add for both radio on/off */
+    {"LYNQ_REQUEST_CHANGE_SLEEP_STATE",getSleepState,"lynq get Sleep State",LYNQ_REQUEST_CHANGE_SLEEP_STATE},/*jb.qi change for suspend 2024/2/23 */
     /*Warren change for t800 ril service 2022/1/18 end*/
 
     #ifdef C2K_SUPPORT
diff --git a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/lynq_interface.h b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/lynq_interface.h
index 4a94b10..95a50ce 100755
--- a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/lynq_interface.h
+++ b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/lynq_interface.h
@@ -23,6 +23,8 @@
 #define LYNQ_REQUEST_OOS_DEEP_SLEEP_RECOVER_TIMER_INTERVAL (LYNQ_REQUEST_VENDOR_BASE +13)
 #define LYNQ_REQUEST_CHANGE_SCREEN_STATE (LYNQ_REQUEST_VENDOR_BASE + 14)/*jb.qi add for two sim suspend 2022/9/19*/
 #define LYNQ_REQUEST_CHANGE_RADIO (LYNQ_REQUEST_VENDOR_BASE + 15)
+#define LYNQ_REQUEST_CHANGE_SLEEP_STATE (LYNQ_REQUEST_VENDOR_BASE + 16)/*jb.qi change for suspend 2024/2/23 start*/
+
 #ifdef ECALL_SUPPORT
 #define RIL_UNSOL_ECALL_T2_TIMER_OUT  9000
 #define RIL_UNSOL_ECALL_T5_TIMER_OUT  9001
diff --git a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/mtk_ril_commands.h b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/mtk_ril_commands.h
index d4a1fdb..2d17ee3 100755
--- a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/mtk_ril_commands.h
+++ b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/mtk_ril_commands.h
@@ -35,6 +35,7 @@
 
 { RIL_REQUEST_SET_TRM, dispatchInts, responseVoid},
 { RIL_REQUEST_SET_IMS_ENABLE,dispatchInts,responseVoid},
+{ LYNQ_REQUEST_CHANGE_SLEEP_STATE,dispatchInts,responseVoid},/*jb.qi change for suspend 2024/2/23 start*/
 //eCall
 #ifdef ECALL_SUPPORT
 { RIL_REQUEST_ECALL_FAST_MAKE_ECALL,dispatchFastEcall,responseVoid},
diff --git a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/ril.cpp b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/ril.cpp
index 4c51a16..0f5785c 100755
--- a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/ril.cpp
+++ b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/ril.cpp
@@ -5268,6 +5268,7 @@
         case LYNQ_REQUEST_CHANGE_RADIO:return "LYNQ_REQUEST_CHANGE_RADIO";/*lei add for factory test of sleep 2022/9/19*/
         case RIL_REQUEST_GET_MSISDN:return "RIL_REQUEST_GET_MSISDN";
         case RIL_REQUEST_RESET_SIMCARD:return "RIL_REQUEST_RESET_SIMCARD";
+        case LYNQ_REQUEST_CHANGE_SLEEP_STATE: return "LYNQ_REQUEST_CHANGE_SLEEP_STATE";/*jb.qi change for suspend 2024/2/23 */
         /*warren add for t800 ril service 2022/1/22 end*/
         default: return "<unknown request>";
     }
@@ -5537,6 +5538,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 LYNQ_REQUEST_CHANGE_SLEEP_STATE:return "LYNQ_REQUEST_CHANGE_SLEEP_STATE";/*jb.qi add for two sim sleep 2022/9/19*/
         case RIL_REQUEST_GET_MSISDN: return "GET MSISDN";
         case RIL_REQUEST_RESET_SIMCARD: return "RESET SIMCARD";
         /*warren add for t800 ril service 2022/1/22 end*/
@@ -6243,7 +6245,7 @@
                     waitResponse(waittoken);
                     memset(Time_buf,0,sizeof(Time_buf));
                     GetTimeString(Time_buf);
-                    FUNCTION_RETURN(Time_buf,requestToString(request));          
+                    FUNCTION_RETURN(Time_buf,requestToString(request));
                     bzero(buffer, LYNQ_SOCKET_BUFFER);
 
                 }
diff --git a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/stateManager/stateManager.cpp b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/stateManager/stateManager.cpp
index 6a7c251..0a66abf 100755
--- a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/stateManager/stateManager.cpp
+++ b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/stateManager/stateManager.cpp
@@ -111,7 +111,7 @@
     lynq_get_value(LYNQ_UCI_FILE, LYNQ_UCI_SECTION, LYNQ_UCI_NETLED_KEY, netled_on);
     if(!atoi(netled_on))
         return -1;
-    mbtk_netled_state_update(screen_state==0 ? GPIO_NETLED_AP_GOINGSLEEP : GPIO_NETLED_AP_WAKEUP);	
+    mbtk_netled_state_update(screen_state==0 ? GPIO_NETLED_AP_GOINGSLEEP : GPIO_NETLED_AP_WAKEUP);
     usleep(wait_led_update_effective_timer_ms*1000);
 #endif
 
@@ -120,6 +120,37 @@
     return 0;
 }
 
+/*jb.qi change for suspend 2024/2/23 start*/
+int getSleepState(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
+{
+    RLOGD("start getSleepState\n");
+    android::Parcel p;
+    int sent;
+    p.writeInt32(0);
+    p.writeInt32(pRI->uToken);
+    p.writeInt32(pRI->pCI->requestNumber);
+    p.writeInt32(socket_id);
+    p.writeInt32(0);//error
+    int sleep_state= atoi(argv[1]);
+    if(sleep_state == 0)
+    {
+        RLOGD("start to sleep\n");
+    }
+    else if(sleep_state ==1)
+    {
+        RLOGD("start to resume\n");
+    }
+    else
+    {
+        return -1;
+    }
+    android::LYNQ_RIL_respSocket(p, (void *)pRI);
+    free(pRI);
+    return 0;
+
+}
+/*jb.qi change for suspend 2024/2/23 end*/
+
 //RIL_REQUEST_SET_TRM
 int setTRM(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
 {
diff --git a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/stateManager/stateManager.h b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/stateManager/stateManager.h
index b96b5ec..da9e083 100755
--- a/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/stateManager/stateManager.h
+++ b/cap/zx297520v3/src/lynq/framework/lynq-ril-service/src/stateManager/stateManager.h
@@ -36,7 +36,7 @@
 #define __RIL_STAM__
 #include  <vendor-ril/telephony/ril.h>
 #include  "common.h"
-
+int getSleepState(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);/*jb.qi change for suspend 2024/2/23 */
 int getDeviceIdentity(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);
 int getIMEI(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);
 int getIMEISV(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI);
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-sim/include/lynq_sim.h b/cap/zx297520v3/src/lynq/lib/liblynq-sim/include/lynq_sim.h
index bf271f1..8bf9069 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-sim/include/lynq_sim.h
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-sim/include/lynq_sim.h
@@ -27,6 +27,9 @@
 int lynq_query_phone_number(char buf[]);
 int lynq_switch_card(int slot);
 int lynq_screen(int num);
+#ifdef MOBILETEK_TARGET_PLATFORM_T106
+int lynq_sleep_status(int sleep_state);
+#endif
 int lynq_get_imei(char buf[]);
 int lynq_get_imei_and_sv(char imei[],char sv[]);
 
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-sim/makefile b/cap/zx297520v3/src/lynq/lib/liblynq-sim/makefile
index 219bda7..0eafd49 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-sim/makefile
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-sim/makefile
@@ -17,6 +17,10 @@
 LOCAL_CFLAGS += -DBINDER_IPC_32BIT=1 -DHAVE_ENDIAN_H -DHAVE_PTHREADS -DHAVE_SYS_UIO_H -DHAVE_POSIX_FILEMAP -DHAVE_STRLCPY -DHAVE_PRCTL -DHAVE_MEMSET16 -DHAVE_MEMSET32 -DANDROID_SMP=0 -DMOBILETEK_TARGET_PLATFORM_T106 -Wl,-Bsymbolic
 endif
 
+ifeq ($(strip $(TARGET_PLATFORM)), T106)
+    LOCAL_CFLAGS += -DMOBILETEK_TARGET_PLATFORM_T106
+endif
+
 $(warning ################# lynq sim ROOT: $(ROOT),includedir:$(includedir))
 LOCAL_PATH   = .
 
diff --git a/cap/zx297520v3/src/lynq/lib/liblynq-sim/src/lynq_sim.cpp b/cap/zx297520v3/src/lynq/lib/liblynq-sim/src/lynq_sim.cpp
index 75a1d0b..cfddb6c 100755
--- a/cap/zx297520v3/src/lynq/lib/liblynq-sim/src/lynq_sim.cpp
+++ b/cap/zx297520v3/src/lynq/lib/liblynq-sim/src/lynq_sim.cpp
@@ -29,6 +29,8 @@
 #define LYNQ_REQUEST_SET_DEFAULT_SIM_ALL 8008
 #define LYNQ_REQUEST_CHANGE_SCREEN_STATE 8014 /*add for two sim suspend on 20220919*/
 #define LYNQ_REQUEST_CHANGE_RADIO 8015
+#define LYNQ_REQUEST_CHANGE_SLEEP_STATE 8016
+
 #define MAX_LEN 1024*8
 #define MAX_NUM 10
 #define LOG_TAG "LYNQ_SIM"
@@ -44,7 +46,7 @@
     char param[MAX_LEN];
 }lynq_client_t;
 
-/* socket文件描述符 */ 
+/* socket file descriptor*/ 
 int len_addr_serv;
 struct sockaddr_in addr_serv;
 static int sock_fd = 0;
@@ -703,6 +705,36 @@
     return res;
 }
 
+#ifdef MOBILETEK_TARGET_PLATFORM_T106
+/**@breif    notice ril the sleep state
+*param       num type: [IN]  sleep_state,0:sleep,1:resume
+*param       ret type: [OUT] result,0:success,other:fail
+*return int
+*/
+int lynq_sleep_status(int sleep_state)
+{
+    RLOGD("start lynq_get_sleep_status\n");
+    if(g_lynq_sim_init_flag == 0)
+    {
+        return -1;
+    }
+    if(!judge(sleep_state))
+        return -1;
+    Parcel p;
+    int res = lynq_send_common_request(&p,LYNQ_REQUEST_CHANGE_SLEEP_STATE,1,1,"%d\n",sleep_state);
+    if(res != 0)
+    {
+        RLOGD("function %s execute error\n", __FUNCTION__);
+        return res;
+    }
+    else
+    {
+        RLOGD("function %s execute success\n", __FUNCTION__);
+    }
+    return res;
+}
+#endif
+
 /**@breif    change screen state
 *param       num type: [IN]  screen_state,0:close,1:open
 *param       ret type: [OUT] result,0:success,other:fail