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