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 OnScreenUnlock(); 50 51 void OnUnlock(); 52 53 void NotifyScreenOn(); 54 55 void SetVisibleChange(int64_t formId, bool isVisible); 56 57 ErrCode StopRenderingForm(int64_t formId, const FormRecord &formRecord, 58 const std::string &compId = "", const sptr<IRemoteObject> &hostToken = nullptr); 59 60 ErrCode ReloadForm(const std::vector<FormRecord> &&formRecords, const std::string &bundleName, int32_t userId); 61 62 ErrCode RenderFormCallback(int64_t formId, const Want &want); 63 64 ErrCode StopRenderingFormCallback(int64_t formId, const Want &want); 65 66 void GetFormRenderState(); 67 68 bool GetIsVerified() const; 69 70 ErrCode AddConnection(int64_t formId, sptr<FormRenderConnection> connection, const FormRecord &formRecord); 71 72 void RemoveConnection(int64_t formId, const FormRecord &formRecord); 73 74 void AddRenderDeathRecipient(const sptr<IRemoteObject> &renderRemoteObj, const FormRecord &formRecord); 75 76 bool IsNeedRender(int64_t formId); 77 78 void CleanFormHost(const sptr<IRemoteObject> &host, const int hostCallingUid); 79 80 void HandleConnectFailed(int64_t formId, int32_t errorCode) const; 81 82 bool IsRerenderForRenderServiceDied(int64_t formId); 83 84 void OnRenderingBlock(const std::string &bundleName); 85 86 ErrCode ReleaseRenderer(int64_t formId, const FormRecord &formRecord, const std::string &compId); 87 88 void AddAcquireProviderFormInfoTask(std::function<void()> task); 89 90 void ExecAcquireProviderTask(); 91 92 void PostOnUnlockTask(); 93 94 ErrCode RecycleForms(const std::vector<int64_t> &formIds, const Want &want, 95 const sptr<IRemoteObject> &remoteObjectOfHost); 96 97 ErrCode RecoverForms(const std::vector<int64_t> &formIds, const WantParams &wantParams); 98 99 void DisconnectAllRenderConnections(int32_t userId); 100 101 void RerenderAllFormsImmediate(int32_t userId); 102 103 private: 104 void InitRenderInner(bool isSandbox, int32_t userId); 105 106 private: 107 mutable std::mutex isVerifiedMutex_; 108 std::mutex renderInnerMutex_; 109 std::mutex taskQueueMutex_; 110 std::queue<std::function<void()>> taskQueue_; 111 // <userId, FormRenderMgrInner> 112 std::unordered_map<int32_t, std::shared_ptr<FormRenderMgrInner>> renderInners_; 113 // <userId, FormSandboxRenderMgrInner> 114 std::unordered_map<int32_t, std::shared_ptr<FormSandboxRenderMgrInner>> sandboxInners_; 115 bool isScreenUnlocked_ = false; 116 bool isVerified_ = false; 117 }; 118 } // namespace AppExecFwk 119 } // namespace OHOS 120 #endif // OHOS_FORM_FWK_FORM_RENDER_MGR_H 121