diff --git a/wm/BUILD.gn b/wm/BUILD.gn index e87036d61b43bf22cb581b18629e2b440eef885d..b311dc9c4154c64b0823f9f77204c8163b566eaf 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -146,6 +146,7 @@ ohos_shared_library("libwm") { "src/window_manager.cpp", "src/window_manager_agent.cpp", "src/window_option.cpp", + "src/window_prepare_terminate.cpp", "src/window_scene.cpp", "src/zidl/window_manager_agent_stub.cpp", "src/zidl/window_stub.cpp", diff --git a/wm/include/window_prepare_terminate.h b/wm/include/window_prepare_terminate.h new file mode 100644 index 0000000000000000000000000000000000000000..8a9650f9f84c425b7b175a85c2b3cee91676a5f7 --- /dev/null +++ b/wm/include/window_prepare_terminate.h @@ -0,0 +1,29 @@ +/* + * 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 + * + * 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 OHOS_WINDOW_PREPARE_TERMINATE_H +#define OHOS_WINDOW_PREPARE_TERMINATE_H + +#include "prepare_terminate_callback_stub.h" + +namespace OHOS { +namespace Rosen { +class WindowPrepareTerminateHandler : public AAFwk::PrepareTerminateCallbackStub { +public: + virtual void DoPrepareTerminate() override; +}; +} // namespace Rosen +} // namespace OHOS +#endif // OHOS_WINDOW_PREPARE_TERMINATE_H diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index 3d3a156b9461230d965a9cbd8a487621f8381f0b..a37ddea92b0eec3c58bca17a6581139d3020c129 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -38,6 +38,8 @@ #include "wm_common_inner.h" #include "wm_math.h" +#include "window_prepare_terminate.h" + namespace OHOS { namespace Rosen { namespace { @@ -2204,7 +2206,22 @@ void WindowImpl::HandleBackKeyPressedEvent(const std::shared_ptr& // TerminateAbility will invoke last ability, CloseAbility will not. bool shouldTerminateAbility = WindowHelper::IsFullScreenWindow(property_->GetWindowMode()); if (shouldTerminateAbility) { - abilityContext->TerminateSelf(); + sptr callback = new WindowPrepareTerminateHandler(); + if (callback == nullptr) { + WLOGI("luc000,callback==nullptr"); + } else { + WLOGI("luc000,callback!=nullptr"); + } + if (AAFwk::AbilityManagerClient::GetInstance()->PrepareTerminateAbility(abilityContext->GetToken(), callback) != ERR_OK) { + WLOGFE("luc000,RegisterWindowManagerServiceHandler failed"); + } + if (callback == nullptr) { + WLOGI("luc000,prepare over,callback==nullptr"); + } else { + WLOGI("luc000,prepare over,callback!=nullptr"); + abilityContext->TerminateSelf(); + } + // abilityContext->TerminateSelf(); } else { abilityContext->CloseAbility(); } diff --git a/wm/src/window_prepare_terminate.cpp b/wm/src/window_prepare_terminate.cpp new file mode 100644 index 0000000000000000000000000000000000000000..93fcb8263fbbbb6e4c835aad78dfcc03d82dda07 --- /dev/null +++ b/wm/src/window_prepare_terminate.cpp @@ -0,0 +1,29 @@ +/* + * 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 + * + * 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 "window_prepare_terminate.h" +#include "window_manager_hilog.h" + +namespace OHOS { +namespace Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowPrepareTerminateHandler"}; +} +void WindowPrepareTerminateHandler::DoPrepareTerminate() +{ + WLOGI("luc,okokok,WindowPrepareTerminateHandler::DoPrepareTerminate."); +} +} // namespace Rosen +} // namespace OHOS