From 48e83d6329ed566c82df980bdaead528d1515b57 Mon Sep 17 00:00:00 2001 From: zhuofan0129 <861080528@qq.com> Date: Sun, 16 Jun 2024 15:28:12 +0800 Subject: [PATCH] feat: add osType judge Signed-off-by: zhuofan0129 <861080528@qq.com> --- .../messenger_device_status_manager.cpp | 28 ++++++++++++++----- services/dslm/dslm_fsm_process.c | 18 ++++++++++-- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/baselib/msglib/src/standard/messenger_device_status_manager.cpp b/baselib/msglib/src/standard/messenger_device_status_manager.cpp index 18a74fa..e9d5553 100644 --- a/baselib/msglib/src/standard/messenger_device_status_manager.cpp +++ b/baselib/msglib/src/standard/messenger_device_status_manager.cpp @@ -27,10 +27,12 @@ #include "messenger_utils.h" #include "utils_log.h" #include "utils_mem.h" +#include "utils_json.h" #define PKG_NAME_LEN 128 +#define TYPE_PLACE 8 -static void GetDeviceSecurityLevelByNetworkId(const std::string &networkId, int32_t &level); +static void GetDeviceSecurityLevelByNetworkId(const OHOS::DistributedHardware::DmDeviceInfo &info, int32_t &level); namespace OHOS { namespace Security { @@ -124,7 +126,7 @@ public: return; } if (state == EVENT_NODE_STATE_ONLINE) { - GetDeviceSecurityLevelByNetworkId(info.networkId, level); + GetDeviceSecurityLevelByNetworkId(info, level); } ProcessDeviceStatusReceiver(&identity, state, level); } @@ -245,11 +247,22 @@ extern "C" { #endif using namespace OHOS::Security::DeviceSecurityLevel; -static void GetDeviceSecurityLevelByNetworkId(const std::string &networkId, int32_t &level) +static void GetDeviceSecurityLevelByNetworkId(const OHOS::DistributedHardware::DmDeviceInfo &info, int32_t &level) { const char pkgName[PKG_NAME_LEN + 1] = "ohos.dslm"; - int32_t ret = DeviceManager::GetInstance().GetDeviceSecurityLevel(pkgName, networkId, level); + int32_t ret = DeviceManager::GetInstance().GetDeviceSecurityLevel(pkgName, info.networkId, level); SECURITY_LOG_INFO("GetDeviceSecurityLevelByNetworkId ret = %{public}d, level = %{public}d", ret, level); + + const char *jsonString = static_cast(info.extraData.c_str()); + DslmJsonHandle handle = DslmCreateJson(jsonString); + if (handle == nullptr) { + return; + } + const int32_t osType = DslmGetJsonFieldInt(handle, "OS_TYPE"); + SECURITY_LOG_INFO("device type is %{public}d", osType); + level |= (osType << TYPE_PLACE); + DslmDestroyJson(handle); + return; } bool InitDeviceStatusManager(WorkQueue *queue, const char *pkgName, DeviceStatusReceiver deviceStatusReceiver) @@ -312,7 +325,7 @@ bool MessengerGetDeviceOnlineStatus(const DeviceIdentify *devId, int32_t *level) DmDeviceInfo info; bool result = MessengerGetDeviceNodeBasicInfo(*devId, info); if (result == true && level != nullptr) { - GetDeviceSecurityLevelByNetworkId(info.networkId, *level); + GetDeviceSecurityLevelByNetworkId(info, *level); } return result; } @@ -337,7 +350,8 @@ bool MessengerGetSelfDeviceIdentify(DeviceIdentify *devId, int32_t *level) return false; } - GetDeviceSecurityLevelByNetworkId(info.networkId, *level); + GetDeviceSecurityLevelByNetworkId(info, *level); + *level = *level & 0xFF; uint32_t maskId = MaskDeviceIdentity((const char *)&devId->identity[0], DEVICE_ID_MAX_LEN); SECURITY_LOG_DEBUG("MessengerGetSelfDeviceIdentify device %{public}x***, level is %{public}d", maskId, *level); @@ -363,7 +377,7 @@ void MessengerForEachDeviceProcess(const DeviceProcessor processor, void *para) DeviceIdentify curr = {DEVICE_ID_MAX_LEN, {0}}; bool convert = MessengerConvertNodeToIdentity(device.networkId, curr); int32_t level = 0; - GetDeviceSecurityLevelByNetworkId(device.networkId, level); + GetDeviceSecurityLevelByNetworkId(device, level); if (convert == true) { processor(&curr, level, para); diff --git a/services/dslm/dslm_fsm_process.c b/services/dslm/dslm_fsm_process.c index c3e6600..5115d26 100644 --- a/services/dslm/dslm_fsm_process.c +++ b/services/dslm/dslm_fsm_process.c @@ -39,6 +39,8 @@ #include "dslm_notify_node.h" #define REQUEST_INTERVAL (24 * 60 * 60 * 1000) +#define DEFAULT_TYPE 10 +#define TYPE_PLACE 8 typedef bool DslmInfoChecker(const DslmDeviceInfo *devInfo, const DslmNotifyListNode *node, DslmCallbackInfo *cbInfo, uint32_t *result); @@ -191,15 +193,25 @@ static bool CheckNeedToResend(const DslmDeviceInfo *info) static bool ProcessDeviceOnline(const StateMachine *machine, uint32_t event, const void *para) { DslmDeviceInfo *info = STATE_MACHINE_ENTRY(machine, DslmDeviceInfo, machine); - if (para != NULL && *(int32_t *)para > 0) { - info->credInfo.credLevel = *(int32_t *)para; + int32_t deviceAttributes = 0; + if (para != NULL) { + deviceAttributes = *(int32_t *)para; + } + int32_t level = deviceAttributes & 0xFF; + int32_t osType = (deviceAttributes & 0xFF00) >> TYPE_PLACE; + if (level == 0 && osType == DEFAULT_TYPE) { + level = 1; + SECURITY_LOG_INFO("level set 1"); + } + if (level > 0) { + info->credInfo.credLevel = level; info->result = SUCCESS; } info->onlineStatus = ONLINE_STATUS_ONLINE; info->queryTimes = 0; info->lastOnlineTime = GetMillisecondSinceBoot(); if (!CheckNeedToResend(info)) { - SECURITY_LOG_DEBUG("last request time is last than 24 hours"); + SECURITY_LOG_INFO("last request time is last than 24 hours"); ScheduleDslmStateMachine(info, EVENT_TO_SYNC, NULL); return true; } -- Gitee