2 * Copyright (c) 2011 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.
22 #include <telephony.h>
27 #define LOG_TAG "CAPI_TELEPHONY_TEST"
29 static GMainLoop *event_loop;
31 static int network_noti_tbl[] = {
32 TELEPHONY_NOTI_NETWORK_SERVICE_STATE,
33 TELEPHONY_NOTI_NETWORK_CELLID,
34 TELEPHONY_NOTI_NETWORK_ROAMING_STATUS,
35 TELEPHONY_NOTI_NETWORK_SIGNALSTRENGTH_LEVEL
38 static int call_noti_tbl[] = {
39 TELEPHONY_NOTI_VOICE_CALL_STATE,
40 TELEPHONY_NOTI_VIDEO_CALL_STATE
43 static const char *_mapping_sim_state(telephony_sim_state_e sim_state)
46 case TELEPHONY_SIM_STATE_AVAILABLE:
48 case TELEPHONY_SIM_STATE_LOCKED:
50 case TELEPHONY_SIM_STATE_UNKNOWN:
57 static void sim_noti_cb(telephony_h handle, telephony_noti_e noti_id, void *data, void *user_data)
59 LOGI("Noti!! SIM status: [%d]", *(int *)data);
61 // g_main_loop_quit(event_loop);
65 static const char *_mapping_service_state(telephony_network_service_state_e service_state)
67 switch (service_state) {
68 case TELEPHONY_NETWORK_SERVICE_STATE_IN_SERVICE:
70 case TELEPHONY_NETWORK_SERVICE_STATE_OUT_OF_SERVICE:
71 return "Out of service";
72 case TELEPHONY_NETWORK_SERVICE_STATE_EMERGENCY_ONLY:
73 return "Emergency only";
75 return "Unknown state";
79 static const char *_mapping_network_type(telephony_network_type_e network_type)
81 switch (network_type) {
82 case TELEPHONY_NETWORK_TYPE_GSM:
84 case TELEPHONY_NETWORK_TYPE_GPRS:
86 case TELEPHONY_NETWORK_TYPE_EDGE:
88 case TELEPHONY_NETWORK_TYPE_UMTS:
90 case TELEPHONY_NETWORK_TYPE_HSDPA:
92 case TELEPHONY_NETWORK_TYPE_LTE:
99 static void network_noti_cb(telephony_h handle, telephony_noti_e noti_id, void *data, void *user_data)
102 case TELEPHONY_NOTI_NETWORK_SERVICE_STATE:
103 LOGI("Noti!!! Service state: [%s]", _mapping_service_state(*(int *)data));
105 case TELEPHONY_NOTI_NETWORK_CELLID:
106 LOGI("Noti!!! Cell ID: [%d]", *(int *)data);
108 case TELEPHONY_NOTI_NETWORK_ROAMING_STATUS:
109 LOGI("Noti!!! Roaming status: [%s]", *(int *)data ? "ON" : "OFF");
111 case TELEPHONY_NOTI_NETWORK_SIGNALSTRENGTH_LEVEL:
112 LOGI("Noti!!! Signal strength: [%d]", *(int *)data);
115 LOGE("Unknown noti");
119 // g_main_loop_quit(event_loop);
122 static const char *_mapping_call_state(telephony_call_state_e call_state)
124 switch (call_state) {
125 case TELEPHONY_CALL_STATE_IDLE:
127 case TELEPHONY_CALL_STATE_CONNECTING:
129 case TELEPHONY_CALL_STATE_CONNECTED:
136 static void call_noti_cb(telephony_h handle, telephony_noti_e noti_id, void *data, void *user_data)
139 case TELEPHONY_NOTI_VOICE_CALL_STATE:
140 LOGI("Noti!!! Voice Call state: [%s]", _mapping_call_state(*(int *)data));
142 case TELEPHONY_NOTI_VIDEO_CALL_STATE:
143 LOGI("Noti!!! Video Call state: [%s]", _mapping_call_state(*(int *)data));
146 LOGE("Unknown noti");
150 // g_main_loop_quit(event_loop);
155 telephony_handle_list_s handle_list;
159 char *operator = NULL;
163 telephony_sim_state_e sim_state = 0;
164 char *subscriber_number = NULL;
171 char *network_name = NULL;
173 telephony_network_rssi_e rssi = 0;
174 telephony_network_service_state_e service_state = 0;
175 telephony_network_type_e network_type = 0;
178 telephony_call_state_e call_state = 0;
183 /* Initialize handle */
184 ret_value = telephony_init(&handle_list);
185 if (ret_value != TELEPHONY_ERROR_NONE) {
186 LOGE("Initialize failed!!!");
190 LOGI("handle count: [%d]", handle_list.count);
193 ret_value = telephony_sim_get_operator(handle_list.handle[0], &operator);
194 if (ret_value != TELEPHONY_ERROR_NONE) {
195 LOGE("telephony_sim_get_operator() failed!!! [%d]", ret_value);
197 LOGI("Operator is [%s]", operator);
201 ret_value = telephony_sim_get_icc_id(handle_list.handle[0], &icc_id);
202 if (ret_value != TELEPHONY_ERROR_NONE) {
203 LOGE("telephony_sim_get_icc_id() failed!!! [%d]", ret_value);
205 LOGI("ICC-ID is [%s]", icc_id);
209 ret_value = telephony_sim_get_msin(handle_list.handle[0], &msin);
210 if (ret_value != TELEPHONY_ERROR_NONE) {
211 LOGE("telephony_sim_get_msin() failed!!! [%d]", ret_value);
213 LOGI("MSIN is [%s]", msin);
217 ret_value = telephony_sim_get_spn(handle_list.handle[0], &spn);
218 if (ret_value != TELEPHONY_ERROR_NONE) {
219 LOGE("telephony_sim_get_spn() failed!!! [%d]", ret_value);
221 LOGI("SPN is [%s]", spn);
225 ret_value = telephony_sim_get_state(handle_list.handle[0], &sim_state);
226 if (ret_value != TELEPHONY_ERROR_NONE) {
227 LOGE("telephony_sim_get_state() failed!!! [%d]", ret_value);
229 LOGI("SIM state is [%s]", _mapping_sim_state(sim_state));
232 ret_value = telephony_sim_get_subscriber_number(handle_list.handle[0], &subscriber_number);
233 if (ret_value != TELEPHONY_ERROR_NONE) {
234 LOGE("telephony_sim_get_subscriber_number() failed!!! [%d]", ret_value);
236 LOGI("Subscriber number is [%s]", subscriber_number);
237 free(subscriber_number);
241 ret_value = telephony_network_get_cell_id(handle_list.handle[0], &cell_id);
242 if (ret_value != TELEPHONY_ERROR_NONE) {
243 LOGE("telephony_network_get_cell_id() failed!!! [%d]", ret_value);
245 LOGI("Cell ID is [%d]", cell_id);
248 ret_value = telephony_network_get_lac(handle_list.handle[0], &lac);
249 if (ret_value != TELEPHONY_ERROR_NONE) {
250 LOGE("telephony_network_get_lac() failed!!! [%d]", ret_value);
252 LOGI("Location Area Code is [%d]", lac);
255 ret_value = telephony_network_get_mcc(handle_list.handle[0], &mcc);
256 if (ret_value != TELEPHONY_ERROR_NONE) {
257 LOGE("telephony_network_get_mcc() failed!!! [%d]", ret_value);
259 LOGI("Mobile Country Code is [%s]", mcc);
263 ret_value = telephony_network_get_mnc(handle_list.handle[0], &mnc);
264 if (ret_value != TELEPHONY_ERROR_NONE) {
265 LOGE("telephony_network_get_mnc() failed!!! [%d]", ret_value);
267 LOGI("Mobile Network Code is [%s]", mnc);
271 ret_value = telephony_network_get_network_name(handle_list.handle[0], &network_name);
272 if (ret_value != TELEPHONY_ERROR_NONE) {
273 LOGE("telephony_network_get_network_name() failed!!! [%d]", ret_value);
275 LOGI("Network name is [%s]", network_name);
279 ret_value = telephony_network_get_roaming_status(handle_list.handle[0], &roaming_status);
280 if (ret_value != TELEPHONY_ERROR_NONE) {
281 LOGE("telephony_network_get_roaming_status() failed!!! [%d]", ret_value);
283 LOGI("Network Roaming: [%s]", roaming_status ? "ON" : "OFF");
286 ret_value = telephony_network_get_rssi(handle_list.handle[0], &rssi);
287 if (ret_value != TELEPHONY_ERROR_NONE) {
288 LOGE("telephony_network_get_rssi() failed!!! [%d]", ret_value);
290 LOGI("Received Signal Strength Indicator is [%d]", rssi);
293 ret_value = telephony_network_get_service_state(handle_list.handle[0], &service_state);
294 if (ret_value != TELEPHONY_ERROR_NONE) {
295 LOGE("telephony_network_get_service_state() failed!!! [%d]", ret_value);
297 LOGI("Network service state is [%s]", _mapping_service_state(service_state));
300 ret_value = telephony_network_get_type(handle_list.handle[0], &network_type);
301 if (ret_value != TELEPHONY_ERROR_NONE) {
302 LOGE("telephony_network_get_type() failed!!! [%d]", ret_value);
304 LOGI("Network type is [%s]", _mapping_network_type(network_type));
308 ret_value = telephony_call_get_voice_call_state(handle_list.handle[0], &call_state);
309 if (ret_value != TELEPHONY_ERROR_NONE) {
310 LOGE("telephony_call_get_voice_call_state() failed!!! [%d]", ret_value);
312 LOGI("Voice Call state is [%s]", _mapping_call_state(call_state));
315 ret_value = telephony_call_get_video_call_state(handle_list.handle[0], &call_state);
316 if (ret_value != TELEPHONY_ERROR_NONE) {
317 LOGE("telephony_call_get_video_call_state() failed!!! [%d]", ret_value);
319 LOGI("Video Call state is [%s]", _mapping_call_state(call_state));
323 ret_value = telephony_modem_get_imei(handle_list.handle[0], &imei);
324 if (ret_value != TELEPHONY_ERROR_NONE) {
325 LOGE("telephony_modem_get_imei() failed!!! [%d]", ret_value);
327 LOGI("IMEI is [%s]", imei);
332 ret_value = telephony_set_noti_cb(handle_list.handle[0], TELEPHONY_NOTI_SIM_STATUS, sim_noti_cb, NULL);
333 if (ret_value != TELEPHONY_ERROR_NONE)
334 LOGE("Set noti failed!!!");
336 for (i = 0; i < 4; i++) {
337 ret_value = telephony_set_noti_cb(handle_list.handle[0], network_noti_tbl[i], network_noti_cb, NULL);
338 if (ret_value != TELEPHONY_ERROR_NONE)
339 LOGE("Set noti failed!!!");
342 for (i = 0; i < 2; i++) {
343 ret_value = telephony_set_noti_cb(handle_list.handle[0], call_noti_tbl[i], call_noti_cb, NULL);
344 if (ret_value != TELEPHONY_ERROR_NONE)
345 LOGE("Set noti failed!!!");
348 LOGI("If telephony status is changed, then callback function will be called");
349 event_loop = g_main_loop_new(NULL, FALSE);
350 g_main_loop_run(event_loop);
352 ret_value = telephony_unset_noti_cb(handle_list.handle[0], TELEPHONY_NOTI_SIM_STATUS);
353 if (ret_value != TELEPHONY_ERROR_NONE)
354 LOGE("Unset noti failed!!!");
356 for (i = 0; i < 4; i++) {
357 ret_value = telephony_unset_noti_cb(handle_list.handle[0], network_noti_tbl[i]);
358 if (ret_value != TELEPHONY_ERROR_NONE)
359 LOGE("Unset noti failed!!!");
362 for (i = 0; i < 2; i++) {
363 ret_value = telephony_unset_noti_cb(handle_list.handle[0], call_noti_tbl[i]);
364 if (ret_value != TELEPHONY_ERROR_NONE)
365 LOGE("Unset noti failed!!!");
368 ret_value = telephony_deinit(&handle_list);
369 if (ret_value != TELEPHONY_ERROR_NONE) {
370 LOGE("Deinitialize failed!!!");