2 * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <Elementary.h>
24 #include <tapi_common.h>
27 #include <ITapiCall.h>
28 #include <TelNetwork.h>
33 #include <tzsh_quickpanel_service.h>
35 #include "setting_utils.h"
37 #include "list_util.h"
38 #include "quickpanel-ui.h"
41 #include "handler_controller.h"
43 #define TAPI_HANDLE_MAX 2
47 TapiHandle *handle[TAPI_HANDLE_MAX+1];
48 Eina_Bool sim_card_ready[2];
52 int call_state; // 0:none, 1:call
59 .sim_card_ready[0] = EINA_FALSE,
60 .sim_card_ready[1] = EINA_FALSE,
65 static void register_sim_callbacks();
66 static void unregister_sim_callbacks();
68 static char *get_sim_plmn(TapiHandle *handle)
71 char *network_name = NULL;
73 /* Reading Network (PLMN) name - ‘string’ type Property */
74 ret = tel_get_property_string(handle,
75 TAPI_PROP_NETWORK_NETWORK_NAME, &network_name);
76 if(ret == TAPI_API_SUCCESS)
78 /* ‘network_name’ contains valid Network name based on Display condition */
83 ERR("Sim = %p PLMN = ERROR[%d]", handle, ret);
84 /* get property failed */
90 static char *get_sim_spn(TapiHandle *handle)
93 char *spn_name = NULL;
96 /* Reading SPN name - ‘string’ type Property */
97 ret = tel_get_property_string(handle,
98 TAPI_PROP_NETWORK_SPN_NAME, &spn_name);
99 if(ret == TAPI_API_SUCCESS)
101 /* ‘spn_name’ contains valid Service provider name */
106 ERR("Sim = %p SPN = ERROR[%d]", handle, ret);
107 /* get property failed */
112 static char *get_plmn_spn_network(int handle_num, TapiHandle *handle)
114 int ret = TAPI_API_SUCCESS;
115 int service_type = TAPI_NETWORK_SERVICE_TYPE_UNKNOWN;
116 int name_option = TAPI_NETWORK_DISP_INVALID;
119 char buf[1024] = { 0, };
122 ret = tel_get_property_int(handle, TAPI_PROP_NETWORK_SERVICE_TYPE, &service_type);
123 if (ret != TAPI_API_SUCCESS) {
124 ERR("Failed to get service type[%d]", ret);
127 if (service_type >= TAPI_NETWORK_SERVICE_TYPE_2G) {
128 // get network name option
129 ret = tel_get_property_int(handle, TAPI_PROP_NETWORK_NAME_OPTION, &name_option);
130 if (ret != TAPI_API_SUCCESS) {
131 ERR("Failed to get name option[%d]", ret);
134 switch (name_option) {
135 case TAPI_NETWORK_DISP_SPN:
136 spn = get_sim_spn(handle);
137 if (spn != NULL && spn[0] != 0) {
138 INFO("PLMN/SPN - Sim %p using SPN: %s", handle, spn);
139 snprintf(buf, sizeof(buf), "%s", spn);
142 case TAPI_NETWORK_DISP_PLMN:
143 plmn = get_sim_plmn(handle);
144 if (plmn != NULL && plmn[0] != 0) {
145 INFO("PLMN/SPN - Sim %p using PLMN: %s", handle, plmn);
146 snprintf(buf, sizeof(buf), "%s", plmn);
149 case TAPI_NETWORK_DISP_SPN_PLMN:
150 spn = get_sim_spn(handle);
151 plmn = get_sim_plmn(handle);
152 if (spn != NULL && spn[0] != 0 && plmn != NULL && plmn[0] != 0) {
153 INFO("PLMN/SPN - Sim %p using SPN: %s, PLMN: %s", handle, spn, plmn);
154 snprintf(buf, sizeof(buf), "%s - %s", plmn, spn);
155 } else if (spn != NULL && spn[0] != 0) {
156 INFO("PLMN/SPN - Sim %p using SPN: %s", handle, spn);
157 snprintf(buf, sizeof(buf), "%s", spn);
158 } else if (plmn != NULL && plmn[0] != 0) {
159 INFO("PLMN/SPN - Sim %p using PLMN: %s", handle, plmn);
160 snprintf(buf, sizeof(buf), "%s", plmn);
164 ERR("Invalid name option[%d]", name_option);
165 plmn = get_sim_plmn(handle);
166 if (plmn != NULL && plmn[0] != 0) {
167 INFO("PLMN/SPN - Sim %p using PLMN: %s", handle, plmn);
168 snprintf(buf, sizeof(buf), "%s", plmn);
173 switch (service_type) {
174 case TAPI_NETWORK_SERVICE_TYPE_NO_SERVICE:
175 snprintf(buf, sizeof(buf), "%s", _("IDS_IDLE_BODY_NO_SERVICE"));
177 case TAPI_NETWORK_SERVICE_TYPE_EMERGENCY:
178 snprintf(buf, sizeof(buf), "%s", _("IDS_IDLE_MBODY_EMERGENCY_CALLS_ONLY"));
180 case TAPI_NETWORK_SERVICE_TYPE_SEARCH:
181 snprintf(buf, sizeof(buf), "%s", _("IDS_COM_BODY_SEARCHING"));
184 ERR("invalid service type[%d]", service_type);
185 plmn = get_sim_plmn(handle);
186 if (plmn != NULL && plmn[0] != 0) {
187 INFO("PLMN/SPN - Sim %p using PLMN: %s", handle, plmn);
188 snprintf(buf, sizeof(buf), "%s", plmn);
194 DBG("handle[%d][%p] service_type[%d], name_option[%d] >> [%s]", handle_num, handle, service_type, name_option, buf);
196 if (strlen(buf) == 0) {
198 snprintf(buf, sizeof(buf), "%s", _("IDS_IDLE_BODY_NO_SERVICE"));
199 } else if (strncasecmp(buf, "No Service", strlen("No Service")) == 0) {
200 ERR("USING SPECIAL NETWORK NAME: %s in handle: %d", _("IDS_IDLE_BODY_NO_SERVICE"), handle_num);
201 return strdup(_("IDS_IDLE_BODY_NO_SERVICE"));
202 } else if (strncasecmp(buf, "EMERGENCY", strlen("EMERGENCY")) == 0) {
203 ERR("USING SPECIAL NETWORK NAME: %s in handle: %d", _("IDS_IDLE_MBODY_EMERGENCY_CALLS_ONLY"), handle_num);
204 return strdup(_("IDS_IDLE_MBODY_EMERGENCY_CALLS_ONLY"));
205 } else if (strncasecmp(buf, "Searching", strlen("Searching")) == 0) {
206 ERR("USING SPECIAL NETWORK NAME: %s in handle: %d", _("IDS_COM_BODY_SEARCHING"), handle_num);
207 return strdup(_("IDS_COM_BODY_SEARCHING"));
208 } else if (strncasecmp(buf, "SIM Error", strlen("SIM Error")) == 0) {
209 ERR("USING SPECIAL NETWORK NAME: %s in handle: %d", _("IDS_IDLE_BODY_INVALID_SIM_CARD"), handle_num);
210 return strdup(_("IDS_IDLE_BODY_INVALID_SIM_CARD"));
211 } else if (strncasecmp(buf, "NO SIM", strlen("NO SIM")) == 0) {
212 ERR("USING SPECIAL NETWORK NAME: %s in handle: %d", _("IDS_IDLE_MBODY_EMERGENCY_CALLS_ONLY"), handle_num);
213 return strdup(_("IDS_IDLE_MBODY_EMERGENCY_CALLS_ONLY"));
219 // --------------------------------------------------------------------------------------------
220 static void print_sim_status(TelSimCardStatus_t sim_status, int card_changed)
223 case TAPI_SIM_STATUS_CARD_ERROR:
224 INFO("Sim card status: TAPI_SIM_STATUS_CARD_ERROR");
227 case TAPI_SIM_STATUS_CARD_NOT_PRESENT:
228 INFO("Sim card status: TAPI_SIM_STATUS_CARD_NOT_PRESENT");
231 case TAPI_SIM_STATUS_SIM_INITIALIZING:
232 INFO("Sim card status: TAPI_SIM_STATUS_SIM_INITIALIZING");
235 case TAPI_SIM_STATUS_SIM_INIT_COMPLETED:
236 INFO("Sim card status: TAPI_SIM_STATUS_SIM_INIT_COMPLETED");
239 case TAPI_SIM_STATUS_SIM_PIN_REQUIRED:
240 INFO("Sim card status: TAPI_SIM_STATUS_SIM_PIN_REQUIRED");
243 case TAPI_SIM_STATUS_SIM_PUK_REQUIRED:
244 INFO("Sim card status: TAPI_SIM_STATUS_SIM_PUK_REQUIRED");
247 case TAPI_SIM_STATUS_CARD_BLOCKED:
248 INFO("Sim card status: TAPI_SIM_STATUS_CARD_BLOCKED");
251 case TAPI_SIM_STATUS_SIM_NCK_REQUIRED:
252 INFO("Sim card status: TAPI_SIM_STATUS_SIM_NCK_REQUIRED");
255 case TAPI_SIM_STATUS_SIM_NSCK_REQUIRED:
256 INFO("Sim card status: TAPI_SIM_STATUS_SIM_NSCK_REQUIRED");
259 case TAPI_SIM_STATUS_SIM_SPCK_REQUIRED:
260 INFO("Sim card status: TAPI_SIM_STATUS_SIM_SPCK_REQUIRED");
263 case TAPI_SIM_STATUS_SIM_CCK_REQUIRED:
264 INFO("Sim card status: TAPI_SIM_STATUS_SIM_CCK_REQUIRED");
267 case TAPI_SIM_STATUS_CARD_REMOVED:
268 INFO("Sim card status: TAPI_SIM_STATUS_CARD_REMOVED");
271 case TAPI_SIM_STATUS_SIM_LOCK_REQUIRED:
272 INFO("Sim card status: TAPI_SIM_STATUS_SIM_LOCK_REQUIRED");
275 case TAPI_SIM_STATUS_CARD_CRASHED:
276 INFO("Sim card status: TAPI_SIM_STATUS_CARD_CRASHED");
279 case TAPI_SIM_STATUS_CARD_POWEROFF:
280 INFO("Sim card status: TAPI_SIM_STATUS_CARD_POWEROFF");
283 case TAPI_SIM_STATUS_UNKNOWN:
284 INFO("Sim card status: TAPI_SIM_STATUS_UNKNOWN");
288 INFO("Sim_card_changed: %d", card_changed);
291 static void get_sim_status()
295 TelSimCardStatus_t sim_status;
298 for (i = 0; i < TAPI_HANDLE_MAX + 1; ++i) {
299 if (sim_state_info.handle[i]) {
300 ret = tel_get_sim_init_info (sim_state_info.handle[i], &sim_status, &card_changed);
302 print_sim_status(sim_status, card_changed);
304 if(sim_status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED || sim_status == TAPI_SIM_STATUS_SIM_PIN_REQUIRED) {
305 if (i < TAPI_HANDLE_MAX) {
306 sim_state_info.sim_card_ready[i] = EINA_TRUE;
309 ERR("SIM[%d] is not completed initialization [%d]", i, sim_status);
312 ERR("Could not get sim[%d] status[%d]", i, ret);
314 } // if sim_state_info
318 static void sim_handler_text_set(Eina_Bool flight_mode)
321 // if flight mode, No service
322 quickpanel_handler_text_set(_("IDS_IDLE_BODY_NO_SERVICE"));
323 } else if (sim_state_info.sim_card_ready[0] && sim_state_info.sim_card_ready[1]) {
324 quickpanel_handler_text_set(NULL);
325 } else if(sim_state_info.sim_card_ready[0]) {
326 char *plmn_spn1 = get_plmn_spn_network(0, sim_state_info.handle[0]);
327 quickpanel_handler_text_set(plmn_spn1);
331 } else if(sim_state_info.sim_card_ready[1]) {
332 char *plmn_spn1 = get_plmn_spn_network(1, sim_state_info.handle[1]);
333 quickpanel_handler_text_set(plmn_spn1);
338 quickpanel_handler_text_set(_("IDS_IDLE_MBODY_EMERGENCY_CALLS_ONLY"));
342 static void init_view()
344 struct appdata *ad = NULL;
346 ad = quickpanel_get_app_data();
352 int flight_mode_state = EINA_FALSE;
353 int ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode_state);
355 ERR("Could not get 'VCONFKEY_TELEPHONY_FLIGHT_MODE' value");
358 sim_handler_text_set(flight_mode_state);
361 /* Initialize TAPI */
362 static void _init_tel()
364 char **cp_list = NULL;
365 unsigned int modem_num = 0;
367 /* Get CP name list – cp_list */
368 cp_list = tel_get_cp_name_list();
370 if(cp_list == NULL) {
371 ERR("Could not get the cp_name_list");
375 while (cp_list[modem_num]) {
376 /* Initialize TAPI handle */
377 sim_state_info.handle[modem_num] = tel_init(cp_list[modem_num]);
379 if (cp_list[modem_num]) {
380 ERR("sim_state_info.handle[%d] = %s; ptr = %p", modem_num, cp_list[modem_num], sim_state_info.handle[modem_num]);
383 /* Move to next CP Name in cp_list */
387 sim_state_info.handle[modem_num] = NULL;
393 /* De-initialize TAPI */
394 static void _deinit_tel()
397 while (sim_state_info.handle[i]) {
398 /* De-initialize TAPI handle */
399 tel_deinit(sim_state_info.handle[i]);
400 sim_state_info.handle[i] = NULL;
402 /* Move to next handle */
407 /* Telephony state change callback */
408 void tel_ready_cb(keynode_t *key, void *data)
410 Eina_Bool status = EINA_FALSE;
412 status = vconf_keynode_get_bool(key);
414 if (status == TRUE) { /* Telephony State - READY */
415 DBG("tel status[%d]", status);
417 register_sim_callbacks();
421 } else { /* Telephony State – NOT READY */
422 /* De-initialization is optional here (ONLY if required) */
423 ERR("tel status[%d]", status);
425 sim_state_info.sim_card_ready[0] = EINA_FALSE;
426 sim_state_info.sim_card_ready[1] = EINA_FALSE;
428 unregister_sim_callbacks();
432 static void tel_flight_mode_cb(keynode_t *key, void *data)
434 Eina_Bool flight_mode_state = EINA_FALSE;
436 flight_mode_state = vconf_keynode_get_bool(key);
437 sim_handler_text_set(flight_mode_state);
440 // --------------------------------------------------------------------------------------------
441 static void on_sim_card_status_changed(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
444 int *sim_status = data;
448 * Casting the pointer to "long" first for 64 bits architecture.
449 * And then convert it to "int"
451 handle_num = (int)((long)user_data);
453 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]);
455 if(*sim_status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED || *sim_status == TAPI_SIM_STATUS_SIM_PIN_REQUIRED) {
456 sim_state_info.sim_card_ready[handle_num] = EINA_TRUE;
458 sim_state_info.sim_card_ready[handle_num] = EINA_FALSE;
464 static void on_plmn_spn_changed(TapiHandle *handle, const char *noti_id,
465 void *data, void *user_data)
468 ERR("handle == NULL");
472 int flight_mode_state = EINA_FALSE;
473 int ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode_state);
475 ERR("Could not get the 'VCONFKEY_TELEPHONY_FLIGHT_MODE' value");
477 sim_handler_text_set(flight_mode_state);
480 static void register_sim_callbacks()
485 for (i = 0; i < TAPI_HANDLE_MAX; ++i) {
486 if (sim_state_info.handle[i]) {
487 ret = tel_register_noti_event(sim_state_info.handle[i], TAPI_NOTI_SIM_STATUS, on_sim_card_status_changed, (void *)i);
488 if (ret != TAPI_API_SUCCESS) {
489 ERR("Failed to register 'on_sim_card_status_changed' callback to handle[%d][%d]", i, ret);
491 ERR("SIM card status changed event registered");
494 ret = tel_register_noti_event(sim_state_info.handle[i], TAPI_PROP_NETWORK_SPN_NAME, on_plmn_spn_changed, (void *)i);
495 if (ret != TAPI_API_SUCCESS) {
496 ERR("Failed to register 'on_plmn_spn_changed' callback to handle[%d][%d]", i, ret);
499 ret = tel_register_noti_event(sim_state_info.handle[i], TAPI_PROP_NETWORK_NETWORK_NAME, on_plmn_spn_changed, (void *)i);
500 if (ret != TAPI_API_SUCCESS) {
501 ERR("Failed to register 'on_plmn_spn_changed' callback to handle: %i", i);
504 ret = tel_register_noti_event(sim_state_info.handle[i], TAPI_PROP_NETWORK_SERVICE_TYPE, on_plmn_spn_changed, (void *)i);
505 if (ret != TAPI_API_SUCCESS) {
506 ERR("Failed to register network service type[%d][%d]", ret, i);
509 ret = tel_register_noti_event(sim_state_info.handle[i], TAPI_PROP_NETWORK_NAME_OPTION, on_plmn_spn_changed, (void *)i);
510 if (ret != TAPI_API_SUCCESS) {
511 ERR("Failed to register network name option[%d][%d]", ret, i);
514 ERR("No handle [%d]", i);
519 static void unregister_sim_callbacks()
523 for(i = 0; i < TAPI_HANDLE_MAX; ++i) {
524 if(sim_state_info.handle[i]) {
525 ret = tel_deregister_noti_event(sim_state_info.handle[i], TAPI_NOTI_SIM_STATUS);
526 if (ret != TAPI_API_SUCCESS) {
527 ERR("Failed to dereregister TAPI_NOTI_SIM_STATUS callback from handle: %i", i);
529 DBG("SIM status changed event deregistered");
532 ret = tel_deregister_noti_event(sim_state_info.handle[i], TAPI_PROP_NETWORK_NETWORK_NAME);
533 if (ret != TAPI_API_SUCCESS) {
534 ERR("Failed to dereregister TAPI_PROP_NETWORK_PLMN callback from handle: %i", i);
537 ret = tel_deregister_noti_event(sim_state_info.handle[i], TAPI_PROP_NETWORK_SPN_NAME);
538 if (ret != TAPI_API_SUCCESS) {
539 ERR("Failed to dereregister TAPI_PROP_NETWORK_SPN_NAME callback from handle: %i", i);
542 ret = tel_deregister_noti_event(sim_state_info.handle[i], TAPI_PROP_NETWORK_SERVICE_TYPE);
543 if (ret != TAPI_API_SUCCESS) {
544 ERR("Failed to deregister network service type[%d][%d]", ret, i);
547 ret = tel_deregister_noti_event(sim_state_info.handle[i], TAPI_PROP_NETWORK_NAME_OPTION);
548 if (ret != TAPI_API_SUCCESS) {
549 ERR("Failed to deregister network name option[%d][%d]", ret, i);
553 ret = tel_deregister_noti_event(sim_state_info.handle[i], TAPI_NOTI_CALL_PREFERRED_VOICE_SUBSCRIPTION);
554 if (ret != TAPI_API_SUCCESS) {
555 ERR("Failed to dereregister callback to handle: %d", i);
562 void sim_controller_init(Evas_Object *master_layout)
564 int state = EINA_FALSE;
566 /* Check if Telephony state - READY */
567 ret = vconf_get_bool(VCONFKEY_TELEPHONY_READY, &state);
569 DBG("VCONFKEY_TELEPHONY_READY == %d", state);
571 if (ret != -1 && state == TRUE) {
572 /* Telephony State - READY */
573 /* Initialize TAPI handles */
576 register_sim_callbacks();
580 } else { /* Telephony State – NOT READY, register for change in state */
581 DBG("Telephony state: [NOT Ready]");
584 /* Register for Telephony state change */
585 ret = vconf_notify_key_changed(VCONFKEY_TELEPHONY_READY, tel_ready_cb, master_layout);
587 ERR("Failed to register VCONFKEY_TELEPHONY_READY key changed callback");
590 ret = vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, tel_flight_mode_cb, master_layout);
592 ERR("Failed to register VCONFKEY_TELEPHONY_FLIGHT_MODE key changed callback");
596 void sim_controller_resume()
601 TelSimCardStatus_t sim_status;
604 ret = vconf_get_bool(VCONFKEY_TELEPHONY_READY, &state);
605 if (ret != 0 || state == FALSE) {
606 ERR("Failed to get telephony state[%d][%d]", state, ret);
610 for (i = 0; i < TAPI_HANDLE_MAX; ++i) {
611 if (sim_state_info.handle[i]) {
612 ret = tel_get_sim_init_info(sim_state_info.handle[i], &sim_status, &card_changed);
613 DBG("SIM[%d] info[%d][%d][%d]", i, ret, sim_status, card_changed);
614 if (sim_status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED || sim_status == TAPI_SIM_STATUS_SIM_PIN_REQUIRED) {
615 if (sim_state_info.sim_card_ready[i] != EINA_TRUE) {
616 ERR("SIM[%d] is init completed but local value is not ture", i);
620 ERR("No handle[%d]", i);
625 void sim_controller_on_language_change()
627 on_plmn_spn_changed(sim_state_info.handle[0], "SELF", NULL, (void*) 0);
628 on_plmn_spn_changed(sim_state_info.handle[1], "SELF", NULL, (void*) 1);
630 if (sim_state_info.handle[0] == NULL && sim_state_info.handle[1] == NULL) {
631 int flight_mode = EINA_FALSE;
632 int ret = vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode);
634 ERR("Failed to get flight mode[%d]", ret);
637 sim_handler_text_set(flight_mode);