diff options
author | Jihoon Jung <jh8801.jung@samsung.com> | 2016-06-02 19:01:58 +0900 |
---|---|---|
committer | Jihoon Jung <jh8801.jung@samsung.com> | 2016-06-02 19:04:35 +0900 |
commit | 1e74825669656e7dab97a57a0bbc96f498a6ce77 (patch) | |
tree | f2308ed487631c475f3da6572762bffc39dd4e2d /NFCTerminal.cpp | |
parent | 5424732c9da8846406c8cf31c53b521a9b94313b (diff) | |
download | smartcard-plugin-nfc-accepted/tizen_mobile.tar.gz smartcard-plugin-nfc-accepted/tizen_mobile.tar.bz2 smartcard-plugin-nfc-accepted/tizen_mobile.zip |
Modify for NFC operationtizen_6.0.m2_releasetizen_5.5.m2_releasetizen_4.0.m2_releasetizen_4.0.m1_releasetizen_4.0.IoT.p2_releasetizen_4.0.IoT.p1_releasesubmit/tizen_unified/20170308.100406submit/tizen_6.0_hotfix/20201103.114803submit/tizen_6.0_hotfix/20201102.192503submit/tizen_6.0/20201029.205103submit/tizen_5.5_wearable_hotfix/20201026.184303submit/tizen_5.5_mobile_hotfix/20201026.185103submit/tizen_5.5/20191031.000003submit/tizen_5.0/20181101.000003submit/tizen_4.0_unified/20170814.115522submit/tizen_4.0/20170828.100003submit/tizen_4.0/20170814.115522submit/tizen_4.0/20170811.094300submit/tizen_3.0_wearable/20161015.000005submit/tizen_3.0_tv/20161015.000005submit/tizen_3.0_mobile/20161015.000006submit/tizen_3.0_ivi/20161010.000007submit/tizen_3.0_common/20161104.104000submit/tizen_3.0.m2/20170104.093750submit/tizen/20160603.011501submit/tizen/20160602.020711accepted/tizen/wearable/20160606.121014accepted/tizen/unified/20170309.032604accepted/tizen/tv/20160606.120856accepted/tizen/mobile/20160606.120701accepted/tizen/ivi/20160606.121100accepted/tizen/common/20160606.141615accepted/tizen/common/20160603.150533accepted/tizen/6.0/unified/hotfix/20201103.045958accepted/tizen/6.0/unified/20201030.120530accepted/tizen/5.5/unified/wearable/hotfix/20201027.115011accepted/tizen/5.5/unified/mobile/hotfix/20201027.083736accepted/tizen/5.5/unified/20191031.023845accepted/tizen/5.0/unified/20181102.014913accepted/tizen/4.0/unified/20170828.223246accepted/tizen/4.0/unified/20170816.014649accepted/tizen/4.0/unified/20170816.011257accepted/tizen/3.0/wearable/20161015.083953accepted/tizen/3.0/tv/20161016.005637accepted/tizen/3.0/mobile/20161015.034110accepted/tizen/3.0/ivi/20161011.065110accepted/tizen/3.0/common/20161114.105709accepted/tizen/3.0.m2/wearable/20170104.125755accepted/tizen/3.0.m2/tv/20170104.125554accepted/tizen/3.0.m2/mobile/20170104.125205tizen_6.0_hotfixtizen_6.0tizen_5.5_wearable_hotfixtizen_5.5_tvtizen_5.5_mobile_hotfixtizen_5.5tizen_5.0tizen_4.0tizen_3.0_tvtizen_3.0.m2tizen_3.0accepted/tizen_wearableaccepted/tizen_tvaccepted/tizen_mobileaccepted/tizen_iviaccepted/tizen_commonaccepted/tizen_6.0_unified_hotfixaccepted/tizen_6.0_unifiedaccepted/tizen_5.5_unified_wearable_hotfixaccepted/tizen_5.5_unified_mobile_hotfixaccepted/tizen_5.5_unifiedaccepted/tizen_5.0_unifiedaccepted/tizen_4.0_unifiedaccepted/tizen_3.0_wearableaccepted/tizen_3.0_tvaccepted/tizen_3.0_mobileaccepted/tizen_3.0_iviaccepted/tizen_3.0_commonaccepted/tizen_3.0.m2_wearableaccepted/tizen_3.0.m2_tvaccepted/tizen_3.0.m2_mobile
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
Change-Id: Ifc3df692e9a7a1a08ceb0db5f3f9ecaa2caa4898
Diffstat (limited to 'NFCTerminal.cpp')
-rw-r--r-- | NFCTerminal.cpp | 102 |
1 files changed, 91 insertions, 11 deletions
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; |