From 8dcc568e1adcdf097e14f1ef1c40e83cd6caa6e4 Mon Sep 17 00:00:00 2001 From: wangbaidong Date: Wed, 6 Aug 2025 20:23:06 +0800 Subject: [PATCH] 0806 Signed-off-by: wangbaidong --- .../native_cpp/include/dm_device_info.h | 3 +- .../authentication_v2/dm_freeze_process.h | 5 ++- .../src/authentication/dm_auth_manager.cpp | 3 +- .../auth_stages/auth_acl.cpp | 6 ++- .../authentication_v2/dm_freeze_process.cpp | 41 +++++++++++++++++++ test/unittest/BUILD.gn | 1 + 6 files changed, 55 insertions(+), 4 deletions(-) diff --git a/interfaces/inner_kits/native_cpp/include/dm_device_info.h b/interfaces/inner_kits/native_cpp/include/dm_device_info.h index 67c3a32ae..b7704d94d 100644 --- a/interfaces/inner_kits/native_cpp/include/dm_device_info.h +++ b/interfaces/inner_kits/native_cpp/include/dm_device_info.h @@ -439,7 +439,8 @@ enum class DMLocalServiceInfoAuthType : int32_t { enum class DMLocalServiceInfoPinExchangeType : int32_t { PINBOX = 1, ULTRASOUND = 2, - FROMDP = 3 + FROMDP = 3, + IMPORT_AUTH_CODE = 5 }; enum class DMLocalServiceInfoAuthBoxType : int32_t { diff --git a/services/implementation/include/authentication_v2/dm_freeze_process.h b/services/implementation/include/authentication_v2/dm_freeze_process.h index 796f36196..7c2974570 100644 --- a/services/implementation/include/authentication_v2/dm_freeze_process.h +++ b/services/implementation/include/authentication_v2/dm_freeze_process.h @@ -18,8 +18,10 @@ #include #include -#include "kv_adapter_manager.h" +#include "deviceprofile_connector.h" +#include "dm_auth_context.h" #include "dm_single_instance.h" +#include "kv_adapter_manager.h" namespace OHOS { namespace DistributedHardware { @@ -59,6 +61,7 @@ public: bool IsFrozen(int64_t &remainingFrozenTime); int32_t DeleteFreezeRecord(); int32_t UpdateFreezeRecord(); + bool IsNeedFreeze(std::shared_ptr context); private: FreezeProcess() = default; ~FreezeProcess() = default; diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 88f61775e..42dc1d7df 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -1608,7 +1608,8 @@ bool DmAuthManager::IsServiceInfoPinExchangeTypeValid(int32_t pinExchangeType) { if (pinExchangeType != (int32_t)DMLocalServiceInfoPinExchangeType::PINBOX && pinExchangeType != (int32_t)DMLocalServiceInfoPinExchangeType::FROMDP && - pinExchangeType != (int32_t)DMLocalServiceInfoPinExchangeType::ULTRASOUND) { + pinExchangeType != (int32_t)DMLocalServiceInfoPinExchangeType::ULTRASOUND && + pinExchangeType != (int32_t)DMLocalServiceInfoPinExchangeType::IMPORT_AUTH_CODE) { return false; } return true; diff --git a/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp b/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp index a4581ac99..fa0d1e9d9 100644 --- a/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp +++ b/services/implementation/src/authentication_v2/auth_stages/auth_acl.cpp @@ -21,6 +21,7 @@ #include "dm_auth_attest_common.h" #include "dm_auth_cert.h" #include "dm_auth_context.h" +#include "dm_auth_manager_base.h" #include "dm_auth_state.h" #include "dm_auth_state_machine.h" #include "dm_constants.h" @@ -211,7 +212,10 @@ int32_t AuthSinkFinishState::Action(std::shared_ptr context) ret = FreezeProcess::GetInstance().DeleteFreezeRecord(); LOGI("DeleteFreezeRecord ret: %{public}d", ret); } - if (context->reason == ERR_DM_BIND_PIN_CODE_ERROR) { + bool isNeedFreeze = FreezeProcess::GetInstance().IsNeedFreeze(context); + bool isInWhiteList = AuthManagerBase::CheckProcessNameInWhiteList(context->accessee.bundleName); + LOGI("isInWhiteList: %{public}d.", isInWhiteList); + if (context->reason == ERR_DM_BIND_PIN_CODE_ERROR && (isNeedFreeze || !isInWhiteList)) { ret = FreezeProcess::GetInstance().UpdateFreezeRecord(); LOGI("UpdateFreezeData ret: %{public}d", ret); } diff --git a/services/implementation/src/authentication_v2/dm_freeze_process.cpp b/services/implementation/src/authentication_v2/dm_freeze_process.cpp index 9e7d4a1e3..7c34cb41f 100644 --- a/services/implementation/src/authentication_v2/dm_freeze_process.cpp +++ b/services/implementation/src/authentication_v2/dm_freeze_process.cpp @@ -30,6 +30,9 @@ constexpr const char* START_FREEZE_TIME_KEY = "startFreezeTimeStamp"; constexpr const char* STOP_FREEZE_TIME_KEY = "stopFreezeTimeStamp"; constexpr const char* FAILED_TIMES_STAMPS_KEY = "failedTimeStamps"; constexpr const char* FREEZE_TIMES_STAMPS_KEY = "freezeTimeStamps"; +constexpr const char* IS_NEED_FREEZE = "IsNeedFreeze"; +constexpr const char* NEED_FREEZE = "0"; +constexpr const char* NO_NEED_FREEZE = "1"; constexpr int32_t MAX_CONTINUOUS_BIND_FAILED_NUM = 2; constexpr int64_t CONTINUEOUS_FAILED_INTERVAL = 6 * 60; constexpr int64_t DATA_REFRESH_INTERVAL = 20 * 60; @@ -331,5 +334,43 @@ void FreezeProcess::CalculateNextFreezeTime(int64_t nowFreezeTime, int64_t &next break; } } + +bool FreezeProcess::IsNeedFreeze(std::shared_ptr context) +{ + LOGI("called"); + bool isNeedFreeze = true; + if (context == nullptr) { + LOGE("context is null"); + return isNeedFreeze; + } + OHOS::DistributedDeviceProfile::LocalServiceInfo srvInfo; + auto ret = DeviceProfileConnector::GetInstance().GetLocalServiceInfoByBundleNameAndPinExchangeType( + context->accessee.pkgName, context->authType, srvInfo); + if (ret != DM_OK) { + LOGE("ServiceInfo not found"); + return isNeedFreeze; + } + std::string extraInfo = srvInfo.GetExtraInfo(); + if (extraInfo.empty()) { + LOGE("no extraInfo"); + return isNeedFreeze; + } + JsonObject jsonObj; + jsonObj.Parse(extraInfo); + if (jsonObj.IsDiscarded()) { + LOGE("extraInfo invalid"); + return isNeedFreeze; + } + std::string isNeedFreezeStr; + if (IsString(jsonObj, IS_NEED_FREEZE)) { + isNeedFreezeStr = jsonObj[IS_NEED_FREEZE].Get(); + LOGI("isNeedFreezeStr: %{public}s.", isNeedFreezeStr.c_str()); + } + if (isNeedFreezeStr == NEED_FREEZE || isNeedFreezeStr == NO_NEED_FREEZE) { + isNeedFreeze = std::atoi(isNeedFreezeStr.c_str()); + } + LOGI("isNeedFreeze: %{public}d.", isNeedFreeze); + return isNeedFreeze; +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index a12e0cfdc..5342cfb74 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -2466,6 +2466,7 @@ ohos_unittest("UTTest_freeze_process") { "device_auth:deviceauth_sdk", "device_info_manager:distributed_device_profile_common", "device_info_manager:distributed_device_profile_sdk", + "dsoftbus:softbus_client", "ffrt:libffrt", "googletest:gmock", "hilog:libhilog", -- Gitee