1 /* 2 * Copyright (c) 2021 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) 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 * @return none. 85 */ 86 void OnUpdate(const int64_t formId) override; 87 88 /** 89 * @brief Called when the form provider is notified that a temporary form is successfully converted to 90 * a normal form. 91 * 92 * @param formId Indicates the ID of the form. 93 * @return None. 94 */ 95 void OnCastTemptoNormal(const int64_t formId) override; 96 97 /** 98 * @brief Called when the form provider receives form events from the fms. 99 * 100 * @param formEventsMap Indicates the form events occurred. The key in the Map object indicates the form ID, 101 * and the value indicates the event type, which can be either FORM_VISIBLE 102 * or FORM_INVISIBLE. FORM_VISIBLE means that the form becomes visible, 103 * and FORM_INVISIBLE means that the form becomes invisible. 104 * @return none. 105 */ 106 void OnVisibilityChanged(const std::map<int64_t, int32_t>& formEventsMap) override; 107 108 bool OnShare(int64_t formId, OHOS::AAFwk::WantParams &wantParams) override; 109 110 private: 111 void LoadFormEnv(const OHOS::AAFwk::Want& want); 112 113 static int32_t instanceId_; 114 static const std::string START_PARAMS_KEY; 115 static const std::string URI; 116 }; 117 118 } // namespace OHOS::Ace 119 #endif // FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_CPP_ACE_FORM_ABILITY_H 120