From 98e0dfc7b46b85349f137369425c85999f5693a2 Mon Sep 17 00:00:00 2001 From: wdh122119 Date: Tue, 30 Apr 2024 15:07:12 +0800 Subject: [PATCH] feat: add inner interface RegisterHibernateSleepCallback Signed-off-by: wdh122119 --- frameworks/native/power_mgr_client.cpp | 14 ++++ interfaces/inner_api/BUILD.gn | 2 + .../hibernate/isync_hibernate_callback.h | 35 +++++++++ ...nc_hibernate_callback_ipc_interface_code.h | 27 +++++++ .../inner_api/native/include/ipower_mgr.h | 4 ++ .../native/include/power_mgr_client.h | 2 + .../include/power_mgr_ipc_interface_code.h | 2 + services/native/include/power_mgr_service.h | 2 + services/native/src/power_mgr_service.cpp | 12 ++++ services/zidl/include/power_mgr_proxy.h | 2 + services/zidl/include/power_mgr_stub.h | 2 + .../include/sync_hibernate_callback_proxy.h | 43 +++++++++++ .../include/sync_hibernate_callback_stub.h | 43 +++++++++++ services/zidl/src/power_mgr_proxy.cpp | 53 ++++++++++++++ services/zidl/src/power_mgr_stub.cpp | 26 +++++++ .../src/sync_hibernate_callback_proxy.cpp | 71 +++++++++++++++++++ .../zidl/src/sync_hibernate_callback_stub.cpp | 65 +++++++++++++++++ 17 files changed, 405 insertions(+) create mode 100644 interfaces/inner_api/native/include/hibernate/isync_hibernate_callback.h create mode 100644 interfaces/inner_api/native/include/hibernate/sync_hibernate_callback_ipc_interface_code.h create mode 100644 services/zidl/include/sync_hibernate_callback_proxy.h create mode 100644 services/zidl/include/sync_hibernate_callback_stub.h create mode 100644 services/zidl/src/sync_hibernate_callback_proxy.cpp create mode 100644 services/zidl/src/sync_hibernate_callback_stub.cpp diff --git a/frameworks/native/power_mgr_client.cpp b/frameworks/native/power_mgr_client.cpp index 649d8c98..ffd5fb87 100644 --- a/frameworks/native/power_mgr_client.cpp +++ b/frameworks/native/power_mgr_client.cpp @@ -305,6 +305,20 @@ bool PowerMgrClient::UnRegisterSyncSleepCallback(const sptr& return ret; } +bool PowerMgrClient::RegisterSyncHibernateCallback(const sptr& callback) +{ + RETURN_IF_WITH_RET((callback == nullptr) || (Connect() != ERR_OK), false); + bool ret = proxy_->RegisterSyncHibernateCallback(callback); + return ret; +} + +bool PowerMgrClient::UnRegisterSyncHibernateCallback(const sptr& callback) +{ + RETURN_IF_WITH_RET((callback == nullptr) || (Connect() != ERR_OK), false); + bool ret = proxy_->UnRegisterSyncHibernateCallback(callback); + return ret; +} + bool PowerMgrClient::RegisterPowerModeCallback(const sptr& callback) { RETURN_IF_WITH_RET((callback == nullptr) || (Connect() != ERR_OK), false); diff --git a/interfaces/inner_api/BUILD.gn b/interfaces/inner_api/BUILD.gn index 463e7b32..6bfa40ed 100644 --- a/interfaces/inner_api/BUILD.gn +++ b/interfaces/inner_api/BUILD.gn @@ -49,6 +49,8 @@ ohos_shared_library("powermgr_client") { "${powermgr_service_zidl}/src/shutdown/sync_shutdown_callback_stub.cpp", "${powermgr_service_zidl}/src/shutdown/takeover_shutdown_callback_proxy.cpp", "${powermgr_service_zidl}/src/shutdown/takeover_shutdown_callback_stub.cpp", + "${powermgr_service_zidl}/src/sync_hibernate_callback_proxy.cpp", + "${powermgr_service_zidl}/src/sync_hibernate_callback_stub.cpp", "${powermgr_service_zidl}/src/sync_sleep_callback_proxy.cpp", "${powermgr_service_zidl}/src/sync_sleep_callback_stub.cpp", ] diff --git a/interfaces/inner_api/native/include/hibernate/isync_hibernate_callback.h b/interfaces/inner_api/native/include/hibernate/isync_hibernate_callback.h new file mode 100644 index 00000000..55f5567e --- /dev/null +++ b/interfaces/inner_api/native/include/hibernate/isync_hibernate_callback.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024 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 POWERMGR_POWER_MANAGER_ISYNC_HIBERNATE_CALLBACK_H +#define POWERMGR_POWER_MANAGER_ISYNC_HIBERNATE_CALLBACK_H + +#include +#include +#include +#include + +namespace OHOS { +namespace PowerMgr { +class ISyncHibernateCallback : public IRemoteBroker { +public: + virtual void OnSyncHibernate() = 0; + virtual void OnSyncWakeup() = 0; + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.powermgr.ISyncHibernateCallback"); +}; +} // namespace PowerMgr +} // namespace OHOS + +#endif // POWERMGR_POWER_MANAGER_ISYNC_HIBERNATE_CALLBACK_H diff --git a/interfaces/inner_api/native/include/hibernate/sync_hibernate_callback_ipc_interface_code.h b/interfaces/inner_api/native/include/hibernate/sync_hibernate_callback_ipc_interface_code.h new file mode 100644 index 00000000..cb7ca6ab --- /dev/null +++ b/interfaces/inner_api/native/include/hibernate/sync_hibernate_callback_ipc_interface_code.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024 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 SYNC_HIBERNATE_CALLBACK_IPC_INTERFACE_CODE_H +#define SYNC_HIBERNATE_CALLBACK_IPC_INTERFACE_CODE_H +namespace OHOS { +namespace PowerMgr { +enum class SyncHibernateCallbackInterfaceCode { + CMD_ON_SYNC_HIBERNATE = 0, + CMD_ON_SYNC_WAKEUP = 1, +}; +} // namespace PowerMgr +} // namespace OHOS + +#endif // SYNC_HIBERNATE_CALLBACK_IPC_INTERFACE_CODE_H diff --git a/interfaces/inner_api/native/include/ipower_mgr.h b/interfaces/inner_api/native/include/ipower_mgr.h index b94a9d19..0ce527f6 100644 --- a/interfaces/inner_api/native/include/ipower_mgr.h +++ b/interfaces/inner_api/native/include/ipower_mgr.h @@ -31,6 +31,7 @@ #include "running_lock_info.h" #include "shutdown/ishutdown_client.h" #include "suspend/isync_sleep_callback.h" +#include "hibernate/isync_hibernate_callback.h" namespace OHOS { namespace PowerMgr { @@ -67,6 +68,9 @@ public: SleepPriority priority = SleepPriority::DEFAULT) = 0; virtual bool UnRegisterSyncSleepCallback(const sptr& callback) = 0; + virtual bool RegisterSyncHibernateCallback(const sptr& callback) = 0; + virtual bool UnRegisterSyncHibernateCallback(const sptr& callback) = 0; + // Used for callback registration upon power mode. virtual bool RegisterPowerModeCallback(const sptr& callback) = 0; virtual bool UnRegisterPowerModeCallback(const sptr& callback) = 0; diff --git a/interfaces/inner_api/native/include/power_mgr_client.h b/interfaces/inner_api/native/include/power_mgr_client.h index e0bad80f..3049cb41 100644 --- a/interfaces/inner_api/native/include/power_mgr_client.h +++ b/interfaces/inner_api/native/include/power_mgr_client.h @@ -147,6 +147,8 @@ public: bool ResetRunningLocks(); bool RegisterPowerStateCallback(const sptr& callback); bool UnRegisterPowerStateCallback(const sptr& callback); + bool RegisterSyncHibernateCallback(const sptr& callback); + bool UnRegisterSyncHibernateCallback(const sptr& callback); bool RegisterSyncSleepCallback(const sptr& callback, SleepPriority priority); bool UnRegisterSyncSleepCallback(const sptr& callback); bool RegisterPowerModeCallback(const sptr& callback); diff --git a/interfaces/inner_api/native/include/power_mgr_ipc_interface_code.h b/interfaces/inner_api/native/include/power_mgr_ipc_interface_code.h index 44f08320..67a86681 100644 --- a/interfaces/inner_api/native/include/power_mgr_ipc_interface_code.h +++ b/interfaces/inner_api/native/include/power_mgr_ipc_interface_code.h @@ -57,6 +57,8 @@ enum class PowerMgrInterfaceCode { REG_RUNNINGLOCK_CALLBACK, UNREG_RUNNINGLOCK_CALLBACK, HIBERNATE, + REG_SYNC_HIBERNATE_CALLBACK, + UNREG_SYNC_HIBERNATE_CALLBACK, }; } // space PowerMgr } // namespace OHOS diff --git a/services/native/include/power_mgr_service.h b/services/native/include/power_mgr_service.h index afd3d088..2de81184 100644 --- a/services/native/include/power_mgr_service.h +++ b/services/native/include/power_mgr_service.h @@ -80,6 +80,8 @@ public: virtual bool RegisterSyncSleepCallback(const sptr& callback, SleepPriority priority) override; virtual bool UnRegisterSyncSleepCallback(const sptr& callback) override; + virtual bool RegisterSyncHibernateCallback(const sptr& callback) override; + virtual bool UnRegisterSyncHibernateCallback(const sptr& callback) override; virtual bool RegisterPowerModeCallback(const sptr& callback) override; virtual bool UnRegisterPowerModeCallback(const sptr& callback) override; diff --git a/services/native/src/power_mgr_service.cpp b/services/native/src/power_mgr_service.cpp index f0118e7c..16a77a74 100644 --- a/services/native/src/power_mgr_service.cpp +++ b/services/native/src/power_mgr_service.cpp @@ -903,6 +903,18 @@ bool PowerMgrService::UnRegisterSyncSleepCallback(const sptr return true; } +bool PowerMgrService::RegisterSyncHibernateCallback(const sptr& callback) +{ + POWER_HILOGI(FEATURE_SUSPEND, "RegisterSyncHibernateCallback begin."); + return true; +} + +bool PowerMgrService::UnRegisterSyncHibernateCallback(const sptr& callback) +{ + POWER_HILOGI(FEATURE_SUSPEND, "UnRegisterSyncHibernateCallback begin."); + return true; +} + bool PowerMgrService::RegisterPowerModeCallback(const sptr& callback) { std::lock_guard lock(modeMutex_); diff --git a/services/zidl/include/power_mgr_proxy.h b/services/zidl/include/power_mgr_proxy.h index 9c4202cd..32841443 100644 --- a/services/zidl/include/power_mgr_proxy.h +++ b/services/zidl/include/power_mgr_proxy.h @@ -89,6 +89,8 @@ public: void RegisterShutdownCallback(const sptr& callback, ShutdownPriority priority) override; void UnRegisterShutdownCallback(const sptr& callback) override; + virtual bool RegisterSyncHibernateCallback(const sptr& callback) override; + virtual bool UnRegisterSyncHibernateCallback(const sptr& callback) override; virtual bool RegisterSyncSleepCallback(const sptr& callback, SleepPriority priority) override; virtual bool UnRegisterSyncSleepCallback(const sptr& callback) override; diff --git a/services/zidl/include/power_mgr_stub.h b/services/zidl/include/power_mgr_stub.h index f99a5621..986d7c70 100644 --- a/services/zidl/include/power_mgr_stub.h +++ b/services/zidl/include/power_mgr_stub.h @@ -56,6 +56,8 @@ private: int32_t ShutDownDeviceStub(MessageParcel& data, MessageParcel& reply); int32_t RegisterPowerStateCallbackStub(MessageParcel& data); + int32_t RegisterSyncHibernateCallbackStub(MessageParcel& data); + int32_t UnRegisterSyncHibernateCallbackStub(MessageParcel& data); int32_t RegisterSyncSleepCallbackStub(MessageParcel& data); int32_t UnRegisterSyncSleepCallbackStub(MessageParcel& data); diff --git a/services/zidl/include/sync_hibernate_callback_proxy.h b/services/zidl/include/sync_hibernate_callback_proxy.h new file mode 100644 index 00000000..2cb7c17b --- /dev/null +++ b/services/zidl/include/sync_hibernate_callback_proxy.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 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 POWERMGR_POWER_MANAGER_SYNC_HIBERNATE_CALLBACK_PROXY_H +#define POWERMGR_POWER_MANAGER_SYNC_HIBERNATE_CALLBACK_PROXY_H + +#include +#include +#include +#include "refbase.h" +#include "iremote_broker.h" +#include "iremote_object.h" + +#include "hibernate/isync_hibernate_callback.h" + +namespace OHOS { +namespace PowerMgr { +class SyncHibernateCallbackProxy : public IRemoteProxy { +public: + explicit SyncHibernateCallbackProxy(const sptr& impl) + : IRemoteProxy(impl) {} + ~SyncHibernateCallbackProxy() = default; + virtual void OnSyncHibernate() override; + virtual void OnSyncWakeup() override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace PowerMgr +} // namespace OHOS +#endif // POWERMGR_POWER_MANAGER_SYNC_HIBERNATE_CALLBACK_PROXY_H diff --git a/services/zidl/include/sync_hibernate_callback_stub.h b/services/zidl/include/sync_hibernate_callback_stub.h new file mode 100644 index 00000000..ee2fcff1 --- /dev/null +++ b/services/zidl/include/sync_hibernate_callback_stub.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2024 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 POWERMGR_POWER_MANAGER_SYNC_HIBERNATE_CALLBACK_STUB_H +#define POWERMGR_POWER_MANAGER_SYNC_HIBERNATE_CALLBACK_STUB_H + +#include +#include + +#include "hibernate/isync_hibernate_callback.h" + +namespace OHOS { +namespace PowerMgr { +class SyncHibernateCallbackStub : public IRemoteStub { +public: + DISALLOW_COPY_AND_MOVE(SyncHibernateCallbackStub); + SyncHibernateCallbackStub() = default; + virtual ~SyncHibernateCallbackStub() = default; + + int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + void OnSyncHibernate() override {} + void OnSyncWakeup() override {} + +private: + int32_t OnSyncHibernateStub(MessageParcel& data); + int32_t OnSyncWakeupStub(MessageParcel& data); +}; +} // namespace PowerMgr +} // namespace OHOS +#endif // POWERMGR_POWER_MANAGER_SYNC_HIBERNATE_CALLBACK_STUB_H + diff --git a/services/zidl/src/power_mgr_proxy.cpp b/services/zidl/src/power_mgr_proxy.cpp index 190667e8..35e8d974 100644 --- a/services/zidl/src/power_mgr_proxy.cpp +++ b/services/zidl/src/power_mgr_proxy.cpp @@ -739,6 +739,59 @@ bool PowerMgrProxy::UnRegisterSyncSleepCallback(const sptr& return true; } +bool PowerMgrProxy::RegisterSyncHibernateCallback(const sptr& callback) +{ + sptr remote = Remote(); + RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { + POWER_HILOGE(FEATURE_POWER_STATE, "Write descriptor failed"); + return false; + } + + WRITE_PARCEL_WITH_RET(data, RemoteObject, callback->AsObject(), false); + + int ret = remote->SendRequest( + static_cast(PowerMgr::PowerMgrInterfaceCode::REG_SYNC_HIBERNATE_CALLBACK), + data, reply, option); + if (ret != ERR_OK) { + POWER_HILOGE(FEATURE_POWER_STATE, "SendRequest is failed, ret: %{public}d", ret); + return false; + } + return true; +} + + +bool PowerMgrProxy::UnRegisterSyncHibernateCallback(const sptr& callback) +{ + sptr remote = Remote(); + RETURN_IF_WITH_RET((remote == nullptr) || (callback == nullptr), false); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!data.WriteInterfaceToken(PowerMgrProxy::GetDescriptor())) { + POWER_HILOGE(FEATURE_POWER_STATE, "Write descriptor failed"); + return false; + } + + WRITE_PARCEL_WITH_RET(data, RemoteObject, callback->AsObject(), false); + + int ret = remote->SendRequest( + static_cast(PowerMgr::PowerMgrInterfaceCode::UNREG_SYNC_HIBERNATE_CALLBACK), + data, reply, option); + if (ret != ERR_OK) { + POWER_HILOGE(FEATURE_POWER_STATE, "SendRequest is failed, ret: %{public}d", ret); + return false; + } + return true; +} + bool PowerMgrProxy::RegisterPowerModeCallback(const sptr& callback) { sptr remote = Remote(); diff --git a/services/zidl/src/power_mgr_stub.cpp b/services/zidl/src/power_mgr_stub.cpp index 42d0df2f..d7ffd3cf 100644 --- a/services/zidl/src/power_mgr_stub.cpp +++ b/services/zidl/src/power_mgr_stub.cpp @@ -159,6 +159,12 @@ int PowerMgrStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessagePar case static_cast(PowerMgr::PowerMgrInterfaceCode::IS_STANDBY): ret = IsStandbyStub(data, reply); break; + case static_cast(PowerMgr::PowerMgrInterfaceCode::REG_SYNC_HIBERNATE_CALLBACK): + ret = RegisterSyncHibernateCallbackStub(data); + break; + case static_cast(PowerMgr::PowerMgrInterfaceCode::UNREG_SYNC_HIBERNATE_CALLBACK): + ret = UnRegisterSyncHibernateCallbackStub(data); + break; case static_cast(PowerMgr::PowerMgrInterfaceCode::REG_SYNC_SLEEP_CALLBACK): ret = RegisterSyncSleepCallbackStub(data); break; @@ -450,6 +456,26 @@ int32_t PowerMgrStub::UnRegisterPowerStateCallbackStub(MessageParcel& data) return ERR_OK; } +int32_t PowerMgrStub::RegisterSyncHibernateCallbackStub(MessageParcel& data) +{ + sptr obj = data.ReadRemoteObject(); + RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR); + sptr callback = iface_cast(obj); + RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR); + RegisterSyncHibernateCallback(callback); + return ERR_OK; +} + +int32_t PowerMgrStub::UnRegisterSyncHibernateCallbackStub(MessageParcel& data) +{ + sptr obj = data.ReadRemoteObject(); + RETURN_IF_WITH_RET((obj == nullptr), E_READ_PARCEL_ERROR); + sptr callback = iface_cast(obj); + RETURN_IF_WITH_RET((callback == nullptr), E_READ_PARCEL_ERROR); + UnRegisterSyncHibernateCallback(callback); + return ERR_OK; +} + int32_t PowerMgrStub::RegisterSyncSleepCallbackStub(MessageParcel& data) { uint32_t priority; diff --git a/services/zidl/src/sync_hibernate_callback_proxy.cpp b/services/zidl/src/sync_hibernate_callback_proxy.cpp new file mode 100644 index 00000000..ea388c1f --- /dev/null +++ b/services/zidl/src/sync_hibernate_callback_proxy.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2024 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 "sync_hibernate_callback_proxy.h" + +#include +#include "errors.h" +#include "message_option.h" +#include "power_log.h" +#include "power_common.h" +#include "hibernate/sync_hibernate_callback_ipc_interface_code.h" + +namespace OHOS { +namespace PowerMgr { +void SyncHibernateCallbackProxy::OnSyncHibernate() +{ + sptr remote = Remote(); + RETURN_IF(remote == nullptr); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!data.WriteInterfaceToken(SyncHibernateCallbackProxy::GetDescriptor())) { + POWER_HILOGE(FEATURE_SUSPEND, "Write descriptor failed"); + return; + } + + int ret = remote->SendRequest( + static_cast(PowerMgr::SyncHibernateCallbackInterfaceCode::CMD_ON_SYNC_HIBERNATE), + data, reply, option); + if (ret != ERR_OK) { + POWER_HILOGE(FEATURE_SUSPEND, "SendRequest is failed, ret: %{public}d", ret); + } +} + +void SyncHibernateCallbackProxy::OnSyncWakeup() +{ + sptr remote = Remote(); + RETURN_IF(remote == nullptr); + + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!data.WriteInterfaceToken(SyncHibernateCallbackProxy::GetDescriptor())) { + POWER_HILOGE(FEATURE_POWER_STATE, "Write descriptor failed"); + return; + } + + int ret = remote->SendRequest( + static_cast(PowerMgr::SyncHibernateCallbackInterfaceCode::CMD_ON_SYNC_WAKEUP), + data, reply, option); + if (ret != ERR_OK) { + POWER_HILOGE(FEATURE_SUSPEND, "SendRequest is failed, ret: %{public}d", ret); + } +} +} // namespace PowerMgr +} // namespace OHOS diff --git a/services/zidl/src/sync_hibernate_callback_stub.cpp b/services/zidl/src/sync_hibernate_callback_stub.cpp new file mode 100644 index 00000000..2162f001 --- /dev/null +++ b/services/zidl/src/sync_hibernate_callback_stub.cpp @@ -0,0 +1,65 @@ +/* + * 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 + * + * 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 "sync_hibernate_callback_stub.h" + +#include + +#include "power_common.h" +#include "hibernate/sync_hibernate_callback_ipc_interface_code.h" +#include "sync_hibernate_callback_proxy.h" +#include "xcollie/xcollie.h" + +namespace OHOS { +namespace PowerMgr { +int SyncHibernateCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) +{ + POWER_HILOGD(COMP_SVC, "cmd = %{public}d, flags= %{public}d", code, option.GetFlags()); + const int DFX_DELAY_MS = 10000; + int id = HiviewDFX::XCollie::GetInstance().SetTimer("SyncHibernateCallbackStub", DFX_DELAY_MS, nullptr, nullptr, + HiviewDFX::XCOLLIE_FLAG_NOOP); + std::u16string descripter = SyncHibernateCallbackStub::GetDescriptor(); + std::u16string remoteDescripter = data.ReadInterfaceToken(); + if (descripter != remoteDescripter) { + POWER_HILOGE(COMP_SVC, "Descriptor is not match"); + return E_GET_POWER_SERVICE_FAILED; + } + + int ret = ERR_OK; + if (code == static_cast(PowerMgr::SyncHibernateCallbackInterfaceCode::CMD_ON_SYNC_HIBERNATE)) { + ret = OnSyncHibernateStub(data); + } else if (code == static_cast(PowerMgr::SyncHibernateCallbackInterfaceCode::CMD_ON_SYNC_WAKEUP)) { + ret = OnSyncWakeupStub(data); + } else { + ret = IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + HiviewDFX::XCollie::GetInstance().CancelTimer(id); + return ret; +} + +int32_t SyncHibernateCallbackStub::OnSyncHibernateStub(MessageParcel& data) +{ + OnSyncHibernate(); + return ERR_OK; +} + +int32_t SyncHibernateCallbackStub::OnSyncWakeupStub(MessageParcel& data) +{ + OnSyncWakeup(); + return ERR_OK; +} +} // namespace PowerMgr +} // namespace OHOS -- Gitee