1 /* 2 * Copyright (c) 2021-2022 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_HOST_RECORD_H 17 #define OHOS_FORM_FWK_FORM_HOST_RECORD_H 18 19 #include <unordered_map> 20 #include <vector> 21 #include "form_host_callback.h" 22 #include "form_item_info.h" 23 #include "form_record.h" 24 #include "hilog_wrapper.h" 25 #include "iremote_object.h" 26 27 namespace OHOS { 28 namespace AppExecFwk { 29 /** 30 * @class FormHostRecord 31 * Form host data. 32 */ 33 class FormHostRecord { 34 public: 35 /** 36 * @brief Create form host record. 37 * @param callback remote object. 38 * @param callingUid Calling uid. 39 */ 40 static FormHostRecord CreateRecord(const FormItemInfo &info, const sptr<IRemoteObject> &callback, int callingUid); 41 /** 42 * @brief Add form id. 43 * @param formId The Id of the form. 44 */ 45 void AddForm(int64_t formId); 46 /** 47 * @brief Delete form id. 48 * @param formId The Id of the form. 49 */ 50 void DelForm(int64_t formId); 51 /** 52 * @brief forms_ is empty or not. 53 * @return forms_ is empty or not. 54 */ 55 bool IsEmpty() const; 56 /** 57 * @brief formId is in forms_ or not. 58 * @param formId The Id of the form. 59 * @return formId is in forms_ or not. 60 */ 61 bool Contains(int64_t formId) const; 62 63 /** 64 * @brief Set refresh enable flag. 65 * @param formId The Id of the form. 66 * @param flag True for enable, false for disable. 67 */ 68 void SetEnableRefresh(int64_t formId, bool flag); 69 70 /** 71 * @brief Refresh enable or not. 72 * @param formId The Id of the form. 73 * @return true on enable, false on disable. 74 */ 75 bool IsEnableRefresh(int64_t formId) const; 76 77 /** 78 * @brief Set Update enable flag. 79 * @param formId The Id of the form. 80 * @param enable True for enable, false for disable. 81 */ 82 void SetEnableUpdate(int64_t formId, bool enable); 83 84 /** 85 * @brief update enable or not. 86 * @param formId The Id of the form. 87 * @return true on enable, false on disable. 88 */ 89 bool IsEnableUpdate(int64_t formId) const; 90 91 /** 92 * @brief Set need refresh enable flag. 93 * @param formId The Id of the form. 94 * @param flag True for enable, false for disable. 95 */ 96 void SetNeedRefresh(int64_t formId, bool flag); 97 /** 98 * @brief Need Refresh enable or not. 99 * @param formId The Id of the form. 100 * @return true on enable, false on disable. 101 */ 102 bool IsNeedRefresh(int64_t formId) const; 103 104 /** 105 * @brief Send form data to form host. 106 * @param id The Id of the form. 107 * @param record Form record. 108 */ 109 void OnAcquire(int64_t id, const FormRecord &record); 110 111 /** 112 * @brief Update form data to form host. 113 * @param id The Id of the form. 114 * @param record Form record. 115 */ 116 void OnUpdate(int64_t id, const FormRecord &record); 117 /** 118 * Send form uninstall message to form host. 119 * 120 * @param formIds the uninstalled form id list. 121 */ 122 void OnFormUninstalled(std::vector<int64_t> &formIds); 123 /** 124 * Send form state message to form host. 125 * 126 * @param state The form state. 127 * @param want The want of onAcquireFormState. 128 */ 129 void OnAcquireState(AppExecFwk::FormState state, const AAFwk::Want &want); 130 131 /** 132 * @brief Release resource. 133 */ 134 void CleanResource(); 135 /** 136 * @brief Get caller Uid. 137 * @return the caller Uid. 138 */ GetCallerUid()139 int GetCallerUid() const 140 { 141 return callerUid_; 142 } 143 /** 144 * @brief Get client stub. 145 * @return client stub. 146 */ 147 sptr<IRemoteObject> GetFormHostClient() const; 148 /** 149 * @brief Get death recipient. 150 * @return death recipient. 151 */ 152 sptr<IRemoteObject::DeathRecipient> GetDeathRecipient() const; 153 /** 154 * @brief Set value of caller uid. 155 * @param callerUid Caller uid. 156 */ 157 void SetCallerUid(const int callerUid); 158 /** 159 * @brief Set value of client stub. 160 * @param formHostClient remote object. 161 */ 162 void SetFormHostClient(const sptr<IRemoteObject> &formHostClient); 163 /** 164 * @brief Set value of formHostCallback_. 165 * @param formHostCallback Form host callback object. 166 */ 167 void SetCallback(const std::shared_ptr<FormHostCallback> &formHostCallback); 168 /** 169 * @brief Set value of deathRecipient_. 170 * @param formHostCallback DeathRecipient object. 171 */ 172 void SetDeathRecipient(const sptr<IRemoteObject::DeathRecipient> &deathRecipient); 173 /** 174 * @brief Add deathRecipient object to formHostClient_. 175 * @param deathRecipient DeathRecipient object. 176 */ 177 void AddDeathRecipient(const sptr<IRemoteObject::DeathRecipient>& deathRecipient); 178 /** 179 * @brief Get hostBundleName_. 180 * @return hostBundleName_. 181 */ 182 std::string GetHostBundleName() const; 183 /** 184 * @brief Set hostBundleName_. 185 * @param hostBundleName Host bundle name. 186 */ 187 void SetHostBundleName(const std::string &hostBundleName); 188 private: 189 int callerUid_ = 0; 190 sptr<IRemoteObject> formHostClient_ = nullptr; 191 std::shared_ptr<FormHostCallback> formHostCallback_ = nullptr; 192 sptr<IRemoteObject::DeathRecipient> deathRecipient_ = nullptr; 193 std::unordered_map<int64_t, bool> forms_; 194 std::unordered_map<int64_t, bool> enableUpdateMap_; 195 std::unordered_map<int64_t, bool> needRefresh_; 196 std::string hostBundleName_ = ""; 197 198 /** 199 * @class ClientDeathRecipient 200 * notices IRemoteBroker died. 201 */ 202 class ClientDeathRecipient : public IRemoteObject::DeathRecipient { 203 public: 204 /** 205 * @brief Constructor 206 */ 207 ClientDeathRecipient() = default; 208 ~ClientDeathRecipient() = default; 209 /** 210 * @brief handle remote object died event. 211 * @param remote remote object. 212 */ 213 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 214 }; 215 }; 216 } // namespace AppExecFwk 217 } // namespace OHOS 218 219 #endif // OHOS_FORM_FWK_FORM_HOST_RECORD_H 220