1 /* 2 * Copyright (c) 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_RENDER_IMPL_H 17 #define OHOS_FORM_FWK_FORM_RENDER_IMPL_H 18 19 #include "form_render_stub.h" 20 21 #include <memory> 22 #include <singleton.h> 23 24 #include "bundle_mgr_interface.h" 25 #include "context_impl.h" 26 #include "event_handler.h" 27 #include "form_render_record.h" 28 #include "form_supply_proxy.h" 29 #include "js_runtime.h" 30 #include "runtime.h" 31 #include "want.h" 32 33 namespace OHOS { 34 namespace AppExecFwk { 35 namespace FormRender { 36 using OHOS::AAFwk::Want; 37 using namespace AbilityRuntime; 38 39 class FormRenderImpl : public FormRenderStub, 40 public std::enable_shared_from_this<FormRenderImpl> { 41 DECLARE_DELAYED_SINGLETON(FormRenderImpl) 42 public: 43 /** 44 * @brief Render form. This is sync API. 45 * @param formJsInfo The form js info. 46 * @param want Indicates the {@link Want} structure containing form info. 47 * @param callerToken Caller ability token. 48 * @return Returns ERR_OK on success, others on failure. 49 */ 50 int32_t RenderForm(const FormJsInfo &formJsInfo, const Want &want, 51 const sptr<IRemoteObject> &callerToken) override; 52 53 /** 54 * @brief Stop rendering form. This is sync API. 55 * @param formJsInfo The form js info. 56 * @param want Indicates the {@link Want} structure containing form info. 57 * @param callerToken Caller ability token. 58 * @return Returns ERR_OK on success, others on failure. 59 */ 60 int32_t StopRenderingForm( 61 const FormJsInfo &formJsInfo, const Want &want, const sptr<IRemoteObject> &callerToken) override; 62 63 /** 64 * @brief When host is died, clean resources. This is async API. 65 * @param hostToken Caller ability token. 66 * @return Returns ERR_OK on success, others on failure. 67 */ 68 int32_t CleanFormHost(const sptr<IRemoteObject> &hostToken) override; 69 70 /** 71 * @brief Reload form When app updated. This is sync API. 72 * @param formIds the form id need to update. 73 * @param want Indicates the {@link Want} structure containing form info. 74 * @return int32_t Returns ERR_OK on success, others on failure. 75 */ 76 int32_t ReloadForm(const std::vector<FormJsInfo> &&formJsInfos, const Want &want) override; 77 78 /** 79 * @brief Called when the system configuration is updated. 80 * @param configuration Indicates the updated configuration information. 81 */ 82 void OnConfigurationUpdated(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& configuration); 83 84 void SetConfiguration(const std::shared_ptr<OHOS::AppExecFwk::Configuration>& config); 85 86 void OnRenderingBlock(const std::string &bundleName); 87 88 int32_t ReleaseRenderer( 89 int64_t formId, const std::string &compId, const std::string &uid) override; 90 91 int32_t OnUnlock() override; 92 93 private: 94 std::mutex renderRecordMutex_; 95 std::unordered_map<std::string, std::shared_ptr<FormRenderRecord>> renderRecordMap_; // <uid(userId + bundleName), renderRecord> 96 std::shared_ptr<OHOS::AppExecFwk::Configuration> configuration_; 97 std::mutex formSupplyMutex_; 98 sptr<IFormSupply> formSupplyClient_; 99 }; 100 } // namespace FormRender 101 } // namespace AppExecFwk 102 } // namespace OHOS 103 #endif // OHOS_FORM_FWK_FORM_RENDER_IMPL_H 104