1 /* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_FORM_FWK_FORM_AMS_HELPER_H 17 #define OHOS_FORM_FWK_FORM_AMS_HELPER_H 18 19 #include <singleton.h> 20 21 #include "ability_connect_callback_interface.h" 22 #include "ability_manager_interface.h" 23 #include "form_event_handler.h" 24 #include "form_serial_queue.h" 25 #include "uri.h" 26 27 namespace OHOS { 28 namespace AppExecFwk { 29 using IAbilityConnection = OHOS::AAFwk::IAbilityConnection; 30 using Want = OHOS::AAFwk::Want; 31 /** 32 * @class FormAmsHelper 33 * Ams helpler. 34 */ 35 class FormAmsHelper final : public DelayedRefSingleton<FormAmsHelper> { 36 DECLARE_DELAYED_REF_SINGLETON(FormAmsHelper) 37 public: 38 DISALLOW_COPY_AND_MOVE(FormAmsHelper); 39 /** 40 * @brief SetEventHandler. 41 * @param handler event handler 42 */ SetSerialQueue(const std::shared_ptr<FormSerialQueue> & serialQueue)43 inline void SetSerialQueue(const std::shared_ptr<FormSerialQueue> &serialQueue) 44 { 45 serialQueue_ = serialQueue; 46 } 47 /** 48 * @brief acquire a form ability manager if it not existed, 49 * @return returns the ability manager ipc object or nullptr for failed. 50 */ 51 sptr<AAFwk::IAbilityManager> GetAbilityManager(); 52 /** 53 * @brief Connect session with service ability. 54 * @param want Special want for service type's ability. 55 * @param connect Callback used to notify caller the result of connecting or disconnecting. 56 * @return Returns ERR_OK on success, others on failure. 57 */ 58 ErrCode ConnectServiceAbility( 59 const Want &want, const sptr<AAFwk::IAbilityConnection> &connect); 60 /** 61 * @brief Disconnect session with service ability. 62 * @param want Special want for service type's ability. 63 * @param connect Callback used to notify caller the result of connecting or disconnecting. 64 * @return Returns ERR_OK on success, others on failure. 65 */ 66 ErrCode DisconnectServiceAbility(const sptr<AAFwk::IAbilityConnection> &connect); 67 /** 68 * @brief Disconnect ability delay, disconnect session with service ability. 69 * @param want Special want for service type's ability. 70 * @param connect Callback used to notify caller the result of connecting or disconnecting. 71 * @return Returns ERR_OK on success, others on failure. 72 */ 73 ErrCode DisconnectServiceAbilityDelay(const sptr<AAFwk::IAbilityConnection> &connect); 74 /** 75 * @brief StartAbility with want, send want to ability manager service. 76 * @param want The want of the ability to start. 77 * @param userId Designation User ID. 78 * @return Returns ERR_OK on success, others on failure. 79 */ 80 ErrCode StartAbility(const Want &want, int32_t userId); 81 /** 82 * @brief Add the ability manager instance for debug. 83 * @param abilityManager the ability manager ipc object. 84 */ 85 void SetAbilityManager(const sptr<AAFwk::IAbilityManager> &abilityManager); 86 /** 87 * @brief StopExtensionAbility with want, send want to ability manager service. 88 * @param want The want of the ability to start. 89 * @return Returns ERR_OK on success, others on failure. 90 */ 91 ErrCode StopExtensionAbility(const Want &want); 92 private: 93 /** 94 * @brief Disconnect ability task, disconnect session with service ability. 95 * @param want Special want for service type's ability. 96 * @param connect Callback used to notify caller the result of connecting or disconnecting. 97 */ 98 void DisconnectAbilityTask(const sptr<AAFwk::IAbilityConnection> &connect); 99 private: 100 sptr<AAFwk::IAbilityManager> abilityManager_ = nullptr; 101 std::shared_ptr<FormSerialQueue> serialQueue_ = nullptr; 102 }; 103 } // namespace AppExecFwk 104 } // namespace OHOS 105 106 #endif // OHOS_FORM_FWK_FORM_AMS_HELPER_H 107