From 3d2574388da95a06d896c5ba2bda61f78fd35202 Mon Sep 17 00:00:00 2001 From: hui1975 Date: Wed, 1 Feb 2023 02:27:13 +0000 Subject: [PATCH 1/2] sensor power frameworks Signed-off-by: hui1975 Change-Id: I67c6c877481b521a8ff7614c2424e57d9d2c29a7 --- .../native/sensor/include/i_sensor_service.h | 10 ++ .../sensor/include/i_sensor_status_callback.h | 37 ++++++ .../sensor/include/sensor_agent_proxy.h | 5 + .../sensor/include/sensor_service_client.h | 6 + .../sensor/include/sensor_service_proxy.h | 4 + .../native/sensor/src/sensor_agent_proxy.cpp | 73 +++++++++++ .../sensor/src/sensor_service_client.cpp | 63 ++++++++++ .../sensor/src/sensor_service_proxy.cpp | 115 ++++++++++++++++++ .../src/sensor_status_callback_stub.cpp | 64 ++++++++++ 9 files changed, 377 insertions(+) create mode 100644 frameworks/native/sensor/include/i_sensor_status_callback.h create mode 100644 frameworks/native/sensor/src/sensor_status_callback_stub.cpp diff --git a/frameworks/native/sensor/include/i_sensor_service.h b/frameworks/native/sensor/include/i_sensor_service.h index e4400ba5..f578ac51 100755 --- a/frameworks/native/sensor/include/i_sensor_service.h +++ b/frameworks/native/sensor/include/i_sensor_service.h @@ -21,7 +21,9 @@ #include "errors.h" #include "iremote_broker.h" +#include "app_sensor.h" #include "i_sensor_client.h" +#include "i_sensor_status_callback.h" #include "sensor_basic_data_channel.h" #include "sensor.h" @@ -39,6 +41,10 @@ public: virtual ErrCode TransferDataChannel(const sptr &sensorBasicDataChannel, const sptr &sensorClient) = 0; virtual ErrCode DestroySensorChannel(sptr sensorClient) = 0; + virtual ErrCode SuspendSensors(int32_t pid) = 0; + virtual ErrCode ResumeSensors(int32_t pid) = 0; + virtual std::vector GetAppSensorList(int32_t pid) = 0; + virtual ErrCode RegisterCallback(sptr callback) = 0; enum { ENABLE_SENSOR = 0, DISABLE_SENSOR, @@ -47,6 +53,10 @@ public: GET_SENSOR_LIST, TRANSFER_DATA_CHANNEL, DESTROY_SENSOR_CHANNEL, + SUSPEND_SENSORS, + RESUME_SENSORS, + GET_APP_SENSOR_LIST, + REGISTER_CALLBACK, }; }; } // namespace Sensors diff --git a/frameworks/native/sensor/include/i_sensor_status_callback.h b/frameworks/native/sensor/include/i_sensor_status_callback.h new file mode 100644 index 00000000..275175f8 --- /dev/null +++ b/frameworks/native/sensor/include/i_sensor_status_callback.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021 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. + */ + +#ifndef I_SENSOR_STATUS_CALLBACK_H +#define I_SENSOR_STATUS_CALLBACK_H + +#include "iremote_broker.h" + +#include "sensor_agent_type.h" + +namespace OHOS { +namespace Sensors { +class ISensorStatusCallback : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.sensors.ISensorStatusCallback"); + + virtual void OnSensorChanged(const AppSensorInfo &appSensorInfo) = 0; + + enum { + SENSOR_CHANGE = 0, + }; +}; +} // namespace Sensors +} // namespace OHOS +#endif // I_SENSOR_STATUS_CALLBACK_H diff --git a/frameworks/native/sensor/include/sensor_agent_proxy.h b/frameworks/native/sensor/include/sensor_agent_proxy.h index a14ea60d..ec059ab7 100644 --- a/frameworks/native/sensor/include/sensor_agent_proxy.h +++ b/frameworks/native/sensor/include/sensor_agent_proxy.h @@ -21,6 +21,7 @@ #include "refbase.h" +#include "i_sensor_status_callback.h" #include "sensor_agent_type.h" #include "sensor_data_channel.h" @@ -43,6 +44,10 @@ public: int32_t SetMode(int32_t sensorId, const SensorUser *user, int32_t mode) const; int32_t SetOption(int32_t sensorId, const SensorUser *user, int32_t option) const; int32_t GetAllSensors(SensorInfo **sensorInfo, int32_t *count) const; + int32_t SuspendSensors(int32_t pid) const; + int32_t ResumeSensors(int32_t pid) const; + int32_t GetAppSensors(int32_t pid, AppSensorInfo **appSensorInfos, int32_t *count) const; + int32_t RegisterCallback(sptr callback) const; private: int32_t CreateSensorDataChannel() const; diff --git a/frameworks/native/sensor/include/sensor_service_client.h b/frameworks/native/sensor/include/sensor_service_client.h index 40b4d78d..dc6852e0 100755 --- a/frameworks/native/sensor/include/sensor_service_client.h +++ b/frameworks/native/sensor/include/sensor_service_client.h @@ -22,6 +22,8 @@ #include "iservice_registry.h" #include "singleton.h" +#include "app_sensor.h" +#include "i_sensor_status_callback.h" #include "sensor_agent_type.h" #include "sensor_basic_data_channel.h" #include "sensor_basic_info.h" @@ -42,6 +44,10 @@ public: int32_t DestroyDataChannel(); void ProcessDeathObserver(const wptr &object); bool IsValid(uint32_t sensorId); + int32_t SuspendSensors(int32_t pid); + int32_t ResumeSensors(int32_t pid); + std::vector GetAppSensorList(int32_t pid); + int32_t RegisterCallback(sptr callback); private: int32_t InitServiceClient(); diff --git a/frameworks/native/sensor/include/sensor_service_proxy.h b/frameworks/native/sensor/include/sensor_service_proxy.h index 70a43eca..90d8d392 100755 --- a/frameworks/native/sensor/include/sensor_service_proxy.h +++ b/frameworks/native/sensor/include/sensor_service_proxy.h @@ -35,6 +35,10 @@ public: ErrCode TransferDataChannel(const sptr &sensorBasicDataChannel, const sptr &sensorClient) override; ErrCode DestroySensorChannel(sptr sensorClient) override; + ErrCode SuspendSensors(int32_t pid) override; + ErrCode ResumeSensors(int32_t pid) override; + std::vector GetAppSensorList(int32_t pid) override; + ErrCode RegisterCallback(sptr callback) override; private: DISALLOW_COPY_AND_MOVE(SensorServiceProxy); diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index 3791a1b9..3ea99ae7 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -331,5 +331,78 @@ int32_t SensorAgentProxy::GetAllSensors(SensorInfo **sensorInfo, int32_t *count) *count = sensorInfoCount_; return SUCCESS; } + +int32_t SensorAgentProxy::SuspendSensors(int32_t pid) const +{ + CALL_LOG_ENTER; + if (pid < 0) { + SEN_HILOGE("pid is invalid, %{public}d", pid); + return PARAMETER_ERROR; + } + int32_t ret = SenClient.SuspendSensors(pid); + if (ret != 0) { + SEN_HILOGE("Suspend pid sensors failed, ret:%{public}d", ret); + } + return ret; +} + +int32_t SensorAgentProxy::ResumeSensors(int32_t pid) const +{ + CALL_LOG_ENTER; + if (pid < 0) { + SEN_HILOGE("pid is invalid, %{public}d", pid); + return PARAMETER_ERROR; + } + int32_t ret = SenClient.ResumeSensors(pid); + if (ret != 0) { + SEN_HILOGE("Resume pid sensors failed, ret:%{public}d", ret); + } + return ret; +} + +int32_t SensorAgentProxy::GetAppSensors(int32_t pid, AppSensorInfo **appSensorInfos, int32_t *count) const +{ + CALL_LOG_ENTER; + if (pid < 0) { + SEN_HILOGE("pid is invalid, %{public}d", pid); + return PARAMETER_ERROR; + } + CHKPR(appSensorInfos, OHOS::Sensors::ERROR); + CHKPR(count, OHOS::Sensors::ERROR); + std::vector appSensorList = SenClient.GetAppSensorList(pid); + if (appSensorList.empty()) { + SEN_HILOGE("get pid app sensor lists failed, pid:%{public}d", pid); + return ERROR; + } + size_t appSensorInfoCount = appSensorList.size(); + if (appSensorInfoCount > MAX_SENSOR_LIST_SIZE) { + SEN_HILOGE("The number of app sensors exceeds the maximum value"); + return ERROR; + } + AppSensorInfo *appSensor = (AppSensorInfo *)malloc(sizeof(AppSensorInfo) * appSensorInfoCount); + CHKPR(appSensor, ERROR); + for (size_t i = 0; i < appSensorInfoCount; ++i) { + AppSensorInfo *curAppSensor = appSensor + i; + curAppSensor->pid = appSensorList[i].pid; + curAppSensor->sensorId = appSensorList[i].sensorId; + curAppSensor->isActive = appSensorList[i].isActive; + curAppSensor->samplingPeriodNs = appSensorList[i].samplingPeriodNs; + curAppSensor->maxReportDelayNs = appSensorList[i].maxReportDelayNs; + } + *appSensorInfos = appSensor; + *count = static_cast(appSensorInfoCount); + return SUCCESS; +} + +int32_t SensorAgentProxy::RegisterCallback(sptr callback) const +{ + CALL_LOG_ENTER; + CHKPR(callback, OHOS::Sensors::ERROR); + int32_t ret = SenClient.RegisterCallback(callback); + if (ret != 0) { + SEN_HILOGE("Register sensor callback failed, ret:%{public}d", ret); + } + return ret; +} } // namespace Sensors } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/sensor/src/sensor_service_client.cpp b/frameworks/native/sensor/src/sensor_service_client.cpp index 3b7e30c7..544e7825 100755 --- a/frameworks/native/sensor/src/sensor_service_client.cpp +++ b/frameworks/native/sensor/src/sensor_service_client.cpp @@ -224,5 +224,68 @@ void SensorServiceClient::DeleteSensorInfoItem(uint32_t sensorId) } return; } + +int32_t SensorServiceClient::SuspendSensors(int32_t pid) +{ + CALL_LOG_ENTER; + int32_t ret = InitServiceClient(); + if (ret != ERR_OK) { + SEN_HILOGE("InitServiceClient failed, ret:%{public}d", ret); + return ret; + } + CHKPR(sensorServer_, ERROR); + StartTrace(HITRACE_TAG_SENSORS, "SuspendSensors"); + ret = sensorServer_->SuspendSensors(pid); + FinishTrace(HITRACE_TAG_SENSORS); + return ret; +} + +int32_t SensorServiceClient::ResumeSensors(int32_t pid) +{ + CALL_LOG_ENTER; + int32_t ret = InitServiceClient(); + if (ret != ERR_OK) { + SEN_HILOGE("InitServiceClient failed, ret:%{public}d", ret); + return ret; + } + CHKPR(sensorServer_, ERROR); + StartTrace(HITRACE_TAG_SENSORS, "ResumeSensors"); + ret = sensorServer_->ResumeSensors(pid); + FinishTrace(HITRACE_TAG_SENSORS); + return ret; +} + +std::vector SensorServiceClient::GetAppSensorList(int32_t pid) +{ + CALL_LOG_ENTER; + int32_t ret = InitServiceClient(); + if (ret != ERR_OK) { + SEN_HILOGE("InitServiceClient failed, ret:%{public}d", ret); + return {}; + } + if (sensorServer_ == nullptr) { + SEN_HILOGE("sensorServer_ is nullptr"); + return {}; + } + StartTrace(HITRACE_TAG_SENSORS, "GetAppSensorList"); + std::vector appSensorList = sensorServer_->GetAppSensorList(pid); + FinishTrace(HITRACE_TAG_SENSORS); + return appSensorList; +} + +int32_t SensorServiceClient::RegisterCallback(sptr callback) +{ + CALL_LOG_ENTER; + int32_t ret = InitServiceClient(); + if (ret != ERR_OK) { + SEN_HILOGE("InitServiceClient failed, ret:%{public}d", ret); + return ret; + } + CHKPR(sensorServer_, ERROR); + StartTrace(HITRACE_TAG_SENSORS, "RegisterCallback"); + ret = sensorServer_->RegisterCallback(callback); + FinishTrace(HITRACE_TAG_SENSORS); + return ret; +} } // namespace Sensors } // namespace OHOS diff --git a/frameworks/native/sensor/src/sensor_service_proxy.cpp b/frameworks/native/sensor/src/sensor_service_proxy.cpp index b04d2429..146ad3f8 100755 --- a/frameworks/native/sensor/src/sensor_service_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_service_proxy.cpp @@ -190,5 +190,120 @@ ErrCode SensorServiceProxy::DestroySensorChannel(sptr sensorClien } return static_cast(ret); } + +ErrCode SensorServiceProxy::SuspendSensors(int32_t pid) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(SensorServiceProxy::GetDescriptor())) { + SEN_HILOGE("write descriptor failed"); + return WRITE_MSG_ERR; + } + if (!data.WriteInt32(pid)) { + SEN_HILOGE("write pid failed"); + return WRITE_MSG_ERR; + } + sptr remote = Remote(); + CHKPR(remote, ERROR); + int32_t ret = remote->SendRequest(ISensorService::SUSPEND_SENSORS, data, reply, option); + if (ret != NO_ERROR) { + HiSysEventWrite(HiSysEvent::Domain::SENSOR, "SENSOR_SERVICE_IPC_EXCEPTION", + HiSysEvent::EventType::FAULT, "PKG_NAME", "SuspendSensors", "ERROR_CODE", ret); + SEN_HILOGE("failed, ret:%{public}d", ret); + } + return static_cast(ret); +} + +ErrCode SensorServiceProxy::ResumeSensors(int32_t pid) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(SensorServiceProxy::GetDescriptor())) { + SEN_HILOGE("write descriptor failed"); + return WRITE_MSG_ERR; + } + if (!data.WriteInt32(pid)) { + SEN_HILOGE("write pid failed"); + return WRITE_MSG_ERR; + } + sptr remote = Remote(); + CHKPR(remote, ERROR); + int32_t ret = remote->SendRequest(ISensorService::RESUME_SENSORS, data, reply, option); + if (ret != NO_ERROR) { + HiSysEventWrite(HiSysEvent::Domain::SENSOR, "SENSOR_SERVICE_IPC_EXCEPTION", + HiSysEvent::EventType::FAULT, "PKG_NAME", "ResumeSensors", "ERROR_CODE", ret); + SEN_HILOGE("failed, ret:%{public}d", ret); + } + return static_cast(ret); +} + +std::vector SensorServiceProxy::GetAppSensorList(int32_t pid) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + std::vector appSensors; + if (!data.WriteInterfaceToken(SensorServiceProxy::GetDescriptor())) { + SEN_HILOGE("write descriptor failed"); + return appSensors; + } + if (!data.WriteInt32(pid)) { + SEN_HILOGE("write pid failed"); + return appSensors; + } + sptr remote = Remote(); + if (remote == nullptr) { + SEN_HILOGE("remote is null"); + return appSensors; + } + int32_t ret = remote->SendRequest(ISensorService::GET_APP_SENSOR_LIST, data, reply, option); + if (ret != NO_ERROR) { + HiSysEventWrite(HiSysEvent::Domain::SENSOR, "SENSOR_SERVICE_IPC_EXCEPTION", + HiSysEvent::EventType::FAULT, "PKG_NAME", "GetAppSensorList", "ERROR_CODE", ret); + SEN_HILOGE("failed, ret:%{public}d", ret); + return appSensors; + } + int32_t appSensorCount; + if (!reply.ReadInt32(appSensorCount)) { + SEN_HILOGE("Parcel read appSensorCount failed"); + return appSensors; + } + SEN_HILOGD("appSensorCount:%{public}d", appSensorCount); + AppSensor appSensor; + for (int32_t i = 0; i < appSensorCount; i++) { + auto tmpAppSensor = appSensor.Unmarshalling(reply); + if (tmpAppSensor == nullptr) { + continue; + } + appSensors.push_back(*tmpAppSensor); + } + return appSensors; +} + +ErrCode SensorServiceProxy::RegisterCallback(sptr callback) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(SensorServiceProxy::GetDescriptor())) { + SEN_HILOGE("write descriptor failed"); + return WRITE_MSG_ERR; + } + if (!data.WriteRemoteObject(callback->AsObject())) { + SEN_HILOGE("write callback failed"); + return WRITE_MSG_ERR; + } + sptr remote = Remote(); + CHKPR(remote, ERROR); + int32_t ret = remote->SendRequest(ISensorService::REGISTER_CALLBACK, data, reply, option); + if (ret != NO_ERROR) { + HiSysEventWrite(HiSysEvent::Domain::SENSOR, "SENSOR_SERVICE_IPC_EXCEPTION", + HiSysEvent::EventType::FAULT, "PKG_NAME", "RegisterCallback", "ERROR_CODE", ret); + SEN_HILOGE("failed, ret:%{public}d", ret); + } + return static_cast(ret); +} } // namespace Sensors } // namespace OHOS diff --git a/frameworks/native/sensor/src/sensor_status_callback_stub.cpp b/frameworks/native/sensor/src/sensor_status_callback_stub.cpp new file mode 100644 index 00000000..d7288a22 --- /dev/null +++ b/frameworks/native/sensor/src/sensor_status_callback_stub.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2021 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. + */ + +#include "sensor_status_callback_stub.h" + +#include "hisysevent.h" +#include "message_parcel.h" + +#include "sensors_errors.h" + +namespace OHOS { +namespace Sensors { +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, SENSOR_LOG_DOMAIN, "SensorStatusCallbackStub" }; +} // namespace + +int32_t SensorStatusCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) +{ + SEN_HILOGD("begin, cmd:%{public}u, flags:%{public}d", code, option.GetFlags()); + std::u16string descriptor = SensorStatusCallbackStub::GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (descriptor != remoteDescriptor) { + SEN_HILOGE("SensorStatusCallbackStub::OnRemoteRequest failed, descriptor mismatch"); + return OBJECT_NULL; + } + int32_t msgCode = static_cast(code); + if (msgCode == ISensorStatusCallback::SENSOR_CHANGE) { + int32_t pid; + int32_t sensorId; + bool isActive; + int64_t samplingPeriodNs; + int64_t maxReportDelayNs; + if ((!data.ReadInt32(pid)) || (!data.ReadInt32(sensorId)) || (!data.ReadBool(isActive)) || + (!data.ReadInt64(samplingPeriodNs)) || (!data.ReadInt64(maxReportDelayNs))) { + SEN_HILOGE("Parcel read failed"); + return ERROR; + } + AppSensorInfo appSensorInfo; + appSensorInfo.pid = pid; + appSensorInfo.sensorId = sensorId; + appSensorInfo.isActive = isActive; + appSensorInfo.samplingPeriodNs = samplingPeriodNs; + appSensorInfo.maxReportDelayNs = maxReportDelayNs; + OnSensorChanged(appSensorInfo); + } else { + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + return NO_ERROR; +} +} // namespace Sensors +} // namespace OHOS -- Gitee From eabb6502dc6d3a2e1ea15e0ebcb915f80206f066 Mon Sep 17 00:00:00 2001 From: hui1975 Date: Mon, 6 Feb 2023 12:24:40 +0000 Subject: [PATCH 2/2] fix review comments Signed-off-by: hui1975 Change-Id: Ib05ec9ca6a2f5a42a0d92665e83458a9d845bab1 --- .../native/sensor/include/i_sensor_service.h | 8 +- .../sensor/include/i_sensor_status_callback.h | 6 +- .../sensor/include/sensor_agent_proxy.h | 2 +- .../sensor/include/sensor_service_client.h | 16 ++-- .../sensor/include/sensor_service_proxy.h | 8 +- .../native/sensor/src/sensor_agent_proxy.cpp | 39 +++++++--- .../sensor/src/sensor_service_client.cpp | 26 +++---- .../sensor/src/sensor_service_proxy.cpp | 74 +++++++++---------- .../src/sensor_status_callback_stub.cpp | 42 +++++------ 9 files changed, 112 insertions(+), 109 deletions(-) diff --git a/frameworks/native/sensor/include/i_sensor_service.h b/frameworks/native/sensor/include/i_sensor_service.h index f578ac51..1fa19127 100755 --- a/frameworks/native/sensor/include/i_sensor_service.h +++ b/frameworks/native/sensor/include/i_sensor_service.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -34,16 +34,16 @@ public: ISensorService() = default; virtual ~ISensorService() = default; DECLARE_INTERFACE_DESCRIPTOR(u"ISensorService"); - virtual ErrCode EnableSensor(uint32_t sensorId, int64_t samplingPeriodNs, + virtual ErrCode EnableSensor(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs) = 0; - virtual ErrCode DisableSensor(uint32_t sensorId) = 0; + virtual ErrCode DisableSensor(int32_t sensorId) = 0; virtual std::vector GetSensorList() = 0; virtual ErrCode TransferDataChannel(const sptr &sensorBasicDataChannel, const sptr &sensorClient) = 0; virtual ErrCode DestroySensorChannel(sptr sensorClient) = 0; virtual ErrCode SuspendSensors(int32_t pid) = 0; virtual ErrCode ResumeSensors(int32_t pid) = 0; - virtual std::vector GetAppSensorList(int32_t pid) = 0; + virtual ErrCode GetAppSensorList(int32_t pid, std::vector &appSensorList) = 0; virtual ErrCode RegisterCallback(sptr callback) = 0; enum { ENABLE_SENSOR = 0, diff --git a/frameworks/native/sensor/include/i_sensor_status_callback.h b/frameworks/native/sensor/include/i_sensor_status_callback.h index 275175f8..98d40bec 100644 --- a/frameworks/native/sensor/include/i_sensor_status_callback.h +++ b/frameworks/native/sensor/include/i_sensor_status_callback.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 @@ -25,10 +25,8 @@ namespace Sensors { class ISensorStatusCallback : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.sensors.ISensorStatusCallback"); - virtual void OnSensorChanged(const AppSensorInfo &appSensorInfo) = 0; - - enum { + enum : uint32_t { SENSOR_CHANGE = 0, }; }; diff --git a/frameworks/native/sensor/include/sensor_agent_proxy.h b/frameworks/native/sensor/include/sensor_agent_proxy.h index ec059ab7..f799fb71 100644 --- a/frameworks/native/sensor/include/sensor_agent_proxy.h +++ b/frameworks/native/sensor/include/sensor_agent_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 diff --git a/frameworks/native/sensor/include/sensor_service_client.h b/frameworks/native/sensor/include/sensor_service_client.h index dc6852e0..414ca74a 100755 --- a/frameworks/native/sensor/include/sensor_service_client.h +++ b/frameworks/native/sensor/include/sensor_service_client.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -38,21 +38,21 @@ namespace Sensors { class SensorServiceClient : public Singleton { public: std::vector GetSensorList(); - int32_t EnableSensor(uint32_t sensorId, int64_t samplingPeriod, int64_t maxReportDelay); - int32_t DisableSensor(uint32_t sensorId); + int32_t EnableSensor(int32_t sensorId, int64_t samplingPeriod, int64_t maxReportDelay); + int32_t DisableSensor(int32_t sensorId); int32_t TransferDataChannel(sptr sensorDataChannel); int32_t DestroyDataChannel(); void ProcessDeathObserver(const wptr &object); - bool IsValid(uint32_t sensorId); + bool IsValid(int32_t sensorId); int32_t SuspendSensors(int32_t pid); int32_t ResumeSensors(int32_t pid); - std::vector GetAppSensorList(int32_t pid); + int32_t GetAppSensorList(int32_t pid, std::vector &appSensorList); int32_t RegisterCallback(sptr callback); private: int32_t InitServiceClient(); - void UpdateSensorInfoMap(uint32_t sensorId, int64_t samplingPeriod, int64_t maxReportDelay); - void DeleteSensorInfoItem(uint32_t sensorId); + void UpdateSensorInfoMap(int32_t sensorId, int64_t samplingPeriod, int64_t maxReportDelay); + void DeleteSensorInfoItem(int32_t sensorId); std::mutex clientMutex_; sptr serviceDeathObserver_; sptr sensorServer_; @@ -60,7 +60,7 @@ private: sptr dataChannel_; sptr sensorClientStub_; std::mutex mapMutex_; - std::map sensorInfoMap_; + std::map sensorInfoMap_; }; } // namespace Sensors } // namespace OHOS diff --git a/frameworks/native/sensor/include/sensor_service_proxy.h b/frameworks/native/sensor/include/sensor_service_proxy.h index 90d8d392..ed9a90f3 100755 --- a/frameworks/native/sensor/include/sensor_service_proxy.h +++ b/frameworks/native/sensor/include/sensor_service_proxy.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -29,15 +29,15 @@ class SensorServiceProxy : public IRemoteProxy { public: explicit SensorServiceProxy(const sptr &impl); virtual ~SensorServiceProxy() = default; - ErrCode EnableSensor(uint32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs) override; - ErrCode DisableSensor(uint32_t sensorId) override; + ErrCode EnableSensor(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs) override; + ErrCode DisableSensor(int32_t sensorId) override; std::vector GetSensorList() override; ErrCode TransferDataChannel(const sptr &sensorBasicDataChannel, const sptr &sensorClient) override; ErrCode DestroySensorChannel(sptr sensorClient) override; ErrCode SuspendSensors(int32_t pid) override; ErrCode ResumeSensors(int32_t pid) override; - std::vector GetAppSensorList(int32_t pid) override; + ErrCode GetAppSensorList(int32_t pid, std::vector &appSensorList) override; ErrCode RegisterCallback(sptr callback) override; private: diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index 3ea99ae7..e373ea08 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -18,7 +18,6 @@ #include #include "securec.h" -#include "sensor_catalog.h" #include "sensor_service_client.h" #include "sensors_errors.h" @@ -39,6 +38,8 @@ std::recursive_mutex SensorAgentProxy::subscribeMutex_; std::mutex SensorAgentProxy::chanelMutex_; std::mutex sensorInfoMutex_; SensorInfo *sensorInfos_ = nullptr; +std::mutex appSensorInfoMutex_; +AppSensorInfo *appSensorInfo_ = nullptr; int32_t sensorInfoCount_ = 0; std::map SensorAgentProxy::g_subscribeMap; std::map SensorAgentProxy::g_unsubscribeMap; @@ -267,6 +268,10 @@ int32_t SensorAgentProxy::SetMode(int32_t sensorId, const SensorUser *user, int3 void SensorAgentProxy::ClearSensorInfos() const { + if (appSensorInfo_ != nullptr) { + free(appSensorInfo_); + appSensorInfo_ = nullptr; + } CHKPV(sensorInfos_); free(sensorInfos_); sensorInfos_ = nullptr; @@ -336,7 +341,7 @@ int32_t SensorAgentProxy::SuspendSensors(int32_t pid) const { CALL_LOG_ENTER; if (pid < 0) { - SEN_HILOGE("pid is invalid, %{public}d", pid); + SEN_HILOGE("Pid is invalid, %{public}d", pid); return PARAMETER_ERROR; } int32_t ret = SenClient.SuspendSensors(pid); @@ -350,7 +355,7 @@ int32_t SensorAgentProxy::ResumeSensors(int32_t pid) const { CALL_LOG_ENTER; if (pid < 0) { - SEN_HILOGE("pid is invalid, %{public}d", pid); + SEN_HILOGE("Pid is invalid, %{public}d", pid); return PARAMETER_ERROR; } int32_t ret = SenClient.ResumeSensors(pid); @@ -364,32 +369,42 @@ int32_t SensorAgentProxy::GetAppSensors(int32_t pid, AppSensorInfo **appSensorIn { CALL_LOG_ENTER; if (pid < 0) { - SEN_HILOGE("pid is invalid, %{public}d", pid); + SEN_HILOGE("Pid is invalid, %{public}d", pid); return PARAMETER_ERROR; } CHKPR(appSensorInfos, OHOS::Sensors::ERROR); CHKPR(count, OHOS::Sensors::ERROR); - std::vector appSensorList = SenClient.GetAppSensorList(pid); + std::lock_guard appSensorInfoLock(appSensorInfoMutex_); + if (appSensorInfo_ != nullptr) { + free(appSensorInfo_); + appSensorInfo_ = nullptr; + } + std::vector appSensorList; + int32_t ret = SenClient.GetAppSensorList(pid, appSensorList); + if (ret != 0) { + SEN_HILOGE("Get app sensor list failed, ret:%{public}d", ret); + return ERROR; + } if (appSensorList.empty()) { - SEN_HILOGE("get pid app sensor lists failed, pid:%{public}d", pid); + SEN_HILOGE("App sensor list is empty, pid:%{public}d", pid); return ERROR; } size_t appSensorInfoCount = appSensorList.size(); if (appSensorInfoCount > MAX_SENSOR_LIST_SIZE) { - SEN_HILOGE("The number of app sensors exceeds the maximum value"); + SEN_HILOGE("The number of app sensors exceeds the maximum value, count:%{public}d", appSensorInfoCount); return ERROR; } - AppSensorInfo *appSensor = (AppSensorInfo *)malloc(sizeof(AppSensorInfo) * appSensorInfoCount); - CHKPR(appSensor, ERROR); + appSensorInfo_ = (AppSensorInfo *)malloc(sizeof(AppSensorInfo) * appSensorInfoCount); + CHKPR(appSensorInfo_, ERROR); for (size_t i = 0; i < appSensorInfoCount; ++i) { - AppSensorInfo *curAppSensor = appSensor + i; + AppSensorInfo *curAppSensor = appSensorInfo_ + i; curAppSensor->pid = appSensorList[i].pid; curAppSensor->sensorId = appSensorList[i].sensorId; curAppSensor->isActive = appSensorList[i].isActive; curAppSensor->samplingPeriodNs = appSensorList[i].samplingPeriodNs; curAppSensor->maxReportDelayNs = appSensorList[i].maxReportDelayNs; } - *appSensorInfos = appSensor; + *appSensorInfos = appSensorInfo_; *count = static_cast(appSensorInfoCount); return SUCCESS; } diff --git a/frameworks/native/sensor/src/sensor_service_client.cpp b/frameworks/native/sensor/src/sensor_service_client.cpp index 544e7825..02865dfb 100755 --- a/frameworks/native/sensor/src/sensor_service_client.cpp +++ b/frameworks/native/sensor/src/sensor_service_client.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -73,7 +73,7 @@ int32_t SensorServiceClient::InitServiceClient() return SENSOR_NATIVE_GET_SERVICE_ERR; } -bool SensorServiceClient::IsValid(uint32_t sensorId) +bool SensorServiceClient::IsValid(int32_t sensorId) { int32_t ret = InitServiceClient(); if (ret != ERR_OK) { @@ -92,7 +92,7 @@ bool SensorServiceClient::IsValid(uint32_t sensorId) return false; } -int32_t SensorServiceClient::EnableSensor(uint32_t sensorId, int64_t samplingPeriod, int64_t maxReportDelay) +int32_t SensorServiceClient::EnableSensor(int32_t sensorId, int64_t samplingPeriod, int64_t maxReportDelay) { CALL_LOG_ENTER; int32_t ret = InitServiceClient(); @@ -110,7 +110,7 @@ int32_t SensorServiceClient::EnableSensor(uint32_t sensorId, int64_t samplingPer return ret; } -int32_t SensorServiceClient::DisableSensor(uint32_t sensorId) +int32_t SensorServiceClient::DisableSensor(int32_t sensorId) { CALL_LOG_ENTER; int32_t ret = InitServiceClient(); @@ -202,7 +202,7 @@ void SensorServiceClient::ProcessDeathObserver(const wptr &object } } -void SensorServiceClient::UpdateSensorInfoMap(uint32_t sensorId, int64_t samplingPeriod, int64_t maxReportDelay) +void SensorServiceClient::UpdateSensorInfoMap(int32_t sensorId, int64_t samplingPeriod, int64_t maxReportDelay) { CALL_LOG_ENTER; std::lock_guard mapLock(mapMutex_); @@ -214,7 +214,7 @@ void SensorServiceClient::UpdateSensorInfoMap(uint32_t sensorId, int64_t samplin return; } -void SensorServiceClient::DeleteSensorInfoItem(uint32_t sensorId) +void SensorServiceClient::DeleteSensorInfoItem(int32_t sensorId) { CALL_LOG_ENTER; std::lock_guard mapLock(mapMutex_); @@ -254,23 +254,19 @@ int32_t SensorServiceClient::ResumeSensors(int32_t pid) FinishTrace(HITRACE_TAG_SENSORS); return ret; } - -std::vector SensorServiceClient::GetAppSensorList(int32_t pid) +int32_t SensorServiceClient::GetAppSensorList(int32_t pid, std::vector &appSensorList) { CALL_LOG_ENTER; int32_t ret = InitServiceClient(); if (ret != ERR_OK) { SEN_HILOGE("InitServiceClient failed, ret:%{public}d", ret); - return {}; - } - if (sensorServer_ == nullptr) { - SEN_HILOGE("sensorServer_ is nullptr"); - return {}; + return ret; } + CHKPR(sensorServer_, ERROR); StartTrace(HITRACE_TAG_SENSORS, "GetAppSensorList"); - std::vector appSensorList = sensorServer_->GetAppSensorList(pid); + ret = sensorServer_->GetAppSensorList(pid, appSensorList); FinishTrace(HITRACE_TAG_SENSORS); - return appSensorList; + return ret; } int32_t SensorServiceClient::RegisterCallback(sptr callback) diff --git a/frameworks/native/sensor/src/sensor_service_proxy.cpp b/frameworks/native/sensor/src/sensor_service_proxy.cpp index 146ad3f8..8c6a46f2 100755 --- a/frameworks/native/sensor/src/sensor_service_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_service_proxy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -39,7 +39,7 @@ enum { SensorServiceProxy::SensorServiceProxy(const sptr &impl) : IRemoteProxy(impl) {} -ErrCode SensorServiceProxy::EnableSensor(uint32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs) +ErrCode SensorServiceProxy::EnableSensor(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs) { MessageParcel data; MessageParcel reply; @@ -48,7 +48,7 @@ ErrCode SensorServiceProxy::EnableSensor(uint32_t sensorId, int64_t samplingPeri SEN_HILOGE("write descriptor failed"); return WRITE_MSG_ERR; } - if (!data.WriteUint32(sensorId)) { + if (!data.WriteInt32(sensorId)) { SEN_HILOGE("write sensorId failed"); return WRITE_MSG_ERR; } @@ -71,7 +71,7 @@ ErrCode SensorServiceProxy::EnableSensor(uint32_t sensorId, int64_t samplingPeri return static_cast(ret); } -ErrCode SensorServiceProxy::DisableSensor(uint32_t sensorId) +ErrCode SensorServiceProxy::DisableSensor(int32_t sensorId) { MessageParcel data; MessageParcel reply; @@ -80,7 +80,7 @@ ErrCode SensorServiceProxy::DisableSensor(uint32_t sensorId) SEN_HILOGE("write descriptor failed"); return WRITE_MSG_ERR; } - if (!data.WriteUint32(sensorId)) { + if (!data.WriteInt32(sensorId)) { SEN_HILOGE("write sensorId failed"); return WRITE_MSG_ERR; } @@ -194,23 +194,23 @@ ErrCode SensorServiceProxy::DestroySensorChannel(sptr sensorClien ErrCode SensorServiceProxy::SuspendSensors(int32_t pid) { MessageParcel data; - MessageParcel reply; - MessageOption option; if (!data.WriteInterfaceToken(SensorServiceProxy::GetDescriptor())) { - SEN_HILOGE("write descriptor failed"); + SEN_HILOGE("Write descriptor failed"); return WRITE_MSG_ERR; } if (!data.WriteInt32(pid)) { - SEN_HILOGE("write pid failed"); + SEN_HILOGE("Write pid failed"); return WRITE_MSG_ERR; } sptr remote = Remote(); CHKPR(remote, ERROR); + MessageParcel reply; + MessageOption option; int32_t ret = remote->SendRequest(ISensorService::SUSPEND_SENSORS, data, reply, option); if (ret != NO_ERROR) { HiSysEventWrite(HiSysEvent::Domain::SENSOR, "SENSOR_SERVICE_IPC_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "SuspendSensors", "ERROR_CODE", ret); - SEN_HILOGE("failed, ret:%{public}d", ret); + SEN_HILOGE("Failed, ret:%{public}d", ret); } return static_cast(ret); } @@ -218,90 +218,86 @@ ErrCode SensorServiceProxy::SuspendSensors(int32_t pid) ErrCode SensorServiceProxy::ResumeSensors(int32_t pid) { MessageParcel data; - MessageParcel reply; - MessageOption option; if (!data.WriteInterfaceToken(SensorServiceProxy::GetDescriptor())) { - SEN_HILOGE("write descriptor failed"); + SEN_HILOGE("Write descriptor failed"); return WRITE_MSG_ERR; } if (!data.WriteInt32(pid)) { - SEN_HILOGE("write pid failed"); + SEN_HILOGE("Write pid failed"); return WRITE_MSG_ERR; } sptr remote = Remote(); CHKPR(remote, ERROR); + MessageParcel reply; + MessageOption option; int32_t ret = remote->SendRequest(ISensorService::RESUME_SENSORS, data, reply, option); if (ret != NO_ERROR) { HiSysEventWrite(HiSysEvent::Domain::SENSOR, "SENSOR_SERVICE_IPC_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "ResumeSensors", "ERROR_CODE", ret); - SEN_HILOGE("failed, ret:%{public}d", ret); + SEN_HILOGE("Failed, ret:%{public}d", ret); } return static_cast(ret); } -std::vector SensorServiceProxy::GetAppSensorList(int32_t pid) +ErrCode SensorServiceProxy::GetAppSensorList(int32_t pid, std::vector &appSensorList) { MessageParcel data; - MessageParcel reply; - MessageOption option; - std::vector appSensors; if (!data.WriteInterfaceToken(SensorServiceProxy::GetDescriptor())) { - SEN_HILOGE("write descriptor failed"); - return appSensors; + SEN_HILOGE("Write descriptor failed"); + return WRITE_MSG_ERR; } if (!data.WriteInt32(pid)) { - SEN_HILOGE("write pid failed"); - return appSensors; + SEN_HILOGE("Write pid failed"); + return WRITE_MSG_ERR; } sptr remote = Remote(); - if (remote == nullptr) { - SEN_HILOGE("remote is null"); - return appSensors; - } + CHKPR(remote, ERROR); + MessageParcel reply; + MessageOption option; int32_t ret = remote->SendRequest(ISensorService::GET_APP_SENSOR_LIST, data, reply, option); if (ret != NO_ERROR) { HiSysEventWrite(HiSysEvent::Domain::SENSOR, "SENSOR_SERVICE_IPC_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "GetAppSensorList", "ERROR_CODE", ret); - SEN_HILOGE("failed, ret:%{public}d", ret); - return appSensors; + SEN_HILOGE("Failed, ret:%{public}d", ret); + return static_cast(ret); } int32_t appSensorCount; if (!reply.ReadInt32(appSensorCount)) { SEN_HILOGE("Parcel read appSensorCount failed"); - return appSensors; + return READ_MSG_ERR; } - SEN_HILOGD("appSensorCount:%{public}d", appSensorCount); AppSensor appSensor; - for (int32_t i = 0; i < appSensorCount; i++) { + for (int32_t i = 0; i < appSensorCount; ++i) { auto tmpAppSensor = appSensor.Unmarshalling(reply); if (tmpAppSensor == nullptr) { + SEN_HILOGE("Current appSensor is nullptr, i:%{public}d", i); continue; } - appSensors.push_back(*tmpAppSensor); + appSensorList.push_back(*tmpAppSensor); } - return appSensors; + return static_cast(ret); } ErrCode SensorServiceProxy::RegisterCallback(sptr callback) { MessageParcel data; - MessageParcel reply; - MessageOption option; if (!data.WriteInterfaceToken(SensorServiceProxy::GetDescriptor())) { - SEN_HILOGE("write descriptor failed"); + SEN_HILOGE("Write descriptor failed"); return WRITE_MSG_ERR; } if (!data.WriteRemoteObject(callback->AsObject())) { - SEN_HILOGE("write callback failed"); + SEN_HILOGE("Write callback failed"); return WRITE_MSG_ERR; } sptr remote = Remote(); CHKPR(remote, ERROR); + MessageParcel reply; + MessageOption option; int32_t ret = remote->SendRequest(ISensorService::REGISTER_CALLBACK, data, reply, option); if (ret != NO_ERROR) { HiSysEventWrite(HiSysEvent::Domain::SENSOR, "SENSOR_SERVICE_IPC_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "RegisterCallback", "ERROR_CODE", ret); - SEN_HILOGE("failed, ret:%{public}d", ret); + SEN_HILOGE("Failed, ret:%{public}d", ret); } return static_cast(ret); } diff --git a/frameworks/native/sensor/src/sensor_status_callback_stub.cpp b/frameworks/native/sensor/src/sensor_status_callback_stub.cpp index d7288a22..663a375b 100644 --- a/frameworks/native/sensor/src/sensor_status_callback_stub.cpp +++ b/frameworks/native/sensor/src/sensor_status_callback_stub.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * 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 @@ -29,35 +29,33 @@ constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, SENSOR_LOG_DOMAIN, "Se int32_t SensorStatusCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - SEN_HILOGD("begin, cmd:%{public}u, flags:%{public}d", code, option.GetFlags()); + SEN_HILOGD("Begin, cmd:%{public}u, flags:%{public}d", code, option.GetFlags()); std::u16string descriptor = SensorStatusCallbackStub::GetDescriptor(); std::u16string remoteDescriptor = data.ReadInterfaceToken(); if (descriptor != remoteDescriptor) { SEN_HILOGE("SensorStatusCallbackStub::OnRemoteRequest failed, descriptor mismatch"); return OBJECT_NULL; } - int32_t msgCode = static_cast(code); - if (msgCode == ISensorStatusCallback::SENSOR_CHANGE) { - int32_t pid; - int32_t sensorId; - bool isActive; - int64_t samplingPeriodNs; - int64_t maxReportDelayNs; - if ((!data.ReadInt32(pid)) || (!data.ReadInt32(sensorId)) || (!data.ReadBool(isActive)) || - (!data.ReadInt64(samplingPeriodNs)) || (!data.ReadInt64(maxReportDelayNs))) { - SEN_HILOGE("Parcel read failed"); - return ERROR; - } - AppSensorInfo appSensorInfo; - appSensorInfo.pid = pid; - appSensorInfo.sensorId = sensorId; - appSensorInfo.isActive = isActive; - appSensorInfo.samplingPeriodNs = samplingPeriodNs; - appSensorInfo.maxReportDelayNs = maxReportDelayNs; - OnSensorChanged(appSensorInfo); - } else { + if (code != ISensorStatusCallback::SENSOR_CHANGE) { return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } + int32_t pid; + int32_t sensorId; + bool isActive; + int64_t samplingPeriodNs; + int64_t maxReportDelayNs; + if (!(data.ReadInt32(pid) && data.ReadInt32(sensorId) && data.ReadBool(isActive) && + data.ReadInt64(samplingPeriodNs) && data.ReadInt64(maxReportDelayNs))) { + SEN_HILOGE("Parcel read failed"); + return ERROR; + } + AppSensorInfo appSensorInfo; + appSensorInfo.pid = pid; + appSensorInfo.sensorId = sensorId; + appSensorInfo.isActive = isActive; + appSensorInfo.samplingPeriodNs = samplingPeriodNs; + appSensorInfo.maxReportDelayNs = maxReportDelayNs; + OnSensorChanged(appSensorInfo); return NO_ERROR; } } // namespace Sensors -- Gitee