From 929bdcae7276320fb037fd9f7fafda73038bd825 Mon Sep 17 00:00:00 2001 From: "jk7744.park" Date: Tue, 8 Sep 2015 22:12:07 +0900 Subject: [PATCH 2/3] tizen 2.3.1 release --- CMakeLists.txt | 139 ++++++++++++++ LICENSE | 204 ++++++++++++++++++++ capi-telephony.manifest | 5 + capi-telephony.pc.in | 14 ++ doc/telephony_doc.h | 137 ++++++++++++++ include/telephony.h | 31 +++ include/telephony_call.h | 109 +++++++++++ include/telephony_common.h | 195 +++++++++++++++++++ include/telephony_modem.h | 69 +++++++ include/telephony_network.h | 324 +++++++++++++++++++++++++++++++ include/telephony_private.h | 61 ++++++ include/telephony_sim.h | 252 ++++++++++++++++++++++++ packaging/capi-telephony.spec | 59 ++++++ src/telephony_call.c | 135 +++++++++++++ src/telephony_common.c | 432 ++++++++++++++++++++++++++++++++++++++++++ src/telephony_modem.c | 78 ++++++++ src/telephony_network.c | 346 +++++++++++++++++++++++++++++++++ src/telephony_sim.c | 399 ++++++++++++++++++++++++++++++++++++++ test/CMakeLists.txt | 20 ++ test/test_all_api.c | 374 ++++++++++++++++++++++++++++++++++++ 20 files changed, 3383 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 LICENSE create mode 100644 capi-telephony.manifest create mode 100644 capi-telephony.pc.in create mode 100644 doc/telephony_doc.h create mode 100644 include/telephony.h create mode 100644 include/telephony_call.h create mode 100644 include/telephony_common.h create mode 100644 include/telephony_modem.h create mode 100644 include/telephony_network.h create mode 100644 include/telephony_private.h create mode 100644 include/telephony_sim.h create mode 100644 packaging/capi-telephony.spec create mode 100644 src/telephony_call.c create mode 100644 src/telephony_common.c create mode 100644 src/telephony_modem.c create mode 100644 src/telephony_network.c create mode 100644 src/telephony_sim.c create mode 100644 test/CMakeLists.txt create mode 100644 test/test_all_api.c diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c3bbf1e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,139 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +SET(project_prefix "capi") +SET(prefix "/usr") +SET(version "0.0.1") +SET(maintainer "Wootak Jung") +SET(description "Telephony Core API") +SET(service "telephony") +SET(dependents "dlog tapi glib-2.0 capi-base-common capi-system-info") +SET(pc_dependents "capi-base-common tapi") + +SET(Services + "application" + "base" + "content" + "location" + "media" + "messaging" + "network" + "social" + "telephony" + "system" + ) + +#FILE(STRINGS config.cfg configs REGEX "^ *[^#]") +FOREACH(lines ${configs}) +# MESSAGE(${lines}) + IF(${lines} MATCHES "([^=]*)=['\"](.*)['\"]") + SET(key ${CMAKE_MATCH_1}) + SET(value ${CMAKE_MATCH_2}) +# MESSAGE("${key} -> ${value}") + SET(${key} "${value}") + ENDIF() +ENDFOREACH(lines ${configs}) + +LIST(FIND Services ${service} sfind) + +IF( ${sfind} EQUAL -1 ) + MESSAGE(FATAL_ERROR "Service must be one of ") + FOREACH( s IN ${Services} ) + MESSAGE(FATAL_ERROR "[${s}]") + ENDFOREACH( s IN ${Services} ) +ENDIF( ${sfind} EQUAL -1 ) + +SET(fw_name "${project_prefix}-${service}") + +PROJECT(${fw_name}) + +SET(CMAKE_INSTALL_PREFIX ${prefix}) +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(VERSION ${version}) + +SET(INC_DIR include) +INCLUDE_DIRECTORIES(${INC_DIR}) + +INCLUDE(FindPkgConfig) +pkg_check_modules(${fw_name} REQUIRED ${dependents}) +FOREACH(flag ${${fw_name}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(ADDITIONAL_CFLAGS "-Wdeclaration-after-statement -Wmissing-declarations -Wredundant-decls -Wcast-align -Wno-array-bounds -Wno-empty-body -Wno-ignored-qualifiers -Wshadow -Wwrite-strings -Wswitch-default -Wno-unused-but-set-parameter -Wno-unused-but-set-variable -Wcast-qual") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ADDITIONAL_CFLAGS}") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") + +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET") +ENDIF("${ARCH}" STREQUAL "arm") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DTIZEN_DEBUG") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib") + +aux_source_directory(src SOURCES) +ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) + +TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS}) + +SET_TARGET_PROPERTIES(${fw_name} + PROPERTIES + VERSION ${FULLVER} + SOVERSION ${MAJORVER} + CLEAN_DIRECT_OUTPUT 1 +) + +INSTALL(TARGETS ${fw_name} DESTINATION lib) +INSTALL( + DIRECTORY ${INC_DIR}/ DESTINATION include/${service} + FILES_MATCHING + PATTERN "*_private.h" EXCLUDE + PATTERN "${INC_DIR}/*.h" + ) + +SET(PC_NAME ${fw_name}) +SET(PC_REQUIRED ${pc_dependents}) +SET(PC_LDFLAGS -l${fw_name}) + +CONFIGURE_FILE( + capi-telephony.pc.in + ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc + @ONLY +) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION /usr/share/license RENAME capi-telephony) + +ADD_SUBDIRECTORY(test) + +IF(UNIX) + +ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution) +ADD_CUSTOM_COMMAND( + DEPENDS clean + COMMENT "distribution clean" + COMMAND find + ARGS . + -not -name config.cmake -and \( + -name tester.c -or + -name Testing -or + -name CMakeFiles -or + -name cmake.depends -or + -name cmake.check_depends -or + -name CMakeCache.txt -or + -name cmake.check_cache -or + -name *.cmake -or + -name Makefile -or + -name core -or + -name core.* -or + -name gmon.out -or + -name install_manifest.txt -or + -name *.pc -or + -name *~ \) + | grep -v TC | xargs rm -rf + TARGET distclean + VERBATIM +) + +ENDIF(UNIX) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a06208b --- /dev/null +++ b/LICENSE @@ -0,0 +1,204 @@ +Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/capi-telephony.manifest b/capi-telephony.manifest new file mode 100644 index 0000000..dfdc35c --- /dev/null +++ b/capi-telephony.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/capi-telephony.pc.in b/capi-telephony.pc.in new file mode 100644 index 0000000..397716c --- /dev/null +++ b/capi-telephony.pc.in @@ -0,0 +1,14 @@ + +# Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=/usr +libdir=/usr/lib +includedir=/usr/include/telephony + +Name: @PC_NAME@ +Description: @PACKAGE_DESCRIPTION@ +Version: @VERSION@ +Requires: @PC_REQUIRED@ +Libs: -L${libdir} @PC_LDFLAGS@ +Cflags: -I${includedir} diff --git a/doc/telephony_doc.h b/doc/telephony_doc.h new file mode 100644 index 0000000..10fc50c --- /dev/null +++ b/doc/telephony_doc.h @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __TIZEN_TELEPHONY_INFORMATION_DOC_H__ +#define __TIZEN_TELEPHONY_INFORMATION_DOC_H__ + +/** + * @ingroup CAPI_TELEPHONY_FRAMEWORK + * @defgroup CAPI_TELEPHONY_INFORMATION Telephony Information + * @brief The Telephony provides call, modem, network, and SIM information. + * + * @section CAPI_TELEPHONY_INFORMATION_HEADER Required Header + * \#include + * + * @section CAPI_TELEPHONY_INFORMATION_OVERVIEW Overview + * The Telephony provides call, modem, network, and SIM information. + * @section CAPI_TELEPHONY_INFORMATION_FEATURE Related Features + * This API is related with the following feature:\n + * - http://tizen.org/feature/network.telephony + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature List. + */ + +/** + * @ingroup CAPI_TELEPHONY_INFORMATION + * @defgroup CAPI_TELEPHONY_INFORMATION_CALL Call + * @brief The Call API provides functions to check the state of voice and video calls. + * + * @section CAPI_TELEPHONY_INFORMATION_CALL_HEADER Required Header + * \#include + * + * @section CAPI_TELEPHONY_INFORMATION_CALL_OVERVIEW Overview + * The Telephony Call API allows you to get the voice and videos call states. + * You can use this information about call related actions. + * @section CAPI_TELEPHONY_INFORMATION_CALL_FEATURE Related Features + * This API is related with the following feature:\n + * - http://tizen.org/feature/network.telephony + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature List. + */ + +/** + * @ingroup CAPI_TELEPHONY_INFORMATION + * @defgroup CAPI_TELEPHONY_INFORMATION_NETWORK Network + * @brief The Network Information API provides functions to obtain information about the current telephony service network. + * + * @section CAPI_TELEPHONY_INFORMATION_NETWORK_HEADER Required Header + * \#include + * + * @section CAPI_TELEPHONY_INFORMATION_NETWORK_OVERVIEW Overview + * The Telephony Network Information API allows you to access, but not change the + * information about the current cellular network and telephony service. + * @section CAPI_TELEPHONY_INFORMATION_NETWORK_FEATURE Related Features + * This API is related with the following feature:\n + * - http://tizen.org/feature/network.telephony + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature List. + */ + +/** + * @ingroup CAPI_TELEPHONY_INFORMATION + * @defgroup CAPI_TELEPHONY_INFORMATION_SIM SIM + * @brief The SIM API provides functions to obtain information from the SIM card, as well as SIM status. + * + * @section CAPI_TELEPHONY_INFORMATION_SIM_HEADER Required Header + * \#include + * + * @section CAPI_TELEPHONY_INFORMATION_SIM_OVERVIEW Overview + * The Telephony SIM API allows you to extract information stored on a SIM card, but not change the information. + * @section CAPI_TELEPHONY_INFORMATION_SIM_FEATURE Related Features + * This API is related with the following feature:\n + * - http://tizen.org/feature/network.telephony + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature List. + */ + +/** + * @ingroup CAPI_TELEPHONY_INFORMATION + * @defgroup CAPI_TELEPHONY_INFORMATION_MODEM Modem + * @brief The Modem Information API provides functions to obtain information from the modem. + * + * @section CAPI_TELEPHONY_INFORMATION_MODEM_HEADER Required Header + * \#include + * + * @section CAPI_TELEPHONY_INFORMATION_MODEM_OVERVIEW Overview + * The Telephony Modem Information API allows you to access, but not change the information about IMEI. + * @section CAPI_TELEPHONY_INFORMATION_MODEM_FEATURE Related Features + * This API is related with the following feature:\n + * - http://tizen.org/feature/network.telephony + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature List. + */ + +#endif /* __TIZEN_TELEPHONY_INFORMATION_DOC_H__ */ diff --git a/include/telephony.h b/include/telephony.h new file mode 100644 index 0000000..69a54e7 --- /dev/null +++ b/include/telephony.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __CAPI_TELEPHONY_H__ +#define __CAPI_TELEPHONY_H__ + +#include "telephony_common.h" +#include "telephony_call.h" +#include "telephony_sim.h" +#include "telephony_network.h" +#include "telephony_modem.h" + +/** + * @file telephony.h + * @brief This file contains telephony related headers. + */ + +#endif /* __CAPI_TELEPHONY_H__ */ diff --git a/include/telephony_call.h b/include/telephony_call.h new file mode 100644 index 0000000..a15de1b --- /dev/null +++ b/include/telephony_call.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __CAPI_TELEPHONY_CALL_H__ +#define __CAPI_TELEPHONY_CALL_H__ + +/** + * @file telephony_call.h + * @brief This file contains call APIs and related enumeration. + */ + +#include "telephony_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup CAPI_TELEPHONY_INFORMATION_CALL + * @{ + */ + +/** + * @brief Enumeration for the call state. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + */ +typedef enum +{ + TELEPHONY_CALL_STATE_IDLE, /**< There exists no calls. */ + TELEPHONY_CALL_STATE_CONNECTING, /**< There exists at least one call that is dialing, alerting or incoming */ + TELEPHONY_CALL_STATE_CONNECTED, /**< There exist active or held calls, and no calls are dialing, alerting or incoming*/ +} telephony_call_state_e; + +/** + * @brief Gets the voice call state of the telephony service. + * @details Determines if the voice call is connecting, connected, or idle. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @remarks When you are dialing a number or a new voice call is ringing, + * the state of the voice call is #TELEPHONY_CALL_STATE_CONNECTING. + * When a new voice call is connecting while another voice call is already connected, + * the state of the voice call is #TELEPHONY_CALL_STATE_CONNECTING as well. + * + * @param[in] handle The handle from telephony_init() + * @param[out] call_state The current state of the voice call + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + */ +int telephony_call_get_voice_call_state(telephony_h handle, telephony_call_state_e *call_state); + +/** + * @brief Gets the video call state of the telephony service. + * @details Determines if the video call is connecting, connected, or idle. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @remarks When you are dialing a number or a new video call is ringing, + * the state of the video call is #TELEPHONY_CALL_STATE_CONNECTING. + * If a video call is connected, then the state of any other call cannot be + * #TELEPHONY_CALL_STATE_CONNECTING and #TELEPHONY_CALL_STATE_CONNECTED. + * + * @param[in] handle The handle from telephony_init() + * @param[out] call_state The current state of the video call + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + */ +int telephony_call_get_video_call_state(telephony_h handle, telephony_call_state_e *call_state); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif // __CAPI_TELEPHONY_CALL_H__ diff --git a/include/telephony_common.h b/include/telephony_common.h new file mode 100644 index 0000000..42f2e40 --- /dev/null +++ b/include/telephony_common.h @@ -0,0 +1,195 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __CAPI_TELEPHONY_COMMON_H__ +#define __CAPI_TELEPHONY_COMMON_H__ + +/** + * @file telephony_common.h + * @brief This file contains telephony common APIs and related enumerations. + */ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file telephony_common.h + * @brief This file contains the common information APIs. + */ + +/** + * @addtogroup CAPI_TELEPHONY_INFORMATION + * @{ + */ + +/** + * @brief The Telephony API handle. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + */ +typedef struct telephony_data *telephony_h; + +/** + * @brief The structure type for the list of handles to use the Telephony API. + * @remarks There are two handles in case of dual SIM device. \n + * In this case, handle[0] is mean Primary SIM and handle[1] is mean Secondary SIM. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + */ +typedef struct { + unsigned int count; /**< Number of available handle */ + telephony_h *handle; /**< Handle to use Telephony API */ +} telephony_handle_list_s; + +/** + * @brief Enumeration for Telephony error. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + */ +typedef enum { + TELEPHONY_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + TELEPHONY_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + TELEPHONY_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + TELEPHONY_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ + TELEPHONY_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */ + TELEPHONY_ERROR_OPERATION_FAILED = TIZEN_ERROR_TELEPHONY | 0x0001, /**< Operation failed */ + TELEPHONY_ERROR_SIM_NOT_AVAILABLE = TIZEN_ERROR_TELEPHONY | 0x1001, /**< SIM is not available */ +} telephony_error_e; + +/** + * @brief Enumeration for Telephony notification. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + */ +typedef enum { + TELEPHONY_NOTI_SIM_STATUS = 0x10, /**< Notification to be invoked when the SIM card state changes */ + + TELEPHONY_NOTI_NETWORK_SERVICE_STATE = 0x20, /**< Notification to be invoked when the network service state changes */ + TELEPHONY_NOTI_NETWORK_CELLID, /**< Notification to be invoked when the cell ID changes */ + TELEPHONY_NOTI_NETWORK_ROAMING_STATUS, /**< Notification to be invoked when the roaming status changes */ + TELEPHONY_NOTI_NETWORK_SIGNALSTRENGTH_LEVEL, /**< Notification to be invoked when the signal strength changes */ + + TELEPHONY_NOTI_VOICE_CALL_STATE = 0x30, /**< Notification to be invoked when the voice call state changes */ + TELEPHONY_NOTI_VIDEO_CALL_STATE /**< Notification to be invoked when the video call state changes */ +} telephony_noti_e; + +/** + * @brief Called when the telephony state changes. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + */ +typedef void (*telephony_noti_cb)(telephony_h handle, telephony_noti_e noti_id, void *data, void *user_data); + +/** + * @brief Sets a callback function to be invoked when the telephony state changes. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @param[in] handle The handle to use the telephony API + * @param[in] noti_id The notification ID to set the callback + * @param[in] cb The callback to be invoked when the telephony state changes + * @param[in] user_data The user data passed to the callback function + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + * + * @post telephony_noti_cb() will be invoked. + * + * @see telephony_unset_noti_cb() + */ +int telephony_set_noti_cb(telephony_h handle, + telephony_noti_e noti_id, telephony_noti_cb cb, void *user_data); + +/** + * @brief Unsets a callback function. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @param[in] handle The handle to use the telephony API + * @param[in] noti_id The notification ID to unset a callback + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + * + * @see telephony_set_noti_cb() + */ +int telephony_unset_noti_cb(telephony_h handle, telephony_noti_e noti_id); + +/** + * @brief Acquires the list of available handles to use the telephony API. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * + * @remarks You will get two handles in case of dual SIM device. \n + * In this case, handle[0] is mean Primary SIM and handle[1] is mean Secondary SIM. + * + * @param[out] list The list contains the number of + * available handles and array of handles + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + * + * @see telephony_deinit() + */ +int telephony_init(telephony_handle_list_s *list); + +/** + * @brief Deinitializes the telephony handle list. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * + * @param[in] list The handle list to be deinitialized + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + * + * @see telephony_init() + */ +int telephony_deinit(telephony_handle_list_s *list); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __CAPI_TELEPHONY_COMMON_H__ */ diff --git a/include/telephony_modem.h b/include/telephony_modem.h new file mode 100644 index 0000000..c0444dd --- /dev/null +++ b/include/telephony_modem.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __CAPI_TELEPHONY_MODEM_H__ +#define __CAPI_TELEPHONY_MODEM_H__ + +/** + * @file telephony_modem.h + * @brief This file contains modem APIs. + */ + +#include "telephony_common.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup CAPI_TELEPHONY_INFORMATION_MODEM + * @{ + */ + +/** + * @brief Gets the IMEI (International Mobile Station Equipment Identity) of a mobile phone. + * @details The IMEI number is used by a GSM network to identify valid devices + * and therefore can be used for stopping a stolen phone from accessing that network. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @remarks You must release @c imei using free(). + * + * @param[in] handle The handle from telephony_init() + * @param[out] imei The International Mobile Station Equipment Identity + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + */ +int telephony_modem_get_imei(telephony_h handle, char **imei); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif // __CAPI_TELEPHONY_MODEM_H__ diff --git a/include/telephony_network.h b/include/telephony_network.h new file mode 100644 index 0000000..1d259f9 --- /dev/null +++ b/include/telephony_network.h @@ -0,0 +1,324 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __CAPI_TELEPHONY_NETWORK_INFO_H__ +#define __CAPI_TELEPHONY_NETWORK_INFO_H__ + +#include "telephony_common.h" + +#ifdef __cplusplus +extern "C" +{ +#endif + +/** + * @file telephony_network.h + * @brief This file contains the network APIs and related enumerations. + */ + +/** + * @addtogroup CAPI_TELEPHONY_INFORMATION_NETWORK + * @{ + */ + +/** + * @brief Enumeration for RSSI (Receive Signal Strength Indicator). + * @details #TELEPHONY_NETWORK_RSSI_6 indicates the highest strength. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + */ +typedef enum +{ + TELEPHONY_NETWORK_RSSI_0, /**< Strength 0 */ + TELEPHONY_NETWORK_RSSI_1, /**< Strength 1 */ + TELEPHONY_NETWORK_RSSI_2, /**< Strength 2 */ + TELEPHONY_NETWORK_RSSI_3, /**< Strength 3 */ + TELEPHONY_NETWORK_RSSI_4, /**< Strength 4 */ + TELEPHONY_NETWORK_RSSI_5, /**< Strength 5 */ + TELEPHONY_NETWORK_RSSI_6, /**< Strength 6 */ +} telephony_network_rssi_e; + + +/** + * @brief Enumeration for Network Type. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + */ +typedef enum +{ + TELEPHONY_NETWORK_TYPE_UNKNOWN, /**< Unknown */ + TELEPHONY_NETWORK_TYPE_GSM, /**< 2G GSM network type */ + TELEPHONY_NETWORK_TYPE_GPRS, /**< 2.5G GPRS network type */ + TELEPHONY_NETWORK_TYPE_EDGE, /**< 2.5G EDGE network type */ + TELEPHONY_NETWORK_TYPE_UMTS, /**< 3G UMTS network type */ + TELEPHONY_NETWORK_TYPE_HSDPA, /**< HSDPA network type */ + TELEPHONY_NETWORK_TYPE_LTE, /**< LTE network type */ +} telephony_network_type_e; + + +/** + * @brief Enumeration for Network Service State. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + */ +typedef enum +{ + TELEPHONY_NETWORK_SERVICE_STATE_IN_SERVICE, /**< In service */ + TELEPHONY_NETWORK_SERVICE_STATE_OUT_OF_SERVICE, /**< Out of service */ + TELEPHONY_NETWORK_SERVICE_STATE_EMERGENCY_ONLY, /**< Only emergency call is allowed */ +} telephony_network_service_state_e; + +/** + * @brief Gets the LAC (Location Area Code) of the current network. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @param[in] handle The handle from telephony_init() + * @param[out] lac The Location Area Code + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + * + * @pre The Network service state must be #TELEPHONY_NETWORK_SERVICE_STATE_IN_SERVICE. + * + * @see telephony_network_get_service_state() + */ +int telephony_network_get_lac(telephony_h handle, int *lac); + +/** + * @brief Gets the cell ID. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @param[in] handle The handle from telephony_init() + * @param[out] cell_id The cell identification number + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + * + * @pre The Network service state must be #TELEPHONY_NETWORK_SERVICE_STATE_IN_SERVICE. + * + * @see telephony_network_get_service_state() + */ +int telephony_network_get_cell_id(telephony_h handle, int *cell_id); + +/** + * @brief Gets the RSSI (Received Signal Strength Indicator). + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @param[in] handle The handle from telephony_init() + * @param[out] rssi The Received Signal Strength Indicator \n + * Higher the received number, the stronger the signal strength. + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + * + * @pre The Network service state must be #TELEPHONY_NETWORK_SERVICE_STATE_IN_SERVICE. + * + * @see telephony_network_get_service_state() + */ +int telephony_network_get_rssi(telephony_h handle, telephony_network_rssi_e *rssi); + +/** + * @brief Gets the roaming state. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @param[in] handle The handle from telephony_init() + * @param[out] status @c true if roaming, + * otherwise @c false if not roaming + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + * + * @pre The Network service state must be #TELEPHONY_NETWORK_SERVICE_STATE_IN_SERVICE. + * + * @see telephony_network_get_service_state() + */ +int telephony_network_get_roaming_status(telephony_h handle, bool *status); + +/** + * @brief Gets the MCC (Mobile Country Code) of the current registered network. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @remarks You must release @c mcc using free(). + * + * @param[in] handle The handle from telephony_init() + * @param[out] mcc The Mobile Country Code (three digits) + * Mobile Country Code (MCC) identifies the country where the cell is being used. + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + * + * @pre The Network service state must be #TELEPHONY_NETWORK_SERVICE_STATE_IN_SERVICE. + * + * @see telephony_network_get_service_state() + */ +int telephony_network_get_mcc(telephony_h handle, char **mcc); + +/** + * @brief Gets the MNC (Mobile Network Code) of the current registered network. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @remarks You must release @c mnc using free(). + * + * @param[in] handle The handle from telephony_init() + * @param[out] mnc The Mobile Network Code (three digits) + * The Mobile Network Code (MNC) identifies the mobile phone operator and network provider. + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + * + * @pre The Network service state must be #TELEPHONY_NETWORK_SERVICE_STATE_IN_SERVICE. + * + * @see telephony_network_get_service_state() + */ +int telephony_network_get_mnc(telephony_h handle, char **mnc); + +/** + * @brief Gets the name of the current registered network. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @remarks You must release @c network_name using free(). + * + * @param[in] handle The handle from telephony_init() + * @param[out] network_name The name of the current registered network + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + * + * @pre The Network service state must be #TELEPHONY_NETWORK_SERVICE_STATE_IN_SERVICE. + * + * @see telephony_network_get_service_state() + */ +int telephony_network_get_network_name(telephony_h handle, char **network_name); + +/** + * @brief Gets the network service type of the current registered network. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @param[in] handle The handle from telephony_init() + * @param[out] network_type The network service type + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + * + * @pre The Network service state must be #TELEPHONY_NETWORK_SERVICE_STATE_IN_SERVICE. + * + * @see telephony_network_get_service_state() + */ +int telephony_network_get_type(telephony_h handle, + telephony_network_type_e *network_type); + +/** + * @brief Gets the current network state of the telephony service. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @remarks To know the state of data network, refer connection API. + * + * @param[in] handle The handle from telephony_init() + * @param[out] network_service_state The current network state + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + */ +int telephony_network_get_service_state(telephony_h handle, + telephony_network_service_state_e *network_service_state); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif // __CAPI_TELEPHONY_NETWORK_INFO_H__ diff --git a/include/telephony_private.h b/include/telephony_private.h new file mode 100644 index 0000000..9ff0c7c --- /dev/null +++ b/include/telephony_private.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __CAPI_TELEPHONY_PRIVATE_H__ +#define __CAPI_TELEPHONY_PRIVATE_H__ + +#include +#include +#include +#include "telephony_common.h" + +#define TELEPHONY_FEATURE "http://tizen.org/feature/network.telephony" + +#define CHECK_TELEPHONY_SUPPORTED(feature_name) { \ + bool telephony_supported = FALSE; \ + if (!system_info_get_platform_bool(feature_name, &telephony_supported)) { \ + if (telephony_supported == FALSE) { \ + LOGE("telephony feature is disabled"); \ + return TELEPHONY_ERROR_NOT_SUPPORTED; \ + } \ + } else { \ + LOGE("Error - Feature getting from System Info"); \ + return TELEPHONY_ERROR_OPERATION_FAILED; \ + } \ +} + +typedef struct { + GSList *evt_list; + struct tapi_handle *tapi_h; +} telephony_data; + +/* + * Need to define the struct same as tapi_handle of libslp-tapi + * because we are request dbus directly using dbus_connection, path + */ +struct tapi_handle { + gpointer dbus_connection; + char *path; + char *cp_name; + GHashTable *evt_list; + char cookie[20]; + GCancellable *ca; + + GHashTable *cache_property; + guint prop_callback_evt_id; +}; + +#endif /* __CAPI_TELEPHONY_PRIVATE_H__ */ diff --git a/include/telephony_sim.h b/include/telephony_sim.h new file mode 100644 index 0000000..d355392 --- /dev/null +++ b/include/telephony_sim.h @@ -0,0 +1,252 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __CAPI_TELEPHONY_SIM_H__ +#define __CAPI_TELEPHONY_SIM_H__ + +#include "telephony_common.h" + +#ifdef __cplusplus + extern "C" { +#endif + +/** + * @file telephony_sim.h + * @brief This file contains the SIM APIs and related enumerations. + */ + +/** + * @addtogroup CAPI_TELEPHONY_INFORMATION_SIM + * @{ + */ + +/** + * @brief Enumeration for the state of SIM card. + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + */ +typedef enum +{ + TELEPHONY_SIM_STATE_UNAVAILABLE, /**< SIM is not available on this device */ + TELEPHONY_SIM_STATE_LOCKED, /**< SIM is locked */ + TELEPHONY_SIM_STATE_AVAILABLE, /**< SIM is available on this device */ + TELEPHONY_SIM_STATE_UNKNOWN, /**< SIM is in transition between states */ +} telephony_sim_state_e; + +/** + * @brief Gets the Integrated Circuit Card IDentification (ICC-ID). + * @details The Integrated Circuit Card Identification number internationally identifies SIM cards. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @remarks You must release @c icc_id using free(). + * + * @param[in] handle The handle from telephony_init() + * @param[out] icc_id The Integrated Circuit Card Identification + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Out of memory + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Invalid parameter + * @retval #TELEPHONY_ERROR_SIM_NOT_AVAILABLE SIM is not available + * + * @pre The SIM state must be #TELEPHONY_SIM_STATE_AVAILABLE. + * + * @see telephony_sim_get_state() + */ +int telephony_sim_get_icc_id(telephony_h handle, char **icc_id); + +/** + * @brief Gets the SIM Operator (MCC [3 digits] + MNC [2~3 digits]). + * @details The Operator is embedded in the SIM card. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @remarks You must release @c sim_operator using free(). + * + * @param[in] handle The handle from telephony_init() + * @param[out] sim_operator The SIM Operator + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Out of memory + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Invalid parameter + * @retval #TELEPHONY_ERROR_SIM_NOT_AVAILABLE SIM is not available + * + * @pre The SIM state must be #TELEPHONY_SIM_STATE_AVAILABLE. + * + * @see telephony_sim_get_state() + */ +int telephony_sim_get_operator(telephony_h handle, char **sim_operator); + +/** + * @brief Gets the Mobile Subscription Identification Number (MSIN [9~10 digits]) of the SIM provider. + * @details This function gets Mobile Subscription Identification Number embedded in the SIM card. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @remarks You must release @c msin using free(). + * + * @param[in] handle The handle from telephony_init() + * @param[out] msin The Mobile Subscription Identification Number + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Out of memory + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Invalid parameter + * @retval #TELEPHONY_ERROR_SIM_NOT_AVAILABLE SIM is not available + * + * @pre The SIM state must be #TELEPHONY_SIM_STATE_AVAILABLE. + * + * @see telephony_sim_get_state() + */ +int telephony_sim_get_msin(telephony_h handle, char **msin); + +/** + * @brief Gets the Service Provider Name (SPN) of the SIM card. + * @details This function gets Service Provider Name embedded in the SIM card. + * If this value is not stored in SIM card, @c NULL will be returned. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @remarks You must release @c spn using free(). + * + * @param[in] handle The handle from telephony_init() + * @param[out] spn The Service Provider Name + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Out of memory + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Invalid parameter + * @retval #TELEPHONY_ERROR_SIM_NOT_AVAILABLE SIM is not available + * + * @pre The SIM state must be #TELEPHONY_SIM_STATE_AVAILABLE. + * + * @see telephony_sim_get_state() + */ +int telephony_sim_get_spn(telephony_h handle, char **spn); + +/** + * @brief Checks whether the current SIM card is different from the previous SIM card. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @param[in] handle The handle from telephony_init() + * @param[out] is_changed @c true if the current SIM card is different from the previous SIM card, + * otherwise @c false if the SIM card is not changed + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Out of memory + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Invalid parameter + * @retval #TELEPHONY_ERROR_SIM_NOT_AVAILABLE SIM is not available + * + * @pre The SIM state must be #TELEPHONY_SIM_STATE_AVAILABLE. + * + * @see telephony_sim_get_state() + */ +int telephony_sim_is_changed(telephony_h handle, bool *is_changed); + +/** + * @brief Gets the state of the SIM. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @param[in] handle The handle from telephony_init() + * @param[out] sim_state The current state of the SIM + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Out of memory + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Invalid parameter + */ +int telephony_sim_get_state(telephony_h handle, telephony_sim_state_e *sim_state); + +/** + * @brief Gets the SIM card subscriber number. + * @details This function gets subscriber number embedded in the SIM card. + * This value contains MSISDN related to the subscriber. + * If this value is not stored in SIM card, @c NULL will be returned. + * + * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @remarks You must release @c subscriber_number using free(). + * + * @param[in] handle The handle from telephony_init() + * @param[out] subscriber_number The subscriber number in the SIM + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Out of memory + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Invalid parameter + * @retval #TELEPHONY_ERROR_SIM_NOT_AVAILABLE SIM is not available + * + * @pre The SIM state must be #TELEPHONY_SIM_STATE_AVAILABLE. + * + * @see telephony_sim_get_state() + */ +int telephony_sim_get_subscriber_number(telephony_h handle, char **subscriber_number); + +/** + * @} + */ + +#ifdef __cplusplus + } +#endif + +#endif // __CAPI_TELEPHONY_SIM_H__ diff --git a/packaging/capi-telephony.spec b/packaging/capi-telephony.spec new file mode 100644 index 0000000..bd5e6fd --- /dev/null +++ b/packaging/capi-telephony.spec @@ -0,0 +1,59 @@ +Name: capi-telephony +Summary: Telephony Core API +Version: 0.1.32 +Release: 1 +Group: System/Libraries +License: Apache-2.0 +Source0: %{name}-%{version}.tar.gz +BuildRequires: cmake +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(tapi) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(capi-system-info) +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + +%description + +%package devel +Summary: Telephony Core API +Group: TO_BE/FILLED_IN +Requires: %{name} = %{version}-%{release} + +%description devel + +%prep +%setup -q + +%build +MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` +cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} + +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install +mkdir -p %{buildroot}/usr/share/license + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + +%files +%manifest capi-telephony.manifest +%{_libdir}/libcapi-telephony.so.* +/usr/share/license/capi-telephony + +%files devel +%{_includedir}/telephony/telephony.h +%{_includedir}/telephony/telephony_common.h +%{_includedir}/telephony/telephony_call.h +%{_includedir}/telephony/telephony_sim.h +%{_includedir}/telephony/telephony_network.h +%{_includedir}/telephony/telephony_modem.h +%{_libdir}/pkgconfig/*.pc +%{_libdir}/libcapi-telephony.so + + diff --git a/src/telephony_call.c b/src/telephony_call.c new file mode 100644 index 0000000..7e6ca6e --- /dev/null +++ b/src/telephony_call.c @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include "telephony_common.h" +#include "telephony_call.h" +#include "telephony_private.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "CAPI_TELEPHONY" + +#define CHECK_INPUT_PARAMETER(arg) \ + if (arg == NULL) { \ + LOGE("INVALID_PARAMETER"); \ + return TELEPHONY_ERROR_INVALID_PARAMETER; \ + } + +static void _mapping_call_state(TelCallStates_t tapi_call_state, telephony_call_state_e *call_state) +{ + switch (tapi_call_state) { + case TAPI_CALL_STATE_ACTIVE: + case TAPI_CALL_STATE_HELD: + if (*call_state != TELEPHONY_CALL_STATE_CONNECTING) + *call_state = TELEPHONY_CALL_STATE_CONNECTED; + break; + case TAPI_CALL_STATE_DIALING: + case TAPI_CALL_STATE_ALERT: + case TAPI_CALL_STATE_INCOMING: + case TAPI_CALL_STATE_WAITING: + *call_state = TELEPHONY_CALL_STATE_CONNECTING; + break; + /* Do not check IDLE state to prevent overriding in case of multi-party call */ + default: + LOGE("Not handled call state: [%d]", tapi_call_state); + break; + } +} + +static void _voice_call_get_state_cb(TelCallStatus_t *tapi_status, void *user_data) +{ + telephony_call_state_e *call_state = user_data; + + if (tapi_status->CallType != TAPI_CALL_TYPE_VOICE + && tapi_status->CallType != TAPI_CALL_TYPE_E911) + return; + + _mapping_call_state(tapi_status->CallState, call_state); +} + +static void _video_call_get_state_cb(TelCallStatus_t *tapi_status, void *user_data) +{ + telephony_call_state_e *call_state = user_data; + + if (tapi_status->CallType != TAPI_CALL_TYPE_DATA) + return; + + _mapping_call_state(tapi_status->CallState, call_state); +} + +int telephony_call_get_voice_call_state(telephony_h handle, telephony_call_state_e *call_state) +{ + int ret; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(call_state); + + *call_state = TELEPHONY_CALL_STATE_IDLE; + + ret = tel_get_call_status_all(tapi_h, _voice_call_get_state_cb, call_state); + if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + return TELEPHONY_ERROR_PERMISSION_DENIED; + } else if (ret != TAPI_API_SUCCESS) { + LOGE("OPERATION_FAILED"); + return TELEPHONY_ERROR_OPERATION_FAILED; + } + + LOGI("call_state: [%d]", *call_state); + + return TELEPHONY_ERROR_NONE; +} + +int telephony_call_get_video_call_state(telephony_h handle, telephony_call_state_e *call_state) +{ + int ret; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(call_state); + + *call_state = TELEPHONY_CALL_STATE_IDLE; + + ret = tel_get_call_status_all(tapi_h, _video_call_get_state_cb, call_state); + if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + return TELEPHONY_ERROR_PERMISSION_DENIED; + } else if (ret != TAPI_API_SUCCESS) { + LOGE("OPERATION_FAILED"); + return TELEPHONY_ERROR_OPERATION_FAILED; + } + + LOGI("call_state: [%d]", *call_state); + + return TELEPHONY_ERROR_NONE; +} diff --git a/src/telephony_common.c b/src/telephony_common.c new file mode 100644 index 0000000..856147c --- /dev/null +++ b/src/telephony_common.c @@ -0,0 +1,432 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "telephony_common.h" +#include "telephony_sim.h" +#include "telephony_call.h" +#include "telephony_network.h" +#include "telephony_private.h" +#include +#include + +#include +#include +#include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "CAPI_TELEPHONY" + +#define CALLBACK_CALL(data) \ + if (evt_cb_data->cb) { \ + evt_cb_data->cb(evt_cb_data->handle, \ + evt_cb_data->noti_id, data, evt_cb_data->user_data); \ + } + +#define CHECK_INPUT_PARAMETER(arg) \ + if (arg == NULL) { \ + LOGE("INVALID_PARAMETER"); \ + return TELEPHONY_ERROR_INVALID_PARAMETER; \ + } + +typedef struct { + telephony_h handle; + telephony_noti_e noti_id; + telephony_noti_cb cb; + void *user_data; +} telephony_evt_cb_data; + +static const char *voice_call_state_tbl[] = { + TAPI_NOTI_VOICE_CALL_STATUS_IDLE, + TAPI_NOTI_VOICE_CALL_STATUS_ACTIVE, + TAPI_NOTI_VOICE_CALL_STATUS_HELD, + TAPI_NOTI_VOICE_CALL_STATUS_DIALING, + TAPI_NOTI_VOICE_CALL_STATUS_ALERT, + TAPI_NOTI_VOICE_CALL_STATUS_INCOMING +}; + +static const char *video_call_state_tbl[] = { + TAPI_NOTI_VIDEO_CALL_STATUS_IDLE, + TAPI_NOTI_VIDEO_CALL_STATUS_ACTIVE, + TAPI_NOTI_VIDEO_CALL_STATUS_DIALING, + TAPI_NOTI_VIDEO_CALL_STATUS_ALERT, + TAPI_NOTI_VIDEO_CALL_STATUS_INCOMING +}; + +static const char *_mapping_noti_id(telephony_noti_e noti_id) +{ + switch (noti_id) { + case TELEPHONY_NOTI_SIM_STATUS: + return TAPI_NOTI_SIM_STATUS; + case TELEPHONY_NOTI_NETWORK_SERVICE_STATE: + return TAPI_PROP_NETWORK_SERVICE_TYPE; + case TELEPHONY_NOTI_NETWORK_CELLID: + return TAPI_PROP_NETWORK_CELLID; + case TELEPHONY_NOTI_NETWORK_ROAMING_STATUS: + return TAPI_PROP_NETWORK_ROAMING_STATUS; + case TELEPHONY_NOTI_NETWORK_SIGNALSTRENGTH_LEVEL: + return TAPI_PROP_NETWORK_SIGNALSTRENGTH_LEVEL; + default: + return NULL; + } +} + +static int _mapping_sim_status(TelSimCardStatus_t tapi_sim_status) +{ + int sim_status; + + switch (tapi_sim_status) { + case TAPI_SIM_STATUS_CARD_ERROR: + case TAPI_SIM_STATUS_CARD_NOT_PRESENT: + case TAPI_SIM_STATUS_CARD_BLOCKED: + case TAPI_SIM_STATUS_CARD_REMOVED: + case TAPI_SIM_STATUS_CARD_CRASHED: + sim_status = TELEPHONY_SIM_STATE_UNAVAILABLE; + break; + case TAPI_SIM_STATUS_SIM_PIN_REQUIRED: + case TAPI_SIM_STATUS_SIM_PUK_REQUIRED: + case TAPI_SIM_STATUS_SIM_NCK_REQUIRED: + case TAPI_SIM_STATUS_SIM_NSCK_REQUIRED: + case TAPI_SIM_STATUS_SIM_SPCK_REQUIRED: + case TAPI_SIM_STATUS_SIM_CCK_REQUIRED: + case TAPI_SIM_STATUS_SIM_LOCK_REQUIRED: + sim_status = TELEPHONY_SIM_STATE_LOCKED; + break; + case TAPI_SIM_STATUS_SIM_INIT_COMPLETED: + sim_status = TELEPHONY_SIM_STATE_AVAILABLE; + break; + case TAPI_SIM_STATUS_UNKNOWN: + case TAPI_SIM_STATUS_SIM_INITIALIZING: + default: + sim_status = TELEPHONY_SIM_STATE_UNKNOWN; + break; + } + + return sim_status; +} + +static int _mapping_service_state(int tapi_service_type) +{ + int service_state; + + switch (tapi_service_type) { + case TAPI_NETWORK_SERVICE_TYPE_UNKNOWN: + case TAPI_NETWORK_SERVICE_TYPE_NO_SERVICE: + case TAPI_NETWORK_SERVICE_TYPE_SEARCH: + service_state = TELEPHONY_NETWORK_SERVICE_STATE_OUT_OF_SERVICE; + break; + case TAPI_NETWORK_SERVICE_TYPE_EMERGENCY: + service_state = TELEPHONY_NETWORK_SERVICE_STATE_EMERGENCY_ONLY; + break; + default: + service_state = TELEPHONY_NETWORK_SERVICE_STATE_IN_SERVICE; + break; + } + + return service_state; +} + +static telephony_error_e __deregister_all_noti(telephony_h handle, telephony_noti_e noti_id) +{ + const char *tapi_noti; + int ret, i; + TapiHandle *tapi_h; + + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + + tapi_noti = _mapping_noti_id(noti_id); + if (tapi_noti == NULL && noti_id != TELEPHONY_NOTI_VOICE_CALL_STATE + && noti_id != TELEPHONY_NOTI_VIDEO_CALL_STATE) { + LOGE("Not supported noti_id"); + return TELEPHONY_ERROR_INVALID_PARAMETER; + } + + /* Deregister all TAPI_NOTI_VOICE/VIDEO_CALL_STATUS_xxx notification */ + if (noti_id == TELEPHONY_NOTI_VOICE_CALL_STATE) { + int count = sizeof(voice_call_state_tbl) / sizeof(char *); + for (i = 0; i < count; i++) { + ret = tel_deregister_noti_event(tapi_h, voice_call_state_tbl[i]); + if (ret != TAPI_API_SUCCESS) { + LOGE("Noti [%s] deregistration failed", voice_call_state_tbl[i]); + } + } + } else if (noti_id == TELEPHONY_NOTI_VIDEO_CALL_STATE) { + int count = sizeof(video_call_state_tbl) / sizeof(char *); + for (i = 0; i < count; i++) { + ret = tel_deregister_noti_event(tapi_h, video_call_state_tbl[i]); + if (ret != TAPI_API_SUCCESS) { + LOGE("Noti [%s] deregistration failed", video_call_state_tbl[i]); + } + } + } else { + /* Deregister other notifications */ + ret = tel_deregister_noti_event(tapi_h, tapi_noti); + if (ret != TAPI_API_SUCCESS) { + LOGE("Noti [%s] deregistration failed", tapi_noti); + } + } + + return TELEPHONY_ERROR_NONE; +} + +static void _deregister_noti(gpointer data) +{ + telephony_evt_cb_data *evt_cb_data = data; + + if (evt_cb_data != NULL) { + /* Deregister all TAPI_NOTI_VOICE/VIDEO_CALL_STATUS_xxx notification */ + if (__deregister_all_noti(evt_cb_data->handle, evt_cb_data->noti_id) + == TELEPHONY_ERROR_NONE) { + LOGI("De-registered noti_id: [%d]", evt_cb_data->noti_id); + } + + /* Free evt_cb_data */ + g_free(evt_cb_data); + } +} + +static void on_signal_callback(TapiHandle *tapi_h, const char *evt_id, + void *data, void *user_data) +{ + telephony_evt_cb_data *evt_cb_data = user_data; + + if (evt_cb_data == NULL) { + LOGE("evt_cb_data is NULL"); + return; + } + + if (!g_strcmp0(evt_id, TAPI_NOTI_SIM_STATUS)) { + int sim_status = _mapping_sim_status(*(TelSimCardStatus_t *)data); + CALLBACK_CALL(&sim_status); + } else if (!g_strcmp0(evt_id, TAPI_PROP_NETWORK_SERVICE_TYPE)) { + int service_state = _mapping_service_state(*(int *)data); + CALLBACK_CALL(&service_state); + } else if (!g_strcmp0(evt_id, TAPI_PROP_NETWORK_CELLID)) { + int cell_id = *(int *)data; + CALLBACK_CALL(&cell_id); + } else if (!g_strcmp0(evt_id, TAPI_PROP_NETWORK_ROAMING_STATUS)) { + int roaming_status = *(int *)data; + CALLBACK_CALL(&roaming_status); + } else if (!g_strcmp0(evt_id, TAPI_PROP_NETWORK_SIGNALSTRENGTH_LEVEL)) { + int rssi = *(int *)data; + CALLBACK_CALL(&rssi); + } else if (!g_strcmp0(evt_id, TAPI_NOTI_VOICE_CALL_STATUS_IDLE) + || !g_strcmp0(evt_id, TAPI_NOTI_VOICE_CALL_STATUS_ACTIVE) + || !g_strcmp0(evt_id, TAPI_NOTI_VOICE_CALL_STATUS_HELD) + || !g_strcmp0(evt_id, TAPI_NOTI_VOICE_CALL_STATUS_DIALING) + || !g_strcmp0(evt_id, TAPI_NOTI_VOICE_CALL_STATUS_ALERT) + || !g_strcmp0(evt_id, TAPI_NOTI_VOICE_CALL_STATUS_INCOMING)) { + telephony_call_state_e call_state; + telephony_call_get_voice_call_state(evt_cb_data->handle, &call_state); + CALLBACK_CALL(&call_state); + } else if (!g_strcmp0(evt_id, TAPI_NOTI_VIDEO_CALL_STATUS_IDLE) + || !g_strcmp0(evt_id, TAPI_NOTI_VIDEO_CALL_STATUS_ACTIVE) + || !g_strcmp0(evt_id, TAPI_NOTI_VIDEO_CALL_STATUS_DIALING) + || !g_strcmp0(evt_id, TAPI_NOTI_VIDEO_CALL_STATUS_ALERT) + || !g_strcmp0(evt_id, TAPI_NOTI_VIDEO_CALL_STATUS_INCOMING)) { + telephony_call_state_e call_state; + telephony_call_get_video_call_state(evt_cb_data->handle, &call_state); + CALLBACK_CALL(&call_state); + } else { + LOGE("Unhandled noti: [%s]", evt_id); + } +} + +int telephony_set_noti_cb(telephony_h handle, + telephony_noti_e noti_id, telephony_noti_cb cb, void *user_data) +{ + telephony_evt_cb_data *evt_cb_data = NULL; + const char *tapi_noti; + int ret, i; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + + LOGI("Entry"); + tapi_h = ((telephony_data *)handle)->tapi_h; + + /* Mapping TAPI notification */ + tapi_noti = _mapping_noti_id(noti_id); + if (tapi_noti == NULL && noti_id != TELEPHONY_NOTI_VOICE_CALL_STATE + && noti_id != TELEPHONY_NOTI_VIDEO_CALL_STATE) { + LOGE("Not supported noti_id"); + return TELEPHONY_ERROR_INVALID_PARAMETER; + } + + /* Make evt_cb_data */ + evt_cb_data = g_new0(telephony_evt_cb_data, 1); + evt_cb_data->handle = handle; + evt_cb_data->noti_id = noti_id; + evt_cb_data->cb = cb; + evt_cb_data->user_data = user_data; + + /* + * In case of register Call State notification, + * we should take care of all TAPI_NOTI_VOICE/VIDEO_CALL_STATUS_xxx notification + */ + if (noti_id == TELEPHONY_NOTI_VOICE_CALL_STATE) { + int count = sizeof(voice_call_state_tbl) / sizeof(char *); + for (i = 0; i < count; i++) { + ret = tel_register_noti_event(tapi_h, voice_call_state_tbl[i], on_signal_callback, evt_cb_data); + if (ret != TAPI_API_SUCCESS) { + LOGE("Noti registration failed"); + g_free(evt_cb_data); + return TELEPHONY_ERROR_OPERATION_FAILED; + } + } + } else if (noti_id == TELEPHONY_NOTI_VIDEO_CALL_STATE) { + int count = sizeof(video_call_state_tbl) / sizeof(char *); + for (i = 0; i < count; i++) { + ret = tel_register_noti_event(tapi_h, video_call_state_tbl[i], on_signal_callback, evt_cb_data); + if (ret != TAPI_API_SUCCESS) { + LOGE("Noti registration failed"); + g_free(evt_cb_data); + return TELEPHONY_ERROR_OPERATION_FAILED; + } + } + } else { /* Register other notifications */ + ret = tel_register_noti_event(tapi_h, tapi_noti, on_signal_callback, evt_cb_data); + if (ret != TAPI_API_SUCCESS) { + LOGE("Noti registration failed"); + g_free(evt_cb_data); + return TELEPHONY_ERROR_OPERATION_FAILED; + } + } + + /* Append evt_cb_data to free */ + ((telephony_data *)handle)->evt_list = g_slist_append(((telephony_data *)handle)->evt_list, evt_cb_data); + + return TELEPHONY_ERROR_NONE; +} + +int telephony_unset_noti_cb(telephony_h handle, telephony_noti_e noti_id) +{ + telephony_evt_cb_data *evt_cb_data = NULL; + GSList *list = NULL; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + + LOGI("Entry"); + + /* Deregister all TAPI_NOTI_VOICE/VIDEO_CALL_STATUS_xxx notification */ + if (__deregister_all_noti(handle, noti_id) != TELEPHONY_ERROR_NONE) { + LOGE("De-registration failed"); + return TELEPHONY_ERROR_INVALID_PARAMETER; + } + LOGI("De-registered noti_id: [%d]", noti_id); + + /* Free evt_cb_data */ + list = g_slist_nth(((telephony_data *)handle)->evt_list, 0); + while (list) { + evt_cb_data = list->data; + if (evt_cb_data->noti_id == noti_id) { + ((telephony_data *)handle)->evt_list = g_slist_remove(((telephony_data *)handle)->evt_list, evt_cb_data); + g_free(evt_cb_data); + break; + } + + list = g_slist_next(list); + } + + return TELEPHONY_ERROR_NONE; +} + +int telephony_init(telephony_handle_list_s *list) +{ + char **cp_list; + int cp_count = 0; + int i; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(list); + +#if !GLIB_CHECK_VERSION(2,35,0) + /* Need g_type_init() to use tel_get_cp_name_list() */ + g_type_init(); +#endif + + cp_list = tel_get_cp_name_list(); + if (cp_list == NULL) { + LOGE("cp_list is NULL"); + return TELEPHONY_ERROR_OPERATION_FAILED; + } + + while (cp_list[cp_count]) { + cp_count++; + } + + list->count = cp_count; + list->handle = g_malloc(cp_count * sizeof(telephony_h)); + for (i = 0; i < cp_count; i++) { + telephony_data *tmp = g_malloc(sizeof(telephony_data)); + tmp->evt_list = NULL; + tmp->tapi_h = tel_init(cp_list[i]); + if (tmp->tapi_h == NULL) { + int j = 0; + LOGE("handle is NULL"); + for (; j < i; j++) { + /* Need to free already allocated data */ + if (list->handle[j]) { + tel_deinit(((telephony_data *)list->handle[j])->tapi_h); + g_free(list->handle[j]); + } + } + g_free(tmp); + g_free(list->handle); + list->handle = NULL; + list->count = 0; + g_strfreev(cp_list); + return TELEPHONY_ERROR_OPERATION_FAILED; + } + list->handle[i] = (telephony_h)tmp; + } + g_strfreev(cp_list); + + return TELEPHONY_ERROR_NONE; +} + +int telephony_deinit(telephony_handle_list_s *list) +{ + unsigned int i; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(list); + + for (i = 0; i < list->count; i++) { + telephony_data *tmp = (telephony_data *)list->handle[i]; + + /* De-init all TapiHandle */ + tel_deinit(tmp->tapi_h); + tmp->tapi_h = NULL; + + /* De-register all registered events */ + g_slist_free_full(tmp->evt_list, _deregister_noti); + tmp->evt_list = NULL; + + /* Free handle[i] */ + g_free(list->handle[i]); + } + g_free(list->handle); + list->handle = NULL; + list->count = 0; + + return TELEPHONY_ERROR_NONE; +} diff --git a/src/telephony_modem.c b/src/telephony_modem.c new file mode 100644 index 0000000..47b0d41 --- /dev/null +++ b/src/telephony_modem.c @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include "telephony_common.h" +#include "telephony_modem.h" +#include "telephony_private.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "CAPI_TELEPHONY" + +#define CHECK_INPUT_PARAMETER(arg) \ + if (arg == NULL) { \ + LOGE("INVALID_PARAMETER"); \ + return TELEPHONY_ERROR_INVALID_PARAMETER; \ + } + +int telephony_modem_get_imei(telephony_h handle, char **imei) +{ + GVariant *gv = NULL; + GError *gerr = NULL; + int tapi_result; + char *tapi_imei = NULL; + int error = TELEPHONY_ERROR_OPERATION_FAILED; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(imei); + + gv = g_dbus_connection_call_sync(tapi_h->dbus_connection, + DBUS_TELEPHONY_SERVICE, tapi_h->path, DBUS_TELEPHONY_MODEM_INTERFACE, + "GetIMEI", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &gerr); + + if (gv) { + g_variant_get(gv, "(is)", &tapi_result, &tapi_imei); + if (tapi_result == 0) { + if (tapi_imei != NULL && strlen(tapi_imei) != 0) { + *imei = g_strdup_printf("%s", tapi_imei); + error = TELEPHONY_ERROR_NONE; + } + g_free(tapi_imei); + } + } else { + LOGE("g_dbus_conn failed. error (%s)", gerr->message); + if (strstr(gerr->message, "No access rights")) { + LOGE("PERMISSION_DENIED"); + error = TELEPHONY_ERROR_PERMISSION_DENIED; + } + } + + return error; +} diff --git a/src/telephony_network.c b/src/telephony_network.c new file mode 100644 index 0000000..728dd73 --- /dev/null +++ b/src/telephony_network.c @@ -0,0 +1,346 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "telephony_network.h" +#include "telephony_common.h" +#include "telephony_private.h" + +#include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "CAPI_TELEPHONY" + +#define CHECK_INPUT_PARAMETER(arg) \ + if (arg == NULL) { \ + LOGE("INVALID_PARAMETER"); \ + return TELEPHONY_ERROR_INVALID_PARAMETER; \ + } + +int telephony_network_get_lac(telephony_h handle, int *lac) +{ + int ret; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(lac); + + ret = tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_LAC, lac); + if (ret == TAPI_API_SUCCESS) { + LOGI("lac:[%d]", *lac); + ret = TELEPHONY_ERROR_NONE; + } else if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + ret = TELEPHONY_ERROR_PERMISSION_DENIED; + } else { + LOGE("OPERATION_FAILED"); + ret = TELEPHONY_ERROR_OPERATION_FAILED; + } + + return ret; +} + +int telephony_network_get_cell_id(telephony_h handle, int *cell_id) +{ + int ret; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(cell_id); + + ret = tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_CELLID, cell_id); + if (ret == TAPI_API_SUCCESS) { + LOGI("cell_id:[%d]", *cell_id); + ret = TELEPHONY_ERROR_NONE; + } else if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + ret = TELEPHONY_ERROR_PERMISSION_DENIED; + } else { + LOGE("OPERATION_FAILED"); + ret = TELEPHONY_ERROR_OPERATION_FAILED; + } + + return ret; +} + +int telephony_network_get_rssi(telephony_h handle, telephony_network_rssi_e *rssi) +{ + int ret; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(rssi); + + ret = tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_SIGNALSTRENGTH_LEVEL, (int *)rssi); + if (ret == TAPI_API_SUCCESS) { + LOGI("rssi:[%d]", *rssi); + ret = TELEPHONY_ERROR_NONE; + } else if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + ret = TELEPHONY_ERROR_PERMISSION_DENIED; + } else { + LOGE("OPERATION_FAILED"); + ret = TELEPHONY_ERROR_OPERATION_FAILED; + } + + return ret; +} + +int telephony_network_get_roaming_status(telephony_h handle, bool *status) +{ + int ret; + int temp = 0; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(status); + + ret = tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_ROAMING_STATUS, &temp); + if (ret == TAPI_API_SUCCESS) { + if (temp == 1) + *status = true; + else + *status = false; + LOGI("status:[%d]", *status); + ret = TELEPHONY_ERROR_NONE; + } else if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + ret = TELEPHONY_ERROR_PERMISSION_DENIED; + } else { + LOGE("OPERATION_FAILED"); + ret = TELEPHONY_ERROR_OPERATION_FAILED; + } + + return ret; +} + +int telephony_network_get_mcc(telephony_h handle, char **mcc) +{ + int ret; + char *plmn_str = NULL; + int mcc_length = 3; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(mcc); + + ret = tel_get_property_string(tapi_h, TAPI_PROP_NETWORK_PLMN, &plmn_str); + if (ret == TAPI_API_SUCCESS) { + *mcc = malloc (sizeof(char) * (mcc_length + 1)); + if (*mcc == NULL) { + LOGE("OUT_OF_MEMORY"); + ret = TELEPHONY_ERROR_OUT_OF_MEMORY; + } else { + memset (*mcc, 0x00, mcc_length + 1); + strncpy (*mcc, plmn_str, mcc_length); + free (plmn_str); + + LOGI("mcc:[%s]", *mcc); + ret = TELEPHONY_ERROR_NONE; + } + } else if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + ret = TELEPHONY_ERROR_PERMISSION_DENIED; + } else { + LOGE("OPERATION_FAILED"); + ret = TELEPHONY_ERROR_OPERATION_FAILED; + } + + return ret; +} + +int telephony_network_get_mnc(telephony_h handle, char **mnc) +{ + int ret; + char *plmn_str = NULL; + int plmn_length; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(mnc); + + ret = tel_get_property_string(tapi_h, TAPI_PROP_NETWORK_PLMN, &plmn_str); + if (ret == TAPI_API_SUCCESS) { + plmn_length = strlen(plmn_str); + LOGI("plmn:[%s], length:[%d]", plmn_str, plmn_length); + + *mnc = malloc (sizeof(char) * (plmn_length -3 + 1)); + if (*mnc == NULL) { + LOGE("OUT_OF_MEMORY"); + ret = TELEPHONY_ERROR_OUT_OF_MEMORY; + } else { + memset (*mnc, 0x00, (plmn_length -3 + 1)); + strncpy (*mnc, plmn_str + 3, (plmn_length -3 + 1)); + free (plmn_str); + + LOGI("mnc:[%s]", *mnc); + ret = TELEPHONY_ERROR_NONE; + } + } else if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + ret = TELEPHONY_ERROR_PERMISSION_DENIED; + } else { + LOGE("OPERATION_FAILED"); + ret = TELEPHONY_ERROR_OPERATION_FAILED; + } + + return ret; +} + +int telephony_network_get_network_name(telephony_h handle, char **network_name) +{ + int ret; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(network_name); + + ret = tel_get_property_string(tapi_h, TAPI_PROP_NETWORK_NETWORK_NAME, network_name); + if (ret == TAPI_API_SUCCESS) { + LOGI("network_name:[%s]", *network_name); + ret = TELEPHONY_ERROR_NONE; + } else if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + ret = TELEPHONY_ERROR_PERMISSION_DENIED; + } else { + LOGE("OPERATION_FAILED"); + ret = TELEPHONY_ERROR_OPERATION_FAILED; + } + + return ret; +} + +int telephony_network_get_type(telephony_h handle, telephony_network_type_e *network_type) +{ + int ret; + int service_type = 0; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(network_type); + + ret = tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_SERVICE_TYPE, &service_type); + if (ret == TAPI_API_SUCCESS) { + switch (service_type) { + case TAPI_NETWORK_SERVICE_TYPE_2G: + *network_type = TELEPHONY_NETWORK_TYPE_GSM; + break; + case TAPI_NETWORK_SERVICE_TYPE_2_5G: + *network_type = TELEPHONY_NETWORK_TYPE_GPRS; + break; + case TAPI_NETWORK_SERVICE_TYPE_2_5G_EDGE: + *network_type = TELEPHONY_NETWORK_TYPE_EDGE; + break; + case TAPI_NETWORK_SERVICE_TYPE_3G: + *network_type = TELEPHONY_NETWORK_TYPE_UMTS; + break; + case TAPI_NETWORK_SERVICE_TYPE_HSDPA: + *network_type = TELEPHONY_NETWORK_TYPE_HSDPA; + break; + case TAPI_NETWORK_SERVICE_TYPE_LTE: + *network_type = TELEPHONY_NETWORK_TYPE_LTE; + break; + default: + *network_type = TELEPHONY_NETWORK_TYPE_UNKNOWN; + break; + } + + LOGI("network_type:[%d]", *network_type); + ret = TELEPHONY_ERROR_NONE; + } else if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + ret = TELEPHONY_ERROR_PERMISSION_DENIED; + } else { + LOGE("OPERATION_FAILED"); + ret = TELEPHONY_ERROR_OPERATION_FAILED; + } + + return ret; +} + +int telephony_network_get_service_state(telephony_h handle, telephony_network_service_state_e *network_service_state) +{ + int ret; + int service_type = 0; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(network_service_state); + + ret = tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_SERVICE_TYPE, &service_type); + if (ret == TAPI_API_SUCCESS) { + switch (service_type) { + case TAPI_NETWORK_SERVICE_TYPE_UNKNOWN: + case TAPI_NETWORK_SERVICE_TYPE_NO_SERVICE: + case TAPI_NETWORK_SERVICE_TYPE_SEARCH: + *network_service_state = TELEPHONY_NETWORK_SERVICE_STATE_OUT_OF_SERVICE; + break; + case TAPI_NETWORK_SERVICE_TYPE_EMERGENCY: + *network_service_state = TELEPHONY_NETWORK_SERVICE_STATE_EMERGENCY_ONLY; + break; + default: + *network_service_state = TELEPHONY_NETWORK_SERVICE_STATE_IN_SERVICE; + break; + } + LOGI("network_service_state:[%d]", *network_service_state); + ret = TELEPHONY_ERROR_NONE; + } else if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + ret = TELEPHONY_ERROR_PERMISSION_DENIED; + } else { + LOGE("OPERATION_FAILED"); + ret = TELEPHONY_ERROR_OPERATION_FAILED; + } + + return ret; +} diff --git a/src/telephony_sim.c b/src/telephony_sim.c new file mode 100644 index 0000000..89f7e98 --- /dev/null +++ b/src/telephony_sim.c @@ -0,0 +1,399 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include "telephony_sim.h" +#include "telephony_private.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "CAPI_TELEPHONY" + +#define DBUS_SIM_STATUS_ERROR "SIM STATUS ERROR" +#define DBUS_SIM_NOT_FOUND "SIM NOT FOUND" +#define DBUS_SIM_PERM_BLOCKED "SIM PERM BLOCKED" +#define DBUS_SIM_CARD_ERROR "SIM CARD ERROR" +#define DBUS_SIM_NOT_INITIALIZED "SIM NOT INITIALIZED" +#define DBUS_SIM_INIT_COMPLETED "SIM INIT COMPLETED" +#define DBUS_SIM_LOCKED "SIM LOCKED" +#define DBUS_SIM_NOT_READY "SIM NOT READY" +#define DBUS_SIM_RESPONSE_DATA_ERROR "SIM RESPONSE DATA ERROR" +#define DBUS_SIM_ACCESS_DENIED "No access rights" + +#define CHECK_INPUT_PARAMETER(arg) \ + if (arg == NULL) { \ + LOGE("INVALID_PARAMETER"); \ + return TELEPHONY_ERROR_INVALID_PARAMETER; \ + } + +#define GET_SIM_STATUS(tapi_h, sim_card_state) { \ + int card_changed = 0; \ + int ret = tel_get_sim_init_info(tapi_h, &sim_card_state, &card_changed); \ + if (ret == TAPI_API_ACCESS_DENIED) { \ + LOGE("PERMISSION_DENIED"); \ + return TELEPHONY_ERROR_PERMISSION_DENIED; \ + } else if (ret != TAPI_API_SUCCESS) { \ + LOGE("OPERATION_FAILED"); \ + return TELEPHONY_ERROR_OPERATION_FAILED; \ + } \ +} + +static telephony_error_e _convert_dbus_errmsg_to_sim_error(gchar *err_msg) +{ + telephony_error_e ret = TELEPHONY_ERROR_OPERATION_FAILED; + if (err_msg == NULL) + return ret; + + if (strstr(err_msg, DBUS_SIM_NOT_FOUND)) { + ret = TELEPHONY_ERROR_SIM_NOT_AVAILABLE; + } else if (strstr(err_msg, DBUS_SIM_PERM_BLOCKED)) { + ret = TELEPHONY_ERROR_SIM_NOT_AVAILABLE; + } else if (strstr(err_msg, DBUS_SIM_CARD_ERROR)) { + ret = TELEPHONY_ERROR_OPERATION_FAILED; + } else if (strstr(err_msg, DBUS_SIM_NOT_INITIALIZED)) { + ret = TELEPHONY_ERROR_SIM_NOT_AVAILABLE; + } else if (strstr(err_msg, DBUS_SIM_INIT_COMPLETED)) { + ret = TELEPHONY_ERROR_NONE; + } else if (strstr(err_msg, DBUS_SIM_LOCKED)) { + ret = TELEPHONY_ERROR_SIM_NOT_AVAILABLE; + } else if (strstr(err_msg, DBUS_SIM_NOT_READY)) { + ret = TELEPHONY_ERROR_SIM_NOT_AVAILABLE; + } else if (strstr(err_msg, DBUS_SIM_RESPONSE_DATA_ERROR)) { + ret = TELEPHONY_ERROR_OPERATION_FAILED; + } else if (strstr(err_msg, DBUS_SIM_ACCESS_DENIED)) { + LOGE("PERMISSION_DENIED"); + ret = TELEPHONY_ERROR_PERMISSION_DENIED; + } else { + ret = TELEPHONY_ERROR_OPERATION_FAILED; + } + + return ret; +} + +int telephony_sim_get_icc_id(telephony_h handle, char **icc_id) +{ + int error_code = TELEPHONY_ERROR_NONE; + TelSimCardStatus_t sim_card_state = TAPI_SIM_STATUS_UNKNOWN; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(icc_id); + GET_SIM_STATUS(tapi_h, sim_card_state); + + *icc_id = NULL; + if (sim_card_state == TAPI_SIM_STATUS_CARD_ERROR + || sim_card_state == TAPI_SIM_STATUS_CARD_BLOCKED + || sim_card_state == TAPI_SIM_STATUS_CARD_NOT_PRESENT + || sim_card_state == TAPI_SIM_STATUS_CARD_REMOVED + || sim_card_state == TAPI_SIM_STATUS_UNKNOWN) { + error_code = TELEPHONY_ERROR_SIM_NOT_AVAILABLE; + } else { + GError *gerr = NULL; + GVariant *sync_gv = NULL; + gchar *iccid = NULL; + TelSimAccessResult_t result = TAPI_SIM_ACCESS_SUCCESS; + + sync_gv = g_dbus_connection_call_sync(tapi_h->dbus_connection, + DBUS_TELEPHONY_SERVICE, tapi_h->path, DBUS_TELEPHONY_SIM_INTERFACE, + "GetICCID", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &gerr); + + if (sync_gv) { + g_variant_get(sync_gv, "(is)", &result, &iccid); + if (result == TAPI_SIM_ACCESS_SUCCESS) { + if (iccid != NULL && strlen(iccid) != 0) { + *icc_id = g_strdup_printf("%s", iccid); + } else { + *icc_id = g_strdup_printf("%s", ""); + } + } else { + error_code = TELEPHONY_ERROR_OPERATION_FAILED; + } + g_free(iccid); + } else { + LOGE("g_dbus_conn failed. error (%s)", gerr->message); + error_code = _convert_dbus_errmsg_to_sim_error(gerr->message); + g_error_free(gerr); + } + } + + return error_code; +} + +int telephony_sim_get_operator(telephony_h handle, char **sim_operator) +{ + int error_code = TELEPHONY_ERROR_NONE; + TelSimCardStatus_t sim_card_state = TAPI_SIM_STATUS_UNKNOWN; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(sim_operator); + GET_SIM_STATUS(tapi_h, sim_card_state); + + *sim_operator = NULL; + if (sim_card_state != TAPI_SIM_STATUS_SIM_INIT_COMPLETED) { + error_code = TELEPHONY_ERROR_SIM_NOT_AVAILABLE; + } else { + TelSimImsiInfo_t sim_imsi_info; + int ret = tel_get_sim_imsi(tapi_h, &sim_imsi_info); + if (ret == TAPI_API_SUCCESS) { + *sim_operator = g_strdup_printf("%s%s", sim_imsi_info.szMcc, sim_imsi_info.szMnc); + LOGI("SIM operator: [%s]", *sim_operator); + } else if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + error_code = TELEPHONY_ERROR_PERMISSION_DENIED; + } else { + LOGE("OPERATION_FAILED"); + error_code = TELEPHONY_ERROR_OPERATION_FAILED; + } + } + + return error_code; +} + +int telephony_sim_get_msin(telephony_h handle, char **msin) +{ + int error_code = TELEPHONY_ERROR_NONE; + TelSimCardStatus_t sim_card_state = TAPI_SIM_STATUS_UNKNOWN; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(msin); + GET_SIM_STATUS(tapi_h, sim_card_state); + + *msin = NULL; + if (sim_card_state != TAPI_SIM_STATUS_SIM_INIT_COMPLETED) { + error_code = TELEPHONY_ERROR_SIM_NOT_AVAILABLE; + } else { + TelSimImsiInfo_t sim_imsi_info; + int ret = tel_get_sim_imsi(tapi_h, &sim_imsi_info); + if (ret == TAPI_API_SUCCESS) { + *msin = g_strdup_printf("%s", sim_imsi_info.szMsin); + } else if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + error_code = TELEPHONY_ERROR_PERMISSION_DENIED; + } else { + LOGE("OPERATION_FAILED"); + error_code = TELEPHONY_ERROR_OPERATION_FAILED; + } + } + + return error_code; +} + +int telephony_sim_get_spn(telephony_h handle, char **spn) +{ + int error_code = TELEPHONY_ERROR_NONE; + TelSimCardStatus_t sim_card_state = TAPI_SIM_STATUS_UNKNOWN; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(spn); + GET_SIM_STATUS(tapi_h, sim_card_state); + + *spn = NULL; + if (sim_card_state == TAPI_SIM_STATUS_CARD_ERROR + || sim_card_state == TAPI_SIM_STATUS_CARD_BLOCKED + || sim_card_state == TAPI_SIM_STATUS_CARD_NOT_PRESENT + || sim_card_state == TAPI_SIM_STATUS_CARD_REMOVED + || sim_card_state == TAPI_SIM_STATUS_UNKNOWN) { + error_code = TELEPHONY_ERROR_SIM_NOT_AVAILABLE; + } else { + GError *gerr = NULL; + GVariant *sync_gv = NULL; + TelSimAccessResult_t result = TAPI_SIM_ACCESS_SUCCESS; + gchar *spn_str = NULL; + guchar dc = 0; + + sync_gv = g_dbus_connection_call_sync(tapi_h->dbus_connection, + DBUS_TELEPHONY_SERVICE, tapi_h->path, DBUS_TELEPHONY_SIM_INTERFACE, + "GetSpn", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &gerr); + + if (sync_gv) { + g_variant_get(sync_gv, "(iys)", &result, &dc, &spn_str); + if (result == TAPI_SIM_ACCESS_SUCCESS) { + if (spn_str != NULL && strlen(spn_str) != 0) { + *spn = g_strdup_printf("%s", spn_str); + LOGI("SPN: [%s]", *spn); + } else { + *spn = g_strdup_printf("%s", ""); + LOGI("SPN: [%s]", *spn); + } + } else { + error_code = TELEPHONY_ERROR_OPERATION_FAILED; + } + g_free(spn_str); + } else { + LOGE("g_dbus_conn failed. error (%s)", gerr->message); + error_code = _convert_dbus_errmsg_to_sim_error(gerr->message); + g_error_free(gerr); + } + } + + return error_code; +} + +int telephony_sim_is_changed(telephony_h handle, bool *is_changed) +{ + int card_changed = 0; + TelSimCardStatus_t sim_card_state = 0x00; + int error_code = TELEPHONY_ERROR_NONE; + int ret; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(is_changed); + + ret = tel_get_sim_init_info(tapi_h, &sim_card_state, &card_changed); + if (ret == TAPI_API_SUCCESS) { + if (sim_card_state == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) { + *is_changed = card_changed; + } else { + LOGE("NOT_AVAILABLE"); + error_code = TELEPHONY_ERROR_SIM_NOT_AVAILABLE; + } + } else if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + error_code = TELEPHONY_ERROR_PERMISSION_DENIED; + } else { + LOGE("OPERATION_FAILED"); + error_code = TELEPHONY_ERROR_OPERATION_FAILED; + } + + return error_code; +} + +int telephony_sim_get_state(telephony_h handle, telephony_sim_state_e *sim_state) +{ + TelSimCardStatus_t sim_card_state = TAPI_SIM_STATUS_UNKNOWN; + int error_code = TELEPHONY_ERROR_NONE; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(sim_state); + GET_SIM_STATUS(tapi_h, sim_card_state); + + switch (sim_card_state) { + case TAPI_SIM_STATUS_CARD_ERROR: + case TAPI_SIM_STATUS_CARD_NOT_PRESENT: + case TAPI_SIM_STATUS_CARD_BLOCKED: + case TAPI_SIM_STATUS_CARD_REMOVED: + case TAPI_SIM_STATUS_CARD_CRASHED: + *sim_state = TELEPHONY_SIM_STATE_UNAVAILABLE; + break; + case TAPI_SIM_STATUS_SIM_PIN_REQUIRED: + case TAPI_SIM_STATUS_SIM_PUK_REQUIRED: + case TAPI_SIM_STATUS_SIM_NCK_REQUIRED: + case TAPI_SIM_STATUS_SIM_NSCK_REQUIRED: + case TAPI_SIM_STATUS_SIM_SPCK_REQUIRED: + case TAPI_SIM_STATUS_SIM_CCK_REQUIRED: + case TAPI_SIM_STATUS_SIM_LOCK_REQUIRED: + *sim_state = TELEPHONY_SIM_STATE_LOCKED; + break; + case TAPI_SIM_STATUS_SIM_INIT_COMPLETED: + *sim_state = TELEPHONY_SIM_STATE_AVAILABLE; + break; + case TAPI_SIM_STATUS_UNKNOWN: + case TAPI_SIM_STATUS_SIM_INITIALIZING: + default: + *sim_state = TELEPHONY_SIM_STATE_UNKNOWN; + break; + } + + return error_code; +} + +int telephony_sim_get_subscriber_number(telephony_h handle, char **subscriber_number) +{ + int error_code = TELEPHONY_ERROR_NONE; + GError *gerr = NULL; + GVariant *sync_gv = NULL; + TelSimAccessResult_t result = TAPI_SIM_ACCESS_SUCCESS; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(subscriber_number); + + *subscriber_number = NULL; + sync_gv = g_dbus_connection_call_sync(tapi_h->dbus_connection, + DBUS_TELEPHONY_SERVICE, tapi_h->path, DBUS_TELEPHONY_SIM_INTERFACE, + "GetMSISDN", NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &gerr); + if (sync_gv) { + GVariantIter *iter = NULL; + g_variant_get(sync_gv, "(iaa{sv})", &result, &iter); + if (result == TAPI_SIM_ACCESS_SUCCESS) { + gchar *key = NULL; + GVariant *value = NULL; + const gchar *str_value = NULL; + GVariantIter *iter_row = NULL; + + while (g_variant_iter_next(iter, "a{sv}", &iter_row)) { + while (g_variant_iter_loop(iter_row, "{sv}", &key, &value)) { + if (!g_strcmp0(key, "number")) { + str_value = g_variant_get_string(value, NULL); + if (str_value != NULL && strlen(str_value) != 0) { + *subscriber_number = g_strdup_printf("%s", str_value); + } + } + } + g_variant_iter_free(iter_row); + /* Acquire only 1 subscriber number */ + break; + } + if (!*subscriber_number) + *subscriber_number = g_strdup_printf("%s", ""); + g_variant_iter_free(iter); + } else { + error_code = TELEPHONY_ERROR_OPERATION_FAILED; + } + } else { + LOGE("g_dbus_conn failed. error (%s)", gerr->message); + error_code = _convert_dbus_errmsg_to_sim_error(gerr->message); + g_error_free(gerr); + } + + return error_code; +} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..97657b6 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,20 @@ +SET(fw_test "${fw_name}-test") + +INCLUDE(FindPkgConfig) +pkg_check_modules(${fw_test} REQUIRED glib-2.0) +FOREACH(flag ${${fw_test}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall") + +#ADD_EXECUTABLE("system-sensor" system-sensor.c) +#TARGET_LINK_LIBRARIES("system-sensor" ${fw_name} ${${fw_test}_LDFLAGS}) + +aux_source_directory(. sources) +FOREACH(src ${sources}) + GET_FILENAME_COMPONENT(src_name ${src} NAME_WE) + MESSAGE("${src_name}") + ADD_EXECUTABLE(${src_name} ${src}) + TARGET_LINK_LIBRARIES(${src_name} ${fw_name} ${${fw_test}_LDFLAGS}) +ENDFOREACH() diff --git a/test/test_all_api.c b/test/test_all_api.c new file mode 100644 index 0000000..cb07e2a --- /dev/null +++ b/test/test_all_api.c @@ -0,0 +1,374 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "CAPI_TELEPHONY_TEST" + +static GMainLoop *event_loop; + +static int network_noti_tbl[] = { + TELEPHONY_NOTI_NETWORK_SERVICE_STATE, + TELEPHONY_NOTI_NETWORK_CELLID, + TELEPHONY_NOTI_NETWORK_ROAMING_STATUS, + TELEPHONY_NOTI_NETWORK_SIGNALSTRENGTH_LEVEL +}; + +static int call_noti_tbl[] = { + TELEPHONY_NOTI_VOICE_CALL_STATE, + TELEPHONY_NOTI_VIDEO_CALL_STATE +}; + +static const char *_mapping_sim_state(telephony_sim_state_e sim_state) +{ + switch (sim_state) { + case TELEPHONY_SIM_STATE_AVAILABLE: + return "Available"; + case TELEPHONY_SIM_STATE_LOCKED: + return "Locked"; + case TELEPHONY_SIM_STATE_UNKNOWN: + return "Unknown"; + default: + return "Unavailable"; + } +} + +static void sim_noti_cb(telephony_h handle, telephony_noti_e noti_id, void *data, void *user_data) +{ + LOGI("Noti!! SIM status: [%d]", *(int *)data); + +// g_main_loop_quit(event_loop); +} + + +static const char *_mapping_service_state(telephony_network_service_state_e service_state) +{ + switch (service_state) { + case TELEPHONY_NETWORK_SERVICE_STATE_IN_SERVICE: + return "In service"; + case TELEPHONY_NETWORK_SERVICE_STATE_OUT_OF_SERVICE: + return "Out of service"; + case TELEPHONY_NETWORK_SERVICE_STATE_EMERGENCY_ONLY: + return "Emergency only"; + default: + return "Unknown state"; + } +} + +static const char *_mapping_network_type(telephony_network_type_e network_type) +{ + switch (network_type) { + case TELEPHONY_NETWORK_TYPE_GSM: + return "GSM"; + case TELEPHONY_NETWORK_TYPE_GPRS: + return "GPRS"; + case TELEPHONY_NETWORK_TYPE_EDGE: + return "EDGE"; + case TELEPHONY_NETWORK_TYPE_UMTS: + return "UMTS"; + case TELEPHONY_NETWORK_TYPE_HSDPA: + return "HSDPA"; + case TELEPHONY_NETWORK_TYPE_LTE: + return "LTE"; + default: + return "Unknown"; + } +} + +static void network_noti_cb(telephony_h handle, telephony_noti_e noti_id, void *data, void *user_data) +{ + switch (noti_id) { + case TELEPHONY_NOTI_NETWORK_SERVICE_STATE: + LOGI("Noti!!! Service state: [%s]", _mapping_service_state(*(int *)data)); + break; + case TELEPHONY_NOTI_NETWORK_CELLID: + LOGI("Noti!!! Cell ID: [%d]", *(int *)data); + break; + case TELEPHONY_NOTI_NETWORK_ROAMING_STATUS: + LOGI("Noti!!! Roaming status: [%s]", *(int *)data ? "ON" : "OFF"); + break; + case TELEPHONY_NOTI_NETWORK_SIGNALSTRENGTH_LEVEL: + LOGI("Noti!!! Signal strength: [%d]", *(int *)data); + break; + default: + LOGE("Unknown noti"); + break; + } + +// g_main_loop_quit(event_loop); +} + +static const char *_mapping_call_state(telephony_call_state_e call_state) +{ + switch (call_state) { + case TELEPHONY_CALL_STATE_IDLE: + return "Idle"; + case TELEPHONY_CALL_STATE_CONNECTING: + return "Connecting"; + case TELEPHONY_CALL_STATE_CONNECTED: + return "Active"; + default: + return "Unknown"; + } +} + +static void call_noti_cb(telephony_h handle, telephony_noti_e noti_id, void *data, void *user_data) +{ + switch (noti_id) { + case TELEPHONY_NOTI_VOICE_CALL_STATE: + LOGI("Noti!!! Voice Call state: [%s]", _mapping_call_state(*(int *)data)); + break; + case TELEPHONY_NOTI_VIDEO_CALL_STATE: + LOGI("Noti!!! Video Call state: [%s]", _mapping_call_state(*(int *)data)); + break; + default: + LOGE("Unknown noti"); + break; + } + +// g_main_loop_quit(event_loop); +} + +int main() +{ + telephony_handle_list_s handle_list; + int ret_value, i; + + /* SIM value */ + char *operator = NULL; + char *icc_id = NULL; + char *msin = NULL; + char *spn = NULL; + telephony_sim_state_e sim_state = 0; + char *subscriber_number = NULL; + + /* Network value */ + int cell_id = 0; + int lac = 0; + char *mcc = NULL; + char *mnc = NULL; + char *network_name = NULL; + bool roaming_status; + telephony_network_rssi_e rssi = 0; + telephony_network_service_state_e service_state = 0; + telephony_network_type_e network_type = 0; + + /* Call value */ + telephony_call_state_e call_state = 0; + + /* Modem value */ + char *imei = NULL; + + /* Initialize handle */ + ret_value = telephony_init(&handle_list); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("Initialize failed!!!"); + return 0; + } + + LOGI("handle count: [%d]", handle_list.count); + + /* SIM API */ + ret_value = telephony_sim_get_operator(handle_list.handle[0], &operator); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_sim_get_operator() failed!!! [%d]", ret_value); + } else { + LOGI("Operator is [%s]", operator); + free(operator); + } + + ret_value = telephony_sim_get_icc_id(handle_list.handle[0], &icc_id); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_sim_get_icc_id() failed!!! [%d]", ret_value); + } else { + LOGI("ICC-ID is [%s]", icc_id); + free(icc_id); + } + + ret_value = telephony_sim_get_msin(handle_list.handle[0], &msin); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_sim_get_msin() failed!!! [%d]", ret_value); + } else { + LOGI("MSIN is [%s]", msin); + free(msin); + } + + ret_value = telephony_sim_get_spn(handle_list.handle[0], &spn); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_sim_get_spn() failed!!! [%d]", ret_value); + } else { + LOGI("SPN is [%s]", spn); + free(spn); + } + + ret_value = telephony_sim_get_state(handle_list.handle[0], &sim_state); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_sim_get_state() failed!!! [%d]", ret_value); + } else { + LOGI("SIM state is [%s]", _mapping_sim_state(sim_state)); + } + + ret_value = telephony_sim_get_subscriber_number(handle_list.handle[0], &subscriber_number); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_sim_get_subscriber_number() failed!!! [%d]", ret_value); + } else { + LOGI("Subscriber number is [%s]", subscriber_number); + free(subscriber_number); + } + + /* Network API */ + ret_value = telephony_network_get_cell_id(handle_list.handle[0], &cell_id); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_network_get_cell_id() failed!!! [%d]", ret_value); + } else { + LOGI("Cell ID is [%d]", cell_id); + } + + ret_value = telephony_network_get_lac(handle_list.handle[0], &lac); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_network_get_lac() failed!!! [%d]", ret_value); + } else { + LOGI("Location Area Code is [%d]", lac); + } + + ret_value = telephony_network_get_mcc(handle_list.handle[0], &mcc); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_network_get_mcc() failed!!! [%d]", ret_value); + } else { + LOGI("Mobile Country Code is [%s]", mcc); + free(mcc); + } + + ret_value = telephony_network_get_mnc(handle_list.handle[0], &mnc); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_network_get_mnc() failed!!! [%d]", ret_value); + } else { + LOGI("Mobile Network Code is [%s]", mnc); + free(mnc); + } + + ret_value = telephony_network_get_network_name(handle_list.handle[0], &network_name); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_network_get_network_name() failed!!! [%d]", ret_value); + } else { + LOGI("Network name is [%s]", network_name); + free(network_name); + } + + ret_value = telephony_network_get_roaming_status(handle_list.handle[0], &roaming_status); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_network_get_roaming_status() failed!!! [%d]", ret_value); + } else { + LOGI("Network Roaming: [%s]", roaming_status ? "ON" : "OFF"); + } + + ret_value = telephony_network_get_rssi(handle_list.handle[0], &rssi); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_network_get_rssi() failed!!! [%d]", ret_value); + } else { + LOGI("Received Signal Strength Indicator is [%d]", rssi); + } + + ret_value = telephony_network_get_service_state(handle_list.handle[0], &service_state); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_network_get_service_state() failed!!! [%d]", ret_value); + } else { + LOGI("Network service state is [%s]", _mapping_service_state(service_state)); + } + + ret_value = telephony_network_get_type(handle_list.handle[0], &network_type); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_network_get_type() failed!!! [%d]", ret_value); + } else { + LOGI("Network type is [%s]", _mapping_network_type(network_type)); + } + + /* Call API */ + ret_value = telephony_call_get_voice_call_state(handle_list.handle[0], &call_state); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_call_get_voice_call_state() failed!!! [%d]", ret_value); + } else { + LOGI("Voice Call state is [%s]", _mapping_call_state(call_state)); + } + + ret_value = telephony_call_get_video_call_state(handle_list.handle[0], &call_state); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_call_get_video_call_state() failed!!! [%d]", ret_value); + } else { + LOGI("Video Call state is [%s]", _mapping_call_state(call_state)); + } + + /* Modem API */ + ret_value = telephony_modem_get_imei(handle_list.handle[0], &imei); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_modem_get_imei() failed!!! [%d]", ret_value); + } else { + LOGI("IMEI is [%s]", imei); + free(imei); + } + + /* set_noti_cb */ + ret_value = telephony_set_noti_cb(handle_list.handle[0], TELEPHONY_NOTI_SIM_STATUS, sim_noti_cb, NULL); + if (ret_value != TELEPHONY_ERROR_NONE) + LOGE("Set noti failed!!!"); + + for (i = 0; i < 4; i++) { + ret_value = telephony_set_noti_cb(handle_list.handle[0], network_noti_tbl[i], network_noti_cb, NULL); + if (ret_value != TELEPHONY_ERROR_NONE) + LOGE("Set noti failed!!!"); + } + + for (i = 0; i < 2; i++) { + ret_value = telephony_set_noti_cb(handle_list.handle[0], call_noti_tbl[i], call_noti_cb, NULL); + if (ret_value != TELEPHONY_ERROR_NONE) + LOGE("Set noti failed!!!"); + } + + LOGI("If telephony status is changed, then callback function will be called"); + event_loop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(event_loop); + + ret_value = telephony_unset_noti_cb(handle_list.handle[0], TELEPHONY_NOTI_SIM_STATUS); + if (ret_value != TELEPHONY_ERROR_NONE) + LOGE("Unset noti failed!!!"); + + for (i = 0; i < 4; i++) { + ret_value = telephony_unset_noti_cb(handle_list.handle[0], network_noti_tbl[i]); + if (ret_value != TELEPHONY_ERROR_NONE) + LOGE("Unset noti failed!!!"); + } + + for (i = 0; i < 2; i++) { + ret_value = telephony_unset_noti_cb(handle_list.handle[0], call_noti_tbl[i]); + if (ret_value != TELEPHONY_ERROR_NONE) + LOGE("Unset noti failed!!!"); + } + + ret_value = telephony_deinit(&handle_list); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("Deinitialize failed!!!"); + } + + return 0; +} -- 2.7.4 From fec85e75e071965a2a1acb677e4495704c8ed2db Mon Sep 17 00:00:00 2001 From: "jk7744.park" Date: Sat, 24 Oct 2015 16:27:12 +0900 Subject: [PATCH 3/3] tizen 2.4 release --- CMakeLists.txt | 4 +- doc/telephony_doc.h | 10 +- include/telephony_call.h | 252 +++++++++++++++++++++++++++++- include/telephony_common.h | 106 ++++++++++++- include/telephony_modem.h | 35 +++++ include/telephony_network.h | 141 +++++++++++++++++ include/telephony_private.h | 31 ++++ include/telephony_sim.h | 98 ++++++++++-- packaging/capi-telephony.spec | 5 +- src/telephony_call.c | 235 ++++++++++++++++++++++++++-- src/telephony_common.c | 177 +++++++++++++++++---- src/telephony_modem.c | 59 +++++-- src/telephony_network.c | 196 ++++++++++++++++++++--- src/telephony_sim.c | 95 ++++++++++-- test/test_all_api.c | 352 ++++++++++++++++++++++++++++++++++++------ 15 files changed, 1624 insertions(+), 172 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c3bbf1e..9fcdced 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ SET(version "0.0.1") SET(maintainer "Wootak Jung") SET(description "Telephony Core API") SET(service "telephony") -SET(dependents "dlog tapi glib-2.0 capi-base-common capi-system-info") +SET(dependents "dlog tapi glib-2.0 capi-base-common openssl capi-system-info") SET(pc_dependents "capi-base-common tapi") SET(Services @@ -59,7 +59,7 @@ FOREACH(flag ${${fw_name}_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) -SET(ADDITIONAL_CFLAGS "-Wdeclaration-after-statement -Wmissing-declarations -Wredundant-decls -Wcast-align -Wno-array-bounds -Wno-empty-body -Wno-ignored-qualifiers -Wshadow -Wwrite-strings -Wswitch-default -Wno-unused-but-set-parameter -Wno-unused-but-set-variable -Wcast-qual") +SET(ADDITIONAL_CFLAGS "-Wdeclaration-after-statement -Wmissing-declarations -Wredundant-decls -Wcast-align -Wno-array-bounds -Wno-empty-body -Wno-ignored-qualifiers -Wshadow -Wwrite-strings -Wswitch-default -Wno-unused-but-set-parameter -Wno-unused-but-set-variable") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ADDITIONAL_CFLAGS}") SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") diff --git a/doc/telephony_doc.h b/doc/telephony_doc.h index 10fc50c..e46da99 100644 --- a/doc/telephony_doc.h +++ b/doc/telephony_doc.h @@ -37,7 +37,7 @@ * * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n * - * More details on featuring your application can be found from Feature List. + * More details on featuring your application can be found from Feature List. */ /** @@ -61,7 +61,7 @@ * * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n * - * More details on featuring your application can be found from Feature List. + * More details on featuring your application can be found from Feature List. */ /** @@ -85,7 +85,7 @@ * * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n * - * More details on featuring your application can be found from Feature List. + * More details on featuring your application can be found from Feature List. */ /** @@ -108,7 +108,7 @@ * * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n * - * More details on featuring your application can be found from Feature List. + * More details on featuring your application can be found from Feature List. */ /** @@ -131,7 +131,7 @@ * * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n * - * More details on featuring your application can be found from Feature List. + * More details on featuring your application can be found from Feature List. */ #endif /* __TIZEN_TELEPHONY_INFORMATION_DOC_H__ */ diff --git a/include/telephony_call.h b/include/telephony_call.h index a15de1b..1264c0d 100644 --- a/include/telephony_call.h +++ b/include/telephony_call.h @@ -34,17 +34,70 @@ extern "C" { */ /** + * @brief The call handle. + * @since_tizen 2.4 + */ +typedef struct telephony_call_info_s *telephony_call_h; + +/** + * @deprecated Deprecated Since 2.4. Use #telephony_call_status_e instead. + * * @brief Enumeration for the call state. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ -typedef enum -{ - TELEPHONY_CALL_STATE_IDLE, /**< There exists no calls. */ - TELEPHONY_CALL_STATE_CONNECTING, /**< There exists at least one call that is dialing, alerting or incoming */ - TELEPHONY_CALL_STATE_CONNECTED, /**< There exist active or held calls, and no calls are dialing, alerting or incoming*/ +typedef enum { + TELEPHONY_CALL_STATE_IDLE, /**< There exists no calls. */ + TELEPHONY_CALL_STATE_CONNECTING, /**< There exists at least one call that is dialing, alerting or incoming */ + TELEPHONY_CALL_STATE_CONNECTED, /**< There exist active or held calls, and no calls are dialing, alerting or incoming */ } telephony_call_state_e; /** + * @brief Enumeration for the call status. + * @since_tizen 2.4 + */ +typedef enum { + TELEPHONY_CALL_STATUS_IDLE, /**< Idle status */ + TELEPHONY_CALL_STATUS_ACTIVE, /**< Active status */ + TELEPHONY_CALL_STATUS_HELD, /**< Held status */ + TELEPHONY_CALL_STATUS_DIALING, /**< Dialing status */ + TELEPHONY_CALL_STATUS_ALERTING, /**< Alerting status */ + TELEPHONY_CALL_STATUS_INCOMING, /**< Incoming status */ +} telephony_call_status_e; + +/** + * @brief Enumeration for the preferred voice call subscription. + * @since_tizen 2.4 + */ +typedef enum { + TELEPHONY_CALL_PREFERRED_VOICE_SUBS_UNKNOWN = -1, /**< Unknown status */ + TELEPHONY_CALL_PREFERRED_VOICE_SUBS_CURRENT_NETWORK = 0, /**< Current network */ + TELEPHONY_CALL_PREFERRED_VOICE_SUBS_ASK_ALWAYS, /**< ASK Always */ + TELEPHONY_CALL_PREFERRED_VOICE_SUBS_SIM1, /**< SIM 1 */ + TELEPHONY_CALL_PREFERRED_VOICE_SUBS_SIM2, /**< SIM 2 */ +} telephony_call_preferred_voice_subs_e; + +/** + * @brief Enumeration for the call type. + * @since_tizen 2.4 + */ +typedef enum { + TELEPHONY_CALL_TYPE_VOICE, /**< Voice call */ + TELEPHONY_CALL_TYPE_VIDEO, /**< Video call */ + TELEPHONY_CALL_TYPE_E911, /**< Emergency call */ +} telephony_call_type_e; + +/** + * @brief Enumeration for the call direction. + * @since_tizen 2.4 + */ +typedef enum { + TELEPHONY_CALL_DIRECTION_MO, /**< MO(Mobile Originated) call */ + TELEPHONY_CALL_DIRECTION_MT, /**< MT(Mobile Terminated) call */ +} telephony_call_direction_e; + +/** + * @deprecated Deprecated Since 2.4. Use #telephony_call_get_status instead. + * * @brief Gets the voice call state of the telephony service. * @details Determines if the voice call is connecting, connected, or idle. * @@ -72,6 +125,8 @@ typedef enum int telephony_call_get_voice_call_state(telephony_h handle, telephony_call_state_e *call_state); /** + * @deprecated Deprecated Since 2.4. Use #telephony_call_get_status instead. + * * @brief Gets the video call state of the telephony service. * @details Determines if the video call is connecting, connected, or idle. * @@ -99,6 +154,193 @@ int telephony_call_get_voice_call_state(telephony_h handle, telephony_call_state int telephony_call_get_video_call_state(telephony_h handle, telephony_call_state_e *call_state); /** + * @brief Gets the current value for the preferred voice call subscription. + * + * @since_tizen 2.4 + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * + * @param[in] handle The handle from telephony_init() + * @param[out] call_sub The currently set preferred call subscription value. (telephony_call_preferred_voice_subs_e) + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + */ +int telephony_call_get_preferred_voice_subscription(telephony_h handle, telephony_call_preferred_voice_subs_e *call_sub); + +/** + * @brief Gets the list of the current call. + * + * @since_tizen 2.4 + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @remarks You must release @c call_list using telephony_call_release_call_list(). + * + * @param[in] handle The handle from telephony_init() + * @param[out] count Count of the existing calls. + * @param[out] call_list List of call information for existing calls. + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + */ +int telephony_call_get_call_list(telephony_h handle, + unsigned int *count, telephony_call_h **call_list); + +/** + * @brief Releases the list allocated from #telephony_call_get_call_list() + * + * @since_tizen 2.4 + * + * @param[in] count The count of the calls from #telephony_call_get_call_list() + * @param[in] call_list The handle from #telephony_call_get_call_list() + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * + * @pre The call list should be validated from #telephony_call_get_call_list() + */ +int telephony_call_release_call_list(unsigned int count, telephony_call_h **call_list); + +/** + * @brief Gets the call handle ID. + * + * @since_tizen 2.4 + * + * @param[in] call_handle The handle from #telephony_call_get_call_list() + * @param[out] handle_id The id of the call handle + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * + * @pre The call handle should be obtained from #telephony_call_get_call_list() + * @post The call list should be released by using #telephony_call_release_call_list() + */ +int telephony_call_get_handle_id(telephony_call_h call_handle, unsigned int *handle_id); + +/** + * @brief Gets the call number. + * + * @since_tizen 2.4 + * + * @remarks You must release @c number using free(). + * + * @param[in] call_handle The handle from #telephony_call_get_call_list() + * @param[out] number The number of the call + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * + * @pre The call handle should be obtained from #telephony_call_get_call_list() + * @post The call list should be released by using #telephony_call_release_call_list() + */ +int telephony_call_get_number(telephony_call_h call_handle, char **number); + +/** + * @brief Gets the call type. + * + * @since_tizen 2.4 + * + * @param[in] call_handle The handle from #telephony_call_get_call_list() + * @param[out] type The type of the call (#telephony_call_type_e) + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * + * @pre The call handle should be obtained from #telephony_call_get_call_list() + * @post The call list should be released by using #telephony_call_release_call_list() + */ +int telephony_call_get_type(telephony_call_h call_handle, telephony_call_type_e *type); + +/** + * @brief Gets the call status. + * + * @since_tizen 2.4 + * + * @param[in] call_handle The handle from #telephony_call_get_call_list() + * @param[out] status The status of the call (#telephony_call_status_e) + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * + * @pre The call handle should be obtained from #telephony_call_get_call_list() + * @post The call list should be released by using #telephony_call_release_call_list() + */ +int telephony_call_get_status(telephony_call_h call_handle, telephony_call_status_e *status); + +/** + * @brief Gets whether the call is MO(Mobile Originated) call or MT(Mobile Terminated). + * @since_tizen 2.4 + * + * @param[in] call_handle The handle from #telephony_call_get_call_list() + * @param[out] direction The direction of the call (#telephony_call_direction_e) + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * + * @pre The call handle should be obtained from #telephony_call_get_call_list() + * @post The call list should be released by using #telephony_call_release_call_list() + */ +int telephony_call_get_direction(telephony_call_h call_handle, telephony_call_direction_e *direction); + +/** + * @brief Gets whether the call is conference call or not. + * @since_tizen 2.4 + * + * @param[in] call_handle The handle from #telephony_call_get_call_list() + * @param[out] conference_status The value whether the call is conference call or not. + * (true: Conference call, false: Single call) + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * + * @pre The call handle should be obtained from #telephony_call_get_call_list() + * @post The call list should be released by using #telephony_call_release_call_list() + */ +int telephony_call_get_conference_status(telephony_call_h call_handle, bool *conference_status); + +/** * @} */ diff --git a/include/telephony_common.h b/include/telephony_common.h index 42f2e40..2693509 100644 --- a/include/telephony_common.h +++ b/include/telephony_common.h @@ -74,15 +74,31 @@ typedef enum { * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ typedef enum { - TELEPHONY_NOTI_SIM_STATUS = 0x10, /**< Notification to be invoked when the SIM card state changes */ + TELEPHONY_NOTI_SIM_STATUS = 0x10, /**< Notification to be invoked when the SIM card state changes, '#telephony_sim_state_e' will be delivered in notification data */ - TELEPHONY_NOTI_NETWORK_SERVICE_STATE = 0x20, /**< Notification to be invoked when the network service state changes */ - TELEPHONY_NOTI_NETWORK_CELLID, /**< Notification to be invoked when the cell ID changes */ - TELEPHONY_NOTI_NETWORK_ROAMING_STATUS, /**< Notification to be invoked when the roaming status changes */ - TELEPHONY_NOTI_NETWORK_SIGNALSTRENGTH_LEVEL, /**< Notification to be invoked when the signal strength changes */ + TELEPHONY_NOTI_NETWORK_SERVICE_STATE = 0x20, /**< Notification to be invoked when the network service state changes, '#telephony_network_service_state_e' will be delivered in notification data */ + TELEPHONY_NOTI_NETWORK_CELLID, /**< Notification to be invoked when the cell ID changes, 'cell_id(int)' will be delivered in notification data */ + TELEPHONY_NOTI_NETWORK_ROAMING_STATUS, /**< Notification to be invoked when the roaming status changes, 'roaming_status(bool)' will be delivered in notification data */ + TELEPHONY_NOTI_NETWORK_SIGNALSTRENGTH_LEVEL, /**< Notification to be invoked when the signal strength changes, '#telephony_network_rssi_e' will be delivered in notification data */ + TELEPHONY_NOTI_NETWORK_NETWORK_NAME, /**< Notification to be invoked when the network name changes, 'network_name(char *)' wil be delivered in notification data (@b Since: 2.4) */ + TELEPHONY_NOTI_NETWORK_PS_TYPE, /**< Notification to be invoked when the ps type changes, '#telephony_network_ps_type_e' will be delivered in notification data (@b Since: 2.4) */ + TELEPHONY_NOTI_NETWORK_DEFAULT_DATA_SUBSCRIPTION, /**< Notification to be invoked when the default data subscription changes, '#telephony_network_default_data_subs_e' wil be delivered in notification data (@b Since: 2.4) */ + TELEPHONY_NOTI_NETWORK_DEFAULT_SUBSCRIPTION, /**< Notification to be invoked when the default subscription changes, '#telephony_network_default_subs_e' will be delivered in notification data (@b Since: 2.4) */ - TELEPHONY_NOTI_VOICE_CALL_STATE = 0x30, /**< Notification to be invoked when the voice call state changes */ - TELEPHONY_NOTI_VIDEO_CALL_STATE /**< Notification to be invoked when the video call state changes */ + TELEPHONY_NOTI_VOICE_CALL_STATE = 0x30, /**< Notification to be invoked when the voice call state changes, '#telephony_call_state_e' will be delivered in notification data (Deprecated Since 2.4. Use #TELEPHONY_NOTI_VOICE_CALL_STATUS_XXX instead.) */ + TELEPHONY_NOTI_VIDEO_CALL_STATE, /**< Notification to be invoked when the video call state changes, '#telephony_call_state_e' will be delivered in notification data (Deprecated Since 2.4. Use #TELEPHONY_NOTI_VIDEO_CALL_STATUS_XXX instead.) */ + TELEPHONY_NOTI_VOICE_CALL_STATUS_IDLE, /**< Notification to be invoked when a voice call is in idle status, 'handle_id(unsigned int)' will be delivered in notification data (@b Since: 2.4) */ + TELEPHONY_NOTI_VOICE_CALL_STATUS_ACTIVE, /**< Notification to be invoked when a voice call is in active status, 'handle_id(unsigned int)' will be delivered in notification data (@b Since: 2.4) */ + TELEPHONY_NOTI_VOICE_CALL_STATUS_HELD, /**< Notification to be invoked when a voice call is in held status, 'handle_id(unsigned int)' will be delivered in notification data (@b Since: 2.4) */ + TELEPHONY_NOTI_VOICE_CALL_STATUS_DIALING, /**< Notification to be invoked when a voice call is in dialing status, 'handle_id(unsigned int)' will be delivered in notification data (@b Since: 2.4) */ + TELEPHONY_NOTI_VOICE_CALL_STATUS_ALERTING, /**< Notification to be invoked when a voice call is in alerting status, 'handle_id(unsigned int)' will be delivered in notification data (@b Since: 2.4) */ + TELEPHONY_NOTI_VOICE_CALL_STATUS_INCOMING, /**< Notification to be invoked when a voice call is in incoming status, 'handle_id(unsigned int)' will be delivered in notification data (@b Since: 2.4) */ + TELEPHONY_NOTI_VIDEO_CALL_STATUS_IDLE, /**< Notification to be invoked when a video call is in idle status, 'handle_id(unsigned int)' will be delivered in notification data (@b Since: 2.4) */ + TELEPHONY_NOTI_VIDEO_CALL_STATUS_ACTIVE, /**< Notification to be invoked when a video call is in active status, 'handle_id(unsigned int)' will be delivered in notification data (@b Since: 2.4) */ + TELEPHONY_NOTI_VIDEO_CALL_STATUS_DIALING, /**< Notification to be invoked when a video call is in dialing status, 'handle_id(unsigned int)' will be delivered in notification data (@b Since: 2.4) */ + TELEPHONY_NOTI_VIDEO_CALL_STATUS_ALERTING, /**< Notification to be invoked when a video call is in alerting status, 'handle_id(unsigned int)' will be delivered in notification data (@b Since: 2.4) */ + TELEPHONY_NOTI_VIDEO_CALL_STATUS_INCOMING, /**< Notification to be invoked when a video call is in incoming status, 'handle_id(unsigned int)' will be delivered in notification data (@b Since: 2.4) */ + TELEPHONY_NOTI_CALL_PREFERRED_VOICE_SUBSCRIPTION /**< Notification to be invoked when the preferred voice subscription changes, '#telephony_call_preferred_voice_subs_e' will be delivered in notification data (@b Since: 2.4) */ } telephony_noti_e; /** @@ -185,6 +201,82 @@ int telephony_init(telephony_handle_list_s *list); int telephony_deinit(telephony_handle_list_s *list); /** + * @brief Enumeration for the telephony state. + * @since_tizen 2.4 + */ +typedef enum { + TELEPHONY_STATE_NOT_READY, /**< Telephony state is not ready */ + TELEPHONY_STATE_READY, /**< Telephony state is ready */ +} telephony_state_e; + +/** + * @brief Called for the telephony state changes. + * @since_tizen 2.4 + */ +typedef void (*telephony_state_changed_cb)(telephony_state_e state, void *user_data); + +/** + * @brief Acquires the telephony state value + * + * @since_tizen 2.4 + * + * @param[out] state The state value of telephony. + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + * + * @see telephony_set_state_changed_cb() + * @see telephony_unset_state_changed_cb() + */ +int telephony_get_state(telephony_state_e *state); + +/** + * @brief Sets a callback function to be invoked when the telephony state changes. + * + * @since_tizen 2.4 + * + * @param[in] callback The callback to be invoked when the telephony state changes + * @param[in] user_data The user data passed to the callback function + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + * + * @post telephony_state_changed_cb() will be invoked. + * + * @see telephony_unset_state_changed_cb() + */ +int telephony_set_state_changed_cb(telephony_state_changed_cb callback, void *user_data); + +/** + * @brief Unsets a telephony state callback function. + * + * @since_tizen 2.4 + * + * @param[in] callback The callback to unset when the telephony state changes + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + * + * @see telephony_set_state_changed_cb() + */ +int telephony_unset_state_changed_cb(telephony_state_changed_cb callback); + +/** * @} */ diff --git a/include/telephony_modem.h b/include/telephony_modem.h index c0444dd..b8f77e1 100644 --- a/include/telephony_modem.h +++ b/include/telephony_modem.h @@ -34,6 +34,19 @@ extern "C" { */ /** + * @brief Enumeration for Modem Power Status. + * @since_tizen 2.4 + */ +typedef enum +{ + TELEPHONY_MODEM_POWER_STATUS_UNKNOWN = -1, /**< Unknown*/ + TELEPHONY_MODEM_POWER_STATUS_ON, /**< Modem power ON */ + TELEPHONY_MODEM_POWER_STATUS_OFF, /**< Modem power OFF */ + TELEPHONY_MODEM_POWER_STATUS_RESET, /**< Modem power RESET */ + TELEPHONY_MODEM_POWER_STATUS_LOW, /**< Modem power LOW */ +} telephony_modem_power_status_e; + +/** * @brief Gets the IMEI (International Mobile Station Equipment Identity) of a mobile phone. * @details The IMEI number is used by a GSM network to identify valid devices * and therefore can be used for stopping a stolen phone from accessing that network. @@ -59,6 +72,28 @@ extern "C" { int telephony_modem_get_imei(telephony_h handle, char **imei); /** + * @brief Gets the power status of the modem + * + * @since_tizen 2.4 + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @param[in] handle The handle from telephony_init() + * @param[out] status The Modem power status (0=on,1=off,2=reset,3=low) + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + */ +int telephony_modem_get_power_status(telephony_h handle, + telephony_modem_power_status_e *status); + +/** * @} */ diff --git a/include/telephony_network.h b/include/telephony_network.h index 1d259f9..dfff3c4 100644 --- a/include/telephony_network.h +++ b/include/telephony_network.h @@ -66,6 +66,18 @@ typedef enum TELEPHONY_NETWORK_TYPE_LTE, /**< LTE network type */ } telephony_network_type_e; +/** + * @brief Enumeration for PS Type. + * @since_tizen 2.4 + */ +typedef enum +{ + TELEPHONY_NETWORK_PS_TYPE_UNKNOWN, /**< Unknown */ + TELEPHONY_NETWORK_PS_TYPE_HSDPA, /**< HSDPA ps type */ + TELEPHONY_NETWORK_PS_TYPE_HSUPA, /**< HSUPA ps type */ + TELEPHONY_NETWORK_PS_TYPE_HSPA, /**< HSPA ps type */ + TELEPHONY_NETWORK_PS_TYPE_HSPAP, /**< HSPAP ps type */ +} telephony_network_ps_type_e; /** * @brief Enumeration for Network Service State. @@ -79,6 +91,38 @@ typedef enum } telephony_network_service_state_e; /** + * @brief Enumeration for Network Name Priority. + * @since_tizen 2.4 + */ +typedef enum +{ + TELEPHONY_NETWORK_NAME_OPTION_UNKNOWN, /**< Unknown */ + TELEPHONY_NETWORK_NAME_OPTION_SPN, /**< Network name displayed by SPN */ + TELEPHONY_NETWORK_NAME_OPTION_NETWORK, /**< Network name displayed by Network */ + TELEPHONY_NETWORK_NAME_OPTION_ANY, /**< Network name displayed by SPN or Network */ +} telephony_network_name_option_e; + +/** + * @brief Enumeration for the possible 'default' Data Subscriptions for Packet Switched(PS). + * @since_tizen 2.4 + */ +typedef enum { + TELEPHONY_NETWORK_DEFAULT_DATA_SUBS_UNKNOWN = -1, /**< Unknown status */ + TELEPHONY_NETWORK_DEFAULT_DATA_SUBS_SIM1 = 0, /**< SIM 1 */ + TELEPHONY_NETWORK_DEFAULT_DATA_SUBS_SIM2 /**< SIM 2 */ +} telephony_network_default_data_subs_e; + +/** + * @brief Enumeration defines possible 'default' Subscriptions for Circuit Switched(CS). + * @since_tizen 2.4 + */ +typedef enum { + TELEPHONY_NETWORK_DEFAULT_SUBS_UNKNOWN = -1, /**< Unknown status **/ + TELEPHONY_NETWORK_DEFAULT_SUBS_SIM1 = 0, /**< SIM 1 network **/ + TELEPHONY_NETWORK_DEFAULT_SUBS_SIM2 /**< SIM 2 network **/ +} telephony_network_default_subs_e; + +/** * @brief Gets the LAC (Location Area Code) of the current network. * * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif @@ -290,6 +334,57 @@ int telephony_network_get_type(telephony_h handle, telephony_network_type_e *network_type); /** + * @brief Gets the packet service type of the current registered network. + * + * @since_tizen 2.4 + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @param[in] handle The handle from telephony_init() + * @param[out] ps_type The type of packet service + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + * + * @pre The Network service state must be #TELEPHONY_NETWORK_SERVICE_STATE_IN_SERVICE. + * + * @see telephony_network_get_service_state() + */ +int telephony_network_get_ps_type(telephony_h handle, telephony_network_ps_type_e *ps_type); + +/** + * @brief Gets the network name option of the current registered network. + * + * @since_tizen 2.4 + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @param[in] handle The handle from telephony_init() + * @param[out] network_name_option The network name display option + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + * + * @pre The Network service state must be #TELEPHONY_NETWORK_SERVICE_STATE_IN_SERVICE. + * + * @see telephony_network_get_service_state() + */ +int telephony_network_get_network_name_option(telephony_h handle, + telephony_network_name_option_e *network_name_option); + +/** * @brief Gets the current network state of the telephony service. * * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif @@ -314,6 +409,52 @@ int telephony_network_get_service_state(telephony_h handle, telephony_network_service_state_e *network_service_state); /** + * @brief Gets the current default subscription for data service (Packet Switched). + * + * @since_tizen 2.4 + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * + * @param[in] handle The handle from telephony_init() + * @param[out] default_sub The current default data subscription + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + */ +int telephony_network_get_default_data_subscription(telephony_h handle, + telephony_network_default_data_subs_e *default_sub); + +/** + * @brief Gets the current default subscription for voice service (Circuit Switched). + * + * @since_tizen 2.4 + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * + * @param[in] handle The handle from telephony_init() + * @param[out] default_sub The current default voice subscription + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + */ +int telephony_network_get_default_subscription(telephony_h handle, + telephony_network_default_subs_e *default_sub); + +/** * @} */ diff --git a/include/telephony_private.h b/include/telephony_private.h index 9ff0c7c..63df3eb 100644 --- a/include/telephony_private.h +++ b/include/telephony_private.h @@ -21,9 +21,21 @@ #include #include #include "telephony_common.h" +#include "telephony_call.h" #define TELEPHONY_FEATURE "http://tizen.org/feature/network.telephony" +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "CAPI_TELEPHONY" + +#define CHECK_INPUT_PARAMETER(arg) \ + if (arg == NULL) { \ + LOGE("INVALID_PARAMETER"); \ + return TELEPHONY_ERROR_INVALID_PARAMETER; \ + } + #define CHECK_TELEPHONY_SUPPORTED(feature_name) { \ bool telephony_supported = FALSE; \ if (!system_info_get_platform_bool(feature_name, &telephony_supported)) { \ @@ -37,6 +49,12 @@ } \ } +/** + * @brief Definition for the max length of call number + * @since_tizen 2.4 + */ +#define TELEPHONY_CALL_NUMBER_LEN_MAX 82 + typedef struct { GSList *evt_list; struct tapi_handle *tapi_h; @@ -58,4 +76,17 @@ struct tapi_handle { guint prop_callback_evt_id; }; +/** + * @brief The structure type for the call information. + * @since_tizen 2.4 + */ +typedef struct { + unsigned int id; /**< The handle of the call */ + char number[TELEPHONY_CALL_NUMBER_LEN_MAX + 1]; /**< Calling number */ + telephony_call_type_e type; /**< Type of call (voice, video, emergency) */ + telephony_call_status_e status; /**< Call Status */ + telephony_call_direction_e direction; /**< Call direction (MO, MT) */ + bool conference_status; /**< true: Conference call, false: Single call */ +} telephony_call_info_s; + #endif /* __CAPI_TELEPHONY_PRIVATE_H__ */ diff --git a/include/telephony_sim.h b/include/telephony_sim.h index d355392..cef6e4b 100644 --- a/include/telephony_sim.h +++ b/include/telephony_sim.h @@ -45,6 +45,19 @@ typedef enum TELEPHONY_SIM_STATE_UNKNOWN, /**< SIM is in transition between states */ } telephony_sim_state_e; + +/** + * @brief Enumeration for the type of SIM card . + * @since_tizen 2.4 + */ +typedef enum { + TELEPHONY_SIM_APP_TYPE_SIM = 0x01, /**< SIM(GSM) Application */ + TELEPHONY_SIM_APP_TYPE_USIM = 0x02, /**< USIM Application */ + TELEPHONY_SIM_APP_TYPE_CSIM = 0x04, /**< CDMA Application */ + TELEPHONY_SIM_APP_TYPE_ISIM = 0x08, /**< ISIM Application */ +} telephony_sim_application_type_e; + + /** * @brief Gets the Integrated Circuit Card IDentification (ICC-ID). * @details The Integrated Circuit Card Identification number internationally identifies SIM cards. @@ -62,10 +75,10 @@ typedef enum * otherwise a negative error value * * @retval #TELEPHONY_ERROR_NONE Successful - * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Out of memory + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported - * @retval #TELEPHONY_ERROR_OPERATION_FAILED Invalid parameter + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed * @retval #TELEPHONY_ERROR_SIM_NOT_AVAILABLE SIM is not available * * @pre The SIM state must be #TELEPHONY_SIM_STATE_AVAILABLE. @@ -91,10 +104,10 @@ int telephony_sim_get_icc_id(telephony_h handle, char **icc_id); * otherwise a negative error value * * @retval #TELEPHONY_ERROR_NONE Successful - * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Out of memory + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported - * @retval #TELEPHONY_ERROR_OPERATION_FAILED Invalid parameter + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed * @retval #TELEPHONY_ERROR_SIM_NOT_AVAILABLE SIM is not available * * @pre The SIM state must be #TELEPHONY_SIM_STATE_AVAILABLE. @@ -120,10 +133,10 @@ int telephony_sim_get_operator(telephony_h handle, char **sim_operator); * otherwise a negative error value * * @retval #TELEPHONY_ERROR_NONE Successful - * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Out of memory + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported - * @retval #TELEPHONY_ERROR_OPERATION_FAILED Invalid parameter + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed * @retval #TELEPHONY_ERROR_SIM_NOT_AVAILABLE SIM is not available * * @pre The SIM state must be #TELEPHONY_SIM_STATE_AVAILABLE. @@ -135,7 +148,8 @@ int telephony_sim_get_msin(telephony_h handle, char **msin); /** * @brief Gets the Service Provider Name (SPN) of the SIM card. * @details This function gets Service Provider Name embedded in the SIM card. - * If this value is not stored in SIM card, @c NULL will be returned. + * If this value is not stored in SIM card, + * negative error returned and @c NULL will be stored in @c spn. * * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @privlevel public @@ -150,10 +164,10 @@ int telephony_sim_get_msin(telephony_h handle, char **msin); * otherwise a negative error value * * @retval #TELEPHONY_ERROR_NONE Successful - * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Out of memory + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported - * @retval #TELEPHONY_ERROR_OPERATION_FAILED Invalid parameter + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed * @retval #TELEPHONY_ERROR_SIM_NOT_AVAILABLE SIM is not available * * @pre The SIM state must be #TELEPHONY_SIM_STATE_AVAILABLE. @@ -177,10 +191,10 @@ int telephony_sim_get_spn(telephony_h handle, char **spn); * otherwise a negative error value * * @retval #TELEPHONY_ERROR_NONE Successful - * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Out of memory + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported - * @retval #TELEPHONY_ERROR_OPERATION_FAILED Invalid parameter + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed * @retval #TELEPHONY_ERROR_SIM_NOT_AVAILABLE SIM is not available * * @pre The SIM state must be #TELEPHONY_SIM_STATE_AVAILABLE. @@ -203,18 +217,44 @@ int telephony_sim_is_changed(telephony_h handle, bool *is_changed); * otherwise a negative error value * * @retval #TELEPHONY_ERROR_NONE Successful - * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Out of memory + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported - * @retval #TELEPHONY_ERROR_OPERATION_FAILED Invalid parameter + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed */ int telephony_sim_get_state(telephony_h handle, telephony_sim_state_e *sim_state); /** + * @brief Gets the list of application on UICC. + * + * @since_tizen 2.4 + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @param[in] handle The handle from telephony_init() + * @param[out] app_list The masking value for below values + * #TELEPHONY_SIM_APP_TYPE_SIM 0x01 GSM Application + * #TELEPHONY_SIM_APP_TYPE_USIM 0x02 USIM Application + * #TELEPHONY_SIM_APP_TYPE_CSIM 0x04 CSIM Application + * #TELEPHONY_SIM_APP_TYPE_ISIM 0x08 ISIM Application + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + */ +int telephony_sim_get_application_list(telephony_h handle, unsigned int *app_list); + +/** * @brief Gets the SIM card subscriber number. * @details This function gets subscriber number embedded in the SIM card. * This value contains MSISDN related to the subscriber. - * If this value is not stored in SIM card, @c NULL will be returned. + * If this value is not stored in SIM card, + * negative error returned and @c NULL will be stored in @c subscriber_number. * * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @privlevel public @@ -229,10 +269,10 @@ int telephony_sim_get_state(telephony_h handle, telephony_sim_state_e *sim_state * otherwise a negative error value * * @retval #TELEPHONY_ERROR_NONE Successful - * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Out of memory + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported - * @retval #TELEPHONY_ERROR_OPERATION_FAILED Invalid parameter + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed * @retval #TELEPHONY_ERROR_SIM_NOT_AVAILABLE SIM is not available * * @pre The SIM state must be #TELEPHONY_SIM_STATE_AVAILABLE. @@ -242,6 +282,32 @@ int telephony_sim_get_state(telephony_h handle, telephony_sim_state_e *sim_state int telephony_sim_get_subscriber_number(telephony_h handle, char **subscriber_number); /** + * @brief Gets the Subscriber ID. + * @details This function gets subscriber ID encoded. + * + * @since_tizen 2.4 + * @privlevel public + * @privilege %http://tizen.org/privilege/telephony + * + * @remarks You must release @c subscriber_id using free(). + * + * @param[in] handle The handle from telephony_init() + * @param[out] subscriber_id The subscriber ID + * + * @retval #TELEPHONY_ERROR_NONE Successful + * @retval #TELEPHONY_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TELEPHONY_ERROR_PERMISSION_DENIED Permission denied + * @retval #TELEPHONY_ERROR_NOT_SUPPORTED Not supported + * @retval #TELEPHONY_ERROR_OPERATION_FAILED Operation failed + * @retval #TELEPHONY_ERROR_SIM_NOT_AVAILABLE SIM is not available + * + * @pre The SIM state must be #TELEPHONY_SIM_STATE_AVAILABLE. + * + * @see telephony_sim_get_state() + */ +int telephony_sim_get_subscriber_id(telephony_h handle, char **subscriber_id); + +/** * @} */ diff --git a/packaging/capi-telephony.spec b/packaging/capi-telephony.spec index bd5e6fd..c5cfa9f 100644 --- a/packaging/capi-telephony.spec +++ b/packaging/capi-telephony.spec @@ -1,6 +1,6 @@ Name: capi-telephony Summary: Telephony Core API -Version: 0.1.32 +Version: 0.1.53 Release: 1 Group: System/Libraries License: Apache-2.0 @@ -10,6 +10,7 @@ BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(tapi) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(openssl) BuildRequires: pkgconfig(capi-system-info) Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig @@ -55,5 +56,3 @@ mkdir -p %{buildroot}/usr/share/license %{_includedir}/telephony/telephony_modem.h %{_libdir}/pkgconfig/*.pc %{_libdir}/libcapi-telephony.so - - diff --git a/src/telephony_call.c b/src/telephony_call.c index 7e6ca6e..143aa09 100644 --- a/src/telephony_call.c +++ b/src/telephony_call.c @@ -27,17 +27,6 @@ #include "telephony_call.h" #include "telephony_private.h" -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "CAPI_TELEPHONY" - -#define CHECK_INPUT_PARAMETER(arg) \ - if (arg == NULL) { \ - LOGE("INVALID_PARAMETER"); \ - return TELEPHONY_ERROR_INVALID_PARAMETER; \ - } - static void _mapping_call_state(TelCallStates_t tapi_call_state, telephony_call_state_e *call_state) { switch (tapi_call_state) { @@ -59,6 +48,35 @@ static void _mapping_call_state(TelCallStates_t tapi_call_state, telephony_call_ } } +static void _mapping_call_status(TelCallStates_t tapi_call_state, + telephony_call_status_e *status) +{ + switch (tapi_call_state) { + case TAPI_CALL_STATE_IDLE: + *status = TELEPHONY_CALL_STATUS_IDLE; + break; + case TAPI_CALL_STATE_ACTIVE: + *status = TELEPHONY_CALL_STATUS_ACTIVE; + break; + case TAPI_CALL_STATE_HELD: + *status = TELEPHONY_CALL_STATUS_HELD; + break; + case TAPI_CALL_STATE_DIALING: + *status = TELEPHONY_CALL_STATUS_DIALING; + break; + case TAPI_CALL_STATE_ALERT: + *status = TELEPHONY_CALL_STATUS_ALERTING; + break; + case TAPI_CALL_STATE_INCOMING: + case TAPI_CALL_STATE_WAITING: + *status = TELEPHONY_CALL_STATUS_INCOMING; + break; + default: + LOGE("Not handled call state: [%d]", tapi_call_state); + break; + } +} + static void _voice_call_get_state_cb(TelCallStatus_t *tapi_status, void *user_data) { telephony_call_state_e *call_state = user_data; @@ -80,6 +98,36 @@ static void _video_call_get_state_cb(TelCallStatus_t *tapi_status, void *user_da _mapping_call_state(tapi_status->CallState, call_state); } +static void _get_call_status_cb(TelCallStatus_t *status, void *user_data) +{ + GSList **list = user_data; + telephony_call_info_s *call_info; + + call_info = g_malloc0(sizeof(telephony_call_info_s)); + if (!call_info) + return; + call_info->id = status->CallHandle; + call_info->type = status->CallType; + call_info->direction = status->bMoCall ? TELEPHONY_CALL_DIRECTION_MO : TELEPHONY_CALL_DIRECTION_MT; + call_info->conference_status = status->bConferenceState; + _mapping_call_status(status->CallState, &call_info->status); + strncpy(call_info->number, status->pNumber, TELEPHONY_CALL_NUMBER_LEN_MAX); + + LOGI("id[%d] number[%s] type[%s] status[%s] direction[%s] conference_status[%s]", + call_info->id, call_info->number, + call_info->type == TELEPHONY_CALL_TYPE_VOICE ? "VOICE" : + call_info->type == TELEPHONY_CALL_TYPE_VIDEO ? "VIDEO" : "E911", + call_info->status == TELEPHONY_CALL_STATUS_IDLE ? "IDLE" : + call_info->status == TELEPHONY_CALL_STATUS_ACTIVE ? "ACTVIE" : + call_info->status == TELEPHONY_CALL_STATUS_HELD ? "HELD" : + call_info->status == TELEPHONY_CALL_STATUS_DIALING ? "DIALING" : + call_info->status == TELEPHONY_CALL_STATUS_ALERTING ? "ALERTING" : + call_info->status == TELEPHONY_CALL_STATUS_INCOMING ? "INCOMING" : "UNKNOWN", + call_info->direction == TELEPHONY_CALL_DIRECTION_MO ? "MO" : "MT", + call_info->conference_status ? "TRUE" : "FALSE"); + *list = g_slist_append(*list, call_info); +} + int telephony_call_get_voice_call_state(telephony_h handle, telephony_call_state_e *call_state) { int ret; @@ -133,3 +181,168 @@ int telephony_call_get_video_call_state(telephony_h handle, telephony_call_state return TELEPHONY_ERROR_NONE; } + +int telephony_call_get_preferred_voice_subscription(telephony_h handle, telephony_call_preferred_voice_subs_e *call_sub) +{ + int ret; + TapiHandle *tapi_h; + TelCallPreferredVoiceSubs_t preferred_sub = TAPI_CALL_PREFERRED_VOICE_SUBS_UNKNOWN; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(call_sub); + + ret = tel_get_call_preferred_voice_subscription(tapi_h, &preferred_sub); + if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + return TELEPHONY_ERROR_PERMISSION_DENIED; + } else if (ret != TAPI_API_SUCCESS) { + LOGE("OPERATION_FAILED"); + return TELEPHONY_ERROR_OPERATION_FAILED; + } else { + switch (preferred_sub) { + case TAPI_CALL_PREFERRED_VOICE_SUBS_CURRENT_NETWORK: + *call_sub = TELEPHONY_CALL_PREFERRED_VOICE_SUBS_CURRENT_NETWORK; + break; + case TAPI_CALL_PREFERRED_VOICE_SUBS_ASK_ALWAYS: + *call_sub = TELEPHONY_CALL_PREFERRED_VOICE_SUBS_ASK_ALWAYS; + break; + case TAPI_CALL_PREFERRED_VOICE_SUBS_SIM1: + *call_sub = TELEPHONY_CALL_PREFERRED_VOICE_SUBS_SIM1; + break; + case TAPI_CALL_PREFERRED_VOICE_SUBS_SIM2: + *call_sub = TELEPHONY_CALL_PREFERRED_VOICE_SUBS_SIM2; + break; + case TAPI_CALL_PREFERRED_VOICE_SUBS_UNKNOWN: + default: + *call_sub = TELEPHONY_CALL_PREFERRED_VOICE_SUBS_UNKNOWN; + break; + } + } + return TELEPHONY_ERROR_NONE; +} + +int telephony_call_get_call_list(telephony_h handle, + unsigned int *count, telephony_call_h **call_list) +{ + int ret; + TapiHandle *tapi_h; + GSList *list = NULL, *tmp; + unsigned int call_index = 0; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(call_list); + CHECK_INPUT_PARAMETER(count); + + ret = tel_get_call_status_all(tapi_h, _get_call_status_cb, &list); + if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + return TELEPHONY_ERROR_PERMISSION_DENIED; + } else if (ret != TAPI_API_SUCCESS) { + LOGE("OPERATION_FAILED"); + return TELEPHONY_ERROR_OPERATION_FAILED; + } + + if (g_slist_length(list)) { + *count = g_slist_length(list); + *call_list = g_malloc0(*count * sizeof(telephony_call_h)); + + tmp = list; + while (tmp) { + telephony_call_info_s *call_info = tmp->data; + (*call_list)[call_index] = g_malloc0(sizeof(telephony_call_info_s)); + memcpy((*call_list)[call_index], call_info, sizeof(telephony_call_info_s)); + tmp = g_slist_next(tmp); + call_index++; + } + g_slist_free(list); + } else { + *count = 0; + *call_list = NULL; + } + + return TELEPHONY_ERROR_NONE; +} + +int telephony_call_release_call_list(unsigned int count, telephony_call_h **call_list) +{ + int i; + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(call_list); + + if (count > 0) { + for (i = 0; i < count; i++) + g_free((telephony_call_info_s *)(*call_list)[i]); + g_free(*call_list); + } + + return TELEPHONY_ERROR_NONE; +} + +int telephony_call_get_handle_id(telephony_call_h call_handle, unsigned int *handle_id) +{ + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(call_handle); + CHECK_INPUT_PARAMETER(handle_id); + + *handle_id = ((telephony_call_info_s *)call_handle)->id; + return TELEPHONY_ERROR_NONE; +} + +int telephony_call_get_number(telephony_call_h call_handle, char **number) +{ + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(call_handle); + CHECK_INPUT_PARAMETER(number); + + *number = g_strdup(((telephony_call_info_s *)call_handle)->number); + return TELEPHONY_ERROR_NONE; +} + +int telephony_call_get_type(telephony_call_h call_handle, + telephony_call_type_e *type) +{ + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(call_handle); + CHECK_INPUT_PARAMETER(type); + + *type = ((telephony_call_info_s *)call_handle)->type; + return TELEPHONY_ERROR_NONE; +} + +int telephony_call_get_status(telephony_call_h call_handle, + telephony_call_status_e *status) +{ + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(call_handle); + CHECK_INPUT_PARAMETER(status); + + *status = ((telephony_call_info_s *)call_handle)->status; + return TELEPHONY_ERROR_NONE; +} + +int telephony_call_get_direction(telephony_call_h call_handle, + telephony_call_direction_e *direction) +{ + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(call_handle); + CHECK_INPUT_PARAMETER(direction); + + *direction = ((telephony_call_info_s *)call_handle)->direction; + return TELEPHONY_ERROR_NONE; +} + +int telephony_call_get_conference_status(telephony_call_h call_handle, bool *conference_status) +{ + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(call_handle); + CHECK_INPUT_PARAMETER(conference_status); + + *conference_status = ((telephony_call_info_s *)call_handle)->conference_status; + return TELEPHONY_ERROR_NONE; +} diff --git a/src/telephony_common.c b/src/telephony_common.c index 856147c..9b30f10 100644 --- a/src/telephony_common.c +++ b/src/telephony_common.c @@ -23,25 +23,29 @@ #include #include +#include #include #include #include -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "CAPI_TELEPHONY" - #define CALLBACK_CALL(data) \ if (evt_cb_data->cb) { \ evt_cb_data->cb(evt_cb_data->handle, \ evt_cb_data->noti_id, data, evt_cb_data->user_data); \ } -#define CHECK_INPUT_PARAMETER(arg) \ - if (arg == NULL) { \ - LOGE("INVALID_PARAMETER"); \ - return TELEPHONY_ERROR_INVALID_PARAMETER; \ +/* Handle deprecated noti_id for backward compatibility */ +#define CALLBACK_CALL_FOR_DEPRECATED_NOTI(evt_cb_data) \ + if (evt_cb_data->noti_id == TELEPHONY_NOTI_VOICE_CALL_STATE) { \ + telephony_call_state_e call_state; \ + telephony_call_get_voice_call_state(evt_cb_data->handle, &call_state); \ + CALLBACK_CALL(&call_state); \ + return; \ + } else if (evt_cb_data->noti_id == TELEPHONY_NOTI_VIDEO_CALL_STATE) { \ + telephony_call_state_e call_state; \ + telephony_call_get_video_call_state(evt_cb_data->handle, &call_state); \ + CALLBACK_CALL(&call_state); \ + return; \ } typedef struct { @@ -81,6 +85,38 @@ static const char *_mapping_noti_id(telephony_noti_e noti_id) return TAPI_PROP_NETWORK_ROAMING_STATUS; case TELEPHONY_NOTI_NETWORK_SIGNALSTRENGTH_LEVEL: return TAPI_PROP_NETWORK_SIGNALSTRENGTH_LEVEL; + case TELEPHONY_NOTI_NETWORK_NETWORK_NAME: + return TAPI_PROP_NETWORK_NETWORK_NAME; + case TELEPHONY_NOTI_CALL_PREFERRED_VOICE_SUBSCRIPTION: + return TAPI_NOTI_CALL_PREFERRED_VOICE_SUBSCRIPTION; + case TELEPHONY_NOTI_NETWORK_PS_TYPE: + return TAPI_PROP_NETWORK_PS_TYPE; + case TELEPHONY_NOTI_NETWORK_DEFAULT_DATA_SUBSCRIPTION: + return TAPI_NOTI_NETWORK_DEFAULT_DATA_SUBSCRIPTION; + case TELEPHONY_NOTI_NETWORK_DEFAULT_SUBSCRIPTION: + return TAPI_NOTI_NETWORK_DEFAULT_SUBSCRIPTION; + case TELEPHONY_NOTI_VOICE_CALL_STATUS_IDLE: + return TAPI_NOTI_VOICE_CALL_STATUS_IDLE; + case TELEPHONY_NOTI_VOICE_CALL_STATUS_ACTIVE: + return TAPI_NOTI_VOICE_CALL_STATUS_ACTIVE; + case TELEPHONY_NOTI_VOICE_CALL_STATUS_HELD: + return TAPI_NOTI_VOICE_CALL_STATUS_HELD; + case TELEPHONY_NOTI_VOICE_CALL_STATUS_DIALING: + return TAPI_NOTI_VOICE_CALL_STATUS_DIALING; + case TELEPHONY_NOTI_VOICE_CALL_STATUS_ALERTING: + return TAPI_NOTI_VOICE_CALL_STATUS_ALERT; + case TELEPHONY_NOTI_VOICE_CALL_STATUS_INCOMING: + return TAPI_NOTI_VOICE_CALL_STATUS_INCOMING; + case TELEPHONY_NOTI_VIDEO_CALL_STATUS_IDLE: + return TAPI_NOTI_VIDEO_CALL_STATUS_IDLE; + case TELEPHONY_NOTI_VIDEO_CALL_STATUS_ACTIVE: + return TAPI_NOTI_VIDEO_CALL_STATUS_ACTIVE; + case TELEPHONY_NOTI_VIDEO_CALL_STATUS_DIALING: + return TAPI_NOTI_VIDEO_CALL_STATUS_DIALING; + case TELEPHONY_NOTI_VIDEO_CALL_STATUS_ALERTING: + return TAPI_NOTI_VIDEO_CALL_STATUS_ALERT; + case TELEPHONY_NOTI_VIDEO_CALL_STATUS_INCOMING: + return TAPI_NOTI_VIDEO_CALL_STATUS_INCOMING; default: return NULL; } @@ -162,24 +198,21 @@ static telephony_error_e __deregister_all_noti(telephony_h handle, telephony_not int count = sizeof(voice_call_state_tbl) / sizeof(char *); for (i = 0; i < count; i++) { ret = tel_deregister_noti_event(tapi_h, voice_call_state_tbl[i]); - if (ret != TAPI_API_SUCCESS) { + if (ret != TAPI_API_SUCCESS) LOGE("Noti [%s] deregistration failed", voice_call_state_tbl[i]); - } } } else if (noti_id == TELEPHONY_NOTI_VIDEO_CALL_STATE) { int count = sizeof(video_call_state_tbl) / sizeof(char *); for (i = 0; i < count; i++) { ret = tel_deregister_noti_event(tapi_h, video_call_state_tbl[i]); - if (ret != TAPI_API_SUCCESS) { + if (ret != TAPI_API_SUCCESS) LOGE("Noti [%s] deregistration failed", video_call_state_tbl[i]); - } } } else { /* Deregister other notifications */ ret = tel_deregister_noti_event(tapi_h, tapi_noti); - if (ret != TAPI_API_SUCCESS) { + if (ret != TAPI_API_SUCCESS) LOGE("Noti [%s] deregistration failed", tapi_noti); - } } return TELEPHONY_ERROR_NONE; @@ -226,23 +259,56 @@ static void on_signal_callback(TapiHandle *tapi_h, const char *evt_id, } else if (!g_strcmp0(evt_id, TAPI_PROP_NETWORK_SIGNALSTRENGTH_LEVEL)) { int rssi = *(int *)data; CALLBACK_CALL(&rssi); + } else if (!g_strcmp0(evt_id, TAPI_PROP_NETWORK_NETWORK_NAME)) { + char *network_name = data; + CALLBACK_CALL(network_name); + } else if (!g_strcmp0(evt_id, TAPI_PROP_NETWORK_PS_TYPE)) { + int ps_type = *(int *)data; + CALLBACK_CALL(&ps_type); + } else if (!g_strcmp0(evt_id, TAPI_NOTI_NETWORK_DEFAULT_DATA_SUBSCRIPTION)) { + int default_data_sub = *(int *)data; + CALLBACK_CALL(&default_data_sub); + } else if (!g_strcmp0(evt_id, TAPI_NOTI_NETWORK_DEFAULT_SUBSCRIPTION)) { + int default_sub = *(int *)data; + CALLBACK_CALL(&default_sub); } else if (!g_strcmp0(evt_id, TAPI_NOTI_VOICE_CALL_STATUS_IDLE) - || !g_strcmp0(evt_id, TAPI_NOTI_VOICE_CALL_STATUS_ACTIVE) - || !g_strcmp0(evt_id, TAPI_NOTI_VOICE_CALL_STATUS_HELD) - || !g_strcmp0(evt_id, TAPI_NOTI_VOICE_CALL_STATUS_DIALING) - || !g_strcmp0(evt_id, TAPI_NOTI_VOICE_CALL_STATUS_ALERT) - || !g_strcmp0(evt_id, TAPI_NOTI_VOICE_CALL_STATUS_INCOMING)) { - telephony_call_state_e call_state; - telephony_call_get_voice_call_state(evt_cb_data->handle, &call_state); - CALLBACK_CALL(&call_state); - } else if (!g_strcmp0(evt_id, TAPI_NOTI_VIDEO_CALL_STATUS_IDLE) - || !g_strcmp0(evt_id, TAPI_NOTI_VIDEO_CALL_STATUS_ACTIVE) - || !g_strcmp0(evt_id, TAPI_NOTI_VIDEO_CALL_STATUS_DIALING) - || !g_strcmp0(evt_id, TAPI_NOTI_VIDEO_CALL_STATUS_ALERT) + || !g_strcmp0(evt_id, TAPI_NOTI_VIDEO_CALL_STATUS_IDLE)) { + TelCallStatusIdleNoti_t *noti = data; + unsigned int handle_id = noti->id; + CALLBACK_CALL_FOR_DEPRECATED_NOTI(evt_cb_data); + CALLBACK_CALL(&handle_id); + } else if (!g_strcmp0(evt_id, TAPI_NOTI_VOICE_CALL_STATUS_ACTIVE) + || !g_strcmp0(evt_id, TAPI_NOTI_VIDEO_CALL_STATUS_ACTIVE)) { + TelCallStatusActiveNoti_t *noti = data; + unsigned int handle_id = noti->id; + CALLBACK_CALL_FOR_DEPRECATED_NOTI(evt_cb_data); + CALLBACK_CALL(&handle_id); + } else if (!g_strcmp0(evt_id, TAPI_NOTI_VOICE_CALL_STATUS_HELD)) { + TelCallStatusHeldNoti_t *noti = data; + unsigned int handle_id = noti->id; + CALLBACK_CALL_FOR_DEPRECATED_NOTI(evt_cb_data); + CALLBACK_CALL(&handle_id); + } else if (!g_strcmp0(evt_id, TAPI_NOTI_VOICE_CALL_STATUS_DIALING) + || !g_strcmp0(evt_id, TAPI_NOTI_VIDEO_CALL_STATUS_DIALING)) { + TelCallStatusDialingNoti_t *noti = data; + unsigned int handle_id = noti->id; + CALLBACK_CALL_FOR_DEPRECATED_NOTI(evt_cb_data); + CALLBACK_CALL(&handle_id); + } else if (!g_strcmp0(evt_id, TAPI_NOTI_VOICE_CALL_STATUS_ALERT) + || !g_strcmp0(evt_id, TAPI_NOTI_VIDEO_CALL_STATUS_ALERT)) { + TelCallStatusAlertNoti_t *noti = data; + unsigned int handle_id = noti->id; + CALLBACK_CALL_FOR_DEPRECATED_NOTI(evt_cb_data); + CALLBACK_CALL(&handle_id); + } else if (!g_strcmp0(evt_id, TAPI_NOTI_VOICE_CALL_STATUS_INCOMING) || !g_strcmp0(evt_id, TAPI_NOTI_VIDEO_CALL_STATUS_INCOMING)) { - telephony_call_state_e call_state; - telephony_call_get_video_call_state(evt_cb_data->handle, &call_state); - CALLBACK_CALL(&call_state); + TelCallIncomingCallInfo_t *noti = data; + unsigned int handle_id = noti->CallHandle; + CALLBACK_CALL_FOR_DEPRECATED_NOTI(evt_cb_data); + CALLBACK_CALL(&handle_id); + } else if (!g_strcmp0(evt_id, TAPI_NOTI_CALL_PREFERRED_VOICE_SUBSCRIPTION)) { + int call_pref_voice_sub = *(int *)data; + CALLBACK_CALL(&call_pref_voice_sub); } else { LOGE("Unhandled noti: [%s]", evt_id); } @@ -358,7 +424,7 @@ int telephony_init(telephony_handle_list_s *list) CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); CHECK_INPUT_PARAMETER(list); -#if !GLIB_CHECK_VERSION(2,35,0) +#if !GLIB_CHECK_VERSION(2, 35, 0) /* Need g_type_init() to use tel_get_cp_name_list() */ g_type_init(); #endif @@ -366,12 +432,12 @@ int telephony_init(telephony_handle_list_s *list) cp_list = tel_get_cp_name_list(); if (cp_list == NULL) { LOGE("cp_list is NULL"); + list->count = 0; return TELEPHONY_ERROR_OPERATION_FAILED; } - while (cp_list[cp_count]) { + while (cp_list[cp_count]) cp_count++; - } list->count = cp_count; list->handle = g_malloc(cp_count * sizeof(telephony_h)); @@ -430,3 +496,48 @@ int telephony_deinit(telephony_handle_list_s *list) return TELEPHONY_ERROR_NONE; } + +int telephony_get_state(telephony_state_e *state) +{ + int res = 0; + int value = 0; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(state); + + res = tel_get_ready_state(&value); + if (res != TAPI_API_SUCCESS) + return TELEPHONY_ERROR_OPERATION_FAILED; + + *state = value; + + return TELEPHONY_ERROR_NONE; +} + +int telephony_set_state_changed_cb(telephony_state_changed_cb callback, void *user_data) +{ + int res = 0; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(callback); + + res = tel_register_ready_state_cb((tapi_state_cb)callback, user_data); + if (res != TAPI_API_SUCCESS) + return TELEPHONY_ERROR_OPERATION_FAILED; + + return TELEPHONY_ERROR_NONE; +} + +int telephony_unset_state_changed_cb(telephony_state_changed_cb callback) +{ + int res = 0; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(callback); + + res = tel_deregister_ready_state_cb((tapi_state_cb)callback); + if (res != TAPI_API_SUCCESS) + return TELEPHONY_ERROR_OPERATION_FAILED; + + return TELEPHONY_ERROR_NONE; +} diff --git a/src/telephony_modem.c b/src/telephony_modem.c index 47b0d41..975eebc 100644 --- a/src/telephony_modem.c +++ b/src/telephony_modem.c @@ -27,17 +27,6 @@ #include "telephony_modem.h" #include "telephony_private.h" -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "CAPI_TELEPHONY" - -#define CHECK_INPUT_PARAMETER(arg) \ - if (arg == NULL) { \ - LOGE("INVALID_PARAMETER"); \ - return TELEPHONY_ERROR_INVALID_PARAMETER; \ - } - int telephony_modem_get_imei(telephony_h handle, char **imei) { GVariant *gv = NULL; @@ -76,3 +65,51 @@ int telephony_modem_get_imei(telephony_h handle, char **imei) return error; } + +int telephony_modem_get_power_status(telephony_h handle, + telephony_modem_power_status_e *status) +{ + TapiHandle *tapi_h; + int ret; + tapi_power_phone_power_status_t modem_status = TAPI_PHONE_POWER_STATUS_UNKNOWN; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(status); + + ret = tel_check_modem_power_status(tapi_h, &modem_status); + if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + return TELEPHONY_ERROR_PERMISSION_DENIED; + } else if (ret != TAPI_API_SUCCESS) { + LOGE("OPERATION_FAILED"); + return TELEPHONY_ERROR_OPERATION_FAILED; + } else { + switch (modem_status) { + case TAPI_PHONE_POWER_STATUS_ON: + *status = TELEPHONY_MODEM_POWER_STATUS_ON; + break; + case TAPI_PHONE_POWER_STATUS_OFF: + *status = TELEPHONY_MODEM_POWER_STATUS_OFF; + break; + case TAPI_PHONE_POWER_STATUS_RESET: + *status = TELEPHONY_MODEM_POWER_STATUS_RESET; + break; + case TAPI_PHONE_POWER_STATUS_LOW: + *status = TELEPHONY_MODEM_POWER_STATUS_LOW; + break; + case TAPI_PHONE_POWER_STATUS_UNKNOWN: + case TAPI_PHONE_POWER_STATUS_ERROR: + default: + *status = TELEPHONY_MODEM_POWER_STATUS_UNKNOWN; + break; + } + } + + LOGI("modem_power_status = %d (0=on,1=off,2=rst,3=low)", *status); + + return TELEPHONY_ERROR_NONE; + +} diff --git a/src/telephony_network.c b/src/telephony_network.c index 728dd73..9517417 100644 --- a/src/telephony_network.c +++ b/src/telephony_network.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include "telephony_network.h" @@ -29,17 +30,6 @@ #include #include -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "CAPI_TELEPHONY" - -#define CHECK_INPUT_PARAMETER(arg) \ - if (arg == NULL) { \ - LOGE("INVALID_PARAMETER"); \ - return TELEPHONY_ERROR_INVALID_PARAMETER; \ - } - int telephony_network_get_lac(telephony_h handle, int *lac) { int ret; @@ -164,14 +154,14 @@ int telephony_network_get_mcc(telephony_h handle, char **mcc) ret = tel_get_property_string(tapi_h, TAPI_PROP_NETWORK_PLMN, &plmn_str); if (ret == TAPI_API_SUCCESS) { - *mcc = malloc (sizeof(char) * (mcc_length + 1)); + *mcc = malloc(sizeof(char) * (mcc_length + 1)); if (*mcc == NULL) { LOGE("OUT_OF_MEMORY"); ret = TELEPHONY_ERROR_OUT_OF_MEMORY; } else { - memset (*mcc, 0x00, mcc_length + 1); - strncpy (*mcc, plmn_str, mcc_length); - free (plmn_str); + memset(*mcc, 0x00, mcc_length + 1); + strncpy(*mcc, plmn_str, mcc_length); + free(plmn_str); LOGI("mcc:[%s]", *mcc); ret = TELEPHONY_ERROR_NONE; @@ -205,14 +195,14 @@ int telephony_network_get_mnc(telephony_h handle, char **mnc) plmn_length = strlen(plmn_str); LOGI("plmn:[%s], length:[%d]", plmn_str, plmn_length); - *mnc = malloc (sizeof(char) * (plmn_length -3 + 1)); + *mnc = malloc(sizeof(char) * (plmn_length -3 + 1)); if (*mnc == NULL) { LOGE("OUT_OF_MEMORY"); ret = TELEPHONY_ERROR_OUT_OF_MEMORY; } else { - memset (*mnc, 0x00, (plmn_length -3 + 1)); - strncpy (*mnc, plmn_str + 3, (plmn_length -3 + 1)); - free (plmn_str); + memset(*mnc, 0x00, (plmn_length -3 + 1)); + strncpy(*mnc, plmn_str + 3, (plmn_length -3 + 1)); + free(plmn_str); LOGI("mnc:[%s]", *mnc); ret = TELEPHONY_ERROR_NONE; @@ -254,6 +244,48 @@ int telephony_network_get_network_name(telephony_h handle, char **network_name) return ret; } +int telephony_network_get_network_name_option(telephony_h handle, telephony_network_name_option_e *network_name_option) +{ + int ret; + int name_option = 0; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(network_name_option); + + ret = tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_NAME_OPTION, &name_option); + if (ret == TAPI_API_SUCCESS) { + switch (name_option) { + case TAPI_NETWORK_NAME_OPTION_SPN: + *network_name_option = TELEPHONY_NETWORK_NAME_OPTION_SPN; + break; + case TAPI_NETWORK_NAME_OPTION_OPERATOR: + *network_name_option = TELEPHONY_NETWORK_NAME_OPTION_NETWORK; + break; + case TAPI_NETWORK_NAME_OPTION_ANY: + *network_name_option = TELEPHONY_NETWORK_NAME_OPTION_ANY; + break; + default: + *network_name_option = TELEPHONY_NETWORK_NAME_OPTION_UNKNOWN; + break; + } + + LOGI("network_name_option:[%d]", *network_name_option); + ret = TELEPHONY_ERROR_NONE; + } else if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + ret = TELEPHONY_ERROR_PERMISSION_DENIED; + } else { + LOGE("OPERATION_FAILED"); + ret = TELEPHONY_ERROR_OPERATION_FAILED; + } + + return ret; +} + int telephony_network_get_type(telephony_h handle, telephony_network_type_e *network_type) { int ret; @@ -305,6 +337,51 @@ int telephony_network_get_type(telephony_h handle, telephony_network_type_e *net return ret; } +int telephony_network_get_ps_type(telephony_h handle, telephony_network_ps_type_e *ps_type) +{ + int ret; + int service_type = 0; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(ps_type); + + ret = tel_get_property_int(tapi_h, TAPI_PROP_NETWORK_PS_TYPE, &service_type); + if (ret == TAPI_API_SUCCESS) { + switch (service_type) { + case TAPI_NETWORK_PS_TYPE_HSDPA: + *ps_type = TELEPHONY_NETWORK_PS_TYPE_HSDPA; + break; + case TAPI_NETWORK_PS_TYPE_HSUPA: + *ps_type = TELEPHONY_NETWORK_PS_TYPE_HSUPA; + break; + case TAPI_NETWORK_PS_TYPE_HSPA: + *ps_type = TELEPHONY_NETWORK_PS_TYPE_HSPA; + break; + case TAPI_NETWORK_PS_TYPE_HSPAP: + *ps_type = TELEPHONY_NETWORK_PS_TYPE_HSPAP; + break; + default: + *ps_type = TELEPHONY_NETWORK_PS_TYPE_UNKNOWN; + break; + } + + LOGI("ps_type:[%d]", *ps_type); + ret = TELEPHONY_ERROR_NONE; + } else if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + ret = TELEPHONY_ERROR_PERMISSION_DENIED; + } else { + LOGE("OPERATION_FAILED"); + ret = TELEPHONY_ERROR_OPERATION_FAILED; + } + + return ret; +} + int telephony_network_get_service_state(telephony_h handle, telephony_network_service_state_e *network_service_state) { int ret; @@ -344,3 +421,84 @@ int telephony_network_get_service_state(telephony_h handle, telephony_network_se return ret; } + +int telephony_network_get_default_data_subscription(telephony_h handle, + telephony_network_default_data_subs_e *default_data_sub) +{ + TapiHandle *tapi_h; + int ret; + TelNetworkDefaultDataSubs_t default_data_subscription = TAPI_NETWORK_DEFAULT_DATA_SUBS_UNKNOWN; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(default_data_sub); + + ret = tel_get_network_default_data_subscription(tapi_h, &default_data_subscription); + if (ret == TAPI_API_SUCCESS) { + switch (default_data_subscription) { + case TAPI_NETWORK_DEFAULT_DATA_SUBS_SIM1: + *default_data_sub = TELEPHONY_NETWORK_DEFAULT_DATA_SUBS_SIM1; + break; + case TAPI_NETWORK_DEFAULT_DATA_SUBS_SIM2: + *default_data_sub = TELEPHONY_NETWORK_DEFAULT_DATA_SUBS_SIM2; + break; + case TAPI_NETWORK_DEFAULT_DATA_SUBS_UNKNOWN: + default: + *default_data_sub = TELEPHONY_NETWORK_DEFAULT_DATA_SUBS_UNKNOWN; + break; + } + LOGI("default data subscription: [%d]", *default_data_sub); + ret = TELEPHONY_ERROR_NONE; + } else if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + ret = TELEPHONY_ERROR_PERMISSION_DENIED; + } else { + LOGE("OPERATION_FAILED"); + ret = TELEPHONY_ERROR_OPERATION_FAILED; + } + + return ret; +} + +int telephony_network_get_default_subscription(telephony_h handle, + telephony_network_default_subs_e *default_sub) +{ + TapiHandle *tapi_h; + int ret; + TelNetworkDefaultSubs_t default_subscription = TAPI_NETWORK_DEFAULT_SUBS_UNKNOWN; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(default_sub); + + ret = tel_get_network_default_subscription(tapi_h, &default_subscription); + if (ret == TAPI_API_SUCCESS) { + switch (default_subscription) { + case TAPI_NETWORK_DEFAULT_SUBS_SIM1: + *default_sub = TELEPHONY_NETWORK_DEFAULT_SUBS_SIM1; + break; + case TAPI_NETWORK_DEFAULT_SUBS_SIM2: + *default_sub = TELEPHONY_NETWORK_DEFAULT_SUBS_SIM2; + break; + case TAPI_NETWORK_DEFAULT_SUBS_UNKNOWN: + default: + *default_sub = TELEPHONY_NETWORK_DEFAULT_SUBS_UNKNOWN; + break; + } + LOGI("default subscription: [%d]", *default_sub); + ret = TELEPHONY_ERROR_NONE; + } else if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + ret = TELEPHONY_ERROR_PERMISSION_DENIED; + } else { + LOGE("OPERATION_FAILED"); + ret = TELEPHONY_ERROR_OPERATION_FAILED; + } + + return ret; +} + diff --git a/src/telephony_sim.c b/src/telephony_sim.c index 89f7e98..ce2e5f0 100644 --- a/src/telephony_sim.c +++ b/src/telephony_sim.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -27,11 +28,6 @@ #include "telephony_sim.h" #include "telephony_private.h" -#ifdef LOG_TAG -#undef LOG_TAG -#endif -#define LOG_TAG "CAPI_TELEPHONY" - #define DBUS_SIM_STATUS_ERROR "SIM STATUS ERROR" #define DBUS_SIM_NOT_FOUND "SIM NOT FOUND" #define DBUS_SIM_PERM_BLOCKED "SIM PERM BLOCKED" @@ -43,12 +39,6 @@ #define DBUS_SIM_RESPONSE_DATA_ERROR "SIM RESPONSE DATA ERROR" #define DBUS_SIM_ACCESS_DENIED "No access rights" -#define CHECK_INPUT_PARAMETER(arg) \ - if (arg == NULL) { \ - LOGE("INVALID_PARAMETER"); \ - return TELEPHONY_ERROR_INVALID_PARAMETER; \ - } - #define GET_SIM_STATUS(tapi_h, sim_card_state) { \ int card_changed = 0; \ int ret = tel_get_sim_init_info(tapi_h, &sim_card_state, &card_changed); \ @@ -126,11 +116,10 @@ int telephony_sim_get_icc_id(telephony_h handle, char **icc_id) if (sync_gv) { g_variant_get(sync_gv, "(is)", &result, &iccid); if (result == TAPI_SIM_ACCESS_SUCCESS) { - if (iccid != NULL && strlen(iccid) != 0) { + if (iccid != NULL && strlen(iccid) != 0) *icc_id = g_strdup_printf("%s", iccid); - } else { + else *icc_id = g_strdup_printf("%s", ""); - } } else { error_code = TELEPHONY_ERROR_OPERATION_FAILED; } @@ -343,6 +332,32 @@ int telephony_sim_get_state(telephony_h handle, telephony_sim_state_e *sim_state return error_code; } +int telephony_sim_get_application_list(telephony_h handle, unsigned int *app_list) +{ + TapiHandle *tapi_h; + unsigned char tapi_app_list; + int ret; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(app_list); + + ret = tel_get_sim_application_list(tapi_h, &tapi_app_list); + if (ret == TAPI_API_ACCESS_DENIED) { + LOGE("PERMISSION_DENIED"); + return TELEPHONY_ERROR_PERMISSION_DENIED; + } else if (ret != TAPI_API_SUCCESS) { + LOGE("OPERATION_FAILED"); + return TELEPHONY_ERROR_OPERATION_FAILED; + } + + *app_list = (unsigned int)tapi_app_list; + LOGI("SIM Application List: [0x%x]", *app_list); + return TELEPHONY_ERROR_NONE; +} + int telephony_sim_get_subscriber_number(telephony_h handle, char **subscriber_number) { int error_code = TELEPHONY_ERROR_NONE; @@ -374,9 +389,8 @@ int telephony_sim_get_subscriber_number(telephony_h handle, char **subscriber_nu while (g_variant_iter_loop(iter_row, "{sv}", &key, &value)) { if (!g_strcmp0(key, "number")) { str_value = g_variant_get_string(value, NULL); - if (str_value != NULL && strlen(str_value) != 0) { + if (str_value != NULL && strlen(str_value) != 0) *subscriber_number = g_strdup_printf("%s", str_value); - } } } g_variant_iter_free(iter_row); @@ -397,3 +411,52 @@ int telephony_sim_get_subscriber_number(telephony_h handle, char **subscriber_nu return error_code; } + +int telephony_sim_get_subscriber_id(telephony_h handle, char **subscriber_id) +{ + int error_code = TELEPHONY_ERROR_NONE; + TelSimCardStatus_t sim_card_state = TAPI_SIM_STATUS_UNKNOWN; + TapiHandle *tapi_h; + + CHECK_TELEPHONY_SUPPORTED(TELEPHONY_FEATURE); + CHECK_INPUT_PARAMETER(handle); + tapi_h = ((telephony_data *)handle)->tapi_h; + CHECK_INPUT_PARAMETER(tapi_h); + CHECK_INPUT_PARAMETER(subscriber_id); + GET_SIM_STATUS(tapi_h, sim_card_state); + + *subscriber_id = NULL; + if (sim_card_state != TAPI_SIM_STATUS_SIM_INIT_COMPLETED) { + error_code = TELEPHONY_ERROR_SIM_NOT_AVAILABLE; + } else { + TelSimImsiInfo_t imsi_info; + error_code = tel_get_sim_imsi(tapi_h, &imsi_info); + if (error_code == TAPI_API_SUCCESS) { + SHA256_CTX ctx; + char *imsi; + unsigned char md[SHA256_DIGEST_LENGTH]; + int i; + + imsi = g_strdup_printf("%s%s%s", + imsi_info.szMcc, imsi_info.szMnc, imsi_info.szMsin); + + SHA256_Init(&ctx); + SHA256_Update(&ctx, imsi, strlen(imsi)); + SHA256_Final(md, &ctx); + + *subscriber_id = g_malloc0(SHA256_DIGEST_LENGTH * 2 + 1); + for (i = 0; i < SHA256_DIGEST_LENGTH; i++) + snprintf(*subscriber_id + (i * 2), 3, "%02x", md[i]); + LOGI("Subscriber ID: [%s]", *subscriber_id); + g_free(imsi); + } else if (error_code == TAPI_API_ACCESS_DENIED) { + LOGE("get_subscriber_id: PERMISSION_DENIED"); + error_code = TELEPHONY_ERROR_PERMISSION_DENIED; + } else { + LOGE("get_subscriber_id: OPERATION_FAILED"); + error_code = TELEPHONY_ERROR_OPERATION_FAILED; + } + } + + return error_code; +} diff --git a/test/test_all_api.c b/test/test_all_api.c index cb07e2a..c5b454d 100644 --- a/test/test_all_api.c +++ b/test/test_all_api.c @@ -27,17 +27,27 @@ #define LOG_TAG "CAPI_TELEPHONY_TEST" static GMainLoop *event_loop; +static telephony_handle_list_s handle_list; static int network_noti_tbl[] = { TELEPHONY_NOTI_NETWORK_SERVICE_STATE, TELEPHONY_NOTI_NETWORK_CELLID, TELEPHONY_NOTI_NETWORK_ROAMING_STATUS, - TELEPHONY_NOTI_NETWORK_SIGNALSTRENGTH_LEVEL + TELEPHONY_NOTI_NETWORK_SIGNALSTRENGTH_LEVEL, + TELEPHONY_NOTI_NETWORK_NETWORK_NAME, + TELEPHONY_NOTI_NETWORK_PS_TYPE, + TELEPHONY_NOTI_NETWORK_DEFAULT_DATA_SUBSCRIPTION, + TELEPHONY_NOTI_NETWORK_DEFAULT_SUBSCRIPTION }; static int call_noti_tbl[] = { - TELEPHONY_NOTI_VOICE_CALL_STATE, - TELEPHONY_NOTI_VIDEO_CALL_STATE + TELEPHONY_NOTI_VOICE_CALL_STATUS_IDLE, + TELEPHONY_NOTI_VOICE_CALL_STATUS_ACTIVE, + TELEPHONY_NOTI_VOICE_CALL_STATUS_HELD, + TELEPHONY_NOTI_VOICE_CALL_STATUS_DIALING, + TELEPHONY_NOTI_VOICE_CALL_STATUS_ALERTING, + TELEPHONY_NOTI_VOICE_CALL_STATUS_INCOMING, + TELEPHONY_NOTI_CALL_PREFERRED_VOICE_SUBSCRIPTION }; static const char *_mapping_sim_state(telephony_sim_state_e sim_state) @@ -57,11 +67,8 @@ static const char *_mapping_sim_state(telephony_sim_state_e sim_state) static void sim_noti_cb(telephony_h handle, telephony_noti_e noti_id, void *data, void *user_data) { LOGI("Noti!! SIM status: [%d]", *(int *)data); - -// g_main_loop_quit(event_loop); } - static const char *_mapping_service_state(telephony_network_service_state_e service_state) { switch (service_state) { @@ -76,6 +83,64 @@ static const char *_mapping_service_state(telephony_network_service_state_e serv } } +static const char *_mapping_name_option(telephony_network_name_option_e option) +{ + switch (option) { + case TELEPHONY_NETWORK_NAME_OPTION_NETWORK: + return "By network"; + case TELEPHONY_NETWORK_NAME_OPTION_SPN: + return "By SPN"; + case TELEPHONY_NETWORK_NAME_OPTION_ANY: + return "By both"; + default: + return "Unknown priority"; + } +} + +static const char *_mapping_ps_type(telephony_network_ps_type_e ps_type) +{ + switch (ps_type) { + case TELEPHONY_NETWORK_PS_TYPE_HSDPA: + return "HSDPA"; + case TELEPHONY_NETWORK_PS_TYPE_HSUPA: + return "HSUPA"; + case TELEPHONY_NETWORK_PS_TYPE_HSPA: + return "HSPA"; + case TELEPHONY_NETWORK_PS_TYPE_HSPAP: + return "HSPAP"; + default: + return "Unknown"; + } +} + +static const char *_mapping_default_data_sub(telephony_network_default_data_subs_e default_data_sub) +{ + switch (default_data_sub) { + case TELEPHONY_NETWORK_DEFAULT_DATA_SUBS_SIM1: + return "SIM1"; + case TELEPHONY_NETWORK_DEFAULT_DATA_SUBS_SIM2: + return "SIM2"; + case TELEPHONY_NETWORK_DEFAULT_DATA_SUBS_UNKNOWN: + return "Unknown"; + default: + return "Unavailable"; + } +} + +static const char *_mapping_default_sub(telephony_network_default_subs_e default_sub) +{ + switch (default_sub) { + case TELEPHONY_NETWORK_DEFAULT_SUBS_SIM1: + return "SIM1"; + case TELEPHONY_NETWORK_DEFAULT_SUBS_SIM2: + return "SIM2"; + case TELEPHONY_NETWORK_DEFAULT_SUBS_UNKNOWN: + return "Unknown"; + default: + return "Unavailable"; + } +} + static const char *_mapping_network_type(telephony_network_type_e network_type) { switch (network_type) { @@ -111,12 +176,23 @@ static void network_noti_cb(telephony_h handle, telephony_noti_e noti_id, void * case TELEPHONY_NOTI_NETWORK_SIGNALSTRENGTH_LEVEL: LOGI("Noti!!! Signal strength: [%d]", *(int *)data); break; + case TELEPHONY_NOTI_NETWORK_NETWORK_NAME: + LOGI("Noti!!! Network Name: [%s]", *(int *)data); + break; + case TELEPHONY_NOTI_NETWORK_PS_TYPE: + LOGI("Noti!!! PS Type: [%s]", _mapping_ps_type(*(int *)data)); + break; + case TELEPHONY_NOTI_NETWORK_DEFAULT_DATA_SUBSCRIPTION: + LOGI("Noti!!! Default Data Subscription: [%d]", *(int *)data); + break; + case TELEPHONY_NOTI_NETWORK_DEFAULT_SUBSCRIPTION: + LOGI("Noti!!! Default Subscription: [%d]", *(int *)data); + break; default: LOGE("Unknown noti"); break; } -// g_main_loop_quit(event_loop); } static const char *_mapping_call_state(telephony_call_state_e call_state) @@ -133,26 +209,104 @@ static const char *_mapping_call_state(telephony_call_state_e call_state) } } +static const char *_mapping_preferred_voice_sub(telephony_call_preferred_voice_subs_e call_sub) +{ + switch (call_sub) { + case TELEPHONY_CALL_PREFERRED_VOICE_SUBS_CURRENT_NETWORK: + return "CURRENT_NETWORK"; + case TELEPHONY_CALL_PREFERRED_VOICE_SUBS_ASK_ALWAYS: + return "ASK_ALWAYS"; + case TELEPHONY_CALL_PREFERRED_VOICE_SUBS_SIM1: + return "SIM1"; + case TELEPHONY_CALL_PREFERRED_VOICE_SUBS_SIM2: + return "SIM2"; + case TELEPHONY_CALL_PREFERRED_VOICE_SUBS_UNKNOWN: + default: + return "Unknown"; + } +} + static void call_noti_cb(telephony_h handle, telephony_noti_e noti_id, void *data, void *user_data) { + int ret_value; + telephony_call_h *call_list; + unsigned int count = 0; + + if (noti_id == TELEPHONY_NOTI_CALL_PREFERRED_VOICE_SUBSCRIPTION) { + LOGI("Noti!!! Preferred Voice Subscription: [%d]", *(int *)data); + return; + } + switch (noti_id) { - case TELEPHONY_NOTI_VOICE_CALL_STATE: - LOGI("Noti!!! Voice Call state: [%s]", _mapping_call_state(*(int *)data)); + case TELEPHONY_NOTI_VOICE_CALL_STATUS_IDLE: + LOGI("Noti!!! Voice Call Status Idle!!! [%d]", *(int *)data); + break; + case TELEPHONY_NOTI_VOICE_CALL_STATUS_ACTIVE: + LOGI("Noti!!! Voice Call Status Active!!! [%d]", *(int *)data); + break; + case TELEPHONY_NOTI_VOICE_CALL_STATUS_HELD: + LOGI("Noti!!! Voice Call Status Held!!! [%d]", *(int *)data); + break; + case TELEPHONY_NOTI_VOICE_CALL_STATUS_DIALING: + LOGI("Noti!!! Voice Call Status Dialing!!! [%d]", *(int *)data); + break; + case TELEPHONY_NOTI_VOICE_CALL_STATUS_ALERTING: + LOGI("Noti!!! Voice Call Status Alerting!!! [%d]", *(int *)data); break; - case TELEPHONY_NOTI_VIDEO_CALL_STATE: - LOGI("Noti!!! Video Call state: [%s]", _mapping_call_state(*(int *)data)); + case TELEPHONY_NOTI_VOICE_CALL_STATUS_INCOMING: + LOGI("Noti!!! Voice Call Status Incoming!!! [%d]", *(int *)data); break; default: LOGE("Unknown noti"); break; } -// g_main_loop_quit(event_loop); + ret_value = telephony_call_get_call_list(handle_list.handle[0], &count, &call_list); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_call_get_call_list() failed!!!zz [0x%x]", ret_value); + } else { + int i; + unsigned int handle_id = 0; + char *number = NULL; + telephony_call_type_e type = 0; + telephony_call_status_e status = 0; + telephony_call_direction_e direction = 0; + bool conf_status = 0; + + for (i = 0; i < count; i++) { + telephony_call_get_handle_id(call_list[i], &handle_id); + telephony_call_get_number(call_list[i], &number); + telephony_call_get_type(call_list[i], &type); + telephony_call_get_status(call_list[i], &status); + telephony_call_get_direction(call_list[i], &direction); + telephony_call_get_conference_status(call_list[i], &conf_status); + LOGI("id[%d] number[%s] type[%s] status[%s] direction[%s] conference_status[%s]", + handle_id, number, + type == TELEPHONY_CALL_TYPE_VOICE ? "VOICE" : + type == TELEPHONY_CALL_TYPE_VIDEO ? "VIDEO" : "E911", + status == TELEPHONY_CALL_STATUS_IDLE ? "IDLE" : + status == TELEPHONY_CALL_STATUS_ACTIVE ? "ACTVIE" : + status == TELEPHONY_CALL_STATUS_HELD ? "HELD" : + status == TELEPHONY_CALL_STATUS_DIALING ? "DIALING" : + status == TELEPHONY_CALL_STATUS_ALERTING ? "ALERTING" : + status == TELEPHONY_CALL_STATUS_INCOMING ? "INCOMING" : "UNKNOWN", + direction == TELEPHONY_CALL_DIRECTION_MO ? "MO" : "MT", + conf_status ? "TRUE" : "FALSE"); + free(number); + number = NULL; + } + telephony_call_release_call_list(count, &call_list); + } + +} + +static void on_telephony_state_changed_cb(telephony_state_e state, void *user_data) +{ + LOGI("telephony state value : [%d]", state); } int main() { - telephony_handle_list_s handle_list; int ret_value, i; /* SIM value */ @@ -161,7 +315,10 @@ int main() char *msin = NULL; char *spn = NULL; telephony_sim_state_e sim_state = 0; + unsigned int app_list = 0; char *subscriber_number = NULL; + char *subscriber_id = NULL; + bool is_changed = FALSE; /* Network value */ int cell_id = 0; @@ -173,12 +330,23 @@ int main() telephony_network_rssi_e rssi = 0; telephony_network_service_state_e service_state = 0; telephony_network_type_e network_type = 0; + telephony_network_default_data_subs_e default_data_sub = 0; + telephony_network_default_subs_e default_sub = 0; + telephony_network_name_option_e network_name_option = 0; + telephony_network_ps_type_e ps_type = 0; /* Call value */ telephony_call_state_e call_state = 0; + telephony_call_preferred_voice_subs_e call_sub = 0; + telephony_call_h *call_list; + unsigned int count = 0; /* Modem value */ char *imei = NULL; + telephony_modem_power_status_e power_status = 0; + + /* Ready */ + telephony_state_e ready_state = 0; /* Initialize handle */ ret_value = telephony_init(&handle_list); @@ -190,6 +358,12 @@ int main() LOGI("handle count: [%d]", handle_list.count); /* SIM API */ + ret_value = telephony_sim_is_changed(handle_list.handle[0], &is_changed); + if (ret_value != TELEPHONY_ERROR_NONE) + LOGE("telephony_sim_is_changed() failed!!! [%d]", ret_value); + else + LOGI("SIM is [%s]", is_changed ? "Changed" : "Not changed"); + ret_value = telephony_sim_get_operator(handle_list.handle[0], &operator); if (ret_value != TELEPHONY_ERROR_NONE) { LOGE("telephony_sim_get_operator() failed!!! [%d]", ret_value); @@ -223,10 +397,21 @@ int main() } ret_value = telephony_sim_get_state(handle_list.handle[0], &sim_state); - if (ret_value != TELEPHONY_ERROR_NONE) { + if (ret_value != TELEPHONY_ERROR_NONE) LOGE("telephony_sim_get_state() failed!!! [%d]", ret_value); - } else { + else LOGI("SIM state is [%s]", _mapping_sim_state(sim_state)); + + ret_value = telephony_sim_get_application_list(handle_list.handle[0], &app_list); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_sim_get_type() failed!!! [%d]", ret_value); + } else { + if (app_list & TELEPHONY_SIM_APP_TYPE_SIM) + LOGI("Sim type [SIM]"); + if (app_list & TELEPHONY_SIM_APP_TYPE_USIM) + LOGI("Sim type [USIM]"); + if (app_list & TELEPHONY_SIM_APP_TYPE_CSIM) + LOGI("Sim type [CSIM]"); } ret_value = telephony_sim_get_subscriber_number(handle_list.handle[0], &subscriber_number); @@ -237,20 +422,26 @@ int main() free(subscriber_number); } + ret_value = telephony_sim_get_subscriber_id(handle_list.handle[0], &subscriber_id); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_sim_get_subscriber_id() failed!!! [%d]", ret_value); + } else { + LOGI("Subscriber ID is [%s]", subscriber_id); + free(subscriber_id); + } + /* Network API */ ret_value = telephony_network_get_cell_id(handle_list.handle[0], &cell_id); - if (ret_value != TELEPHONY_ERROR_NONE) { + if (ret_value != TELEPHONY_ERROR_NONE) LOGE("telephony_network_get_cell_id() failed!!! [%d]", ret_value); - } else { + else LOGI("Cell ID is [%d]", cell_id); - } ret_value = telephony_network_get_lac(handle_list.handle[0], &lac); - if (ret_value != TELEPHONY_ERROR_NONE) { + if (ret_value != TELEPHONY_ERROR_NONE) LOGE("telephony_network_get_lac() failed!!! [%d]", ret_value); - } else { + else LOGI("Location Area Code is [%d]", lac); - } ret_value = telephony_network_get_mcc(handle_list.handle[0], &mcc); if (ret_value != TELEPHONY_ERROR_NONE) { @@ -276,47 +467,97 @@ int main() free(network_name); } + ret_value = telephony_network_get_network_name_option(handle_list.handle[0], &network_name_option); + if (ret_value != TELEPHONY_ERROR_NONE) + LOGE("telephony_network_get_network_name_option() failed!!! [%d]", ret_value); + else + LOGI("Network_name_option name is [%s]", _mapping_name_option(network_name_option)); + ret_value = telephony_network_get_roaming_status(handle_list.handle[0], &roaming_status); - if (ret_value != TELEPHONY_ERROR_NONE) { + if (ret_value != TELEPHONY_ERROR_NONE) LOGE("telephony_network_get_roaming_status() failed!!! [%d]", ret_value); - } else { + else LOGI("Network Roaming: [%s]", roaming_status ? "ON" : "OFF"); - } ret_value = telephony_network_get_rssi(handle_list.handle[0], &rssi); - if (ret_value != TELEPHONY_ERROR_NONE) { + if (ret_value != TELEPHONY_ERROR_NONE) LOGE("telephony_network_get_rssi() failed!!! [%d]", ret_value); - } else { + else LOGI("Received Signal Strength Indicator is [%d]", rssi); - } ret_value = telephony_network_get_service_state(handle_list.handle[0], &service_state); - if (ret_value != TELEPHONY_ERROR_NONE) { + if (ret_value != TELEPHONY_ERROR_NONE) LOGE("telephony_network_get_service_state() failed!!! [%d]", ret_value); - } else { + else LOGI("Network service state is [%s]", _mapping_service_state(service_state)); - } ret_value = telephony_network_get_type(handle_list.handle[0], &network_type); - if (ret_value != TELEPHONY_ERROR_NONE) { + if (ret_value != TELEPHONY_ERROR_NONE) LOGE("telephony_network_get_type() failed!!! [%d]", ret_value); - } else { + else LOGI("Network type is [%s]", _mapping_network_type(network_type)); - } + + ret_value = telephony_network_get_ps_type(handle_list.handle[0], &ps_type); + if (ret_value != TELEPHONY_ERROR_NONE) + LOGE("telephony_network_get_ps_type() failed!!! [%d]", ret_value); + else + LOGI("PS type is [%s]", _mapping_ps_type(ps_type)); + + ret_value = telephony_network_get_default_data_subscription(handle_list.handle[0], &default_data_sub); + if (ret_value != TELEPHONY_ERROR_NONE) + LOGE("telephony_network_get_default_data_subscription() failed!!! [%d]", ret_value); + else + LOGI("Default data subscription is [%s]", _mapping_default_data_sub(default_data_sub)); + + ret_value = telephony_network_get_default_subscription(handle_list.handle[0], &default_sub); + if (ret_value != TELEPHONY_ERROR_NONE) + LOGE("telephony_network_get_default_subscription() failed!!! [%d]", ret_value); + else + LOGI("Default subscription is [%s]", _mapping_default_sub(default_sub)); /* Call API */ ret_value = telephony_call_get_voice_call_state(handle_list.handle[0], &call_state); - if (ret_value != TELEPHONY_ERROR_NONE) { + if (ret_value != TELEPHONY_ERROR_NONE) LOGE("telephony_call_get_voice_call_state() failed!!! [%d]", ret_value); - } else { + else LOGI("Voice Call state is [%s]", _mapping_call_state(call_state)); - } ret_value = telephony_call_get_video_call_state(handle_list.handle[0], &call_state); - if (ret_value != TELEPHONY_ERROR_NONE) { + if (ret_value != TELEPHONY_ERROR_NONE) LOGE("telephony_call_get_video_call_state() failed!!! [%d]", ret_value); - } else { + else LOGI("Video Call state is [%s]", _mapping_call_state(call_state)); + + ret_value = telephony_call_get_preferred_voice_subscription(handle_list.handle[0], &call_sub); + if (ret_value != TELEPHONY_ERROR_NONE) + LOGE("telephony_call_get_preferred_voice_subscription() failed!!! [%d]", ret_value); + else + LOGI("Preferred voice subscription is [%s]", _mapping_preferred_voice_sub(call_sub)); + + ret_value = telephony_call_get_call_list(handle_list.handle[0], &count, &call_list); + if (ret_value != TELEPHONY_ERROR_NONE) { + LOGE("telephony_call_get_call_list() failed!!! [0x%x]", ret_value); + } else { + unsigned int handle_id = 0; + char *number = NULL; + telephony_call_type_e type = 0; + telephony_call_status_e status = 0; + telephony_call_direction_e direction = 0; + bool conf_status = 0; + + for (i = 0; i < count; i++) { + telephony_call_get_handle_id(call_list[i], &handle_id); + telephony_call_get_number(call_list[i], &number); + telephony_call_get_type(call_list[i], &type); + telephony_call_get_status(call_list[i], &status); + telephony_call_get_direction(call_list[i], &direction); + telephony_call_get_conference_status(call_list[i], &conf_status); + LOGI("handle_id[%d] number[%s] type[%d] status[%d] direction[%d] conf_status[%d]", + handle_id, number, type, status, direction, conf_status); + free(number); + number = NULL; + } + telephony_call_release_call_list(count, &call_list); } /* Modem API */ @@ -328,23 +569,41 @@ int main() free(imei); } + ret_value = telephony_modem_get_power_status(handle_list.handle[0], &power_status); + if (ret_value != TELEPHONY_ERROR_NONE) + LOGE("telephony_modem_get_power_status() failed!!! [%d]", ret_value); + else + LOGI("Modem power status is [%d] (0=on,1=off,2=rst,3=low)", power_status); + /* set_noti_cb */ ret_value = telephony_set_noti_cb(handle_list.handle[0], TELEPHONY_NOTI_SIM_STATUS, sim_noti_cb, NULL); if (ret_value != TELEPHONY_ERROR_NONE) LOGE("Set noti failed!!!"); - for (i = 0; i < 4; i++) { + for (i = 0; i < (sizeof(network_noti_tbl) / sizeof(int)); i++) { ret_value = telephony_set_noti_cb(handle_list.handle[0], network_noti_tbl[i], network_noti_cb, NULL); if (ret_value != TELEPHONY_ERROR_NONE) LOGE("Set noti failed!!!"); } - for (i = 0; i < 2; i++) { + for (i = 0; i < (sizeof(call_noti_tbl) / sizeof(int)); i++) { ret_value = telephony_set_noti_cb(handle_list.handle[0], call_noti_tbl[i], call_noti_cb, NULL); if (ret_value != TELEPHONY_ERROR_NONE) LOGE("Set noti failed!!!"); } + ret_value = telephony_get_state(&ready_state); + if (ret_value != TELEPHONY_ERROR_NONE) + LOGI("telephony_get_state() failed!!!"); + else + LOGI("telephony_get_state() succeed ! : %s", ready_state ? "TRUE" : "FALSE"); + + ret_value = telephony_set_state_changed_cb(on_telephony_state_changed_cb, NULL); + if (ret_value != TELEPHONY_ERROR_NONE) + LOGI("telephony_set_state_changed_cb() failed!!!"); + else + LOGI("telephony_set_state_changed_cb() succeed!!"); + LOGI("If telephony status is changed, then callback function will be called"); event_loop = g_main_loop_new(NULL, FALSE); g_main_loop_run(event_loop); @@ -353,22 +612,27 @@ int main() if (ret_value != TELEPHONY_ERROR_NONE) LOGE("Unset noti failed!!!"); - for (i = 0; i < 4; i++) { + for (i = 0; i < (sizeof(network_noti_tbl) / sizeof(int)); i++) { ret_value = telephony_unset_noti_cb(handle_list.handle[0], network_noti_tbl[i]); if (ret_value != TELEPHONY_ERROR_NONE) LOGE("Unset noti failed!!!"); } - for (i = 0; i < 2; i++) { + for (i = 0; i < (sizeof(call_noti_tbl) / sizeof(int)); i++) { ret_value = telephony_unset_noti_cb(handle_list.handle[0], call_noti_tbl[i]); if (ret_value != TELEPHONY_ERROR_NONE) LOGE("Unset noti failed!!!"); } ret_value = telephony_deinit(&handle_list); - if (ret_value != TELEPHONY_ERROR_NONE) { + if (ret_value != TELEPHONY_ERROR_NONE) LOGE("Deinitialize failed!!!"); - } + + ret_value = telephony_unset_state_changed_cb(on_telephony_state_changed_cb); + if (ret_value != TELEPHONY_ERROR_NONE) + LOGE("telephony_unset_state_changed_cb() failed!!!"); + else + LOGD("telephony_unset_state_changed_cb() succeed!!"); return 0; } -- 2.7.4