diff --git a/services/include/sensor_service.h b/services/include/sensor_service.h index 39286c8a47d6d9531e05ed6ff2a61c076ed4e67d..969b482e25a540375f5378ccbed4006a43ddebc8 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 132203d9a1e83462eff0e9c91ee55973ffb1f503..8450e199bdb338bef1bed313cfb8c3c1db92fcba 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 3aa7951575156ee05f4b5086a692528e7f2c8037..4c0806855ca93eec1d367789f9cbcc156db89caf 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);