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_MGR_H 17 #define OHOS_FORM_FWK_FORM_RENDER_MGR_H 18 19 #include <atomic> 20 #include <queue> 21 #include <singleton.h> 22 23 #include "form_record.h" 24 #include "form_render_connection.h" 25 #include "form_render_interface.h" 26 #include "form_render_mgr_inner.h" 27 #include "form_sandbox_render_mgr_inner.h" 28 #include "want.h" 29 30 namespace OHOS { 31 namespace AppExecFwk { 32 using Want = OHOS::AAFwk::Want; 33 using WantParams = OHOS::AAFwk::WantParams; 34 /** 35 * @class FormRenderService 36 * FormRenderService provides a facility for managing form render life cycle. 37 */ 38 class FormRenderMgr : public DelayedRefSingleton<FormRenderMgr> { 39 DECLARE_DELAYED_REF_SINGLETON(FormRenderMgr) 40 public: 41 DISALLOW_COPY_AND_MOVE(FormRenderMgr); 42 43 ErrCode RenderForm( 44 const FormRecord &formRecord, const WantParams &wantParams, const sptr<IRemoteObject> &hostToken = nullptr); 45 46 ErrCode UpdateRenderingForm(int64_t formId, const FormProviderData &formProviderData, 47 const WantParams &wantParams, bool mergeData); 48 49 void OnUnlock(); 50 51 ErrCode StopRenderingForm(int64_t formId, const FormRecord &formRecord, 52 const std::string &compId = "", const sptr<IRemoteObject> &hostToken = nullptr); 53 54 ErrCode ReloadForm(const std::vector<FormRecord> &&formRecords, const std::string &bundleName, int32_t userId); 55 56 ErrCode RenderFormCallback(int64_t formId, const Want &want); 57 58 ErrCode StopRenderingFormCallback(int64_t formId, const Want &want); 59 60 void GetFormRenderState() const; 61 62 bool GetIsVerified() const; 63 64 ErrCode AddConnection(int64_t formId, sptr<FormRenderConnection> connection, int32_t privacyLevel); 65 66 void RemoveConnection(int64_t formId, int32_t privacyLevel); 67 68 void AddRenderDeathRecipient(const sptr<IRemoteObject> &renderRemoteObj, int32_t privacyLevel); 69 70 bool IsNeedRender(int64_t formId); 71 72 void CleanFormHost(const sptr<IRemoteObject> &host); 73 74 void HandleConnectFailed(int64_t formId, int32_t errorCode) const; 75 76 bool IsRerenderForRenderServiceDied(int64_t formId); 77 78 void OnRenderingBlock(const std::string &bundleName); 79 80 ErrCode ReleaseRenderer(int64_t formId, const FormRecord &formRecord, const std::string &compId); 81 82 void SetFormRenderState(bool isVerified); 83 84 void AddAcquireProviderFormInfoTask(std::function<void()> task); 85 86 void ExecAcquireProviderTask(); 87 88 void PostOnUnlockTask(); 89 90 ErrCode RecycleForms(const std::vector<int64_t> &formIds, const Want &want, 91 const sptr<IRemoteObject> &remoteObjectOfHost); 92 93 ErrCode RecoverForms(const std::vector<int64_t> &formIds, const std::string &bundleName, 94 const WantParams &wantParams); 95 96 private: 97 void InitRenderInner(bool isSandbox); 98 99 private: 100 mutable std::mutex isVerifiedMutex_; 101 std::mutex renderInnerMutex_; 102 std::mutex taskQueueMutex_; 103 std::queue<std::function<void()>> taskQueue_; 104 std::shared_ptr<FormRenderMgrInner> renderInner_ = nullptr; 105 std::shared_ptr<FormSandboxRenderMgrInner> sandboxInner_ = nullptr; 106 mutable bool isVerified_ = false; 107 }; 108 } // namespace AppExecFwk 109 } // namespace OHOS 110 #endif // OHOS_FORM_FWK_FORM_RENDER_MGR_H 111