tizen 2.3 release
[apps/home/lockscreen.git] / src / sim-state.c
1 /*
2  * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
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 #include <Elementary.h>
18
19 #include <tapi_common.h>
20 #include <ITapiSim.h>
21 #include <TelCall.h>
22 #include <ITapiSim.h>
23 #include <TelNetwork.h>
24 #include <vconf.h>
25
26 #include "sim-state.h"
27 #include "util.h"
28 #include "control-panel.h"
29 #include "lockscreen-lite.h"
30 #include "util-time.h"
31
32 #if !DISABLE_TELEPHONY
33 #include <telephony_network.h>
34 #endif
35
36 #define TAPI_HANDLE_MAX 2
37 #define NO_SIM_LEN 8
38
39 static struct {
40         int is_initialized;
41         TapiHandle *handle[TAPI_HANDLE_MAX+1];
42         Eina_Bool sim_card_ready[2];
43         Eina_Bool sim_card_roam[2];
44         int is_flight_mode_on;
45
46         char *network_name_1;
47         char *network_name_2;
48
49         char *network_name; //this name represents viewed string in lockscreen
50
51 } s_sim_state = {
52         .is_initialized = 0,
53         .handle[0] = NULL,
54         .handle[1] = NULL,
55         .handle[2] = NULL,
56         .sim_card_ready[0] = EINA_FALSE,
57         .sim_card_ready[1] = EINA_FALSE,
58         .sim_card_roam[0] = EINA_FALSE,
59         .sim_card_roam[1] = EINA_FALSE,
60         .is_flight_mode_on = false,
61
62         .network_name_1 = NULL,
63         .network_name_2 = NULL,
64
65         .network_name = NULL,
66 };
67
68 static bool _get_sim_status(void);
69 static bool _sim_status_network_names_init(void);
70 static char *_get_spn_or_name(TapiHandle *handle);
71
72 /**
73  * Network name functions
74  */
75 static char *_sim_network_name(TapiHandle *handle);
76 static char *_sim_spn_name(TapiHandle *handle);
77
78 /**
79  * Callback registering and unregistering
80  */
81 static void _sim_state_register();
82 static void _sim_state_unregister();
83
84 /**
85  * Callback functions
86  */
87 static void _sim_status_changed_cb(TapiHandle *handle, const char *noti_id, void *data, void *user_data);
88 static void _sim_name_changed_cb(TapiHandle *handle, const char *noti_id, void *data, void *user_data);
89 static void _sim_roam_changed_cb(TapiHandle *handle, const char *noti_id, void *data, void *user_data);
90
91 static void _ready_cb(keynode_t *key, void *data);
92 static void _flight_mode_cb(keynode_t *key, void *data);
93
94 #if     !DISABLE_TELEPHONY
95 static void _sim_status_listener_init(void)
96 {
97         LOCK_SCREEN_TRACE_DBG("");
98
99         int modem_num  =  0;
100         char **cp_list = NULL;
101
102         if (s_sim_state.is_initialized == 1) {
103                 LOCK_SCREEN_TRACE_WARN("already initialized");
104                 return ;
105         }
106
107         cp_list = tel_get_cp_name_list();
108         if(cp_list == NULL)
109         {
110                 LOCK_SCREEN_TRACE_ERR("Failed to get tel_get_cp_name_list");
111                 return ;
112         }
113
114         /**
115          * Initialize sim handlers
116          */
117         while(cp_list[modem_num])
118         {
119                 s_sim_state.handle[modem_num] = tel_init(cp_list[modem_num]);
120                 if(!s_sim_state.handle[modem_num])
121                 {
122                         LOCK_SCREEN_TRACE_ERR("Failed to initialize modem %d ", modem_num);
123                 }
124                 modem_num++;
125         }
126         s_sim_state.handle[modem_num] = NULL;
127
128         int i = 0;
129         while (cp_list[i] != NULL) {
130                 free(cp_list[i++]);
131         }
132         free(cp_list);
133
134         _sim_state_register();
135         if(!_sim_status_network_names_init())
136         {
137                 LOCK_SCREEN_TRACE_ERR("Failed to init network names getter");
138         }
139
140         if(!_get_sim_status())
141         {
142                 /* roam state : dual clock set */
143                 if(s_sim_state.sim_card_roam[0] || s_sim_state.sim_card_roam[1])
144                 {
145                         util_time_roaming_state_set(1);
146                 }
147                 else
148                 {
149                         util_time_roaming_state_set(0);
150                 }
151         } else {
152                 LOCK_SCREEN_TRACE_ERR("Failed to get sim status ");
153         }
154
155         s_sim_state.is_initialized = 1;
156 }
157
158 bool sim_status_listener_init(void)
159 {
160         int tel_status = 0;
161         int vconf_ret  = -1;
162
163         vconf_ret = vconf_get_bool(VCONFKEY_TELEPHONY_READY, &tel_status);
164         if(vconf_ret != VCONF_OK)
165         {
166                 LOCK_SCREEN_TRACE_ERR("Failed to get VCONFKEY_TELEPHONY_READY");
167         }
168         if (vconf_notify_key_changed(VCONFKEY_TELEPHONY_READY, _ready_cb, NULL) != 0)
169         {
170                 LOCK_SCREEN_TRACE_ERR("Failed to listen VCONFKEY_TELEPHONY_READY");
171         }
172         if (vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, _flight_mode_cb, NULL) != 0)
173         {
174                 LOCK_SCREEN_TRACE_ERR("Failed to listen VCONFKEY_TELEPHONY_FLIGHT_MODE");
175         }
176
177         if (tel_status) {
178                 _sim_status_listener_init();
179                 control_panel_sim_state_changed();
180                 update_time(NULL);
181                 return true;
182         } else {
183                 LOCK_SCREEN_TRACE_ERR("TAPI isn't ready yet");
184                 return false;
185         }
186 }
187 #endif
188
189 void sim_status_listener_deinit(void)
190 {
191         int it = 0;
192         int ret = 0;
193         LOCK_SCREEN_TRACE_DBG("");
194
195         if (s_sim_state.is_initialized == 0) {
196                 LOCK_SCREEN_TRACE_ERR("TAPI handler is already initialized");
197                 return;
198         }
199         _sim_state_unregister();
200
201         while(s_sim_state.handle[it])
202         {
203                 ret = tel_deregister_noti_event(s_sim_state.handle[it], TAPI_NOTI_SIM_STATUS);
204                 if(ret != TAPI_API_SUCCESS)
205                 {
206                         LOCK_SCREEN_TRACE_ERR("Failed to deinitialize callback");
207                 }
208                 it++;
209         }
210
211         it = 0;
212         while(s_sim_state.handle[it])
213         {
214                 tel_deinit(s_sim_state.handle[it]);
215                 it++;
216         }
217
218         s_sim_state.is_initialized = 0;
219 }
220
221 char *sim_status_network_name_get(void)
222 {
223         LOGD("");
224
225         if(s_sim_state.is_flight_mode_on == EINA_TRUE)
226         {
227                 LOCK_SCREEN_TRACE_DBG("Fligh mode is enabled");
228                 return strdup(_("IDS_COM_BODY_NO_SERVICE"));
229         }
230         else if(!s_sim_state.sim_card_ready[0] && !s_sim_state.sim_card_ready[1])
231         {
232                 LOCK_SCREEN_TRACE_DBG("Sim card slots are empty");
233                 return strdup(_("IDS_IDLE_MBODY_EMERGENCY_CALLS_ONLY"));
234         }
235         else
236         {
237                 if(s_sim_state.network_name_1 && (!s_sim_state.network_name_2 || !s_sim_state.sim_card_ready[1]))
238                 {
239                         return strdup(s_sim_state.network_name_1);
240                 }
241                 else if((!s_sim_state.network_name_1 || !s_sim_state.sim_card_ready[0]) && s_sim_state.network_name_2)
242                 {
243                         return strdup(s_sim_state.network_name_2);
244                 }
245                 else if(s_sim_state.network_name_1 && s_sim_state.network_name_2)
246                 {
247                         char buf[BUF_SIZE];
248                         snprintf(buf, sizeof(buf), "%s / %s", s_sim_state.network_name_1, s_sim_state.network_name_2);
249                         return strdup(buf);
250                 }
251         }
252
253         return NULL;
254 }
255
256 int sim_status_roaming_status_is_on_check(void)
257 {
258         LOGD("");
259
260         int status_sim1 = 0, status_sim2 = 0;
261         int ret    = 0;
262
263         ret = tel_get_property_int(s_sim_state.handle[0], TAPI_PROP_NETWORK_ROAMING_STATUS, &status_sim1);
264         LOCK_SCREEN_TRACE_DBG("Roaming status for SIM1 is : %d ", status_sim1);
265         if(ret != TAPI_API_SUCCESS)
266         {
267                 LOCK_SCREEN_TRACE_ERR("Failed to get roaming status ");
268                 return -1;
269         }
270
271         ret = tel_get_property_int(s_sim_state.handle[1], TAPI_PROP_NETWORK_ROAMING_STATUS, &status_sim2);
272         LOCK_SCREEN_TRACE_DBG("Roaming status for SIM2 is : %d ", status_sim2);
273         if(ret != TAPI_API_SUCCESS)
274         {
275                 LOCK_SCREEN_TRACE_ERR("Failed to get roaming status ");
276                 return -1;
277         }
278
279         return status_sim1 | status_sim2;
280 }
281
282 /**
283  * @brief Set network name
284  * @return TRUE if no error
285  */
286 static bool _sim_status_network_names_init(void)
287 {
288         free(s_sim_state.network_name_1);
289         s_sim_state.network_name_1 = NULL;
290
291         free(s_sim_state.network_name_2);
292         s_sim_state.network_name_2 = NULL;
293
294         s_sim_state.network_name_1 = _get_spn_or_name(s_sim_state.handle[0]);
295         if(!s_sim_state.network_name_1)
296         {
297                 LOCK_SCREEN_TRACE_ERR("Failed to get sim 1 name");
298         }
299         s_sim_state.network_name_2 = _get_spn_or_name(s_sim_state.handle[1]);
300         if(!s_sim_state.network_name_2)
301         {
302                 LOCK_SCREEN_TRACE_ERR("Failed to get sim 2 name");
303         }
304
305         LOCK_SCREEN_TRACE_WARN("sim1:%s", s_sim_state.network_name_1);
306         LOCK_SCREEN_TRACE_WARN("sim2:%s", s_sim_state.network_name_2);
307
308         return true;
309 }
310
311 /**
312  * @brief Function initialize status table of sim cards. If status of sim card is correct it set proper table element as EINA_TRUE
313  */
314 static bool _get_sim_status(void)
315 {
316         LOGD("");
317
318         int i = 0;
319         int ret;
320         int card_changed;
321
322         TelSimCardStatus_t sim_status;
323
324         while(s_sim_state.handle[i])
325         {
326                 ret = tel_get_sim_init_info(s_sim_state.handle[i], &sim_status, &card_changed);
327                 if(ret != TAPI_API_SUCCESS)
328                 {
329                         LOCK_SCREEN_TRACE_ERR("Failed to get sim %d status ", i);
330                         return false;
331                 }
332
333                 LOCK_SCREEN_TRACE_DBG("Sims status is %d ", sim_status);
334
335                 if(sim_status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED ||
336                         sim_status == TAPI_SIM_STATUS_SIM_PIN_REQUIRED)
337                 {
338                         LOCK_SCREEN_TRACE_DBG("Sim %d ready", i);
339                         s_sim_state.sim_card_ready[i] = EINA_TRUE;
340                 }
341
342                 /* sim state */
343                 int roam = 0;
344                 ret = tel_get_property_int (s_sim_state.handle[i], TAPI_PROP_NETWORK_ROAMING_STATUS, &roam);
345                 if(roam)
346                 {
347                         LOCK_SCREEN_TRACE_DBG("Sim %d roaming is enabled", i);
348                         s_sim_state.sim_card_roam[i] = EINA_TRUE;
349                 }
350                 else
351                 {
352                         LOCK_SCREEN_TRACE_DBG("Sim %d roaming is disabled", i);
353                         s_sim_state.sim_card_roam[i] = EINA_FALSE;
354                 }
355
356                 i++;
357         }
358
359         return true;
360 }
361
362 static int _get_china_spn_or_name(char *mcc_mnc, int service_type, char *buf)
363 {
364         retv_if(mcc_mnc == NULL, 0);
365         retv_if(buf == NULL, 0);
366
367         const char *rat = NULL;
368         if (service_type == TAPI_NETWORK_SERVICE_TYPE_3G) {
369                 rat = "3G";
370         }
371
372         LOCK_SCREEN_TRACE_DBG("PLMN:%s", mcc_mnc);
373
374         if (strcmp(mcc_mnc, "46001") == 0) {
375                 if (rat == NULL) {
376                         strncpy(buf,_("IDS_SIM_BODY_CHINA_UNICOM_M_CHINA_OPERATOR_CHN"), BUF_SIZE - 1);
377                 } else {
378                         snprintf(buf, BUF_SIZE - 1,"%s %s",_("IDS_SIM_BODY_CHINA_UNICOM_M_CHINA_OPERATOR_CHN"), rat);
379                 }
380         }
381         else if (strcmp(mcc_mnc, "46000") == 0 ||
382                          strcmp(mcc_mnc, "46002") == 0 ||
383                          strcmp(mcc_mnc, "46007") == 0 ||
384                          strcmp(mcc_mnc, "46008") == 0) {
385                 if(rat == NULL) {
386                         strncpy(buf,_("IDS_IDLE_BODY_CMCC_CHN"), BUF_SIZE - 1);
387                 } else {
388                         snprintf(buf, BUF_SIZE - 1, "%s %s", _("IDS_IDLE_BODY_CMCC_CHN"), rat);
389                 }
390         }
391         else if (strcmp(mcc_mnc, "46692") == 0) {
392                 strncpy(buf, _("IDS_SIM_BODY_CHUNGHWA_M_CHINA_OPERATOR_CHN"), BUF_SIZE - 1);//chunghwa_operator_name
393         }
394         else if (strcmp(mcc_mnc, "46601") == 0) {
395                 strncpy(buf, _("IDS_IDLE_BODY_FAREASTONE_CHN"), BUF_SIZE - 1);//fareastone_operator_name
396         }
397         else if (strcmp(mcc_mnc, "46688") == 0) {
398                 strncpy(buf, _("IDS_SIM_BODY_KGT_M_CHINA_OPERATOR_CHN"), BUF_SIZE - 1);//kgt_operator_name
399         }
400         else if (strcmp(mcc_mnc, "46689") == 0) {
401                 strncpy(buf, _("IDS_SIM_BODY_T_STAR_M_CHINA_OPERATOR_CHN"), BUF_SIZE - 1);//kgt_operator_name
402         }
403         else if(strcmp(mcc_mnc, "46697") == 0 ||
404                         strcmp(mcc_mnc, "46693") == 0 ||
405                         strcmp(mcc_mnc, "46699") == 0) {
406                 strncpy(buf, _("IDS_IDLE_BODY_TW_MOBILE_CHN"), BUF_SIZE - 1);//kgt_operator_name
407         }
408
409         if (strlen(buf) > 0) {
410                 return 1;
411         }
412
413         return 0;
414 }
415
416 /**
417  * @brief Function get spn or network name for sim card
418  * @details Function get network name property or it is not correct try to get SPN name for sim card.
419  * @param pointer to proper Sim card handle
420  * @return returns char pointer if no error, or empty string "" if network name or spin is NULL.
421  */
422 static char *_get_spn_or_name(TapiHandle *handle)
423 {
424         LOGD("");
425
426         int ret = TAPI_API_SUCCESS;
427         int service_type = TAPI_NETWORK_SERVICE_TYPE_UNKNOWN;
428         int name_option = TAPI_NETWORK_DISP_INVALID;
429         char *plmn = NULL;
430         char *spn = NULL;
431         char buf[BUF_SIZE];
432
433         memset(buf, 0, BUF_SIZE);
434
435         if(handle == NULL)
436         {
437                 LOCK_SCREEN_TRACE_ERR("Invalid parameter");
438                 return NULL;
439         }
440
441         ret = tel_get_property_int(handle, TAPI_PROP_NETWORK_SERVICE_TYPE, &service_type);
442         if(ret != TAPI_API_SUCCESS)
443         {
444                 LOCK_SCREEN_TRACE_ERR("Failed to get service type");
445                 return NULL;
446         }
447
448         if(service_type >= TAPI_NETWORK_SERVICE_TYPE_2G)
449         {
450                 ret = tel_get_property_int(handle, TAPI_PROP_NETWORK_NAME_OPTION, &name_option);
451                 if(ret != TAPI_API_SUCCESS)
452                 {
453                         LOCK_SCREEN_TRACE_ERR("Failed to get name_option");
454                         return NULL;
455                 }
456                 char *mcc_mnc = NULL;
457                 ret = tel_get_property_string(handle, TAPI_PROP_NETWORK_PLMN, &mcc_mnc);
458                 if(ret != TAPI_API_SUCCESS)
459                 {
460                         LOCK_SCREEN_TRACE_ERR("Failed to get PLMN");
461                         return NULL;
462                 }
463
464                 if (_get_china_spn_or_name(mcc_mnc, service_type, buf) == 0) {
465                         switch(name_option)
466                         {
467                                 case TAPI_NETWORK_DISP_SPN:
468                                         spn = _sim_spn_name(handle);
469                                         if (spn != NULL && spn[0] != 0)
470                                         {
471                                                 snprintf(buf, sizeof(buf), "%s", spn);
472                                         }
473                                         break;
474                                 case TAPI_NETWORK_DISP_PLMN:
475                                         plmn = _sim_network_name(handle);
476                                         if(plmn != NULL && plmn[0] != 0)
477                                         {
478                                                 snprintf(buf, sizeof(buf), "%s", plmn);
479                                         }
480                                         break;
481                                 case TAPI_NETWORK_DISP_SPN_PLMN:
482                                         spn = _sim_spn_name(handle);
483                                         plmn = _sim_network_name(handle);
484                                         if (spn != NULL && spn[0] != 0 && plmn != NULL && plmn[0] != 0)
485                                         {
486                                                 snprintf(buf, sizeof(buf), "%s - %s", plmn, spn);
487                                         }
488                                         else if (spn != NULL && spn[0] != 0)
489                                         {
490                                                 snprintf(buf, sizeof(buf), "%s", spn);
491                                         }
492                                         else if (plmn != NULL && plmn[0] != 0)
493                                         {
494                                                 snprintf(buf, sizeof(buf), "%s", plmn);
495                                         }
496                                         break;
497                                 default:
498                                         plmn = _sim_network_name(handle);
499                                         if (plmn != NULL && plmn[0] != 0)
500                                         {
501                                                 snprintf(buf, sizeof(buf), "%s", plmn);
502                                         }
503                                         break;
504                         }
505                 }
506                 free(mcc_mnc);
507                 LOCK_SCREEN_TRACE_WARN("name option:%d", name_option);
508                 LOCK_SCREEN_TRACE_WARN("spn/plmn:%s", buf);
509         }
510         else
511         {
512                 switch (service_type)
513                 {
514                         case TAPI_NETWORK_SERVICE_TYPE_NO_SERVICE:
515                                 LOCK_SCREEN_TRACE_DBG("No service");
516                                 snprintf(buf, sizeof(buf), "%s", _("IDS_COM_BODY_NO_SERVICE"));
517                                 break;
518                         case TAPI_NETWORK_SERVICE_TYPE_EMERGENCY:
519                                 LOCK_SCREEN_TRACE_DBG("Emergency");
520                                 snprintf(buf, sizeof(buf), "%s", _("IDS_IDLE_MBODY_EMERGENCY_CALLS_ONLY"));
521                                 break;
522                         case TAPI_NETWORK_SERVICE_TYPE_SEARCH:
523                                 LOCK_SCREEN_TRACE_DBG("Searching");
524                                 snprintf(buf, sizeof(buf), "%s", _("IDS_COM_BODY_SEARCHING"));
525                                 break;
526                         default:
527                                 plmn = _sim_network_name(handle);
528                                 if (plmn != NULL && plmn[0] != 0)
529                                 {
530                                         snprintf(buf, sizeof(buf), "%s", plmn);
531                                 }
532                                 break;
533                 }
534                 LOCK_SCREEN_TRACE_WARN("service_type:%d", service_type);
535                 LOCK_SCREEN_TRACE_WARN("spn/plmn:%s", buf);
536         }
537
538         free(spn);
539         free(plmn);
540
541         if (strlen(buf) > 0)
542         {
543                 control_panel_sim_state_changed();
544                 return strdup(buf);
545         }
546         else
547         {
548                 return NULL;
549         }
550
551 }
552
553 /**
554  * @brief Register callbacks
555  * @details Register callback function for sim status, sim name, sim spn , sim plm
556  * @return FALSE if something went wrong.
557  */
558 static void _sim_state_register()
559 {
560         LOGD("");
561
562         int i = 0;
563         int ret;
564
565         ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &s_sim_state.is_flight_mode_on);
566         if(ret != 0)
567         {
568                 LOCK_SCREEN_TRACE_ERR("Could not get 'VCONFKEY_TELEPHONY_FLIGHT_MODE' value");
569         }
570
571         for(i = 0; i < TAPI_HANDLE_MAX; ++i)
572         {
573                 if(s_sim_state.handle[i])
574                 {
575                         ret = tel_register_noti_event(s_sim_state.handle[i], TAPI_NOTI_SIM_STATUS, _sim_status_changed_cb, (void*)i);
576                         if(ret != TAPI_API_SUCCESS)
577                         {
578                                 LOCK_SCREEN_TRACE_ERR("Failed to register _sim_status_changed_cb");
579                         }
580
581                         ret = tel_register_noti_event(s_sim_state.handle[i], TAPI_PROP_NETWORK_PLMN, _sim_name_changed_cb, (void*)i);
582                         if(ret != TAPI_API_SUCCESS)
583                         {
584                                 LOCK_SCREEN_TRACE_ERR("Failed to register _sim_name_changed_cb");
585                         }
586
587                         ret = tel_register_noti_event(s_sim_state.handle[i], TAPI_PROP_NETWORK_SPN_NAME, _sim_name_changed_cb, (void*)i);
588                         if(ret != TAPI_API_SUCCESS)
589                         {
590                                 LOCK_SCREEN_TRACE_ERR("Failed to register _sim_name_changed_cb");
591                         }
592
593                         ret = tel_register_noti_event(s_sim_state.handle[i], TAPI_PROP_NETWORK_NETWORK_NAME, _sim_name_changed_cb, (void*)i);
594                         if(ret != TAPI_API_SUCCESS)
595                         {
596                                 LOCK_SCREEN_TRACE_ERR("Failed to register _sim_name_changed_cb");
597                         }
598
599                         ret = tel_register_noti_event(s_sim_state.handle[i], TAPI_PROP_NETWORK_SERVICE_TYPE, _sim_name_changed_cb, (void*)i);
600                         if(ret != TAPI_API_SUCCESS)
601                         {
602                                 LOCK_SCREEN_TRACE_ERR("Failed to register _sim_name_changed_cb");
603                         }
604
605                         /* roam check */
606                         ret = tel_register_noti_event(s_sim_state.handle[i], TAPI_PROP_NETWORK_ROAMING_STATUS, _sim_roam_changed_cb, (void*)i);
607                         if(ret != TAPI_API_SUCCESS)
608                         {
609                                 LOCK_SCREEN_TRACE_ERR("Failed to register _sim_roam_changed_cb for : %d" , i);
610                         }
611                 }
612         }
613 }
614
615 /**
616  * Unregister sim callbacks
617  */
618 static void _sim_state_unregister()
619 {
620         LOGD("");
621
622         int i = 0;
623         int ret;
624
625         for(i = 0; i < TAPI_HANDLE_MAX; ++i)
626         {
627                 if(s_sim_state.handle[i])
628                 {
629                         ret = tel_deregister_noti_event(s_sim_state.handle[i], TAPI_NOTI_SIM_STATUS);
630                         if(ret != TAPI_API_SUCCESS)
631                         {
632                                 LOCK_SCREEN_TRACE_ERR("Failed to register _sim_status_changed_cb");
633                         }
634
635                         ret = tel_deregister_noti_event(s_sim_state.handle[i], TAPI_PROP_NETWORK_PLMN);
636                         if(ret != TAPI_API_SUCCESS)
637                         {
638                                 LOCK_SCREEN_TRACE_ERR("Failed to register _sim_plm_changed_cb");
639                         }
640
641                         ret = tel_deregister_noti_event(s_sim_state.handle[i], TAPI_PROP_NETWORK_SPN_NAME);
642                         if(ret != TAPI_API_SUCCESS)
643                         {
644                                 LOCK_SCREEN_TRACE_ERR("Failed to register _sim_spn_changed_cb");
645                         }
646
647                         ret = tel_deregister_noti_event(s_sim_state.handle[i], TAPI_PROP_NETWORK_NETWORK_NAME);
648                         if(ret != TAPI_API_SUCCESS)
649                         {
650                                 LOCK_SCREEN_TRACE_ERR("Failed to register _sim_spn_changed_cb");
651                         }
652
653                         ret = tel_deregister_noti_event(s_sim_state.handle[i], TAPI_PROP_NETWORK_SERVICE_TYPE);
654                         if(ret != TAPI_API_SUCCESS)
655                         {
656                                 LOCK_SCREEN_TRACE_ERR("Failed to register _sim_spn_changed_cb");
657                         }
658
659                         ret = tel_deregister_noti_event(s_sim_state.handle[i], TAPI_PROP_NETWORK_ROAMING_STATUS);
660                         if(ret != TAPI_API_SUCCESS)
661                         {
662                                 LOCK_SCREEN_TRACE_ERR("Failed to register _sim_name_changed_cb");
663                         }
664                 }
665         }
666 }
667
668 /**
669  * Callback functions
670  */
671 static void _ready_cb(keynode_t *key, void *data)
672 {
673         Eina_Bool status = EINA_FALSE;
674         status = vconf_keynode_get_bool(key);
675
676         LOCK_SCREEN_TRACE_DBG("TAPI ready:%d", status);
677
678         if(status == TRUE)
679         {
680 #if !DISABLE_TELEPHONY
681                 _sim_status_listener_init();
682 #endif
683                 control_panel_sim_state_changed();
684         }
685         else
686         {
687                 sim_status_listener_deinit();
688         }
689 }
690
691 /**
692  * @brief Vconf callback function for flight mode key.
693  */
694 static void _flight_mode_cb(keynode_t *key, void *data)
695 {
696         s_sim_state.is_flight_mode_on = vconf_keynode_get_bool(key);
697
698         if(!_sim_status_network_names_init())
699         {
700                 LOCK_SCREEN_TRACE_ERR("Failed to reinitialize network names");
701                 return;
702         }
703         control_panel_sim_state_changed();
704 }
705
706 /**
707  * @brief Tapi callback for handle change of sim cards states.
708  */
709 static void _sim_status_changed_cb(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
710 {
711         LOGD("");
712
713         int i = (int) user_data;
714         int *sim_status = data;
715
716         if(*sim_status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED || *sim_status == TAPI_SIM_STATUS_SIM_PIN_REQUIRED)
717         {
718                 s_sim_state.sim_card_ready[i] = EINA_TRUE;
719         }
720         else
721         {
722                 s_sim_state.sim_card_ready[i] = EINA_FALSE;
723         }
724
725         control_panel_sim_state_changed();
726 }
727
728 /**
729  * @brief Tapi callback function for handle network name changes.
730  */
731 static void _sim_name_changed_cb(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
732 {
733         LOGD("");
734
735         if(!_sim_status_network_names_init())
736         {
737                 LOCK_SCREEN_TRACE_ERR("Failed to reinitialize network names");
738                 return;
739         }
740
741         control_panel_sim_state_changed();
742 }
743
744 static void _sim_roam_changed_cb(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
745 {
746         LOGD("");
747
748         guchar *roaming_status = data;
749         int i_roaming_status = *roaming_status;
750
751         if(i_roaming_status)
752         {
753                 s_sim_state.sim_card_roam[(int)user_data] = EINA_TRUE;
754         }
755         else
756         {
757                 s_sim_state.sim_card_roam[(int)user_data] = EINA_FALSE;
758         }
759
760         if(s_sim_state.sim_card_roam[0] || s_sim_state.sim_card_roam[1])
761         {
762                 util_time_roaming_state_set(1);
763         }
764         else
765         {
766                 util_time_roaming_state_set(0);
767         }
768 }
769
770 /**
771  * @brief Gets network name from TAPI handle
772  * @param handle pointer
773  * @return name of network or NULL if error.
774  */
775 static char *_sim_network_name(TapiHandle *handle)
776 {
777         LOGD("");
778
779         int ret;
780         char *name = NULL;
781
782         ret = tel_get_property_string(handle, TAPI_PROP_NETWORK_NETWORK_NAME, &name);
783         if(ret == TAPI_API_SUCCESS && name != NULL)
784         {
785                 return name;
786         }
787         else
788         {
789                 return NULL;
790         }
791 }
792
793 /**
794  * @brief Gets spn name from TAPI handle
795  * @return spn network name  or NULL if error.
796  */
797 static char *_sim_spn_name(TapiHandle *handle)
798 {
799         LOGD("");
800         int ret;
801         char *spn_name = NULL;
802
803         ret = tel_get_property_string(handle, TAPI_PROP_NETWORK_SPN_NAME, &spn_name);
804         if(ret == TAPI_API_SUCCESS && spn_name != NULL)
805         {
806                 return spn_name;
807         }
808         else
809         {
810                 return NULL;
811         }
812 }
813
814 /*!
815  * module
816  */
817 static Evas_Object *_create_view(Evas_Object *parent, LKD_Module_Data *md)
818 {
819         return NULL;
820 }
821
822 static int _destroy_view(LKD_Module_Data *md)
823 {
824         return LKD_RET_OK;
825 }
826
827 static void _resume(LKD_Module_Data *md)
828 {
829 }
830
831 static void _pause(LKD_Module_Data *md)
832 {
833 }
834
835 LKD_Module  g_mod_sim_state = {
836         .id = "sim-state",
837         .notifying = 1,
838         .init = NULL,
839         .fini = NULL,
840         .create_view = _create_view,
841         .destroy_view = _destroy_view,
842         .resume = _resume,
843         .pause = _pause,
844 };