diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h old mode 100755 new mode 100644 index e497dd87f3de547cef20a3c785b7fd982256b684..4c816a1add44efb21cd3bc574c0b59b7f7dfb4f5 --- 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,7 +188,7 @@ const std::string ETH_PORT = "ETH_PORT"; // ACE const int32_t ACE_X = 50; const int32_t ACE_Y = 300; -const int32_t ACE_WIDTH = 600; +const int32_t ACE_WIDTH = 500; const int32_t ACE_HEIGHT = 400; const std::string EVENT_CONFIRM = "EVENT_CONFIRM"; const std::string EVENT_CANCEL = "EVENT_CANCEL"; diff --git a/ext/BUILD.gn b/ext/BUILD.gn index df1b58535c2d55fa019bf3c12c6dafefad964edb..a9813f7740aadbe4b9e8d82afab611091ea903b4 100644 --- a/ext/BUILD.gn +++ b/ext/BUILD.gn @@ -19,6 +19,9 @@ group("ext_modules") { deps += [ "./pin_auth:devicemanagerext_pin_auth", "./profile:devicemanagerext_profile", + "./nfc_auth:devicemanager_nfcauth", + "./pin_auth:devicemanagerext_pin_auth", + "./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..fc2207c2f9f7e3d00aa2e2d32073cbfbf2ea34ec --- /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..7ffe782c77dc278e7b2d62a45e82a790a9ae085b --- /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..1022fbde82b756f4fea23b00a370debdf0bcc0ca --- /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..fc2207c2f9f7e3d00aa2e2d32073cbfbf2ea34ec --- /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..35caeca2446a06760541d385d6abc018dfb2f33a --- /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..d4f481b35e18d4657223b9b718446230f5a505c2 --- /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/profile/include/device_profile_adapter.h b/ext/profile/include/device_profile_adapter.h old mode 100755 new mode 100644 diff --git a/ext/profile/include/profile_connector.h b/ext/profile/include/profile_connector.h old mode 100755 new mode 100644 diff --git a/ext/profile/src/device_profile_adapter.cpp b/ext/profile/src/device_profile_adapter.cpp old mode 100755 new mode 100644 diff --git a/ext/profile/src/profile_connector.cpp b/ext/profile/src/profile_connector.cpp old mode 100755 new mode 100644 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..fc2207c2f9f7e3d00aa2e2d32073cbfbf2ea34ec --- /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..83def4a4db760918ca6632af3f093c0fb66917bb --- /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..61904e56de8b30741255433a8772c27ff410300b --- /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..fc2207c2f9f7e3d00aa2e2d32073cbfbf2ea34ec --- /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..aa63d94c877b02ce57d9e7b540f5de4618b72fe9 --- /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..67fdac255e713e9eab9fd613d16904b508e6b8c1 --- /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..2b3ec357a0583cb607482a99318e44908d9d3b30 --- /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 (params != "0") { + 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 (params != "0") { + 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/BUILD.gn b/services/devicemanagerservice/BUILD.gn old mode 100755 new mode 100644 diff --git a/services/devicemanagerservice/include/authentication/auth_message_processor.h b/services/devicemanagerservice/include/authentication/auth_message_processor.h index 5bc633bc9f39fea8c963bd50a81626dd4bd0aad0..bf1665a570c29ec652cb47770d549b6d52a9a6a7 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 799e61e3aeba43f9ef2da02d95719d3cc9b41081..48c3e30396a242251d95cd7e420d49d3297c91d4 100644 --- a/services/devicemanagerservice/include/authentication/dm_auth_manager.h +++ b/services/devicemanagerservice/include/authentication/dm_auth_manager.h @@ -143,6 +143,7 @@ public: void SendAuthRequest(const int32_t &sessionId); int32_t StartAuthProcess(const int32_t &authType); void StartRespAuthProcess(); + void JoinAuthInfo(); int32_t CreateGroup(); int32_t AddMember(const std::string &deviceId); std::string GetConnectAddr(std::string deviceId); diff --git a/services/devicemanagerservice/include/devicestate/dm_device_state_manager.h b/services/devicemanagerservice/include/devicestate/dm_device_state_manager.h old mode 100755 new mode 100644 diff --git a/services/devicemanagerservice/src/authentication/auth_message_processor.cpp b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp index 77c7126ad642f8270a2cfca5aed5db5110448b72..8eb46a2d893bd07439241b5f28f868c1d86388d4 100644 --- a/services/devicemanagerservice/src/authentication/auth_message_processor.cpp +++ b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp @@ -96,6 +96,9 @@ 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; } @@ -153,6 +156,11 @@ void AuthMessageProcessor::CreateResponseFinishMessage(nlohmann::json &json) json[TAG_REPLY] = authResponseContext_->reply; } +void AuthMessageProcessor::CreteJoinAuthInfoMessage(nlohmann::json &json) +{ + json[TAG_REPLY] = authResponseContext_->reply; +} + int32_t AuthMessageProcessor::ParseMessage(const std::string &message) { LOGE(" AuthMessageProcessor ParseMessage"); @@ -185,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); @@ -199,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; } @@ -210,6 +220,11 @@ void AuthMessageProcessor::ParseResponseFinishMessage(nlohmann::json &json) authResponseContext_->reply = json[TAG_REPLY]; } +void AuthMessageProcessor::ParseJoinAuthInfoMessage(nlohmann::json &json) +{ + authResponseContext_->reply = json[TAG_REPLY]; +} + void AuthMessageProcessor::ParseAuthResponseMessage(nlohmann::json &json) { LOGI("AuthMessageProcessor::ParseAuthResponseMessage "); diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index e38be895e75fa3604884dccb5c0a526c828c8d05..6d342405f46c7c0c3957f7ca1a83a11ef3a41aee 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -173,28 +173,44 @@ int32_t DmAuthManager::VerifyAuthentication(const std::string &authParam) LOGI("authResponseContext_ is not init"); return DM_AUTH_NOT_START; } - std::shared_ptr ptr; - if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end() - || timerMap_.find(INPUT_TIMEOUT_TASK) == timerMap_.end()) { + std::shared_ptr ptr; + 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 +292,11 @@ void DmAuthManager::OnDataReceived(int32_t sessionId, std::string message) 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; @@ -528,6 +549,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"); diff --git a/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp b/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp index 2a4dd1384903daa5cc179a1653aeeb9fbe703786..ad0cd3e7cc24011ba1daeb24b298d9f5e8a20413 100644 --- a/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp +++ b/services/devicemanagerservice/src/dependency/timer/dm_timer.cpp @@ -49,10 +49,8 @@ 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(); } @@ -107,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); + 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); + } + } } - } else if (nfds == 0) { - if (mHandleData_ != nullptr) { - mHandle_(mHandleData_, *this); - LOGI("DmTimer %s end timer at (%d)s", mTimerName_.c_str(), mTimeOutSec_); - } - } else { + } + + 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 end timer", mTimerName_.c_str()); } Release(); } @@ -133,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); @@ -149,6 +155,7 @@ int32_t DmTimer::CreateTimeFd() if (ret != 0) { Release(); } + return ret; } @@ -158,7 +165,9 @@ 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()); return; @@ -170,7 +179,6 @@ void DmTimer::Release() if (mEpFd_ >= 0) { close(mEpFd_); } - mTimerName_ = ""; mTimeOutSec_ = 0; mHandle_ = nullptr; mHandleData_ = nullptr; diff --git a/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp b/services/devicemanagerservice/src/devicestate/dm_device_state_manager.cpp old mode 100755 new mode 100644 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;