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