Modify for NFC operation 57/72757/2 accepted/tizen_3.0.m2_mobile accepted/tizen_3.0.m2_tv accepted/tizen_3.0.m2_wearable accepted/tizen_3.0_common accepted/tizen_3.0_ivi accepted/tizen_3.0_mobile accepted/tizen_3.0_tv accepted/tizen_3.0_wearable accepted/tizen_4.0_unified accepted/tizen_5.0_unified accepted/tizen_5.5_unified accepted/tizen_5.5_unified_mobile_hotfix accepted/tizen_5.5_unified_wearable_hotfix accepted/tizen_6.0_unified accepted/tizen_6.0_unified_hotfix accepted/tizen_common accepted/tizen_ivi accepted/tizen_mobile accepted/tizen_tv accepted/tizen_wearable tizen_3.0 tizen_3.0.m2 tizen_3.0_tv tizen_4.0 tizen_5.0 tizen_5.5 tizen_5.5_mobile_hotfix tizen_5.5_tv tizen_5.5_wearable_hotfix tizen_6.0 tizen_6.0_hotfix accepted/tizen/3.0.m2/mobile/20170104.125205 accepted/tizen/3.0.m2/tv/20170104.125554 accepted/tizen/3.0.m2/wearable/20170104.125755 accepted/tizen/3.0/common/20161114.105709 accepted/tizen/3.0/ivi/20161011.065110 accepted/tizen/3.0/mobile/20161015.034110 accepted/tizen/3.0/tv/20161016.005637 accepted/tizen/3.0/wearable/20161015.083953 accepted/tizen/4.0/unified/20170816.011257 accepted/tizen/4.0/unified/20170816.014649 accepted/tizen/4.0/unified/20170828.223246 accepted/tizen/5.0/unified/20181102.014913 accepted/tizen/5.5/unified/20191031.023845 accepted/tizen/5.5/unified/mobile/hotfix/20201027.083736 accepted/tizen/5.5/unified/wearable/hotfix/20201027.115011 accepted/tizen/6.0/unified/20201030.120530 accepted/tizen/6.0/unified/hotfix/20201103.045958 accepted/tizen/common/20160603.150533 accepted/tizen/common/20160606.141615 accepted/tizen/ivi/20160606.121100 accepted/tizen/mobile/20160606.120701 accepted/tizen/tv/20160606.120856 accepted/tizen/unified/20170309.032604 accepted/tizen/wearable/20160606.121014 submit/tizen/20160602.020711 submit/tizen/20160603.011501 submit/tizen_3.0.m2/20170104.093750 submit/tizen_3.0_common/20161104.104000 submit/tizen_3.0_ivi/20161010.000007 submit/tizen_3.0_mobile/20161015.000006 submit/tizen_3.0_tv/20161015.000005 submit/tizen_3.0_wearable/20161015.000005 submit/tizen_4.0/20170811.094300 submit/tizen_4.0/20170814.115522 submit/tizen_4.0/20170828.100003 submit/tizen_4.0_unified/20170814.115522 submit/tizen_5.0/20181101.000003 submit/tizen_5.5/20191031.000003 submit/tizen_5.5_mobile_hotfix/20201026.185103 submit/tizen_5.5_wearable_hotfix/20201026.184303 submit/tizen_6.0/20201029.205103 submit/tizen_6.0_hotfix/20201102.192503 submit/tizen_6.0_hotfix/20201103.114803 submit/tizen_unified/20170308.100406 tizen_4.0.IoT.p1_release tizen_4.0.IoT.p2_release tizen_4.0.m1_release tizen_4.0.m2_release tizen_5.5.m2_release tizen_6.0.m2_release
authorJihoon Jung <jh8801.jung@samsung.com>
Thu, 2 Jun 2016 10:01:58 +0000 (19:01 +0900)
committerJihoon Jung <jh8801.jung@samsung.com>
Thu, 2 Jun 2016 10:04:35 +0000 (19:04 +0900)
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
Change-Id: Ifc3df692e9a7a1a08ceb0db5f3f9ecaa2caa4898

CMakeLists.txt
NFCTerminal.cpp
include/NFCTerminal.h
packaging/smartcard-plugin-nfc.spec

index cb015d4..bf3f8c1 100644 (file)
@@ -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}")
index 263b97e..174c915 100644 (file)
@@ -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;
index 7362258..9bf04d8 100644 (file)
@@ -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();
 
index 685a5ab..f762710 100755 (executable)
@@ -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