From 5c78324e8585884ad38fb8d5c618e8a45edc8eeb Mon Sep 17 00:00:00 2001 From: renguang1116 Date: Thu, 26 May 2022 23:30:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B7=A8=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E8=AE=A4=E8=AF=81=E4=B8=ADpin=E7=A0=81=E6=98=8E?= =?UTF-8?q?=E6=96=87=E4=BC=A0=E8=BE=93=E5=AF=BC=E8=87=B4=E7=9A=84=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E9=97=AE=E9=A2=98=20Signed-off-by:=20renguang1116=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/include/dm_constants.h | 8 +- .../include/no_interaction_auth.h | 1 + .../src/no_interaction_auth.cpp | 5 + ext/pin_auth/include/lite/pin_auth_ui.h | 9 +- ext/pin_auth/include/pin_auth.h | 8 ++ ext/pin_auth/include/standard/pin_auth_ui.h | 4 +- .../dialog_ui/js/pages/index/index.hml | 2 +- .../dialog_ui/js/pages/index/index.js | 46 +++---- ext/pin_auth/src/lite/pin_auth_ui.cpp | 7 +- ext/pin_auth/src/pin_auth.cpp | 16 +-- ext/pin_auth/src/standard/pin_auth_ui.cpp | 38 ++++-- .../kits/js/src/native_devicemanager_js.cpp | 2 +- .../js_mini/include/native_devicemanager_js.h | 2 +- .../authentication/auth_request_state.h | 17 --- .../include/authentication/authentication.h | 1 + .../include/authentication/dm_auth_manager.h | 9 +- .../include/discovery/dm_discovery_manager.h | 1 + .../src/authentication/auth_request_state.cpp | 19 +-- .../src/authentication/dm_auth_manager.cpp | 125 +++++++----------- .../src/discovery/dm_discovery_manager.cpp | 15 ++- test/unittest/UTTest_auth_request_state.cpp | 53 +------- test/unittest/UTTest_auth_response_state.cpp | 4 + test/unittest/UTTest_dm_auth_manager.cpp | 4 +- test/unittest/UTTest_pin_auth_ui.cpp | 6 +- test/unittest/auth_request_state.cpp | 17 --- 25 files changed, 171 insertions(+), 248 deletions(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 4ff3d02b3..58c26ce39 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -74,6 +74,8 @@ enum { ERR_DM_AUTH_NOT_START = -20026, ERR_DM_AUTH_MESSAGE_INCOMPLETE = -20027, ERR_DM_CREATE_GROUP_FAILED = -20028, + ERR_DM_IPC_READ_TOKEN_FAILED = -20029, + ERR_DM_AUTH_INPUT_PARAMETER_FAILED = -20030, }; const std::string TARGET_PKG_NAME_KEY = "targetPkgName"; @@ -135,11 +137,13 @@ 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 VERIFY_FAILED = "verifyFailed"; const int32_t AUTH_TYPE_PIN = 1; const int32_t AUTH_TYPE_SCAN = 2; const int32_t AUTH_TYPE_TOUCH = 3; const int32_t DEFAULT_PIN_CODE = 0; const int32_t DEFAULT_PIN_TOKEN = 0; +const int32_t DEFAULT_PIN_CODE_LENGTH = 6; // Softbus const int32_t SOFTBUS_CHECK_INTERVAL = 100000; // 100ms @@ -171,8 +175,8 @@ const std::string ETH_PORT = "ETH_PORT"; // ACE const int32_t ACE_X = 50; const int32_t ACE_Y = 300; -const int32_t ACE_WIDTH = 450; -const int32_t ACE_HEIGHT = 400; +const int32_t ACE_WIDTH = 580; +const int32_t ACE_HEIGHT = 520; const std::string EVENT_CONFIRM = "EVENT_CONFIRM"; const std::string EVENT_CANCEL = "EVENT_CANCEL"; const std::string EVENT_INIT = "EVENT_INIT"; diff --git a/ext/no_interaction_auth/include/no_interaction_auth.h b/ext/no_interaction_auth/include/no_interaction_auth.h index 3675a0650..30d91dab8 100644 --- a/ext/no_interaction_auth/include/no_interaction_auth.h +++ b/ext/no_interaction_auth/include/no_interaction_auth.h @@ -33,6 +33,7 @@ public: 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; + int32_t UpdateAuthInfo(const int32_t &pageId) 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 93b783047..2dff14318 100644 --- a/ext/no_interaction_auth/src/no_interaction_auth.cpp +++ b/ext/no_interaction_auth/src/no_interaction_auth.cpp @@ -52,6 +52,11 @@ int32_t NoInteractionAuth::CloseAuthInfo(const int32_t &pageId, std::shared_ptr< return DM_OK; } +int32_t NoInteractionAuth::UpdateAuthInfo(const int32_t &pageId) +{ + return DM_OK; +} + extern "C" IAuthentication *CreatePinAuthObject(void) { return new NoInteractionAuth; diff --git a/ext/pin_auth/include/lite/pin_auth_ui.h b/ext/pin_auth/include/lite/pin_auth_ui.h index aad43c505..3337829c4 100644 --- a/ext/pin_auth/include/lite/pin_auth_ui.h +++ b/ext/pin_auth/include/lite/pin_auth_ui.h @@ -42,7 +42,7 @@ public: * @tc.desc: Show Input PinDialog * @tc.type: FUNC */ - int32_t InputPinDialog(int32_t code, std::shared_ptr authManager); + int32_t InputPinDialog(std::shared_ptr authManager); /** * @tc.name: PinAuthUi::ClosePage * @tc.desc: Close Page @@ -50,6 +50,13 @@ public: */ int32_t ClosePage(const int32_t &pageId, std::shared_ptr authManager); + /** + * @tc.name: PinAuth::UpdateAuthInfo + * @tc.desc: Update the page information + * @tc.type: FUNC + */ + int32_t UpdatePinDialog(int32_t pageId); + private: int32_t StartFaUiService(std::shared_ptr dmAbilityManager); }; diff --git a/ext/pin_auth/include/pin_auth.h b/ext/pin_auth/include/pin_auth.h index 13afc8cd2..4e2b0b4ac 100644 --- a/ext/pin_auth/include/pin_auth.h +++ b/ext/pin_auth/include/pin_auth.h @@ -58,6 +58,14 @@ public: * @tc.type: FUNC */ int32_t CloseAuthInfo(const int32_t &pageId, std::shared_ptr authManager) override; + + /** + * @tc.name: PinAuth::UpdateAuthInfo + * @tc.desc: Update Auth Info of the PinAuth + * @tc.type: FUNC + */ + int32_t UpdateAuthInfo(const int32_t &pageId) 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 index 7c5941526..bb9e2742c 100644 --- a/ext/pin_auth/include/standard/pin_auth_ui.h +++ b/ext/pin_auth/include/standard/pin_auth_ui.h @@ -27,9 +27,9 @@ 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 InputPinDialog(std::shared_ptr authManager); int32_t ClosePage(const int32_t &pageId, std::shared_ptr authManager); - + int32_t UpdatePinDialog(int32_t pageId); private: int32_t StartFaUiService(std::shared_ptr dmAbilityManager); }; diff --git a/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.hml b/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.hml index 0d0451017..a82024d3b 100644 --- a/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.hml +++ b/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.hml @@ -22,7 +22,7 @@ 请输入另一个设备显示的PIN码进行验证 - + PIN码输入错误,请重新输入(3次:还有{{isTimes}}次机会) diff --git a/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.js b/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.js index 48a242f2d..c897f8794 100644 --- a/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.js +++ b/ext/pin_auth/input_pin_dialog/dialog_ui/js/pages/index/index.js @@ -15,51 +15,37 @@ import router from '@ohos.router'; -var numbs = 0; -var code = 0; -var inputVal = 0; +var inputValue; var EVENT_CONFIRM = "EVENT_CONFIRM"; var EVENT_CANCEL = "EVENT_CANCEL"; var EVENT_INIT = "EVENT_INIT"; -var EVENT_CONFIRM_CODE = "0"; var EVENT_CANCEL_CODE = "1"; var EVENT_INIT_CODE = "2"; + export default { data: { - pincode: router.getParams().pinCode, - isShow:false, - isTimes:3, + inputValue: "", + isShow: false, + isTimes: 3, }, onInit() { - code = router.getParams().pinCode; callNativeHandler(EVENT_INIT, EVENT_INIT_CODE); }, - onChange(e){ - inputVal = e.value; - }, + onChange(e){ + inputValue = e.value; + }, onConfirm() { - numbs = numbs + 1; - if(numbs <= 3){ - console.info('click confirm numbs < 3 '); - if(code == inputVal){ - console.info('click confirm code == inputVal'); - callNativeHandler(EVENT_CONFIRM, EVENT_CONFIRM_CODE); - }else{ - if(numbs == 3){ - console.info('click confirm code != inputVal and numbs == 3'); - callNativeHandler(EVENT_CANCEL, EVENT_CANCEL_CODE); - } - console.info('click confirm code != inputVal'); - this.isShow = true; - this.isTimes = 3 - numbs; - } - }else{ - console.info('click confirm numbs > 3 '); - callNativeHandler(EVENT_CANCEL, EVENT_CANCEL_CODE); - } + if ((inputValue == null) || (inputValue == "")) { + return; + } + this.isTimes--; + callNativeHandler(EVENT_CONFIRM, inputValue); }, onCancel() { console.info('click cancel'); callNativeHandler(EVENT_CANCEL, EVENT_CANCEL_CODE); + }, + onDialogUpdatedd(param) { + this.isShow = param.verifyFailed; } } \ 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 index 205d32762..70a594063 100644 --- a/ext/pin_auth/src/lite/pin_auth_ui.cpp +++ b/ext/pin_auth/src/lite/pin_auth_ui.cpp @@ -33,7 +33,7 @@ int32_t PinAuthUi::ShowPinDialog(int32_t code, std::shared_ptr au return DM_OK; } -int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr authManager) +int32_t PinAuthUi::InputPinDialog(std::shared_ptr authManager) { LOGI("InputPinDialog start"); std::shared_ptr dmAbilityManager_ = std::make_shared(); @@ -66,5 +66,10 @@ int32_t PinAuthUi::StartFaUiService(std::shared_ptr dmAbilityM } return DM_OK; } + +int32_t PinAuthUi::UpdatePinDialog(int32_t pageId) +{ + return DM_OK; +} } // namespace DistributedHardware } // namespace OHOS diff --git a/ext/pin_auth/src/pin_auth.cpp b/ext/pin_auth/src/pin_auth.cpp index a746406f9..5ae4f09a8 100644 --- a/ext/pin_auth/src/pin_auth.cpp +++ b/ext/pin_auth/src/pin_auth.cpp @@ -51,16 +51,7 @@ int32_t PinAuth::ShowAuthInfo(std::string &authToken, std::shared_ptr authManager) { - nlohmann::json jsonObject = nlohmann::json::parse(authToken, nullptr, false); - if (jsonObject.is_discarded()) { - LOGE("DecodeRequestAuth jsonStr error"); - return ERR_DM_FAILED; - } - if (!jsonObject.contains(PIN_CODE_KEY)) { - LOGE("err json string, first time"); - return ERR_DM_FAILED; - } - return pinAuthUi_->InputPinDialog(jsonObject[PIN_CODE_KEY], authManager); + return pinAuthUi_->InputPinDialog(authManager); } int32_t PinAuth::VerifyAuthentication(std::string &authToken, const std::string &authParam) @@ -106,6 +97,11 @@ int32_t PinAuth::CloseAuthInfo(const int32_t &pageId, std::shared_ptrClosePage(pageId, authManager); } +int32_t PinAuth::UpdateAuthInfo(const int32_t &pageId) +{ + return pinAuthUi_->UpdatePinDialog(pageId); +} + extern "C" IAuthentication *CreatePinAuthObject(void) { return new PinAuth; diff --git a/ext/pin_auth/src/standard/pin_auth_ui.cpp b/ext/pin_auth/src/standard/pin_auth_ui.cpp index 6e349747a..d702ca37a 100644 --- a/ext/pin_auth/src/standard/pin_auth_ui.cpp +++ b/ext/pin_auth/src/standard/pin_auth_ui.cpp @@ -58,7 +58,7 @@ int32_t PinAuthUi::ShowPinDialog(int32_t code, std::shared_ptr au return DM_OK; } -int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr authManager) +int32_t PinAuthUi::InputPinDialog(std::shared_ptr authManager) { LOGI("InputPinDialog start"); if (authManager == nullptr) { @@ -66,7 +66,7 @@ int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr a return ERR_DM_FAILED; } nlohmann::json jsonObj; - jsonObj[PIN_CODE_KEY] = code; + jsonObj[VERIFY_FAILED] = false; jsonObj.dump(); const std::string params = jsonObj.dump(); @@ -76,13 +76,21 @@ int32_t PinAuthUi::InputPinDialog(int32_t code, std::shared_ptr a 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) { - authManager->SetPageId(id); - } - if (params == EVENT_CANCEL_CODE || params == EVENT_CONFIRM_CODE) { - Ace::UIServiceMgrClient::GetInstance()->CancelDialog(id); - LOGI("CancelDialog start id:%d,event:%s,parms:%s", id, event.c_str(), params.c_str()); - authManager->VerifyAuthentication(params.c_str()); + switch (event) { + case EVENT_INIT: + authManager->SetPageId(id); + break; + case EVENT_CONFIRM: + LOGI("On confirm event for page id:%d, parms:%s", id, params.c_str()); + if (params.length() == DEFAULT_PIN_CODE_LENGTH) { + authManager->AddMember(std::stoi(params)); + } else { + UpdatePinDialog(id); + } + break; + default: + authManager->SetReasonAndFinish(ERR_DM_AUTH_INPUT_PARAMETER_FAILED, AuthState::AUTH_REQUEST_JOIN); + break; } }); LOGI("ShowConfigDialog end"); @@ -97,6 +105,18 @@ int32_t PinAuthUi::ClosePage(const int32_t &pageId, std::shared_ptrUpdateDialog(pageId, params); + LOGI("UpdatePinDialog end"); + return DM_OK; +} + int32_t PinAuthUi::StartFaUiService(std::shared_ptr dmAbilityManager) { AbilityStatus status = dmAbilityManager->StartAbility(AbilityRole::ABILITY_ROLE_INITIATIVE); diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index ef8dc9c4e..271f0bb3f 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -46,7 +46,7 @@ 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; -const int32_t DM_AUTH_REQUEST_SUCCESS_STATUS = 8; +const int32_t DM_AUTH_REQUEST_SUCCESS_STATUS = 7; napi_ref deviceTypeEnumConstructor_ = nullptr; napi_ref deviceStateChangeActionEnumConstructor_ = nullptr; diff --git a/interfaces/kits/js_mini/include/native_devicemanager_js.h b/interfaces/kits/js_mini/include/native_devicemanager_js.h index c161d6941..a786bc7d3 100644 --- a/interfaces/kits/js_mini/include/native_devicemanager_js.h +++ b/interfaces/kits/js_mini/include/native_devicemanager_js.h @@ -32,7 +32,7 @@ namespace OHOS { namespace ACELite { #define DM_JSI_BUF_LENGTH (256) -#define DM_JSI_AUTH_REQUEST_FINISH (8) +#define DM_JSI_AUTH_REQUEST_FINISH (7) struct AuthFuncParams { JSIValue handlerRef = JSI::CreateUndefined(); diff --git a/services/devicemanagerservice/include/authentication/auth_request_state.h b/services/devicemanagerservice/include/authentication/auth_request_state.h index 35d5cfde1..647ce7db1 100644 --- a/services/devicemanagerservice/include/authentication/auth_request_state.h +++ b/services/devicemanagerservice/include/authentication/auth_request_state.h @@ -131,23 +131,6 @@ public: int32_t Enter() override; }; -class AuthRequestInputState : public AuthRequestState { -public: - /** - * @tc.name: AuthRequestInputState::GetStateType - * @tc.desc: Get State Type of the AuthRequest Input State - * @tc.type: FUNC - */ - int32_t GetStateType() override; - - /** - * @tc.name: AuthRequestInputState::Enter - * @tc.desc: Enter of the AuthRequest Input State - * @tc.type: FUNC - */ - int32_t Enter() override; -}; - class AuthRequestJoinState : public AuthRequestState { public: /** diff --git a/services/devicemanagerservice/include/authentication/authentication.h b/services/devicemanagerservice/include/authentication/authentication.h index b5f8db044..301768379 100644 --- a/services/devicemanagerservice/include/authentication/authentication.h +++ b/services/devicemanagerservice/include/authentication/authentication.h @@ -28,6 +28,7 @@ public: 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; + virtual int32_t UpdateAuthInfo(const int32_t &pageId) = 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 c5f69a69c..83726a5f8 100644 --- a/services/devicemanagerservice/include/authentication/dm_auth_manager.h +++ b/services/devicemanagerservice/include/authentication/dm_auth_manager.h @@ -39,7 +39,6 @@ typedef enum AuthState { AUTH_REQUEST_NEGOTIATE, AUTH_REQUEST_NEGOTIATE_DONE, AUTH_REQUEST_REPLY, - AUTH_REQUEST_INPUT, AUTH_REQUEST_JOIN, AUTH_REQUEST_NETWORK, AUTH_REQUEST_FINISH, @@ -238,7 +237,7 @@ public: * @tc.desc: Add Member of the DeviceManager Authenticate Manager * @tc.type: FUNC */ - int32_t AddMember(const std::string &deviceId); + int32_t AddMember(int32_t pinCode); /** * @tc.name: DmAuthManager::GetConnectAddr @@ -367,11 +366,11 @@ public: int32_t SetPageId(int32_t pageId); /** - * @tc.name: DmAuthManager::SetReason + * @tc.name: DmAuthManager::SetReasonAndFinish * @tc.desc: Set Reason of the DeviceManager Authenticate Manager * @tc.type: FUNC */ - int32_t SetReason(int32_t reason, int32_t state); + int32_t SetReasonAndFinish(int32_t reason, int32_t state); private: std::shared_ptr softbusConnector_; @@ -388,6 +387,8 @@ private: std::shared_ptr dmAbilityMgr_; bool isCryptoSupport_ = false; bool isFinishOfLocal_ = true; + int32_t authTimes_ = 0; + std::shared_ptr authPtr_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/include/discovery/dm_discovery_manager.h b/services/devicemanagerservice/include/discovery/dm_discovery_manager.h index 135be035c..7234c97a1 100644 --- a/services/devicemanagerservice/include/discovery/dm_discovery_manager.h +++ b/services/devicemanagerservice/include/discovery/dm_discovery_manager.h @@ -85,6 +85,7 @@ private: std::queue discoveryQueue_; std::map discoveryContextMap_; std::shared_ptr timer_; + std::mutex locks_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/devicemanagerservice/src/authentication/auth_request_state.cpp b/services/devicemanagerservice/src/authentication/auth_request_state.cpp index 716367185..94ea2544a 100644 --- a/services/devicemanagerservice/src/authentication/auth_request_state.cpp +++ b/services/devicemanagerservice/src/authentication/auth_request_state.cpp @@ -122,23 +122,6 @@ int32_t AuthRequestReplyState::Enter() return DM_OK; } -int32_t AuthRequestInputState::GetStateType() -{ - return AuthState::AUTH_REQUEST_INPUT; -} - -int32_t AuthRequestInputState::Enter() -{ - LOGI("DmAuthManager::AuthRequestInputState"); - std::shared_ptr stateAuthManager = authManager_.lock(); - if (stateAuthManager == nullptr) { - LOGE("AuthRequestState::authManager_ null"); - return ERR_DM_FAILED; - } - stateAuthManager->ShowStartAuthDialog(); - return DM_OK; -} - int32_t AuthRequestJoinState::GetStateType() { return AuthState::AUTH_REQUEST_JOIN; @@ -152,7 +135,7 @@ int32_t AuthRequestJoinState::Enter() LOGE("AuthRequestState::authManager_ null"); return ERR_DM_FAILED; } - stateAuthManager->AddMember(context_->deviceId); + stateAuthManager->ShowStartAuthDialog(); return DM_OK; } diff --git a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp index ff50edcfa..450829e4e 100644 --- a/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp +++ b/services/devicemanagerservice/src/authentication/dm_auth_manager.cpp @@ -40,6 +40,7 @@ const int32_t WAIT_NEGOTIATE_TIMEOUT = 10; const int32_t WAIT_REQUEST_TIMEOUT = 10; const int32_t CANCEL_PIN_CODE_DISPLAY = 1; const int32_t DEVICE_ID_HALF = 2; +const int32_t MAX_AUTH_TIMES = 3; DmAuthManager::DmAuthManager(std::shared_ptr softbusConnector, std::shared_ptr listener, @@ -84,6 +85,7 @@ int32_t DmAuthManager::AuthenticateDevice(const std::string &pkgName, int32_t au return ERR_DM_INPUT_PARAMETER_EMPTY; } + authPtr_ = authenticationMap_[authType]; if (timer_ == nullptr) { timer_ = std::make_shared(); } @@ -160,14 +162,8 @@ int32_t DmAuthManager::VerifyAuthentication(const std::string &authParam) LOGE("authResponseContext_ is not init"); return ERR_DM_AUTH_NOT_START; } - std::shared_ptr ptr; - if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { - LOGE("DmAuthManager::authenticationMap_ is null"); - return ERR_DM_FAILED; - } timer_->DeleteTimer(INPUT_TIMEOUT_TASK); - ptr = authenticationMap_[authResponseContext_->authType]; - int32_t ret = ptr->VerifyAuthentication(authResponseContext_->authToken, authParam); + int32_t ret = authPtr_->VerifyAuthentication(authResponseContext_->authToken, authParam); switch (ret) { case DM_OK: authRequestState_->TransitionTo(std::make_shared()); @@ -314,7 +310,7 @@ void DmAuthManager::OnDataReceived(const int32_t sessionId, const std::string me void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId) { - LOGI("DmAuthManager::OnGroupCreated start"); + LOGI("DmAuthManager::OnGroupCreated start group id %s", groupId.c_str()); if (authResponseState_ == nullptr) { LOGE("DmAuthManager::AuthenticateDevice end"); return; @@ -329,11 +325,11 @@ void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId int32_t pinCode = GeneratePincode(); nlohmann::json jsonObj; - jsonObj[PIN_CODE_KEY] = pinCode; jsonObj[PIN_TOKEN] = authResponseContext_->token; jsonObj[QR_CODE_KEY] = GenerateGroupName(); jsonObj[NFC_CODE_KEY] = GenerateGroupName(); authResponseContext_->authToken = jsonObj.dump(); + LOGI("DmAuthManager::OnGroupCreated start group id %s", groupId.c_str()); authResponseContext_->groupId = groupId; authResponseContext_->code = pinCode; authMessageProcessor_->SetResponseContext(authResponseContext_); @@ -344,24 +340,31 @@ void DmAuthManager::OnGroupCreated(int64_t requestId, const std::string &groupId void DmAuthManager::OnMemberJoin(int64_t requestId, int32_t status) { - LOGI("DmAuthManager OnMemberJoin start"); + LOGI("DmAuthManager OnMemberJoin start authTimes %d", authTimes_); if (authRequestState_ != nullptr) { + authTimes_++; timer_->DeleteTimer(ADD_TIMEOUT_TASK); if (status != DM_OK || authResponseContext_->requestId != requestId) { - if (authRequestState_ != nullptr) { + if (authRequestState_ != nullptr && authTimes_ >= MAX_AUTH_TIMES) { authResponseContext_->state = AuthState::AUTH_REQUEST_JOIN; authRequestContext_->reason = ERR_DM_INPUT_PARAMETER_EMPTY; authRequestState_->TransitionTo(std::make_shared()); - return; + } else { + timer_->StartTimer(INPUT_TIMEOUT_TASK, INPUT_TIMEOUT, + [this] (std::string name) { + DmAuthManager::HandleAuthenticateTimeout(name); + }); + authPtr_->UpdateAuthInfo(authResponseContext_->pageId); } + } else { + authRequestState_->TransitionTo(std::make_shared()); } - authRequestState_->TransitionTo(std::make_shared()); } } void DmAuthManager::HandleAuthenticateTimeout(std::string name) { - LOGI("DmAuthManager::HandleAuthenticateTimeout start"); + LOGI("DmAuthManager::HandleAuthenticateTimeout start timer name %s", name.c_str()); if (authRequestState_ != nullptr && authRequestState_->GetStateType() != AuthState::AUTH_REQUEST_FINISH) { if (authResponseContext_ == nullptr) { authResponseContext_ = std::make_shared(); @@ -427,6 +430,8 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) if (authentication == nullptr) { LOGE("DmAuthManager::AuthenticateDevice authType %d not support.", authResponseContext_->authType); authResponseContext_->reply = ERR_DM_UNSUPPORTED_AUTH_TYPE; + } else { + authPtr_ = authenticationMap_[authResponseContext_->authType]; } std::string message = authMessageProcessor_->CreateSimpleMessage(MSG_TYPE_RESP_NEGOTIATE); @@ -435,7 +440,7 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); } authResponseContext_ = authResponseState_->GetAuthContext(); - if (jsonObject[TAG_CRYPTO_SUPPORT] == "true" && authResponseContext_->cryptoSupport) { + if (jsonObject[TAG_CRYPTO_SUPPORT] == true && authResponseContext_->cryptoSupport) { if (jsonObject[TAG_CRYPTO_NAME] == authResponseContext_->cryptoName && jsonObject[TAG_CRYPTO_VERSION] == authResponseContext_->cryptoVer) { isCryptoSupport_ = true; @@ -443,7 +448,7 @@ void DmAuthManager::RespNegotiate(const int32_t &sessionId) return; } } - jsonObject[TAG_CRYPTO_SUPPORT] = "false"; + jsonObject[TAG_CRYPTO_SUPPORT] = false; message = jsonObject.dump(); softbusConnector_->GetSoftbusSession()->SendData(sessionId, message); timer_->StartTimer(WAIT_REQUEST_TIMEOUT_TASK, WAIT_REQUEST_TIMEOUT, @@ -502,7 +507,7 @@ void DmAuthManager::StartRespAuthProcess() [this] (std::string name) { DmAuthManager::HandleAuthenticateTimeout(name); }); - authRequestState_->TransitionTo(std::make_shared()); + authRequestState_->TransitionTo(std::make_shared()); } else { LOGE("do not accept"); authResponseContext_->state = AuthState::AUTH_REQUEST_REPLY; @@ -520,19 +525,14 @@ int32_t DmAuthManager::CreateGroup() return DM_OK; } -int32_t DmAuthManager::AddMember(const std::string &deviceId) +int32_t DmAuthManager::AddMember(int32_t pinCode) { - LOGI("DmAuthManager::AddMember start"); - nlohmann::json jsonObj = nlohmann::json::parse(authResponseContext_->authToken, nullptr, false); - if (jsonObj.is_discarded()) { - LOGE("DecodeRequestAuth jsonStr error"); - return ERR_DM_FAILED; - } - + LOGI("DmAuthManager::AddMember start group id %s", authResponseContext_->groupId.c_str()); + timer_->DeleteTimer(INPUT_TIMEOUT_TASK); nlohmann::json jsonObject; jsonObject[TAG_GROUP_ID] = authResponseContext_->groupId; jsonObject[TAG_GROUP_NAME] = authResponseContext_->groupName; - jsonObject[PIN_CODE_KEY] = jsonObj[PIN_CODE_KEY]; + jsonObject[PIN_CODE_KEY] = pinCode; jsonObject[TAG_REQUEST_ID] = authResponseContext_->requestId; jsonObject[TAG_DEVICE_ID] = authResponseContext_->deviceId; std::string connectInfo = jsonObject.dump(); @@ -540,18 +540,10 @@ int32_t DmAuthManager::AddMember(const std::string &deviceId) [this] (std::string name) { DmAuthManager::HandleAuthenticateTimeout(name); }); - int32_t ret = hiChainConnector_->AddMember(deviceId, connectInfo); + int32_t ret = hiChainConnector_->AddMember(authRequestContext_->deviceId, connectInfo); if (ret != 0) { return ERR_DM_FAILED; } - LOGI("DmAuthManager::authRequestContext CancelDisplay start"); - std::shared_ptr ptr; - if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { - LOGE("DmAuthManager::authenticationMap_ is null"); - return ERR_DM_FAILED; - } - ptr = authenticationMap_[authResponseContext_->authType]; - ptr->CloseAuthInfo(authResponseContext_->pageId, shared_from_this()); return DM_OK; } @@ -578,13 +570,7 @@ void DmAuthManager::AuthenticateFinish() LOGI("DmAuthManager::AuthenticateFinish start"); if (authResponseState_ != nullptr) { if (authResponseState_->GetStateType() == AuthState::AUTH_RESPONSE_FINISH) { - 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()); + authPtr_->CloseAuthInfo(authResponseContext_->pageId, shared_from_this()); } if (isFinishOfLocal_) { authMessageProcessor_->SetResponseContext(authResponseContext_); @@ -596,6 +582,7 @@ void DmAuthManager::AuthenticateFinish() authResponseContext_ = nullptr; authResponseState_ = nullptr; authMessageProcessor_ = nullptr; + authPtr_ = nullptr; } else if (authRequestState_ != nullptr) { if (isFinishOfLocal_) { authMessageProcessor_->SetResponseContext(authResponseContext_); @@ -604,14 +591,9 @@ void DmAuthManager::AuthenticateFinish() } else { authRequestContext_->reason = authResponseContext_->reply; } - if (authResponseContext_->state == AuthState::AUTH_REQUEST_INPUT) { - 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()); + if (authResponseContext_->state == AuthState::AUTH_REQUEST_JOIN || + authResponseContext_->state == AuthState::AUTH_REQUEST_FINISH) { + authPtr_->CloseAuthInfo(authResponseContext_->pageId, shared_from_this()); } listener_->OnAuthResult(authRequestContext_->hostPkgName, authRequestContext_->deviceId, authRequestContext_->token, authResponseContext_->state, authRequestContext_->reason); @@ -622,6 +604,8 @@ void DmAuthManager::AuthenticateFinish() authResponseContext_ = nullptr; authRequestState_ = nullptr; authMessageProcessor_ = nullptr; + authPtr_ = nullptr; + authTimes_ = 0; } LOGI("DmAuthManager::AuthenticateFinish complete"); } @@ -686,12 +670,8 @@ int32_t DmAuthManager::SetAuthResponseState(std::shared_ptr a int32_t DmAuthManager::GetPinCode() { - nlohmann::json jsonObj = nlohmann::json::parse(authResponseContext_->authToken, nullptr, false); - if (jsonObj.is_discarded()) { - LOGE("DecodeRequestAuth jsonStr error"); - return ERR_DM_FAILED; - } - return jsonObj[PIN_CODE_KEY]; + LOGI("ShowConfigDialog start add member pin code %d", authResponseContext_->code); + return authResponseContext_->code; } void DmAuthManager::ShowConfigDialog() @@ -711,27 +691,17 @@ void DmAuthManager::ShowConfigDialog() void DmAuthManager::ShowAuthInfoDialog() { - LOGI("DmAuthManager::ShowAuthInfoDialog start"); - std::shared_ptr ptr; - if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { - LOGE("DmAuthManager::authenticationMap_ is null"); - return; - } - ptr = authenticationMap_[authResponseContext_->authType]; - LOGI("ShowAuthInfoDialog authToken:%s", authResponseContext_->authToken.c_str()); - ptr->ShowAuthInfo(authResponseContext_->authToken, shared_from_this()); + LOGI("DmAuthManager::ShowAuthInfoDialog start %d", authResponseContext_->code); + nlohmann::json jsonObj; + jsonObj[PIN_CODE_KEY] = authResponseContext_->code; + std::string authParam = jsonObj.dump(); + authPtr_->ShowAuthInfo(authParam, shared_from_this()); } void DmAuthManager::ShowStartAuthDialog() { LOGI("DmAuthManager::ShowStartAuthDialog start"); - std::shared_ptr ptr; - if (authenticationMap_.find(authResponseContext_->authType) == authenticationMap_.end()) { - LOGE("DmAuthManager::authenticationMap_ is null"); - return; - } - ptr = authenticationMap_[authResponseContext_->authType]; - ptr->StartAuth(authResponseContext_->authToken, shared_from_this()); + authPtr_->StartAuth(authResponseContext_->authToken, shared_from_this()); } int32_t DmAuthManager::GetAuthenticationParam(DmAuthParam &authParam) @@ -835,17 +805,20 @@ int32_t DmAuthManager::SetPageId(int32_t pageId) return DM_OK; } -int32_t DmAuthManager::SetReason(int32_t reason, int32_t state) +int32_t DmAuthManager::SetReasonAndFinish(int32_t reason, int32_t state) { if (authResponseContext_ == nullptr) { LOGE("Authenticate is not start"); return ERR_DM_AUTH_NOT_START; } - if (state < AuthState::AUTH_REQUEST_FINISH) { - authRequestContext_->reason = reason; - } authResponseContext_->state = state; authResponseContext_->reply = reason; + if (authRequestState_ != nullptr && authRequestState_->GetStateType() != AuthState::AUTH_REQUEST_FINISH) { + authRequestContext_->reason = reason; + authRequestState_->TransitionTo(std::make_shared()); + } else if (authResponseState_ != nullptr && authResponseState_->GetStateType() != AuthState::AUTH_RESPONSE_FINISH) { + authResponseState_->TransitionTo(std::make_shared()); + } return DM_OK; } } // namespace DistributedHardware diff --git a/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp b/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp index 6d49b0439..659d5a1f4 100644 --- a/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp +++ b/services/devicemanagerservice/src/discovery/dm_discovery_manager.cpp @@ -39,6 +39,7 @@ DmDiscoveryManager::~DmDiscoveryManager() int32_t DmDiscoveryManager::StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo, const std::string &extra) { + std::lock_guard autoLock(locks_); if (!discoveryQueue_.empty()) { if (pkgName == discoveryQueue_.front()) { LOGE("DmDiscoveryManager::StartDeviceDiscovery repeated, pkgName:%s", pkgName.c_str()); @@ -66,6 +67,7 @@ int32_t DmDiscoveryManager::StartDeviceDiscovery(const std::string &pkgName, con int32_t DmDiscoveryManager::StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId) { + std::lock_guard autoLock(locks_); if (!discoveryQueue_.empty()) { discoveryQueue_.pop(); } @@ -105,7 +107,18 @@ void DmDiscoveryManager::OnDiscoverySuccess(const std::string &pkgName, int32_t void DmDiscoveryManager::HandleDiscoveryTimeout(std::string name) { LOGI("DmDiscoveryManager::HandleDiscoveryTimeout"); - StopDeviceDiscovery(discoveryQueue_.front(), discoveryContextMap_[discoveryQueue_.front()].subscribeId); + if (discoveryQueue_.empty()) { + LOGE("HandleDiscoveryTimeout: discovery queue is empty."); + return; + } + + std::string pkgName = discoveryQueue_.front(); + auto iter = discoveryContextMap_.find(pkgName); + if (iter == discoveryContextMap_.end()) { + LOGE("HandleDiscoveryTimeout: subscribeId not found by pkgName %s", GetAnonyString(pkgName).c_str()); + return; + } + StopDeviceDiscovery(pkgName, discoveryContextMap_[pkgName].subscribeId); } } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_auth_request_state.cpp b/test/unittest/UTTest_auth_request_state.cpp index 9aad18166..9d0b6b0dc 100644 --- a/test/unittest/UTTest_auth_request_state.cpp +++ b/test/unittest/UTTest_auth_request_state.cpp @@ -439,57 +439,6 @@ HWTEST_F(AuthRequestStateTest, Enter_008, testing::ext::TestSize.Level0) ASSERT_EQ(ret, DM_OK); } -/** - * @tc.name: AuthRequestInputState::GetStateType_005 - * @tc.desc: 1 call AuthRequestInputState::GetStateType - * 2 check ret is AuthState::AUTH_REQUEST_INPUT - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(AuthRequestStateTest, GetStateType_005, testing::ext::TestSize.Level0) -{ - std::shared_ptr authRequestState = std::make_shared(); - int32_t ret = authRequestState->GetStateType(); - ASSERT_EQ(ret, AuthState::AUTH_REQUEST_INPUT); -} - -/** - * @tc.name: AuthRequestInputState::Enter_009 - * @tc.desc: 1 set authManager to null - * 2 call AuthRequestInputState::Enter with authManager = null - * 3 check ret is ERR_DM_FAILED - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(AuthRequestStateTest, Enter_009, testing::ext::TestSize.Level0) -{ - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); - std::shared_ptr authRequestState = std::make_shared(); - authRequestState->SetAuthManager(nullptr); - int32_t ret = authRequestState->Enter(); - ASSERT_EQ(ret, ERR_DM_FAILED); -} - -/** - * @tc.name: AuthRequestInputState::Enter_010 - * @tc.desc: 1 set authManager not null - * 2 call AuthRequestInputState::Enter with authManager != null - * 3 check ret is DM_OK - * @tc.type: FUNC - * @tc.require: AR000GHSJK - */ -HWTEST_F(AuthRequestStateTest, Enter_010, testing::ext::TestSize.Level0) -{ - std::shared_ptr authManager = - std::make_shared(softbusConnector, listener, hiChainConnector); - authManager->authResponseContext_ = std::make_shared(); - std::shared_ptr authRequestState = std::make_shared(); - authRequestState->SetAuthManager(authManager); - int32_t ret = authRequestState->Enter(); - ASSERT_EQ(ret, DM_OK); -} - /** * @tc.name: AuthRequestJoinState::GetStateType_006 * @tc.desc: 1 call AuthRequestJoinState::GetStateType @@ -538,6 +487,7 @@ HWTEST_F(AuthRequestStateTest, Enter_012, testing::ext::TestSize.Level0) authManager->authRequestContext_ = std::make_shared(); authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->authResponseContext_ = std::make_shared(); + authManager->authPtr_ = authManager->authenticationMap_[1]; authManager->authResponseContext_->groupId = "111"; authManager->authResponseContext_->groupName = "222"; authManager->authResponseContext_->code = 123; @@ -660,6 +610,7 @@ HWTEST_F(AuthRequestStateTest, Enter_016, testing::ext::TestSize.Level0) std::make_shared(softbusConnector, listener, hiChainConnector); std::shared_ptr authRequestState = std::make_shared(); authManager->timer_ = std::make_shared(); + authManager->authPtr_ = authManager->authenticationMap_[1]; authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->authResponseContext_ = std::make_shared(); authManager->authRequestContext_ = std::make_shared(); diff --git a/test/unittest/UTTest_auth_response_state.cpp b/test/unittest/UTTest_auth_response_state.cpp index 9ddcb2be6..51ef19ee7 100644 --- a/test/unittest/UTTest_auth_response_state.cpp +++ b/test/unittest/UTTest_auth_response_state.cpp @@ -235,6 +235,7 @@ HWTEST_F(AuthResponseStateTest, Enter_003, testing::ext::TestSize.Level0) authManager->authRequestState_ = std::make_shared(); authManager->authResponseContext_->deviceId = "111"; authManager->authResponseContext_->localDeviceId = "222"; + authManager->authPtr_ = authManager->authenticationMap_[1]; authManager->authMessageProcessor_->SetResponseContext(authManager->authResponseContext_); authManager->authMessageProcessor_->SetRequestContext(authManager->authRequestContext_); authManager->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(authManager); @@ -397,6 +398,8 @@ HWTEST_F(AuthResponseStateTest, Enter_009, testing::ext::TestSize.Level0) std::make_shared(softbusConnector, listener, hiChainConnector); authManager->authResponseContext_ = std::make_shared(); std::shared_ptr authResponseState = std::make_shared(); + authManager->authPtr_ = authManager->authenticationMap_[1]; + authManager->authResponseContext_->code = 123456; authResponseState->SetAuthManager(authManager); int32_t ret = authResponseState->Enter(); ASSERT_EQ(ret, DM_OK); @@ -453,6 +456,7 @@ HWTEST_F(AuthResponseStateTest, Enter_011, testing::ext::TestSize.Level0) authManager->authRequestContext_ = std::make_shared(); authManager->authMessageProcessor_ = std::make_shared(authManager); authManager->listener_ = std::make_shared(); + authManager->authPtr_ = authManager->authenticationMap_[1]; authManager->authResponseContext_->sessionId = 1; authManager->authRequestContext_->deviceId = "2"; authManager->authRequestContext_->hostPkgName = "3"; diff --git a/test/unittest/UTTest_dm_auth_manager.cpp b/test/unittest/UTTest_dm_auth_manager.cpp index 764c8322f..a6c76070a 100644 --- a/test/unittest/UTTest_dm_auth_manager.cpp +++ b/test/unittest/UTTest_dm_auth_manager.cpp @@ -208,10 +208,10 @@ HWTEST_F(DmAuthManagerTest, AddMember_001, testing::ext::TestSize.Level0) authManager->authResponseContext_->code = 123; authManager->authResponseContext_->requestId = 234; authManager->authResponseContext_->deviceId = "234"; - std::string deviceId = "44444"; + int32_t pinCode = 444444; authManager->hiChainConnector_->RegisterHiChainCallback(authManager); authManager->SetAuthResponseState(authResponseState); - int32_t ret = authManager->AddMember(deviceId); + int32_t ret = authManager->AddMember(pinCode); ASSERT_EQ(ret, ERR_DM_FAILED); } diff --git a/test/unittest/UTTest_pin_auth_ui.cpp b/test/unittest/UTTest_pin_auth_ui.cpp index 448854f0d..b1055473d 100644 --- a/test/unittest/UTTest_pin_auth_ui.cpp +++ b/test/unittest/UTTest_pin_auth_ui.cpp @@ -86,8 +86,7 @@ HWTEST_F(PinAuthUiTest, ShowPinDialog_002, testing::ext::TestSize.Level0) HWTEST_F(PinAuthUiTest, InputPinDialog_001, testing::ext::TestSize.Level0) { std::shared_ptr pinAuthUi = std::make_shared(); - int32_t code = 123456; - int32_t ret = pinAuthUi->InputPinDialog(code, nullptr); + int32_t ret = pinAuthUi->InputPinDialog(nullptr); ASSERT_EQ(ret, DM_OK); } @@ -100,8 +99,7 @@ HWTEST_F(PinAuthUiTest, InputPinDialog_001, testing::ext::TestSize.Level0) HWTEST_F(PinAuthUiTest, InputPinDialog_002, testing::ext::TestSize.Level0) { std::shared_ptr pinAuthUi = std::make_shared(); - int32_t code = 123456; - int32_t ret = pinAuthUi->InputPinDialog(code, authManager); + int32_t ret = pinAuthUi->InputPinDialog(authManager); ASSERT_EQ(ret, DM_OK); } } diff --git a/test/unittest/auth_request_state.cpp b/test/unittest/auth_request_state.cpp index 716367185..d3fdd78ec 100644 --- a/test/unittest/auth_request_state.cpp +++ b/test/unittest/auth_request_state.cpp @@ -122,23 +122,6 @@ int32_t AuthRequestReplyState::Enter() return DM_OK; } -int32_t AuthRequestInputState::GetStateType() -{ - return AuthState::AUTH_REQUEST_INPUT; -} - -int32_t AuthRequestInputState::Enter() -{ - LOGI("DmAuthManager::AuthRequestInputState"); - std::shared_ptr stateAuthManager = authManager_.lock(); - if (stateAuthManager == nullptr) { - LOGE("AuthRequestState::authManager_ null"); - return ERR_DM_FAILED; - } - stateAuthManager->ShowStartAuthDialog(); - return DM_OK; -} - int32_t AuthRequestJoinState::GetStateType() { return AuthState::AUTH_REQUEST_JOIN; -- Gitee From fed8aafb8f5e49ee7e50d8c7f33c483711d2f3a6 Mon Sep 17 00:00:00 2001 From: renguang1116 Date: Fri, 27 May 2022 11:36:04 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B7=A8=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E8=AE=A4=E8=AF=81=E4=B8=ADpin=E7=A0=81=E6=98=8E?= =?UTF-8?q?=E6=96=87=E4=BC=A0=E8=BE=93=E5=AF=BC=E8=87=B4=E7=9A=84=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E9=97=AE=E9=A2=98=20Signed-off-by:=20renguang1116=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ext/pin_auth/src/standard/pin_auth_ui.cpp | 24 +++++++++-------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/ext/pin_auth/src/standard/pin_auth_ui.cpp b/ext/pin_auth/src/standard/pin_auth_ui.cpp index d702ca37a..f294723b0 100644 --- a/ext/pin_auth/src/standard/pin_auth_ui.cpp +++ b/ext/pin_auth/src/standard/pin_auth_ui.cpp @@ -76,21 +76,15 @@ int32_t PinAuthUi::InputPinDialog(std::shared_ptr authManager) 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) { - switch (event) { - case EVENT_INIT: - authManager->SetPageId(id); - break; - case EVENT_CONFIRM: - LOGI("On confirm event for page id:%d, parms:%s", id, params.c_str()); - if (params.length() == DEFAULT_PIN_CODE_LENGTH) { - authManager->AddMember(std::stoi(params)); - } else { - UpdatePinDialog(id); - } - break; - default: - authManager->SetReasonAndFinish(ERR_DM_AUTH_INPUT_PARAMETER_FAILED, AuthState::AUTH_REQUEST_JOIN); - break; + if (event == EVENT_INIT) { + authManager->SetPageId(id); + } else if (event == EVENT_CONFIRM) { + LOGI("On confirm event for page id:%d, parms:%s", id, params.c_str()); + if (params.length() <= DEFAULT_PIN_CODE_LENGTH) { + authManager->AddMember(std::stoi(params)); + } + } else { + authManager->SetReasonAndFinish(ERR_DM_AUTH_INPUT_PARAMETER_FAILED, AuthState::AUTH_REQUEST_JOIN); } }); LOGI("ShowConfigDialog end"); -- Gitee