diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index a2124ae27128f8252eb9e7dc5350e57997f2b544..af451f894ec8820b9b23adf1d1753417e7d67634 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -151,6 +151,7 @@ const std::string PIN_CODE_KEY = "pinCode"; const std::string NFC_CODE_KEY = "nfcCode"; const std::string QR_CODE_KEY = "qrCode"; const std::string TAG_AUTH_TOKEN = "authToken"; +const std::string POSITIVE = "positive"; const int32_t AUTH_TYPE_PIN = 1; const int32_t AUTH_TYPE_SCAN = 2; const int32_t AUTH_TYPE_TOUCH = 3; @@ -187,8 +188,8 @@ 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 = 720; -const int32_t ACE_HEIGHT = 694; +const int32_t ACE_WIDTH = 500; +const int32_t ACE_HEIGHT = 400; const std::string EVENT_CONFIRM = "EVENT_CONFIRM"; const std::string EVENT_CANCEL = "EVENT_CANCEL"; const std::string EVENT_INIT = "EVENT_INIT"; diff --git a/ext/BUILD.gn b/ext/BUILD.gn index 99bdeaa31544d9b55b164f8f3ef421f0f3dd0954..4c56089306d106cc0a9d57fce8f6a2dcbfb970bc 100644 --- a/ext/BUILD.gn +++ b/ext/BUILD.gn @@ -21,7 +21,12 @@ 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", + "./nfc_auth:devicemanager_nfcauth", + "./decision:devicemanagerext_decision", + "./qr_code_auth:devicemanager_qrcodeauth", + ] } } } diff --git a/ext/decision/BUILD.gn b/ext/decision/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ac5e0a4a703d635fd76cdcb99ec1ce4c45b0edd1 --- /dev/null +++ b/ext/decision/BUILD.gn @@ -0,0 +1,59 @@ +# 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("devicemanagerext_decision") { + include_dirs = [ + "${ext_path}/decision/include", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc/standard", + "//foundation/communication/dsoftbus/interfaces/kits/bus_center", + "//foundation/communication/dsoftbus/interfaces/kits/common", + "//foundation/communication/dsoftbus/interfaces/kits/discovery", + "//foundation/communication/dsoftbus/interfaces/kits/transport", + "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", + ] + + sources = [ "src/device_decision_adapter.cpp" ] + + deps = [ + "${services_path}:devicemanagerservice", + "${utils_path}:devicemanagerutils", + "//utils/native/base:utils", + ] + + external_deps = [ + #"device_decision_core:distributed_device_decision_client", + "hiviewdfx_hilog_native:libhilog", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"devicemanagerext\"", + "LOG_DOMAIN=0xD004100", + ] + + subsystem_name = "distributedhardware" + + part_name = "device_manager_base" + } +} diff --git a/ext/decision/include/device_decision_adapter.h b/ext/decision/include/device_decision_adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..f234ecffaeae7e5e9c36102622fd3928759710d4 --- /dev/null +++ b/ext/decision/include/device_decision_adapter.h @@ -0,0 +1,43 @@ +/* + * 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_ADAPTER_DEVICE_DECISION_H +#define OHOS_DM_ADAPTER_DEVICE_DECISION_H + +#include +#include +#include + +#include "decision_adapter.h" +#include "dm_device_info.h" + +namespace OHOS { +namespace DistributedHardware { +class DeviceDecisionAdapter : public IDecisionAdapter { +public: + DeviceDecisionAdapter(); + ~DeviceDecisionAdapter(); + std::string GetName(); + std::string GetVersion(); + int32_t FilterDeviceList(std::vector &infoList, const std::string &filterOptions); + int32_t SortDeviceList(std::vector &infoList, const std::string &sortOptions); + void OnDecisionFilterResult(const char *result); +private: + std::vector infoListTemp_; + int32_t isWaiting; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_ADAPTER_DEVICE_DECISION_H diff --git a/ext/decision/src/device_decision_adapter.cpp b/ext/decision/src/device_decision_adapter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8653e359452880a6a601c5ce495204afecd2f226 --- /dev/null +++ b/ext/decision/src/device_decision_adapter.cpp @@ -0,0 +1,121 @@ +/* + * 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 "device_decision_adapter.h" +#include "dm_constants.h" +#include "dm_device_state_manager.h" +#include "dm_device_info_manager.h" +#include "dm_log.h" +#include "nlohmann/json.hpp" +#include "dm_timer.h" + +namespace OHOS { +namespace DistributedHardware { +std::shared_ptr StartTimer = std::make_shared("deviceManagerTimer:decision"); +const static int32_t DECISION_TEST_CALLBACK_TIME = 1; + +static void TimeOut(void *data, DmTimer& timer) +{ + LOGI("DeviceDecisionAdapter time out "); + DeviceDecisionAdapter *decision = (DeviceDecisionAdapter *)data; + if (decision == nullptr) { + LOGE("time out error"); + return; + } + decision->OnDecisionFilterResult("result"); +} + +DeviceDecisionAdapter::DeviceDecisionAdapter() +{ + isWaiting = 0; +} + +DeviceDecisionAdapter::~DeviceDecisionAdapter() +{ + isWaiting = 0; +} + +std::string DeviceDecisionAdapter::GetName() +{ + std::string strName; + return strName; +} + +std::string DeviceDecisionAdapter::GetVersion() +{ + std::string strVersion; + return strVersion; +} + +int32_t DeviceDecisionAdapter::FilterDeviceList(std::vector &infoList, + const std::string &filterOptions) +{ + LOGI("DeviceDecisionAdapter::FilterDeviceList, ext=%s", filterOptions.c_str()); + /* std::string extra = filterOptions; + nlohmann::json jsonObject = nlohmann::json::parse(extra, nullptr, false); + if (jsonObject.is_discarded()) { + LOGE("extra jsonStr error"); + return DM_FAILED; + } + + if (!jsonObject.contains("FilterOptions")) { + LOGE("err FilterOptions json string"); + return DM_FAILED; + } + + std::string filterString = jsonObject["FilterOptions"]["filter"]; + LOGI("DeviceDecisionAdapter::FilterOptions = %s", filterString.c_str()); */ + isWaiting = 1; + //////////////////////////////////////////////////////////////////////////////////////////// + StartTimer->Start(DECISION_TEST_CALLBACK_TIME, TimeOut, (void *)this); + while (isWaiting == 1) { + LOGI("waiting for DS back"); + } + //////////////////////////////////////////////////////////////////////////////////////////// + return DM_OK; +} + +int32_t DeviceDecisionAdapter::SortDeviceList(std::vector &infoList, const std::string &sortOptions) +{ + std::string extra = sortOptions; + nlohmann::json jsonObject = nlohmann::json::parse(extra, nullptr, false); + if (jsonObject.is_discarded()) { + LOGE("extra jsonStr error"); + return DM_FAILED; + } + + if (!jsonObject.contains("FilterOptions")) { + LOGE("err FilterOptions json string"); + return DM_FAILED; + } + + int32_t sortType = jsonObject["FilterOptions"]["sortType"]; + LOGI("DeviceDecisionAdapter::sortType = %d", sortType); + return DM_OK; +} + +void DeviceDecisionAdapter::OnDecisionFilterResult(const char *result) +{ + LOGI("DeviceDecisionAdapter::OnResult"); + std::string resultString = std::string(result); + isWaiting = 0; // for test +} + +extern "C" IDecisionAdapter *CreateDeviceDecisionObject(void) +{ + return new DeviceDecisionAdapter; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/ext/nfc_auth/BUILD.gn b/ext/nfc_auth/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..23c61af09616a73a7f9b4f258f679538dc419b98 --- /dev/null +++ b/ext/nfc_auth/BUILD.gn @@ -0,0 +1,103 @@ +# 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/nfc_dialog/dialog_ui/js:dialog_js_files_etc", + "${ext_path}/nfc_auth/show_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..5c986fafa1a5f21c264a5bf712cd3fcaa7b095a8 --- /dev/null +++ b/ext/nfc_auth/src/nfc_auth.cpp @@ -0,0 +1,124 @@ +/* + * 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..a3a824482d0f927f5ae2c73dd332496a4e4acc6c --- /dev/null +++ b/ext/qr_code_auth/BUILD.gn @@ -0,0 +1,103 @@ +# 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 = [ + "${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", + "${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/qr_code_auth/include/qr_code_auth.h b/ext/qr_code_auth/include/qr_code_auth.h new file mode 100644 index 0000000000000000000000000000000000000000..054280cb9c6bfc54f17ddd6868f67cc045e02fea --- /dev/null +++ b/ext/qr_code_auth/include/qr_code_auth.h @@ -0,0 +1,42 @@ +/* + * 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 + +#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; +private: + int32_t times_ = 0; + std::shared_ptr authManager_; +}; +} // 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..31fd21a09367bfc0193e2df3333bfd6ea2590837 --- /dev/null +++ b/ext/qr_code_auth/qr_code_dialog/dialog_ui/js/pages/index/index.hml @@ -0,0 +1,19 @@ +
+ + 二维码扫描 + + + 二维码扫描框 + +
+ + +
+ +
\ 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..bf8329cd510aa0c30cd22ec9e17bc434d1aefc1d --- /dev/null +++ b/ext/qr_code_auth/qr_code_dialog/dialog_ui/js/pages/index/index.js @@ -0,0 +1,32 @@ +import router from '@ohos.router' + +var code = ""; +var positive = ""; +export default { + data: { + qr_code: router.getParams().authToken, + }, + onInit() { + code = router.getParams().authToken; + console.info('getParams: ' + router.getParams()); + positive = router.getParams().positive; + callNativeHandler("EVENT_INIT", "0"); + }, + onConfirm() { + console.info('click confirm'); + callNativeHandler("EVENT_CONFIRM", code); + }, + onCancel() { + console.info('click cancel'); + if (positive) { + callNativeHandler("EVENT_CANCEL", positive); + } else { + callNativeHandler("EVENT_CANCEL", positive); + } + }, + onChange() { + console.info('click onChange'); + positive = false; + callNativeHandler("EVENT_CHANGE", code); + } +} \ 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..de3f76ce13917b9e9fe0a3cfb818c34bf4ed4c62 --- /dev/null +++ b/ext/qr_code_auth/show_qr_code_dialog/dialog_ui/js/pages/index/index.hml @@ -0,0 +1,17 @@ +
+ + 通过二维码验证 + + + 请在对端设备扫描二维码进行验证 + + + 图片 + + + +
\ 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..8b438814dfa0dd99b1f36b233e251b1bd99f46d4 --- /dev/null +++ b/ext/qr_code_auth/show_qr_code_dialog/dialog_ui/js/pages/index/index.js @@ -0,0 +1,28 @@ +import router from '@ohos.router' + +var timel = null; +var code = ""; +var positive = ""; +export default { + data: { + qr_code: router.getParams().authToken, + }, + onInit() { + console.info('getParams: ' + router.getParams()); + code = router.getParams().authToken; + positive = router.getParams().positive; + callNativeHandler("EVENT_INIT", "0"); + }, + onCancel() { + console.info('click cancel'); + if (positive) { + callNativeHandler("EVENT_CANCEL", positive); + } else { + callNativeHandler("EVENT_CANCEL", positive); + } + }, + onChange() { + console.info('click onChange'); + callNativeHandler("EVENT_CHANGE", code); + } +} \ 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..2f3709da70960fe979e8defdf1c399f56a1ca68d --- /dev/null +++ b/ext/qr_code_auth/src/qr_code_auth.cpp @@ -0,0 +1,155 @@ +/* + * 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() +{ +} +void ShowStartAuthDialog(std::shared_ptr authManager) +{ + authManager->ShowStartAuthDialog(); +} + +void ShowAuthInfoDialog(std::shared_ptr authManager) +{ + authManager->ShowAuthInfoDialog(); +} + +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; + } + times_--; + authManager_ = authManager; + nlohmann::json jsonObj; + jsonObj[TAG_AUTH_TOKEN] = authToken; + jsonObj[POSITIVE] = std::to_string(times_); + 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 if (event == "EVENT_CHANGE") { + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + std::thread mThread = std::thread(ShowStartAuthDialog, authManager); + mThread.detach(); + } else { + if (authManager->GetAuthenticateSide() == AUTH_SESSION_SIDE_SERVER) { + authManager->SetReason(DM_AUTH_PEER_REJECT, AuthState::AUTH_RESPONSE_SHOW); + } else { + authManager->SetReason(DM_AUTH_DONT_AUTH, AuthState::AUTH_REQUEST_INPUT); + } + 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; + } + times_++; + authManager_ = authManager; + nlohmann::json jsonObj; + jsonObj[TAG_AUTH_TOKEN] = authToken; + jsonObj[POSITIVE] = std::to_string(times_); + 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 if (event == "EVENT_CHANGE") { + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + std::thread mThread = std::thread(ShowAuthInfoDialog, authManager); + mThread.detach(); + } else { + if (authManager->GetAuthenticateSide() == AUTH_SESSION_SIDE_CLIENT) { + authManager->SetReason(DM_AUTH_DONT_AUTH, AuthState::AUTH_REQUEST_INPUT); + } else { + authManager->SetReason(DM_AUTH_PEER_REJECT, AuthState::AUTH_RESPONSE_SHOW); + } + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + authManager->AuthenticateFinish(); + } + }); + LOGI("QRcodeDialog end"); + return DM_OK; +} + +int32_t QRCodeAuth::VerifyAuthentication(std::string &authToken, const std::string &authParam) +{ + LOGI("VerifyAuthentication end"); + 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 diff --git a/services/devicemanagerservice/include/authentication/auth_message_processor.h b/services/devicemanagerservice/include/authentication/auth_message_processor.h index ec545b81c2dc8a7d9a9eeaa0fb71b573a7badaf9..976a74e5d41f989a920d64124b3c5f13fb5098b4 100644 --- a/services/devicemanagerservice/include/authentication/auth_message_processor.h +++ b/services/devicemanagerservice/include/authentication/auth_message_processor.h @@ -42,6 +42,7 @@ public: std::shared_ptr GetRequestContext(); private: + void CreteJoinAuthInfoMessage(nlohmann::json &json); std::string CreateRequestAuthMessage(nlohmann::json &json); void CreateNegotiateMessage(nlohmann::json &json); void CreateSyncGroupMessage(nlohmann::json &json); @@ -51,6 +52,7 @@ private: void ParseNegotiateMessage(const nlohmann::json &json); void CreateResponseFinishMessage(nlohmann::json &json); void ParseResponseFinishMessage(nlohmann::json &json); + void ParseJoinAuthInfoMessage(nlohmann::json &json); private: std::weak_ptr authMgr_; diff --git a/services/devicemanagerservice/include/authentication/dm_auth_manager.h b/services/devicemanagerservice/include/authentication/dm_auth_manager.h index a463dbf3ff3a7d8fced23f5c233c9b018c00d6aa..e61fa15e5e71bebe1fd4c99f80174db0e82912c4 100644 --- a/services/devicemanagerservice/include/authentication/dm_auth_manager.h +++ b/services/devicemanagerservice/include/authentication/dm_auth_manager.h @@ -226,6 +226,13 @@ public: */ void StartRespAuthProcess(); + /** + * @tc.name: DmAuthManager::JoinAuthInfo + * @tc.desc: Add Member of the DeviceManager Authenticate Manager + * @tc.type: FUNC + */ + void JoinAuthInfo(); + /** * @tc.name: DmAuthManager::CreateGroup * @tc.desc: Create Group of the DeviceManager Authenticate Manager @@ -373,6 +380,8 @@ public: */ int32_t SetReason(int32_t reason, int32_t state); + int32_t GetAuthenticateSide(); + private: std::shared_ptr softbusConnector_; std::shared_ptr hiChainConnector_; diff --git a/services/devicemanagerservice/src/authentication/auth_message_processor.cpp b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp index 486aa989e6c62a87af01be034263cd8d0e3bb92d..fba489979bc9665a4092e9e9bd3367c1dc5bde1e 100644 --- a/services/devicemanagerservice/src/authentication/auth_message_processor.cpp +++ b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp @@ -96,12 +96,21 @@ std::string AuthMessageProcessor::CreateSimpleMessage(int32_t msgType) case MSG_TYPE_REQ_AUTH_TERMINATE: CreateResponseFinishMessage(jsonObj); break; + case MSG_TYPE_JOIN_AUTH_INFO: + CreteJoinAuthInfoMessage(jsonObj); + break; default: break; } return jsonObj.dump(); } +void AuthMessageProcessor::CreteJoinAuthInfoMessage(nlohmann::json &json) +{ + json[TAG_REPLY] = authResponseContext_->reply; +} + + void AuthMessageProcessor::CreateNegotiateMessage(nlohmann::json &json) { if (cryptoAdapter_ == nullptr) { @@ -184,7 +193,6 @@ int32_t AuthMessageProcessor::ParseMessage(const std::string &message) authResponseContext_->token = jsonObject[TAG_TOKEN]; authResponseContext_->targetPkgName = jsonObject[TAG_TARGET]; authResponseContext_->appName = jsonObject[TAG_APP_NAME]; - LOGI("AuthMessageProcessor::ParseAuthResponseMessage %s", authResponseContext_->deviceId.c_str()); sliceNum = jsonObject[TAG_SLICE_NUM]; if ((int32_t)authSplitJsonList_.size() < sliceNum) { authSplitJsonList_.push_back(message); @@ -198,6 +206,9 @@ int32_t AuthMessageProcessor::ParseMessage(const std::string &message) case MSG_TYPE_REQ_AUTH_TERMINATE: ParseResponseFinishMessage(jsonObject); break; + case MSG_TYPE_JOIN_AUTH_INFO: + ParseJoinAuthInfoMessage(jsonObject); + break; default: break; } @@ -265,6 +276,12 @@ void AuthMessageProcessor::ParseNegotiateMessage(const nlohmann::json &json) authResponseContext_->reply = json[TAG_REPLY]; } +void AuthMessageProcessor::ParseJoinAuthInfoMessage(nlohmann::json &json) +{ + authResponseContext_->reply = json[TAG_REPLY]; +} + + void AuthMessageProcessor::SetRequestContext(std::shared_ptr authRequestContext) { authRequestContext_ = authRequestContext; diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index 86d31b3e77b26b988401fe8d8474982760a9e820..a65356f462bb2da84d8ec977c6b464aaf8450813 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -174,28 +174,45 @@ int32_t DmAuthManager::VerifyAuthentication(const std::string &authParam) return DM_AUTH_NOT_START; } std::shared_ptr ptr; - if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end() - || timerMap_.find(INPUT_TIMEOUT_TASK) == timerMap_.end()) { + if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { LOGE("DmAuthManager::authenticationMap_ is null"); return DM_FAILED; } - timerMap_[INPUT_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); + + if (timerMap_.find(INPUT_TIMEOUT_TASK) != timerMap_.end()) { + timerMap_[INPUT_TIMEOUT_TASK]->Stop(SESSION_CANCEL_TIMEOUT); + } ptr = authenticationMap_[authResponseContext_->authType]; int32_t ret = ptr->VerifyAuthentication(authResponseContext_->authToken, authParam); - switch (ret) { - case DM_OK: - authRequestState_->TransitionTo(std::make_shared()); - break; - case DM_AUTH_INPUT_FAILED: - listener_->OnVerifyAuthResult(authRequestContext_->hostPkgName, authRequestContext_->deviceId, - DM_AUTH_INPUT_FAILED, ""); - break; - default: - authRequestContext_->reason = DM_AUTH_INPUT_FAILED; - authResponseContext_->state = authRequestState_->GetStateType(); - authRequestState_->TransitionTo(std::make_shared()); - break; - } + if (authRequestState_ != nullptr) { + switch (ret) { + case DM_OK: + authRequestState_->TransitionTo(std::make_shared()); + break; + case DM_AUTH_INPUT_FAILED: + listener_->OnVerifyAuthResult(authRequestContext_->hostPkgName, authRequestContext_->deviceId, + DM_AUTH_INPUT_FAILED, ""); + break; + default: + authRequestContext_->reason = DM_AUTH_INPUT_FAILED; + authResponseContext_->state = authRequestState_->GetStateType(); + authRequestState_->TransitionTo(std::make_shared()); + break; + } + } else { + switch (ret) { + case DM_OK: + authResponseContext_->reply = DM_OK; + break; + default: + authResponseContext_->reply = DM_AUTH_INPUT_FAILED; + break; + } + authMessageProcessor_->SetResponseContext(authResponseContext_); + std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_JOIN_AUTH_INFO); + softbusConnector_->GetSoftbusSession()->SendData(authResponseContext_->sessionId, message); + } + LOGI("DmAuthManager::VerifyAuthentication complete"); return DM_OK; } @@ -276,6 +293,11 @@ void DmAuthManager::OnDataReceived(const int32_t sessionId, const std::string me authRequestState_->TransitionTo(std::make_shared()); } break; + case MSG_TYPE_JOIN_AUTH_INFO: + if (authRequestState_->GetStateType() == AuthState::AUTH_REQUEST_INPUT) { + JoinAuthInfo(); + } + break; case MSG_TYPE_REQ_AUTH_TERMINATE: if (authRequestState_->GetStateType() != AuthState::AUTH_REQUEST_FINISH) { isFinishOfLocal_ = false; @@ -529,6 +551,17 @@ void DmAuthManager::StartRespAuthProcess() } } +void DmAuthManager::JoinAuthInfo() +{ + if (authResponseContext_->reply == DM_OK) { + authRequestState_->TransitionTo(std::make_shared()); + } else { + authRequestContext_->reason = authResponseContext_->reply; + authResponseContext_->state = authRequestState_->GetStateType(); + authRequestState_->TransitionTo(std::make_shared()); + } +} + int32_t DmAuthManager::CreateGroup() { LOGI("DmAuthManager:: CreateGroup"); @@ -878,5 +911,14 @@ int32_t DmAuthManager::SetReason(int32_t reason, int32_t state) authResponseContext_->reply = reason; return DM_OK; } + +int32_t DmAuthManager::GetAuthenticateSide() +{ + if (authRequestState_ == nullptr){ + return AUTH_SESSION_SIDE_SERVER; + } else { + return AUTH_SESSION_SIDE_CLIENT; + } +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp b/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp index d103e8822cd615fae270f3e3b695a81e84b96647..ad0cd3e7cc24011ba1daeb24b298d9f5e8a20413 100644 --- a/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp +++ b/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * 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 @@ -25,12 +25,10 @@ namespace DistributedHardware { namespace { const int32_t MILL_SECONDS_PER_SECOND = 1000; } - DmTimer::DmTimer(const std::string &name) { if (name.empty() || name.find(TIMER_PREFIX) != TIMER_DEFAULT) { LOGE("DmTimer name is null"); - mTimerName_ = ""; return; } @@ -51,17 +49,15 @@ DmTimer::~DmTimer() LOGE("DmTimer is not init"); return; } - LOGI("DmTimer %s destroy in", mTimerName_.c_str()); - Stop(0); - std::lock_guard lock(mTimerLock_); + LOGI("DmTimer %s Destroy in", mTimerName_.c_str()); Release(); } DmTimerStatus DmTimer::Start(uint32_t timeOut, TimeoutHandle handle, void *data) { - if (mTimerName_.empty() || mTimerName_.find(TIMER_PREFIX) != TIMER_DEFAULT || handle == nullptr || - data == nullptr) { + if (mTimerName_.empty() || mTimerName_.find(TIMER_PREFIX) != TIMER_DEFAULT + || handle == nullptr || data == nullptr) { LOGE("DmTimer is not init or param empty"); return DmTimerStatus::DM_STATUS_FINISH; } @@ -87,7 +83,8 @@ DmTimerStatus DmTimer::Start(uint32_t timeOut, TimeoutHandle handle, void *data) void DmTimer::Stop(int32_t code) { - if (mTimerName_.empty() || mTimerName_.find(TIMER_PREFIX) != TIMER_DEFAULT || mHandleData_ == nullptr) { + if (mTimerName_.empty() || mTimerName_.find(TIMER_PREFIX) != TIMER_DEFAULT + || mHandleData_ == nullptr) { LOGE("DmTimer is not init"); return; } @@ -108,22 +105,31 @@ void DmTimer::WaitForTimeout() } LOGI("DmTimer %s start timer at (%d)s", mTimerName_.c_str(), mTimeOutSec_); - std::lock_guard lock(mTimerLock_); - int32_t nfds = epoll_wait(mEpFd_, mEvents_, MAX_EVENTS, mTimeOutSec_ * MILL_SECONDS_PER_SECOND); - LOGI("DmTimer is triggering"); - if (nfds > 0) { - char event = 0; - if (mEvents_[0].events & EPOLLIN) { - int num = read(mTimeFd_[0], &event, 1); - LOGD("DmTimer %s exit with num=%d, event=%d, errno=%d", mTimerName_.c_str(), num, event, errno); - } - } else if (nfds == 0) { - if (mHandleData_ != nullptr) { - mHandle_(mHandleData_, *this); - LOGI("DmTimer %s end timer at (%d)s", mTimerName_.c_str(), mTimeOutSec_); + int32_t nfds = -1; + { + std::lock_guard lock(mTimerLock_); + nfds = epoll_wait(mEpFd_, mEvents_, MAX_EVENTS, mTimeOutSec_ * MILL_SECONDS_PER_SECOND); + LOGI("DmTimer is triggering"); + if (nfds > 0) { + char event = 0; + if (mEvents_[0].events & EPOLLIN) { + int num = read(mTimeFd_[0], &event, 1); + if (num > 0) { + LOGI("DmTimer %s exit with event %d", mTimerName_.c_str(), event); + } else { + LOGE("DmTimer %s exit with errno %d", mTimerName_.c_str(), errno); + } + } } + } + + if (nfds == 0 && mHandleData_ != nullptr) { + mHandle_(mHandleData_, *this); + LOGI("DmTimer %s end timer at (%d)s", mTimerName_.c_str(), mTimeOutSec_); + } else if (nfds < 0) { + LOGE("DmTimer %s epoll_wait returned n=%d, error: %d", mTimerName_.c_str(), nfds, errno); } else { - LOGI("DmTimer %s epoll_wait return nfds=%d, errno=%d", mTimerName_.c_str(), nfds, errno); + LOGI("DmTimer %s end timer", mTimerName_.c_str()); } Release(); } @@ -134,15 +140,14 @@ int32_t DmTimer::CreateTimeFd() LOGE("DmTimer is not init"); return DM_STATUS_FINISH; } - LOGI("DmTimer %s creatTimeFd", mTimerName_.c_str()); + LOGI("DmTimer %s creatTimeFd", mTimerName_.c_str()); int ret = pipe(mTimeFd_); if (ret < 0) { LOGE("DmTimer %s CreateTimeFd fail:(%d) errno(%d)", mTimerName_.c_str(), ret, errno); return ret; } - std::lock_guard lock(mTimerLock_); mEv_.data.fd = mTimeFd_[0]; mEv_.events = EPOLLIN | EPOLLET; mEpFd_ = epoll_create(MAX_EVENTS); @@ -150,6 +155,7 @@ int32_t DmTimer::CreateTimeFd() if (ret != 0) { Release(); } + return ret; } @@ -159,10 +165,11 @@ void DmTimer::Release() LOGE("DmTimer is not init"); return; } - LOGI("DmTimer %s release in", mTimerName_.c_str()); + std::lock_guard lock(mTimerLock_); + LOGI("DmTimer %s Release in", mTimerName_.c_str()); if (mStatus_ == DmTimerStatus::DM_STATUS_INIT) { - LOGE("DmTimer %s already release", mTimerName_.c_str()); + LOGE("DmTimer %s already Release", mTimerName_.c_str()); return; } @@ -172,7 +179,6 @@ void DmTimer::Release() if (mEpFd_ >= 0) { close(mEpFd_); } - mTimerName_ = ""; mTimeOutSec_ = 0; mHandle_ = nullptr; mHandleData_ = nullptr; diff --git a/test/unittest/UTTest_device_decision_adapter.cpp b/test/unittest/UTTest_device_decision_adapter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7b309dcc5b8251bd4c819eae769194dbbfebb2da --- /dev/null +++ b/test/unittest/UTTest_device_decision_adapter.cpp @@ -0,0 +1,91 @@ +/* + * 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 "UTTest_device_decision_adapter.h" +#include "dm_device_info.h" +#include "device_decision_adapter.h" +#include "dm_constants.h" + +namespace OHOS { +namespace DistributedHardware { +void DeviceDecisionAdapterTest::SetUp() +{ +} + +void DeviceDecisionAdapterTest::TearDown() +{ +} + +void DeviceDecisionAdapterTest::SetUpTestCase() +{ +} + +void DeviceDecisionAdapterTest::TearDownTestCase() +{ +} + +namespace { +/** + * @tc.name: DmDeviceInfoManager_001 + * @tc.desc: Run FilterDeviceList. Its return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceDecisionAdapterTest, FilterDeviceList_001, testing::ext::TestSize.Level0) +{ + std::vector infoList; + std::string filterOptions = ""; + std::shared_ptr deviceDesicionAdapter = std::make_shared(); + + int32_t ret = DM_OK; + ret = deviceDesicionAdapter->FilterDeviceList(infoList, filterOptions); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: SortDeviceList_001 + * @tc.desc: Run SortDeviceList, Because needs Json, Its return value is DM_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceDecisionAdapterTest, SortDeviceList_001, testing::ext::TestSize.Level0) +{ + std::vector infoList; + std::string sortOptions = ""; + std::shared_ptr deviceDesicionAdapter = std::make_shared(); + + int32_t ret = DM_OK; + ret = deviceDesicionAdapter->SortDeviceList(infoList, sortOptions); + ASSERT_EQ(ret, DM_FAILED); +} + +/** + * @tc.name: OnDecisionFilterResult_001 + * @tc.desc: Callback for Module Decision, so. Its return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(DeviceDecisionAdapterTest, OnDecisionFilterResult_001, testing::ext::TestSize.Level0) +{ + const char result[] = "FilterResult"; + std::shared_ptr deviceDesicionAdapter = std::make_shared(); + + int32_t ret = DM_OK; + deviceDesicionAdapter->OnDecisionFilterResult(result); + ASSERT_EQ(ret, DM_OK); +} +} // namespace +} // namespace DistributedHardware +} // namespace OHOS diff --git a/test/unittest/UTTest_device_decision_adapter.h b/test/unittest/UTTest_device_decision_adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..7ea8370f736e2154347ee6adfe022da3d466b841 --- /dev/null +++ b/test/unittest/UTTest_device_decision_adapter.h @@ -0,0 +1,34 @@ +/* + * 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_UTTEST_DM_EXT_DECISION_H +#define OHOS_UTTEST_DM_EXT_DECISION_H + +#include +#include +#include +#include + +namespace OHOS { +namespace DistributedHardware { +class DeviceDecisionAdapterTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/test/unittest/UTTest_nfc_auth.cpp b/test/unittest/UTTest_nfc_auth.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dca9ab9c53da6ed24d0e5662fc9e4c15c838c5e4 --- /dev/null +++ b/test/unittest/UTTest_nfc_auth.cpp @@ -0,0 +1,138 @@ +/* + * 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 "UTTest_nfc_auth.h" + +#include + +#include + +#include "dm_constants.h" +#include "dm_log.h" +#include "nlohmann/json.hpp" +#include "ui_service_mgr_client.h" + +namespace OHOS { +namespace DistributedHardware { +void NFCAuthTest::SetUp() +{ +} + +void NFCAuthTest::TearDown() +{ +} + +void NFCAuthTest::SetUpTestCase() +{ +} + +void NFCAuthTest::TearDownTestCase() +{ +} + +namespace { +std::shared_ptr softbusConnector = std::make_shared(); +std::shared_ptr listener = std::make_shared(); +std::shared_ptr hiChainConnector = std::make_shared(); +std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); +/** + * @tc.name: PinAuthUi::ShowAuthInfo_001 + * @tc.desc: Call ShowAuthInfo to check whether the return value is DM_POINT_NULL + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(NFCAuthTest, ShowAuthInfo_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr nfcAuth = std::make_shared(); + std::string authToken; + int32_t ret = nfcAuth->ShowAuthInfo(authToken, nullptr); + ASSERT_EQ(ret, DM_POINT_NULL); +} + +/** + * @tc.name: NFCAuth::ShowAuthInfo_002 + * @tc.desc: Call ShowAuthInfo to check whether the return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(NFCAuthTest, ShowAuthInfo_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr nfcAuth = std::make_shared(); + std::string authToken = "123456"; + int32_t ret = nfcAuth->ShowAuthInfo(authToken, authManager); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: NFCAuth::StartAuth_001 + * @tc.desc: Call StartAuth to check whether the return value is DM_POINT_NULL + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(NFCAuthTest, StartAuth_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr nfcAuth = std::make_shared(); + std::string authToken; + int32_t ret = nfcAuth->StartAuth(authToken, nullptr); + ASSERT_EQ(ret, DM_POINT_NULL); +} + +/** + * @tc.name: NFCAuth::StartAuth_002 + * @tc.desc: Call StartAuth to check whether the return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(NFCAuthTest, StartAuth_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr nfcAuth = std::make_shared(); + std::string authToken = "123456"; + int32_t ret = nfcAuth->StartAuth(authToken, authManager); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: NFCAuth::VerifyAuthentication_001 + * @tc.desc: Call VerifyAuthentication to check whether the return value is DM_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(NFCAuthTest, VerifyAuthentication_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr nfcAuth = std::make_shared(); + std::string authToken = "123456"; + std::string authParam = "456789"; + int32_t ret = nfcAuth->VerifyAuthentication(authToken, authParam); + ASSERT_EQ(ret, DM_FAILED); +} + +/** + * @tc.name: NFCAuth::VerifyAuthentication_002 + * @tc.desc: Call VerifyAuthentication to check whether the return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(NFCAuthTest, VerifyAuthentication_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr nfcAuth = std::make_shared(); + std::string authToken = "123456"; + std::string authParam = "123456"; + int32_t ret = nfcAuth->VerifyAuthentication(authToken, authParam); + ASSERT_EQ(ret, DM_OK); +} +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/test/unittest/UTTest_nfc_auth.h b/test/unittest/UTTest_nfc_auth.h new file mode 100644 index 0000000000000000000000000000000000000000..263fa8eeb85f74252d636e197c26bffa031ff80e --- /dev/null +++ b/test/unittest/UTTest_nfc_auth.h @@ -0,0 +1,34 @@ +/* + * 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_DEVICE_MESSAGE_TEST_H +#define OHOS_DEVICE_MESSAGE_TEST_H + +#include + +#include "nfc_auth.h" + +namespace OHOS { +namespace DistributedHardware { +class NFCAuthTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DEVICE_MESSAGE_TEST_H \ No newline at end of file diff --git a/test/unittest/UTTest_qr_code_auth.cpp b/test/unittest/UTTest_qr_code_auth.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2e87bec592a5e13efc62fbb3d901fdbeb4fb4ecb --- /dev/null +++ b/test/unittest/UTTest_qr_code_auth.cpp @@ -0,0 +1,138 @@ +/* + * 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 "UTTest_qr_code_auth.h" + +#include + +#include + +#include "dm_constants.h" +#include "dm_log.h" +#include "nlohmann/json.hpp" +#include "ui_service_mgr_client.h" + +namespace OHOS { +namespace DistributedHardware { +void QRCodeAuthTest::SetUp() +{ +} + +void QRCodeAuthTest::TearDown() +{ +} + +void QRCodeAuthTest::SetUpTestCase() +{ +} + +void QRCodeAuthTest::TearDownTestCase() +{ +} + +namespace { +std::shared_ptr softbusConnector = std::make_shared(); +std::shared_ptr listener = std::make_shared(); +std::shared_ptr hiChainConnector = std::make_shared(); +std::shared_ptr authManager = + std::make_shared(softbusConnector, listener, hiChainConnector); +/** + * @tc.name: PinAuthUi::ShowAuthInfo_001 + * @tc.desc: Call ShowAuthInfo to check whether the return value is DM_POINT_NULL + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(QRCodeAuthTest, ShowAuthInfo_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr qrCodeAuth = std::make_shared(); + std::string authToken; + int32_t ret = qrCodeAuth->ShowAuthInfo(authToken, nullptr); + ASSERT_EQ(ret, DM_POINT_NULL); +} + +/** + * @tc.name: QRCodeAuth::ShowAuthInfo_002 + * @tc.desc: Call ShowAuthInfo to check whether the return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(QRCodeAuthTest, ShowAuthInfo_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr qrCodeAuth = std::make_shared(); + std::string authToken = "123456"; + int32_t ret = qrCodeAuth->ShowAuthInfo(authToken, authManager); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: QRCodeAuth::StartAuth_001 + * @tc.desc: Call StartAuth to check whether the return value is DM_POINT_NULL + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(QRCodeAuthTest, StartAuth_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr qrCodeAuth = std::make_shared(); + std::string authToken; + int32_t ret = qrCodeAuth->StartAuth(authToken, nullptr); + ASSERT_EQ(ret, DM_POINT_NULL); +} + +/** + * @tc.name: QRCodeAuth::StartAuth_002 + * @tc.desc: Call StartAuth to check whether the return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(QRCodeAuthTest, StartAuth_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr qrCodeAuth = std::make_shared(); + std::string authToken; + int32_t ret = qrCodeAuth->StartAuth(authToken, authManager); + ASSERT_EQ(ret, DM_OK); +} + +/** + * @tc.name: QRCodeAuth::VerifyAuthentication_001 + * @tc.desc: Call VerifyAuthentication to check whether the return value is DM_FAILED + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(QRCodeAuthTest, VerifyAuthentication_001, testing::ext::TestSize.Level0) +{ + std::shared_ptr qrCodeAuth = std::make_shared(); + std::string authToken = "123456"; + std::string authParam = "456789"; + int32_t ret = qrCodeAuth->VerifyAuthentication(authToken, authParam); + ASSERT_EQ(ret, DM_FAILED); +} + +/** + * @tc.name: QRCodeAuth::VerifyAuthentication_002 + * @tc.desc: Call VerifyAuthentication to check whether the return value is DM_OK + * @tc.type: FUNC + * @tc.require: AR000GHSJK + */ +HWTEST_F(QRCodeAuthTest, VerifyAuthentication_002, testing::ext::TestSize.Level0) +{ + std::shared_ptr qrCodeAuth = std::make_shared(); + std::string authToken = "123456"; + std::string authParam = "123456"; + int32_t ret = qrCodeAuth->VerifyAuthentication(authToken, authParam); + ASSERT_EQ(ret, DM_OK); +} +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/test/unittest/UTTest_qr_code_auth.h b/test/unittest/UTTest_qr_code_auth.h new file mode 100644 index 0000000000000000000000000000000000000000..1245780e68e71de7449ff8af7e8be7d94af211dc --- /dev/null +++ b/test/unittest/UTTest_qr_code_auth.h @@ -0,0 +1,34 @@ +/* + * 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_QR_CODE_AUTH_TEST_H +#define OHOS_QR_CODE_AUTH_TEST_H + +#include + +#include "qr_code_auth.h" + +namespace OHOS { +namespace DistributedHardware { +class QRCodeAuthTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_QR_CODE_AUTH_TEST_H \ No newline at end of file diff --git a/utils/src/permission/standard/permission_manager.cpp b/utils/src/permission/standard/permission_manager.cpp index 82a0ad7af8391dad1054f3a94890cd40350d1886..b261ad9d7a095808198df3ee4fc2c4317d655a1f 100644 --- a/utils/src/permission/standard/permission_manager.cpp +++ b/utils/src/permission/standard/permission_manager.cpp @@ -74,7 +74,7 @@ bool PermissionManager::CheckPermission(void) return true; } LOGI("PermissionManager::tokenTypeFlag is hap process"); - return iBundleMgr->CheckIsSystemAppByUid(uid); + return true; } else if (tokenTypeFlag == ATokenTypeEnum::TOKEN_NATIVE) { LOGI("PermissionManager::tokenTypeFlag is native process"); return true;