From 38b908eb129e807964f80acbcc4efe3593908cab Mon Sep 17 00:00:00 2001 From: maan4 Date: Tue, 27 May 2025 22:03:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=9B=B4=E6=9D=BF=E6=9C=BA?= =?UTF-8?q?=E5=86=85=E5=AD=98=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: maan4 --- services/include/sensor_service.h | 1 + services/src/sensor_service.cpp | 31 ++++++++++++++++++++++++++++-- utils/common/src/motion_plugin.cpp | 6 +++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/services/include/sensor_service.h b/services/include/sensor_service.h index 39286c8a..969b482e 100644 --- a/services/include/sensor_service.h +++ b/services/include/sensor_service.h @@ -89,6 +89,7 @@ private: bool CheckSensorId(int32_t sensorId); bool IsSystemServiceCalling(); bool IsSystemCalling(); + bool IsNeedLoadMotionLib(); SensorServiceState state_; std::mutex serviceLock_; std::mutex sensorsMutex_; diff --git a/services/src/sensor_service.cpp b/services/src/sensor_service.cpp index 132203d9..8450e199 100644 --- a/services/src/sensor_service.cpp +++ b/services/src/sensor_service.cpp @@ -46,6 +46,9 @@ const bool G_REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(g_sensorSer constexpr int32_t INVALID_PID = -1; constexpr int64_t MAX_EVENT_COUNT = 1000; std::atomic_bool g_isRegister = false; +constexpr int32_t SINGLE_DISPLAY_SMALL_FOLD = 4; +constexpr int32_t SINGLE_DISPLAY_THREE_FOLD = 6; +const std::string DEFAULTS_FOLD_TYPE = "0,0,0,0"; } // namespace std::atomic_bool SensorService::isAccessTokenServiceActive_ = false; @@ -56,7 +59,10 @@ SensorService::SensorService() SEN_HILOGD("Add SystemAbility"); } -SensorService::~SensorService() {} +SensorService::~SensorService() +{ + UnloadMotionSensor(); +} void SensorService::OnDump() { @@ -68,6 +74,25 @@ std::string GetDmsDeviceStatus() return OHOS::system::GetParameter("persist.dms.device.status", "0"); } +bool SensorService::IsNeedLoadMotionLib() +{ + std::string supportDevice = OHOS::system::GetParameter("const.window.foldscreen.type", DEFAULTS_FOLD_TYPE); + size_t index = supportDevice.find(','); + if (index != std::string::npos) { + std::string firstValue = supportDevice.substr(0, index); + SEN_HILOGI("firstValue:%{public}s", firstValue.c_str()); + if (std::isdigit(firstValue[0]) == 0) { + SEN_HILOGI("firstValue is not number"); + return false; + } + if (std::stoi(firstValue) == SINGLE_DISPLAY_SMALL_FOLD || std::stoi(firstValue) == SINGLE_DISPLAY_THREE_FOLD) { + return true; + } + } + SEN_HILOGI("Not support in this device"); + return false; +} + void SensorService::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) { SEN_HILOGI("OnAddSystemAbility systemAbilityId:%{public}d", systemAbilityId); @@ -84,7 +109,9 @@ void SensorService::OnAddSystemAbility(int32_t systemAbilityId, const std::strin #endif // ACCESS_TOKEN_ENABLE #ifdef MSDP_MOTION_ENABLE if (systemAbilityId == MSDP_MOTION_SERVICE_ID) { - if (!LoadMotionSensor()) { + if (!IsNeedLoadMotionLib()) { + SEN_HILOGI("No need to load motion lib"); + } else if (!LoadMotionSensor()) { SEN_HILOGI("LoadMotionSensor fail"); } } diff --git a/utils/common/src/motion_plugin.cpp b/utils/common/src/motion_plugin.cpp index 3aa79515..4c080685 100644 --- a/utils/common/src/motion_plugin.cpp +++ b/utils/common/src/motion_plugin.cpp @@ -59,10 +59,14 @@ __attribute__((no_sanitize("cfi"))) void MotionTransformIfRequired(const std::st uint32_t state, SensorData* sensorData) { if (g_handle == nullptr) { - SEN_HILOGE("g_handle is nullptr"); + SEN_HILOGD("g_handle is nullptr"); return; } MotionTransformIfRequiredPtr func = (MotionTransformIfRequiredPtr)(dlsym(g_handle, "TransformIfRequired")); + if (func == nullptr) { + SEN_HILOGE("func is nullptr"); + return; + } const char* dlsymError = dlerror(); if (dlsymError) { SEN_HILOGE("dlsym error: %{public}s", dlsymError); -- Gitee