diff --git a/frameworks/native/include/i_sensor_service.h b/frameworks/native/include/i_sensor_service.h index 6df8958628da1c7ac8586431ec83a110f14d6e68..205e85aa4a958b82d539385e0143e6c0707b2eb1 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 5d58e1126257e9a5c137c0f866cee8838b2f5620..def1f2df4b781c43d2288e4318ad9a8adb21080c 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 963dc9067a8cde16ae2a642ebb7a512a12961826..3d86548ed08a24742ef1e5056d87d4c6a8031141 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 be7fbea805ac195dc969d88759e6050d58eaf4b0..5ddcbfc6c14f12f952f5bc712b194d6b74d58e69 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 2fd9df9ac4441be519248b32630f20f7699daa22..0f1ecdb66db93a84a2c96b10b4c29604bc4f11a1 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 3a8d0e4ff94d4924a698a0c3b56a711d10f3fc0f..212d10d61f946b17168d6352281c03b850c19a3a 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 f5d7368cd421ff6a4a617e149d8d64f9eba7bb20..38d1356c97a41e303961b4e603df51b533607f21 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 dc52fa12b250d0fdb138ad1eef8c505aadb250a1..99514071581e4c28fe213a05030ff4d6b829d173 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 b9b2b3d967f0062c0a982dc29b882ca6a8b8a6e9..be2432651f6bfa81f63aeb5021761c133ed63097 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 246e42a5afc1032bb3add343fc777ca36998f07d..ab4451618bc85b516d2c4c7ba0db588a25dedd9c 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 75460182ec1d71e95bbdaeb9b702b326f67f010f..48b23d0c8745effc8606889f8a4da8a7c742955c 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 fbc192b09fb2a6a6eed09dedc1a86a8123260133..9b730c460c63c22ecd7254d1da04e03809a9dc6f 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 9c07aa2ab32b24ab1b725daa5978be8ca191c435..40b0a7f75f25086cc87b156237180876a2094470 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 27cb4a71915b740413a9dec2a2023e2e63bc1f80..a1ebc03881ae24482f493fe810cda0eaa5813a01 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 50e6101b589ab7c2f0ff80c0d827e974f82b40a7..6b818887c80319de8f0b2f939371074524e885d0 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 1021cffa4a96fac3c5a7d84cd58fd01117a3ba5b..0c2442b3be35f1b467cd401f5b2b4adb00b07fd6 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 06a53f4476f5676cd74ec115369e9e6fea5a8212..98641de8dc9bd86a24ad9f331793c79d2a1d4edd 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 67c14bb4a0216a15fc9b73c967087c3bb139d7b3..b40011da6fe4f00114d412c852c655e688107b72 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 2f7e949fc2e5ec24ba23f05f7b3e3176265ba2fb..f98fc7f63dcd71ca7ed7ab4dcb66209d9b98d8c1 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 5ff2a6c4dee73c8bb43c6ecee857559bbd12a6f9..c9c58e657cae05815600f1ba565b748b04a3d885 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 c799965d4dca6fa4b18826e9811fc3c262e524d4..414924c1aa7b05637d357dd2a39eeb4f3533d6bb 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 5aadddc10a5ee54851b6a4e6e3da221f01abd15c..c191cadc808bd951b3796b9e659f4198aaafbbf8 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 36a679fb667eb27ff5ac12f3f744882e98c6fa61..a57373b22fe703792f00e425427103a7c9d79635 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