merge with master
[platform/core/system/system-server.git] / ss_predefine.c
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 #include <unistd.h>
19 #include <time.h>
20 #include <limits.h>
21 #include <fcntl.h>
22 #include <dirent.h>
23 #include <sysman.h>
24 #include <vconf.h>
25 #include <pmapi.h>
26 #include <ITapiModem.h>
27 #include <TelPower.h>
28 #include <tapi_event.h>
29 #include <tapi_common.h>
30 #include <syspopup_caller.h>
31 #include <sys/reboot.h>
32 #include <sys/time.h>
33
34 #include "ss_log.h"
35 #include "ss_launch.h"
36 #include "ss_queue.h"
37 #include "ss_device_handler.h"
38 #include "device-node.h"
39 #include "ss_predefine.h"
40 #include "ss_procmgr.h"
41 #include "ss_vibrator.h"
42 #include "include/ss_data.h"
43
44 #define PREDEFINE_SO_DIR                        PREFIX"/lib/ss_predefine/"
45
46 #define CALL_EXEC_PATH                          PREFIX"/bin/call"
47 #define LOWMEM_EXEC_PATH                        PREFIX"/bin/lowmem-popup"
48 #define LOWBAT_EXEC_PATH                        PREFIX"/bin/lowbatt-popup"
49 #define USBCON_EXEC_PATH                        PREFIX"/bin/usb-server"
50 #define TVOUT_EXEC_PATH                         PREFIX"/bin/tvout-selector"
51 #define PWROFF_EXEC_PATH                        PREFIX"/bin/poweroff-popup"
52 #define MEMPS_EXEC_PATH                         PREFIX"/bin/memps"
53
54 /* wait for 5 sec as victim process be dead */
55 #define WAITING_INTERVAL                        5
56
57 #define TVOUT_X_BIN                             "/usr/bin/xberc"
58 #define TVOUT_FLAG                              0x00000001
59 #define MEMPS_LOG_FILE                          "/var/log/memps"
60 #define MAX_RETRY                               2
61
62 #define POWEROFF_DURATION                       2
63 #define POWEROFF_ANIMATION_PATH                 "/usr/bin/boot-animation"
64 #define POWEROFF_NOTI_NAME                      "power_off_start"
65
66 #define WM_READY_PATH                           "/tmp/.wm_ready"
67
68 #define LOWBAT_OPT_WARNING              1
69 #define LOWBAT_OPT_POWEROFF             2
70 #define LOWBAT_OPT_CHARGEERR    3
71 #define LOWBAT_OPT_CHECK                4
72
73 static Ecore_Timer *lowbat_popup_id = NULL;
74 static int lowbat_popup_option = 0;
75
76 static struct timeval tv_start_poweroff;
77 static void powerdown_ap(TapiHandle *handle, const char *noti_id, void *data, void *user_data);
78 static void poweroff_control_cb(keynode_t *in_key, struct ss_main_data *ad);
79
80 static int ss_flags = 0;
81
82 static Ecore_Timer *poweroff_timer_id = NULL;
83 static TapiHandle *tapi_handle = NULL;
84 static int power_off = 0;
85
86 static void make_memps_log(char *file, pid_t pid, char *victim_name)
87 {
88         time_t now;
89         struct tm cur_tm;
90         char params[4096];
91         char new_log[NAME_MAX];
92         static pid_t old_pid = 0;
93         int ret=-1;
94
95         if (old_pid == pid)
96                 return;
97         old_pid = pid;
98
99         now = time(NULL);
100
101         if (localtime_r(&now, &cur_tm) == NULL) {
102                 PRT_TRACE_ERR("Fail to get localtime");
103                 return;
104         }
105
106         PRT_TRACE("%s_%s_%d_%.4d%.2d%.2d_%.2d%.2d%.2d.log", file, victim_name,
107                  pid, (1900 + cur_tm.tm_year), 1 + cur_tm.tm_mon,
108                  cur_tm.tm_mday, cur_tm.tm_hour, cur_tm.tm_min,
109                  cur_tm.tm_sec);
110         snprintf(new_log, sizeof(new_log),
111                  "%s_%s_%d_%.4d%.2d%.2d_%.2d%.2d%.2d.log", file, victim_name,
112                  pid, (1900 + cur_tm.tm_year), 1 + cur_tm.tm_mon,
113                  cur_tm.tm_mday, cur_tm.tm_hour, cur_tm.tm_min,
114                  cur_tm.tm_sec);
115
116         snprintf(params, sizeof(params), "-f %s", new_log);
117         ret = ss_launch_evenif_exist(MEMPS_EXEC_PATH, params);
118
119         if(ret > 0) {
120                 char buf[PATH_MAX];
121                 FILE *fp;
122                 snprintf(buf, sizeof(buf), "/proc/%d/oom_adj", ret);
123                 fp = fopen(buf, "w");
124                 if (fp != NULL) {
125                         fprintf(fp, "%d", (-17));
126                         fclose(fp);
127                 }
128         }
129 }
130
131 static int lowmem_get_victim_pid()
132 {
133         pid_t pid;
134         int fd;
135
136         if (device_get_property(DEVICE_TYPE_MEMORY, PROP_MEMORY_VICTIM_TASK, &pid) < 0) {
137                 PRT_TRACE_ERR("Get victim task failed");
138                 return -1;
139         }
140
141         return pid;
142 }
143
144 int lowmem_def_predefine_action(int argc, char **argv)
145 {
146         int pid, ret, oom_adj;
147         char appname[PATH_MAX];
148
149         if (argc < 1)
150                 return -1;
151
152         if (!strcmp(argv[0], OOM_MEM_ACT)) {
153                 pid = lowmem_get_victim_pid();
154                 if (pid > 0 && pid != sysman_get_pid(LOWMEM_EXEC_PATH) && pid != sysman_get_pid(MEMPS_EXEC_PATH)) {
155                         if ((sysman_get_cmdline_name(pid, appname, PATH_MAX)) ==
156                             0) {
157                                 PRT_TRACE_EM
158                                     ("we will kill, lowmem lv2 = %d (%s)\n",
159                                      pid, appname);
160         
161                                 make_memps_log(MEMPS_LOG_FILE, pid, appname);
162
163                                 if(get_app_oomadj(pid, &oom_adj) < 0) {
164                                         PRT_TRACE_ERR("Failed to get oom_adj");
165                                 }
166                                 PRT_TRACE("%d will be killed with %d oom_adj value", pid, oom_adj);
167
168                                 kill(pid, SIGTERM);
169
170                                 if (oom_adj != OOMADJ_FOREGRD_LOCKED && oom_adj != OOMADJ_FOREGRD_UNLOCKED) {
171                                         return 0;
172                                 }
173
174                                 bundle *b = NULL;
175
176                                 b = bundle_create();
177                                 bundle_add(b, "_APP_NAME_", appname);
178                                 ret = syspopup_launch("lowmem-syspopup", b);
179                                 bundle_free(b);
180                                 if (ret < 0) {
181                                         PRT_TRACE_EM("popup lauch failed\n");
182                                         return -1;
183                                 }
184                                 
185                                 if (set_app_oomadj(ret, OOMADJ_SU) < 0) {       
186                                         PRT_TRACE_ERR("Failed to set oom_adj");
187                                 }
188                         }
189                 }
190         }
191         return 0;
192 }
193
194 int usbcon_def_predefine_action(int argc, char **argv)
195 {
196         int pid;
197         int val = -1;
198         int ret = -1;
199         int bat_state = VCONFKEY_SYSMAN_BAT_NORMAL;
200
201         if (device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_USB_ONLINE, &val) == 0) {
202                 if (val == 0) {
203                         vconf_set_int(VCONFKEY_SYSMAN_USB_STATUS,
204                                       VCONFKEY_SYSMAN_USB_DISCONNECTED);
205                         pm_unlock_state(LCD_OFF, STAY_CUR_STATE);
206                         return 0;
207                 }
208
209                 vconf_set_int(VCONFKEY_SYSMAN_USB_STATUS,
210                               VCONFKEY_SYSMAN_USB_AVAILABLE);
211                 pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
212                 pid = ss_launch_if_noexist(USBCON_EXEC_PATH, NULL);
213                 if (pid < 0) {
214                         PRT_TRACE_ERR("usb predefine action failed\n");
215                         return -1;
216                 }
217                 return pid;
218         }
219         PRT_TRACE_ERR("failed to get usb status\n");
220         return -1;
221 }
222
223 int earjackcon_def_predefine_action(int argc, char **argv)
224 {
225         int val;
226
227         PRT_TRACE_EM("earjack_normal predefine action\n");
228         if (device_get_property(DEVICE_TYPE_EXTCON, PROP_EXTCON_EARJACK_ONLINE, &val) == 0) {
229                 return vconf_set_int(VCONFKEY_SYSMAN_EARJACK, val);
230         }
231
232         return -1;
233 }
234
235 int lowbat_popup(void *data)
236 {
237         int ret = -1, state = 0;
238         ret = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &state);
239         if (state == 1 || ret != 0) {
240                 bundle *b = NULL;
241                 b = bundle_create();
242                 if(lowbat_popup_option == LOWBAT_OPT_WARNING) {
243                         bundle_add(b, "_SYSPOPUP_CONTENT_", "warning");
244                 } else if(lowbat_popup_option == LOWBAT_OPT_POWEROFF) {
245                         bundle_add(b, "_SYSPOPUP_CONTENT_", "poweroff");
246                 } else if(lowbat_popup_option == LOWBAT_OPT_CHARGEERR) {
247                         bundle_add(b, "_SYSPOPUP_CONTENT_", "chargeerr");
248                 } else {
249                         bundle_add(b, "_SYSPOPUP_CONTENT_", "check");
250                 }
251
252                 ret = syspopup_launch("lowbat-syspopup", b);
253                 if (ret < 0) {
254                         PRT_TRACE_EM("popup lauch failed\n");
255                         bundle_free(b);
256                         return 1;
257                 }
258                 lowbat_popup_id = NULL;
259                 lowbat_popup_option = 0;
260                 bundle_free(b);
261         } else {
262                 PRT_TRACE_EM("boot-animation running yet");
263                 return 1;
264         }
265
266         return 0;
267 }
268
269 int lowbat_def_predefine_action(int argc, char **argv)
270 {
271         int ret, state=0;
272         char argstr[128];
273         char* option = NULL;
274
275         if (argc < 1)
276                 return -1;
277
278         if(lowbat_popup_id != NULL) {
279                 ecore_timer_del(lowbat_popup_id);
280                 lowbat_popup_id = NULL;
281         }
282
283         bundle *b = NULL;
284         b = bundle_create();
285         if(!strcmp(argv[0],WARNING_LOW_BAT_ACT) || !strcmp(argv[0],CRITICAL_LOW_BAT_ACT)) {
286                 bundle_add(b, "_SYSPOPUP_CONTENT_", "warning");
287                 lowbat_popup_option = LOWBAT_OPT_WARNING;
288         } else if(!strcmp(argv[0],POWER_OFF_BAT_ACT)) {
289                 bundle_add(b, "_SYSPOPUP_CONTENT_", "poweroff");
290                 lowbat_popup_option = LOWBAT_OPT_POWEROFF;
291         } else if(!strcmp(argv[0],CHARGE_ERROR_ACT)) {
292                 bundle_add(b, "_SYSPOPUP_CONTENT_", "chargeerr");
293                 lowbat_popup_option = LOWBAT_OPT_CHARGEERR;
294         } else {
295                 bundle_add(b, "_SYSPOPUP_CONTENT_", "check");
296                 lowbat_popup_option = LOWBAT_OPT_CHECK;
297         }
298
299         ret = vconf_get_int(VCONFKEY_STARTER_SEQUENCE, &state);
300         if (state == 1 || ret != 0) {
301                 ret = syspopup_launch("lowbat-syspopup", b);
302                 if (ret < 0) {
303                         PRT_TRACE_EM("popup lauch failed\n");
304                         bundle_free(b);
305                         lowbat_popup_option = 0;
306                         return -1;
307                 }
308         } else {
309                 PRT_TRACE_EM("boot-animation running yet");
310                 lowbat_popup_id = ecore_timer_add(1, lowbat_popup, NULL);
311         }
312         bundle_free(b);
313         return 0;
314 }
315
316 Eina_Bool powerdown_ap_by_force(void *data)
317 {
318         struct timeval now;
319         int poweroff_duration = POWEROFF_DURATION;
320         char *buf;
321
322         if(tapi_handle != NULL)
323         {
324                 tel_deinit(tapi_handle);
325                 tapi_handle = NULL;
326         }
327         /* Getting poweroff duration */
328         buf = getenv("PWROFF_DUR");
329         if (buf != NULL && strlen(buf) < 1024)
330                 poweroff_duration = atoi(buf);
331         if (poweroff_duration < 0 || poweroff_duration > 60)
332                 poweroff_duration = POWEROFF_DURATION;
333
334         gettimeofday(&now, NULL);
335         /* Waiting until power off duration and displaying animation */
336         while (now.tv_sec - tv_start_poweroff.tv_sec < poweroff_duration) {
337                 usleep(100000);
338                 gettimeofday(&now, NULL);
339         }
340
341         PRT_TRACE("Power off by force\n");
342         /* give a chance to be terminated for each process */
343         power_off = 1;
344         sleep(1);
345         sync();
346         reboot(RB_POWER_OFF);
347         return EINA_TRUE;
348 }
349
350 static void powerdown_ap(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
351 {
352         struct timeval now;
353         int poweroff_duration = POWEROFF_DURATION;
354         char *buf;
355
356         if (poweroff_timer_id) {
357                 ecore_timer_del(poweroff_timer_id);
358                 poweroff_timer_id = NULL;
359         }
360         if (tapi_handle) {
361                 tel_deregister_noti_event(tapi_handle,TAPI_NOTI_MODEM_POWER);
362                 tel_deinit(tapi_handle);
363                 tapi_handle = NULL;
364         }
365         PRT_TRACE("Power off \n");
366
367         /* Getting poweroff duration */
368         buf = getenv("PWROFF_DUR");
369         if (buf != NULL && strlen(buf) < 1024)
370                 poweroff_duration = atoi(buf);
371         if (poweroff_duration < 0 || poweroff_duration > 60)
372                 poweroff_duration = POWEROFF_DURATION;
373
374         gettimeofday(&now, NULL);
375         /* Waiting until power off duration and displaying animation */
376         while (now.tv_sec - tv_start_poweroff.tv_sec < poweroff_duration) {
377                 usleep(100000);
378                 gettimeofday(&now, NULL);
379         }
380
381         /* give a chance to be terminated for each process */
382         power_off = 1;
383         sleep(1);
384         sync();
385         reboot(RB_POWER_OFF);
386 }
387 static void powerdown_res_cb(TapiHandle *handle, int result, void *data, void *user_data)
388 {
389         PRT_TRACE("poweroff command request : %d",result);
390 }
391 int poweroff_def_predefine_action(int argc, char **argv)
392 {
393         int ret;
394
395         heynoti_publish(POWEROFF_NOTI_NAME);
396         vconf_ignore_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, (void*)poweroff_control_cb);
397
398         pm_change_state(LCD_NORMAL);
399         system("/etc/rc.d/rc.shutdown &");
400         sync();
401
402         gettimeofday(&tv_start_poweroff, NULL);
403         if (tapi_handle) {
404                 ret = tel_register_noti_event(tapi_handle, TAPI_NOTI_MODEM_POWER, powerdown_ap, NULL);
405
406                 if (ret != TAPI_API_SUCCESS) {
407                         PRT_TRACE_ERR
408                             ("tel_register_event is not subscribed. error %d\n", ret);
409                         powerdown_ap_by_force(NULL);
410                         return 0;
411                 }
412
413                 ret = tel_process_power_command(tapi_handle, TAPI_PHONE_POWER_OFF, powerdown_res_cb, NULL);
414                 if (ret != TAPI_API_SUCCESS) {
415                         PRT_TRACE_ERR("tel_process_power_command() error %d\n", ret);
416                         powerdown_ap_by_force(NULL);
417                         return 0;
418                 }
419                 poweroff_timer_id = ecore_timer_add(15, powerdown_ap_by_force, NULL);
420         } else {
421                 powerdown_ap_by_force(NULL);
422         }
423         return 0;
424 }
425
426 static void enter_flight_mode_cb(TapiHandle *handle, int result, void *data, void *user_data)
427 {
428         int bCurFlightMode = 0;
429         if (result != TAPI_POWER_FLIGHT_MODE_ENTER) {
430                 PRT_TRACE_ERR("flight mode enter failed %d",result);
431         } else {
432                 PRT_TRACE("enter flight mode result : %d",result);
433                 if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE,&bCurFlightMode) == 0) {
434                         PRT_TRACE("Flight Mode is %d", bCurFlightMode);
435                 } else {
436                         PRT_TRACE_ERR("failed to get vconf key");
437                 }
438         }
439 }
440
441 static void leave_flight_mode_cb(TapiHandle *handle, int result, void *data, void *user_data)
442 {
443         int bCurFlightMode = 0;
444         if (result != TAPI_POWER_FLIGHT_MODE_LEAVE) {
445                 PRT_TRACE_ERR("flight mode leave failed %d",result);
446         } else {
447                 PRT_TRACE("leave flight mode result : %d",result);
448                 if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE,&bCurFlightMode) == 0) {
449                         PRT_TRACE("Flight Mode is %d", bCurFlightMode);
450                 } else {
451                         PRT_TRACE_ERR("failed to get vconf key");
452                 }
453         }
454 }
455
456 int entersleep_def_predefine_action(int argc, char **argv)
457 {
458         int ret;
459
460         pm_change_state(LCD_NORMAL);
461         sync();
462
463         ret = tel_set_flight_mode(tapi_handle, TAPI_POWER_FLIGHT_MODE_ENTER, enter_flight_mode_cb, NULL);
464         PRT_TRACE_ERR("request for changing into flight mode : %d\n", ret);
465
466         system("/etc/rc.d/rc.entersleep");
467         pm_change_state(POWER_OFF);
468
469         return 0;
470 }
471
472 int leavesleep_def_predefine_action(int argc, char **argv)
473 {
474         int ret;
475
476         pm_change_state(LCD_NORMAL);
477         sync();
478
479         ret = tel_set_flight_mode(tapi_handle, TAPI_POWER_FLIGHT_MODE_LEAVE, leave_flight_mode_cb, NULL);
480         PRT_TRACE_ERR("request for changing into flight mode : %d\n", ret);
481
482         return 0;
483 }
484
485 static void restart_ap(TapiHandle *handle, const char *noti_id, void *data, void *user_data);
486
487 Eina_Bool restart_ap_ecore(void *data)
488 {
489         restart_ap(tapi_handle,NULL,(void *)-1,NULL);
490         return EINA_TRUE;
491 }
492
493 static void restart_ap(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
494 {
495         struct timeval now;
496         int poweroff_duration = POWEROFF_DURATION;
497         char *buf;
498
499         if (poweroff_timer_id) {
500                 ecore_timer_del(poweroff_timer_id);
501                 poweroff_timer_id = NULL;
502         }
503
504
505         if(tapi_handle != NULL)
506         {
507                 tel_deregister_noti_event(tapi_handle,TAPI_NOTI_MODEM_POWER);
508                 tel_deinit(tapi_handle);
509                 tapi_handle = NULL;
510         }
511
512         PRT_INFO("Restart\n");
513         sync();
514
515         buf = getenv("PWROFF_DUR");
516         if (buf != NULL && strlen(buf) < 1024)
517                 poweroff_duration = atoi(buf);
518         if (poweroff_duration < 0 || poweroff_duration > 60)
519                 poweroff_duration = POWEROFF_DURATION;
520         gettimeofday(&now, NULL);
521         while (now.tv_sec - tv_start_poweroff.tv_sec < poweroff_duration) {
522                 usleep(100000);
523                 gettimeofday(&now, NULL);
524         }
525
526         reboot(RB_AUTOBOOT);
527 }
528
529 static void restart_ap_by_force(void *data)
530 {
531         struct timeval now;
532         int poweroff_duration = POWEROFF_DURATION;
533         char *buf;
534
535         if (poweroff_timer_id) {
536                 ecore_timer_del(poweroff_timer_id);
537                 poweroff_timer_id = NULL;
538         }
539
540
541         if(tapi_handle != NULL)
542         {
543                 tel_deinit(tapi_handle);
544                 tapi_handle = NULL;
545         }
546
547         PRT_INFO("Restart\n");
548         sync();
549
550         buf = getenv("PWROFF_DUR");
551         if (buf != NULL && strlen(buf) < 1024)
552                 poweroff_duration = atoi(buf);
553         if (poweroff_duration < 0 || poweroff_duration > 60)
554                 poweroff_duration = POWEROFF_DURATION;
555         gettimeofday(&now, NULL);
556         while (now.tv_sec - tv_start_poweroff.tv_sec < poweroff_duration) {
557                 usleep(100000);
558                 gettimeofday(&now, NULL);
559         }
560
561         reboot(RB_AUTOBOOT);
562 }
563
564 int restart_def_predefine_action(int argc, char **argv)
565 {
566         int ret;
567
568         pm_change_state(LCD_NORMAL);
569         system("/etc/rc.d/rc.shutdown &");
570         sync();
571
572         gettimeofday(&tv_start_poweroff, NULL);
573
574         ret =
575             tel_register_noti_event(tapi_handle, TAPI_NOTI_MODEM_POWER, restart_ap, NULL);
576         if (ret != TAPI_API_SUCCESS) {
577                 PRT_TRACE_ERR
578                     ("tel_register_event is not subscribed. error %d\n", ret);
579                 restart_ap_by_force((void *)-1);
580                 return 0;
581         }
582
583
584         ret = tel_process_power_command(tapi_handle, TAPI_PHONE_POWER_OFF, powerdown_res_cb, NULL);
585         if (ret != TAPI_API_SUCCESS) {
586                 PRT_TRACE_ERR("tel_process_power_command() error %d\n", ret);
587                 restart_ap_by_force((void *)-1);
588                 return 0;
589         }
590
591         poweroff_timer_id = ecore_timer_add(15, restart_ap_ecore, NULL);
592         return 0;
593 }
594
595 int launching_predefine_action(int argc, char **argv)
596 {
597         int ret;
598
599         if (argc < 0)
600                 return -1;
601
602         /* current just launching poweroff-popup */
603         ret = syspopup_launch("poweroff-syspopup", NULL);
604         if (ret < 0) {
605                 PRT_TRACE_ERR("poweroff popup predefine action failed");
606                 return -1;
607         }
608         return 0;
609 }
610
611 int flight_mode_def_predefine_action(int argc, char **argv)
612 {
613         int bCurFlightMode;
614         int err = TAPI_API_SUCCESS;
615         if (argc != 1 || argv[0] == NULL) {
616                 PRT_TRACE_ERR("FlightMode Set predefine action failed");
617                 return -1;
618         }
619         bCurFlightMode = atoi(argv[0]);
620         if (bCurFlightMode == 1) {
621                 err = tel_set_flight_mode(tapi_handle, TAPI_POWER_FLIGHT_MODE_LEAVE, leave_flight_mode_cb, NULL);
622         } else if (bCurFlightMode == 0) {
623                 err = tel_set_flight_mode(tapi_handle, TAPI_POWER_FLIGHT_MODE_ENTER, enter_flight_mode_cb, NULL);
624         }
625         if (err != TAPI_API_SUCCESS)
626                 PRT_TRACE_ERR("FlightMode tel api action failed %d",err);
627         return 0;
628
629 }
630
631 static void ss_action_entry_load_from_sodir()
632 {
633         DIR *dp;
634         struct dirent *dentry;
635         struct sysnoti *msg;
636         char *ext;
637         char tmp[128];
638
639         dp = opendir(PREDEFINE_SO_DIR);
640         if (!dp) {
641                 ERR("fail open %s", PREDEFINE_SO_DIR);
642                 return;
643         }
644
645         msg = malloc(sizeof(struct sysnoti));
646         if (msg == NULL) {
647                 ERR("Malloc failed");
648                 closedir(dp);
649                 return;
650         }
651
652         msg->pid = getpid();
653
654         while ((dentry = readdir(dp)) != NULL) {
655                 if ((ext = strstr(dentry->d_name, ".so")) == NULL)
656                         continue;
657
658                 snprintf(tmp, sizeof(tmp), "%s/%s", PREDEFINE_SO_DIR,
659                          dentry->d_name);
660                 msg->path = tmp;
661                 *ext = 0;
662                 msg->type = &(dentry->d_name[3]);
663                 ss_action_entry_add(msg);
664         }
665         free(msg);
666
667         closedir(dp);
668 }
669 static void __tel_init_cb(keynode_t *key_nodes,void *data)
670 {
671         int bTelReady = 0;
672         bTelReady = vconf_keynode_get_bool(key_nodes);
673         if (bTelReady == 1) {
674                 vconf_ignore_key_changed(VCONFKEY_TELEPHONY_READY, (void*)__tel_init_cb);
675                 tapi_handle = tel_init(NULL);
676                 if (tapi_handle == NULL) {
677                         PRT_TRACE_ERR("tapi init error");
678                 }
679         } else {
680                 PRT_TRACE_ERR("tapi is not ready yet");
681         }
682 }
683 static void poweroff_control_cb(keynode_t *in_key, struct ss_main_data *ad)
684 {
685         int val;
686         if (vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &val) != 0)
687                 return;
688         switch (val) {
689         case VCONFKEY_SYSMAN_POWER_OFF_DIRECT:
690                 ss_action_entry_call_internal(PREDEF_POWEROFF, 0);
691                 break;
692         case VCONFKEY_SYSMAN_POWER_OFF_POPUP:
693                 ss_action_entry_call_internal(PREDEF_PWROFF_POPUP, 0);
694                 break;
695         }
696 }
697
698 void ss_predefine_internal_init(void)
699 {
700
701         /* telephony initialize */
702         int ret = 0;
703         int bTelReady = 0;
704         if (vconf_get_bool(VCONFKEY_TELEPHONY_READY,&bTelReady) == 0) {
705                 if (bTelReady == 1) {
706                         tapi_handle = tel_init(NULL);
707                         if (tapi_handle == NULL) {
708                                 PRT_TRACE_ERR("tapi init error");
709                         }
710                 } else {
711                         vconf_notify_key_changed(VCONFKEY_TELEPHONY_READY, (void *)__tel_init_cb, NULL);
712                 }
713         } else {
714                 PRT_TRACE_ERR("failed to get tapi vconf key");
715         }
716 #ifdef NOUSE
717         ss_action_entry_add_internal(PREDEF_CALL, call_predefine_action, NULL,
718                                      NULL);
719 #endif
720         ss_action_entry_add_internal(PREDEF_LOWMEM, lowmem_def_predefine_action,
721                                      NULL, NULL);
722         ss_action_entry_add_internal(PREDEF_LOWBAT, lowbat_def_predefine_action,
723                                      NULL, NULL);
724         ss_action_entry_add_internal(PREDEF_USBCON, usbcon_def_predefine_action,
725                                      NULL, NULL);
726         ss_action_entry_add_internal(PREDEF_EARJACKCON,
727                                      earjackcon_def_predefine_action, NULL,
728                                      NULL);
729         ss_action_entry_add_internal(PREDEF_POWEROFF,
730                                      poweroff_def_predefine_action, NULL, NULL);
731         ss_action_entry_add_internal(PREDEF_PWROFF_POPUP,
732                                      launching_predefine_action, NULL, NULL);
733         ss_action_entry_add_internal(PREDEF_REBOOT,
734                                      restart_def_predefine_action, NULL, NULL);
735         ss_action_entry_add_internal(PREDEF_FLIGHT_MODE,
736                                      flight_mode_def_predefine_action, NULL, NULL);
737         ss_action_entry_add_internal(PREDEF_HAPTIC, haptic_def_predefine_action,
738                                         NULL, NULL);
739
740         if (vconf_notify_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, (void *)poweroff_control_cb, NULL) < 0) {
741                 PRT_TRACE_ERR("Vconf notify key chaneged failed: KEY(%s)", VCONFKEY_SYSMAN_POWER_OFF_STATUS);
742         }
743         ss_action_entry_load_from_sodir();
744
745         /* check and set earjack init status */
746         earjackcon_def_predefine_action(0, NULL);
747 }