diff --git a/ext/no_interaction_auth/include/no_interaction_auth.h b/ext/no_interaction_auth/include/no_interaction_auth.h index 83ab2efcfce8c080a0d656343de501a83890f3f6..3675a0650ae45c590bdc0e48ede1622606f76ecf 100644 --- a/ext/no_interaction_auth/include/no_interaction_auth.h +++ b/ext/no_interaction_auth/include/no_interaction_auth.h @@ -32,6 +32,7 @@ public: 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 diff --git a/ext/no_interaction_auth/src/no_interaction_auth.cpp b/ext/no_interaction_auth/src/no_interaction_auth.cpp index 115f2995b1afe3e335d751447e8f596512be29ce..93b78304754e7b67e502221365b7db543aab7ecc 100644 --- a/ext/no_interaction_auth/src/no_interaction_auth.cpp +++ b/ext/no_interaction_auth/src/no_interaction_auth.cpp @@ -47,6 +47,11 @@ int32_t NoInteractionAuth::VerifyAuthentication(std::string &authToken, const st return DM_OK; } +int32_t NoInteractionAuth::CloseAuthInfo(const int32_t &pageId, std::shared_ptr authManager) +{ + return DM_OK; +} + extern "C" IAuthentication *CreatePinAuthObject(void) { return new NoInteractionAuth; diff --git a/ext/pin_auth/BUILD.gn b/ext/pin_auth/BUILD.gn index a8b548826a1a76bb12888146a202b51ec667196c..ddd423cee25473e10901e7a7d3dcb9831569c305 100644 --- a/ext/pin_auth/BUILD.gn +++ b/ext/pin_auth/BUILD.gn @@ -23,12 +23,14 @@ if (defined(ohos_lite)) { ohos_shared_library("devicemanagerext_pin_auth") { include_dirs = [ "include", + "include/standard", "${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/authentication/showconfirm/standard", "${services_path}/include/ability", "${services_path}/include/deviceinfo", "${services_path}/include/devicestate", @@ -61,7 +63,7 @@ if (defined(ohos_lite)) { sources = [ "src/ability/standard/dm_ability_manager.cpp", "src/pin_auth.cpp", - "src/pin_auth_ui.cpp", + "src/standard/pin_auth_ui.cpp", ] deps = [ diff --git a/ext/pin_auth/include/pin_auth_ui.h b/ext/pin_auth/include/lite/pin_auth_ui.h similarity index 90% rename from ext/pin_auth/include/pin_auth_ui.h rename to ext/pin_auth/include/lite/pin_auth_ui.h index a8dfe4d82d3fccd6271033b46323bf121efdec69..7c59415265145e81512e62186f69f0c099a77e0e 100644 --- a/ext/pin_auth/include/pin_auth_ui.h +++ b/ext/pin_auth/include/lite/pin_auth_ui.h @@ -28,10 +28,11 @@ public: PinAuthUi(); int32_t ShowPinDialog(int32_t code, std::shared_ptr authManager); int32_t InputPinDialog(int32_t code, std::shared_ptr authManager); + int32_t ClosePage(const int32_t &pageId, std::shared_ptr authManager); private: int32_t StartFaUiService(std::shared_ptr dmAbilityManager); }; } // namespace DistributedHardware } // namespace OHOS -#endif // OHOS_DM_PIN_AUTH_UI_H +#endif // OHOS_DM_PIN_AUTH_UI_H \ No newline at end of file diff --git a/ext/pin_auth/include/pin_auth.h b/ext/pin_auth/include/pin_auth.h index 4403a2197895129fa734ab134281f17df462df04..643d6acd3645de0588593ad222c0a48563361f4d 100644 --- a/ext/pin_auth/include/pin_auth.h +++ b/ext/pin_auth/include/pin_auth.h @@ -33,6 +33,7 @@ public: 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 pinAuthUi_; diff --git a/ext/pin_auth/include/standard/pin_auth_ui.h b/ext/pin_auth/include/standard/pin_auth_ui.h new file mode 100644 index 0000000000000000000000000000000000000000..7c59415265145e81512e62186f69f0c099a77e0e --- /dev/null +++ b/ext/pin_auth/include/standard/pin_auth_ui.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2022 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_PIN_AUTH_UI_H +#define OHOS_DM_PIN_AUTH_UI_H + +#include + +#include "dm_auth_manager.h" +#include "dm_ability_manager.h" + +namespace OHOS { +namespace DistributedHardware { +class PinAuthUi { +public: + PinAuthUi(); + int32_t ShowPinDialog(int32_t code, std::shared_ptr authManager); + int32_t InputPinDialog(int32_t code, std::shared_ptr authManager); + int32_t ClosePage(const int32_t &pageId, std::shared_ptr authManager); + +private: + int32_t StartFaUiService(std::shared_ptr dmAbilityManager); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_PIN_AUTH_UI_H \ No newline at end of file diff --git a/ext/pin_auth/src/lite/pin_auth_ui.cpp b/ext/pin_auth/src/lite/pin_auth_ui.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b4aff1297ba2ceee51f694e5a37ab2745a9adf05 --- /dev/null +++ b/ext/pin_auth/src/lite/pin_auth_ui.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2022 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 "pin_auth_ui.h" + +#include "dm_ability_manager.h" +#include "dm_constants.h" +#include "dm_log.h" +#include "nlohmann/json.hpp" + +namespace OHOS { +namespace DistributedHardware { +PinAuthUi::PinAuthUi() +{ + LOGI("AuthUi constructor"); +} + +int32_t PinAuthUi::ShowPinDialog(int32_t code, std::shared_ptr authManager) +{ + LOGI("ShowConfigDialog end"); + return DM_OK; +} + +int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr authManager) +{ + LOGI("InputPinDialog start"); + std::shared_ptr dmAbilityManager_ = std::make_shared(); + if (dmAbilityManager_ == nullptr) { + LOGE("PinAuthUi::dmAbilityManager is null"); + return DM_FAILED; + } + LOGI("InputPinDialog end"); + return StartFaUiService(dmAbilityManager_); +} + +int32_t ClosePage(const int32_t &pageId, std::shared_ptr authManager) +{ + LOGI("ClosePage hap start"); + if (authManager == nullptr) { + LOGE("PinAuthUi::authManager is null"); + return DM_FAILED; + } + LOGI("ClosePage hap end"); + authManager->CancelDisplay(); + return DM_OK; +} + +int32_t PinAuthUi::StartFaUiService(std::shared_ptr dmAbilityManager) +{ + AbilityStatus status = dmAbilityManager->StartAbility(AbilityRole::ABILITY_ROLE_INITIATIVE); + if (status != AbilityStatus::ABILITY_STATUS_SUCCESS) { + LOGE("PinAuthUi::StartFaService timeout"); + return DM_FAILED; + } + return DM_OK; +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/ext/pin_auth/src/pin_auth.cpp b/ext/pin_auth/src/pin_auth.cpp index 31bc7673fa033f63ceaefcb820e8664ff2f072a4..da2d8865349b2919c3f42f53e57759bb30e202e1 100644 --- a/ext/pin_auth/src/pin_auth.cpp +++ b/ext/pin_auth/src/pin_auth.cpp @@ -101,6 +101,11 @@ int32_t PinAuth::VerifyAuthentication(std::string &authToken, const std::string } } +int32_t PinAuth::CloseAuthInfo(const int32_t &pageId, std::shared_ptr authManager) +{ + return pinAuthUi_->ClosePage(pageId, authManager); +} + extern "C" IAuthentication *CreatePinAuthObject(void) { return new PinAuth; diff --git a/ext/pin_auth/src/pin_auth_ui.cpp b/ext/pin_auth/src/standard/pin_auth_ui.cpp similarity index 86% rename from ext/pin_auth/src/pin_auth_ui.cpp rename to ext/pin_auth/src/standard/pin_auth_ui.cpp index 1e8d8fb41cb97b9d66dfbfb8672818ace0424946..65851bcb930aea9bdaeac8b714a6876624e5fbbb 100644 --- a/ext/pin_auth/src/pin_auth_ui.cpp +++ b/ext/pin_auth/src/standard/pin_auth_ui.cpp @@ -27,10 +27,14 @@ PinAuthUi::PinAuthUi() { LOGI("AuthUi constructor"); } - + int32_t PinAuthUi::ShowPinDialog(int32_t code, std::shared_ptr authManager) { LOGI("ShowPinDialog start"); + if (authManager == nullptr) { + LOGE("ShowPinDialog authManager is null"); + return DM_FAILED; + } nlohmann::json jsonObj; jsonObj[PIN_CODE_KEY] = code; jsonObj.dump(); @@ -53,10 +57,14 @@ int32_t PinAuthUi::ShowPinDialog(int32_t code, std::shared_ptr au LOGI("ShowConfigDialog end"); return DM_OK; } - + int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr authManager) { LOGI("InputPinDialog start"); + if (authManager == nullptr) { + LOGE("ShowPinDialog InputPinDialog is null"); + return DM_FAILED; + } nlohmann::json jsonObj; jsonObj[PIN_CODE_KEY] = code; jsonObj.dump(); @@ -81,6 +89,14 @@ int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr a return DM_OK; } +int32_t PinAuthUi::ClosePage(const int32_t &pageId, std::shared_ptr authManager) +{ + LOGI("PinAuthUi start"); + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(pageId); + LOGI("PinAuthUi end"); + return DM_OK; +} + int32_t PinAuthUi::StartFaUiService(std::shared_ptr dmAbilityManager) { AbilityStatus status = dmAbilityManager->StartAbility(AbilityRole::ABILITY_ROLE_INITIATIVE); @@ -91,4 +107,4 @@ int32_t PinAuthUi::StartFaUiService(std::shared_ptr dmAbilityM return DM_OK; } } // namespace DistributedHardware -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index 14380584232d960e2afe3bf1963dd452b50cddda..50a5b98e95005e229df9457ebad6729feab53674 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -45,6 +45,7 @@ const int32_t DM_NAPI_ARGS_ONE = 1; const int32_t DM_NAPI_ARGS_TWO = 2; const int32_t DM_NAPI_ARGS_THREE = 3; const int32_t DM_NAPI_SUB_ID_MAX = 65535; +const int32_t DM_AUTH_DIRECTION_CLIENT = 1; napi_ref deviceTypeEnumConstructor_ = nullptr; napi_ref deviceStateChangeActionEnumConstructor_ = nullptr; @@ -587,6 +588,51 @@ void DeviceManagerNapi::DeviceInfoToJsArray(const napi_env &env, const std::vect void DeviceManagerNapi::DmAuthParamToJsAuthParam(const napi_env &env, const DmAuthParam &authParam, napi_value ¶mResult) { + napi_value extraInfo = nullptr; + napi_create_object(env, &extraInfo); + SetValueInt32(env, "direction", authParam.direction, extraInfo); + SetValueInt32(env, "authType", authParam.authType, paramResult); + SetValueInt32(env, "pinToken", stoi(authParam.authToken), extraInfo); + + if (authParam.direction == DM_AUTH_DIRECTION_CLIENT) { + napi_set_named_property(env, paramResult, "extraInfo", extraInfo); + return; + } + + SetValueUtf8String(env, "packageName", authParam.packageName, extraInfo); + SetValueUtf8String(env, "appName", authParam.appName, extraInfo); + SetValueUtf8String(env, "appDescription", authParam.appDescription, extraInfo); + SetValueInt32(env, "business", authParam.business, extraInfo); + SetValueInt32(env, "pinCode", authParam.pincode, extraInfo); + napi_set_named_property(env, paramResult, "extraInfo", extraInfo); + + size_t appIconLen = (size_t)authParam.imageinfo.GetAppIconLen(); + if (appIconLen > 0) { + void *appIcon = nullptr; + napi_value appIconBuffer = nullptr; + napi_create_arraybuffer(env, appIconLen, &appIcon, &appIconBuffer); + if (appIcon != nullptr && + memcpy_s(appIcon, appIconLen, reinterpret_cast(authParam.imageinfo.GetAppIcon()), + appIconLen) == 0) { + napi_value appIconArray = nullptr; + napi_create_typedarray(env, napi_uint8_array, appIconLen, appIconBuffer, 0, &appIconArray); + napi_set_named_property(env, paramResult, "appIcon", appIconArray); + } + } + + size_t appThumbnailLen = (size_t)authParam.imageinfo.GetAppThumbnailLen(); + if (appThumbnailLen > 0) { + void *appThumbnail = nullptr; + napi_value appThumbnailBuffer = nullptr; + napi_create_arraybuffer(env, appThumbnailLen, &appThumbnail, &appThumbnailBuffer); + if (appThumbnail != nullptr && + memcpy_s(appThumbnail, appThumbnailLen, + reinterpret_cast(authParam.imageinfo.GetAppThumbnail()), appThumbnailLen) == 0) { + napi_value appThumbnailArray = nullptr; + napi_create_typedarray(env, napi_uint8_array, appThumbnailLen, appThumbnailBuffer, 0, &appThumbnailArray); + napi_set_named_property(env, paramResult, "appThumbnail", appThumbnailArray); + } + } return; } diff --git a/services/devicemanagerservice/BUILD.gn b/services/devicemanagerservice/BUILD.gn index 5eebc235d9db6efbc21c0f9c8bc213ac061633fa..ee18a47596cc6b122b858eb5f0d8942ce14c746f 100755 --- a/services/devicemanagerservice/BUILD.gn +++ b/services/devicemanagerservice/BUILD.gn @@ -76,7 +76,6 @@ if (defined(ohos_lite)) { "${services_path}/src/authentication/auth_message_processor.cpp", "${services_path}/src/authentication/auth_request_state.cpp", "${services_path}/src/authentication/auth_response_state.cpp", - "${services_path}/src/authentication/auth_ui.cpp", "${services_path}/src/authentication/dm_auth_manager.cpp", "${services_path}/src/config/mini/dm_config_manager.cpp", "${services_path}/src/config/mini/pin_auth.cpp", @@ -134,6 +133,7 @@ if (defined(ohos_lite)) { "include/config", "include/adapter", "include/authentication", + "include/authentication/showconfirm/standard", "include/ability", "include/deviceinfo", "include/devicestate", @@ -164,8 +164,8 @@ if (defined(ohos_lite)) { "src/authentication/auth_message_processor.cpp", "src/authentication/auth_request_state.cpp", "src/authentication/auth_response_state.cpp", - "src/authentication/auth_ui.cpp", "src/authentication/dm_auth_manager.cpp", + "src/authentication/showconfirm/standard/show_confirm.cpp", "src/config/dm_config_manager.cpp", "src/dependency/commonevent/dm_common_event_manager.cpp", "src/dependency/hichain/hichain_connector.cpp", diff --git a/services/devicemanagerservice/include/authentication/authentication.h b/services/devicemanagerservice/include/authentication/authentication.h index f73ca272450e1b6cbd1f9871217af08c5b0d2259..b5f8db04489c53e8706954b64fb009856869598a 100644 --- a/services/devicemanagerservice/include/authentication/authentication.h +++ b/services/devicemanagerservice/include/authentication/authentication.h @@ -27,6 +27,7 @@ public: virtual int32_t ShowAuthInfo(std::string &authToken, std::shared_ptr authManager) = 0; virtual int32_t StartAuth(std::string &authToken, std::shared_ptr authManager) = 0; virtual int32_t VerifyAuthentication(std::string &authToken, const std::string &authParam) = 0; + virtual int32_t CloseAuthInfo(const int32_t &pageId, std::shared_ptr authManager) = 0; }; using CreateIAuthAdapterFuncPtr = IAuthentication *(*)(void); diff --git a/services/devicemanagerservice/include/authentication/dm_auth_manager.h b/services/devicemanagerservice/include/authentication/dm_auth_manager.h index 8a73fe200cb302ba463bc545a1f0cc593ba538d5..087370127fbb89f692e4dbf238b5bb1a2273ef3d 100644 --- a/services/devicemanagerservice/include/authentication/dm_auth_manager.h +++ b/services/devicemanagerservice/include/authentication/dm_auth_manager.h @@ -21,7 +21,6 @@ #include "auth_request_state.h" #include "auth_response_state.h" -#include "auth_ui.h" #include "authentication.h" #include "device_manager_service_listener.h" #include "dm_ability_manager.h" diff --git a/services/devicemanagerservice/include/authentication/auth_ui.h b/services/devicemanagerservice/include/authentication/showconfirm/lite/show_confirm.h similarity index 67% rename from services/devicemanagerservice/include/authentication/auth_ui.h rename to services/devicemanagerservice/include/authentication/showconfirm/lite/show_confirm.h index b8d5b3a645cf141f521725f2ea02086007ce282a..96b3d3d787c2f5905d580d3de98bc25e3d4ec607 100644 --- a/services/devicemanagerservice/include/authentication/auth_ui.h +++ b/services/devicemanagerservice/include/authentication/showconfirm/lite/show_confirm.h @@ -13,26 +13,25 @@ * limitations under the License. */ -#ifndef OHOS_DM_AUTH_UI_H -#define OHOS_DM_AUTH_UI_H +#ifndef OHOS_DM_SHOW_CONFIRM_H +#define OHOS_DM_SHOW_CONFIRM_H -#include +#include +#include #include + +#include "dm_auth_manager.h" #include "dm_ability_manager.h" namespace OHOS { namespace DistributedHardware { -class AuthUi { +class ShowConfirm { public: - AuthUi(); - int32_t ShowConfirmDialog(std::shared_ptr dmAbilityManager); - -private: - int32_t StartFaService(); - -private: - std::shared_ptr dmAbilityMgr_; + ShowConfirm(); + ~ShowConfirm(); + void ShowConfirmDialog(const std::string ¶ms, + std::shared_ptr authManager, std::shared_ptr dmAbilityMgr); }; } // namespace DistributedHardware } // namespace OHOS -#endif // OHOS_DM_AUTH_UI_H \ No newline at end of file +#endif // OHOS_DM_SHOW_CONFIRM_H \ No newline at end of file diff --git a/services/devicemanagerservice/include/authentication/showconfirm/standard/show_confirm.h b/services/devicemanagerservice/include/authentication/showconfirm/standard/show_confirm.h new file mode 100644 index 0000000000000000000000000000000000000000..96b3d3d787c2f5905d580d3de98bc25e3d4ec607 --- /dev/null +++ b/services/devicemanagerservice/include/authentication/showconfirm/standard/show_confirm.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 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_SHOW_CONFIRM_H +#define OHOS_DM_SHOW_CONFIRM_H + +#include +#include +#include + +#include "dm_auth_manager.h" +#include "dm_ability_manager.h" + +namespace OHOS { +namespace DistributedHardware { +class ShowConfirm { +public: + ShowConfirm(); + ~ShowConfirm(); + void ShowConfirmDialog(const std::string ¶ms, + std::shared_ptr authManager, std::shared_ptr dmAbilityMgr); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_SHOW_CONFIRM_H \ No newline at end of file diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index 0b26255bb37ccd55aeeb17ba55531ae3809f4491..0ef2165d35d01ace06d3a4f8943218f43dd4ad41 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -18,7 +18,6 @@ #include #include "auth_message_processor.h" -#include "auth_ui.h" #include "dm_ability_manager.h" #include "dm_config_manager.h" #include "dm_constants.h" @@ -28,9 +27,8 @@ #include "nlohmann/json.hpp" #include "parameter.h" #ifdef SUPPORT_GRAPHICS -#include "ui_service_mgr_client.h" -#include "dialog_callback_stub.h" -#include "dialog_callback.h" +#include "show_confirm.h" + #endif namespace OHOS { @@ -566,7 +564,13 @@ int32_t DmAuthManager::AddMember(const std::string &deviceId) } LOGI("DmAuthManager::authRequestContext CancelDisplay start"); #ifdef SUPPORT_GRAPHICS - Ace::UIServiceMgrClient::GetInstance()->CancelDialog(authResponseContext_->pageId); + std::shared_ptr ptr; + if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { + LOGE("DmAuthManager::authenticationMap_ is null"); + return DM_FAILED; + } + ptr = authenticationMap_[authResponseContext_->authType]; + ptr->CloseAuthInfo(authResponseContext_->pageId, shared_from_this()); #endif return DM_OK; } @@ -598,7 +602,13 @@ void DmAuthManager::AuthenticateFinish() if (authResponseState_ != nullptr) { #ifdef SUPPORT_GRAPHICS if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_FINISH) { - Ace::UIServiceMgrClient::GetInstance()->CancelDialog(authResponseContext_->pageId); + std::shared_ptr ptr; + if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { + LOGE("DmAuthManager::authenticationMap_ is null"); + return ; + } + ptr = authenticationMap_[authResponseContext_->authType]; + ptr->CloseAuthInfo(authResponseContext_->pageId, shared_from_this()); } #endif if (isFinishOfLocal_) { @@ -626,7 +636,13 @@ void DmAuthManager::AuthenticateFinish() } #ifdef SUPPORT_GRAPHICS if (authResponseContext_->state == AuthState::AUTH_REQUEST_INPUT) { - Ace::UIServiceMgrClient::GetInstance()->CancelDialog(authResponseContext_->pageId); + std::shared_ptr ptr; + if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { + LOGE("DmAuthManager::authenticationMap_ is null"); + return ; + } + ptr = authenticationMap_[authResponseContext_->authType]; + ptr->CloseAuthInfo(authResponseContext_->pageId, shared_from_this()); } #endif listener_->OnAuthResult(authRequestContext_->hostPkgName, authRequestContext_->deviceId, @@ -720,29 +736,15 @@ void DmAuthManager::ShowConfigDialog() { #ifdef SUPPORT_GRAPHICS LOGI("ShowConfigDialog start"); + dmAbilityMgr_ = std::make_shared(); nlohmann::json jsonObj; jsonObj[TAG_AUTH_TYPE] = AUTH_TYPE_PIN; jsonObj[TAG_TOKEN] = authResponseContext_->token; jsonObj[TARGET_PKG_NAME_KEY] = authResponseContext_->targetPkgName; jsonObj.dump(); const std::string params = jsonObj.dump(); - std::shared_ptr authMgr_ = shared_from_this(); - - Ace::UIServiceMgrClient::GetInstance()->ShowDialog( - "config_dialog_service", - params, - OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, - ACE_X, ACE_Y, ACE_WIDTH, ACE_HEIGHT, - [authMgr_](int32_t id, const std::string& event, const std::string& params) { - if (params == EVENT_INIT_CODE) { - LOGI("Dialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); - authMgr_->SetPageId(id); - } else { - Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); - LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); - authMgr_->StartAuthProcess(atoi(params.c_str())); - } - }); + std::shared_ptr showConfirm_ = std::make_shared(); + showConfirm_->ShowConfirmDialog(params, shared_from_this(), dmAbilityMgr_); LOGI("ShowConfigDialog end"); #endif } diff --git a/services/devicemanagerservice/src/authentication/auth_ui.cpp b/services/devicemanagerservice/src/authentication/showconfirm/lite/show_confirm.cpp similarity index 56% rename from services/devicemanagerservice/src/authentication/auth_ui.cpp rename to services/devicemanagerservice/src/authentication/showconfirm/lite/show_confirm.cpp index a42e1b38fdb9d0e051e50c68e9b0dbea2e3c5b22..0815f2ad0684659eee0254402fae18b883cbb0e8 100644 --- a/services/devicemanagerservice/src/authentication/auth_ui.cpp +++ b/services/devicemanagerservice/src/authentication/showconfirm/lite/show_confirm.cpp @@ -13,37 +13,37 @@ * limitations under the License. */ -#include "auth_ui.h" +#include "show_confirm.h" +#include "dm_auth_manager.h" #include "dm_ability_manager.h" #include "dm_constants.h" #include "dm_log.h" namespace OHOS { namespace DistributedHardware { -AuthUi::AuthUi() +ShowConfirm::ShowConfirm() { - LOGI("AuthUi constructor"); } -int32_t AuthUi::ShowConfirmDialog(std::shared_ptr dmAbilityManager) +ShowConfirm::~ShowConfirm() { - if (dmAbilityManager == nullptr) { - LOGE("AuthUi::dmAbilityManager is null"); - return DM_FAILED; - } - dmAbilityMgr_ = dmAbilityManager; - return StartFaService(); } -int32_t AuthUi::StartFaService() +void ShowConfirm::ShowConfirmDialog(const std::string ¶ms, std::shared_ptr authManager, + std::shared_ptr dmAbilityMgr) { - AbilityStatus status = dmAbilityMgr_->StartAbility(AbilityRole::ABILITY_ROLE_PASSIVE); + LOGI("ShowConfirm hap start"); + if (dmAbilityMgr == nullptr) { + LOGE("ShowConfirm::dmAbilityManager is null"); + return; + } + AbilityStatus status = dmAbilityMgr->StartAbility(AbilityRole::ABILITY_ROLE_PASSIVE); if (status != AbilityStatus::ABILITY_STATUS_SUCCESS) { - LOGE("AuthUi::StartFaService timeout"); - return DM_FAILED; + LOGE("ShowConfirm::startFaservice timeout"); + return; } - return DM_OK; -} + LOGI("ShowConfirm hap end"); +}; } // namespace DistributedHardware -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/services/devicemanagerservice/src/authentication/showconfirm/standard/show_confirm.cpp b/services/devicemanagerservice/src/authentication/showconfirm/standard/show_confirm.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d9b98924a5bfdff7113c426d34ce5680ca9be880 --- /dev/null +++ b/services/devicemanagerservice/src/authentication/showconfirm/standard/show_confirm.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2022 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 "show_confirm.h" + +#include "dm_auth_manager.h" +#include "dm_constants.h" +#include "dm_log.h" +#ifdef SUPPORT_GRAPHICS +#include "ui_service_mgr_client.h" +#endif + +namespace OHOS { +namespace DistributedHardware { +ShowConfirm::ShowConfirm() +{ + LOGI("ShowConfirm ace constructor"); +} + +ShowConfirm::~ShowConfirm() +{ +} + +void ShowConfirm::ShowConfirmDialog(const std::string ¶ms, std::shared_ptr authManager, + std::shared_ptr dmAbilityMgr) +{ +#ifdef SUPPORT_GRAPHICS + LOGI("ShowConfirm ace start"); + if (authManager == nullptr) { + LOGE("ShowConfirm::dmAbilityManager is null"); + return; + } + Ace::UIServiceMgrClient::GetInstance()->ShowDialog( + "config_dialog_service", + params, + OHOS::Rosen::WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW, + ACE_X, ACE_Y, ACE_WIDTH, ACE_HEIGHT, + [authManager](int32_t id, const std::string& event, const std::string& params) { + if (params == EVENT_INIT_CODE) { + LOGI("Dialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); + authManager->SetPageId(id); + } else { + Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); + LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); + authManager->StartAuthProcess(atoi(params.c_str())); + } + }); + LOGI("ShowConfirm ace end"); +#endif +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file