From 8e3623bf9f97a3b79e4865845e7e0db949f9cbb1 Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Thu, 8 May 2025 16:34:49 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhaohao --- .../utils/content_sensor_manager_utils.h | 1 + .../utils/content_sensor_manager_utils.cpp | 29 +++++++++++++++++++ ...distributed_device_profile_service_new.cpp | 4 +++ 3 files changed, 34 insertions(+) diff --git a/common/include/utils/content_sensor_manager_utils.h b/common/include/utils/content_sensor_manager_utils.h index 070d9d9e..0c7110ee 100644 --- a/common/include/utils/content_sensor_manager_utils.h +++ b/common/include/utils/content_sensor_manager_utils.h @@ -41,6 +41,7 @@ public: bool IsDeviceE2ESync(); int32_t GetProtType(); std::string GetSubProductId(); + std::string DecodeHexStr(const std::string &str); private: bool IsWifiOnly(); diff --git a/common/src/utils/content_sensor_manager_utils.cpp b/common/src/utils/content_sensor_manager_utils.cpp index 018d44bb..4eac69b4 100644 --- a/common/src/utils/content_sensor_manager_utils.cpp +++ b/common/src/utils/content_sensor_manager_utils.cpp @@ -46,6 +46,8 @@ namespace { constexpr int32_t WIFI_ONLY_FLAG_VALUE_MAX_LEN = 8; const char* OHOS_BOOT_BACKCOLOR = "ohos.boot.backcolor"; const char* SUB_PROD_ID_MAP = "const.distributed_collaboration.subProdIdMap"; + const std::string MANU_NAME = "485541574549"; + const std::string MANU_CODE = "001"; } IMPLEMENT_SINGLE_INSTANCE(ContentSensorManagerUtils); std::string ContentSensorManagerUtils::ObtainProductModel() @@ -112,6 +114,9 @@ std::string ContentSensorManagerUtils::ObtainManufacture() return manufacture_; } std::string manufactureTemp = system::GetParameter(MANUFACTURER_KEY, ""); + if (manufactureTemp == DecodeHexStr(MANU_NAME)) { + manufactureTemp = MANU_CODE; + } if (manufactureTemp.empty()) { HILOGE("get manufacture failed!"); return ""; @@ -333,5 +338,29 @@ std::map ContentSensorManagerUtils::GetSubProdIdMap() cJSON_Delete(json); return subProdIdMap_; } + +std::string ContentSensorManagerUtils::DecodeHexStr(const std::string &str) +{ + if (str.empty() || str.length() % NUM_2 != 0) { + HILOGE("str.length:%{public}zu is not an even number.", str.length()); + return EMPTY_STRING; + } + std::vector bytes; + for (size_t i = 0; i < str.length(); i += NUM_2) { + std::string byteStr = str.substr(i, NUM_2); + long result = strtol(byteStr.c_str(), nullptr, NUM_16); + if (result == LONG_MIN || result == LONG_MAX) { + HILOGE("decode hexstring error."); + return EMPTY_STRING; + } + uint8_t byte = (uint8_t)result; + bytes.push_back(byte); + } + if (bytes.empty()) { + HILOGE("bytes is empty"); + return EMPTY_STRING; + } + return std::string(bytes.begin(), bytes.end()); +} } // namespace DistributedDeviceProfile } // namespace OHOS diff --git a/services/core/src/distributed_device_profile_service_new.cpp b/services/core/src/distributed_device_profile_service_new.cpp index b8c0cb7f..1e91cdf2 100644 --- a/services/core/src/distributed_device_profile_service_new.cpp +++ b/services/core/src/distributed_device_profile_service_new.cpp @@ -954,6 +954,10 @@ void DistributedDeviceProfileServiceNew::AccountCommonEventCallback(int32_t user if (commonEventType == EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED) { // swithed MultiUserManager::GetInstance().SetCurrentForegroundUserID(userId); + if (ContentSensorManager::GetInstance().Init() != DP_SUCCESS) { + HILOGE("ContentSensorManager init failed"); + return; + } return; } if (commonEventType == EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED) { -- Gitee From d3c0f6853c17528223ae6543f68648c2cea4d56f Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Thu, 8 May 2025 16:53:19 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhaohao --- .../src/contentsensormanager/system_info_collector.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/services/core/src/contentsensormanager/system_info_collector.cpp b/services/core/src/contentsensormanager/system_info_collector.cpp index b2c71bc6..282c3c8e 100644 --- a/services/core/src/contentsensormanager/system_info_collector.cpp +++ b/services/core/src/contentsensormanager/system_info_collector.cpp @@ -41,6 +41,7 @@ constexpr uint32_t API_VERSION_LEN = 10; constexpr uint32_t SN_LEN = 32; constexpr uint32_t FULL_NAME_LEN = 128; constexpr uint32_t VERSION_SDK_LEN = 10; +const std::vector PRODUCT_NAME_PREFIXS {"485541574549", "687561776569", "e58d8ee4b8ba"}; } bool SystemInfoCollector::ConvertToProfile(DeviceProfile& profile) @@ -109,8 +110,12 @@ std::string SystemInfoCollector::GetProductId() std::string SystemInfoCollector::GetProductName() { - std::string productName = ""; - SettingsDataManager::GetInstance().GetDeviceName(productName); + std::string productName = ContentSensorManagerUtils::GetInstance().ObtainMarketName(); + for (const auto &item : PRODUCT_NAME_PREFIXS) { + productName = TrimStr(ReplaceStr(productName, + DistributedDeviceProfile::ContentSensorManagerUtils::GetInstance().DecodeHexStr(item), "")); + } + HILOGI("productName : %{public}s", ProfileUtils::GetAnonyString(productName).c_str()); return productName; } -- Gitee From 918a5c355f5bd4573e6fa6586eb4d3e6cf3e0bfb Mon Sep 17 00:00:00 2001 From: wangzhaohao Date: Thu, 8 May 2025 18:38:31 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangzhaohao --- common/include/constants/distributed_device_profile_constants.h | 1 + 1 file changed, 1 insertion(+) diff --git a/common/include/constants/distributed_device_profile_constants.h b/common/include/constants/distributed_device_profile_constants.h index 3c4af7f3..5d65eaee 100644 --- a/common/include/constants/distributed_device_profile_constants.h +++ b/common/include/constants/distributed_device_profile_constants.h @@ -264,6 +264,7 @@ constexpr int32_t NUM_3 = 3; constexpr int32_t NUM_4 = 4; constexpr int32_t NUM_5 = 5; constexpr int32_t NUM_6 = 6; +constexpr int32_t NUM_16 = 16; constexpr int32_t DEFAULT_USER_ID = -1; constexpr int32_t DEFAULT_USER_ID_EXTRA = 0; constexpr int32_t U_100 = 100; -- Gitee