diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index f517f9230b40f2519dc0e49a2a8b45c315568a14..c3e54f4277d7d259e0f0a056d1fd2ee6642b45b1 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 d0ac1fc8a6e66e01ad9a10bc5e993af459429296..1bcb7eb0694853e743c6e9d86d7665d25f90f989 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 b67246a0b4afb00059c8509d13377ccd84db51e2..5c1404db59a5ce0cde724cc609404a183165cfd9 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 9a9271708f5b758841655766f3099ac0b2b41e4d..04373d589e81810a101e1456a2675f24ee42accd 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");