From e54d0bddf68a3ee1eff98d355d1a521d5b3b5e0c Mon Sep 17 00:00:00 2001 From: renguang1116 Date: Sun, 30 Jan 2022 15:58:32 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=9A=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E9=97=AE=E9=A2=98=20Signed-off-by:=20renguang1116=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bundle.json | 2 +- .../dialog_ui/js/pages/index/index.css | 22 +- .../dialog_ui/js/pages/index/index.hml | 2 +- .../include/dialog_ui/js/pages/index/index.js | 11 - common/include/dm_constants.h | 6 +- .../dialog_ui/js/pages/index/index.css | 35 +- .../dialog_ui/js/pages/index/index.hml | 7 +- .../dialog_ui/js/pages/index/index.js | 28 +- ext/pin_auth/include/pin_auth.h | 2 +- ext/pin_auth/include/pin_auth_ui.h | 2 +- ext/pin_auth/src/pin_auth.cpp | 4 +- ext/pin_auth/src/pin_auth_ui.cpp | 13 +- .../dialog_ui/js/pages/index/index.css | 18 +- .../dialog_ui/js/pages/index/index.js | 1 + .../kits/js/include/native_devicemanager_js.h | 57 ++- .../kits/js/src/native_devicemanager_js.cpp | 324 +++++++++++++++--- .../include/authentication/authentication.h | 2 +- .../include/authentication/dm_auth_manager.h | 3 + .../src/authentication/dm_auth_manager.cpp | 13 +- 19 files changed, 408 insertions(+), 144 deletions(-) diff --git a/bundle.json b/bundle.json index a204d9be7..4f20bcf82 100644 --- a/bundle.json +++ b/bundle.json @@ -13,7 +13,7 @@ "component": { "name": "device_manager_base", "subsystem": "distributedhardware", - "syscap":[ "systemcapbility.distributedhardware.devicemanager" ], + "syscap":[ "SystemCapability.DistributedHardware.DeviceManager" ], "features":[], "adapted_system_type": [ "standard", "small" ], "rom": "2M", diff --git a/common/include/dialog_ui/js/pages/index/index.css b/common/include/dialog_ui/js/pages/index/index.css index b87a3962a..997f0c8af 100644 --- a/common/include/dialog_ui/js/pages/index/index.css +++ b/common/include/dialog_ui/js/pages/index/index.css @@ -7,8 +7,8 @@ } .title { - font-size: 48px; - line-height: 70px; + font-size: 80px; + line-height: 150px; font-weight: 800; } @@ -16,26 +16,26 @@ width: 85%; margin-top: 10%; text-align: center; - height: 45px; + height: 100px; } .but1 { - width: 40%; - height: 36px; - font-size: 26px; + width: 30%; + height: 80px; + font-size: 50px; margin-left: 10%; } .but2 { - width: 20%; - height: 36px; - font-size: 26px; + width: 30%; + height: 80px; + font-size: 50px; margin-left: 55%; } .title-list { - font-size: 38px; - line-height: 40px; + font-size: 70px; + line-height: 100px; font-weight: 800; } diff --git a/common/include/dialog_ui/js/pages/index/index.hml b/common/include/dialog_ui/js/pages/index/index.hml index 81ab90ff6..0ab94e3af 100644 --- a/common/include/dialog_ui/js/pages/index/index.hml +++ b/common/include/dialog_ui/js/pages/index/index.hml @@ -7,7 +7,7 @@
-
diff --git a/ext/input_pin_dialog/dialog_ui/js/pages/index/index.js b/ext/input_pin_dialog/dialog_ui/js/pages/index/index.js index 8a38e6188..fc6a23af6 100644 --- a/ext/input_pin_dialog/dialog_ui/js/pages/index/index.js +++ b/ext/input_pin_dialog/dialog_ui/js/pages/index/index.js @@ -1,4 +1,4 @@ -import router from '@ohos.router' +import router from '@ohos.router'; var numbs = 0; export default { @@ -9,22 +9,20 @@ export default { console.info('getParams: ' + router.getParams()); }, onConfirm() { - console.info('click confirm'); + console.info('click inpout confirm numbs'+ numbs); + console.info('click inpout confirm'); numbs = numbs + 1; - if (numbs < 3){ - var input= document.getElementById("input").value; - console.info('input: ' + input); - console.info('pincode: ' + pincode); - if (input == pincode){ - console.info('pincode: = input'); - callNativeHandler(input, "0"); - } else { - console.info('pincode: != input'); - //刷新页面,提示输入错误 - } + console.info('click inpout confirm numbs'+ numbs); + console.info('click confirm start'); + var input= this.$element('input').value; + console.info('click confirm end'); + console.info('input: ' + input); + console.info('pincode: ' + pincode); + if (input == pincode){ + console.info('pincode: = input'); + callNativeHandler(input, "0"); } else { - console.info('click cancel'); - callNativeHandler("EVENT_CONFIRM", "1"); + console.info('pincode: != input'); } }, onCancel() { diff --git a/ext/pin_auth/include/pin_auth.h b/ext/pin_auth/include/pin_auth.h index b2636e0af..dca2e7e7f 100644 --- a/ext/pin_auth/include/pin_auth.h +++ b/ext/pin_auth/include/pin_auth.h @@ -30,7 +30,7 @@ class PinAuth : public IAuthentication { public: PinAuth(); ~PinAuth(); - int32_t ShowAuthInfo(int32_t code) override; + int32_t ShowAuthInfo(int32_t code, std::shared_ptr authManager) override; int32_t StartAuth(int32_t code, std::shared_ptr authManager) override; int32_t VerifyAuthentication(std::string pinToken, int32_t code, const std::string &authParam) override; diff --git a/ext/pin_auth/include/pin_auth_ui.h b/ext/pin_auth/include/pin_auth_ui.h index 61575797f..5ff26c3e1 100644 --- a/ext/pin_auth/include/pin_auth_ui.h +++ b/ext/pin_auth/include/pin_auth_ui.h @@ -26,7 +26,7 @@ namespace DistributedHardware { class PinAuthUi { public: PinAuthUi(); - int32_t ShowPinDialog(int32_t code); + int32_t ShowPinDialog(int32_t code, std::shared_ptr authManager); int32_t InputPinDialog(int32_t code, std::shared_ptr authManager); private: diff --git a/ext/pin_auth/src/pin_auth.cpp b/ext/pin_auth/src/pin_auth.cpp index 138abc56f..0bbadd15f 100644 --- a/ext/pin_auth/src/pin_auth.cpp +++ b/ext/pin_auth/src/pin_auth.cpp @@ -33,9 +33,9 @@ PinAuth::~PinAuth() { } -int32_t PinAuth::ShowAuthInfo(int32_t code) +int32_t PinAuth::ShowAuthInfo(int32_t code, std::shared_ptr authManager) { - return pinAuthUi_->ShowPinDialog(code); + return pinAuthUi_->ShowPinDialog(code, authManager); } int32_t PinAuth::StartAuth(int32_t code, std::shared_ptr authManager) diff --git a/ext/pin_auth/src/pin_auth_ui.cpp b/ext/pin_auth/src/pin_auth_ui.cpp index a3cfeefe2..51f76bdb4 100644 --- a/ext/pin_auth/src/pin_auth_ui.cpp +++ b/ext/pin_auth/src/pin_auth_ui.cpp @@ -28,7 +28,7 @@ PinAuthUi::PinAuthUi() LOGI("AuthUi constructor"); } -int32_t PinAuthUi::ShowPinDialog(int32_t code) +int32_t PinAuthUi::ShowPinDialog(int32_t code, std::shared_ptr authManager) { LOGI("ShowPinDialog start"); nlohmann::json jsonObj; @@ -41,9 +41,14 @@ int32_t PinAuthUi::ShowPinDialog(int32_t code) params, OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, ACE_X, ACE_Y, ACE_WIDTH, ACE_HEIGHT, - [](int32_t id, const std::string& event, const std::string& params) { - LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); - Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + [authManager](int32_t id, const std::string& event, const std::string& params) { + if (strcmp(params.c_str(), "0") == 0) { + authManager->ClosePage(id); + } + if (strcmp(params.c_str(), "1") == 0) { + LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + } }); LOGI("ShowConfigDialog end"); return DM_OK; diff --git a/ext/show_pin_dialog/dialog_ui/js/pages/index/index.css b/ext/show_pin_dialog/dialog_ui/js/pages/index/index.css index feb20b4fd..4e83197eb 100644 --- a/ext/show_pin_dialog/dialog_ui/js/pages/index/index.css +++ b/ext/show_pin_dialog/dialog_ui/js/pages/index/index.css @@ -7,25 +7,25 @@ } .title { - font-size: 48px; - line-height: 50px; + font-size: 80px; + line-height: 120px; font-weight: 800; } .title-list { - font-size: 38px; - line-height: 40px; + font-size: 60px; + line-height: 100px; font-weight: 800; } .title-pin { - font-size: 48px; - line-height: 50px; + font-size: 60px; + line-height: 100px; font-weight: 800; } .but { - width: 100%; - font-size: 26px; - height: 36px; + width: 30%; + font-size: 50px; + height: 80px; } \ No newline at end of file diff --git a/ext/show_pin_dialog/dialog_ui/js/pages/index/index.js b/ext/show_pin_dialog/dialog_ui/js/pages/index/index.js index 114655c3a..3a55ac1cc 100644 --- a/ext/show_pin_dialog/dialog_ui/js/pages/index/index.js +++ b/ext/show_pin_dialog/dialog_ui/js/pages/index/index.js @@ -6,6 +6,7 @@ export default { }, onInit() { console.info('getParams: ' + router.getParams()); + callNativeHandler("EVENT_CONFIRM", "0"); }, onConfirm() { console.info('click confirm'); diff --git a/interfaces/kits/js/include/native_devicemanager_js.h b/interfaces/kits/js/include/native_devicemanager_js.h index b05fef48f..84348c505 100644 --- a/interfaces/kits/js/include/native_devicemanager_js.h +++ b/interfaces/kits/js/include/native_devicemanager_js.h @@ -56,6 +56,7 @@ struct DeviceInfoAsyncCallbackInfo { int32_t status = -1; int32_t isList = 0; }; + struct AuthAsyncCallbackInfo { napi_env env = nullptr; @@ -66,11 +67,44 @@ struct AuthAsyncCallbackInfo { int32_t authType = -1; }; +struct DmNapiStateJsCallback { + std::string bundleName_; + uint16_t subscribeId_; + int32_t reason_; + OHOS::DistributedHardware::DmDeviceInfo deviceInfo_; + + DmNapiStateJsCallback(std::string bundleName, uint16_t subscribeId, int32_t reason, + OHOS::DistributedHardware::DmDeviceInfo deviceInfo) + : bundleName_(bundleName), subscribeId_(subscribeId), reason_(reason), deviceInfo_(deviceInfo) {} +}; + +struct DmNapiAuthJsCallback { + std::string bundleName_; + std::string deviceId_; + std::string token_; + int32_t status_; + int32_t reason_; + + DmNapiAuthJsCallback(std::string bundleName, std::string deviceId, std::string token, int32_t status, + int32_t reason) + : bundleName_(bundleName), deviceId_(deviceId), token_(token), status_(status), reason_(reason) {} +}; + +struct DmNapiVerifyJsCallback { + std::string bundleName_; + std::string deviceId_; + int32_t resultCode_; + int32_t flag_; + + DmNapiVerifyJsCallback(std::string bundleName, std::string deviceId, int32_t resultCode, int32_t flag) + : bundleName_(bundleName), deviceId_(deviceId), resultCode_(resultCode), flag_(flag) {} +}; + enum DmNapiDevStateChangeAction { ONLINE = 0, READY = 1, OFFLINE = 2, CHANGE = 3 }; class DmNapiInitCallback : public OHOS::DistributedHardware::DmInitCallback { public: - explicit DmNapiInitCallback(std::string &bundleName) : bundleName_(bundleName) + explicit DmNapiInitCallback(napi_env env, std::string &bundleName) : env_(env), bundleName_(bundleName) { } virtual ~DmNapiInitCallback() @@ -79,12 +113,13 @@ public: void OnRemoteDied() override; private: + napi_env env_; std::string bundleName_; }; class DmNapiDeviceStateCallback : public OHOS::DistributedHardware::DeviceStateCallback { public: - explicit DmNapiDeviceStateCallback(std::string &bundleName) : bundleName_(bundleName) + explicit DmNapiDeviceStateCallback(napi_env env, std::string &bundleName) : env_(env), bundleName_(bundleName) { } virtual ~DmNapiDeviceStateCallback() {}; @@ -94,12 +129,14 @@ public: void OnDeviceChanged(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override; private: + napi_env env_; std::string bundleName_; }; class DmNapiDiscoveryCallback : public OHOS::DistributedHardware::DiscoveryCallback { public: - explicit DmNapiDiscoveryCallback(std::string &bundleName) : refCount_(0), bundleName_(bundleName) + explicit DmNapiDiscoveryCallback(napi_env env, std::string &bundleName) + : env_(env), refCount_(0), bundleName_(bundleName) { } virtual ~DmNapiDiscoveryCallback() {}; @@ -111,43 +148,47 @@ public: int32_t GetRefCount(); private: + napi_env env_; std::atomic refCount_; std::string bundleName_; }; class DmNapiDeviceManagerFaCallback : public OHOS::DistributedHardware::DeviceManagerFaCallback { public: - explicit DmNapiDeviceManagerFaCallback(std::string &bundleName) : bundleName_(bundleName) + explicit DmNapiDeviceManagerFaCallback(napi_env env, std::string &bundleName) : env_(env), bundleName_(bundleName) { } virtual ~DmNapiDeviceManagerFaCallback() {}; void OnCall(const std::string ¶mJson) override; private: + napi_env env_; std::string bundleName_; }; class DmNapiAuthenticateCallback : public OHOS::DistributedHardware::AuthenticateCallback { public: - explicit DmNapiAuthenticateCallback(std::string &bundleName) : bundleName_(bundleName) + explicit DmNapiAuthenticateCallback(napi_env env, std::string &bundleName) : env_(env), bundleName_(bundleName) { } virtual ~DmNapiAuthenticateCallback() {}; void OnAuthResult(const std::string &deviceId, const std::string &token, int32_t status, int32_t reason) override; private: + napi_env env_; std::string bundleName_; }; class DmNapiVerifyAuthCallback : public OHOS::DistributedHardware::VerifyAuthCallback { public: - explicit DmNapiVerifyAuthCallback(std::string &bundleName) : bundleName_(bundleName) + explicit DmNapiVerifyAuthCallback(napi_env env, std::string &bundleName) : env_(env), bundleName_(bundleName) { } virtual ~DmNapiVerifyAuthCallback() {}; void OnVerifyAuthResult(const std::string &deviceId, int32_t resultCode, int32_t flag) override; private: + napi_env env_; std::string bundleName_; }; @@ -174,7 +215,7 @@ public: static napi_value GetAuthenticationParamSync(napi_env env, napi_callback_info info); static void HandleCreateDmCallBack(const napi_env &env, AsyncCallbackInfo *asCallbackInfo); static DeviceManagerNapi *GetDeviceManagerNapi(std::string &buldleName); - static void CreateDmCallback(std::string &bundleName, std::string &eventType); + static void CreateDmCallback(napi_env env, std::string &bundleName, std::string &eventType); static void ReleaseDmCallback(std::string &bundleName, std::string &eventType); static void DeviceInfoToJsArray(const napi_env &env, const std::vector &vecDevInfo, @@ -235,7 +276,7 @@ private: private: napi_env env_; napi_ref wrapper_; - static napi_ref sConstructor_; + static thread_local napi_ref sConstructor_; std::string bundleName_; static AuthAsyncCallbackInfo authAsyncCallbackInfo_; static AuthAsyncCallbackInfo verifyAsyncCallbackInfo_; diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index c314e669c..50add0353 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -16,6 +16,7 @@ #include "native_devicemanager_js.h" #include +#include #include "device_manager.h" #include "dm_constants.h" @@ -56,81 +57,238 @@ std::map> g_verifyAuthCal std::map> g_dmfaCallbackMap; } // namespace -napi_ref DeviceManagerNapi::sConstructor_ = nullptr; +thread_local napi_ref DeviceManagerNapi::sConstructor_ = nullptr; AuthAsyncCallbackInfo DeviceManagerNapi::authAsyncCallbackInfo_; AuthAsyncCallbackInfo DeviceManagerNapi::verifyAsyncCallbackInfo_; void DmNapiInitCallback::OnRemoteDied() { - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); - if (deviceManagerNapi == nullptr) { - LOGE("OnRemoteDied, deviceManagerNapi not find for bunderName %s", bundleName_.c_str()); + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(env_, &loop); + if (loop == nullptr) { + return; + } + uv_work_t *work = new (std::nothrow) uv_work_t; + if (loop == nullptr) { + LOGE("DmNapiInitCallback: OnRemoteDied, No memory"); return; } - deviceManagerNapi->OnEvent("serviceDie", 0, nullptr); + DmDeviceInfo info; + std::unique_ptr jsCallback = + std::make_unique(bundleName_, 0, 0, info); + work->data = reinterpret_cast(jsCallback.get()); + + int ret = uv_queue_work(loop, work, [] (uv_work_t *work) {}, [] (uv_work_t *work, int status) { + DmNapiStateJsCallback *callback = reinterpret_cast(work->data); + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(callback->bundleName_); + if (deviceManagerNapi == nullptr) { + LOGE("OnRemoteDied, deviceManagerNapi not find for bunderName %s", callback->bundleName_.c_str()); + return; + } + deviceManagerNapi->OnEvent("serviceDie", 0, nullptr); + delete work; + }); + if (ret != 0) { + LOGE("Failed to execute OnRemoteDied work queue"); + delete work; + } } void DmNapiDeviceStateCallback::OnDeviceOnline(const DmDeviceInfo &deviceInfo) { - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); - if (deviceManagerNapi == nullptr) { - LOGE("OnDeviceOnline, deviceManagerNapi not find for bunderName %s", bundleName_.c_str()); + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(env_, &loop); + if (loop == nullptr) { return; } - deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::ONLINE, deviceInfo); + uv_work_t *work = new (std::nothrow) uv_work_t; + if (loop == nullptr) { + LOGE("DmNapiDeviceStateCallback: OnDeviceOnline, No memory"); + return; + } + std::unique_ptr jsCallback = + std::make_unique(bundleName_, 0, 0, deviceInfo); + work->data = reinterpret_cast(jsCallback.get()); + + int ret = uv_queue_work(loop, work, [] (uv_work_t *work) {}, [] (uv_work_t *work, int status) { + DmNapiStateJsCallback *callback = reinterpret_cast(work->data); + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(callback->bundleName_); + if (deviceManagerNapi == nullptr) { + LOGE("OnDeviceOnline, deviceManagerNapi not find for bunderName %s", callback->bundleName_.c_str()); + return; + } + deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::ONLINE, callback->deviceInfo_); + delete work; + }); + if (ret != 0) { + LOGE("Failed to execute OnDeviceOnline work queue"); + delete work; + } } void DmNapiDeviceStateCallback::OnDeviceReady(const DmDeviceInfo &deviceInfo) { - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); - if (deviceManagerNapi == nullptr) { - LOGE("OnDeviceOnline, deviceManagerNapi not find for bunderName %s", bundleName_.c_str()); + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(env_, &loop); + if (loop == nullptr) { return; } - deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::READY, deviceInfo); + uv_work_t *work = new (std::nothrow) uv_work_t; + if (loop == nullptr) { + LOGE("DmNapiDeviceStateCallback: OnDeviceReady, No memory"); + return; + } + std::unique_ptr jsCallback = + std::make_unique(bundleName_, 0, 0, deviceInfo); + work->data = reinterpret_cast(jsCallback.get()); + + int ret = uv_queue_work(loop, work, [] (uv_work_t *work) {}, [] (uv_work_t *work, int status) { + DmNapiStateJsCallback *callback = reinterpret_cast(work->data); + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(callback->bundleName_); + if (deviceManagerNapi == nullptr) { + LOGE("OnDeviceReady, deviceManagerNapi not find for bunderName %s", callback->bundleName_.c_str()); + return; + } + deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::READY, callback->deviceInfo_); + delete work; + }); + if (ret != 0) { + LOGE("Failed to execute OnDeviceReady work queue"); + delete work; + } } void DmNapiDeviceStateCallback::OnDeviceOffline(const DmDeviceInfo &deviceInfo) { - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); - if (deviceManagerNapi == nullptr) { - LOGE("OnDeviceOffline, deviceManagerNapi not find for bunderName %s", bundleName_.c_str()); + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(env_, &loop); + if (loop == nullptr) { return; } - deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::OFFLINE, deviceInfo); + uv_work_t *work = new (std::nothrow) uv_work_t; + if (loop == nullptr) { + LOGE("DmNapiDeviceStateCallback: OnDeviceOffline, No memory"); + return; + } + std::unique_ptr jsCallback = + std::make_unique(bundleName_, 0, 0, deviceInfo); + work->data = reinterpret_cast(jsCallback.get()); + + int ret = uv_queue_work(loop, work, [] (uv_work_t *work) {}, [] (uv_work_t *work, int status) { + DmNapiStateJsCallback *callback = reinterpret_cast(work->data); + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(callback->bundleName_); + if (deviceManagerNapi == nullptr) { + LOGE("OnDeviceOffline, deviceManagerNapi not find for bunderName %s", callback->bundleName_.c_str()); + return; + } + deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::OFFLINE, callback->deviceInfo_); + delete work; + }); + if (ret != 0) { + LOGE("Failed to execute OnDeviceOffline work queue"); + delete work; + } } void DmNapiDeviceStateCallback::OnDeviceChanged(const DmDeviceInfo &deviceInfo) { - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); - if (deviceManagerNapi == nullptr) { - LOGE("OnDeviceChanged, deviceManagerNapi not find for bunderName %s", bundleName_.c_str()); + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(env_, &loop); + if (loop == nullptr) { return; } - deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::CHANGE, deviceInfo); + uv_work_t *work = new (std::nothrow) uv_work_t; + if (loop == nullptr) { + LOGE("DmNapiDeviceStateCallback: OnDeviceChanged, No memory"); + return; + } + std::unique_ptr jsCallback = + std::make_unique(bundleName_, 0, 0, deviceInfo); + work->data = reinterpret_cast(jsCallback.get()); + + int ret = uv_queue_work(loop, work, [] (uv_work_t *work) {}, [] (uv_work_t *work, int status) { + DmNapiStateJsCallback *callback = reinterpret_cast(work->data); + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(callback->bundleName_); + if (deviceManagerNapi == nullptr) { + LOGE("OnDeviceChanged, deviceManagerNapi not find for bunderName %s", callback->bundleName_.c_str()); + return; + } + deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::CHANGE, callback->deviceInfo_); + delete work; + }); + if (ret != 0) { + LOGE("Failed to execute OnDeviceChanged work queue"); + delete work; + } } void DmNapiDiscoveryCallback::OnDeviceFound(uint16_t subscribeId, const DmDeviceInfo &deviceInfo) { - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); - if (deviceManagerNapi == nullptr) { - LOGE("OnDeviceFound, deviceManagerNapi not find for bunderName %s", bundleName_.c_str()); + LOGI("OnDeviceFound for %s, subscribeId %d", bundleName_.c_str(), (int32_t)subscribeId); + + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(env_, &loop); + if (loop == nullptr) { return; } + uv_work_t *work = new (std::nothrow) uv_work_t; + if (loop == nullptr) { + LOGE("DmNapiDiscoveryCallback: OnDeviceFound, No memory"); + return; + } + std::unique_ptr jsCallback = + std::make_unique(bundleName_, subscribeId, 0, deviceInfo); + work->data = reinterpret_cast(jsCallback.get()); - LOGI("OnDeviceFound for %s, subscribeId %d", bundleName_.c_str(), (int32_t)subscribeId); - deviceManagerNapi->OnDeviceFound(subscribeId, deviceInfo); + int ret = uv_queue_work(loop, work, [] (uv_work_t *work) {}, [] (uv_work_t *work, int status) { + DmNapiStateJsCallback *callback = reinterpret_cast(work->data); + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(callback->bundleName_); + if (deviceManagerNapi == nullptr) { + LOGE("OnDeviceFound, deviceManagerNapi not find for bunderName %s", callback->bundleName_.c_str()); + return; + } + deviceManagerNapi->OnDeviceFound(callback->subscribeId_, callback->deviceInfo_); + delete work; + }); + if (ret != 0) { + LOGE("Failed to execute OnDeviceFound work queue"); + delete work; + } } void DmNapiDiscoveryCallback::OnDiscoveryFailed(uint16_t subscribeId, int32_t failedReason) { - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); - if (deviceManagerNapi == nullptr) { - LOGE("OnDiscoveryFailed, deviceManagerNapi not find for bunderName %s", bundleName_.c_str()); + LOGI("OnDiscoveryFailed for %s, subscribeId %d", bundleName_.c_str(), (int32_t)subscribeId); + + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(env_, &loop); + if (loop == nullptr) { + return; + } + uv_work_t *work = new (std::nothrow) uv_work_t; + if (loop == nullptr) { + LOGE("DmNapiDiscoveryCallback: OnDiscoveryFailed, No memory"); return; } + DmDeviceInfo info; + std::unique_ptr jsCallback = + std::make_unique(bundleName_, subscribeId, failedReason, info); + work->data = reinterpret_cast(jsCallback.get()); - deviceManagerNapi->OnDiscoveryFailed(subscribeId, failedReason); + int ret = uv_queue_work(loop, work, [] (uv_work_t *work) {}, [] (uv_work_t *work, int status) { + DmNapiStateJsCallback *callback = reinterpret_cast(work->data); + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(callback->bundleName_); + if (deviceManagerNapi == nullptr) { + LOGE("OnDiscoveryFailed, deviceManagerNapi not find for bunderName %s", callback->bundleName_.c_str()); + return; + } + deviceManagerNapi->OnDiscoveryFailed(callback->subscribeId_, callback->reason_); + delete work; + }); + if (ret != 0) { + LOGE("Failed to execute OnDiscoveryFailed work queue"); + delete work; + } } void DmNapiDiscoveryCallback::OnDiscoverySuccess(uint16_t subscribeId) @@ -161,22 +319,66 @@ int32_t DmNapiDiscoveryCallback::GetRefCount() void DmNapiAuthenticateCallback::OnAuthResult(const std::string &deviceId, const std::string &token, int32_t status, int32_t reason) { - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); - if (deviceManagerNapi == nullptr) { - LOGE("OnAuthResult, deviceManagerNapi not find for bunderName %s", bundleName_.c_str()); + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(env_, &loop); + if (loop == nullptr) { + return; + } + uv_work_t *work = new (std::nothrow) uv_work_t; + if (loop == nullptr) { + LOGE("DmNapiAuthenticateCallback: OnAuthResult, No memory"); return; } - deviceManagerNapi->OnAuthResult(deviceId, token, status, reason); + std::unique_ptr jsCallback = + std::make_unique(bundleName_, deviceId, token, status, reason); + work->data = reinterpret_cast(jsCallback.get()); + + int ret = uv_queue_work(loop, work, [] (uv_work_t *work) {}, [] (uv_work_t *work, int status) { + DmNapiAuthJsCallback *callback = reinterpret_cast(work->data); + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(callback->bundleName_); + if (deviceManagerNapi == nullptr) { + LOGE("OnAuthResult, deviceManagerNapi not find for bunderName %s", callback->bundleName_.c_str()); + return; + } + deviceManagerNapi->OnAuthResult(callback->deviceId_, callback->token_, callback->status_, callback->reason_); + delete work; + }); + if (ret != 0) { + LOGE("Failed to execute OnAuthResult work queue"); + delete work; + } } void DmNapiVerifyAuthCallback::OnVerifyAuthResult(const std::string &deviceId, int32_t resultCode, int32_t flag) { - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); - if (deviceManagerNapi == nullptr) { - LOGE("OnCheckAuthResult, deviceManagerNapi not find for bunderName %s", bundleName_.c_str()); + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(env_, &loop); + if (loop == nullptr) { + return; + } + uv_work_t *work = new (std::nothrow) uv_work_t; + if (loop == nullptr) { + LOGE("DmNapiVerifyAuthCallback: OnVerifyAuthResult, No memory"); return; } - deviceManagerNapi->OnVerifyResult(deviceId, resultCode, flag); + std::unique_ptr jsCallback = + std::make_unique(bundleName_, deviceId, resultCode, flag); + work->data = reinterpret_cast(jsCallback.get()); + + int ret = uv_queue_work(loop, work, [] (uv_work_t *work) {}, [] (uv_work_t *work, int status) { + DmNapiVerifyJsCallback *callback = reinterpret_cast(work->data); + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(callback->bundleName_); + if (deviceManagerNapi == nullptr) { + LOGE("OnVerifyAuthResult, deviceManagerNapi not find for bunderName %s", callback->bundleName_.c_str()); + return; + } + deviceManagerNapi->OnVerifyResult(callback->deviceId_, callback->resultCode_, callback->flag_); + delete work; + }); + if (ret != 0) { + LOGE("Failed to execute OnVerifyAuthResult work queue"); + delete work; + } } DeviceManagerNapi::DeviceManagerNapi(napi_env env, napi_value thisVar) : DmNativeEvent(env, thisVar) @@ -669,13 +871,13 @@ void DeviceManagerNapi::DmDeviceInfotoJsDeviceInfo(const napi_env &env, const Dm SetValueInt32(env, "deviceType", (int)vecDevInfo.deviceTypeId, result); } -void DeviceManagerNapi::CreateDmCallback(std::string &bundleName, std::string &eventType) +void DeviceManagerNapi::CreateDmCallback(napi_env env, std::string &bundleName, std::string &eventType) { LOGE("CreateDmCallback for bundleName %s eventType %s", bundleName.c_str(), eventType.c_str()); if (eventType == DM_NAPI_EVENT_DEVICE_STATE_CHANGE) { auto iter = g_deviceStateCallbackMap.find(bundleName); if (iter == g_deviceStateCallbackMap.end()) { - auto callback = std::make_shared(bundleName); + auto callback = std::make_shared(env, bundleName); std::string extra = ""; int32_t ret = DeviceManager::GetInstance().RegisterDevStateCallback(bundleName, extra, callback); if (ret != 0) { @@ -691,7 +893,7 @@ void DeviceManagerNapi::CreateDmCallback(std::string &bundleName, std::string &e std::shared_ptr DiscoveryCallback = nullptr; auto iter = g_DiscoveryCallbackMap.find(bundleName); if (iter == g_DiscoveryCallbackMap.end()) { - auto callback = std::make_shared(bundleName); + auto callback = std::make_shared(env, bundleName); g_DiscoveryCallbackMap[bundleName] = callback; DiscoveryCallback = callback; } else { @@ -705,7 +907,7 @@ void DeviceManagerNapi::CreateDmCallback(std::string &bundleName, std::string &e if (eventType == DM_NAPI_EVENT_DMFA_CALLBACK) { auto iter = g_dmfaCallbackMap.find(bundleName); if (iter == g_dmfaCallbackMap.end()) { - auto callback = std::make_shared(bundleName); + auto callback = std::make_shared(env, bundleName); int32_t ret = DeviceManager::GetInstance().RegisterDeviceManagerFaCallback(bundleName, callback); if (ret != 0) { LOGE("RegisterDeviceManagerFaCallback failed for bunderName %s", bundleName.c_str()); @@ -844,12 +1046,32 @@ void DeviceManagerNapi::CallGetTrustedDeviceListStatusSync(napi_env env, napi_st void DmNapiDeviceManagerFaCallback::OnCall(const std::string ¶mJson) { - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(bundleName_); - if (deviceManagerNapi == nullptr) { - LOGE("OnCall, deviceManagerNapi not find for bunderName %s", bundleName_.c_str()); + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(env_, &loop); + if (loop == nullptr) { + return; + } + uv_work_t *work = new (std::nothrow) uv_work_t; + if (loop == nullptr) { + LOGE("DmNapiDeviceManagerFaCallback: OnCall, No memory"); return; } - deviceManagerNapi->OnDmfaCall(paramJson); + + static std::string staticBundleName = bundleName_; + static std::string staticParamJson = paramJson; + int ret = uv_queue_work(loop, work, [] (uv_work_t *work) {}, [] (uv_work_t *work, int status) { + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(staticBundleName); + if (deviceManagerNapi == nullptr) { + LOGE("OnCall, deviceManagerNapi not find for bunderName %s", staticBundleName.c_str()); + return; + } + deviceManagerNapi->OnDmfaCall(staticParamJson); + delete work; + }); + if (ret != 0) { + LOGE("Failed to execute OnCall work queue"); + delete work; + } } void DeviceManagerNapi::OnDmfaCall(const std::string ¶mJson) @@ -1245,7 +1467,7 @@ napi_value DeviceManagerNapi::StartDeviceDiscoverSync(napi_env env, napi_callbac std::shared_ptr DiscoveryCallback = nullptr; auto iter = g_DiscoveryCallbackMap.find(deviceManagerWrapper->bundleName_); if (iter == g_DiscoveryCallbackMap.end()) { - DiscoveryCallback = std::make_shared(deviceManagerWrapper->bundleName_); + DiscoveryCallback = std::make_shared(env, deviceManagerWrapper->bundleName_); g_DiscoveryCallbackMap[deviceManagerWrapper->bundleName_] = DiscoveryCallback; } else { DiscoveryCallback = iter->second; @@ -1319,7 +1541,7 @@ napi_value DeviceManagerNapi::AuthenticateDevice(napi_env env, napi_callback_inf std::shared_ptr authCallback = nullptr; auto iter = g_authCallbackMap.find(deviceManagerWrapper->bundleName_); if (iter == g_authCallbackMap.end()) { - authCallback = std::make_shared(deviceManagerWrapper->bundleName_); + authCallback = std::make_shared(env, deviceManagerWrapper->bundleName_); g_authCallbackMap[deviceManagerWrapper->bundleName_] = authCallback; } else { authCallback = iter->second; @@ -1359,7 +1581,7 @@ napi_value DeviceManagerNapi::VerifyAuthInfo(napi_env env, napi_callback_info in std::shared_ptr verifyCallback = nullptr; auto iter = g_verifyAuthCallbackMap.find(deviceManagerWrapper->bundleName_); if (iter == g_verifyAuthCallbackMap.end()) { - verifyCallback = std::make_shared(deviceManagerWrapper->bundleName_); + verifyCallback = std::make_shared(env, deviceManagerWrapper->bundleName_); g_verifyAuthCallbackMap[deviceManagerWrapper->bundleName_] = verifyCallback; } else { verifyCallback = iter->second; @@ -1394,7 +1616,7 @@ napi_value DeviceManagerNapi::JsOnFrench(napi_env env, int32_t num, napi_value t LOGI("JsOn for bunderName %s, eventType %s ", deviceManagerWrapper->bundleName_.c_str(), eventType.c_str()); deviceManagerWrapper->On(eventType, argv[num + 1]); - CreateDmCallback(deviceManagerWrapper->bundleName_, eventType); + CreateDmCallback(env, deviceManagerWrapper->bundleName_, eventType); napi_value result = nullptr; napi_get_undefined(env, &result); @@ -1546,7 +1768,7 @@ void DeviceManagerNapi::HandleCreateDmCallBack(const napi_env &env, AsyncCallbac (void)env; AsyncCallbackInfo *asCallbackInfo = (AsyncCallbackInfo *)data; std::string bundleName = std::string(asCallbackInfo->bundleName); - std::shared_ptr initCallback = std::make_shared(bundleName); + std::shared_ptr initCallback = std::make_shared(env, bundleName); if (DeviceManager::GetInstance().InitDeviceManager(bundleName, initCallback) != 0) { LOGE("InitDeviceManager for bunderName %s failed", bundleName.c_str()); return; diff --git a/services/devicemanagerservice/include/authentication/authentication.h b/services/devicemanagerservice/include/authentication/authentication.h index 43c486511..67ca0c3ee 100644 --- a/services/devicemanagerservice/include/authentication/authentication.h +++ b/services/devicemanagerservice/include/authentication/authentication.h @@ -24,7 +24,7 @@ class DmAuthManager; class IAuthentication { public: virtual ~IAuthentication() = default; - virtual int32_t ShowAuthInfo(int32_t code) = 0; + virtual int32_t ShowAuthInfo(int32_t code, std::shared_ptr authManager) = 0; virtual int32_t StartAuth(int32_t code, std::shared_ptr authManager) = 0; virtual int32_t VerifyAuthentication(std::string pinToken, int32_t code, const std::string &authParam) = 0; }; diff --git a/services/devicemanagerservice/include/authentication/dm_auth_manager.h b/services/devicemanagerservice/include/authentication/dm_auth_manager.h index 6b0298ec9..a24f9d45d 100644 --- a/services/devicemanagerservice/include/authentication/dm_auth_manager.h +++ b/services/devicemanagerservice/include/authentication/dm_auth_manager.h @@ -86,6 +86,7 @@ typedef struct DmAuthRequestContext { std::string appThumbnail; std::string token; int32_t reason; + int32_t aceId; std::vector syncGroupList; } DmAuthRequestContext; @@ -112,6 +113,7 @@ typedef struct DmAuthResponseContext { int64_t requestId; int32_t code; int32_t state; + int32_t aceId; std::vector syncGroupList; } DmAuthResponseContext; @@ -162,6 +164,7 @@ public: int32_t GetAuthenticationParam(DmAuthParam &authParam); int32_t OnUserOperation(int32_t action); void UserSwitchEventCallback(void); + void ClosePage(const int32_t &id); private: std::shared_ptr softbusConnector_; diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index 1e9976f44..6bc37f975 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -520,7 +520,7 @@ int32_t DmAuthManager::AddMember(const std::string &deviceId) return DM_FAILED; } LOGI("DmAuthManager::authRequestContext CancelDisplay start"); - CancelDisplay(); + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(authResponseContext_->aceId); return DM_OK; } @@ -547,7 +547,7 @@ void DmAuthManager::AuthenticateFinish() LOGI("DmAuthManager::AuthenticateFinish start"); if (authResponseState_ != nullptr) { if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_FINISH) { - CancelDisplay(); + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(authResponseContext_->aceId); } if (!timerMap_.empty()) { for (auto &iter : timerMap_) { @@ -688,7 +688,7 @@ void DmAuthManager::ShowAuthInfoDialog() } ptr = authenticationMap_[1]; LOGI("ShowAuthInfoDialog code:%d", authResponseContext_->code); - ptr->ShowAuthInfo(authResponseContext_->code); + ptr->ShowAuthInfo(authResponseContext_->code, shared_from_this()); } void DmAuthManager::ShowStartAuthDialog() @@ -709,7 +709,7 @@ int32_t DmAuthManager::GetAuthenticationParam(DmAuthParam &authParam) LOGI("dmAbilityMgr_ is nullptr"); return DM_POINT_NULL; } - + dmAbilityMgr_->StartAbilityDone(); AbilityRole role = dmAbilityMgr_->GetAbilityRole(); authParam.direction = (int32_t)role; @@ -785,5 +785,10 @@ void DmAuthManager::VerifyPinAuthAuthentication(const std::string &action) } LOGI("DmAuthManager::VerifyAuthentication complete"); } + +void DmAuthManager::ClosePage(const int32_t &id) +{ + authResponseContext_->aceId = id; +} } // namespace DistributedHardware } // namespace OHOS -- Gitee From 9d05f4a424f483db49ff51c8e529b5bebc6cc013 Mon Sep 17 00:00:00 2001 From: renguang1116 Date: Sun, 30 Jan 2022 17:04:48 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9crash=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20Signed-off-by:=20renguang1116=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kits/js/include/native_devicemanager_js.h | 33 ----- .../kits/js/src/native_devicemanager_js.cpp | 114 ++++++++---------- 2 files changed, 50 insertions(+), 97 deletions(-) diff --git a/interfaces/kits/js/include/native_devicemanager_js.h b/interfaces/kits/js/include/native_devicemanager_js.h index 84348c505..71cb995b4 100644 --- a/interfaces/kits/js/include/native_devicemanager_js.h +++ b/interfaces/kits/js/include/native_devicemanager_js.h @@ -67,39 +67,6 @@ struct AuthAsyncCallbackInfo { int32_t authType = -1; }; -struct DmNapiStateJsCallback { - std::string bundleName_; - uint16_t subscribeId_; - int32_t reason_; - OHOS::DistributedHardware::DmDeviceInfo deviceInfo_; - - DmNapiStateJsCallback(std::string bundleName, uint16_t subscribeId, int32_t reason, - OHOS::DistributedHardware::DmDeviceInfo deviceInfo) - : bundleName_(bundleName), subscribeId_(subscribeId), reason_(reason), deviceInfo_(deviceInfo) {} -}; - -struct DmNapiAuthJsCallback { - std::string bundleName_; - std::string deviceId_; - std::string token_; - int32_t status_; - int32_t reason_; - - DmNapiAuthJsCallback(std::string bundleName, std::string deviceId, std::string token, int32_t status, - int32_t reason) - : bundleName_(bundleName), deviceId_(deviceId), token_(token), status_(status), reason_(reason) {} -}; - -struct DmNapiVerifyJsCallback { - std::string bundleName_; - std::string deviceId_; - int32_t resultCode_; - int32_t flag_; - - DmNapiVerifyJsCallback(std::string bundleName, std::string deviceId, int32_t resultCode, int32_t flag) - : bundleName_(bundleName), deviceId_(deviceId), resultCode_(resultCode), flag_(flag) {} -}; - enum DmNapiDevStateChangeAction { ONLINE = 0, READY = 1, OFFLINE = 2, CHANGE = 3 }; class DmNapiInitCallback : public OHOS::DistributedHardware::DmInitCallback { diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index 50add0353..5a265ae1c 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -73,16 +73,12 @@ void DmNapiInitCallback::OnRemoteDied() LOGE("DmNapiInitCallback: OnRemoteDied, No memory"); return; } - DmDeviceInfo info; - std::unique_ptr jsCallback = - std::make_unique(bundleName_, 0, 0, info); - work->data = reinterpret_cast(jsCallback.get()); + static std::string staticBundleName = bundleName_; int ret = uv_queue_work(loop, work, [] (uv_work_t *work) {}, [] (uv_work_t *work, int status) { - DmNapiStateJsCallback *callback = reinterpret_cast(work->data); - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(callback->bundleName_); + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(staticBundleName); if (deviceManagerNapi == nullptr) { - LOGE("OnRemoteDied, deviceManagerNapi not find for bunderName %s", callback->bundleName_.c_str()); + LOGE("OnRemoteDied, deviceManagerNapi not find for bunderName %s", staticBundleName.c_str()); return; } deviceManagerNapi->OnEvent("serviceDie", 0, nullptr); @@ -106,18 +102,16 @@ void DmNapiDeviceStateCallback::OnDeviceOnline(const DmDeviceInfo &deviceInfo) LOGE("DmNapiDeviceStateCallback: OnDeviceOnline, No memory"); return; } - std::unique_ptr jsCallback = - std::make_unique(bundleName_, 0, 0, deviceInfo); - work->data = reinterpret_cast(jsCallback.get()); + static std::string staticBundleName = bundleName_; + static DmDeviceInfo staticDeviceInfo = deviceInfo; int ret = uv_queue_work(loop, work, [] (uv_work_t *work) {}, [] (uv_work_t *work, int status) { - DmNapiStateJsCallback *callback = reinterpret_cast(work->data); - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(callback->bundleName_); + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(staticBundleName); if (deviceManagerNapi == nullptr) { - LOGE("OnDeviceOnline, deviceManagerNapi not find for bunderName %s", callback->bundleName_.c_str()); + LOGE("OnDeviceOnline, deviceManagerNapi not find for bunderName %s", staticBundleName.c_str()); return; } - deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::ONLINE, callback->deviceInfo_); + deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::ONLINE, staticDeviceInfo); delete work; }); if (ret != 0) { @@ -138,18 +132,16 @@ void DmNapiDeviceStateCallback::OnDeviceReady(const DmDeviceInfo &deviceInfo) LOGE("DmNapiDeviceStateCallback: OnDeviceReady, No memory"); return; } - std::unique_ptr jsCallback = - std::make_unique(bundleName_, 0, 0, deviceInfo); - work->data = reinterpret_cast(jsCallback.get()); + static std::string staticBundleName = bundleName_; + static DmDeviceInfo staticDeviceInfo = deviceInfo; int ret = uv_queue_work(loop, work, [] (uv_work_t *work) {}, [] (uv_work_t *work, int status) { - DmNapiStateJsCallback *callback = reinterpret_cast(work->data); - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(callback->bundleName_); + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(staticBundleName); if (deviceManagerNapi == nullptr) { - LOGE("OnDeviceReady, deviceManagerNapi not find for bunderName %s", callback->bundleName_.c_str()); + LOGE("OnDeviceReady, deviceManagerNapi not find for bunderName %s", staticBundleName.c_str()); return; } - deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::READY, callback->deviceInfo_); + deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::READY, staticDeviceInfo); delete work; }); if (ret != 0) { @@ -170,18 +162,16 @@ void DmNapiDeviceStateCallback::OnDeviceOffline(const DmDeviceInfo &deviceInfo) LOGE("DmNapiDeviceStateCallback: OnDeviceOffline, No memory"); return; } - std::unique_ptr jsCallback = - std::make_unique(bundleName_, 0, 0, deviceInfo); - work->data = reinterpret_cast(jsCallback.get()); + static std::string staticBundleName = bundleName_; + static DmDeviceInfo staticDeviceInfo = deviceInfo; int ret = uv_queue_work(loop, work, [] (uv_work_t *work) {}, [] (uv_work_t *work, int status) { - DmNapiStateJsCallback *callback = reinterpret_cast(work->data); - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(callback->bundleName_); + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(staticBundleName); if (deviceManagerNapi == nullptr) { - LOGE("OnDeviceOffline, deviceManagerNapi not find for bunderName %s", callback->bundleName_.c_str()); + LOGE("OnDeviceOffline, deviceManagerNapi not find for bunderName %s", staticBundleName.c_str()); return; } - deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::OFFLINE, callback->deviceInfo_); + deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::OFFLINE, staticDeviceInfo); delete work; }); if (ret != 0) { @@ -202,18 +192,16 @@ void DmNapiDeviceStateCallback::OnDeviceChanged(const DmDeviceInfo &deviceInfo) LOGE("DmNapiDeviceStateCallback: OnDeviceChanged, No memory"); return; } - std::unique_ptr jsCallback = - std::make_unique(bundleName_, 0, 0, deviceInfo); - work->data = reinterpret_cast(jsCallback.get()); + static std::string staticBundleName = bundleName_; + static DmDeviceInfo staticDeviceInfo = deviceInfo; int ret = uv_queue_work(loop, work, [] (uv_work_t *work) {}, [] (uv_work_t *work, int status) { - DmNapiStateJsCallback *callback = reinterpret_cast(work->data); - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(callback->bundleName_); + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(staticBundleName); if (deviceManagerNapi == nullptr) { - LOGE("OnDeviceChanged, deviceManagerNapi not find for bunderName %s", callback->bundleName_.c_str()); + LOGE("OnDeviceChanged, deviceManagerNapi not find for bunderName %s", staticBundleName.c_str()); return; } - deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::CHANGE, callback->deviceInfo_); + deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::CHANGE, staticDeviceInfo); delete work; }); if (ret != 0) { @@ -236,18 +224,17 @@ void DmNapiDiscoveryCallback::OnDeviceFound(uint16_t subscribeId, const DmDevice LOGE("DmNapiDiscoveryCallback: OnDeviceFound, No memory"); return; } - std::unique_ptr jsCallback = - std::make_unique(bundleName_, subscribeId, 0, deviceInfo); - work->data = reinterpret_cast(jsCallback.get()); + static std::string staticBundleName = bundleName_; + static uint16_t staticSubscribeId = subscribeId; + static DmDeviceInfo staticDeviceInfo = deviceInfo; int ret = uv_queue_work(loop, work, [] (uv_work_t *work) {}, [] (uv_work_t *work, int status) { - DmNapiStateJsCallback *callback = reinterpret_cast(work->data); - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(callback->bundleName_); + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(staticBundleName); if (deviceManagerNapi == nullptr) { - LOGE("OnDeviceFound, deviceManagerNapi not find for bunderName %s", callback->bundleName_.c_str()); + LOGE("OnDeviceFound, deviceManagerNapi not find for bunderName %s", staticBundleName.c_str()); return; } - deviceManagerNapi->OnDeviceFound(callback->subscribeId_, callback->deviceInfo_); + deviceManagerNapi->OnDeviceFound(staticSubscribeId, staticDeviceInfo); delete work; }); if (ret != 0) { @@ -270,19 +257,17 @@ void DmNapiDiscoveryCallback::OnDiscoveryFailed(uint16_t subscribeId, int32_t fa LOGE("DmNapiDiscoveryCallback: OnDiscoveryFailed, No memory"); return; } - DmDeviceInfo info; - std::unique_ptr jsCallback = - std::make_unique(bundleName_, subscribeId, failedReason, info); - work->data = reinterpret_cast(jsCallback.get()); + static std::string staticBundleName = bundleName_; + static uint16_t staticSubscribeId = subscribeId; + static int32_t staticReason = failedReason; int ret = uv_queue_work(loop, work, [] (uv_work_t *work) {}, [] (uv_work_t *work, int status) { - DmNapiStateJsCallback *callback = reinterpret_cast(work->data); - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(callback->bundleName_); + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(staticBundleName); if (deviceManagerNapi == nullptr) { - LOGE("OnDiscoveryFailed, deviceManagerNapi not find for bunderName %s", callback->bundleName_.c_str()); + LOGE("OnDiscoveryFailed, deviceManagerNapi not find for bunderName %s", staticBundleName.c_str()); return; } - deviceManagerNapi->OnDiscoveryFailed(callback->subscribeId_, callback->reason_); + deviceManagerNapi->OnDiscoveryFailed(staticSubscribeId, staticReason); delete work; }); if (ret != 0) { @@ -329,18 +314,19 @@ void DmNapiAuthenticateCallback::OnAuthResult(const std::string &deviceId, const LOGE("DmNapiAuthenticateCallback: OnAuthResult, No memory"); return; } - std::unique_ptr jsCallback = - std::make_unique(bundleName_, deviceId, token, status, reason); - work->data = reinterpret_cast(jsCallback.get()); + static std::string staticBundleName = bundleName_; + static std::string staticDeviceId = deviceId; + static std::string staticToken = token; + static int32_t staticStatus = status; + static int32_t staticReason = reason; int ret = uv_queue_work(loop, work, [] (uv_work_t *work) {}, [] (uv_work_t *work, int status) { - DmNapiAuthJsCallback *callback = reinterpret_cast(work->data); - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(callback->bundleName_); + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(staticBundleName); if (deviceManagerNapi == nullptr) { - LOGE("OnAuthResult, deviceManagerNapi not find for bunderName %s", callback->bundleName_.c_str()); + LOGE("OnAuthResult, deviceManagerNapi not find for bunderName %s", staticBundleName.c_str()); return; } - deviceManagerNapi->OnAuthResult(callback->deviceId_, callback->token_, callback->status_, callback->reason_); + deviceManagerNapi->OnAuthResult(staticDeviceId, staticToken, staticStatus, staticReason); delete work; }); if (ret != 0) { @@ -361,18 +347,18 @@ void DmNapiVerifyAuthCallback::OnVerifyAuthResult(const std::string &deviceId, i LOGE("DmNapiVerifyAuthCallback: OnVerifyAuthResult, No memory"); return; } - std::unique_ptr jsCallback = - std::make_unique(bundleName_, deviceId, resultCode, flag); - work->data = reinterpret_cast(jsCallback.get()); + static std::string staticBundleName = bundleName_; + static std::string staticDeviceId = deviceId; + static int32_t staticCode = resultCode; + static int32_t staticFlag = flag; int ret = uv_queue_work(loop, work, [] (uv_work_t *work) {}, [] (uv_work_t *work, int status) { - DmNapiVerifyJsCallback *callback = reinterpret_cast(work->data); - DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(callback->bundleName_); + DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(staticBundleName); if (deviceManagerNapi == nullptr) { - LOGE("OnVerifyAuthResult, deviceManagerNapi not find for bunderName %s", callback->bundleName_.c_str()); + LOGE("OnVerifyAuthResult, deviceManagerNapi not find for bunderName %s", staticBundleName.c_str()); return; } - deviceManagerNapi->OnVerifyResult(callback->deviceId_, callback->resultCode_, callback->flag_); + deviceManagerNapi->OnVerifyResult(staticDeviceId, staticCode, staticFlag); delete work; }); if (ret != 0) { -- Gitee From 30873293f1eb71a2a63984b3fad5b34698a313b0 Mon Sep 17 00:00:00 2001 From: renguang1116 Date: Sun, 30 Jan 2022 18:05:53 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=A4=E8=AF=81?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20Signed-off-by:=20renguang1116=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ext/input_pin_dialog/dialog_ui/js/pages/index/index.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/ext/input_pin_dialog/dialog_ui/js/pages/index/index.js b/ext/input_pin_dialog/dialog_ui/js/pages/index/index.js index fc6a23af6..870893941 100644 --- a/ext/input_pin_dialog/dialog_ui/js/pages/index/index.js +++ b/ext/input_pin_dialog/dialog_ui/js/pages/index/index.js @@ -18,12 +18,7 @@ export default { console.info('click confirm end'); console.info('input: ' + input); console.info('pincode: ' + pincode); - if (input == pincode){ - console.info('pincode: = input'); - callNativeHandler(input, "0"); - } else { - console.info('pincode: != input'); - } + callNativeHandler(input, "0"); }, onCancel() { console.info('click cancel'); -- Gitee