diff --git a/common/include/dialog_ui/js/BUILD.gn b/common/include/dialog_ui/js/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..0792bde2900fd3ac9b5176e43f724b8de178ce9f
--- /dev/null
+++ b/common/include/dialog_ui/js/BUILD.gn
@@ -0,0 +1,22 @@
+# Copyright (c) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//foundation/ace/ace_engine/build/ace_gen_sa_dialog_js.gni")
+import("//foundation/distributedhardware/devicemanager/devicemanager.gni")
+
+gen_sa_dialog_js("dialog_js_files_etc") {
+ project_path = "//foundation/distributedhardware/devicemanager/common/include/dialog_ui/js"
+ dialog_name = "config_dialog_service"
+ part_name = "device_manager_base"
+ subsystem_name = "distributedhardware"
+}
diff --git a/common/include/dialog_ui/js/common/pincode.png b/common/include/dialog_ui/js/common/pincode.png
new file mode 100644
index 0000000000000000000000000000000000000000..6616f7659fcf1d5da5ab6796863e32efbe086cdc
Binary files /dev/null and b/common/include/dialog_ui/js/common/pincode.png differ
diff --git a/common/include/dialog_ui/js/i18n/en-US.json b/common/include/dialog_ui/js/i18n/en-US.json
new file mode 100644
index 0000000000000000000000000000000000000000..0714fc75f8420ac089a6ee1c24c8f2d8472ff511
--- /dev/null
+++ b/common/include/dialog_ui/js/i18n/en-US.json
@@ -0,0 +1,5 @@
+{
+ "message":{
+ "hello": "hello world"
+ }
+}
\ No newline at end of file
diff --git a/common/include/dialog_ui/js/i18n/zh-CN.json b/common/include/dialog_ui/js/i18n/zh-CN.json
new file mode 100644
index 0000000000000000000000000000000000000000..53afe2047da6ff0423e5eae8d9f9af9f73d85d0b
--- /dev/null
+++ b/common/include/dialog_ui/js/i18n/zh-CN.json
@@ -0,0 +1,5 @@
+{
+ "message": {
+ "hello": "你好世界"
+ }
+}
\ No newline at end of file
diff --git a/common/include/dialog_ui/js/pages/index/index.css b/common/include/dialog_ui/js/pages/index/index.css
new file mode 100644
index 0000000000000000000000000000000000000000..997f0c8af087e0a65c72efeeddec3f8fd665cbf6
--- /dev/null
+++ b/common/include/dialog_ui/js/pages/index/index.css
@@ -0,0 +1,41 @@
+.container {
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ opacity: 0.8;
+ background-color: azure;
+}
+
+.title {
+ font-size: 80px;
+ line-height: 150px;
+ font-weight: 800;
+}
+
+.but {
+ width: 85%;
+ margin-top: 10%;
+ text-align: center;
+ height: 100px;
+}
+
+.but1 {
+ width: 30%;
+ height: 80px;
+ font-size: 50px;
+ margin-left: 10%;
+}
+
+.but2 {
+ width: 30%;
+ height: 80px;
+ font-size: 50px;
+ margin-left: 55%;
+}
+
+
+.title-list {
+ 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
new file mode 100644
index 0000000000000000000000000000000000000000..0ab94e3af4aafb49db32d01fe08e57ae2e3c2835
--- /dev/null
+++ b/common/include/dialog_ui/js/pages/index/index.hml
@@ -0,0 +1,16 @@
+
+
+ 是否允许对端连接本机
+
+
+ 用于分享图片
+
+
+
+
+
+
diff --git a/common/include/dialog_ui/js/pages/index/index.js b/common/include/dialog_ui/js/pages/index/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..5597a1fb8ada44b09d3b87c5f8ea3a7c1461ae80
--- /dev/null
+++ b/common/include/dialog_ui/js/pages/index/index.js
@@ -0,0 +1,18 @@
+import router from '@ohos.router'
+
+export default {
+ data: {
+ message: router.getParams().targetPkgName,
+ },
+ onInit() {
+ console.info('getParams: ' + router.getParams());
+ },
+ onConfirm() {
+ console.info('click confirm');
+ callNativeHandler("EVENT_CONFIRM", "0");
+ },
+ onCancel() {
+ console.info('click cancel');
+ callNativeHandler("EVENT_CANCEL", "1");
+ }
+}
\ No newline at end of file
diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h
index 492de42c1eab4429d8646330cfea50dc3829c173..1206f3909740ac8325d19fdcb5f1a940afb2e817 100644
--- a/common/include/dm_constants.h
+++ b/common/include/dm_constants.h
@@ -172,6 +172,12 @@ const std::string BR_MAC = "BR_MAC";
const std::string BLE_MAC = "BLE_MAC";
const std::string ETH_IP = "ETH_IP";
const std::string ETH_PORT = "ETH_PORT";
+
+// ACE
+const int32_t ACE_X = 50;
+const int32_t ACE_Y = 300;
+const int32_t ACE_WIDTH = 600;
+const int32_t ACE_HEIGHT = 400;
} // namespace DistributedHardware
} // namespace OHOS
#endif
diff --git a/ext/input_pin_dialog/dialog_ui/js/BUILD.gn b/ext/input_pin_dialog/dialog_ui/js/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..8abf88695e272f47842c8c6549920376cff6b74b
--- /dev/null
+++ b/ext/input_pin_dialog/dialog_ui/js/BUILD.gn
@@ -0,0 +1,22 @@
+# Copyright (c) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//foundation/ace/ace_engine/build/ace_gen_sa_dialog_js.gni")
+import("//foundation/distributedhardware/devicemanager/devicemanager.gni")
+
+gen_sa_dialog_js("dialog_js_files_etc") {
+ project_path = "//foundation/distributedhardware/devicemanager/ext/input_pin_dialog/dialog_ui/js"
+ dialog_name = "input_pin_service"
+ part_name = "device_manager_base"
+ subsystem_name = "distributedhardware"
+}
diff --git a/ext/input_pin_dialog/dialog_ui/js/common/KeyBoard.js b/ext/input_pin_dialog/dialog_ui/js/common/KeyBoard.js
new file mode 100644
index 0000000000000000000000000000000000000000..c3234a50dc7569ed8bf587f6ea22899f0671b0f2
--- /dev/null
+++ b/ext/input_pin_dialog/dialog_ui/js/common/KeyBoard.js
@@ -0,0 +1,86 @@
+
+;(function(exports){
+ var KeyBoard = function(input, options){
+ var body = document.getElementsByTagName('body')[0];
+ var DIV_ID = options && options.divId || '__w_l_h_v_c_z_e_r_o_divid';
+
+ if(document.getElementById(DIV_ID)){
+ body.removeChild(document.getElementById(DIV_ID));
+ }
+
+ this.input = input;
+ this.el = document.createElement('div');
+
+ var self = this;
+ var zIndex = options && options.zIndex || 1000;
+ var width = options && options.width || '100%';
+ var height = options && options.height || '193px';
+ var fontSize = options && options.fontSize || '15px';
+ var backgroundColor = options && options.backgroundColor || '#fff';
+ var TABLE_ID = options && options.table_id || 'table_0909099';
+ var mobile = typeof orientation !== 'undefined';
+
+ this.el.id = DIV_ID;
+ this.el.style.position = 'absolute';
+ this.el.style.left = 0;
+ this.el.style.right = 0;
+ this.el.style.bottom = 0;
+ this.el.style.zIndex = zIndex;
+ this.el.style.width = width;
+ this.el.style.height = height;
+ this.el.style.backgroundColor = backgroundColor;
+
+ //样式
+ var cssStr = '';
+
+ //Button
+ var btnStr = '完成
';
+
+ //table
+ var tableStr = '';
+ tableStr += '1 | 2 | 3 |
';
+ tableStr += '4 | 5 | 6 |
';
+ tableStr += '7 | 8 | 9 |
';
+ tableStr += '. | 0 | ';
+ tableStr += '删除 |
';
+ tableStr += '
';
+ this.el.innerHTML = cssStr + btnStr + tableStr;
+
+ function addEvent(e){
+ var ev = e || window.event;
+ var clickEl = ev.element || ev.target;
+ var value = clickEl.textContent || clickEl.innerText;
+ if(clickEl.tagName.toLocaleLowerCase() === 'td' && value !== "删除"){
+ if(self.input){
+ self.input.value += value;
+ }
+ }else if(clickEl.tagName.toLocaleLowerCase() === 'div' && value === "完成"){
+ body.removeChild(self.el);
+ }else if(clickEl.tagName.toLocaleLowerCase() === 'td' && value === "删除"){
+ var num = self.input.value;
+ if(num){
+ var newNum = num.substr(0, num.length - 1);
+ self.input.value = newNum;
+ }
+ }
+ }
+
+ if(mobile){
+ this.el.ontouchstart = addEvent;
+ }else{
+ this.el.onclick = addEvent;
+ }
+ body.appendChild(this.el);
+ }
+
+ exports.KeyBoard = KeyBoard;
+
+})(window);
\ No newline at end of file
diff --git a/ext/input_pin_dialog/dialog_ui/js/common/index.hml b/ext/input_pin_dialog/dialog_ui/js/common/index.hml
new file mode 100644
index 0000000000000000000000000000000000000000..3566d9ba28b0696c15f59dcf87adaa6155fb5430
--- /dev/null
+++ b/ext/input_pin_dialog/dialog_ui/js/common/index.hml
@@ -0,0 +1,32 @@
+
+
+ PIN码连接
+
+
+ 请输入另一个设备显示的PIN码进行验证
+
+
+
+
+ PIN码输入错误,请重新输入
+
+
+
+
+
+
+
+
+
diff --git a/ext/input_pin_dialog/dialog_ui/js/common/pincode.png b/ext/input_pin_dialog/dialog_ui/js/common/pincode.png
new file mode 100644
index 0000000000000000000000000000000000000000..6616f7659fcf1d5da5ab6796863e32efbe086cdc
Binary files /dev/null and b/ext/input_pin_dialog/dialog_ui/js/common/pincode.png differ
diff --git a/ext/input_pin_dialog/dialog_ui/js/i18n/en-US.json b/ext/input_pin_dialog/dialog_ui/js/i18n/en-US.json
new file mode 100644
index 0000000000000000000000000000000000000000..0714fc75f8420ac089a6ee1c24c8f2d8472ff511
--- /dev/null
+++ b/ext/input_pin_dialog/dialog_ui/js/i18n/en-US.json
@@ -0,0 +1,5 @@
+{
+ "message":{
+ "hello": "hello world"
+ }
+}
\ No newline at end of file
diff --git a/ext/input_pin_dialog/dialog_ui/js/i18n/zh-CN.json b/ext/input_pin_dialog/dialog_ui/js/i18n/zh-CN.json
new file mode 100644
index 0000000000000000000000000000000000000000..53afe2047da6ff0423e5eae8d9f9af9f73d85d0b
--- /dev/null
+++ b/ext/input_pin_dialog/dialog_ui/js/i18n/zh-CN.json
@@ -0,0 +1,5 @@
+{
+ "message": {
+ "hello": "你好世界"
+ }
+}
\ No newline at end of file
diff --git a/ext/input_pin_dialog/dialog_ui/js/pages/index/index.css b/ext/input_pin_dialog/dialog_ui/js/pages/index/index.css
new file mode 100644
index 0000000000000000000000000000000000000000..fc2207c2f9f7e3d00aa2e2d32073cbfbf2ea34ec
--- /dev/null
+++ b/ext/input_pin_dialog/dialog_ui/js/pages/index/index.css
@@ -0,0 +1,53 @@
+.container {
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ opacity: 0.8;
+ background-color: azure;
+}
+
+.title {
+ font-size: 80px;
+ line-height: 100px;
+ font-weight: 800;
+}
+
+.title-list {
+ font-size: 60px;
+ line-height: 60px;
+ font-weight: 800;
+}
+
+.title-error {
+ font-size: 30px;
+ line-height: 40px;
+ font-weight: 800;
+ color: #ff0000;
+}
+
+.title-pin {
+ font-size: 60px;
+ line-height: 80px;
+ font-weight: 800;
+}
+
+.but {
+ width: 85%;
+ margin-top: 10%;
+ text-align: center;
+ height: 100px;
+}
+
+.but1 {
+ width: 30%;
+ height: 80px;
+ font-size: 50px;
+ margin-left: 10%;
+}
+
+.but2 {
+ width: 30%;
+ height: 80px;
+ font-size: 50px;
+ margin-left: 55%;
+}
\ No newline at end of file
diff --git a/ext/input_pin_dialog/dialog_ui/js/pages/index/index.hml b/ext/input_pin_dialog/dialog_ui/js/pages/index/index.hml
new file mode 100644
index 0000000000000000000000000000000000000000..1515226bcfc74d87757d27a2703cdf9d7aebc974
--- /dev/null
+++ b/ext/input_pin_dialog/dialog_ui/js/pages/index/index.hml
@@ -0,0 +1,20 @@
+
+
+ PIN码连接
+
+
+ 请输入另一个设备显示的PIN码进行验证
+
+
+
+
+
+
+
+
+
+
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
new file mode 100644
index 0000000000000000000000000000000000000000..82d40b46a5137f7e0ce9d4651b0248937b5b4d44
--- /dev/null
+++ b/ext/input_pin_dialog/dialog_ui/js/pages/index/index.js
@@ -0,0 +1,26 @@
+import router from '@ohos.router';
+
+var numbs = 0;
+export default {
+ data: {
+ pincode: router.getParams().pinCode,
+ },
+ onInit() {
+ console.info('getParams: ' + router.getParams());
+ },
+ onConfirm() {
+ console.info('click inpout confirm numbs'+ numbs);
+ console.info('click inpout confirm');
+ numbs = numbs + 1;
+ 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);
+ callNativeHandler("EVENT_INPUT", "0");
+ },
+ onCancel() {
+ console.info('click cancel');
+ callNativeHandler("EVENT_CONFIRM", "1");
+ }
+}
\ No newline at end of file
diff --git a/ext/pin_auth/BUILD.gn b/ext/pin_auth/BUILD.gn
index 603d4ff14d53df50cfdca566af1ab3cae631d406..41bfe45895d84043dd289304b4e37359cf414055 100644
--- a/ext/pin_auth/BUILD.gn
+++ b/ext/pin_auth/BUILD.gn
@@ -25,10 +25,38 @@ if (defined(ohos_lite)) {
include_dirs = [
"include",
"${common_path}/include",
- "${services_path}/include/adapter",
"${ext_path}/pin_auth/include/ability",
+ "${services_path}/include/dependency/timer",
+ "${services_path}/include/config",
+ "${services_path}/include/adapter",
"${services_path}/include/authentication",
+ "${services_path}/include/ability",
+ "${services_path}/include/deviceinfo",
+ "${services_path}/include/devicestate",
+ "${services_path}/include/discovery",
+ "${services_path}/include/dependency/commonevent",
+ "${services_path}/include/dependency/hichain",
+ "${services_path}/include/dependency/softbus",
+ "${services_path}/include/dependency/timer",
+ "${services_path}/include/ipc",
+ "${services_path}/include/ipc/standard",
"${utils_path}/include",
+ "${utils_path}/include/ipc/standard",
+ "${services_path}/include",
+ "${innerkits_path}/native_cpp/include",
+ "${common_path}/include/ipc",
+ "${common_path}/include/ipc/model",
+ "${innerkits_path}/native_cpp/include",
+ "${innerkits_path}/native_cpp/include/ipc",
+ "${innerkits_path}/native_cpp/include/ipc/standard",
+ "//third_party/json/include",
+ "//utils/native/base/include",
+ "//utils/system/safwk/native/include",
+ "//base/notification/ces_standard/frameworks/core/include",
+ "//base/notification/ces_standard/interfaces/innerkits/native/include",
+ "//base/security/deviceauth/interfaces/innerkits",
+ "//base/startup/syspara_lite/interfaces/kits",
+ "//base/startup/syspara_lite/adapter/native/syspara/include",
]
sources = [
@@ -38,20 +66,32 @@ if (defined(ohos_lite)) {
]
deps = [
+ "${ext_path}/input_pin_dialog/dialog_ui/js:dialog_js_files_etc",
+ "${ext_path}/show_pin_dialog/dialog_ui/js:dialog_js_files_etc",
+ "${innerkits_path}/native_cpp:devicemanagersdk",
"${utils_path}:devicemanagerutils",
+ "//base/security/deviceauth/services:deviceauth_sdk",
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//foundation/aafwk/standard/services/abilitymgr:abilityms",
+ "//foundation/ace/ace_engine/interfaces/innerkits/ui_service_manager:ui_service_mgr",
+ "//foundation/distributedhardware/devicemanager/services/devicemanagerservice:devicemanagerservice",
+ "//foundation/windowmanager/wm:libwm",
"//utils/native/base:utils",
]
external_deps = [
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
+ "ces_standard:cesfwk_core",
+ "ces_standard:cesfwk_innerkits",
+ "dsoftbus_standard:softbus_client",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
"safwk:system_ability_fwk",
+ "samgr_standard:samgr_proxy",
"startup_l2:syspara",
+ "startup_l2:syspara_watchagent",
]
defines = [
diff --git a/ext/pin_auth/include/pin_auth.h b/ext/pin_auth/include/pin_auth.h
index 2129c94a1a5cd949d018fdb30bcca668f5efc474..dca2e7e7f9e12b4679d778c7d4a9b893f46c129d 100644
--- a/ext/pin_auth/include/pin_auth.h
+++ b/ext/pin_auth/include/pin_auth.h
@@ -20,6 +20,7 @@
#include
#include "authentication.h"
+#include "dm_auth_manager.h"
#include "dm_ability_manager.h"
#include "pin_auth_ui.h"
@@ -29,8 +30,8 @@ class PinAuth : public IAuthentication {
public:
PinAuth();
~PinAuth();
- int32_t ShowAuthInfo() override;
- int32_t StartAuth(std::shared_ptr dmAbilityManager) 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;
private:
diff --git a/ext/pin_auth/include/pin_auth_ui.h b/ext/pin_auth/include/pin_auth_ui.h
index f8910cba26fe134c29fd199449c8ba622da6018d..5ff26c3e1634b9bfb1ae370b8349b8c0ebab3ebe 100644
--- a/ext/pin_auth/include/pin_auth_ui.h
+++ b/ext/pin_auth/include/pin_auth_ui.h
@@ -18,6 +18,7 @@
#include
+#include "dm_auth_manager.h"
#include "dm_ability_manager.h"
namespace OHOS {
@@ -25,8 +26,8 @@ namespace DistributedHardware {
class PinAuthUi {
public:
PinAuthUi();
- int32_t ShowPinDialog();
- int32_t InputPinDialog(std::shared_ptr dmAbilityManager);
+ int32_t ShowPinDialog(int32_t code, std::shared_ptr authManager);
+ int32_t InputPinDialog(int32_t code, std::shared_ptr authManager);
private:
int32_t StartFaUiService(std::shared_ptr dmAbilityManager);
diff --git a/ext/pin_auth/src/pin_auth.cpp b/ext/pin_auth/src/pin_auth.cpp
index 5e123b0c550dc0f5b51059b318390dee00151e73..0bbadd15f7aa503e771432a132e9512f1834eec8 100644
--- a/ext/pin_auth/src/pin_auth.cpp
+++ b/ext/pin_auth/src/pin_auth.cpp
@@ -33,15 +33,14 @@ PinAuth::~PinAuth()
{
}
-int32_t PinAuth::ShowAuthInfo()
+int32_t PinAuth::ShowAuthInfo(int32_t code, std::shared_ptr authManager)
{
- return pinAuthUi_->ShowPinDialog();
+ return pinAuthUi_->ShowPinDialog(code, authManager);
}
-int32_t PinAuth::StartAuth(std::shared_ptr dmAbilityManager)
+int32_t PinAuth::StartAuth(int32_t code, std::shared_ptr authManager)
{
- times_ = 0;
- return pinAuthUi_->InputPinDialog(dmAbilityManager);
+ return pinAuthUi_->InputPinDialog(code, authManager);
}
int32_t PinAuth::VerifyAuthentication(std::string pinToken, int32_t code, const std::string &authParam)
diff --git a/ext/pin_auth/src/pin_auth_ui.cpp b/ext/pin_auth/src/pin_auth_ui.cpp
index 691e5005239562cdeed0aad76f73cabbbaf91826..51f76bdb4ce70a6218f42bd8850ef686cadeea7f 100644
--- a/ext/pin_auth/src/pin_auth_ui.cpp
+++ b/ext/pin_auth/src/pin_auth_ui.cpp
@@ -18,6 +18,8 @@
#include "dm_ability_manager.h"
#include "dm_constants.h"
#include "dm_log.h"
+#include "nlohmann/json.hpp"
+#include "ui_service_mgr_client.h"
namespace OHOS {
namespace DistributedHardware {
@@ -26,18 +28,52 @@ PinAuthUi::PinAuthUi()
LOGI("AuthUi constructor");
}
-int32_t PinAuthUi::ShowPinDialog()
+int32_t PinAuthUi::ShowPinDialog(int32_t code, std::shared_ptr authManager)
{
+ LOGI("ShowPinDialog start");
+ nlohmann::json jsonObj;
+ jsonObj[PIN_CODE_KEY] = code;
+ jsonObj.dump();
+ const std::string params = jsonObj.dump();
+
+ Ace::UIServiceMgrClient::GetInstance()->ShowDialog(
+ "show_pin_service",
+ params,
+ OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW,
+ ACE_X, ACE_Y, ACE_WIDTH, ACE_HEIGHT,
+ [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;
}
-int32_t PinAuthUi::InputPinDialog(std::shared_ptr dmAbilityManager)
+int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr authManager)
{
- if (dmAbilityManager == nullptr) {
- LOGE("PinAuthUi::dmAbilityManager is null");
- return DM_FAILED;
- }
- return StartFaUiService(dmAbilityManager);
+ LOGI("InputPinDialog start");
+ nlohmann::json jsonObj;
+ jsonObj[PIN_CODE_KEY] = code;
+ jsonObj.dump();
+ const std::string params = jsonObj.dump();
+
+ Ace::UIServiceMgrClient::GetInstance()->ShowDialog(
+ "input_pin_service",
+ params,
+ OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW,
+ ACE_X, ACE_Y, ACE_WIDTH, ACE_HEIGHT,
+ [authManager](int32_t id, const std::string& event, const std::string& params) {
+ Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id);
+ LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str());
+ authManager->VerifyPinAuthAuthentication(params.c_str());
+ });
+ LOGI("ShowConfigDialog end");
+ return DM_OK;
}
int32_t PinAuthUi::StartFaUiService(std::shared_ptr dmAbilityManager)
diff --git a/ext/show_pin_dialog/dialog_ui/js/BUILD.gn b/ext/show_pin_dialog/dialog_ui/js/BUILD.gn
new file mode 100644
index 0000000000000000000000000000000000000000..8c623e7f87ffeec940e5f3a0730114001f79f6e0
--- /dev/null
+++ b/ext/show_pin_dialog/dialog_ui/js/BUILD.gn
@@ -0,0 +1,22 @@
+# Copyright (c) 2021 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//foundation/ace/ace_engine/build/ace_gen_sa_dialog_js.gni")
+import("//foundation/distributedhardware/devicemanager/devicemanager.gni")
+
+gen_sa_dialog_js("dialog_js_files_etc") {
+ project_path = "//foundation/distributedhardware/devicemanager/ext/show_pin_dialog/dialog_ui/js"
+ dialog_name = "show_pin_service"
+ part_name = "device_manager_base"
+ subsystem_name = "distributedhardware"
+}
diff --git a/ext/show_pin_dialog/dialog_ui/js/common/pincode.png b/ext/show_pin_dialog/dialog_ui/js/common/pincode.png
new file mode 100644
index 0000000000000000000000000000000000000000..6616f7659fcf1d5da5ab6796863e32efbe086cdc
Binary files /dev/null and b/ext/show_pin_dialog/dialog_ui/js/common/pincode.png differ
diff --git a/ext/show_pin_dialog/dialog_ui/js/i18n/en-US.json b/ext/show_pin_dialog/dialog_ui/js/i18n/en-US.json
new file mode 100644
index 0000000000000000000000000000000000000000..0714fc75f8420ac089a6ee1c24c8f2d8472ff511
--- /dev/null
+++ b/ext/show_pin_dialog/dialog_ui/js/i18n/en-US.json
@@ -0,0 +1,5 @@
+{
+ "message":{
+ "hello": "hello world"
+ }
+}
\ No newline at end of file
diff --git a/ext/show_pin_dialog/dialog_ui/js/i18n/zh-CN.json b/ext/show_pin_dialog/dialog_ui/js/i18n/zh-CN.json
new file mode 100644
index 0000000000000000000000000000000000000000..53afe2047da6ff0423e5eae8d9f9af9f73d85d0b
--- /dev/null
+++ b/ext/show_pin_dialog/dialog_ui/js/i18n/zh-CN.json
@@ -0,0 +1,5 @@
+{
+ "message": {
+ "hello": "你好世界"
+ }
+}
\ No newline at end of file
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
new file mode 100644
index 0000000000000000000000000000000000000000..4e83197eb87599519a190b689eceb3182591d24c
--- /dev/null
+++ b/ext/show_pin_dialog/dialog_ui/js/pages/index/index.css
@@ -0,0 +1,31 @@
+.container {
+ flex-direction: column;
+ justify-content: center;
+ align-items: center;
+ opacity: 0.8;
+ background-color: azure;
+}
+
+.title {
+ font-size: 80px;
+ line-height: 120px;
+ font-weight: 800;
+}
+
+.title-list {
+ font-size: 60px;
+ line-height: 100px;
+ font-weight: 800;
+}
+
+.title-pin {
+ font-size: 60px;
+ line-height: 100px;
+ font-weight: 800;
+}
+
+.but {
+ 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.hml b/ext/show_pin_dialog/dialog_ui/js/pages/index/index.hml
new file mode 100644
index 0000000000000000000000000000000000000000..9cb650aefdc7650e308f4202a3b9ca0ee11cba57
--- /dev/null
+++ b/ext/show_pin_dialog/dialog_ui/js/pages/index/index.hml
@@ -0,0 +1,14 @@
+
+
+ PIN码连接
+
+
+ 请在设备端输入链接码进行验证
+
+
+ {{ pincode }}
+
+
+
\ 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
new file mode 100644
index 0000000000000000000000000000000000000000..3a55ac1cc8215df26437b036c9f92ec5dbb7568d
--- /dev/null
+++ b/ext/show_pin_dialog/dialog_ui/js/pages/index/index.js
@@ -0,0 +1,15 @@
+import router from '@ohos.router'
+
+export default {
+ data: {
+ pincode: router.getParams().pinCode,
+ },
+ onInit() {
+ console.info('getParams: ' + router.getParams());
+ callNativeHandler("EVENT_CONFIRM", "0");
+ },
+ onConfirm() {
+ console.info('click confirm');
+ callNativeHandler("EVENT_CONFIRM", "1");
+ }
+}
\ No newline at end of file
diff --git a/interfaces/kits/js/include/native_devicemanager_js.h b/interfaces/kits/js/include/native_devicemanager_js.h
index b05fef48f692bb11a5fa8c346a3a243ed4ba3175..71cb995b4f81a9ffcb6fd2b857fbecaeb4e5c78b 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;
@@ -70,7 +71,7 @@ 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 +80,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 +96,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 +115,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 +182,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 +243,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 c314e669c14fc60715df330920e395414cb9d4c3..5a265ae1c955c20fc253ce750c447d6ab816925a 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,223 @@ 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);
+
+ static std::string staticBundleName = bundleName_;
+ 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("OnRemoteDied, deviceManagerNapi not find for bunderName %s", staticBundleName.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;
+ }
+
+ 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) {
+ DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(staticBundleName);
+ if (deviceManagerNapi == nullptr) {
+ LOGE("OnDeviceOnline, deviceManagerNapi not find for bunderName %s", staticBundleName.c_str());
+ return;
+ }
+ deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::ONLINE, staticDeviceInfo);
+ 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;
+ }
+
+ 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) {
+ DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(staticBundleName);
+ if (deviceManagerNapi == nullptr) {
+ LOGE("OnDeviceReady, deviceManagerNapi not find for bunderName %s", staticBundleName.c_str());
+ return;
+ }
+ deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::READY, staticDeviceInfo);
+ 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;
+ }
+
+ 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) {
+ DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(staticBundleName);
+ if (deviceManagerNapi == nullptr) {
+ LOGE("OnDeviceOffline, deviceManagerNapi not find for bunderName %s", staticBundleName.c_str());
+ return;
+ }
+ deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::OFFLINE, staticDeviceInfo);
+ 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;
+ }
+
+ 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) {
+ DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(staticBundleName);
+ if (deviceManagerNapi == nullptr) {
+ LOGE("OnDeviceChanged, deviceManagerNapi not find for bunderName %s", staticBundleName.c_str());
+ return;
+ }
+ deviceManagerNapi->OnDeviceStateChange(DmNapiDevStateChangeAction::CHANGE, staticDeviceInfo);
+ 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;
}
- LOGI("OnDeviceFound for %s, subscribeId %d", bundleName_.c_str(), (int32_t)subscribeId);
- deviceManagerNapi->OnDeviceFound(subscribeId, deviceInfo);
+ 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) {
+ DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(staticBundleName);
+ if (deviceManagerNapi == nullptr) {
+ LOGE("OnDeviceFound, deviceManagerNapi not find for bunderName %s", staticBundleName.c_str());
+ return;
+ }
+ deviceManagerNapi->OnDeviceFound(staticSubscribeId, staticDeviceInfo);
+ 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;
}
- deviceManagerNapi->OnDiscoveryFailed(subscribeId, failedReason);
+ 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) {
+ DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(staticBundleName);
+ if (deviceManagerNapi == nullptr) {
+ LOGE("OnDiscoveryFailed, deviceManagerNapi not find for bunderName %s", staticBundleName.c_str());
+ return;
+ }
+ deviceManagerNapi->OnDiscoveryFailed(staticSubscribeId, staticReason);
+ delete work;
+ });
+ if (ret != 0) {
+ LOGE("Failed to execute OnDiscoveryFailed work queue");
+ delete work;
+ }
}
void DmNapiDiscoveryCallback::OnDiscoverySuccess(uint16_t subscribeId)
@@ -161,22 +304,67 @@ 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);
+
+ 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) {
+ DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(staticBundleName);
+ if (deviceManagerNapi == nullptr) {
+ LOGE("OnAuthResult, deviceManagerNapi not find for bunderName %s", staticBundleName.c_str());
+ return;
+ }
+ deviceManagerNapi->OnAuthResult(staticDeviceId, staticToken, staticStatus, staticReason);
+ 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);
+
+ 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) {
+ DeviceManagerNapi *deviceManagerNapi = DeviceManagerNapi::GetDeviceManagerNapi(staticBundleName);
+ if (deviceManagerNapi == nullptr) {
+ LOGE("OnVerifyAuthResult, deviceManagerNapi not find for bunderName %s", staticBundleName.c_str());
+ return;
+ }
+ deviceManagerNapi->OnVerifyResult(staticDeviceId, staticCode, staticFlag);
+ 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 +857,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 +879,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 +893,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 +1032,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 +1453,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 +1527,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 +1567,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 +1602,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 +1754,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/BUILD.gn b/services/devicemanagerservice/BUILD.gn
index 8d979936963a84b0e6eb2c892bd65119e257bcfc..f4359edcc645959257b185de9c1af264a2656d47 100644
--- a/services/devicemanagerservice/BUILD.gn
+++ b/services/devicemanagerservice/BUILD.gn
@@ -57,6 +57,7 @@ if (defined(ohos_lite)) {
"//base/startup/syspara_lite/interfaces/kits",
"//base/startup/syspara_lite/adapter/native/syspara/include",
"//third_party/json/include",
+ "//third_party/flutter/skia",
]
sources = [
@@ -85,12 +86,15 @@ if (defined(ohos_lite)) {
]
deps = [
+ "${common_path}/include/dialog_ui/js:dialog_js_files_etc",
"${innerkits_path}/native_cpp:devicemanagersdk",
"${utils_path}:devicemanagerutils",
"//base/security/deviceauth/services:deviceauth_sdk",
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//foundation/aafwk/standard/services/abilitymgr:abilityms",
+ "//foundation/ace/ace_engine/interfaces/innerkits/ui_service_manager:ui_service_mgr",
+ "//foundation/windowmanager/wm:libwm",
"//utils/native/base:utils",
]
diff --git a/services/devicemanagerservice/include/authentication/authentication.h b/services/devicemanagerservice/include/authentication/authentication.h
index 5783f11125a23e813979ae3249a9cfd3d3d97603..67ca0c3ee86b1e0fccae4eb20927cda40dc3a829 100644
--- a/services/devicemanagerservice/include/authentication/authentication.h
+++ b/services/devicemanagerservice/include/authentication/authentication.h
@@ -20,11 +20,12 @@
namespace OHOS {
namespace DistributedHardware {
+class DmAuthManager;
class IAuthentication {
public:
virtual ~IAuthentication() = default;
- virtual int32_t ShowAuthInfo() = 0;
- virtual int32_t StartAuth(std::shared_ptr dmAbilityManager) = 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 2ea42c9b7c8a6bbe7bff6a445610ba6f8ea97bf0..a24f9d45d6a58adf253a7b9b9f47d11f882e3b69 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;
@@ -129,6 +131,7 @@ public:
const std::string &extra);
int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &deviceId);
int32_t VerifyAuthentication(const std::string &authParam);
+ void VerifyPinAuthAuthentication(const std::string &action);
void OnSessionOpened(int32_t sessionId, int32_t sessionSide, int32_t result);
void OnSessionClosed(int32_t sessionId);
void OnDataReceived(int32_t sessionId, std::string message);
@@ -161,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 cde8a2e3c052955edaba675d906d20d830e4c998..21fca1e946c3005451b649861dfeb4a566ab2cce 100644
--- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp
+++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp
@@ -24,6 +24,9 @@
#include "dm_random.h"
#include "nlohmann/json.hpp"
#include "parameter.h"
+#include "ui_service_mgr_client.h"
+#include "dialog_callback_stub.h"
+#include "dialog_callback.h"
namespace OHOS {
namespace DistributedHardware {
@@ -322,6 +325,7 @@ void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId
softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message);
return;
}
+ authResponseContext_->code = GeneratePincode();
authResponseContext_->groupId = groupId;
authMessageProcessor_->SetResponseContext(authResponseContext_);
std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_AUTH);
@@ -517,7 +521,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;
}
@@ -544,7 +548,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_) {
@@ -652,31 +656,60 @@ int32_t DmAuthManager::GetPinCode()
void DmAuthManager::ShowConfigDialog()
{
- std::shared_ptr authUi_ = std::make_shared();
- dmAbilityMgr_ = std::make_shared();
- authUi_->ShowConfirmDialog(dmAbilityMgr_);
+ LOGI("ShowConfigDialog start");
+ nlohmann::json jsonObj;
+ jsonObj[TAG_AUTH_TYPE] = AUTH_TYPE_PIN;
+ jsonObj[TAG_TOKEN] = authResponseContext_->token;
+ jsonObj[TARGET_PKG_NAME_KEY] = authResponseContext_->targetPkgName;
+ jsonObj.dump();
+ const std::string params = jsonObj.dump();
+ std::shared_ptr authMgr_ = shared_from_this();
+
+ Ace::UIServiceMgrClient::GetInstance()->ShowDialog(
+ "config_dialog_service",
+ params,
+ OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW,
+ ACE_X, ACE_Y, ACE_WIDTH, ACE_HEIGHT,
+ [authMgr_](int32_t id, const std::string& event, const std::string& params) {
+ Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id);
+ LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str());
+ authMgr_->StartAuthProcess(atoi(params.c_str()));
+ });
+ LOGI("ShowConfigDialog end");
}
void DmAuthManager::ShowAuthInfoDialog()
{
- return;
+ LOGI("DmAuthManager::ShowAuthInfoDialog start");
+ std::shared_ptr ptr;
+ if (authenticationMap_.find(1) == authenticationMap_.end()) {
+ LOGE("DmAuthManager::authenticationMap_ is null");
+ return;
+ }
+ ptr = authenticationMap_[1];
+ LOGI("ShowAuthInfoDialog code:%d", authResponseContext_->code);
+ ptr->ShowAuthInfo(authResponseContext_->code, shared_from_this());
}
void DmAuthManager::ShowStartAuthDialog()
{
LOGI("DmAuthManager::ShowStartAuthDialog start");
- dmAbilityMgr_ = std::make_shared();
std::shared_ptr ptr;
if (authenticationMap_.find(1) == authenticationMap_.end()) {
LOGE("DmAuthManager::authenticationMap_ is null");
return;
}
ptr = authenticationMap_[1];
- ptr->StartAuth(dmAbilityMgr_);
+ ptr->StartAuth(authResponseContext_->code, shared_from_this());
}
int32_t DmAuthManager::GetAuthenticationParam(DmAuthParam &authParam)
{
+ if (dmAbilityMgr_ == nullptr) {
+ LOGI("dmAbilityMgr_ is nullptr");
+ return DM_POINT_NULL;
+ }
+
dmAbilityMgr_->StartAbilityDone();
AbilityRole role = dmAbilityMgr_->GetAbilityRole();
authParam.direction = (int32_t)role;
@@ -737,5 +770,25 @@ void DmAuthManager::UserSwitchEventCallback (void)
}
}
}
+
+void DmAuthManager::VerifyPinAuthAuthentication(const std::string &action)
+{
+ LOGI("DmAuthManager::VerifyPinAuthAuthentication");
+ timerMap_[INPUT_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT);
+ if (action == "0") {
+ authRequestState_->TransitionTo(std::make_shared());
+ }
+ if (action == "1") {
+ authRequestContext_->reason = DM_AUTH_INPUT_FAILED;
+ authResponseContext_->state = authRequestState_->GetStateType();
+ authRequestState_->TransitionTo(std::make_shared());
+ }
+ LOGI("DmAuthManager::VerifyAuthentication complete");
+}
+
+void DmAuthManager::ClosePage(const int32_t &id)
+{
+ authResponseContext_->aceId = id;
+}
} // namespace DistributedHardware
} // namespace OHOS
diff --git a/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp b/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp
index ab7b0d162d404beea13aaf17cb4f78039144950d..fc6fed38b42b22e0d114599824be46f0a3561919 100644
--- a/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp
+++ b/services/devicemanagerservice/src/dependency/hichain/hichain_connector.cpp
@@ -196,6 +196,7 @@ int32_t HiChainConnector::AddMember(std::string deviceId, std::string &connectIn
std::string tmpStr = jsonObj.dump();
int64_t requestId = jsonObject[TAG_REQUEST_ID];
int32_t ret = deviceGroupManager_->addMemberToGroup(requestId, DM_PKG_NAME.c_str(), tmpStr.c_str());
+ LOGI("HiChainConnector::tmpStr:%s", tmpStr.c_str());
LOGI("HiChainConnector::AddMember completed");
return ret;
}