Support for cardEmulationMode attribute of NFCAdaper added.
Change-Id: Ifc700942695702326387b662a596ed96bcf1d0d7
Signed-off-by: Marcin Kaminski <marcin.ka@samsung.com>
}
+std::string NFCAdapter::GetCardEmulationMode() {
+
+ LoggerD("Entered");
+
+ nfc_se_card_emulation_mode_type_e mode;
+ int ret = nfc_se_get_card_emulation_mode(&mode);
+
+ if (NFC_ERROR_NONE != ret) {
+ LoggerE("Failed to get card emulation mode %d", ret);
+ NFCUtil::throwNFCException(ret, "Failed to get card emulation mode");
+ }
+
+ return NFCUtil::toStringCardEmulationMode(mode);
+}
+
+void NFCAdapter::SetCardEmulationMode(std::string mode) {
+
+ LoggerD("Entered");
+
+ nfc_se_card_emulation_mode_type_e newmode =
+ NFCUtil::toCardEmulationMode(mode);
+ std::string current_mode = GetCardEmulationMode();
+
+ if (mode.compare(current_mode) == 0) {
+ LoggerD("Card emulation mode already set to given value (%s)",
+ mode.c_str());
+ return;
+ }
+
+ int ret = NFC_ERROR_NONE;
+ switch (newmode) {
+ case NFC_SE_CARD_EMULATION_MODE_OFF:
+ ret = nfc_se_disable_card_emulation();
+ break;
+ case NFC_SE_CARD_EMULATION_MODE_ON:
+ ret = nfc_se_enable_card_emulation();
+ break;
+ default:
+ // Should never go here - in case of invalid mode
+ // exception is thrown from convertert few lines above
+ LoggerE("Invalid card emulation mode: %s", mode.c_str());
+ throw InvalidValuesException("Invalid card emulation mode given");
+ }
+
+ if (NFC_ERROR_NONE != ret) {
+ LoggerE("Failed to set card emulation mode %d", ret);
+ NFCUtil::throwNFCException(ret, "Failed to set card emulation mode");
+ }
+}
+
+
}// nfc
}// extension
bool GetPowered();
void SetPowered(const picojson::value& args);
+// cardEmulationModer getter and setter
+ std::string GetCardEmulationMode();
+ void SetCardEmulationMode(std::string mode);
+
+
static NFCAdapter* GetInstance();
NFCInstance *xwalk_instance;
private:
return native_.getResultObject(ret);
}
+ function cardEmulationModeGetter() {
+ var result = native_.callSync('NFCAdapter_cardEmulationModeGetter');
+
+ if (native_.isFailure(result)) {
+ throw new tizen.WebAPIException(0, result.error.message, result.error.name);
+ }
+
+ return native_.getResultObject(result);
+ }
+
+ function cardEmulationModeSetter(cem) {
+ // "NFCAdapter_cardEmulationModeSetter"
+
+ var args = validator_.validateArgs(arguments, [
+ {name: 'emulationMode', type: types_.STRING}
+ ]);
+
+ var result = native_.callSync(
+ 'NFCAdapter_cardEmulationModeSetter',
+ { 'emulationMode': args.emulationMode}
+ );
+
+ if(native_.isFailure(result)) {
+ throw new tizen.WebAPIException(0, result.error.message, result.error.name);
+ }
+ return;
+ }
+
Object.defineProperties(this, {
powered: {enumerable: true,
set : function(){},
get : poweredGetter
},
cardEmulationMode: {enumerable: true,
- set : function(){},
- get : function(){}
+ set : cardEmulationModeSetter,
+ get : cardEmulationModeGetter
},
activeSecureElement: {enumerable: true,
set : function(){},
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "nfc/nfc_instance.h"
+#include "nfc_instance.h"
+#include "nfc_util.h"
#include "common/picojson.h"
#include "common/logger.h"
REGISTER_SYNC("NFCManager_getDefaultAdapter", GetDefaultAdapter);
REGISTER_SYNC("NFCManager_setExclusiveMode", SetExclusiveMode);
REGISTER_SYNC("NFCAdapter_getPowered", GetPowered);
+ REGISTER_SYNC("NFCAdapter_cardEmulationModeSetter", CardEmulationModeSetter);
+ REGISTER_SYNC("NFCAdapter_cardEmulationModeGetter", CardEmulationModeGetter);
REGISTER_SYNC("NFCAdapter_setPeerListener", SetPeerListener);
REGISTER_SYNC("NFCAdapter_setTagListener", SetTagListener);
REGISTER_SYNC("NFCAdapter_setPeerListener", SetPeerListener);
}
if (NFC_ERROR_NONE != ret) {
- LoggerE("setExclusiveModeForTransaction failed: %d", ret);
- switch(ret) {
- case NFC_ERROR_SECURITY_RESTRICTED:
- {
- auto ex = common::SecurityException("Not allowed to set exclusive mode");
- ReportError(ex, out);
- break;
- }
- case NFC_ERROR_OPERATION_FAILED:
- {
- auto ex = common::UnknownException("Setting exclusive mode failed (IPC fail)");
- ReportError(ex, out);
- break;
- }
- default:
- {
- auto ex = common::UnknownException("Unkown error");
- ReportError(ex, out);
- break;
- }
- }
- }
- else {
- ReportSuccess(out);
+ LoggerE("setExclusiveMode() failed: %d", ret);
+ NFCUtil::throwNFCException(ret, "Failed to set exclusie mode");
}
+ ReportSuccess(out);
+
}
void NFCInstance::SetPowered(
ReportSuccess(picojson::value(ret), out);
}
+void NFCInstance::CardEmulationModeSetter(
+ const picojson::value& args, picojson::object& out) {
+
+ std::string mode = args.get("emulationMode").get<std::string>();
+ try {
+ NFCAdapter::GetInstance()->SetCardEmulationMode(mode);
+ }
+ catch(const common::PlatformException& ex) {
+ ReportError(ex, out);
+ }
+ ReportSuccess(out);
+}
+
+void NFCInstance::CardEmulationModeGetter(
+ const picojson::value& args, picojson::object& out) {
+
+ std::string mode;
+ try {
+ mode = NFCAdapter::GetInstance()->GetCardEmulationMode();
+ }
+ catch(const common::PlatformException& ex) {
+ ReportError(ex, out);
+ }
+ ReportSuccess(picojson::value(mode), out);
+}
+
void NFCInstance::SetTagListener(
const picojson::value& args, picojson::object& out) {
void SetExclusiveMode(const picojson::value& args, picojson::object& out);
void SetPowered(const picojson::value& args, picojson::object& out);
void GetPowered(const picojson::value& args, picojson::object& out);
+ void CardEmulationModeSetter(const picojson::value& args, picojson::object& out);
+ void CardEmulationModeGetter(const picojson::value& args, picojson::object& out);
void SetTagListener(const picojson::value& args, picojson::object& out);
void SetPeerListener(const picojson::value& args, picojson::object& out);
void UnsetTagListener(const picojson::value& args, picojson::object& out);
throw InvalidValuesException(message);
break;
case NFC_ERROR_SECURITY_RESTRICTED:
+ case NFC_ERROR_PERMISSION_DENIED:
throw SecurityException(message);
break;
case NFC_ERROR_NOT_ACTIVATED: