diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | NFCTerminal.cpp | 102 | ||||
-rw-r--r-- | include/NFCTerminal.h | 3 | ||||
-rwxr-xr-x | packaging/smartcard-plugin-nfc.spec | 3 |
4 files changed, 97 insertions, 13 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index cb015d4..bf3f8c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SRCS) #MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") INCLUDE(FindPkgConfig) -pkg_check_modules(pkgs_common REQUIRED glib-2.0 dlog smartcard-service-common capi-network-nfc) +pkg_check_modules(pkgs_common REQUIRED glib-2.0 dlog smartcard-service-common capi-network-nfc vconf) FOREACH(flag ${pkgs_common_CFLAGS}) SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} ${flag}") diff --git a/NFCTerminal.cpp b/NFCTerminal.cpp index 263b97e..174c915 100644 --- a/NFCTerminal.cpp +++ b/NFCTerminal.cpp @@ -56,7 +56,12 @@ EXPORT_API const char *get_name() EXPORT_API void *create_instance() { - return (void *)NFCTerminal::getInstance(); + int value; + + if (vconf_get_bool(VCONFKEY_NFC_ESE_DISABLE, &value) < 0) + return NULL; + + return value ? NULL : (void *)NFCTerminal::getInstance(); } EXPORT_API void destroy_instance(void *instance) @@ -97,6 +102,63 @@ namespace smartcard_service_api finalize(); } + void NFCTerminal::onActivationChanged(bool activated, void *userData) + { + NFCTerminal *instance = (NFCTerminal *)userData; + + _ERR("nfc state changed [%s]", activated ? "activated" : "deactivated"); + + if (activated == true) { + if (instance->present == false) { + if (instance->open() == true) { + instance->present = true; + instance->close(); + + if (instance->statusCallback != NULL) { + instance->statusCallback( + instance->getName(), + NOTIFY_SE_AVAILABLE, + SCARD_ERROR_OK, + NULL); + } + } else { + _ERR("ese open failed"); + } + } else { + /* okay */ + } + } else { + if (instance->present == true) { + instance->present = false; + + if (instance->isClosed() == false) { + int ret; + + /* close now */ + ret = nfc_se_close_secure_element_internal( + instance->seHandle); + if (ret != NFC_ERROR_NONE) { + _ERR("nfc_se_close_secure_element failed [%d]", ret); + } + + instance->seHandle = NULL; + instance->closed = true; + instance->referred = 0; + } + + if (instance->statusCallback != NULL) { + instance->statusCallback( + instance->getName(), + NOTIFY_SE_NOT_AVAILABLE, + SCARD_ERROR_OK, + NULL); + } + } else { + /* okay */ + } + } + } + bool NFCTerminal::initialize() { int ret; @@ -104,14 +166,26 @@ namespace smartcard_service_api if (initialized == true) return initialized; - ret = nfc_manager_initialize_sync(); + ret = nfc_manager_initialize(); if (ret == NFC_ERROR_NONE) { initialized = true; - if (open() == true) { - present = true; - close(); + ret = nfc_manager_set_activation_changed_cb( + &NFCTerminal::onActivationChanged, this); + if (ret != NFC_ERROR_NONE) { + _ERR("nfc_manager_set_activation_changed_cb failed, [%d]", ret); + } + + if (nfc_manager_is_activated() == true) { + if (open() == true) { + present = true; + close(); + } else { + _ERR("ese open failed"); + } + } else { + _ERR("nfc is not activated."); } } else @@ -129,15 +203,19 @@ namespace smartcard_service_api if (isClosed() == false) { /* close now */ ret = nfc_se_close_secure_element_internal(seHandle); - if (ret == NFC_ERROR_NONE) { - seHandle = NULL; - closed = true; - referred = 0; - } else { - _ERR("nfc_se_close_secure_element_internal failed [%d]", ret); + if (ret != NFC_ERROR_NONE) { + _ERR("nfc_se_close_secure_element failed [%d]", ret); } + + seHandle = NULL; + closed = true; + referred = 0; } + present = false; + + nfc_manager_unset_activation_changed_cb(); + ret = nfc_manager_deinitialize(); if (ret == NFC_ERROR_NONE) { initialized = false; @@ -183,6 +261,8 @@ namespace smartcard_service_api if (isInitialized()) { if (referred <= 1) { + g_usleep(1000000); + ret = nfc_se_close_secure_element_internal(seHandle); if (ret == NFC_ERROR_NONE) { seHandle = NULL; diff --git a/include/NFCTerminal.h b/include/NFCTerminal.h index 7362258..9bf04d8 100644 --- a/include/NFCTerminal.h +++ b/include/NFCTerminal.h @@ -21,6 +21,7 @@ /* Tizen library header */ #include "nfc.h" #include "nfc_internal.h" +#include <vconf.h> /* local header */ #include "Terminal.h" @@ -39,6 +40,8 @@ namespace smartcard_service_api NFCTerminal(); ~NFCTerminal(); + static void onActivationChanged(bool activated, void *userData); + public: static NFCTerminal *getInstance(); diff --git a/packaging/smartcard-plugin-nfc.spec b/packaging/smartcard-plugin-nfc.spec index 685a5ab..f762710 100755 --- a/packaging/smartcard-plugin-nfc.spec +++ b/packaging/smartcard-plugin-nfc.spec @@ -1,6 +1,6 @@ Name: smartcard-plugin-nfc Summary: Smartcard plugin nfc -Version: 0.0.10 +Version: 0.0.11 Release: 0 Group: Network & Connectivity/NFC License: Apache-2.0 @@ -12,6 +12,7 @@ BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(smartcard-service-common) BuildRequires: pkgconfig(capi-network-nfc) +BuildRequires: pkgconfig(vconf) Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig |