diff --git a/frameworks/kits/ability/ability_runtime/test/mock/AMS/mock_serviceability_manager_service.h b/frameworks/kits/ability/ability_runtime/test/mock/AMS/mock_serviceability_manager_service.h index 5d1052f930..0bf58a0691 100644 --- a/frameworks/kits/ability/ability_runtime/test/mock/AMS/mock_serviceability_manager_service.h +++ b/frameworks/kits/ability/ability_runtime/test/mock/AMS/mock_serviceability_manager_service.h @@ -271,7 +271,7 @@ public: return 0; } - virtual int RegisterWindowHandler(const sptr& handler) override + virtual int RegisterWindowManagerServiceHandler(const sptr& handler) override { return 0; } diff --git a/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h b/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h index 1352b55cd1..58110fa1a1 100644 --- a/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h +++ b/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h @@ -254,7 +254,7 @@ public: return 0; } - virtual int RegisterWindowHandler(const sptr& handler) override + virtual int RegisterWindowManagerServiceHandler(const sptr& handler) override { return 0; } diff --git a/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h b/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h index 1a47a7dfb5..977a5b1443 100644 --- a/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h +++ b/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h @@ -231,7 +231,7 @@ public: return 0; } - virtual int RegisterWindowHandler(const sptr& handler) override + virtual int RegisterWindowManagerServiceHandler(const sptr& handler) override { return 0; } diff --git a/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h b/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h index dfbb2e4898..142c74d787 100644 --- a/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h +++ b/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h @@ -244,7 +244,7 @@ public: return 0; } - virtual int RegisterWindowHandler(const sptr& handler) override + virtual int RegisterWindowManagerServiceHandler(const sptr& handler) override { return 0; } diff --git a/interfaces/innerkits/ability_manager/BUILD.gn b/interfaces/innerkits/ability_manager/BUILD.gn index 62246b7cff..161ca8a504 100644 --- a/interfaces/innerkits/ability_manager/BUILD.gn +++ b/interfaces/innerkits/ability_manager/BUILD.gn @@ -86,6 +86,8 @@ ohos_shared_library("ability_manager") { "${services_path}/abilitymgr/src/want_sender_proxy.cpp", "${services_path}/abilitymgr/src/want_sender_stub.cpp", "${services_path}/abilitymgr/src/wants_info.cpp", + "src/window_manager_service_handler_proxy.cpp", + "src/window_manager_service_handler_stub.cpp", ] public_configs = [ diff --git a/interfaces/innerkits/ability_manager/include/ability_manager_client.h b/interfaces/innerkits/ability_manager/include/ability_manager_client.h index 65d8a7a61c..fcef1af2f6 100644 --- a/interfaces/innerkits/ability_manager/include/ability_manager_client.h +++ b/interfaces/innerkits/ability_manager/include/ability_manager_client.h @@ -538,13 +538,6 @@ public: */ ErrCode RegisterSnapshotHandler(const sptr& handler); - /** - * @brief Register the window handler - * @param handler window handler - * @return ErrCode Returns ERR_OK on success, others on failure. - */ - ErrCode RegisterWindowHandler(const sptr& handler); - /** * Set mission label of this ability. * @@ -564,6 +557,13 @@ public: */ ErrCode SetMissionIcon(const sptr &abilityToken, const std::shared_ptr &icon); + + /** + * @brief Register the WMS handler + * @param handler WMS handler + * @return ErrCode Returns ERR_OK on success, others on failure. + */ + ErrCode RegisterWindowManagerServiceHandler(const sptr& handler); #endif /** diff --git a/interfaces/innerkits/ability_manager/include/ability_manager_interface.h b/interfaces/innerkits/ability_manager/include/ability_manager_interface.h index 7652590bc8..f30b2770e1 100644 --- a/interfaces/innerkits/ability_manager/include/ability_manager_interface.h +++ b/interfaces/innerkits/ability_manager/include/ability_manager_interface.h @@ -22,28 +22,28 @@ #include #include "ability_connect_callback_interface.h" +#include "ability_running_info.h" #include "ability_scheduler_interface.h" #include "ability_start_setting.h" -#include "foundation/aafwk/standard/interfaces/innerkits/app_manager/include/appmgr/configuration.h" -#include "mission_snapshot.h" -#include "ability_running_info.h" #include "extension_running_info.h" -#include "uri.h" -#include "want.h" -#include "want_sender_info.h" -#include "sender_info.h" -#include "want_sender_interface.h" -#include "want_receiver_interface.h" -#include "system_memory_attr.h" -#include "system_memory_attr.h" +#include "foundation/aafwk/standard/interfaces/innerkits/app_manager/include/appmgr/configuration.h" +#include "iability_controller.h" #include "mission_listener_interface.h" #include "mission_info.h" +#include "mission_snapshot.h" +#include "remote_mission_listener_interface.h" +#include "running_process_info.h" +#include "sender_info.h" #include "snapshot.h" #include "start_options.h" #include "stop_user_callback.h" -#include "running_process_info.h" -#include "remote_mission_listener_interface.h" -#include "iability_controller.h" +#include "system_memory_attr.h" +#include "want.h" +#include "want_receiver_interface.h" +#include "want_sender_info.h" +#include "want_sender_interface.h" +#include "uri.h" +#include "window_manager_service_handler.h" namespace OHOS { namespace AAFwk { @@ -433,6 +433,8 @@ public: #ifdef SUPPORT_GRAPHICS virtual int SetMissionIcon(const sptr &token, const std::shared_ptr &icon) = 0; + + virtual int RegisterWindowManagerServiceHandler(const sptr& handler) = 0; #endif virtual int GetAbilityRunningInfos(std::vector &info) = 0; @@ -547,8 +549,6 @@ public: */ virtual int32_t GetMissionIdByToken(const sptr &token) = 0; - virtual int RegisterWindowHandler(const sptr& handler) = 0; - #ifdef ABILITY_COMMAND_FOR_TEST /** * Block ability manager service. @@ -879,7 +879,7 @@ public: DUMPSYS_STATE = 2002, FORCE_TIMEOUT, - REGISTER_WINDOW_HANDLER = 2500, + REGISTER_WMS_HANDLER = 2500, GET_TOP_ABILITY = 3000, FREE_INSTALL_ABILITY_FROM_REMOTE = 3001, diff --git a/interfaces/innerkits/ability_manager/include/snapshot.h b/interfaces/innerkits/ability_manager/include/snapshot.h index 7096d58db4..0110a8a5fc 100644 --- a/interfaces/innerkits/ability_manager/include/snapshot.h +++ b/interfaces/innerkits/ability_manager/include/snapshot.h @@ -66,23 +66,6 @@ public: */ virtual int32_t GetSnapshot(const sptr& token, Snapshot& snapshot) = 0; }; - - -/** - * @class IWindowHandler - * Window handler, use to get window - */ -class IWindowHandler : public OHOS::IRemoteBroker { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.aafwk.WindowHandler"); - - /** - * @brief Get the Window object - * @param abilityToken ability token - * @return int32_t function result - */ - virtual int32_t GetFocusAbility(sptr& abilityToken); -}; } // namespace AAFwk } // namespace OHOS #endif // OHOS_AAFWK_SNAPSHOT_H \ No newline at end of file diff --git a/interfaces/innerkits/ability_manager/include/window_info.h b/interfaces/innerkits/ability_manager/include/window_info.h new file mode 100644 index 0000000000..0365b19473 --- /dev/null +++ b/interfaces/innerkits/ability_manager/include/window_info.h @@ -0,0 +1,79 @@ +/* + * 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 OHOS_AAFWK_WINDOW_TRANSITION_INFO_H +#define OHOS_AAFWK_WINDOW_TRANSITION_INFO_H + +#ifdef SUPPORT_GRAPHICS +#include + +#include "iremote_object.h" +#include "parcel.h" + +namespace OHOS { +namespace AAFwk { +struct AbilityTransitionInfo : public Parcelable { + std::string bundleName_; + std::string abilityName_; + uint32_t mode_ = 1; + sptr abilityToken_ = nullptr; + uint64_t displayId_ = 0; + bool isShowWhenLocked_ = false; + + virtual bool Marshalling(Parcel& parcel) const override + { + if (!parcel.WriteString(bundleName_)) { + return false; + } + + if (!parcel.WriteString(abilityName_)) { + return false; + } + + if (!parcel.WriteUint32(mode_)) { + return false; + } + + if (!parcel.WriteObject(abilityToken_)) { + return false; + } + + if (!parcel.WriteUint64(displayId_)) { + return false; + } + + if (!parcel.WriteBool(isShowWhenLocked_)) { + return false; + } + + return true; + } + + static AbilityTransitionInfo* Unmarshalling(Parcel& parcel) + { + AbilityTransitionInfo* info = new AbilityTransitionInfo(); + info->bundleName_ = parcel.ReadString(); + info->abilityName_ = parcel.ReadString(); + info->mode_ = parcel.ReadUint32(); + info->abilityToken_ = parcel.ReadObject(); + info->displayId_ = parcel.ReadUint64(); + info->isShowWhenLocked_ = parcel.ReadBool(); + return info; + } +}; +} // namespace AAFwk +} // namespace OHOS +#endif +#endif // OHOS_AAFWK_WINDOW_TRANSITION_INFO_H \ No newline at end of file diff --git a/interfaces/innerkits/ability_manager/include/window_manager_service_handler.h b/interfaces/innerkits/ability_manager/include/window_manager_service_handler.h new file mode 100644 index 0000000000..43549e3243 --- /dev/null +++ b/interfaces/innerkits/ability_manager/include/window_manager_service_handler.h @@ -0,0 +1,43 @@ +/* + * 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 OHOS_AAFWK_WMS_HANDLER_H +#define OHOS_AAFWK_WMS_HANDLER_H + +#ifdef SUPPORT_GRAPHICS +#include "iremote_broker.h" +#include "window_info.h" + +namespace OHOS { +namespace AAFwk { +/** + * @class IWindowManagerServiceHandler + * Window Manager Service Handler, use to call methods of WMS + */ +class IWindowManagerServiceHandler : public OHOS::IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.aafwk.WindowManagerServiceHandler"); + + virtual void NotifyWindowTransition(sptr fromInfo, sptr toInfo) = 0; + + enum WMSCmd { + // ipc id for NotifyWindowTransition + ON_NOTIFY_WINDOW_TRANSITION, + }; +}; +} // namespace AAFwk +} // namespace OHOS +#endif +#endif // OHOS_AAFWK_WMS_HANDLER_H \ No newline at end of file diff --git a/interfaces/innerkits/ability_manager/include/window_manager_service_handler_proxy.h b/interfaces/innerkits/ability_manager/include/window_manager_service_handler_proxy.h new file mode 100644 index 0000000000..29de0e263c --- /dev/null +++ b/interfaces/innerkits/ability_manager/include/window_manager_service_handler_proxy.h @@ -0,0 +1,39 @@ +/* + * 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 OHOS_AAFWK_WMS_HANDLER_PROXY_H +#define OHOS_AAFWK_WMS_HANDLER_PROXY_H + +#ifdef SUPPORT_GRAPHICS +#include "iremote_proxy.h" +#include "window_manager_service_handler.h" + +namespace OHOS { +namespace AAFwk { +class WindowManagerServiceHandlerProxy : public IRemoteProxy { +public: + explicit WindowManagerServiceHandlerProxy(const sptr &impl); + virtual ~WindowManagerServiceHandlerProxy() = default; + + virtual void NotifyWindowTransition(sptr fromInfo, + sptr toInfo) override; + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace AAFwk +} // namespace OHOS +#endif +#endif // OHOS_AAFWK_WMS_HANDLER_PROXY_H diff --git a/interfaces/innerkits/ability_manager/include/window_manager_service_handler_stub.h b/interfaces/innerkits/ability_manager/include/window_manager_service_handler_stub.h new file mode 100644 index 0000000000..a1d62f04f4 --- /dev/null +++ b/interfaces/innerkits/ability_manager/include/window_manager_service_handler_stub.h @@ -0,0 +1,40 @@ +/* + * 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 OHOS_AAFWK_WMS_HANDLER_STUB_H +#define OHOS_AAFWK_WMS_HANDLER_STUB_H + +#ifdef SUPPORT_GRAPHICS +#include "iremote_stub.h" +#include "message_parcel.h" +#include "nocopyable.h" +#include "window_manager_service_handler.h" + +namespace OHOS { +namespace AAFwk { +class WindowManagerServiceHandlerStub : public IRemoteStub { +public: + WindowManagerServiceHandlerStub() = default; + virtual ~WindowManagerServiceHandlerStub() = default; + + int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + DISALLOW_COPY_AND_MOVE(WindowManagerServiceHandlerStub); +}; +} // namespace AAFwk +} // namespace OHOS +#endif +#endif // OHOS_AAFWK_WMS_HANDLER_STUB_H diff --git a/interfaces/innerkits/ability_manager/src/window_manager_service_handler_proxy.cpp b/interfaces/innerkits/ability_manager/src/window_manager_service_handler_proxy.cpp new file mode 100644 index 0000000000..bbd016bda5 --- /dev/null +++ b/interfaces/innerkits/ability_manager/src/window_manager_service_handler_proxy.cpp @@ -0,0 +1,53 @@ +/* + * 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. + */ + +#ifdef SUPPORT_GRAPHICS +#include "window_manager_service_handler_proxy.h" + +#include "hilog_wrapper.h" +#include "parcel.h" + +namespace OHOS { +namespace AAFwk { +WindowManagerServiceHandlerProxy::WindowManagerServiceHandlerProxy(const sptr &impl) + : IRemoteProxy(impl) {} + +void WindowManagerServiceHandlerProxy::NotifyWindowTransition(sptr fromInfo, + sptr toInfo) +{ + HILOG_DEBUG("%{public}s is called.", __func__); + MessageParcel data; + if (!data.WriteInterfaceToken(IWindowManagerServiceHandler::GetDescriptor())) { + HILOG_ERROR("Write interface token failed."); + return; + } + if (!data.WriteParcelable(fromInfo.GetRefPtr())) { + HILOG_ERROR("Write fromInfo failed."); + return; + } + if (!data.WriteParcelable(toInfo.GetRefPtr())) { + HILOG_ERROR("Write toInfo failed."); + return; + } + MessageParcel reply; + MessageOption option; + int error = Remote()->SendRequest(WMSCmd::ON_NOTIFY_WINDOW_TRANSITION, data, reply, option); + if (error != ERR_OK) { + HILOG_ERROR("SendRequest fial, error: %{public}d", error); + } +} +} // namespace AAFwk +} // namespace OHOS +#endif diff --git a/interfaces/innerkits/ability_manager/src/window_manager_service_handler_stub.cpp b/interfaces/innerkits/ability_manager/src/window_manager_service_handler_stub.cpp new file mode 100644 index 0000000000..dd7fa2f320 --- /dev/null +++ b/interfaces/innerkits/ability_manager/src/window_manager_service_handler_stub.cpp @@ -0,0 +1,55 @@ +/* + * 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. + */ + +#ifdef SUPPORT_GRAPHICS +#include "window_manager_service_handler_stub.h" + +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AAFwk { +int WindowManagerServiceHandlerStub::OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + if (data.ReadInterfaceToken() != IWindowManagerServiceHandler::GetDescriptor()) { + HILOG_ERROR("InterfaceToken not equal IWindowManagerServiceHandler's descriptor."); + return ERR_INVALID_VALUE; + } + ErrCode errCode = ERR_OK; + switch (code) { + case WMSCmd::ON_NOTIFY_WINDOW_TRANSITION : { + sptr fromInfo(data.ReadParcelable()); + if (!fromInfo) { + errCode = ERR_DEAD_OBJECT; + HILOG_ERROR("To read fromInfo failed."); + break; + } + sptr toInfo(data.ReadParcelable()); + if (!toInfo) { + errCode = ERR_DEAD_OBJECT; + HILOG_ERROR("To read toInfo failed."); + break; + } + NotifyWindowTransition(fromInfo, toInfo); + break; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + return errCode; +} +} // namespace AAFwk +} // namespace OHOS +#endif diff --git a/services/abilitymgr/include/ability_config.h b/services/abilitymgr/include/ability_config.h index c223f62f43..98d76fd2d3 100644 --- a/services/abilitymgr/include/ability_config.h +++ b/services/abilitymgr/include/ability_config.h @@ -63,6 +63,9 @@ const std::string SCREEN_LOCK_ABILITY_NAME = "com.ohos.screenlock.ServiceExtAbil const std::string SCREEN_LOCK_BUNDLE_NAME = "com.ohos.screenlock"; const std::string PARAMS_STREAM = "ability.params.stream"; + +const std::string GRANT_ABILITY_BUNDLE_NAME = "com.ohos.permissionmanager"; +const std::string GRANT_ABILITY_ABILITY_NAME = "com.ohos.permissionmanager.GrantAbility"; } // namespace AbilityConfig } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 0b67f41189..d61428a91b 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -407,6 +407,8 @@ public: #ifdef SUPPORT_GRAPHICS virtual int SetMissionIcon(const sptr &token, const std::shared_ptr &icon) override; + + virtual int RegisterWindowManagerServiceHandler(const sptr& handler) override; #endif virtual int GetAbilityRunningInfos(std::vector &info) override; @@ -439,8 +441,6 @@ public: virtual int RegisterSnapshotHandler(const sptr& handler) override; - virtual int RegisterWindowHandler(const sptr& handler) override; - virtual int GetMissionSnapshot(const std::string& deviceId, int32_t missionId, MissionSnapshot& snapshot) override; virtual int StartUserTest(const Want &want, const sptr &observer) override; diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 22a2f5b56c..6fe1c0cf24 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -592,14 +592,16 @@ public: #ifdef SUPPORT_GRAPHICS virtual int SetMissionIcon(const sptr &token, const std::shared_ptr &icon) override; + + virtual int RegisterWindowManagerServiceHandler(const sptr& handler) override; + + sptr GetWMSHandler() const; #endif void ClearUserData(int32_t userId); virtual int RegisterSnapshotHandler(const sptr& handler) override; - virtual int RegisterWindowHandler(const sptr& handler) override; - virtual int32_t GetMissionSnapshot(const std::string& deviceId, int32_t missionId, MissionSnapshot& snapshot) override; @@ -1038,7 +1040,9 @@ private: std::unordered_map> missionListManagers_; std::shared_ptr currentMissionListManager_; - sptr windowHandler_; +#ifdef SUPPORT_GRAPHICS + sptr wmsHandler_; +#endif std::shared_ptr userController_; sptr abilityController_ = nullptr; bool controllerIsAStabilityTest_ = false; diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index d99a365281..bffa8ac7b2 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -152,7 +152,9 @@ private: int IsRunningInStabilityTestInner(MessageParcel &data, MessageParcel &reply); int MoveMissionToFrontByOptionsInner(MessageParcel &data, MessageParcel &reply); - int RegisterWindowHandlerInner(MessageParcel &data, MessageParcel &reply); +#ifdef SUPPORT_GRAPHICS + int RegisterWindowManagerServiceHandlerInner(MessageParcel &data, MessageParcel &reply); +#endif #ifdef ABILITY_COMMAND_FOR_TEST int ForceTimeoutForTestInner(MessageParcel &data, MessageParcel &reply); diff --git a/services/abilitymgr/include/mission_list_manager.h b/services/abilitymgr/include/mission_list_manager.h index 994926e5f4..81cccd1de0 100644 --- a/services/abilitymgr/include/mission_list_manager.h +++ b/services/abilitymgr/include/mission_list_manager.h @@ -29,6 +29,9 @@ #include "snapshot.h" #include "start_options.h" #include "want.h" +#ifdef SUPPORT_GRAPHICS +#include "window_manager_service_handler.h" +#endif namespace OHOS { namespace AAFwk { @@ -432,6 +435,18 @@ private: void AddUninstallTags(const std::string &bundleName, int32_t uid); +#ifdef SUPPORT_GRAPHICS + void NotifyAnimationFromRecentTask(const std::shared_ptr &abilityRecord, + const std::shared_ptr &startOptions, const Want &want) const; + void NotifyAnimationFromStartingAbility(const std::shared_ptr &callerAbility, + const AbilityRequest &abilityRequest, const std::shared_ptr &targetAbilityRecord) const; + void SetShowWhenLocked(const AppExecFwk::AbilityInfo &abilityInfo, sptr &info) const; + void SetAbilityTransitionInfo(const AppExecFwk::AbilityInfo &abilityInfo, sptr &info, + const std::shared_ptr &abilityRecord) const; + void SetWindowModeAndDisplayId(sptr &info, const Want &want) const; + sptr GetWMSHandler() const; +#endif + private: int userId_; mutable std::recursive_mutex managerLock_; diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 4c86c49d10..00f0435c28 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -659,13 +659,6 @@ ErrCode AbilityManagerClient::RegisterSnapshotHandler(const sptrRegisterSnapshotHandler(handler); } -ErrCode AbilityManagerClient::RegisterWindowHandler(const sptr& handler) -{ - auto abms = GetAbilityManager(); - CHECK_POINTER_RETURN_NOT_CONNECTED(abms); - return abms->RegisterWindowHandler(handler); -} - ErrCode AbilityManagerClient::GetMissionSnapshot(const std::string& deviceId, int32_t missionId, MissionSnapshot& snapshot) { @@ -725,6 +718,13 @@ ErrCode AbilityManagerClient::SetMissionIcon( CHECK_POINTER_RETURN_NOT_CONNECTED(abms); return abms->SetMissionIcon(abilityToken, icon); } + +ErrCode AbilityManagerClient::RegisterWindowManagerServiceHandler(const sptr& handler) +{ + auto abms = GetAbilityManager(); + CHECK_POINTER_RETURN_NOT_CONNECTED(abms); + return abms->RegisterWindowManagerServiceHandler(handler); +} #endif ErrCode AbilityManagerClient::DoAbilityForeground(const sptr &token, uint32_t flag) diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 8f536ed1de..9e01baef39 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -1757,6 +1757,31 @@ int AbilityManagerProxy::SetMissionIcon(const sptr &token, } return reply.ReadInt32(); } + +int AbilityManagerProxy::RegisterWindowManagerServiceHandler(const sptr& handler) +{ + if (!handler) { + HILOG_ERROR("%{public}s: handler is nullptr.", __func__); + return INNER_ERR; + } + MessageParcel data; + if (!WriteInterfaceToken(data)) { + HILOG_ERROR("%{public}s: write interface token failed.", __func__); + return INNER_ERR; + } + if (!data.WriteRemoteObject(handler->AsObject())) { + HILOG_ERROR("%{public}s: handler write failed.", __func__); + return INNER_ERR; + } + MessageOption option; + MessageParcel reply; + auto error = Remote()->SendRequest(IAbilityManager::REGISTER_WMS_HANDLER, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("%{public}s: send request error: %{public}d", __func__, error); + return error; + } + return reply.ReadInt32(); +} #endif int AbilityManagerProxy::GetAbilityRunningInfos(std::vector &info) @@ -2012,26 +2037,6 @@ int AbilityManagerProxy::RegisterSnapshotHandler(const sptr& h return reply.ReadInt32(); } -int AbilityManagerProxy::RegisterWindowHandler(const sptr& handler) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option; - if (!WriteInterfaceToken(data)) { - return INNER_ERR; - } - if (!data.WriteRemoteObject(handler->AsObject())) { - HILOG_ERROR("window: handler write failed."); - return INNER_ERR; - } - auto error = Remote()->SendRequest(IAbilityManager::REGISTER_WINDOW_HANDLER, data, reply, option); - if (error != NO_ERROR) { - HILOG_ERROR("window: send request error: %{public}d", error); - return error; - } - return reply.ReadInt32(); -} - int AbilityManagerProxy::SetAbilityController(const sptr &abilityController, bool imAStabilityTest) { diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 8198b1d80d..db0af6e725 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -3273,6 +3273,23 @@ int AbilityManagerService::SetMissionIcon(const sptr &token, return missionListManager->SetMissionIcon(token, icon); } + +int AbilityManagerService::RegisterWindowManagerServiceHandler(const sptr &handler) +{ + auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); + if (!isSaCall) { + HILOG_ERROR("%{public}s: Permission verification failed", __func__); + return CHECK_PERMISSION_FAILED; + } + wmsHandler_ = handler; + HILOG_DEBUG("%{public}s: WMS handler registered successfully.", __func__); + return ERR_OK; +} + +sptr AbilityManagerService::GetWMSHandler() const +{ + return wmsHandler_; +} #endif int AbilityManagerService::StartUser(int userId) @@ -3388,18 +3405,6 @@ int AbilityManagerService::RegisterSnapshotHandler(const sptr& return ERR_OK; } -int AbilityManagerService::RegisterWindowHandler(const sptr &handler) -{ - auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); - if (!isSaCall) { - HILOG_ERROR("%{public}s: Permission verification failed", __func__); - return 0; - } - windowHandler_ = handler; - HILOG_INFO("window: AbilityManagerService register windows handler success."); - return ERR_OK; -} - int32_t AbilityManagerService::GetMissionSnapshot(const std::string& deviceId, int32_t missionId, MissionSnapshot& missionSnapshot) { diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index c32ea39f19..edaa9a110b 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -138,8 +138,10 @@ void AbilityManagerStub::ThirdStepInit() requestFuncMap_[GET_MISSION_ID_BY_ABILITY_TOKEN] = &AbilityManagerStub::GetMissionIdByTokenInner; requestFuncMap_[GET_TOP_ABILITY] = &AbilityManagerStub::GetTopAbilityInner; requestFuncMap_[SET_MISSION_ICON] = &AbilityManagerStub::SetMissionIconInner; - requestFuncMap_[REGISTER_WINDOW_HANDLER] = &AbilityManagerStub::RegisterWindowHandlerInner; requestFuncMap_[DUMP_ABILITY_INFO_DONE] = &AbilityManagerStub::DumpAbilityInfoDoneInner; +#ifdef SUPPORT_GRAPHICS + requestFuncMap_[REGISTER_WMS_HANDLER] = &AbilityManagerStub::RegisterWindowManagerServiceHandlerInner; +#endif } int AbilityManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) @@ -1182,17 +1184,17 @@ int AbilityManagerStub::RegisterSnapshotHandlerInner(MessageParcel &data, Messag return result; } -int AbilityManagerStub::RegisterWindowHandlerInner(MessageParcel &data, MessageParcel &reply) +#ifdef SUPPORT_GRAPHICS +int AbilityManagerStub::RegisterWindowManagerServiceHandlerInner(MessageParcel &data, MessageParcel &reply) { - sptr handler = iface_cast(data.ReadRemoteObject()); + sptr handler = iface_cast(data.ReadRemoteObject()); if (handler == nullptr) { - HILOG_ERROR("window: AbilityManagerStub read window handler failed!"); + HILOG_ERROR("%{public}s read WMS handler failed!", __func__); return ERR_NULL_OBJECT; } - int32_t result = RegisterWindowHandler(handler); - HILOG_INFO("window: AbilityManagerStub register window handler result = %{public}d", result); - return result; + return RegisterWindowManagerServiceHandler(handler); } +#endif int AbilityManagerStub::GetMissionSnapshotInfoInner(MessageParcel &data, MessageParcel &reply) { diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission_list_manager.cpp index cfc500b1f2..3ea3555806 100644 --- a/services/abilitymgr/src/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission_list_manager.cpp @@ -34,6 +34,7 @@ constexpr char EVENT_KEY_PACKAGE_NAME[] = "PACKAGE_NAME"; constexpr char EVENT_KEY_PROCESS_NAME[] = "PROCESS_NAME"; constexpr uint32_t NEXTABILITY_TIMEOUT = 1000; // ms constexpr uint64_t NANO_SECOND_PER_SEC = 1000000000; // ns +const std::string SHOW_ON_LOCK_SCREEN = "ShowOnLockScreen"; std::string GetCurrentTime() { struct timespec tn; @@ -41,7 +42,8 @@ std::string GetCurrentTime() uint64_t uTime = static_cast(tn.tv_sec) * NANO_SECOND_PER_SEC + tn.tv_nsec; return std::to_string(uTime); } -} +} // namespace + MissionListManager::MissionListManager(int userId) : userId_(userId) {} MissionListManager::~MissionListManager() {} @@ -183,6 +185,18 @@ int MissionListManager::MoveMissionToFront(int32_t missionId, bool isCallerFromL if (startOptions != nullptr) { targetAbilityRecord->SetWindowMode(startOptions->GetWindowMode()); } + +#ifdef SUPPORT_GRAPHICS + InnerMissionInfo innerMissionInfo; + int getMission = DelayedSingleton::GetInstance()->GetInnerMissionInfoById( + missionId, innerMissionInfo); + if (getMission != ERR_OK) { + HILOG_ERROR("cannot find mission info from MissionInfoList by missionId: %{public}d", missionId); + return MOVE_MISSION_FAILED; + } + NotifyAnimationFromRecentTask(targetAbilityRecord, startOptions, innerMissionInfo.missionInfo.want); +#endif + // schedule target ability to foreground. targetAbilityRecord->ProcessForegroundAbility(); HILOG_DEBUG("SetMovingState, missionId: %{public}d", missionId); @@ -245,6 +259,7 @@ int MissionListManager::StartAbilityLocked(const std::shared_ptr HILOG_ERROR("Failed to get mission or record."); return ERR_INVALID_VALUE; } + if (abilityRequest.IsContinuation()) { targetAbilityRecord->SetLaunchReason(LaunchReason::LAUNCHREASON_CONTINUATION); } else { @@ -259,6 +274,13 @@ int MissionListManager::StartAbilityLocked(const std::shared_ptr // 4. move target list to top MoveMissionListToTop(targetList); +#ifdef SUPPORT_GRAPHICS + auto state = targetAbilityRecord->GetAbilityState(); + if (state != AbilityState::FOREGROUND && state != AbilityState::FOREGROUNDING) { + NotifyAnimationFromStartingAbility(callerAbility, abilityRequest, targetAbilityRecord); + } +#endif + // 5. schedule target ability if (!currentTopAbility) { // top ability is null, then launch the first Ability. @@ -1908,6 +1930,119 @@ int MissionListManager::SetMissionIcon(const sptr &token, const s return 0; } + +void MissionListManager::SetShowWhenLocked(const AppExecFwk::AbilityInfo &abilityInfo, + sptr &info) const +{ + bool showOnLockScreen = false; + std::vector datas = abilityInfo.metaData.customizeData; + for (AppExecFwk::CustomizeData data : datas) { + if (data.name == SHOW_ON_LOCK_SCREEN) { + showOnLockScreen = true; + } + } + if (showOnLockScreen) { + info->isShowWhenLocked_ = true; + } +} + +sptr MissionListManager::GetWMSHandler() const +{ + auto abilityMgr = DelayedSingleton::GetInstance(); + if (!abilityMgr) { + HILOG_WARN("%{public}s, Get Ability Manager Service failed.", __func__); + return nullptr; + } + return abilityMgr->GetWMSHandler(); +} + +void MissionListManager::SetAbilityTransitionInfo(const AppExecFwk::AbilityInfo &abilityInfo, + sptr &info, const std::shared_ptr &abilityRecord) const +{ + info->abilityName_ = abilityInfo.name; + info->bundleName_ = abilityInfo.bundleName; + info->abilityToken_ = abilityRecord->GetToken(); + SetShowWhenLocked(abilityInfo, info); +} + +void MissionListManager::SetWindowModeAndDisplayId(sptr &info, const Want &want) const +{ + auto mode = want.GetIntParam(Want::PARAM_RESV_WINDOW_MODE, -1); + auto displayId = want.GetIntParam(Want::PARAM_RESV_DISPLAY_ID, -1); + if (mode != -1) { + info->mode_ = static_cast(mode); + } + if (displayId != -1) { + info->displayId_ = static_cast(displayId); + } +} + +void MissionListManager::NotifyAnimationFromRecentTask(const std::shared_ptr &abilityRecord, + const std::shared_ptr &startOptions, const Want &want) const +{ + auto abilityInfo = abilityRecord->GetAbilityInfo(); + if (abilityInfo.name == AbilityConfig::GRANT_ABILITY_ABILITY_NAME && + abilityInfo.bundleName == AbilityConfig::GRANT_ABILITY_BUNDLE_NAME) { + HILOG_INFO("%{public}s, ignore GrantAbility.", __func__); + return; + } + + auto windowHandler = GetWMSHandler(); + if (!windowHandler) { + HILOG_WARN("%{public}s, Get WMS handler failed.", __func__); + return; + } + + sptr toInfo = new AbilityTransitionInfo(); + if (startOptions != nullptr) { + toInfo->mode_ = static_cast(startOptions->GetWindowMode()); + toInfo->displayId_ = static_cast(startOptions->GetDisplayID()); + } else { + SetWindowModeAndDisplayId(toInfo, want); + } + SetAbilityTransitionInfo(abilityInfo, toInfo, abilityRecord); + sptr fromInfo = new AbilityTransitionInfo(); + windowHandler->NotifyWindowTransition(fromInfo, toInfo); +} + +void MissionListManager::NotifyAnimationFromStartingAbility(const std::shared_ptr &callerAbility, + const AbilityRequest &abilityRequest, const std::shared_ptr &targetAbilityRecord) const +{ + auto abilityInfo = abilityRequest.abilityInfo; + if (abilityInfo.name == AbilityConfig::GRANT_ABILITY_ABILITY_NAME && + abilityInfo.bundleName == AbilityConfig::GRANT_ABILITY_BUNDLE_NAME) { + HILOG_INFO("%{public}s, ignore GrantAbility.", __func__); + return; + } + + auto windowHandler = GetWMSHandler(); + if (!windowHandler) { + HILOG_WARN("%{public}s, Get WMS handler failed.", __func__); + return; + } + + sptr fromInfo = new AbilityTransitionInfo(); + if (callerAbility) { + auto callerAbilityInfo = callerAbility->GetAbilityInfo(); + SetAbilityTransitionInfo(callerAbilityInfo, fromInfo, callerAbility); + } else { + fromInfo->abilityToken_ = abilityRequest.callerToken; + } + + sptr toInfo = new AbilityTransitionInfo(); + auto abilityStartSetting = abilityRequest.startSetting; + if (abilityStartSetting) { + auto mode = std::stoi(abilityStartSetting->GetProperty(AbilityStartSetting::WINDOW_MODE_KEY)); + toInfo->mode_ = static_cast(mode); + auto displayId = std::stoi(abilityStartSetting->GetProperty(AbilityStartSetting::WINDOW_DISPLAY_ID_KEY)); + toInfo->displayId_ = static_cast(displayId); + } else { + SetWindowModeAndDisplayId(toInfo, abilityRequest.want); + } + SetAbilityTransitionInfo(abilityInfo, toInfo, targetAbilityRecord); + + windowHandler->NotifyWindowTransition(fromInfo, toInfo); +} #endif void MissionListManager::Dump(std::vector &info) diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_client_test/ability_manager_stub_mock_test.h b/services/abilitymgr/test/unittest/phone/ability_manager_client_test/ability_manager_stub_mock_test.h index 1e349980fa..1958a0ff5a 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_client_test/ability_manager_stub_mock_test.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_client_test/ability_manager_stub_mock_test.h @@ -220,7 +220,7 @@ public: return 0; } - virtual int RegisterWindowHandler(const sptr& handler) override + virtual int RegisterWindowManagerServiceHandler(const sptr& handler) override { return 0; } diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h index 600087fb7a..e8e11b8b4b 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h @@ -220,7 +220,7 @@ public: return 0; } - virtual int RegisterWindowHandler(const sptr& handler) override + virtual int RegisterWindowManagerServiceHandler(const sptr& handler) override { return 0; } diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h index 2b218ee533..2899a38758 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h @@ -291,7 +291,7 @@ public: return 0; } - virtual int RegisterWindowHandler(const sptr& handler) override + virtual int RegisterWindowManagerServiceHandler(const sptr& handler) override { return 0; } diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h index 3816232c9e..88e0e01ab6 100644 --- a/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h @@ -130,7 +130,7 @@ public: return 0; } - virtual int RegisterWindowHandler(const sptr& handler) override + virtual int RegisterWindowManagerServiceHandler(const sptr& handler) override { return 0; } diff --git a/services/formmgr/test/mock/include/mock_ability_manager.h b/services/formmgr/test/mock/include/mock_ability_manager.h index a82da7a3a9..36790f922c 100644 --- a/services/formmgr/test/mock/include/mock_ability_manager.h +++ b/services/formmgr/test/mock/include/mock_ability_manager.h @@ -679,7 +679,7 @@ public: return 0; } - virtual int RegisterWindowHandler(const sptr& handler) override + virtual int RegisterWindowManagerServiceHandler(const sptr& handler) override { return 0; } diff --git a/services/test/mock/include/mock_ability_mgr_service.h b/services/test/mock/include/mock_ability_mgr_service.h index d2d94ff787..5c1210a165 100644 --- a/services/test/mock/include/mock_ability_mgr_service.h +++ b/services/test/mock/include/mock_ability_mgr_service.h @@ -163,7 +163,7 @@ public: return 0; } - virtual int RegisterWindowHandler(const sptr& handler) override + virtual int RegisterWindowManagerServiceHandler(const sptr& handler) override { return 0; } diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index 4b1dafefe1..5d1ff41b46 100644 --- a/tools/test/mock/mock_ability_manager_stub.h +++ b/tools/test/mock/mock_ability_manager_stub.h @@ -182,7 +182,7 @@ public: return 0; } - virtual int RegisterWindowHandler(const sptr& handler) override + virtual int RegisterWindowManagerServiceHandler(const sptr& handler) override { return 0; }