diff --git a/bundle.json b/bundle.json index f240097189198e83b61cd2055ff4560db4fbd964..0d3714a305cb5cf8c52461f03ec16880508f3184 100644 --- a/bundle.json +++ b/bundle.json @@ -16,12 +16,13 @@ "ram": "~200KB", "deps": { "components": [ - "samgr_lite", + "drivers_peripheral_sensor", + "hilog_lite", "ipc", - "utils_base", - "hdi_sensor" + "samgr_lite", + "utils_lite" ], - "third_party": [] + "third_party": [ "bounds_checking_function" ] }, "build": { "sub_component": [ diff --git a/sensor_lite.gni b/sensor_lite.gni new file mode 100644 index 0000000000000000000000000000000000000000..c69a7f4588e0d0fddca204e0a1a6b9cf1c8235ed --- /dev/null +++ b/sensor_lite.gni @@ -0,0 +1,24 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") + +sensor_default_defines = [] + +if (!defined(global_parts_info) || + defined(global_parts_info.hdf_drivers_peripheral_sensor)) { + has_drivers_peripheral_sensor_part = true + sensor_default_defines += [ "HAS_HDI_SENSOR_LITE_PRAT" ] +} else { + has_drivers_peripheral_sensor_part = false +} diff --git a/services/BUILD.gn b/services/BUILD.gn old mode 100644 new mode 100755 index a70fa4c7ca6d2af7511b4c1f0c4a7f64b760484b..8fb43ab4ea714a14c45487d2928589a53161c26f --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/lite/config/component/lite_component.gni") +import("../sensor_lite.gni") executable("sensor_service") { sources = [ @@ -32,13 +33,18 @@ executable("sensor_service") { "//foundation/communication/ipc/interfaces/innerkits/c/ipc/include", "//foundation/communication/ipc/ipc/native/c/manager/include", "//foundation/communication/ipc/services/dbinder/c/include", - "//drivers/peripheral/sensor/interfaces/include", "//base/sensors/sensor_lite/frameworks/include", ] + defines = sensor_default_defines + deps = [ - "//drivers/peripheral/sensor/hal:hdi_sensor", "//foundation/communication/ipc/interfaces/innerkits/c/ipc:ipc_single", "//foundation/systemabilitymgr/samgr_lite/samgr:samgr", ] + + if (has_drivers_peripheral_sensor_part) { + deps += [ "//drivers/peripheral/sensor/hal:hdi_sensor" ] + include_dirs += [ "//drivers/peripheral/sensor/interfaces/include" ] + } } diff --git a/services/src/sensor_service.c b/services/src/sensor_service.c old mode 100644 new mode 100755 diff --git a/services/src/sensor_service_impl.c b/services/src/sensor_service_impl.c index 2477b38b9ae79678a0e31986af279167509510b5..f3f7cb80d41d5efa7b3812f0735dd59e50f16247 100644 --- a/services/src/sensor_service_impl.c +++ b/services/src/sensor_service_impl.c @@ -33,6 +33,7 @@ static SvcIdentity g_svcIdentity = { int32_t InitSensorList() { HILOG_DEBUG(HILOG_MODULE_APP, "[SERVICE:%s]: %s begin", SENSOR_SERVICE, __func__); +#ifdef HAS_HDI_SENSOR_LITE_PRAT if (g_sensorDevice == NULL) { HILOG_ERROR(HILOG_MODULE_APP, "[SERVICE:%s]: %s g_sensorDevice is NULL", SENSOR_SERVICE, __func__); @@ -44,6 +45,7 @@ int32_t InitSensorList() SENSOR_SERVICE, __func__, ret); return SENSOR_ERROR_INVALID_PARAM; } +#endif // HAS_HDI_SENSOR_LITE_PRAT return SENSOR_OK; } @@ -92,11 +94,13 @@ void SetSvcIdentity(IpcIo *req, const IpcIo *reply) BOOL Initialize(Service *service, Identity identity) { HILOG_DEBUG(HILOG_MODULE_APP, "[SERVICE:%s]: %s begin", SENSOR_SERVICE, __func__); +#ifdef HAS_HDI_SENSOR_LITE_PRAT g_sensorDevice = NewSensorInterfaceInstance(); if (g_sensorDevice == NULL) { HILOG_ERROR(HILOG_MODULE_APP, "[SERVICE:%s]: %s g_sensorDevice is NULL", SENSOR_SERVICE, __func__); } +#endif // HAS_HDI_SENSOR_LITE_PRAT return TRUE; } @@ -148,6 +152,7 @@ int32_t ActivateSensorImpl(int32_t sensorId, const SensorUser *user) SENSOR_SERVICE, __func__); return SENSOR_ERROR_INVALID_PARAM; } +#ifdef HAS_HDI_SENSOR_LITE_PRAT if (g_sensorDevice == NULL) { HILOG_ERROR(HILOG_MODULE_APP, "[SERVICE:%s]: %s g_sensorDevice is NULL", SENSOR_SERVICE, __func__); @@ -159,6 +164,7 @@ int32_t ActivateSensorImpl(int32_t sensorId, const SensorUser *user) SENSOR_SERVICE, __func__, ret); return ret; } +#endif // HAS_HDI_SENSOR_LITE_PRAT return SENSOR_OK; } @@ -176,6 +182,7 @@ int32_t DeactivateSensorImpl(int32_t sensorId, const SensorUser *user) SENSOR_SERVICE, __func__); return SENSOR_ERROR_INVALID_PARAM; } +#ifdef HAS_HDI_SENSOR_LITE_PRAT if (g_sensorDevice == NULL) { HILOG_ERROR(HILOG_MODULE_APP, "[SERVICE:%s]: %s g_sensorDevice is NULL", SENSOR_SERVICE, __func__); @@ -187,6 +194,7 @@ int32_t DeactivateSensorImpl(int32_t sensorId, const SensorUser *user) SENSOR_SERVICE, __func__, ret); return ret; } +#endif // HAS_HDI_SENSOR_LITE_PRAT return SENSOR_OK; } @@ -222,6 +230,7 @@ int32_t SubscribeSensorImpl(int32_t sensorId, const SensorUser *user) SENSOR_SERVICE, __func__); return SENSOR_ERROR_INVALID_PARAM; } +#ifdef HAS_HDI_SENSOR_LITE_PRAT if (g_sensorDevice == NULL) { HILOG_ERROR(HILOG_MODULE_APP, "[SERVICE:%s]: %s g_sensorDevice is NULL", SENSOR_SERVICE, __func__); @@ -233,6 +242,7 @@ int32_t SubscribeSensorImpl(int32_t sensorId, const SensorUser *user) SENSOR_SERVICE, __func__, ret); return SENSOR_ERROR_INVALID_PARAM; } +#endif // HAS_HDI_SENSOR_LITE_PRAT return SENSOR_OK; } @@ -250,6 +260,7 @@ int32_t UnsubscribeSensorImpl(int32_t sensorId, const SensorUser *user) SENSOR_SERVICE, __func__); return SENSOR_ERROR_INVALID_PARAM; } +#ifdef HAS_HDI_SENSOR_LITE_PRAT if (g_sensorDevice == NULL) { HILOG_ERROR(HILOG_MODULE_APP, "[SERVICE:%s]: %s g_sensorDevice is NULL", SENSOR_SERVICE, __func__); @@ -261,6 +272,7 @@ int32_t UnsubscribeSensorImpl(int32_t sensorId, const SensorUser *user) SENSOR_SERVICE, __func__, ret); return SENSOR_ERROR_INVALID_PARAM; } +#endif // HAS_HDI_SENSOR_LITE_PRAT return SENSOR_OK; }