• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(int32_t userId);
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     ErrCode checkConnectionsFormIds(std::vector<int64_t> formIds, int32_t userId, std::vector<int64_t> &needconFormIds);
75 
76     void reAddConnections(std::vector<int64_t> formIds, int32_t userId, const sptr<IRemoteObject> &remoteObject);
77 
78     void AddRenderDeathRecipient(const sptr<IRemoteObject> &renderRemoteObj, const FormRecord &formRecord);
79 
80     bool IsNeedRender(int64_t formId);
81 
82     void CleanFormHost(const sptr<IRemoteObject> &host, const int hostCallingUid);
83 
84     void HandleConnectFailed(int64_t formId, int32_t errorCode) const;
85 
86     bool IsRerenderForRenderServiceDied(int64_t formId);
87 
88     void OnRenderingBlock(const std::string &bundleName);
89 
90     ErrCode ReleaseRenderer(int64_t formId, const FormRecord &formRecord, const std::string &compId);
91 
92     void AddAcquireProviderFormInfoTask(int32_t userId, std::function<void()> task);
93 
94     void ExecAcquireProviderTask(int32_t userId);
95 
96     void AddAcquireProviderForbiddenTask(const std::string &bundleName, int64_t formId, std::function<void()> task);
97 
98     void ExecAcquireProviderForbiddenTask(const std::string &bundleName);
99 
100     void ExecAcquireProviderForbiddenTaskByFormId(const int64_t formId);
101 
102     void DeleteAcquireForbiddenTasksByBundleName(const std::string &bundleName);
103 
104     void DeleteAcquireForbiddenTaskByFormId(int64_t formId);
105 
106     void AddPostRenderFormTask(int64_t formId, std::function<void()> task);
107 
108     void ExecPostRenderFormTask(int64_t formId);
109 
110     void DeletePostRenderFormTask(int64_t formId);
111 
112     void PostOnUnlockTask();
113 
114     ErrCode RecycleForms(const std::vector<int64_t> &formIds, const Want &want,
115         const sptr<IRemoteObject> &remoteObjectOfHost);
116 
117     ErrCode RecoverForms(const std::vector<int64_t> &formIds, const WantParams &wantParams);
118 
119     void UpdateFormSize(const int64_t &formId, float width, float height, float borderWidth);
120 
121     void DisconnectAllRenderConnections(int32_t userId);
122 
123     void RerenderAllFormsImmediate(int32_t userId);
124 
125 private:
126     void InitRenderInner(bool isSandbox, int32_t userId);
127 
128 private:
129     mutable std::mutex isVerifiedMutex_;
130     std::mutex renderInnerMutex_;
131     std::mutex taskQueueMutex_;
132     std::unordered_map<int32_t, std::queue<std::function<void()>>> taskQueueMap_;
133     std::mutex forbiddenTaskMapMutex_;
134     std::unordered_map<std::string, std::unordered_map<int64_t, std::function<void()>>> forbiddenTaskMap_;
135     std::mutex renderFormTaskMapMutex_;
136     std::unordered_map<int64_t, std::function<void()>> renderFormTaskMap_;
137     // <userId, FormRenderMgrInner>
138     std::unordered_map<int32_t, std::shared_ptr<FormRenderMgrInner>> renderInners_;
139     // <userId, FormSandboxRenderMgrInner>
140     std::unordered_map<int32_t, std::shared_ptr<FormSandboxRenderMgrInner>> sandboxInners_;
141     bool isScreenUnlocked_ = false;
142     bool isVerified_ = false;
143 };
144 } // namespace AppExecFwk
145 } // namespace OHOS
146 #endif // OHOS_FORM_FWK_FORM_RENDER_MGR_H
147