1 /*
2  * Copyright (c) 2022-2024 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 FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_MGR_SERVICE_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_MGR_SERVICE_H
18 
19 #include <codecvt>
20 #include <memory>
21 #include <singleton.h>
22 #include <system_ability.h>
23 #include <thread_ex.h>
24 #include <unordered_map>
25 
26 #include "form_mgr_stub.h"
27 #include "form_provider_data.h"
28 #include "iremote_object.h"
29 
30 namespace OHOS {
31 namespace AppExecFwk {
32 /**
33  * @class MockFormMgrService
34  */
35 class MockFormMgrService : public FormMgrStub,
36                        public std::enable_shared_from_this<MockFormMgrService> {
37 public:
38     MockFormMgrService() = default;
39     virtual~MockFormMgrService() = default;
40     int32_t AddForm(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken,
41         FormJsInfo &formInfo) override
42     {
43         return ERR_OK;
44     };
45     int32_t DeleteForm(const int64_t formId, const sptr<IRemoteObject> &callerToken) override
46     {
47         return ERR_OK;
48     };
49     int32_t ReleaseForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const bool delCache) override
50     {
51         return ERR_OK;
52     };
53     int32_t UpdateForm(const int64_t formId, const FormProviderData &FormProviderData) override
54     {
55         return ERR_OK;
56     };
57     int32_t SetNextRefreshTime(const int64_t formId, const int64_t nextTime) override
58     {
59         return ERR_OK;
60     };
61     int32_t LifecycleUpdate(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
62         const bool updateType) override
63     {
64         return ERR_OK;
65     };
66     ErrCode RequestPublishForm(Want &want, bool withFormBindingData,
67         std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId) override
68     {
69         return ERR_OK;
70     };
71     int32_t RequestForm(const int64_t formId, const sptr<IRemoteObject> &callerToken, const Want &want) override
72     {
73         return ERR_OK;
74     };
75     int32_t NotifyWhetherVisibleForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
76         const int32_t formVisibleType) override
77     {
78         return ERR_OK;
79     };
80     bool HasFormVisible(const uint32_t tokenId) override
81     {
82         return false;
83     }
84     int32_t CastTempForm(const int64_t formId, const sptr<IRemoteObject> &callerToken) override
85     {
86         return ERR_OK;
87     };
88     int32_t DumpStorageFormInfos(std::string &formInfos) override
89     {
90         return ERR_OK;
91     };
92     int32_t DumpFormInfoByBundleName(const std::string &bundleName, std::string &formInfos) override
93     {
94         return ERR_OK;
95     };
96     int32_t DumpFormInfoByFormId(const std::int64_t formId, std::string &formInfo) override
97     {
98         return ERR_OK;
99     };
100     int32_t DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService) override
101     {
102         return ERR_OK;
103     };
104     int32_t MessageEvent(const int64_t formId, const Want &want, const sptr<IRemoteObject> &callerToken) override
105     {
106         return ERR_OK;
107     };
108     int32_t RouterEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken) override
109     {
110         return ERR_OK;
111     };
112     int32_t BackgroundEvent(const int64_t formId, Want &want, const sptr<IRemoteObject> &callerToken) override
113     {
114         return ERR_OK;
115     };
116     int32_t DeleteInvalidForms(const std::vector<int64_t> &formIds, const sptr<IRemoteObject> &callerToken,
117                                    int32_t &numFormsDeleted) override
118     {
119         return ERR_OK;
120     };
121     int32_t AcquireFormState(const Want &want, const sptr<IRemoteObject> &callerToken,
122                                  FormStateInfo &stateInfo) override
123     {
124         return ERR_OK;
125     };
126     int32_t NotifyFormsVisible(const std::vector<int64_t> &formIds, bool isVisible,
127                                    const sptr<IRemoteObject> &callerToken) override
128     {
129         return ERR_OK;
130     };
131     int32_t NotifyFormsPrivacyProtected(const std::vector<int64_t> &formIds, bool isProtected,
132                                         const sptr<IRemoteObject> &callerToken) override
133     {
134         return ERR_OK;
135     };
136     int32_t NotifyFormsEnableUpdate(const std::vector<int64_t> &formIds, bool isEnableUpdate,
137                                         const sptr<IRemoteObject> &callerToken) override
138     {
139         return ERR_OK;
140     };
141     int32_t GetAllFormsInfo(std::vector<FormInfo> &formInfos) override
142     {
143         return ERR_OK;
144     };
145     int32_t GetFormsInfoByApp(std::string &bundleName, std::vector<FormInfo> &formInfos) override
146     {
147         return ERR_OK;
148     };
149     int32_t GetFormsInfoByModule(std::string &bundleName, std::string &moduleName,
150                              std::vector<FormInfo> &formInfos) override
151     {
152         return ERR_OK;
153     };
154     int32_t ShareForm(const int64_t formId, const std::string &deviceId,
155         const sptr<IRemoteObject> &callerToken, const int64_t requestCode) override
156     {
157         return ERR_OK;
158     };
159     int32_t AcquireFormData(int64_t formId, int64_t requestCode, const sptr<IRemoteObject> &callerToken,
160         AAFwk::WantParams &formData) override
161     {
162         return ERR_OK;
163     };
164     int32_t RecvFormShareInfoFromRemote(const FormShareInfo &info) override
165     {
166         return ERR_OK;
167     };
168     bool IsRequestPublishFormSupported() override
169     {
170         return true;
171     };
172     int32_t StartAbility(const Want &want, const sptr<IRemoteObject> &callerToken) override
173     {
174         return ERR_OK;
175     };
176     int32_t GetFormsInfo(const FormInfoFilter &filter, std::vector<FormInfo> &formInfos) override
177     {
178         return ERR_OK;
179     };
180     bool CheckFMSReady() override
181     {
182         return false;
183     };
184     int32_t SetBackgroundFunction(const std::string method, const std::string params) override
185     {
186         return ERR_OK;
187     };
188     int32_t GetFormsCount(bool isTempFormFlag, int32_t &formCount) override
189     {
190         return ERR_OK;
191     }
192     int32_t GetHostFormsCount(std::string &bundleName, int32_t &formCount) override
193     {
194         return ERR_OK;
195     }
196     ErrCode GetRunningFormInfos(bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos) override
197     {
198         return ERR_OK;
199     }
200     ErrCode GetRunningFormInfosByBundleName(
201         const std::string &bundleName, bool isUnusedIncluded, std::vector<RunningFormInfo> &runningFormInfos) override
202     {
203         return ERR_OK;
204     }
205     int32_t GetFormInstancesByFilter(const FormInstancesFilter &formInstancesFilter,
206         std::vector<FormInstance> &formInstances) override
207     {
208         return 0;
209     }
210     int32_t GetFormInstanceById(const int64_t formId, FormInstance &formInstance) override
211     {
212         return 0;
213     }
214     ErrCode RegisterFormAddObserverByBundle(const std::string bundleName,
215         const sptr<IRemoteObject> &callerToken) override
216     {
217         return ERR_OK;
218     }
219     ErrCode RegisterFormRemoveObserverByBundle(const std::string bundleName,
220         const sptr<IRemoteObject> &callerToken) override
221     {
222         return ERR_OK;
223     }
224     ErrCode RegisterAddObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken) override
225     {
226         return ERR_OK;
227     }
228     ErrCode RegisterRemoveObserver(const std::string &bundleName, const sptr<IRemoteObject> &callerToken) override
229     {
230         return ERR_OK;
231     }
232     ErrCode RegisterFormRouterProxy(const std::vector<int64_t> &formIds,
233         const sptr<IRemoteObject> &callerToken) override
234     {
235         return ERR_OK;
236     }
237     ErrCode UnregisterFormRouterProxy(const std::vector<int64_t> &formIds) override
238     {
239         return ERR_OK;
240     }
241     ErrCode RegisterClickEventObserver(
242         const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer) override
243     {
244         return ERR_OK;
245     }
246     ErrCode UnregisterClickEventObserver(
247         const std::string &bundleName, const std::string &formEventType, const sptr<IRemoteObject> &observer) override
248     {
249         return ERR_OK;
250     }
251     ErrCode RequestPublishFormWithSnapshot(Want &want, bool withFormBindingData,
252         std::unique_ptr<FormProviderData> &formBindingData, int64_t &formId) override
253     {
254         return ERR_OK;
255     };
256 };
257 }  // namespace AppExecFwk
258 }  // namespace OHOS
259 #endif  // FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_MGR_SERVICE_H