merge from 2.4 , block compile error
[apps/core/preloaded/quickpanel.git] / daemon / sim_controller.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
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <Evas.h>
22 #include <Elementary.h>
23 #include <Eina.h>
24 #include <dlog.h>
25 #include <vconf.h>
26
27 #include <tapi_common.h>
28 #include <ITapiSim.h>
29 #include <TelCall.h>
30 #include <ITapiCall.h>
31 #include <TelNetwork.h>
32 #include "setting_utils.h"
33
34 #include "list_util.h"
35 #include "quickpanel-ui.h"
36 #include "common.h"
37
38 #include "handler_controller.h"
39
40 #define TAPI_HANDLE_MAX  2
41
42 static struct
43 {
44         TapiHandle *handle[TAPI_HANDLE_MAX+1];
45         Eina_Bool sim_card_ready[2];
46
47         Evas_Object *layout;
48
49         int call_state; // 0:none, 1:call
50 }
51 sim_state_info =
52 {
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                 .layout = NULL,
59                 .call_state = 0,
60 };
61
62 static int _sim_controller_get_call_state(void);
63
64 static void register_sim_callbacks();
65 static void unregister_sim_callbacks();
66
67 static void __sim_controller_call_state_changed_cb(keynode_t *key, void *data)
68 {
69         int call_state = _sim_controller_get_call_state();
70
71         if (sim_state_info.call_state != call_state)
72         {
73                 DBG("Call state changed[%d]", call_state);
74                 sim_state_info.call_state = call_state;
75         }
76 }
77
78 static int _sim_controller_get_call_state(void)
79 {
80         int value = 0;
81         int ret = 0;
82
83         ret = vconf_get_int(VCONFKEY_CALL_STATE, &value);
84         if (ret != 0)
85         {
86                 ERR("Failed to get call state");
87                 return 0;
88         }
89
90         if (value == VCONFKEY_CALL_OFF)
91         {
92                 return 0;
93         }
94
95         DBG("Call status[%d]", value);
96         return 1;
97 }
98
99 static char *get_sim_plmn(TapiHandle *handle)
100 {
101         int ret;
102         char *network_name = NULL;
103
104         /* Reading Network (PLMN) name - ‘string’ type Property */
105         ret = tel_get_property_string(handle,
106                         TAPI_PROP_NETWORK_NETWORK_NAME, &network_name);
107         if(ret == TAPI_API_SUCCESS)
108         {
109           /* ‘network_name’ contains valid Network name based on Display condition */
110                 return network_name;
111         }
112         else
113         {
114                 ERR("Sim = %p PLMN = ERROR[%d]", handle, ret);
115           /* get property failed */
116         }
117
118         return NULL;
119 }
120
121 static char *get_sim_spn(TapiHandle *handle)
122 {
123         int ret;
124         char *spn_name = NULL;
125
126
127         /* Reading SPN name - ‘string’ type Property */
128         ret = tel_get_property_string(handle,
129                         TAPI_PROP_NETWORK_SPN_NAME, &spn_name);
130         if(ret == TAPI_API_SUCCESS)
131         {
132           /* ‘spn_name’ contains valid Service provider name */
133                 return spn_name;
134         }
135         else
136         {
137                 ERR("Sim = %p SPN = ERROR[%d]", handle, ret);
138           /* get property failed */
139                 return NULL;
140         }
141 }
142
143 static char *get_plmn_spn_network(int handle_num, TapiHandle *handle)
144 {
145         int ret = TAPI_API_SUCCESS;
146         int service_type = TAPI_NETWORK_SERVICE_TYPE_UNKNOWN;
147         int name_option = TAPI_NETWORK_DISP_INVALID;
148         char *plmn = NULL;
149         char *spn = NULL;
150         char buf[1024] = { 0, };
151
152         // get service type
153         ret = tel_get_property_int(handle, TAPI_PROP_NETWORK_SERVICE_TYPE, &service_type);
154         if (ret != TAPI_API_SUCCESS)
155         {
156                 ERR("Failed to get service type[%d]", ret);
157         }
158
159         if (service_type >= TAPI_NETWORK_SERVICE_TYPE_2G)
160         {
161                 // get network name option
162                 ret = tel_get_property_int(handle, TAPI_PROP_NETWORK_NAME_OPTION, &name_option);
163                 if (ret != TAPI_API_SUCCESS)
164                 {
165                         ERR("Failed to get name option[%d]", ret);
166                 }
167
168                 switch (name_option)
169                 {
170                 case TAPI_NETWORK_DISP_SPN:
171                         spn = get_sim_spn(handle);
172                         if (spn != NULL && spn[0] != 0)
173                         {
174                                 INFO("PLMN/SPN - Sim %p using SPN: %s", handle, spn);
175                                 snprintf(buf, sizeof(buf), "%s", spn);
176                         }
177                         break;
178                 case TAPI_NETWORK_DISP_PLMN:
179                         plmn = get_sim_plmn(handle);
180                         if (plmn != NULL && plmn[0] != 0)
181                         {
182                                 INFO("PLMN/SPN - Sim %p using PLMN: %s", handle, plmn);
183                                 snprintf(buf, sizeof(buf), "%s", plmn);
184                         }
185                         break;
186                 case TAPI_NETWORK_DISP_SPN_PLMN:
187                         spn = get_sim_spn(handle);
188                         plmn = get_sim_plmn(handle);
189                         if (spn != NULL && spn[0] != 0 && plmn != NULL && plmn[0] != 0)
190                         {
191                                 INFO("PLMN/SPN - Sim %p using SPN: %s, PLMN: %s", handle, spn, plmn);
192                                 snprintf(buf, sizeof(buf), "%s - %s", plmn, spn);
193                         }
194                         else if (spn != NULL && spn[0] != 0)
195                         {
196                                 INFO("PLMN/SPN - Sim %p using SPN: %s", handle, spn);
197                                 snprintf(buf, sizeof(buf), "%s", spn);
198                         }
199                         else if (plmn != NULL && plmn[0] != 0)
200                         {
201                                 INFO("PLMN/SPN - Sim %p using PLMN: %s", handle, plmn);
202                                 snprintf(buf, sizeof(buf), "%s", plmn);
203                         }
204                         break;
205                 default:
206                         ERR("Invalid name option[%d]", name_option);
207                         plmn = get_sim_plmn(handle);
208                         if (plmn != NULL && plmn[0] != 0)
209                         {
210                                 INFO("PLMN/SPN - Sim %p using PLMN: %s", handle, plmn);
211                                 snprintf(buf, sizeof(buf), "%s", plmn);
212                         }
213                         break;
214                 }
215         }
216         else
217         {
218                 switch (service_type)
219                 {
220                 case TAPI_NETWORK_SERVICE_TYPE_NO_SERVICE:
221                         snprintf(buf, sizeof(buf), "%s", _("IDS_IDLE_BODY_NO_SERVICE"));
222                         break;
223                 case TAPI_NETWORK_SERVICE_TYPE_EMERGENCY:
224                         snprintf(buf, sizeof(buf), "%s", _("IDS_IDLE_MBODY_EMERGENCY_CALLS_ONLY"));
225                         break;
226                 case TAPI_NETWORK_SERVICE_TYPE_SEARCH:
227                         snprintf(buf, sizeof(buf), "%s", _("IDS_COM_BODY_SEARCHING"));
228                         break;
229                 default:
230                         ERR("invalid service type[%d]", service_type);
231                         plmn = get_sim_plmn(handle);
232                         if (plmn != NULL && plmn[0] != 0)
233                         {
234                                 INFO("PLMN/SPN - Sim %p using PLMN: %s", handle, plmn);
235                                 snprintf(buf, sizeof(buf), "%s", plmn);
236                         }
237                         break;
238                 }
239         }
240
241         DBG("handle[%d][%p] service_type[%d], name_option[%d] >> [%s]", handle_num, handle, service_type, name_option, buf);
242
243         if (strlen(buf) == 0)
244         {
245                 ERR("Empty string");
246                 snprintf(buf, sizeof(buf), "%s", _("IDS_IDLE_BODY_NO_SERVICE"));
247         }
248         else if (strncasecmp(buf, "No Service", strlen("No Service")) == 0)
249         {
250                 ERR("USING SPECIAL NETWORK NAME:  %s in handle: %d", _("IDS_IDLE_BODY_NO_SERVICE"), handle_num);
251                 return strdup(_("IDS_IDLE_BODY_NO_SERVICE"));
252         }
253         else if (strncasecmp(buf, "EMERGENCY", strlen("EMERGENCY")) == 0)
254         {
255                 ERR("USING SPECIAL NETWORK NAME:  %s in handle: %d", _("IDS_IDLE_MBODY_EMERGENCY_CALLS_ONLY"), handle_num);
256                 return strdup(_("IDS_IDLE_MBODY_EMERGENCY_CALLS_ONLY"));
257         }
258         else if (strncasecmp(buf, "Searching", strlen("Searching")) == 0)
259         {
260                 ERR("USING SPECIAL NETWORK NAME:  %s in handle: %d", _("IDS_COM_BODY_SEARCHING"), handle_num);
261                 return strdup(_("IDS_COM_BODY_SEARCHING"));
262         }
263         else if (strncasecmp(buf, "SIM Error", strlen("SIM Error")) == 0)
264         {
265                 ERR("USING SPECIAL NETWORK NAME:  %s in handle: %d", _("IDS_IDLE_BODY_INVALID_SIM_CARD"), handle_num);
266                 return strdup(_("IDS_IDLE_BODY_INVALID_SIM_CARD"));
267         }
268         else if (strncasecmp(buf, "NO SIM", strlen("NO SIM")) == 0)
269         {
270                 ERR("USING SPECIAL NETWORK NAME:  %s in handle: %d", _("IDS_IDLE_MBODY_EMERGENCY_CALLS_ONLY"), handle_num);
271                 return strdup(_("IDS_IDLE_MBODY_EMERGENCY_CALLS_ONLY"));
272         }
273
274         return strdup(buf);
275 }
276
277 // --------------------------------------------------------------------------------------------
278 static void print_sim_status(TelSimCardStatus_t sim_status, int card_changed)
279 {
280         switch(sim_status)
281         {
282                 case TAPI_SIM_STATUS_CARD_ERROR        :
283                         INFO("Sim card status: TAPI_SIM_STATUS_CARD_ERROR");
284                 break;
285
286                 case TAPI_SIM_STATUS_CARD_NOT_PRESENT  :
287                         INFO("Sim card status: TAPI_SIM_STATUS_CARD_NOT_PRESENT");
288                 break;
289
290                 case TAPI_SIM_STATUS_SIM_INITIALIZING  :
291                         INFO("Sim card status: TAPI_SIM_STATUS_SIM_INITIALIZING");
292                 break;
293
294                 case TAPI_SIM_STATUS_SIM_INIT_COMPLETED:
295                         INFO("Sim card status: TAPI_SIM_STATUS_SIM_INIT_COMPLETED");
296                 break;
297
298                 case TAPI_SIM_STATUS_SIM_PIN_REQUIRED  :
299                         INFO("Sim card status: TAPI_SIM_STATUS_SIM_PIN_REQUIRED");
300                 break;
301
302                 case TAPI_SIM_STATUS_SIM_PUK_REQUIRED  :
303                         INFO("Sim card status: TAPI_SIM_STATUS_SIM_PUK_REQUIRED");
304                 break;
305
306                 case TAPI_SIM_STATUS_CARD_BLOCKED      :
307                         INFO("Sim card status: TAPI_SIM_STATUS_CARD_BLOCKED");
308                 break;
309
310                 case TAPI_SIM_STATUS_SIM_NCK_REQUIRED  :
311                         INFO("Sim card status: TAPI_SIM_STATUS_SIM_NCK_REQUIRED");
312                 break;
313
314                 case TAPI_SIM_STATUS_SIM_NSCK_REQUIRED :
315                         INFO("Sim card status: TAPI_SIM_STATUS_SIM_NSCK_REQUIRED");
316                 break;
317
318                 case TAPI_SIM_STATUS_SIM_SPCK_REQUIRED :
319                         INFO("Sim card status: TAPI_SIM_STATUS_SIM_SPCK_REQUIRED");
320                 break;
321
322                 case TAPI_SIM_STATUS_SIM_CCK_REQUIRED  :
323                         INFO("Sim card status: TAPI_SIM_STATUS_SIM_CCK_REQUIRED");
324                 break;
325
326                 case TAPI_SIM_STATUS_CARD_REMOVED      :
327                         INFO("Sim card status: TAPI_SIM_STATUS_CARD_REMOVED");
328                 break;
329
330                 case TAPI_SIM_STATUS_SIM_LOCK_REQUIRED :
331                         INFO("Sim card status: TAPI_SIM_STATUS_SIM_LOCK_REQUIRED");
332                 break;
333
334                 case TAPI_SIM_STATUS_CARD_CRASHED      :
335                         INFO("Sim card status: TAPI_SIM_STATUS_CARD_CRASHED");
336                 break;
337
338                 case TAPI_SIM_STATUS_CARD_POWEROFF     :
339                         INFO("Sim card status: TAPI_SIM_STATUS_CARD_POWEROFF");
340                 break;
341
342                 case TAPI_SIM_STATUS_UNKNOWN           :
343                         INFO("Sim card status: TAPI_SIM_STATUS_UNKNOWN");
344                 break;
345         }
346
347         INFO("Sim_card_changed: %d", card_changed);
348 }
349
350 static void get_sim_status()
351 {
352         int i;
353         int ret;
354         TelSimCardStatus_t sim_status;
355         int card_changed;
356
357         for(i = 0; i < TAPI_HANDLE_MAX + 1; ++i)
358         {
359                 if(sim_state_info.handle[i])
360                 {
361                         ret = tel_get_sim_init_info (sim_state_info.handle[i], &sim_status, &card_changed);
362                         if(ret == 0)
363                         {
364                                 print_sim_status(sim_status, card_changed);
365
366                                 if(sim_status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED ||
367                                         sim_status == TAPI_SIM_STATUS_SIM_PIN_REQUIRED)
368                                 {
369                                         if (i < TAPI_HANDLE_MAX)
370                                         {
371                                                 sim_state_info.sim_card_ready[i] = EINA_TRUE;
372                                         }
373                                 }
374                                 else
375                                 {
376                                         ERR("SIM[%d] is not completed initialization [%d]", i, sim_status);
377                                 }
378                         }
379                         else
380                         {
381                                 ERR("Could not get sim[%d] status[%d]", i, ret);
382                         }
383                 }
384         }
385 }
386
387 static void sim_handler_text_set(Eina_Bool flight_mode)
388 {
389         if (flight_mode)
390         {
391                 // if flight mode, No service
392                 quickpanel_handler_text_set(_("IDS_IDLE_BODY_NO_SERVICE"));
393         }
394         else if (sim_state_info.sim_card_ready[0] && sim_state_info.sim_card_ready[1])
395         {
396                 quickpanel_handler_text_set(NULL);
397         }
398         else if(sim_state_info.sim_card_ready[0])
399         {
400                 char *plmn_spn1 = get_plmn_spn_network(0, sim_state_info.handle[0]);
401                 quickpanel_handler_text_set(plmn_spn1);
402                 if (plmn_spn1)
403                 {
404                         free(plmn_spn1);
405                 }
406         }
407         else if(sim_state_info.sim_card_ready[1])
408         {
409                 char *plmn_spn1 = get_plmn_spn_network(1, sim_state_info.handle[1]);
410                 quickpanel_handler_text_set(plmn_spn1);
411                 if (plmn_spn1)
412                 {
413                         free(plmn_spn1);
414                 }
415         }
416         else
417         {
418                 quickpanel_handler_text_set(_("IDS_IDLE_MBODY_EMERGENCY_CALLS_ONLY"));
419         }
420
421 }
422
423 static void init_view()
424 {
425         struct appdata *ad = NULL;
426
427         ad = quickpanel_get_app_data();
428         if (ad == NULL)
429         {
430                 ERR("invalid data");
431                 return;
432         }
433
434         int flight_mode_state = EINA_FALSE;
435         int ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode_state);
436         if(ret != 0)
437         {
438                 ERR("Could not get 'VCONFKEY_TELEPHONY_FLIGHT_MODE' value");
439         }
440
441         sim_handler_text_set(flight_mode_state);
442 }
443
444 /* Initialize TAPI */
445 static void _init_tel()
446 {
447         char **cp_list = NULL;
448         unsigned int modem_num = 0;
449
450         /* Get CP name list – cp_list */
451         cp_list = tel_get_cp_name_list();
452
453         if(cp_list == NULL)
454         {
455                 ERR("Could not get the cp_name_list");
456                 return;
457         }
458
459         while (cp_list[modem_num])
460         {
461                 /* Initialize TAPI handle */
462                 sim_state_info.handle[modem_num] = tel_init(cp_list[modem_num]);
463
464                 if(cp_list[modem_num])
465                 ERR("sim_state_info.handle[%d] = %s; ptr = %p", modem_num,
466                                 cp_list[modem_num], sim_state_info.handle[modem_num]);
467
468                 /* Move to next CP Name in cp_list */
469                 modem_num++;
470         }
471
472         sim_state_info.handle[modem_num] = NULL;
473
474         /* free cp_list */
475         free(cp_list);
476 }
477
478 /* De-initialize TAPI */
479 static void _deinit_tel()
480 {
481         int i = 0;
482         while (sim_state_info.handle[i])
483         {
484                 /* De-initialize TAPI handle */
485                 tel_deinit(sim_state_info.handle[i]);
486                 sim_state_info.handle[i] = NULL;
487
488                 /* Move to next handle */
489                 i++;
490         }
491 }
492
493 /* Telephony state change callback */
494 void tel_ready_cb(keynode_t *key, void *data)
495 {
496         Eina_Bool status = EINA_FALSE;
497
498         status = vconf_keynode_get_bool(key);
499
500         if (status == TRUE)
501         {       /* Telephony State - READY */
502                 DBG("tel status[%d]", status);
503                 _init_tel();
504                 register_sim_callbacks();
505                 get_sim_status();
506
507                 init_view();
508         }
509         else
510         {   /* Telephony State – NOT READY */
511                 /* De-initialization is optional here (ONLY if required) */
512                 ERR("tel status[%d]", status);
513                 _deinit_tel();
514                 sim_state_info.sim_card_ready[0] = EINA_FALSE;
515                 sim_state_info.sim_card_ready[1] = EINA_FALSE;
516
517                 unregister_sim_callbacks();
518         }
519 }
520
521 static void tel_flight_mode_cb(keynode_t *key, void *data)
522 {
523         Eina_Bool flight_mode_state = EINA_FALSE;
524
525         flight_mode_state = vconf_keynode_get_bool(key);
526         sim_handler_text_set(flight_mode_state);
527 }
528
529 // --------------------------------------------------------------------------------------------
530 static void on_sim_card_status_changed(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
531 {
532         int handle_num = (int)user_data;
533         int *sim_status = data;
534
535         ERR("SIM[%p][%d] status[%d], [%d][%d]", handle, handle_num, *sim_status, sim_state_info.sim_card_ready[0], sim_state_info.sim_card_ready[1]);
536
537         if(*sim_status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED ||
538                 *sim_status == TAPI_SIM_STATUS_SIM_PIN_REQUIRED)
539         {
540                 sim_state_info.sim_card_ready[handle_num] = EINA_TRUE;
541         }
542         else
543         {
544                 sim_state_info.sim_card_ready[handle_num] = EINA_FALSE;
545         }
546
547         init_view();
548 }
549
550 static void on_plmn_spn_changed(TapiHandle *handle, const char *noti_id,
551                 void *data, void *user_data)
552 {
553         if(!handle)
554         {
555                 ERR("handle == NULL");
556                 return;
557         }
558
559         int  flight_mode_state = EINA_FALSE;
560         int ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode_state);
561         if(ret != 0)
562         {
563                 ERR("Could not get the 'VCONFKEY_TELEPHONY_FLIGHT_MODE' value");
564         }
565         sim_handler_text_set(flight_mode_state);
566 }
567
568 static void register_sim_callbacks()
569 {
570         int i;
571         int ret;
572         for(i = 0; i < TAPI_HANDLE_MAX; ++i)
573         {
574                 if(sim_state_info.handle[i])
575                 {
576                         ret = tel_register_noti_event (sim_state_info.handle[i],
577                                         TAPI_NOTI_SIM_STATUS, on_sim_card_status_changed, (void*)i);
578
579                         if (ret != TAPI_API_SUCCESS)
580                         {
581                                 ERR("Failed to register 'on_sim_card_status_changed' callback to handle[%d][%d]", i, ret);
582                         }
583                         else
584                         {
585                                 ERR("SIM card status changed event registered");
586                         }
587
588                         ret = tel_register_noti_event(sim_state_info.handle[i],
589                                         TAPI_PROP_NETWORK_SPN_NAME, on_plmn_spn_changed, (void*)i);
590                         if (ret != TAPI_API_SUCCESS)
591                         {
592                                 ERR("Failed to register 'on_plmn_spn_changed' callback to handle[%d][%d]", i, ret);
593                         }
594
595                         ret = tel_register_noti_event(sim_state_info.handle[i],
596                                         TAPI_PROP_NETWORK_NETWORK_NAME, on_plmn_spn_changed, (void*)i);
597                         if (ret != TAPI_API_SUCCESS)
598                         {
599                                 ERR("Failed to register 'on_plmn_spn_changed' callback to handle: %i", i);
600                         }
601
602                         ret = tel_register_noti_event(sim_state_info.handle[i], TAPI_PROP_NETWORK_SERVICE_TYPE, on_plmn_spn_changed, (void*) i);
603                         if (ret != TAPI_API_SUCCESS)
604                         {
605                                 ERR("Failed to register network service type[%d][%d]", ret, i);
606                         }
607
608                         ret = tel_register_noti_event(sim_state_info.handle[i], TAPI_PROP_NETWORK_NAME_OPTION, on_plmn_spn_changed, (void*) i);
609                         if (ret != TAPI_API_SUCCESS)
610                         {
611                                 ERR("Failed to register network name option[%d][%d]", ret, i);
612                         }
613                 }
614                 else
615                 {
616                         ERR("No handle [%d]", i);
617                 }
618         }
619 }
620
621 static void unregister_sim_callbacks()
622 {
623         int i;
624         int ret;
625         for(i = 0; i < TAPI_HANDLE_MAX; ++i)
626         {
627                 if(sim_state_info.handle[i])
628                 {
629                         ret = tel_deregister_noti_event(sim_state_info.handle[i], TAPI_NOTI_SIM_STATUS);
630                         if (ret != TAPI_API_SUCCESS)
631                         {
632                                 ERR("Failed to dereregister TAPI_NOTI_SIM_STATUS callback from handle: %i", i);
633                         }
634                         else
635                         {
636                                 DBG("SIM status changed event deregistered");
637                         }
638
639                         ret = tel_deregister_noti_event(sim_state_info.handle[i], TAPI_PROP_NETWORK_NETWORK_NAME);
640                         if (ret != TAPI_API_SUCCESS)
641                         {
642                                 ERR("Failed to dereregister TAPI_PROP_NETWORK_PLMN callback from handle: %i", i);
643                         }
644
645                         ret = tel_deregister_noti_event(sim_state_info.handle[i], TAPI_PROP_NETWORK_SPN_NAME);
646                         if (ret != TAPI_API_SUCCESS)
647                         {
648                                 ERR("Failed to dereregister TAPI_PROP_NETWORK_SPN_NAME callback from handle: %i", i);
649                         }
650
651                         ret = tel_deregister_noti_event(sim_state_info.handle[i], TAPI_PROP_NETWORK_SERVICE_TYPE);
652                         if (ret != TAPI_API_SUCCESS)
653                         {
654                                 ERR("Failed to deregister network service type[%d][%d]", ret, i);
655                         }
656
657                         ret = tel_deregister_noti_event(sim_state_info.handle[i], TAPI_PROP_NETWORK_NAME_OPTION);
658                         if (ret != TAPI_API_SUCCESS)
659                         {
660                                 ERR("Failed to deregister network name option[%d][%d]", ret, i);
661                         }
662
663                         if(i == 0)
664                         {
665                                 ret = tel_deregister_noti_event(sim_state_info.handle[i], TAPI_NOTI_CALL_PREFERRED_VOICE_SUBSCRIPTION);
666                                 if (ret != TAPI_API_SUCCESS)
667                                 {
668                                         ERR("Failed to dereregister  callback to handle: %d", i);
669                                 }
670                         }
671                 }
672         }
673 }
674
675
676 void sim_controller_init(Evas_Object *master_layout)
677 {
678         int state = EINA_FALSE;
679         int ret;
680         /* Check if Telephony state - READY */
681         ret = vconf_get_bool(VCONFKEY_TELEPHONY_READY, &state);
682
683         DBG("VCONFKEY_TELEPHONY_READY == %d", state);
684
685         if (ret != -1 && state == TRUE)
686         {       /* Telephony State - READY */
687                 /* Initialize TAPI handles */
688
689                 _init_tel();
690                 register_sim_callbacks();
691                 get_sim_status();
692
693                 init_view();
694         }
695         else
696         {       /* Telephony State – NOT READY, register for change in state */
697                 DBG("Telephony state: [NOT Ready]");
698         }
699
700         /* Register for Telephony state change */
701         ret = vconf_notify_key_changed(VCONFKEY_TELEPHONY_READY, tel_ready_cb, master_layout);
702         if(ret != 0)
703                 ERR("Failed to register VCONFKEY_TELEPHONY_READY key changed callback");
704
705         ret = vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, tel_flight_mode_cb, master_layout);
706         if(ret != 0)
707                 ERR("Failed to register VCONFKEY_TELEPHONY_FLIGHT_MODE key changed callback");
708
709         ret = vconf_notify_key_changed(VCONFKEY_CALL_STATE, __sim_controller_call_state_changed_cb, NULL);
710         if (ret != 0)
711         {
712                 ERR("Failed to notify call state[%d]", ret);
713         }
714 }
715
716 void sim_controller_resume()
717 {
718         int state = FALSE;
719         int ret = 0;
720         int i = 0;
721         TelSimCardStatus_t sim_status;
722         int card_changed;
723
724         ret = vconf_get_bool(VCONFKEY_TELEPHONY_READY, &state);
725         if (ret != 0 || state == FALSE)
726         {
727                 ERR("Failed to get telephony state[%d][%d]", state, ret);
728                 return;
729         }
730
731         for (i = 0; i < TAPI_HANDLE_MAX; ++i)
732         {
733                 if (sim_state_info.handle[i])
734                 {
735                         ret = tel_get_sim_init_info(sim_state_info.handle[i], &sim_status, &card_changed);
736                         DBG("SIM[%d] info[%d][%d][%d]", i, ret, sim_status, card_changed);
737                         if (sim_status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED ||
738                                 sim_status == TAPI_SIM_STATUS_SIM_PIN_REQUIRED)
739                         {
740                                 if (sim_state_info.sim_card_ready[i] != EINA_TRUE)
741                                 {
742                                         ERR("SIM[%d] is init completed but local value is not ture", i);
743                                 }
744                         }
745                 }
746                 else
747                 {
748                         ERR("No handle[%d]", i);
749                 }
750         }
751 }
752
753 void sim_controller_on_language_change()
754 {
755         on_plmn_spn_changed(sim_state_info.handle[0], "SELF", NULL, (void*) 0);
756         on_plmn_spn_changed(sim_state_info.handle[1], "SELF", NULL, (void*) 1);
757
758         if (sim_state_info.handle[0] == NULL && sim_state_info.handle[1] == NULL)
759         {
760                 int flight_mode = EINA_FALSE;
761                 int ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
762                 if (ret != 0)
763                 {
764                         ERR("Failed to get flight mode[%d]", ret);
765                 }
766
767                 sim_handler_text_set(flight_mode);
768         }
769 }