1 /*
2  * Copyright (c) 2021-2022 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_MOCK_FORM_PROVIDER_CLIENT_H
17 #define OHOS_FORM_FWK_MOCK_FORM_PROVIDER_CLIENT_H
18 
19 #include <map>
20 #include <iremote_object.h>
21 #include <iremote_stub.h>
22 #include "form_provider_stub.h"
23 
24 #include "want.h"
25 
26 namespace OHOS {
27 namespace AppExecFwk {
28 /**
29  * @class FormProviderStub
30  * FormProviderStub.
31  */
32 class MockFormProviderClient : public FormProviderStub {
33 public:
34     MockFormProviderClient() = default;
35     virtual ~MockFormProviderClient() = default;
36 
37     bool acquireShareFormState_ = false;
38 private:
39     /**
40      * Acquire to give back an ProviderFormInfo. This is sync API.
41      *
42      * @param want, Indicates the {@link Want} structure containing form info.
43      * @param callerToken, Caller ability token.
44      * @return none.
45      */
46     virtual int AcquireProviderFormInfo(const FormJsInfo &formJsInfo, const Want &want,
47         const sptr<IRemoteObject> &callerToken) override;
48 
49     /**
50      * Notify provider when the form was deleted.
51      *
52      * @param formId, The Id of the form.
53      * @param callerToken, Caller ability token.
54      * @return none.
55      */
56     virtual int NotifyFormDelete(const int64_t formId, const Want &want,
57         const sptr<IRemoteObject> &callerToken) override;
58 
59     /**
60      * Notify provider when the form was deleted.
61      *
62      * @param formIds, The id list of forms.
63      * @param want Indicates the structure containing form info.
64      * @param callerToken, Caller ability token.
65      * @return none.
66      */
67     virtual int NotifyFormsDelete(const std::vector<int64_t> &formIds, const Want &want,
68         const sptr<IRemoteObject> &callerToken) override;
69 
70     /**
71      * @brief Notify provider when the form need update.
72      * @param formId The Id of the form.
73      * @param want Indicates the structure containing form info.
74      * @param callerToken Caller ability token.
75      */
76     virtual int NotifyFormUpdate(const int64_t formId, const Want &want,
77         const sptr<IRemoteObject> &callerToken) override;
78 
79     /**
80      * @brief Event notify when change the form visible.
81      * @param formEvents The vector of form ids.
82      * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
83      * @param want Indicates the structure containing form info.
84      * @param callerToken Caller ability token.
85      * @return Returns ERR_OK on success, others on failure.
86      */
87     virtual int EventNotify(const std::vector<int64_t> &formIds, const int32_t formVisibleType,
88         const Want &want, const sptr<IRemoteObject> &callerToken) override;
89 
90     /**
91      * Notify provider when the temp form was cast to normal form.
92      *
93      * @param formId, The Id of the form to update.
94      * @param callerToken, Caller ability token.
95      * @return none.
96      */
97     virtual int NotifyFormCastTempForm(const int64_t formId, const Want &want,
98         const sptr<IRemoteObject> &callerToken) override;
99     /**
100      * @brief Fire message event to form provider.
101      * @param formId The Id of the from.
102      * @param message Event message.
103      * @param want The want of the request.
104      * @param callerToken Form provider proxy object.
105      * @return Returns ERR_OK on success, others on failure.
106      */
107     virtual int FireFormEvent(const int64_t formId, const std::string &message, const Want &want,
108         const sptr<IRemoteObject> &callerToken) override;
109 
110     /**
111      * @brief Acquire form state to form provider.
112      * @param wantArg The want of onAcquireFormState.
113      * @param provider The provider info.
114      * @param want The want of the request.
115      * @param callerToken Form provider proxy object.
116      * @return Returns ERR_OK on success, others on failure.
117      */
118     virtual int AcquireState(const Want &wantArg, const std::string &provider, const Want &want,
119                              const sptr<IRemoteObject> &callerToken) override;
120 
121     int32_t AcquireShareFormData(int64_t formId, const std::string &remoteDeviceId,
122         const sptr<IRemoteObject> &formSupplyCallback, int64_t requestCode) override;
123 
124     /**
125      * @brief Acquire to form data.
126      * @param formId The Id of the from.
127      * @param formSupplyCallback Indicates lifecycle callbacks.
128      * @param requestCode Indicates the request code.
129      * @return Returns ERR_OK on success, others on failure.
130      */
131     virtual int32_t AcquireFormData(int64_t formId, const sptr<IRemoteObject> &formSupplyCallback,
132         int64_t requestCode) override;
133 private:
134     DISALLOW_COPY_AND_MOVE(MockFormProviderClient);
135 };
136 } // namespace AppExecFwk
137 } // namespace OHOS
138 #endif // OHOS_FORM_FWK_MOCK_FORM_PROVIDER_CLIENT_H