diff --git a/sensor.gni b/sensor.gni index 1a0bbf4c..4306a824 100644 --- a/sensor.gni +++ b/sensor.gni @@ -35,6 +35,13 @@ if (!defined(global_parts_info) || hdf_drivers_interface_sensor = false } +if (!defined(global_parts_info) || + defined(global_parts_info.resourceschedule_memmgr_override)) { + sensor_memmgr_enable = true +} else { + sensor_memmgr_enable = false +} + if (build_variant == "root") { sensor_default_defines += [ "BUILD_VARIANT_ENG" ] sensor_build_eng = true diff --git a/services/BUILD.gn b/services/BUILD.gn index a9c7f1ee..f8b346c3 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -62,11 +62,14 @@ ohos_shared_library("libsensor_service") { "hisysevent:libhisysevent", "hitrace:hitrace_meter", "ipc:ipc_single", - "memmgr:memmgrclient", "safwk:system_ability_fwk", - "samgr:samgr_proxy", ] + if (sensor_memmgr_enable) { + defines += [ "MEMMGR_ENABLE" ] + external_deps += [ "memmgr:memmgrclient" ] + } + if (hdf_drivers_interface_sensor) { sources += [ "hdi_connection/adapter/src/hdi_connection.cpp", @@ -147,11 +150,14 @@ ohos_static_library("libsensor_service_static") { "hisysevent:libhisysevent", "hitrace:hitrace_meter", "ipc:ipc_single", - "memmgr:memmgrclient", "safwk:system_ability_fwk", - "samgr:samgr_proxy", ] + if (sensor_memmgr_enable) { + defines += [ "MEMMGR_ENABLE" ] + external_deps += [ "memmgr:memmgrclient" ] + } + if (hdf_drivers_interface_sensor) { sources += [ "hdi_connection/adapter/src/hdi_connection.cpp", diff --git a/services/src/sensor_service.cpp b/services/src/sensor_service.cpp index e2f57111..2aa55dc4 100644 --- a/services/src/sensor_service.cpp +++ b/services/src/sensor_service.cpp @@ -22,8 +22,9 @@ #include "hisysevent.h" #include "iservice_registry.h" +#ifdef MEMMGR_ENABLE #include "mem_mgr_client.h" -#include "mem_mgr_proxy.h" +#endif // MEMMGR_ENABLE #include "permission_util.h" #include "securec.h" @@ -43,10 +44,6 @@ auto g_sensorService = SensorDelayedSpSingleton::GetInstance(); const bool G_REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(g_sensorService.GetRefPtr()); constexpr int32_t INVALID_PID = -1; constexpr int64_t MAX_EVENT_COUNT = 1000; -constexpr int32_t SA_ID = 3601; -constexpr int32_t SYSTEM_STATUS_START = 1; -constexpr int32_t SYSTEM_STATUS_STOP = 0; -constexpr int32_t SYSTEM_PROCESS_TYPE = 1; std::atomic_bool g_isRegister = false; } // namespace @@ -66,10 +63,12 @@ void SensorService::OnDump() void SensorService::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) { SEN_HILOGI("OnAddSystemAbility systemAbilityId:%{public}d", systemAbilityId); +#ifdef MEMMGR_ENABLE if (systemAbilityId == MEMORY_MANAGER_SA_ID) { Memory::MemMgrClient::GetInstance().NotifyProcessStatus(getpid(), - SYSTEM_PROCESS_TYPE, SYSTEM_STATUS_START, SA_ID); + PROCESS_TYPE_SA, PROCESS_STATUS_STARTED, SENSOR_SERVICE_ABILITY_ID); } +#endif // MEMMGR_ENABLE } void SensorService::OnStart() @@ -105,7 +104,9 @@ void SensorService::OnStart() return; } state_ = SensorServiceState::STATE_RUNNING; +#ifdef MEMMGR_ENABLE AddSystemAbilityListener(MEMORY_MANAGER_SA_ID); +#endif // MEMMGR_ENABLE } #ifdef HDF_DRIVERS_INTERFACE_SENSOR @@ -172,8 +173,10 @@ void SensorService::OnStop() } #endif // HDF_DRIVERS_INTERFACE_SENSOR UnregisterPermCallback(); - Memory::MemMgrClient::GetInstance().NotifyProcessStatus(getpid(), - SYSTEM_PROCESS_TYPE, SYSTEM_STATUS_STOP, SA_ID); +#ifdef MEMMGR_ENABLE + Memory::MemMgrClient::GetInstance().NotifyProcessStatus(getpid(), PROCESS_TYPE_SA, PROCESS_STATUS_DIED, + SENSOR_SERVICE_ABILITY_ID); +#endif // MEMMGR_ENABLE } void SensorService::ReportSensorSysEvent(int32_t sensorId, bool enable, int32_t pid)