diff --git a/ext/BUILD.gn b/ext/BUILD.gn index 99bdeaa31544d9b55b164f8f3ef421f0f3dd0954..d037dc55cf03ec4963e143591ebb2c8807a09e37 100644 --- a/ext/BUILD.gn +++ b/ext/BUILD.gn @@ -21,7 +21,11 @@ group("ext_modules") { if (device_manager_base_no_interaction_auth) { deps += [ "./no_interaction_auth:devicemanagerext_no_interaction_auth" ] } else { - deps += [ "./pin_auth:devicemanagerext_pin_auth" ] + deps += [ + "./pin_auth:devicemanagerext_pin_auth", + "./qr_code_auth:devicemanager_qrcodeauth", + "./nfc_auth:devicemanager_nfcauth" + ] } } } diff --git a/ext/nfc_auth/BUILD.gn b/ext/nfc_auth/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6a75b9c18b61b90d39d6dec63fe49fa1710291de --- /dev/null +++ b/ext/nfc_auth/BUILD.gn @@ -0,0 +1,105 @@ +# 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. + +if (defined(ohos_lite)) { + import("//build/lite/config/component/lite_component.gni") +} else { + import("//build/ohos.gni") +} + +import("//foundation/distributedhardware/devicemanager/devicemanager.gni") + +if (defined(ohos_lite)) { +} else { + ohos_shared_library("devicemanager_nfcauth") { + include_dirs = [ + "include", + "${common_path}/include", + "${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 = [ + "src/nfc_auth.cpp" + ] + + deps = [ + "${ext_path}/nfc_auth/show_nfc_dialog/dialog_ui/js:dialog_js_files_etc", + "${ext_path}/nfc_auth/nfc_dialog/dialog_ui/js:dialog_js_files_etc", + "${innerkits_path}/native_cpp:devicemanagersdk", + "${services_path}:devicemanagerservice", + "${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", + ] + + 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 = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"devicemanagerext\"", + "LOG_DOMAIN=0xD004100", + ] + + subsystem_name = "distributedhardware" + + part_name = "device_manager_base" + } +} diff --git a/ext/nfc_auth/include/nfc_auth.h b/ext/nfc_auth/include/nfc_auth.h new file mode 100644 index 0000000000000000000000000000000000000000..75b450c3d8f7d69b76d82cbfd130badf7c2e0247 --- /dev/null +++ b/ext/nfc_auth/include/nfc_auth.h @@ -0,0 +1,38 @@ +/* + * 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. + */ + +#ifndef OHOS_DM_TOUCH_AUTH_H +#define OHOS_DM_TOUCH_AUTH_H + +#include +#include + +#include "authentication.h" +#include "dm_auth_manager.h" + +namespace OHOS { +namespace DistributedHardware { +class NFCAuth : public IAuthentication { +public: + NFCAuth(); + ~NFCAuth(); + int32_t ShowAuthInfo(std::string &authToken, std::shared_ptr authManager) override; + int32_t StartAuth(std::string &authToken, std::shared_ptr authManager) override; + int32_t VerifyAuthentication(std::string &authToken, const std::string &authParam) override; + int32_t CloseAuthInfo(const int32_t &pageId, std::shared_ptr authManager) override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_TOUCH_AUTH_H \ No newline at end of file diff --git a/ext/nfc_auth/nfc_dialog/dialog_ui/js/BUILD.gn b/ext/nfc_auth/nfc_dialog/dialog_ui/js/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ce1e0a5813a93ca757f37350dce56498f6969958 --- /dev/null +++ b/ext/nfc_auth/nfc_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/nfc_auth/nfc_dialog/dialog_ui/js" + dialog_name = "nfc_service" + part_name = "device_manager_base" + subsystem_name = "distributedhardware" +} diff --git a/ext/nfc_auth/nfc_dialog/dialog_ui/js/common/pincode.png b/ext/nfc_auth/nfc_dialog/dialog_ui/js/common/pincode.png new file mode 100644 index 0000000000000000000000000000000000000000..6616f7659fcf1d5da5ab6796863e32efbe086cdc Binary files /dev/null and b/ext/nfc_auth/nfc_dialog/dialog_ui/js/common/pincode.png differ diff --git a/ext/nfc_auth/nfc_dialog/dialog_ui/js/i18n/en-US.json b/ext/nfc_auth/nfc_dialog/dialog_ui/js/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..0714fc75f8420ac089a6ee1c24c8f2d8472ff511 --- /dev/null +++ b/ext/nfc_auth/nfc_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/nfc_auth/nfc_dialog/dialog_ui/js/i18n/zh-CN.json b/ext/nfc_auth/nfc_dialog/dialog_ui/js/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..53afe2047da6ff0423e5eae8d9f9af9f73d85d0b --- /dev/null +++ b/ext/nfc_auth/nfc_dialog/dialog_ui/js/i18n/zh-CN.json @@ -0,0 +1,5 @@ +{ + "message": { + "hello": "你好世界" + } +} \ No newline at end of file diff --git a/ext/nfc_auth/nfc_dialog/dialog_ui/js/pages/index/index.css b/ext/nfc_auth/nfc_dialog/dialog_ui/js/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..d6b65b0781fc28b3933b4ca103878e1b1b27e073 --- /dev/null +++ b/ext/nfc_auth/nfc_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/nfc_auth/nfc_dialog/dialog_ui/js/pages/index/index.hml b/ext/nfc_auth/nfc_dialog/dialog_ui/js/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..8b2066f1cacd1e8f1271b2a4f5888353bbfd4157 --- /dev/null +++ b/ext/nfc_auth/nfc_dialog/dialog_ui/js/pages/index/index.hml @@ -0,0 +1,19 @@ +
+ + 碰一碰 + + + 请点击确认 + + + 图片 + +
+ + +
+
\ No newline at end of file diff --git a/ext/nfc_auth/nfc_dialog/dialog_ui/js/pages/index/index.js b/ext/nfc_auth/nfc_dialog/dialog_ui/js/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..d033be9487f850f13f11958c4693a4534954e48c --- /dev/null +++ b/ext/nfc_auth/nfc_dialog/dialog_ui/js/pages/index/index.js @@ -0,0 +1,21 @@ +import router from '@ohos.router' + +var code = ""; +export default { + data: { + nfcCode: router.getParams().authToken, + }, + onInit() { + code = router.getParams().authToken; + console.info('getParams: ' + router.getParams()); + callNativeHandler("EVENT_INIT", "0"); + }, + onConfirm() { + console.info('click confirm'); + callNativeHandler("EVENT_CONFIRM", code); + }, + onCancel() { + console.info('click cancel'); + callNativeHandler("EVENT_CANCEL", "2"); + } +} diff --git a/ext/nfc_auth/show_nfc_dialog/dialog_ui/js/BUILD.gn b/ext/nfc_auth/show_nfc_dialog/dialog_ui/js/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a5b0b16ef67ee0c05bb96cbd96a42425c6379b3b --- /dev/null +++ b/ext/nfc_auth/show_nfc_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/nfc_auth/show_nfc_dialog/dialog_ui/js" + dialog_name = "show_nfc_service" + part_name = "device_manager_base" + subsystem_name = "distributedhardware" +} diff --git a/ext/nfc_auth/show_nfc_dialog/dialog_ui/js/common/pincode.png b/ext/nfc_auth/show_nfc_dialog/dialog_ui/js/common/pincode.png new file mode 100644 index 0000000000000000000000000000000000000000..6616f7659fcf1d5da5ab6796863e32efbe086cdc Binary files /dev/null and b/ext/nfc_auth/show_nfc_dialog/dialog_ui/js/common/pincode.png differ diff --git a/ext/nfc_auth/show_nfc_dialog/dialog_ui/js/i18n/en-US.json b/ext/nfc_auth/show_nfc_dialog/dialog_ui/js/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..0714fc75f8420ac089a6ee1c24c8f2d8472ff511 --- /dev/null +++ b/ext/nfc_auth/show_nfc_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/nfc_auth/show_nfc_dialog/dialog_ui/js/i18n/zh-CN.json b/ext/nfc_auth/show_nfc_dialog/dialog_ui/js/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..53afe2047da6ff0423e5eae8d9f9af9f73d85d0b --- /dev/null +++ b/ext/nfc_auth/show_nfc_dialog/dialog_ui/js/i18n/zh-CN.json @@ -0,0 +1,5 @@ +{ + "message": { + "hello": "你好世界" + } +} \ No newline at end of file diff --git a/ext/nfc_auth/show_nfc_dialog/dialog_ui/js/pages/index/index.css b/ext/nfc_auth/show_nfc_dialog/dialog_ui/js/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..d6b65b0781fc28b3933b4ca103878e1b1b27e073 --- /dev/null +++ b/ext/nfc_auth/show_nfc_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/nfc_auth/show_nfc_dialog/dialog_ui/js/pages/index/index.hml b/ext/nfc_auth/show_nfc_dialog/dialog_ui/js/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..2eda353dd683d431c978648793ce3e8f2dc18c3e --- /dev/null +++ b/ext/nfc_auth/show_nfc_dialog/dialog_ui/js/pages/index/index.hml @@ -0,0 +1,14 @@ +
+ + 碰一碰 + + + 若终止,请取消 + + + 图片 + + +
\ No newline at end of file diff --git a/ext/nfc_auth/show_nfc_dialog/dialog_ui/js/pages/index/index.js b/ext/nfc_auth/show_nfc_dialog/dialog_ui/js/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..ab5cdc0b58a6cf3fc322e63bddd6c60167095318 --- /dev/null +++ b/ext/nfc_auth/show_nfc_dialog/dialog_ui/js/pages/index/index.js @@ -0,0 +1,29 @@ +import router from '@ohos.router' + +var timel = null; +export default { + data: { + nfcCode: router.getParams().authToken, + seconds:60, + }, + onInit() { + console.info('getParams: ' + router.getParams()); + callNativeHandler("EVENT_INIT", "0"); + }, + onShow() { + timel = setInterval(this.run,1000) + }, + run() { + this.seconds--; + if (this.seconds == 0) { + clearInterval(timel); + timel = null; + console.info('click cancel'); + callNativeHandler("TIMER_OUT", "2"); + } + }, + onCancel() { + console.info('click cancel'); + callNativeHandler("EVENT_CANCEL", "1"); + } +} \ No newline at end of file diff --git a/ext/nfc_auth/src/nfc_auth.cpp b/ext/nfc_auth/src/nfc_auth.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7e2bc186f3716338e6a51a302b270f490f549ef8 --- /dev/null +++ b/ext/nfc_auth/src/nfc_auth.cpp @@ -0,0 +1,126 @@ +/* + * 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. + */ + +#include "nfc_auth.h" + +#include + +#include "dm_constants.h" +#include "dm_log.h" +#include "nlohmann/json.hpp" +#include "ui_service_mgr_client.h" +namespace OHOS { +namespace DistributedHardware { +NFCAuth::NFCAuth() +{ + LOGI("NFCAuth constructor"); +} + +NFCAuth::~NFCAuth() +{ +} + +int32_t NFCAuth::ShowAuthInfo(std::string &authToken, std::shared_ptr authManager) +{ + LOGI("ShowNFCDialog start"); + if (authManager == nullptr) { + LOGI("authManager is nullptr"); + return DM_POINT_NULL; + } + nlohmann::json jsonObj; + jsonObj[TAG_AUTH_TOKEN] = authToken; + jsonObj.dump(); + const std::string params = jsonObj.dump(); + + Ace::UIServiceMgrClient::GetInstance()->ShowDialog( + "show_nfc_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) { + LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); + if (strcmp(event.c_str(), "EVENT_INIT") == 0) { + authManager->SetPageId(id); + } else if (event == "TIMER_OUT"){ + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + authManager->SetReason(DM_TIME_OUT, AuthState::AUTH_RESPONSE_SHOW); + authManager->AuthenticateFinish(); + } else + { + authManager->SetReason(DM_AUTH_PEER_REJECT, AuthState::AUTH_RESPONSE_SHOW); + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + authManager->AuthenticateFinish(); + } + + }); + LOGI("ShowNFCDialog end"); + return DM_OK; +} + +int32_t NFCAuth::StartAuth(std::string &authToken, std::shared_ptr authManager) +{ + LOGI("NFCDialog start"); + if (authManager == nullptr) { + LOGI("authManager is nullptr"); + return DM_POINT_NULL; + } + nlohmann::json jsonObj; + jsonObj[TAG_AUTH_TOKEN] = authToken; + jsonObj.dump(); + const std::string params = jsonObj.dump(); + + Ace::UIServiceMgrClient::GetInstance()->ShowDialog( + "nfc_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) { + LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); + if (strcmp(event.c_str(), "EVENT_INIT") == 0) { + authManager->SetPageId(id); + } else if (strcmp(event.c_str(), "EVENT_CONFIRM") == 0) { + authManager->VerifyAuthentication(params); + } else { + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + authManager->SetReason(DM_AUTH_DONT_AUTH, AuthState::AUTH_REQUEST_INPUT); + authManager->AuthenticateFinish(); + } + }); + LOGI("NFCDialog end"); + return DM_OK; +} + +int32_t NFCAuth::VerifyAuthentication(std::string &authToken, const std::string &authParam) +{ + if (authToken == authParam) { + return DM_OK; + } + return DM_FAILED; +} + +int32_t NFCAuth::CloseAuthInfo(const int32_t &pageId, std::shared_ptr authManager) +{ + LOGI("PinAuthUi start"); + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(pageId); + LOGI("PinAuthUi end"); + return DM_OK; +} + +extern "C" IAuthentication *CreateNfcAuthObject(void) +{ + return new NFCAuth; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/ext/qr_code_auth/BUILD.gn b/ext/qr_code_auth/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..58f62c002791a2db39a9a452b7bcaaba13fba498 --- /dev/null +++ b/ext/qr_code_auth/BUILD.gn @@ -0,0 +1,105 @@ +# 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. + +if (defined(ohos_lite)) { + import("//build/lite/config/component/lite_component.gni") +} else { + import("//build/ohos.gni") +} + +import("//foundation/distributedhardware/devicemanager/devicemanager.gni") + +if (defined(ohos_lite)) { +} else { + ohos_shared_library("devicemanager_qrcodeauth") { + include_dirs = [ + "include", + "${common_path}/include", + "${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 = [ + "src/qr_code_auth.cpp", + ] + + deps = [ + "${utils_path}:devicemanagerutils", + "${services_path}:devicemanagerservice", + "${innerkits_path}/native_cpp:devicemanagersdk", + "${ext_path}/qr_code_auth/qr_code_dialog/dialog_ui/js:dialog_js_files_etc", + "${ext_path}/qr_code_auth/show_qr_code_dialog/dialog_ui/js:dialog_js_files_etc", + "//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", + ] + + 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 = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"devicemanagerext\"", + "LOG_DOMAIN=0xD004100", + ] + + subsystem_name = "distributedhardware" + + part_name = "device_manager_base" + } +} diff --git a/ext/qr_code_auth/include/qr_code_auth.h b/ext/qr_code_auth/include/qr_code_auth.h new file mode 100644 index 0000000000000000000000000000000000000000..7e932bc55f84a75f81870580936b435fd821323f --- /dev/null +++ b/ext/qr_code_auth/include/qr_code_auth.h @@ -0,0 +1,38 @@ +/* + * 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. + */ + +#ifndef OHOS_DM_QR_CODE_AUTH_H +#define OHOS_DM_QR_CODE_AUTH_H + +#include +#include + +#include "authentication.h" +#include "dm_auth_manager.h" + +namespace OHOS { +namespace DistributedHardware { +class QRCodeAuth : public IAuthentication { +public: + QRCodeAuth(); + ~QRCodeAuth(); + int32_t ShowAuthInfo(std::string &authToken, std::shared_ptr authManager) override; + int32_t StartAuth(std::string &authToken, std::shared_ptr authManager) override; + int32_t VerifyAuthentication(std::string &authToken, const std::string &authParam) override; + int32_t CloseAuthInfo(const int32_t &pageId, std::shared_ptr authManager) override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_QR_CODE_AUTH_H \ No newline at end of file diff --git a/ext/qr_code_auth/qr_code_dialog/dialog_ui/js/BUILD.gn b/ext/qr_code_auth/qr_code_dialog/dialog_ui/js/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e4424589f1a7a200e1fa3068d9188879cc5e0fec --- /dev/null +++ b/ext/qr_code_auth/qr_code_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/qr_code_auth/qr_code_dialog/dialog_ui/js" + dialog_name = "qr_code_service" + part_name = "device_manager_base" + subsystem_name = "distributedhardware" +} diff --git a/ext/qr_code_auth/qr_code_dialog/dialog_ui/js/common/pincode.png b/ext/qr_code_auth/qr_code_dialog/dialog_ui/js/common/pincode.png new file mode 100644 index 0000000000000000000000000000000000000000..6616f7659fcf1d5da5ab6796863e32efbe086cdc Binary files /dev/null and b/ext/qr_code_auth/qr_code_dialog/dialog_ui/js/common/pincode.png differ diff --git a/ext/qr_code_auth/qr_code_dialog/dialog_ui/js/i18n/en-US.json b/ext/qr_code_auth/qr_code_dialog/dialog_ui/js/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..0714fc75f8420ac089a6ee1c24c8f2d8472ff511 --- /dev/null +++ b/ext/qr_code_auth/qr_code_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/qr_code_auth/qr_code_dialog/dialog_ui/js/i18n/zh-CN.json b/ext/qr_code_auth/qr_code_dialog/dialog_ui/js/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..53afe2047da6ff0423e5eae8d9f9af9f73d85d0b --- /dev/null +++ b/ext/qr_code_auth/qr_code_dialog/dialog_ui/js/i18n/zh-CN.json @@ -0,0 +1,5 @@ +{ + "message": { + "hello": "你好世界" + } +} \ No newline at end of file diff --git a/ext/qr_code_auth/qr_code_dialog/dialog_ui/js/pages/index/index.css b/ext/qr_code_auth/qr_code_dialog/dialog_ui/js/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..d6b65b0781fc28b3933b4ca103878e1b1b27e073 --- /dev/null +++ b/ext/qr_code_auth/qr_code_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/qr_code_auth/qr_code_dialog/dialog_ui/js/pages/index/index.hml b/ext/qr_code_auth/qr_code_dialog/dialog_ui/js/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..45c8429e09673275d3f00e54e0dccd7c52a1c678 --- /dev/null +++ b/ext/qr_code_auth/qr_code_dialog/dialog_ui/js/pages/index/index.hml @@ -0,0 +1,16 @@ +
+ + 二维码扫描 + + + 二维码扫描框 + +
+ + +
+
\ No newline at end of file diff --git a/ext/qr_code_auth/qr_code_dialog/dialog_ui/js/pages/index/index.js b/ext/qr_code_auth/qr_code_dialog/dialog_ui/js/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..6bcbc976239670231ade67183194d6c0ea430355 --- /dev/null +++ b/ext/qr_code_auth/qr_code_dialog/dialog_ui/js/pages/index/index.js @@ -0,0 +1,21 @@ +import router from '@ohos.router' + +var code = ""; +export default { + data: { + qr_code: router.getParams().authToken, + }, + onInit() { + code = router.getParams().authToken; + console.info('getParams: ' + router.getParams()); + callNativeHandler("EVENT_INIT", "0"); + }, + onConfirm() { + console.info('click confirm'); + callNativeHandler("EVENT_CONFIRM", code); + }, + onCancel() { + console.info('click cancel'); + callNativeHandler("EVENT_CANCEL", "2"); + } +} \ No newline at end of file diff --git a/ext/qr_code_auth/show_qr_code_dialog/dialog_ui/js/BUILD.gn b/ext/qr_code_auth/show_qr_code_dialog/dialog_ui/js/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f23aef5c3193de0310e9112477bde544f92c5b74 --- /dev/null +++ b/ext/qr_code_auth/show_qr_code_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/qr_code_auth/show_qr_code_dialog/dialog_ui/js" + dialog_name = "show_qr_code_dialog" + part_name = "device_manager_base" + subsystem_name = "distributedhardware" +} diff --git a/ext/qr_code_auth/show_qr_code_dialog/dialog_ui/js/common/pincode.png b/ext/qr_code_auth/show_qr_code_dialog/dialog_ui/js/common/pincode.png new file mode 100644 index 0000000000000000000000000000000000000000..6616f7659fcf1d5da5ab6796863e32efbe086cdc Binary files /dev/null and b/ext/qr_code_auth/show_qr_code_dialog/dialog_ui/js/common/pincode.png differ diff --git a/ext/qr_code_auth/show_qr_code_dialog/dialog_ui/js/i18n/en-US.json b/ext/qr_code_auth/show_qr_code_dialog/dialog_ui/js/i18n/en-US.json new file mode 100644 index 0000000000000000000000000000000000000000..0714fc75f8420ac089a6ee1c24c8f2d8472ff511 --- /dev/null +++ b/ext/qr_code_auth/show_qr_code_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/qr_code_auth/show_qr_code_dialog/dialog_ui/js/i18n/zh-CN.json b/ext/qr_code_auth/show_qr_code_dialog/dialog_ui/js/i18n/zh-CN.json new file mode 100644 index 0000000000000000000000000000000000000000..53afe2047da6ff0423e5eae8d9f9af9f73d85d0b --- /dev/null +++ b/ext/qr_code_auth/show_qr_code_dialog/dialog_ui/js/i18n/zh-CN.json @@ -0,0 +1,5 @@ +{ + "message": { + "hello": "你好世界" + } +} \ No newline at end of file diff --git a/ext/qr_code_auth/show_qr_code_dialog/dialog_ui/js/pages/index/index.css b/ext/qr_code_auth/show_qr_code_dialog/dialog_ui/js/pages/index/index.css new file mode 100644 index 0000000000000000000000000000000000000000..d6b65b0781fc28b3933b4ca103878e1b1b27e073 --- /dev/null +++ b/ext/qr_code_auth/show_qr_code_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/qr_code_auth/show_qr_code_dialog/dialog_ui/js/pages/index/index.hml b/ext/qr_code_auth/show_qr_code_dialog/dialog_ui/js/pages/index/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..e05240ebe86afdf21b76d73d9bbe687d51c492c2 --- /dev/null +++ b/ext/qr_code_auth/show_qr_code_dialog/dialog_ui/js/pages/index/index.hml @@ -0,0 +1,14 @@ +
+ + 通过二维码验证 + + + 请在对端设备扫描二维码进行验证 + + + 图片 + + +
\ No newline at end of file diff --git a/ext/qr_code_auth/show_qr_code_dialog/dialog_ui/js/pages/index/index.js b/ext/qr_code_auth/show_qr_code_dialog/dialog_ui/js/pages/index/index.js new file mode 100644 index 0000000000000000000000000000000000000000..85560bcc0527fe5ce3fd560725dd476b31fc594c --- /dev/null +++ b/ext/qr_code_auth/show_qr_code_dialog/dialog_ui/js/pages/index/index.js @@ -0,0 +1,29 @@ +import router from '@ohos.router' + +var timel = null; +export default { + data: { + qr_code: router.getParams().authToken, + seconds:60, + }, + onInit() { + console.info('getParams: ' + router.getParams()); + callNativeHandler("EVENT_INIT", "0"); + }, + onShow() { + timel = setInterval(this.run,1000) + }, + run() { + this.seconds--; + if (this.seconds == 0) { + clearInterval(timel); + timel = null; + console.info('click cancel'); + callNativeHandler("TIMER_OUT", "2"); + } + }, + onCancel() { + console.info('click cancel'); + callNativeHandler("EVENT_CANCEL", ""); + } +} \ No newline at end of file diff --git a/ext/qr_code_auth/src/qr_code_auth.cpp b/ext/qr_code_auth/src/qr_code_auth.cpp new file mode 100644 index 0000000000000000000000000000000000000000..54fee65c06edfa125e08ba679d444486f1204128 --- /dev/null +++ b/ext/qr_code_auth/src/qr_code_auth.cpp @@ -0,0 +1,125 @@ +/* + * 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. + */ + +#include "qr_code_auth.h" + +#include + +#include "dm_constants.h" +#include "dm_log.h" +#include "nlohmann/json.hpp" +#include "ui_service_mgr_client.h" +namespace OHOS { +namespace DistributedHardware { +QRCodeAuth::QRCodeAuth() +{ + LOGI("QRCodeAuth constructor"); +} + +QRCodeAuth::~QRCodeAuth() +{ +} + +int32_t QRCodeAuth::ShowAuthInfo(std::string &authToken, std::shared_ptr authManager) +{ + LOGI("ShowQRcodeDialog start"); + if (authManager == nullptr) { + LOGI("authManager is nullptr"); + return DM_POINT_NULL; + } + nlohmann::json jsonObj; + jsonObj[TAG_AUTH_TOKEN] = authToken; + jsonObj.dump(); + const std::string params = jsonObj.dump(); + + Ace::UIServiceMgrClient::GetInstance()->ShowDialog( + "show_qr_code_dialog", + 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) { + LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); + if (strcmp(event.c_str(), "EVENT_INIT") == 0) { + authManager->SetPageId(id); + } else if (event == "TIMER_OUT"){ + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + authManager->SetReason(DM_TIME_OUT, AuthState::AUTH_RESPONSE_SHOW); + authManager->AuthenticateFinish(); + } else + { + authManager->SetReason(DM_AUTH_PEER_REJECT, AuthState::AUTH_RESPONSE_SHOW); + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + authManager->AuthenticateFinish(); + } + }); + LOGI("ShowQRcodeDialog end"); + return DM_OK; +} + +int32_t QRCodeAuth::StartAuth(std::string &authToken, std::shared_ptr authManager) +{ + LOGI("QRcodeDialog start"); + if (authManager == nullptr) { + LOGI("authManager is nullptr"); + return DM_POINT_NULL; + } + nlohmann::json jsonObj; + jsonObj[TAG_AUTH_TOKEN] = authToken; + jsonObj.dump(); + const std::string params = jsonObj.dump(); + + Ace::UIServiceMgrClient::GetInstance()->ShowDialog( + "qr_code_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) { + LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); + if (strcmp(event.c_str(), "EVENT_INIT") == 0) { + authManager->SetPageId(id); + } else if (strcmp(event.c_str(), "EVENT_CONFIRM") == 0) { + authManager->VerifyAuthentication(params); + } else { + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + authManager->SetReason(DM_AUTH_DONT_AUTH, AuthState::AUTH_REQUEST_INPUT); + authManager->AuthenticateFinish(); + } + }); + LOGI("QRcodeDialog end"); + return DM_OK; +} + +int32_t QRCodeAuth::VerifyAuthentication(std::string &authToken, const std::string &authParam) +{ + if (authToken == authParam) { + return DM_OK; + } + return DM_FAILED; +} + +int32_t QRCodeAuth::CloseAuthInfo(const int32_t &pageId, std::shared_ptr authManager) +{ + LOGI("PinAuthUi start"); + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(pageId); + LOGI("PinAuthUi end"); + return DM_OK; +} + +extern "C" IAuthentication *CreateQRcodeAuthObject(void) +{ + return new QRCodeAuth; +} +} // namespace DistributedHardware +} // namespace OHOS