Remove security-server dependency
[apps/core/preloaded/lockscreen.git] / src / sim_state.c
1 /*
2  * Copyright (c) 2009-2014 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 <tapi_common.h>
18 #include <ITapiSim.h>
19 #include <TelCall.h>
20 #include <ITapiSim.h>
21 #include <TelNetwork.h>
22
23 #if TIZEN_BUILD_TARGET
24 //#include <telephony_network.h>
25 #endif
26
27 #include "lockscreen.h"
28 #include "log.h"
29 #include "sim_state.h"
30 #include "property.h"
31 #include "default_lock.h"
32
33 #define NO_SIM_LEN 8
34 #define PLMN_LENGTH 6
35 #define PLMN_SPN_LENGTH 32
36 #define EMG_BUTTON_WIDTH 322
37
38 #define TAPI_HANDLE_MAX  2
39
40 #define PLMN_LABEL_STYLE_START "<style=far_shadow,bottom><shadow_color=#00000033><font_size=24><align=left><color=#FFFFFF><text_class=ATO007><color_class=ATO007><wrap=none>"
41 #define PLMN_LABEL_STYLE_END "</wrap></color_class></text_class></color></align></font_size></shadow_color></style>"
42
43 static struct _s_info {
44         TapiHandle *handle[TAPI_HANDLE_MAX+1];
45         Eina_Bool sim_card_ready[2];
46
47         Evas_Object *layout;
48         Evas_Object *operator_name;
49
50         int call_state; // 0:none, 1:call
51 } s_info = {
52         .handle[0] = NULL,
53         .handle[1] = NULL,
54         .handle[2] = NULL,
55         .sim_card_ready[0] = EINA_FALSE,
56         .sim_card_ready[1] = EINA_FALSE,
57         .layout = NULL,
58         .operator_name = NULL,
59         .call_state = 0,
60 };
61
62 static void _sim_callback_register(void);
63 static void _sim_callback_unregister(void);
64
65 static void _operator_name_slide_mode_set(Evas_Object *label)
66 {
67         Evas_Object *label_edje = NULL;
68         Evas_Object *tb = NULL;
69         Evas_Coord tb_w = 0;
70
71         ret_if(!label);
72
73         elm_label_slide_mode_set(label, ELM_LABEL_SLIDE_MODE_NONE);
74
75         label_edje = elm_layout_edje_get(label);
76         ret_if(!label_edje);
77
78         tb = (Evas_Object*)edje_object_part_object_get(label_edje, "elm.text");
79         ret_if(!tb);
80
81         evas_object_textblock_size_native_get(tb, &tb_w, NULL);
82
83         if ((tb_w > 0) && (tb_w > _X(EMG_BUTTON_WIDTH))) {
84                 elm_label_slide_mode_set(label, ELM_LABEL_SLIDE_MODE_AUTO);
85         }
86
87         elm_label_slide_go(label);
88 }
89
90 static void _operator_sliding_label_create(Evas_Object *layout, char *text)
91 {
92         Evas_Object *label = NULL;
93         char buf[512] = { 0, };
94         char *markup_text = NULL;
95
96         label = elm_label_add(layout);
97         ret_if(!label);
98
99         markup_text = elm_entry_utf8_to_markup(text);
100         snprintf(buf, sizeof(buf), "%s%s%s", PLMN_LABEL_STYLE_START, markup_text, PLMN_LABEL_STYLE_END);
101         free(markup_text);
102
103         elm_object_style_set(label, "slide_short");
104         elm_label_wrap_width_set(label, 100);
105         elm_label_ellipsis_set(label, EINA_TRUE);
106         elm_label_slide_duration_set(label, 2);
107         _operator_name_slide_mode_set(label);
108
109         elm_object_text_set(label, buf);
110
111         elm_object_part_content_set(layout, "txt.plmn", label);
112         evas_object_show(label);
113
114         s_info.operator_name = label;
115 }
116
117 static int _sim_controller_get_call_state(void)
118 {
119         int value = 0;
120         int ret = 0;
121
122         ret = lock_property_get_int(PROPERTY_TYPE_VCONFKEY, VCONFKEY_CALL_STATE, &value);
123         retv_if(ret != LOCK_ERROR_OK, 0);
124
125         if (value == VCONFKEY_CALL_OFF) {
126                 _E("Call is OFF");
127                 return 0;
128         }
129
130         _D("Call status[%d]", value);
131
132         return 1;
133 }
134
135 static void _sim_controller_call_state_changed_cb(keynode_t *key, void *data)
136 {
137         int call_state = _sim_controller_get_call_state();
138
139         if (s_info.call_state != call_state) {
140                 _D("Call state changed[%d]", call_state);
141                 s_info.call_state = call_state;
142         }
143 }
144
145 static char *_sim_plmn_get(TapiHandle *handle)
146 {
147         int ret = 0;
148         char *network_name = NULL;
149
150         /* Reading Network (PLMN) name - ‘string’ type Property */
151         ret = tel_get_property_string(handle, TAPI_PROP_NETWORK_NETWORK_NAME, &network_name);
152         if (ret == TAPI_API_SUCCESS) {
153                 /* ‘network_name’ contains valid Network name based on Display condition */
154                 return network_name;
155         } else {
156                 _E("Sim = %p PLMN = ERROR[%d]", handle, ret);
157                 /* get property failed */
158         }
159
160         return NULL;
161 }
162
163 static char *_sim_spn_get(TapiHandle *handle)
164 {
165         int ret = 0;
166         char *spn_name = NULL;
167
168         /* Reading SPN name - ‘string’ type Property */
169         ret = tel_get_property_string(handle, TAPI_PROP_NETWORK_SPN_NAME, &spn_name);
170         if (ret == TAPI_API_SUCCESS) {
171                 /* ‘spn_name’ contains valid Service provider name */
172                 return spn_name;
173         } else {
174                 _E("Sim = %p SPN = ERROR[%d]", handle, ret);
175                 /* get property failed */
176                 return NULL;
177         }
178 }
179
180 static char *_plmn_spn_network_get(int handle_num, TapiHandle *handle)
181 {
182         int ret = TAPI_API_SUCCESS;
183         int service_type = TAPI_NETWORK_SERVICE_TYPE_UNKNOWN;
184         int name_option = TAPI_NETWORK_DISP_INVALID;
185         char *plmn = NULL;
186         char *spn = NULL;
187         char buf[1024] = { 0, };
188
189         // get service type
190         ret = tel_get_property_int(handle, TAPI_PROP_NETWORK_SERVICE_TYPE, &service_type);
191         if (ret != TAPI_API_SUCCESS) {
192                 _E("Failed to get service type[%d]", ret);
193         }
194
195         if (service_type >= TAPI_NETWORK_SERVICE_TYPE_2G) {
196                 // get network name option
197                 ret = tel_get_property_int(handle, TAPI_PROP_NETWORK_NAME_OPTION, &name_option);
198                 if (ret != TAPI_API_SUCCESS) {
199                         _E("Failed to get name option[%d]", ret);
200                 }
201
202                 switch (name_option) {
203                 case TAPI_NETWORK_DISP_SPN:
204                         spn = _sim_spn_get(handle);
205                         if (spn != NULL && spn[0] != 0) {
206                                 _I("PLMN/SPN - Sim %p using SPN: %s", handle, spn);
207                                 snprintf(buf, sizeof(buf), "%s", spn);
208                         }
209                         break;
210                 case TAPI_NETWORK_DISP_PLMN:
211                         plmn = _sim_plmn_get(handle);
212                         if (plmn != NULL && plmn[0] != 0) {
213                                 _I("PLMN/SPN - Sim %p using PLMN: %s", handle, plmn);
214                                 snprintf(buf, sizeof(buf), "%s", plmn);
215                         }
216                         break;
217                 case TAPI_NETWORK_DISP_SPN_PLMN:
218                         spn = _sim_spn_get(handle);
219                         plmn = _sim_plmn_get(handle);
220                         if (spn != NULL && spn[0] != 0 && plmn != NULL && plmn[0] != 0) {
221                                 _I("PLMN/SPN - Sim %p using SPN: %s, PLMN: %s", handle, spn, plmn);
222                                 snprintf(buf, sizeof(buf), "%s - %s", plmn, spn);
223                         } else if (spn != NULL && spn[0] != 0) {
224                                 _I("PLMN/SPN - Sim %p using SPN: %s", handle, spn);
225                                 snprintf(buf, sizeof(buf), "%s", spn);
226                         } else if (plmn != NULL && plmn[0] != 0) {
227                                 _I("PLMN/SPN - Sim %p using PLMN: %s", handle, plmn);
228                                 snprintf(buf, sizeof(buf), "%s", plmn);
229                         }
230                         break;
231                 default:
232                         _E("Invalid name option[%d]", name_option);
233                         plmn = _sim_plmn_get(handle);
234                         if (plmn != NULL && plmn[0] != 0) {
235                                 _I("PLMN/SPN - Sim %p using PLMN: %s", handle, plmn);
236                                 snprintf(buf, sizeof(buf), "%s", plmn);
237                         }
238                         break;
239                 }
240         } else {
241                 switch (service_type) {
242                 case TAPI_NETWORK_SERVICE_TYPE_NO_SERVICE:
243                         snprintf(buf, sizeof(buf), "%s", _("IDS_COM_BODY_NO_SERVICE"));
244                         break;
245                 case TAPI_NETWORK_SERVICE_TYPE_EMERGENCY:
246                         snprintf(buf, sizeof(buf), "%s", _("IDS_IDLE_MBODY_EMERGENCY_CALLS_ONLY"));
247                         break;
248                 case TAPI_NETWORK_SERVICE_TYPE_SEARCH:
249                         snprintf(buf, sizeof(buf), "%s", _("IDS_COM_BODY_SEARCHING"));
250                         break;
251                 default:
252                         _E("invalid service type[%d]", service_type);
253                         plmn = _sim_plmn_get(handle);
254                         if (plmn != NULL && plmn[0] != 0) {
255                                 _I("PLMN/SPN - Sim %p using PLMN: %s", handle, plmn);
256                                 snprintf(buf, sizeof(buf), "%s", plmn);
257                         }
258                         break;
259                 }
260         }
261
262         _D("handle[%d][%p] service_type[%d], name_option[%d] >> [%s]", handle_num, handle, service_type, name_option, buf);
263
264         if (strlen(buf) == 0) {
265                 _E("Empty string");
266                 snprintf(buf, sizeof(buf), "%s", _("IDS_COM_BODY_NO_SERVICE"));
267         } else if (strncasecmp(buf, "No Service", strlen("No Service")) == 0) {
268                 _E("USING SPECIAL NETWORK NAME:  %s in handle: %d", _("IDS_COM_BODY_NO_SERVICE"), handle_num);
269                 return strdup(_("IDS_COM_BODY_NO_SERVICE"));
270         } else if (strncasecmp(buf, "EMERGENCY", strlen("EMERGENCY")) == 0) {
271                 _E("USING SPECIAL NETWORK NAME:  %s in handle: %d", _("IDS_IDLE_MBODY_EMERGENCY_CALLS_ONLY"), handle_num);
272                 return strdup(_("IDS_IDLE_MBODY_EMERGENCY_CALLS_ONLY"));
273         } else if (strncasecmp(buf, "Searching", strlen("Searching")) == 0) {
274                 _E("USING SPECIAL NETWORK NAME:  %s in handle: %d", _("IDS_COM_BODY_SEARCHING"), handle_num);
275                 return strdup(_("IDS_COM_BODY_SEARCHING"));
276         } else if (strncasecmp(buf, "SIM _Eor", strlen("SIM Error")) == 0) {
277                 _E("USING SPECIAL NETWORK NAME:  %s in handle: %d", _("IDS_IDLE_BODY_INVALID_SIM_CARD"), handle_num);
278                 return strdup(_("IDS_IDLE_BODY_INVALID_SIM_CARD"));
279         } else if (strncasecmp(buf, "NO SIM", strlen("NO SIM")) == 0) {
280                 _E("USING SPECIAL NETWORK NAME:  %s in handle: %d", _("IDS_IDLE_MBODY_EMERGENCY_CALLS_ONLY"), handle_num);
281                 return strdup(_("IDS_IDLE_MBODY_EMERGENCY_CALLS_ONLY"));
282         }
283
284         return strdup(buf);
285 }
286
287 static void _sim_status_print(TelSimCardStatus_t sim_status, int card_changed)
288 {
289         switch(sim_status) {
290         case TAPI_SIM_STATUS_CARD_ERROR:
291                 _I("Sim card status: TAPI_SIM_STATUS_CARD__EOR");
292                 break;
293         case TAPI_SIM_STATUS_CARD_NOT_PRESENT:
294                 _I("Sim card status: TAPI_SIM_STATUS_CARD_NOT_PRESENT");
295                 break;
296         case TAPI_SIM_STATUS_SIM_INITIALIZING:
297                 _I("Sim card status: TAPI_SIM_STATUS_SIM_INITIALIZING");
298                 break;
299         case TAPI_SIM_STATUS_SIM_INIT_COMPLETED:
300                 _I("Sim card status: TAPI_SIM_STATUS_SIM_INIT_COMPLETED");
301                 break;
302         case TAPI_SIM_STATUS_SIM_PIN_REQUIRED:
303                 _I("Sim card status: TAPI_SIM_STATUS_SIM_PIN_REQUIRED");
304                 break;
305         case TAPI_SIM_STATUS_SIM_PUK_REQUIRED:
306                 _I("Sim card status: TAPI_SIM_STATUS_SIM_PUK_REQUIRED");
307                 break;
308         case TAPI_SIM_STATUS_CARD_BLOCKED:
309                 _I("Sim card status: TAPI_SIM_STATUS_CARD_BLOCKED");
310                 break;
311         case TAPI_SIM_STATUS_SIM_NCK_REQUIRED:
312                 _I("Sim card status: TAPI_SIM_STATUS_SIM_NCK_REQUIRED");
313                 break;
314         case TAPI_SIM_STATUS_SIM_NSCK_REQUIRED:
315                 _I("Sim card status: TAPI_SIM_STATUS_SIM_NSCK_REQUIRED");
316                 break;
317         case TAPI_SIM_STATUS_SIM_SPCK_REQUIRED:
318                 _I("Sim card status: TAPI_SIM_STATUS_SIM_SPCK_REQUIRED");
319                 break;
320         case TAPI_SIM_STATUS_SIM_CCK_REQUIRED:
321                 _I("Sim card status: TAPI_SIM_STATUS_SIM_CCK_REQUIRED");
322                 break;
323         case TAPI_SIM_STATUS_CARD_REMOVED:
324                 _I("Sim card status: TAPI_SIM_STATUS_CARD_REMOVED");
325                 break;
326         case TAPI_SIM_STATUS_SIM_LOCK_REQUIRED:
327                 _I("Sim card status: TAPI_SIM_STATUS_SIM_LOCK_REQUIRED");
328                 break;
329         case TAPI_SIM_STATUS_CARD_CRASHED:
330                 _I("Sim card status: TAPI_SIM_STATUS_CARD_CRASHED");
331                 break;
332         case TAPI_SIM_STATUS_CARD_POWEROFF:
333                 _I("Sim card status: TAPI_SIM_STATUS_CARD_POWEROFF");
334                 break;
335         case TAPI_SIM_STATUS_UNKNOWN:
336                 _I("Sim card status: TAPI_SIM_STATUS_UNKNOWN");
337                 break;
338         }
339
340         _I("Sim_card_changed: %d", card_changed);
341 }
342
343 static void _sim_status_get(void)
344 {
345         int i = 0;
346         int ret = 0;
347         TelSimCardStatus_t sim_status;
348         int card_changed = 0;
349
350         for (i = 0; i < TAPI_HANDLE_MAX + 1; ++i) {
351                 if (s_info.handle[i]) {
352                         ret = tel_get_sim_init_info (s_info.handle[i], &sim_status, &card_changed);
353                         if (ret == 0) {
354                                 _sim_status_print(sim_status, card_changed);
355
356                                 if (sim_status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED || sim_status == TAPI_SIM_STATUS_SIM_PIN_REQUIRED) {
357                                         if (i < TAPI_HANDLE_MAX) {
358                                                 s_info.sim_card_ready[i] = EINA_TRUE;
359                                         }
360                                 } else {
361                                         _E("SIM[%d] is not completed initialization [%d]", i, sim_status);
362                                 }
363                         } else {
364                                 _E("Could not get sim[%d] status[%d]", i, ret);
365                         }
366                 }
367         }
368 }
369
370 static void _sim_state_text_set(Eina_Bool flight_mode)
371 {
372         Evas_Object *swipe_layout = lock_default_swipe_layout_get();
373         ret_if(!swipe_layout);
374
375         if (flight_mode) {
376                 /* if flight mode, No service */
377                 _operator_sliding_label_create(swipe_layout, _("IDS_COM_BODY_NO_SERVICE"));
378         } else if (s_info.sim_card_ready[0] && s_info.sim_card_ready[1]) {
379                 _operator_sliding_label_create(swipe_layout, "");
380         } else if (s_info.sim_card_ready[0]) {
381                 char *plmn_spn1 = _plmn_spn_network_get(0, s_info.handle[0]);
382                 _operator_sliding_label_create(swipe_layout, plmn_spn1);
383                 free(plmn_spn1);
384         } else if (s_info.sim_card_ready[1]) {
385                 char *plmn_spn1 = _plmn_spn_network_get(1, s_info.handle[1]);
386                 _operator_sliding_label_create(swipe_layout, plmn_spn1);
387                 free(plmn_spn1);
388         } else {
389                 _operator_sliding_label_create(swipe_layout, _("IDS_IDLE_MBODY_EMERGENCY_CALLS_ONLY"));
390         }
391 }
392
393 static void _view_init(void)
394 {
395         int flight_mode_state = EINA_FALSE;
396         int ret = 0;
397
398         ret = lock_property_get_bool(PROPERTY_TYPE_VCONFKEY, VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode_state);
399         if (ret != LOCK_ERROR_OK) {
400                 _E("Could not get 'VCONFKEY_TELEPHONY_FLIGHT_MODE' value");
401         }
402
403         _sim_state_text_set(flight_mode_state);
404 }
405
406 static void _tel_init(void)
407 {
408         char **cp_list = NULL;
409         unsigned int modem_num = 0;
410
411         /* Get CP name list – cp_list */
412         cp_list = tel_get_cp_name_list();
413         ret_if(!cp_list);
414
415         while (cp_list[modem_num]) {
416                 /* Initialize TAPI handle */
417                 s_info.handle[modem_num] = tel_init(cp_list[modem_num]);
418
419                 if (cp_list[modem_num]) {
420                         _E("s_info.handle[%d] = %s; ptr = %p", modem_num, cp_list[modem_num], s_info.handle[modem_num]);
421                 }
422
423                 /* Move to next CP Name in cp_list */
424                 modem_num++;
425         }
426
427         s_info.handle[modem_num] = NULL;
428
429         /* free cp_list */
430         free(cp_list);
431 }
432
433 static void _tel_deinit(void)
434 {
435         int i = 0;
436         while (s_info.handle[i]) {
437                 /* De-initialize TAPI handle */
438                 tel_deinit(s_info.handle[i]);
439                 s_info.handle[i] = NULL;
440
441                 /* Move to next handle */
442                 i++;
443         }
444 }
445
446 static void _tel_ready_cb(keynode_t *key, void *data)
447 {
448         Eina_Bool status = EINA_FALSE;
449
450         status = vconf_keynode_get_bool(key);
451         _D("tel status[%d]", status);
452
453         if (status) {   /* Telephony State - READY */
454                 _tel_init();
455                 _sim_callback_register();
456                 _sim_status_get();
457
458                 _view_init();
459         } else {   /* Telephony State – NOT READY */
460                 /* De-initialization is optional here (ONLY if required) */
461                 _tel_deinit();
462                 s_info.sim_card_ready[0] = EINA_FALSE;
463                 s_info.sim_card_ready[1] = EINA_FALSE;
464
465                 _sim_callback_unregister();
466         }
467 }
468
469 static void _tel_flight_mode_cb(keynode_t *key, void *data)
470 {
471         Eina_Bool flight_mode_state = EINA_FALSE;
472
473         flight_mode_state = vconf_keynode_get_bool(key);
474         _sim_state_text_set(flight_mode_state);
475 }
476
477 static void _on_sim_card_status_changed_cb(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
478 {
479         int handle_num = (int)user_data;
480         int *sim_status = data;
481
482         _E("SIM[%p][%d] status[%d], [%d][%d]", handle, handle_num, *sim_status, s_info.sim_card_ready[0], s_info.sim_card_ready[1]);
483
484         if (*sim_status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED || *sim_status == TAPI_SIM_STATUS_SIM_PIN_REQUIRED) {
485                 s_info.sim_card_ready[handle_num] = EINA_TRUE;
486         } else {
487                 s_info.sim_card_ready[handle_num] = EINA_FALSE;
488         }
489
490         _view_init();
491 }
492
493 static void _on_plmn_spn_changed_cb(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
494 {
495         int  flight_mode_state = EINA_FALSE;
496         int ret = 0;
497
498         ret_if(!handle);
499
500         ret = lock_property_get_bool(PROPERTY_TYPE_VCONFKEY, VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode_state);
501         if (ret != LOCK_ERROR_OK) {
502                 _E("Could not get the 'VCONFKEY_TELEPHONY_FLIGHT_MODE' value");
503         }
504
505         _sim_state_text_set(flight_mode_state);
506 }
507
508 static void _sim_callback_register(void)
509 {
510         int i = 0;
511         int ret = 0;
512
513         for (i = 0; i < TAPI_HANDLE_MAX; ++i) {
514                 if (s_info.handle[i]) {
515                         ret = tel_register_noti_event(s_info.handle[i], TAPI_NOTI_SIM_STATUS, _on_sim_card_status_changed_cb, (void*)i);
516                         if (ret != TAPI_API_SUCCESS) {
517                                 _E("Failed to register '_on_sim_card_status_changed_cb' callback to handle[%d][%d]", i, ret);
518                         } else {
519                                 _E("SIM card status changed event registered");
520                         }
521
522                         ret = tel_register_noti_event(s_info.handle[i], TAPI_PROP_NETWORK_SPN_NAME, _on_plmn_spn_changed_cb, (void*)i);
523                         if (ret != TAPI_API_SUCCESS) {
524                                 _E("Failed to register '_on_plmn_spn_changed_cb' callback to handle[%d][%d]", i, ret);
525                         }
526
527                         ret = tel_register_noti_event(s_info.handle[i], TAPI_PROP_NETWORK_NETWORK_NAME, _on_plmn_spn_changed_cb, (void*)i);
528                         if (ret != TAPI_API_SUCCESS) {
529                                 _E("Failed to register '_on_plmn_spn_changed_cb' callback to handle: %i", i);
530                         }
531
532                         ret = tel_register_noti_event(s_info.handle[i], TAPI_PROP_NETWORK_SERVICE_TYPE, _on_plmn_spn_changed_cb, (void*) i);
533                         if (ret != TAPI_API_SUCCESS) {
534                                 _E("Failed to register network service type[%d][%d]", ret, i);
535                         }
536
537                         ret = tel_register_noti_event(s_info.handle[i], TAPI_PROP_NETWORK_NAME_OPTION, _on_plmn_spn_changed_cb, (void*) i);
538                         if (ret != TAPI_API_SUCCESS) {
539                                 _E("Failed to register network name option[%d][%d]", ret, i);
540                         }
541                 } else {
542                         _E("No handle [%d]", i);
543                 }
544         }
545 }
546
547 static void _sim_callback_unregister(void)
548 {
549         int i = 0;
550         int ret = 0;
551         for (i = 0; i < TAPI_HANDLE_MAX; ++i) {
552                 if (s_info.handle[i]) {
553                         ret = tel_deregister_noti_event(s_info.handle[i], TAPI_NOTI_SIM_STATUS);
554                         if (ret != TAPI_API_SUCCESS) {
555                                 _E("Failed to dereregister TAPI_NOTI_SIM_STATUS callback from handle: %i", i);
556                         } else {
557                                 _D("SIM status changed event deregistered");
558                         }
559
560                         ret = tel_deregister_noti_event(s_info.handle[i], TAPI_PROP_NETWORK_NETWORK_NAME);
561                         if (ret != TAPI_API_SUCCESS) {
562                                 _E("Failed to dereregister TAPI_PROP_NETWORK_PLMN callback from handle: %i", i);
563                         }
564
565                         ret = tel_deregister_noti_event(s_info.handle[i], TAPI_PROP_NETWORK_SPN_NAME);
566                         if (ret != TAPI_API_SUCCESS) {
567                                 _E("Failed to dereregister TAPI_PROP_NETWORK_SPN_NAME callback from handle: %i", i);
568                         }
569
570                         ret = tel_deregister_noti_event(s_info.handle[i], TAPI_PROP_NETWORK_SERVICE_TYPE);
571                         if (ret != TAPI_API_SUCCESS) {
572                                 _E("Failed to deregister network service type[%d][%d]", ret, i);
573                         }
574
575                         ret = tel_deregister_noti_event(s_info.handle[i], TAPI_PROP_NETWORK_NAME_OPTION);
576                         if (ret != TAPI_API_SUCCESS) {
577                                 _E("Failed to deregister network name option[%d][%d]", ret, i);
578                         }
579
580                         if (i == 0) {
581                                 ret = tel_deregister_noti_event(s_info.handle[i], TAPI_NOTI_CALL_PREFERRED_VOICE_SUBSCRIPTION);
582                                 if (ret != TAPI_API_SUCCESS) {
583                                         _E("Failed to dereregister  callback to handle: %d", i);
584                                 }
585                         }
586                 }
587         }
588 }
589
590
591 lock_error_e lock_sim_state_init(void)
592 {
593         int state = EINA_FALSE;
594         int ret = 0;
595         /* Check if Telephony state - READY */
596         ret = lock_property_get_bool(PROPERTY_TYPE_VCONFKEY, VCONFKEY_TELEPHONY_READY, &state);
597
598         _D("Telephony Ready : %d", state);
599
600         if (ret == LOCK_ERROR_OK && state == EINA_TRUE) {
601                 /* Telephony State - READY */
602                 /* Initialize TAPI handles */
603
604                 _tel_init();
605                 _sim_callback_register();
606                 _sim_status_get();
607
608                 _view_init();
609         } else {
610                 /* Telephony State – NOT READY, register for change in state */
611                 _D("Telephony state: [NOT Ready]");
612         }
613
614         /* Register for Telephony state change */
615         ret = vconf_notify_key_changed(VCONFKEY_TELEPHONY_READY, _tel_ready_cb, NULL);
616         if (ret != 0) {
617                 _E("Failed to register VCONFKEY_TELEPHONY_READY key changed callback");
618         }
619
620         ret = vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, _tel_flight_mode_cb, NULL);
621         if (ret != 0) {
622                 _E("Failed to register VCONFKEY_TELEPHONY_FLIGHT_MODE key changed callback");
623         }
624
625         ret = vconf_notify_key_changed(VCONFKEY_CALL_STATE, _sim_controller_call_state_changed_cb, NULL);
626         if (ret != 0) {
627                 _E("Failed to notify call state[%d]", ret);
628         }
629
630         return LOCK_ERROR_OK;
631 }
632
633 void lock_sim_state_resume(void)
634 {
635         int state = FALSE;
636         int ret = 0;
637         int i = 0;
638         TelSimCardStatus_t sim_status;
639         int card_changed = 0;
640
641         ret = lock_property_get_bool(PROPERTY_TYPE_VCONFKEY, VCONFKEY_TELEPHONY_READY, &state);
642         if (ret != LOCK_ERROR_OK || state == FALSE) {
643                 _E("Failed to get telephony state[%d][%d]", state, ret);
644                 return;
645         }
646
647         for (i = 0; i < TAPI_HANDLE_MAX; ++i) {
648                 if (s_info.handle[i]) {
649                         ret = tel_get_sim_init_info(s_info.handle[i], &sim_status, &card_changed);
650                         _D("SIM[%d] info[%d][%d][%d]", i, ret, sim_status, card_changed);
651                         if (sim_status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED || sim_status == TAPI_SIM_STATUS_SIM_PIN_REQUIRED) {
652                                 if (s_info.sim_card_ready[i] != EINA_TRUE) {
653                                         _E("SIM[%d] is init completed but local value is not ture", i);
654                                 }
655                         }
656                 } else {
657                         _E("No handle[%d]", i);
658                 }
659         }
660 }
661
662 void lock_sim_state_deinit(void)
663 {
664         _D("De-initialization");
665         _tel_deinit();
666         s_info.sim_card_ready[0] = EINA_FALSE;
667         s_info.sim_card_ready[1] = EINA_FALSE;
668
669         _sim_callback_unregister();
670 }
671
672 void lock_sim_state_language_change(void)
673 {
674         _on_plmn_spn_changed_cb(s_info.handle[0], "SELF", NULL, (void*) 0);
675         _on_plmn_spn_changed_cb(s_info.handle[1], "SELF", NULL, (void*) 1);
676
677         if (s_info.handle[0] == NULL && s_info.handle[1] == NULL) {
678                 int flight_mode = EINA_FALSE;
679                 int ret = lock_property_get_bool(PROPERTY_TYPE_VCONFKEY, VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
680                 if (ret != 0) {
681                         _E("Failed to get flight mode[%d]", ret);
682                 }
683
684                 _sim_state_text_set(flight_mode);
685         }
686 }