From f48abee21bf0e20f886d57bf32b774d90465f858 Mon Sep 17 00:00:00 2001 From: qiuxiangdong Date: Tue, 20 Jun 2023 21:42:14 +0800 Subject: [PATCH] fix: Replace the shutdown callback method Signed-off-by: qiuxiangdong Change-Id: Ia1e85f41211c4dadcaf52c3b83da5a52d6f7c435 --- BUILD.gn | 2 - .../common/include/bundle_active_service.h | 3 +- .../bundle_active_shutdown_callback_proxy.h | 39 --------------- .../bundle_active_shutdown_callback_service.h | 6 +-- .../bundle_active_shutdown_callback_stub.h | 41 ---------------- services/common/src/bundle_active_service.cpp | 7 ++- .../bundle_active_shutdown_callback_proxy.cpp | 39 --------------- ...undle_active_shutdown_callback_service.cpp | 2 +- .../bundle_active_shutdown_callback_stub.cpp | 48 ------------------- 9 files changed, 11 insertions(+), 176 deletions(-) delete mode 100644 services/common/include/bundle_active_shutdown_callback_proxy.h delete mode 100644 services/common/include/bundle_active_shutdown_callback_stub.h delete mode 100644 services/common/src/bundle_active_shutdown_callback_proxy.cpp delete mode 100644 services/common/src/bundle_active_shutdown_callback_stub.cpp diff --git a/BUILD.gn b/BUILD.gn index e7c020d..8f3d319 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -153,9 +153,7 @@ ohos_shared_library("usagestatservice") { "services/common/src/bundle_active_power_state_callback_service.cpp", "services/common/src/bundle_active_power_state_callback_stub.cpp", "services/common/src/bundle_active_service.cpp", - "services/common/src/bundle_active_shutdown_callback_proxy.cpp", "services/common/src/bundle_active_shutdown_callback_service.cpp", - "services/common/src/bundle_active_shutdown_callback_stub.cpp", "services/common/src/bundle_active_stub.cpp", "services/common/src/bundle_active_usage_database.cpp", "services/packagegroup/src/bundle_active_group_controller.cpp", diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h index 0fb666e..6eda74c 100644 --- a/services/common/include/bundle_active_service.h +++ b/services/common/include/bundle_active_service.h @@ -29,6 +29,7 @@ #include "bundle_active_continuous_task_observer.h" #include "bundle_active_account_helper.h" #include "file_ex.h" +#include "shutdown/iasync_shutdown_callback.h" #include "string_ex.h" #include "system_ability.h" @@ -214,7 +215,7 @@ private: #ifdef BGTASKMGR_ENABLE std::shared_ptr continuousTaskObserver_; #endif - sptr shutdownCallback_; + sptr shutdownCallback_; sptr powerStateCallback_; std::shared_ptr runner_; std::shared_ptr handler_; diff --git a/services/common/include/bundle_active_shutdown_callback_proxy.h b/services/common/include/bundle_active_shutdown_callback_proxy.h deleted file mode 100644 index e53fe5e..0000000 --- a/services/common/include/bundle_active_shutdown_callback_proxy.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022 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 BUNDLE_ACTIVE_SHUTDOWN_CALLBACK_PROXY_H -#define BUNDLE_ACTIVE_SHUTDOWN_CALLBACK_PROXY_H - -#include "ibundle_active_service.h" -#include "ishutdown_callback.h" -#include "nocopyable.h" - -namespace OHOS { -namespace DeviceUsageStats { -using IShutdownCallback = OHOS::PowerMgr::IShutdownCallback; -class BundleActiveShutdownCallbackProxy : public IRemoteProxy { -public: - explicit BundleActiveShutdownCallbackProxy(const sptr& impl) - : IRemoteProxy(impl) {} - ~BundleActiveShutdownCallbackProxy() = default; - DISALLOW_COPY_AND_MOVE(BundleActiveShutdownCallbackProxy); - void ShutdownCallback() override; -private: - static inline BrokerDelegator delegator_; -}; -} // namespace DeviceUsageStats -} // namespace OHOS -#endif // BUNDLE_ACTIVE_SHUTDOWN_CALLBACK_PROXY_H - diff --git a/services/common/include/bundle_active_shutdown_callback_service.h b/services/common/include/bundle_active_shutdown_callback_service.h index 95b3648..b544eb9 100644 --- a/services/common/include/bundle_active_shutdown_callback_service.h +++ b/services/common/include/bundle_active_shutdown_callback_service.h @@ -16,16 +16,16 @@ #ifndef BUNDLE_ACTIVE_SHUTDOWN_CALLBACK_SERVICE_H #define BUNDLE_ACTIVE_SHUTDOWN_CALLBACK_SERVICE_H -#include "bundle_active_shutdown_callback_stub.h" +#include "shutdown/async_shutdown_callback_stub.h" #include "bundle_active_core.h" namespace OHOS { namespace DeviceUsageStats { -class BundleActiveShutdownCallbackService : public BundleActiveShutdownCallbackStub { +class BundleActiveShutdownCallbackService : public PowerMgr::AsyncShutdownCallbackStub { public: BundleActiveShutdownCallbackService(std::shared_ptr bundleActiveCore); virtual ~BundleActiveShutdownCallbackService() {} - void ShutdownCallback() override; + void OnAsyncShutdown() override; private: std::shared_ptr bundleActiveCore_; }; diff --git a/services/common/include/bundle_active_shutdown_callback_stub.h b/services/common/include/bundle_active_shutdown_callback_stub.h deleted file mode 100644 index 134e33d..0000000 --- a/services/common/include/bundle_active_shutdown_callback_stub.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2022 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 BUNDLE_ACTIVE_SHUTDOWN_CALLBACK_STUB_H -#define BUNDLE_ACTIVE_SHUTDOWN_CALLBACK_STUB_H - -#include -#include "iremote_stub.h" -#include "ishutdown_callback.h" -#include "message_option.h" -#include "message_parcel.h" -#include "nocopyable.h" - -namespace OHOS { -namespace DeviceUsageStats { -using IShutdownCallback = OHOS::PowerMgr::IShutdownCallback; -class BundleActiveShutdownCallbackStub : public IRemoteStub { -public: - DISALLOW_COPY_AND_MOVE(BundleActiveShutdownCallbackStub); - BundleActiveShutdownCallbackStub() = default; - virtual ~BundleActiveShutdownCallbackStub() = default; - int32_t OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel &reply, MessageOption &option) override; -private: - void ShutdownStub(); -}; -} // namespace DeviceUsageStats -} // namespace OHOS -#endif // BUNDLE_ACTIVE_SHUTDOWN_CALLBACK_STUB_H - diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index c094b55..c8fb6a8 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -15,6 +15,7 @@ #include "time_service_client.h" #include "power_mgr_client.h" +#include "shutdown/shutdown_client.h" #include "unistd.h" #include "accesstoken_kit.h" @@ -143,9 +144,10 @@ void BundleActiveService::InitService() } shutdownCallback_ = new (std::nothrow) BundleActiveShutdownCallbackService(bundleActiveCore_); powerStateCallback_ = new (std::nothrow) BundleActivePowerStateCallbackService(bundleActiveCore_); + auto& shutdownClient = OHOS::PowerMgr::ShutdownClient::GetInstance(); auto& powerManagerClient = OHOS::PowerMgr::PowerMgrClient::GetInstance(); if (shutdownCallback_) { - powerManagerClient.RegisterShutdownCallback(shutdownCallback_); + shutdownClient.RegisterShutdownCallback(shutdownCallback_); } if (powerStateCallback_) { powerManagerClient.RegisterPowerStateCallback(powerStateCallback_); @@ -225,8 +227,9 @@ bool BundleActiveService::SubscribeContinuousTask() void BundleActiveService::OnStop() { if (shutdownCallback_ != nullptr) { + auto& shutdownClient = OHOS::PowerMgr::ShutdownClient::GetInstance(); auto& powerManagerClient = OHOS::PowerMgr::PowerMgrClient::GetInstance(); - powerManagerClient.UnRegisterShutdownCallback(shutdownCallback_); + shutdownClient.UnRegisterShutdownCallback(shutdownCallback_); powerManagerClient.UnRegisterPowerStateCallback(powerStateCallback_); return; } diff --git a/services/common/src/bundle_active_shutdown_callback_proxy.cpp b/services/common/src/bundle_active_shutdown_callback_proxy.cpp deleted file mode 100644 index a8c60c3..0000000 --- a/services/common/src/bundle_active_shutdown_callback_proxy.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022 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 "bundle_active_shutdown_callback_proxy.h" - -namespace OHOS { -namespace DeviceUsageStats { -void BundleActiveShutdownCallbackProxy::ShutdownCallback() -{ - sptr remote = Remote(); - if (remote == nullptr) { - return; - } - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!data.WriteInterfaceToken(BundleActiveShutdownCallbackProxy::GetDescriptor())) { - return; - } - int32_t ret = remote->SendRequest(IShutdownCallback::POWER_SHUTDOWN_CHANGED, data, reply, option); - if (ret != ERR_OK) { - BUNDLE_ACTIVE_LOGE("BundleActiveShutdownCallbackProxy::ShutdownCallback failed!"); - } -} -} // namespace DeviceUsageStats -} // namespace OHOS - diff --git a/services/common/src/bundle_active_shutdown_callback_service.cpp b/services/common/src/bundle_active_shutdown_callback_service.cpp index 18d469a..c6676f4 100644 --- a/services/common/src/bundle_active_shutdown_callback_service.cpp +++ b/services/common/src/bundle_active_shutdown_callback_service.cpp @@ -25,7 +25,7 @@ BundleActiveShutdownCallbackService::BundleActiveShutdownCallbackService( } } -void BundleActiveShutdownCallbackService::ShutdownCallback() +void BundleActiveShutdownCallbackService::OnAsyncShutdown() { bundleActiveCore_->ShutDown(); } diff --git a/services/common/src/bundle_active_shutdown_callback_stub.cpp b/services/common/src/bundle_active_shutdown_callback_stub.cpp deleted file mode 100644 index 5380b59..0000000 --- a/services/common/src/bundle_active_shutdown_callback_stub.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2022 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 "bundle_active_shutdown_callback_stub.h" -#include "bundle_active_log.h" -#include "errors.h" -#include "ipc_object_stub.h" - -namespace OHOS { -namespace DeviceUsageStats { -int32_t BundleActiveShutdownCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel &reply, - MessageOption &option) -{ - std::u16string descriptor = BundleActiveShutdownCallbackStub::GetDescriptor(); - std::u16string remoteDescriptor = data.ReadInterfaceToken(); - if (descriptor != remoteDescriptor) { - BUNDLE_ACTIVE_LOGI("BundleActiveShutdownCallbackStub::OnRemoteRequest cannot get power mgr service"); - return -1; - } - switch (code) { - case IShutdownCallback::POWER_SHUTDOWN_CHANGED: { - ShutdownStub(); - return ERR_OK; - } - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } -} - -void BundleActiveShutdownCallbackStub::ShutdownStub() -{ - ShutdownCallback(); -} -} // namespace DeviceUsageStats -} // namespace OHOS - -- Gitee