[Feature][T3TSK-8][AT]Optimize 103 Sleep
[Feature][T3TSK-9][System]Optimize the ATSVC service

Change-Id: I629520b62f1ee1ad11003321c902b62e44c2a3a4
diff --git a/src/lynq/framework/lynq-atsvc/src/lynq-atsvc.service b/src/lynq/framework/lynq-atsvc/src/lynq-atsvc.service
index a39f000..5465d15 100755
--- a/src/lynq/framework/lynq-atsvc/src/lynq-atsvc.service
+++ b/src/lynq/framework/lynq-atsvc/src/lynq-atsvc.service
@@ -1,13 +1,14 @@
 [Unit]
 Description=lynq ril service
-After=wmtd.service
+After=bach_telephony.service
+Requires=bach_telephony.service
 
 [Service]
 StandardOutput=syslog+console
-Type=oneshot
+Type=simple
 RemainAfterExit=no
 ExecStart=/usr/bin/lynq-atsvc
+Restart=always
 
 [Install]
-Alias=pwrild
 WantedBy=multi-user.target
\ No newline at end of file
diff --git a/src/lynq/framework/lynq-atsvc/src/lynq_common.cpp b/src/lynq/framework/lynq-atsvc/src/lynq_common.cpp
index 11a0cf1..c2a3a75 100755
--- a/src/lynq/framework/lynq-atsvc/src/lynq_common.cpp
+++ b/src/lynq/framework/lynq-atsvc/src/lynq_common.cpp
@@ -725,45 +725,40 @@
     return;
 }
 
+void lynq_sendRequestToMd(int request, int id)
+{
+    RequestInfo* info = creatRILInfoAndInit(request, INIT, (RIL_SOCKET_ID) ((id)));
+    switch(request){
+        case RIL_REQUEST_SCREEN_STATE:
+        {
+            char *argv[2] = {0};
+            argv[1] = "0";//default value
+            getScreenState(2, argv, (RIL_SOCKET_ID) ((id)), info);
+            break;
+        }
+        default:
+            RLOGE("don't support  %d in init", id);
+            if(info) {
+                free(info);
+            }
+    }
+}
+
+
 /**
  * @brief auto_suspend
  * @param  argv        [Type]:in     My Param doc
  */
 void auto_suspend(int argv)
 {
-    // pthread_t thid;
-    // pthread_attr_t a;
-    // pthread_attr_init(&a);
-    // pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED);
-    // int ret = pthread_create(&thid, &a, thread_test, NULL);
-    // if(ret != 0){
-    //     RLOGD("pthread_create error!!!");
-    //     return;
-    // }
     system("echo 11 | emdlogger_ctrl");
     int res = system("mdlogctl stop");
-    //printf("auto_suspend mdlogctl stop ret %d\n", res);
     res = system("echo 0 > /dev/wmtWifi");
-    //printf("auto_suspend echo 0 > /dev/wmtWifi ret %d\n", res);
     res = system("echo 7 9 0 > /proc/driver/wmt_dbg");
-    //printf("auto_suspend echo 7 9 0 > /proc/driver/wmt_dbg ret %d\n", res);
-    /*If have two cards*/
-    /*Query the current card*/
-    int id = get_default_sim_all();
-    //printf("FUNCIONT %s LINE %d\n", __FUNCTION__, __LINE__);
-    lynq_switch_card("1");
-    //printf("FUNCIONT %s LINE %d\n", __FUNCTION__, __LINE__);
-    lynq_shutdown_modem();
-    //printf("FUNCIONT %s LINE %d\n", __FUNCTION__, __LINE__);
-    lynq_switch_card("0");
-    //printf("FUNCIONT %s LINE %d\n", __FUNCTION__, __LINE__);
-    lynq_shutdown_modem();
-    //printf("FUNCIONT %s LINE %d\n", __FUNCTION__, __LINE__);
-    if(id == RIL_SOCKET_2)
+    for(int i = 0; i < 2; i++)
     {
-        lynq_switch_card("1");
+        lynq_sendRequestToMd(RIL_REQUEST_SCREEN_STATE, i);
     }
-    /*If have two cards*/
     if(argv==1)
     {
         //autosleep
diff --git a/src/lynq/framework/lynq-atsvc/src/lynq_common.h b/src/lynq/framework/lynq-atsvc/src/lynq_common.h
index 4cf1b15..4990550 100755
--- a/src/lynq/framework/lynq-atsvc/src/lynq_common.h
+++ b/src/lynq/framework/lynq-atsvc/src/lynq_common.h
@@ -141,6 +141,7 @@
 int lynqParseUsbCommand(const char* cmd,char *argv[],char test[],char* parser_buf,int maxArgc);
 void auto_suspend(int argv);
 void check_autosleep(int testnum);
+void lynq_sendRequestToMd(int request, int id);
 
 int routeCmd(int request);
 
diff --git a/src/lynq/framework/lynq-atsvc/src/main.cpp b/src/lynq/framework/lynq-atsvc/src/main.cpp
index 6529ab2..2c85896 100755
--- a/src/lynq/framework/lynq-atsvc/src/main.cpp
+++ b/src/lynq/framework/lynq-atsvc/src/main.cpp
@@ -108,10 +108,7 @@
 
 void signal_handler_fun(int signum) {
     RLOGD("signal_handler_fun catch signal %d\n", signum);
-    //printf("signal_handler_fun catch signal %d\n", signum);
     check_autosleep(signum);
-    //RLOGD("signal_handler_fun catch signal %d %d\n", signum, __LINE__);
-    //printf("signal_handler_fun catch signal %d %d\n", signum, __LINE__);
     return;
 }
 
@@ -144,18 +141,16 @@
     #if 0
     /*ensure inject 2G/3G/4G*/
     int slot_id = get_default_sim_all(); 
-    int i = 3;
+    int i = 10;
     while (i)
     {
         if(!sleep_flag)
         {
             RLOGD("function %s no network\n", __FUNCTION__);
-            printf("%s no network\n", __FUNCTION__);
         }
         else
         {
             RLOGD("%s network is online\n", __FUNCTION__);
-            printf("%s network is online\n",__FUNCTION__);
             break;
         }
         //query_network_state(RIL_REQUEST_DATA_REGISTRATION_STATE, slot_id);
@@ -163,7 +158,6 @@
         sleep(1);
         i--;
     }
-    printf("%s i %d\n",__FUNCTION__, i);
     #endif
     return 1;
 }
@@ -193,7 +187,6 @@
         if(g_lynq_mwakeupcfg != 0)//means user must be configed it
         {
             RLOGD("means user must be configed it go to sleep\n");
-            //printf("means user must be configed it go to sleep\n");
             sleep(5);//for too early to send command cause fail
             auto_suspend(g_lynq_mpwrsm);
             //sleep(4);
@@ -202,7 +195,6 @@
     else
     {
         RLOGD("can't autosleep because network is unreable %d\n", sleep_flag);
-        //printf("can't autosleep because network is unreable %d\n", sleep_flag);
     }
     sleep_end = 1;
     return;
@@ -267,11 +259,8 @@
     g_pmsManagement->lynq_read_pms_from_memory("CSCLK", &g_lynq_csclk);
     g_pmsManagement->lynq_read_pms_from_memory("MWAKEUPCFG", &g_lynq_mwakeupcfg);
     RLOGD("g_lynq_mpwrsm %d\n", g_lynq_mpwrsm);
-    //printf("g_lynq_mpwrsm %d\n", g_lynq_mpwrsm);
     RLOGD("CSCLK %d\n", g_lynq_csclk);
-    //printf("CSCLK %d\n", g_lynq_csclk);
     RLOGD("MWAKEUPCFG %d\n", g_lynq_mwakeupcfg);
-    //printf("MWAKEUPCFG %d\n", g_lynq_mwakeupcfg);
     int lock_file = open("/tmp/tel_demo_single_proc.lock", O_CREAT|O_RDWR, 0666);
     int rc = flock(lock_file,LOCK_EX|LOCK_NB);
     if(rc) {