From 5f73bca51172f820754cbdd5aec3948000c39409 Mon Sep 17 00:00:00 2001 From: shenpeixing Date: Thu, 2 Jan 2025 17:42:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0SetDisplayMode=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shenpeixing --- frameworks/native/include/i_sensor_service.h | 1 + .../native/include/sensor_agent_proxy.h | 1 + .../native/include/sensor_service_client.h | 1 + .../native/include/sensor_service_proxy.h | 1 + .../include/sensors_ipc_interface_code.h | 1 + frameworks/native/src/sensor_agent.cpp | 9 ++++++++ frameworks/native/src/sensor_agent_proxy.cpp | 9 ++++++++ .../native/src/sensor_service_client.cpp | 17 ++++++++++++++ .../native/src/sensor_service_proxy.cpp | 22 +++++++++++++++++++ interfaces/inner_api/sensor_agent.h | 10 +++++++++ .../adapter/include/compatible_connection.h | 1 + .../adapter/include/hdi_connection.h | 1 + .../adapter/src/compatible_connection.cpp | 9 ++++++++ .../adapter/src/hdi_connection.cpp | 11 ++++++++++ .../hardware/include/hdi_service_impl.h | 1 + .../hardware/src/hdi_service_impl.cpp | 5 +++++ .../include/i_sensor_hdi_connection.h | 1 + .../interface/include/sensor_hdi_connection.h | 1 + .../interface/src/sensor_hdi_connection.cpp | 10 +++++++++ services/include/sensor_service.h | 1 + services/include/sensor_service_stub.h | 1 + services/src/sensor_service.cpp | 10 +++++++++ services/src/sensor_service_stub.cpp | 11 ++++++++++ 23 files changed, 135 insertions(+) diff --git a/frameworks/native/include/i_sensor_service.h b/frameworks/native/include/i_sensor_service.h index 6df89586..205e85aa 100755 --- a/frameworks/native/include/i_sensor_service.h +++ b/frameworks/native/include/i_sensor_service.h @@ -49,6 +49,7 @@ public: virtual ErrCode EnableActiveInfoCB() = 0; virtual ErrCode DisableActiveInfoCB() = 0; virtual ErrCode ResetSensors() = 0; + virtual ErrCode SetDisplayMode(int32_t displayMode) = 0; }; } // namespace Sensors } // namespace OHOS diff --git a/frameworks/native/include/sensor_agent_proxy.h b/frameworks/native/include/sensor_agent_proxy.h index 5d58e112..def1f2df 100644 --- a/frameworks/native/include/sensor_agent_proxy.h +++ b/frameworks/native/include/sensor_agent_proxy.h @@ -51,6 +51,7 @@ public: int32_t Unregister(SensorActiveInfoCB callback); void HandleSensorData(SensorEvent *events, int32_t num, void *data); int32_t ResetSensors() const; + int32_t SetDisplayMode(int32_t displayMode); private: int32_t CreateSensorDataChannel(); diff --git a/frameworks/native/include/sensor_service_client.h b/frameworks/native/include/sensor_service_client.h index 963dc906..3d86548e 100755 --- a/frameworks/native/include/sensor_service_client.h +++ b/frameworks/native/include/sensor_service_client.h @@ -54,6 +54,7 @@ public: void ReceiveMessage(const char *buf, size_t size); void Disconnect(); void HandleNetPacke(NetPacket &pkt); + int32_t SetDisplayMode(int32_t displayMode); private: int32_t InitServiceClient(); diff --git a/frameworks/native/include/sensor_service_proxy.h b/frameworks/native/include/sensor_service_proxy.h index be7fbea8..5ddcbfc6 100755 --- a/frameworks/native/include/sensor_service_proxy.h +++ b/frameworks/native/include/sensor_service_proxy.h @@ -43,6 +43,7 @@ public: ErrCode EnableActiveInfoCB() override; ErrCode DisableActiveInfoCB() override; ErrCode ResetSensors() override; + ErrCode SetDisplayMode(int32_t displayMode) override; private: DISALLOW_COPY_AND_MOVE(SensorServiceProxy); diff --git a/frameworks/native/include/sensors_ipc_interface_code.h b/frameworks/native/include/sensors_ipc_interface_code.h index 2fd9df9a..0f1ecdb6 100644 --- a/frameworks/native/include/sensors_ipc_interface_code.h +++ b/frameworks/native/include/sensors_ipc_interface_code.h @@ -33,6 +33,7 @@ enum class SensorInterfaceCode { ENABLE_ACTIVE_INFO_CB, DISABLE_ACTIVE_INFO_CB, RESET_SENSORS, + SET_DISPLAY_MODE, }; } // namespace Sensors } // namespace OHOS diff --git a/frameworks/native/src/sensor_agent.cpp b/frameworks/native/src/sensor_agent.cpp index 3a8d0e4f..212d10d6 100644 --- a/frameworks/native/src/sensor_agent.cpp +++ b/frameworks/native/src/sensor_agent.cpp @@ -169,4 +169,13 @@ int32_t ResetSensors() return NormalizeErrCode(ret); } return ret; +} + +int32_t SetDisplayMode(int32_t displayMode) +{ + int32_t ret = SENSOR_AGENT_IMPL->SetDisplayMode(displayMode); + if (ret != OHOS::ERR_OK) { + SEN_HILOGE("Set display mode failed, ret:%{public}d", ret); + } + return ret; } \ No newline at end of file diff --git a/frameworks/native/src/sensor_agent_proxy.cpp b/frameworks/native/src/sensor_agent_proxy.cpp index f5d7368c..38d1356c 100644 --- a/frameworks/native/src/sensor_agent_proxy.cpp +++ b/frameworks/native/src/sensor_agent_proxy.cpp @@ -513,5 +513,14 @@ int32_t SensorAgentProxy::ResetSensors() const } return ret; } + +int32_t SensorAgentProxy::SetDisplayMode(int32_t displayMode) +{ + int32_t ret = SEN_CLIENT.SetDisplayMode(displayMode); + if (ret != ERR_OK) { + SEN_HILOGE("Set display mode failed, ret:%{public}d", ret); + } + return ret; +} } // namespace Sensors } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/src/sensor_service_client.cpp b/frameworks/native/src/sensor_service_client.cpp index dc52fa12..99514071 100644 --- a/frameworks/native/src/sensor_service_client.cpp +++ b/frameworks/native/src/sensor_service_client.cpp @@ -596,5 +596,22 @@ int32_t SensorServiceClient::CreateSocketChannel() isConnected_ = true; return ERR_OK; } + +int32_t SensorServiceClient::SetDisplayMode(int32_t displayMode) +{ + CALL_LOG_ENTER; + int32_t ret = InitServiceClient(); + if (ret != ERR_OK) { + SEN_HILOGE("InitServiceClient failed, ret:%{public}d", ret); + return ret; + } + std::lock_guard clientLock(clientMutex_); + CHKPR(sensorServer_, ERROR); + ret = sensorServer_->SetDisplayMode(displayMode); + if (ret != ERR_OK) { + SEN_HILOGE("Set display mode failed, ret:%{public}d", ret); + } + return ret; +} } // namespace Sensors } // namespace OHOS diff --git a/frameworks/native/src/sensor_service_proxy.cpp b/frameworks/native/src/sensor_service_proxy.cpp index b9b2b3d9..be243265 100644 --- a/frameworks/native/src/sensor_service_proxy.cpp +++ b/frameworks/native/src/sensor_service_proxy.cpp @@ -379,5 +379,27 @@ ErrCode SensorServiceProxy::ResetSensors() } return static_cast(ret); } + +ErrCode SensorServiceProxy::SetDisplayMode(int32_t displayMode) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(SensorServiceProxy::GetDescriptor())) { + SEN_HILOGE("Parcel write descriptor failed"); + return WRITE_PARCEL_ERR; + } + MessageParcel reply; + MessageOption option; + WRITEINT32(data, displayMode, WRITE_PARCEL_ERR); + sptr remote = Remote(); + CHKPR(remote, ERROR); + int32_t ret = + remote->SendRequest(static_cast(SensorInterfaceCode::SET_DISPLAY_MODE), data, reply, option); + if (ret != NO_ERROR) { + HiSysEventWrite(HiSysEvent::Domain::SENSOR, "SERVICE_IPC_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", + "SetDisplayMode", "ERROR_CODE", ret); + SEN_HILOGE("Failed, ret:%{public}d", ret); + } + return static_cast(ret); +} } // namespace Sensors } // namespace OHOS diff --git a/interfaces/inner_api/sensor_agent.h b/interfaces/inner_api/sensor_agent.h index 246e42a5..ab445161 100755 --- a/interfaces/inner_api/sensor_agent.h +++ b/interfaces/inner_api/sensor_agent.h @@ -189,6 +189,16 @@ int32_t Unregister(SensorActiveInfoCB callback); */ int32_t ResetSensors(); +/** + * @brief Set the data display mode. + * + * @param displayMode display mode. + * @return Returns 0 if the data display mode is successfully set; returns a non-zero value otherwise. + * + * @since 16 + */ +int32_t SetDisplayMode(int32_t displayMode); + #ifdef __cplusplus #if __cplusplus } diff --git a/services/hdi_connection/adapter/include/compatible_connection.h b/services/hdi_connection/adapter/include/compatible_connection.h index 75460182..48b23d0c 100644 --- a/services/hdi_connection/adapter/include/compatible_connection.h +++ b/services/hdi_connection/adapter/include/compatible_connection.h @@ -33,6 +33,7 @@ public: int32_t SetMode(int32_t sensorId, int32_t mode) override; int32_t RegisterDataReport(ReportDataCb cb, sptr reportDataCallback) override; int32_t DestroyHdiConnection() override; + int32_t SetDisplayMode(int32_t displayMode) override; private: DISALLOW_COPY_AND_MOVE(CompatibleConnection); diff --git a/services/hdi_connection/adapter/include/hdi_connection.h b/services/hdi_connection/adapter/include/hdi_connection.h index fbc192b0..9b730c46 100644 --- a/services/hdi_connection/adapter/include/hdi_connection.h +++ b/services/hdi_connection/adapter/include/hdi_connection.h @@ -37,6 +37,7 @@ public: ReportDataCb GetReportDataCb(); sptr GetReportDataCallback(); void ProcessDeathObserver(const wptr &object); + int32_t SetDisplayMode(int32_t displayMode) override; private: DISALLOW_COPY_AND_MOVE(HdiConnection); diff --git a/services/hdi_connection/adapter/src/compatible_connection.cpp b/services/hdi_connection/adapter/src/compatible_connection.cpp index 9c07aa2a..40b0a7f7 100644 --- a/services/hdi_connection/adapter/src/compatible_connection.cpp +++ b/services/hdi_connection/adapter/src/compatible_connection.cpp @@ -163,5 +163,14 @@ int32_t CompatibleConnection::DestroyHdiConnection() } return ERR_OK; } + +int32_t CompatibleConnection::SetDisplayMode(int32_t displayMode) +{ + int32_t ret = hdiServiceImpl_.SetDisplayMode(displayMode); + if (ret != ERR_OK) { + SEN_HILOGE("SetDisplayMode failed"); + } + return ret; +} } // namespace Sensors } // namespace OHOS \ No newline at end of file diff --git a/services/hdi_connection/adapter/src/hdi_connection.cpp b/services/hdi_connection/adapter/src/hdi_connection.cpp index 27cb4a71..a1ebc038 100644 --- a/services/hdi_connection/adapter/src/hdi_connection.cpp +++ b/services/hdi_connection/adapter/src/hdi_connection.cpp @@ -343,5 +343,16 @@ void HdiConnection::Reconnect() } } } + +int32_t HdiConnection::SetDisplayMode(int32_t displayMode) +{ + CALL_LOG_ENTER; + CHKPR(g_sensorInterface, ERR_NO_INIT); + int32_t ret = g_sensorInterface.SetDisplayMode(displayMode); + if (ret != ERR_OK) { + SEN_HILOGE("SetDisplayMode fail!"); + } + return ret; +} } // namespace Sensors } // namespace OHOS diff --git a/services/hdi_connection/hardware/include/hdi_service_impl.h b/services/hdi_connection/hardware/include/hdi_service_impl.h index 50e6101b..6b818887 100644 --- a/services/hdi_connection/hardware/include/hdi_service_impl.h +++ b/services/hdi_connection/hardware/include/hdi_service_impl.h @@ -35,6 +35,7 @@ public: int32_t SetMode(int32_t sensorId, int32_t mode); int32_t Register(RecordSensorCallback cb); int32_t Unregister(); + int32_t SetDisplayMode(int32_t displayMode); private: DISALLOW_COPY_AND_MOVE(HdiServiceImpl); diff --git a/services/hdi_connection/hardware/src/hdi_service_impl.cpp b/services/hdi_connection/hardware/src/hdi_service_impl.cpp index 1021cffa..0c2442b3 100644 --- a/services/hdi_connection/hardware/src/hdi_service_impl.cpp +++ b/services/hdi_connection/hardware/src/hdi_service_impl.cpp @@ -312,5 +312,10 @@ int32_t HdiServiceImpl::Unregister() isStop_ = true; return ERR_OK; } + +int32_t HdiServiceImpl::SetDisplayMode(int32_t displayMode) +{ + return ERR_OK; +} } // namespace Sensors } // namespace OHOS \ No newline at end of file diff --git a/services/hdi_connection/interface/include/i_sensor_hdi_connection.h b/services/hdi_connection/interface/include/i_sensor_hdi_connection.h index 06a53f44..98641de8 100644 --- a/services/hdi_connection/interface/include/i_sensor_hdi_connection.h +++ b/services/hdi_connection/interface/include/i_sensor_hdi_connection.h @@ -38,6 +38,7 @@ public: static std::mutex dataMutex_; static std::condition_variable dataCondition_; static std::atomic dataReady_; + virtual int32_t SetDisplayMode(int32_t displayMode) = 0; private: DISALLOW_COPY_AND_MOVE(ISensorHdiConnection); diff --git a/services/hdi_connection/interface/include/sensor_hdi_connection.h b/services/hdi_connection/interface/include/sensor_hdi_connection.h index 67c14bb4..b40011da 100644 --- a/services/hdi_connection/interface/include/sensor_hdi_connection.h +++ b/services/hdi_connection/interface/include/sensor_hdi_connection.h @@ -36,6 +36,7 @@ public: int32_t SetMode(int32_t sensorId, int32_t mode) override; int32_t RegisterDataReport(ReportDataCb cb, sptr reportDataCallback) override; int32_t DestroyHdiConnection() override; + int32_t SetDisplayMode(int32_t displayMode) override; private: DISALLOW_COPY_AND_MOVE(SensorHdiConnection); diff --git a/services/hdi_connection/interface/src/sensor_hdi_connection.cpp b/services/hdi_connection/interface/src/sensor_hdi_connection.cpp index 2f7e949f..f98fc7f6 100644 --- a/services/hdi_connection/interface/src/sensor_hdi_connection.cpp +++ b/services/hdi_connection/interface/src/sensor_hdi_connection.cpp @@ -404,5 +404,15 @@ int32_t SensorHdiConnection::DestroyHdiConnection() #endif // BUILD_VARIANT_ENG return ret; } + +int32_t SensorHdiConnection::SetDisplayMode(int32_t displayMode) +{ + CHKPR(iSensorHdiConnection_, DEVICE_ERR); + int32_t ret = iSensorHdiConnection_->SetDisplayMode(displayMode); + if (ret != ERR_OK) { + SEN_HILOGE("SetDisplayMode failed"); + } + return ret; +} } // namespace Sensors } // namespace OHOS diff --git a/services/include/sensor_service.h b/services/include/sensor_service.h index 5ff2a6c4..c9c58e65 100644 --- a/services/include/sensor_service.h +++ b/services/include/sensor_service.h @@ -66,6 +66,7 @@ public: ErrCode EnableActiveInfoCB() override; ErrCode DisableActiveInfoCB() override; ErrCode ResetSensors() override; + ErrCode SetDisplayMode(int32_t displayMode) override; private: DISALLOW_COPY_AND_MOVE(SensorService); diff --git a/services/include/sensor_service_stub.h b/services/include/sensor_service_stub.h index c799965d..414924c1 100644 --- a/services/include/sensor_service_stub.h +++ b/services/include/sensor_service_stub.h @@ -49,6 +49,7 @@ private: bool IsSystemServiceCalling(); int32_t ProcessRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); bool IsSystemCalling(); + ErrCode SetDisplayModeInner(MessageParcel &data, MessageParcel &reply); }; } // namespace Sensors } // namespace OHOS diff --git a/services/src/sensor_service.cpp b/services/src/sensor_service.cpp index 5aadddc1..c191cadc 100644 --- a/services/src/sensor_service.cpp +++ b/services/src/sensor_service.cpp @@ -636,5 +636,15 @@ void SensorService::PermStateChangeCb::PermStateChangeCallback(Security::AccessT server_->clientInfo_.ChangeSensorPerm(result.tokenID, result.permissionName, (result.permStateChangeType != 0)); } + +ErrCode SensorService::SetDisplayMode(int32_t displayMode) +{ + CALL_LOG_ENTER; + int32_t ret = sensorHdiConnection_.SetDisplayMode(displayMode); + if (ret != ERR_OK) { + SEN_HILOGE("SetDisplayMode fail!"); + } + return static_cast(ret); +} } // namespace Sensors } // namespace OHOS diff --git a/services/src/sensor_service_stub.cpp b/services/src/sensor_service_stub.cpp index 36a679fb..a57373b2 100644 --- a/services/src/sensor_service_stub.cpp +++ b/services/src/sensor_service_stub.cpp @@ -86,6 +86,9 @@ int32_t SensorServiceStub::ProcessRemoteRequest(uint32_t code, MessageParcel &da case static_cast(SensorInterfaceCode::RESET_SENSORS): { return ResetSensorsInner(data, reply); } + case static_cast(SensorInterfaceCode::SET_DISPLAY_MODE): { + return SetDisplayModeInner(data, reply); + } default: { SEN_HILOGD("No member func supporting, applying default process"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); @@ -358,5 +361,13 @@ ErrCode SensorServiceStub::ResetSensorsInner(MessageParcel &data, MessageParcel } return ResetSensors(); } + +ErrCode SensorServiceStub::SetDisplayModeInner(MessageParcel &data, MessageParcel &reply) +{ + (void)reply; + int32_t displayMode; + READINT32(data, displayMode, READ_PARCEL_ERR); + return SetDisplayMode(displayMode); +} } // namespace Sensors } // namespace OHOS -- Gitee