From 92a560e94346a75e87003e32f768359c3f0d9834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Tue, 7 Jan 2025 19:32:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BF=A1=E4=BB=BB=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- common/include/dm_constants.h | 1 + .../include/authentication/dm_auth_manager.h | 3 ++ .../authentication/auth_message_processor.cpp | 10 +++++++ .../src/authentication/dm_auth_manager.cpp | 30 +++++++++++++++---- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index f517f9230..c3e54f427 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -253,6 +253,7 @@ constexpr const char* PARAM_KEY_POLICY_TIME_OUT = "DM_POLICY_TIMEOUT"; constexpr const char* DEVICE_SCREEN_STATUS = "DEVICE_SCREEN_STATUS"; constexpr const char* PROCESS_NAME = "PROCESS_NAME"; constexpr const char* PARAM_CLOSE_SESSION_DELAY_SECONDS = "DM_CLOSE_SESSION_DELAY_SECONDS"; +constexpr const char* DM_USER_OPERATION_TYPE = "DM_USER_OPERATION_TYPE"; // screen state constexpr int32_t DM_SCREEN_UNKNOWN = -1; diff --git a/services/implementation/include/authentication/dm_auth_manager.h b/services/implementation/include/authentication/dm_auth_manager.h index d0ac1fc8a..1bcb7eb06 100644 --- a/services/implementation/include/authentication/dm_auth_manager.h +++ b/services/implementation/include/authentication/dm_auth_manager.h @@ -134,6 +134,7 @@ typedef struct DmAuthRequestContext { std::string addr; std::string hostPkgLabel; int32_t closeSessionDelaySeconds = 0; + int32_t userOperationType = USER_OPERATION_TYPE_ALLOW_AUTH; } DmAuthRequestContext; typedef struct DmAuthResponseContext { @@ -191,6 +192,7 @@ typedef struct DmAuthResponseContext { bool isFinish = false; std::string edition; int32_t localBindLevel; + int32_t userOperationType = USER_OPERATION_TYPE_ALLOW_AUTH; } DmAuthResponseContext; class AuthMessageProcessor; @@ -554,6 +556,7 @@ private: void ConverToFinish(); bool IsSinkMsgValid(); bool IsSourceMsgValid(); + int32_t GetUserOperationType(std::string &userOperationTypeStr); private: std::shared_ptr softbusConnector_; diff --git a/services/implementation/src/authentication/auth_message_processor.cpp b/services/implementation/src/authentication/auth_message_processor.cpp index b67246a0b..5c1404db5 100644 --- a/services/implementation/src/authentication/auth_message_processor.cpp +++ b/services/implementation/src/authentication/auth_message_processor.cpp @@ -80,6 +80,7 @@ void AuthMessageProcessor::GetJsonObj(nlohmann::json &jsonObj) std::string itemStr = std::to_string(item); jsonObj[itemStr] = authResponseContext_->bindType[item]; } + jsonObj[DM_USER_OPERATION_TYPE] = authRequestContext_->userOperationType; } std::vector AuthMessageProcessor::CreateAuthRequestMessage() @@ -457,6 +458,15 @@ int32_t AuthMessageProcessor::ParseAuthRequestMessage(nlohmann::json &json) } else { authResponseContext_->isShowDialog = true; } + authResponseContext_->userOperationType = USER_OPERATION_TYPE_ALLOW_AUTH; + if (IsInt32(json, DM_USER_OPERATION_TYPE)) { + int32_t userOperationType = json[DM_USER_OPERATION_TYPE].get(); + if (userOperationType < 0 || userOperationType > USER_OPERATION_TYPE_ALLOW_AUTH_ALWAYS) { + authResponseContext_->userOperationType = USER_OPERATION_TYPE_ALLOW_AUTH; + } else { + authResponseContext_->userOperationType = userOperationType; + } + } if (IsInt32(json, TAG_BIND_TYPE_SIZE)) { int32_t bindTypeSize = json[TAG_BIND_TYPE_SIZE].get(); if (bindTypeSize > MAX_BINDTYPE_SIZE) { diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 9a9271708..04373d589 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -277,10 +277,29 @@ void DmAuthManager::ParseJsonObject(nlohmann::json jsonObject) } else { authRequestContext_->peerBundleName = authRequestContext_->hostPkgName; } + authRequestContext_->userOperationType = USER_OPERATION_TYPE_ALLOW_AUTH; + if (IsString(jsonObject, DM_USER_OPERATION_TYPE)) { + std::string operatorTypeStr = jsonObject[DM_USER_OPERATION_TYPE].get(); + authRequestContext_->userOperationType = GetUserOperationType(operatorTypeStr); + } } authRequestContext_->bundleName = GetBundleName(jsonObject); } +int32_t DmAuthManager::GetUserOperationType(std::string &userOperationTypeStr) +{ + if (!IsNumberString(userOperationTypeStr)) { + LOGE("Invalid parameter, param is not number."); + return USER_OPERATION_TYPE_ALLOW_AUTH; + } + int32_t userOperationType = std::atoi(userOperationTypeStr.c_str()); + if (userOperationType < 0 || userOperationType > USER_OPERATION_TYPE_ALLOW_AUTH_ALWAYS) { + LOGE("Invalid parameter, param out of range."); + return USER_OPERATION_TYPE_ALLOW_AUTH; + } + return userOperationType; +} + int32_t DmAuthManager::GetCloseSessionDelaySeconds(std::string &delaySecondsStr) { if (!IsNumberString(delaySecondsStr)) { @@ -1349,10 +1368,6 @@ void DmAuthManager::SrcAuthenticateFinish() authUiStateMgr_->UpdateUiState(DmUiStateMsg::MSG_CANCEL_PIN_CODE_INPUT); } usleep(USLEEP_TIME_US_500000); // 500ms - listener_->OnAuthResult(processInfo_, peerTargetId_.deviceId, authRequestContext_->token, - authResponseContext_->state, authRequestContext_->reason); - listener_->OnBindResult(processInfo_, peerTargetId_, authRequestContext_->reason, - authResponseContext_->state, GenerateBindResultContent()); int32_t sessionId = authRequestContext_->sessionId; auto taskFunc = [this, sessionId]() { @@ -1364,6 +1379,11 @@ void DmAuthManager::SrcAuthenticateFinish() int32_t delaySeconds = authRequestContext_->closeSessionDelaySeconds; ffrt::submit(taskFunc, ffrt::task_attr().delay(delaySeconds * MICROSECOND_PER_SECOND)); + listener_->OnAuthResult(processInfo_, peerTargetId_.deviceId, authRequestContext_->token, + authResponseContext_->state, authRequestContext_->reason); + listener_->OnBindResult(processInfo_, peerTargetId_, authRequestContext_->reason, + authResponseContext_->state, GenerateBindResultContent()); + authRequestContext_ = nullptr; authRequestState_ = nullptr; authTimes_ = 0; @@ -1520,7 +1540,7 @@ void DmAuthManager::ShowConfigDialog() } if (!authResponseContext_->isShowDialog) { LOGI("start auth process"); - StartAuthProcess(USER_OPERATION_TYPE_ALLOW_AUTH); + StartAuthProcess(authResponseContext_->userOperationType); return; } LOGI("ShowConfigDialog start"); -- Gitee