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_SUPPLY_CALLBACK_H 17 #define OHOS_FORM_FWK_FORM_SUPPLY_CALLBACK_H 18 19 #include "form_ability_connection.h" 20 #include "form_supply_stub.h" 21 22 namespace OHOS { 23 namespace AppExecFwk { 24 /** 25 * @class FormSupplyCallback 26 * form supply service stub. 27 */ 28 class FormSupplyCallback : public FormSupplyStub { 29 public: 30 FormSupplyCallback() = default; 31 virtual ~FormSupplyCallback() = default; 32 static sptr<FormSupplyCallback> GetInstance(); 33 34 void ProcessFormAcquisition(int64_t formId); 35 /** 36 * @brief Accept form binding data from form provider. 37 * @param providerFormInfo Form binding data. 38 * @param want input data. 39 * @return Returns ERR_OK on success, others on failure. 40 */ 41 int OnAcquire(const FormProviderInfo &formInfo, const Want &want) override; 42 43 /** 44 * @brief Accept other event. 45 * @param want input data. 46 * @return Returns ERR_OK on success, others on failure. 47 */ 48 int OnEventHandle(const Want &want) override; 49 50 /** 51 * @brief Accept form state from form provider. 52 * @param state Form state. 53 * @param provider provider info. 54 * @param wantArg The want of onAcquireFormState. 55 * @param want input data. 56 * @return Returns ERR_OK on success, others on failure. 57 */ 58 int OnAcquireStateResult(FormState state, const std::string &provider, const Want &wantArg, 59 const Want &want) override; 60 61 /** 62 * @brief Accept form data from form provider. 63 * @param formId The Id of the from. 64 * @param wantParams Indicates the data information acquired by the form. 65 * @param requestCode Indicates the requested id. 66 * @return Returns ERR_OK on success, others on failure. 67 */ 68 int OnAcquireDataResult(const AAFwk::WantParams &wantParams, int64_t requestCode) override; 69 70 /** 71 * @brief Save ability Connection for the callback. 72 * @param connection ability connection. 73 */ 74 void AddConnection(sptr<FormAbilityConnection> connection); 75 /** 76 * @brief Delete ability connection after the callback come. 77 * @param connectId The ability connection id generated when save. 78 */ 79 void RemoveConnection(int32_t connectId); 80 /** 81 * @brief Delete ability connection by formId and hostToken. 82 * @param formId Indicates the ID of the form. 83 * @param hostToken Indicates the host token for matching connection. 84 */ 85 void RemoveConnection(int64_t formId, const sptr<IRemoteObject> &hostToken); 86 87 void OnShareAcquire(int64_t formId, const std::string &remoteDeviceId, 88 const AAFwk::WantParams &wantParams, int64_t requestCode, const bool &result) override; 89 90 /** 91 * @brief Handle form host died. 92 * @param hostToken Form host proxy object. 93 */ 94 void HandleHostDied(const sptr<IRemoteObject> &hostToken); 95 96 /** 97 * @brief Accept form render task done from render service. 98 * @param formId The Id of the form. 99 * @param want input data. 100 * @return Returns ERR_OK on success, others on failure. 101 */ 102 int32_t OnRenderTaskDone(int64_t formId, const Want &want) override; 103 104 /** 105 * @brief Accept form stop rendering task done from render service. 106 * @param formId The Id of the form. 107 * @param want input data. 108 * @return Returns ERR_OK on success, others on failure. 109 */ 110 int32_t OnStopRenderingTaskDone(int64_t formId, const Want &want) override; 111 112 /** 113 * @brief Accept rendering block from render service. 114 * @param bundleName The block of bundleName. 115 * @return Returns ERR_OK on success, others on failure. 116 */ 117 int32_t OnRenderingBlock(const std::string &bundleName) override; 118 119 /** 120 * @brief Accept status data of recycled form from render service 121 * @param formId The Id of the form. 122 * @param want Input data. 123 * @return Returns ERR_OK on success, others on failure. 124 */ 125 int32_t OnRecycleForm(const int64_t &formId, const Want &want) override; 126 127 /** 128 * @brief Trigger card recover when configuration changes occur. 129 * @param formIds The ids of the forms. 130 * @return Returns ERR_OK on success, others on failure. 131 */ 132 int32_t OnRecoverFormsByConfigUpdate(std::vector<int64_t> &formIds) override; 133 134 int32_t OnNotifyRefreshForm(const int64_t &formId) override; 135 136 private: 137 /** 138 * @brief check if disconnect ability or not. 139 * @param connection The ability connection. 140 */ 141 bool CanDisconnect(sptr<FormAbilityConnection> &connection); 142 143 bool IsRemoveConnection(int64_t formId, const sptr<IRemoteObject> &hostToken); 144 private: 145 static std::mutex mutex_; 146 static sptr<FormSupplyCallback> instance_; 147 148 mutable std::mutex conMutex_; 149 std::map<int32_t, sptr<FormAbilityConnection>> connections_; 150 DISALLOW_COPY_AND_MOVE(FormSupplyCallback); 151 }; 152 } // namespace AppExecFwk 153 } // namespace OHOS 154 #endif // OHOS_FORM_FWK_FORM_SUPPLY_CALLBACK_H 155