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 FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_CPP_ACE_FORM_ABILITY_H 17 #define FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_CPP_ACE_FORM_ABILITY_H 18 19 #include <string> 20 #include <vector> 21 22 #include "ability.h" 23 #include "ability_loader.h" 24 #include "iremote_object.h" 25 #include "want.h" 26 27 namespace OHOS::Ace { 28 29 class AceFormAbility final : public OHOS::AppExecFwk::Ability { 30 public: 31 AceFormAbility(); 32 virtual ~AceFormAbility() = default; 33 void OnStart(const OHOS::AAFwk::Want& want, sptr<AAFwk::SessionInfo> sessionInfo = nullptr) override; 34 void OnStop() override; 35 sptr<IRemoteObject> OnConnect(const OHOS::AAFwk::Want& want) override; 36 void OnDisconnect(const OHOS::AAFwk::Want& want) override; 37 38 /** 39 * @brief Called to return a FormProviderInfo object. 40 * 41 * <p>You must override this method if your ability will serve as a form provider to provide a form for clients. 42 * The default implementation returns nullptr. </p> 43 * 44 * @param want Indicates the detailed information for creating a FormProviderInfo. 45 * The Want object must include the form ID, form name of the form, 46 * which can be obtained from Ability#PARAM_FORM_IDENTITY_KEY, 47 * Ability#PARAM_FORM_NAME_KEY, and Ability#PARAM_FORM_DIMENSION_KEY, 48 * respectively. Such form information must be managed as persistent data for further form 49 * acquisition, update, and deletion. 50 * 51 * @return Returns the created FormProviderInfo object. 52 */ 53 OHOS::AppExecFwk::FormProviderInfo OnCreate(const OHOS::AAFwk::Want& want) override; 54 55 /** 56 * @brief Called to notify the form provider that a specified form has been deleted. Override this method if 57 * you want your application, as the form provider, to be notified of form deletion. 58 * 59 * @param formId Indicates the ID of the deleted form. 60 * @return None. 61 */ 62 void OnDelete(const int64_t formId) override; 63 64 /** 65 * @brief Called to notify the form provider to update a specified form. 66 * 67 * @param formId Indicates the ID of the form to update. 68 * @param message Form event message. 69 */ 70 void OnTriggerEvent(const int64_t formId, const std::string& message) override; 71 72 /** 73 * @brief Called to notify the form supplier to acquire form state. 74 * 75 * @param want Indicates the detailed information about the form to be obtained, including 76 * the bundle name, module name, ability name, form name and form dimension. 77 */ 78 virtual AppExecFwk::FormState OnAcquireFormState(const OHOS::AAFwk::Want& want) override; 79 80 /** 81 * @brief Called to notify the form provider to update a specified form. 82 * 83 * @param formId Indicates the ID of the form to update. 84 * @param wantParams Indicates the params of form to update. 85 * @return none. 86 */ 87 void OnUpdate(const int64_t formId, const OHOS::AAFwk::WantParams &wantParams) override; 88 89 /** 90 * @brief Called when the form provider is notified that a temporary form is successfully converted to 91 * a normal form. 92 * 93 * @param formId Indicates the ID of the form. 94 * @return None. 95 */ 96 void OnCastTemptoNormal(const int64_t formId) override; 97 98 /** 99 * @brief Called when the form provider receives form events from the fms. 100 * 101 * @param formEventsMap Indicates the form events occurred. The key in the Map object indicates the form ID, 102 * and the value indicates the event type, which can be either FORM_VISIBLE 103 * or FORM_INVISIBLE. FORM_VISIBLE means that the form becomes visible, 104 * and FORM_INVISIBLE means that the form becomes invisible. 105 * @return none. 106 */ 107 void OnVisibilityChanged(const std::map<int64_t, int32_t>& formEventsMap) override; 108 109 bool OnShare(int64_t formId, OHOS::AAFwk::WantParams &wantParams) override; 110 111 /** 112 * @brief Acquire a form provider remote object. 113 * @return Returns form provider remote object. 114 */ 115 sptr<IRemoteObject> GetFormRemoteObject(); 116 117 private: 118 void LoadFormEnv(const OHOS::AAFwk::Want& want); 119 120 int32_t instanceId_; 121 static const std::string START_PARAMS_KEY; 122 static const std::string URI; 123 sptr<IRemoteObject> formProviderRemoteObject_; 124 }; 125 126 } // namespace OHOS::Ace 127 #endif // FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_CPP_ACE_FORM_ABILITY_H 128