From b64ca18554366e8d817770575a7b815e6da932b2 Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Thu, 5 May 2022 09:39:44 +0800 Subject: [PATCH] =?UTF-8?q?js=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyb0625 --- .../kits/js/include/native_devicemanager_js.h | 1 + .../kits/js/src/native_devicemanager_js.cpp | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/interfaces/kits/js/include/native_devicemanager_js.h b/interfaces/kits/js/include/native_devicemanager_js.h index 8db0b6022..aa109c6df 100644 --- a/interfaces/kits/js/include/native_devicemanager_js.h +++ b/interfaces/kits/js/include/native_devicemanager_js.h @@ -311,5 +311,6 @@ private: std::string bundleName_; static AuthAsyncCallbackInfo authAsyncCallbackInfo_; static AuthAsyncCallbackInfo verifyAsyncCallbackInfo_; + std::map errCodeInfo_; }; #endif // OHOS_DM_NATIVE_DEVICEMANAGER_JS_H diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index acd42777c..912fa27e8 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -428,6 +428,38 @@ DeviceManagerNapi::DeviceManagerNapi(napi_env env, napi_value thisVar) : DmNativ { env_ = env; wrapper_ = nullptr; + errCodeInfo_.insert(std::pair(-0,"DeviceManager APIs called successfully.")); + errCodeInfo_.insert(std::pair(-20001,"DeviceManager APIs called failed. Please try again later.")); + errCodeInfo_.insert(std::pair(-20002,"DeviceManager internal process execution timed out. Please try again later.")); + errCodeInfo_.insert(std::pair(-20003,"DeviceManager service has not been initialized. Restart the device and try again.")); + errCodeInfo_.insert(std::pair(-20004,"DeviceManager service does not allowed repeated initialization.")); + errCodeInfo_.insert(std::pair(-20005,"DeviceManager service fails to be initialized. Restart the device and try again.")); + errCodeInfo_.insert(std::pair(-20006,"DeviceManager service abnormal. Restart the device and try again.")); + errCodeInfo_.insert(std::pair(-20007,"DeviceManager internal process occurs NullPointerException. Please try again later.")); + errCodeInfo_.insert(std::pair(-20008,"The API input parameter is invalid. Please confirm and try again.")); + errCodeInfo_.insert(std::pair(-20009,"The hap application has no permission to call DeviceManager APIs. Please confirm and try again.")); + errCodeInfo_.insert(std::pair(-20010,"Device resources are insufficient. Memory allocation failed. Restart the device and try again.")); + errCodeInfo_.insert(std::pair(-20011,"Device resources are insufficient. Memory copy failed. Restart the device and try again.")); + errCodeInfo_.insert(std::pair(-20012,"IPC process abnormal. Write object failed. Restart the device and try again.")); + errCodeInfo_.insert(std::pair(-20013,"Failed to discover devices. Please try again later.")); + errCodeInfo_.insert(std::pair(-20014,"DeviceManager service abnormal. Restart the device and try again.")); + errCodeInfo_.insert(std::pair(-20015,"Failed to call SubscribeProfileEvents API of DP module. Please try again later.")); + errCodeInfo_.insert(std::pair(-20016,"IPC process abnormal. Restart the device and try again.")); + errCodeInfo_.insert(std::pair(-20017,"IPC process failed to write data. Restart the device and try again.")); + errCodeInfo_.insert(std::pair(-20018,"IPC process failed to copy data. Restart the device and try again.")); + errCodeInfo_.insert(std::pair(-20019,"IPC process failed to send request. Restart the device and try again.")); + errCodeInfo_.insert(std::pair(-20020,"IPC process failed to register function. Restart the device and try again.")); + errCodeInfo_.insert(std::pair(-20021,"IPC process failed to receive response. Restart the device and try again.")); + errCodeInfo_.insert(std::pair(-20022,"IPC process failed to write token. Restart the device and try again.")); + errCodeInfo_.insert(std::pair(-20023,"Repeat device discovery is not allowed within 1 minute. Please try again later.")); + errCodeInfo_.insert(std::pair(-20024,"The device authentication request is being processed. Please try again later.")); + errCodeInfo_.insert(std::pair(-20025,"The AuthenticateDevice API input parameter is invalid. Please confirm and try again.")); + errCodeInfo_.insert(std::pair(-20026,"Failed to open authenticate session. Please restart the device and try again.")); + errCodeInfo_.insert(std::pair(-20027,"The remote device rejected the request. Please confirm and try again.")); + errCodeInfo_.insert(std::pair(-20028,"The local device rejected the request. Please confirm and try again.")); + errCodeInfo_.insert(std::pair(-20029,"The local device authentication failed. Please try again later.")); + errCodeInfo_.insert(std::pair(-20030,"The device authentication process has not started. Please try again later.")); + errCodeInfo_.insert(std::pair(-20031,"HiChain module failed to create user group. Please restart the device and try again.")); } DeviceManagerNapi::~DeviceManagerNapi() @@ -478,6 +510,15 @@ void DeviceManagerNapi::OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo & SetValueUtf8String(env_, "deviceName", deviceInfo.deviceName, device); SetValueInt32(env_, "deviceType", (int)deviceInfo.deviceTypeId, device); + std::map::iterator iter=errCodeInfo_.find(failedReason); + std::string tmp_iter; + if (iter != errCodeInfo_.end()) { + tmp_iter = iter->second; + LOGE("Found, the value is %s",tmp_iter.c_str()); + } else { + LOGI("Do not found"); + } + SetValueUtf8String(env_, "errInfo", tmp_iter, result);/// env std::string std::string napi_set_named_property(env_, result, "device", device); OnEvent("deviceFound", DM_NAPI_ARGS_ONE, &result); } @@ -510,6 +551,15 @@ void DeviceManagerNapi::OnAuthResult(const std::string &deviceId, const std::str napi_create_object(env_, &result[0]); SetValueInt32(env_, "code", status, result[0]); SetValueInt32(env_, "reason", reason, result[0]); + std::map::iterator iter=errCodeInfo_.find(reason); + std::string tmp_iter; + if (iter != errCodeInfo_.end()) { + tmp_iter = iter->second; + LOGE("Found, the value is %s",tmp_iter.c_str()); + } else { + LOGI("Do not found"); + } + SetValueUtf8String(env_, "errInfo", tmp_iter, result[0]);/// env std::string std::string napi_get_undefined(env_, &result[1]); } -- Gitee