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 #include "mock_form_provider_client.h"
17 
18 #include "errors.h"
19 #include "fms_log_wrapper.h"
20 #include "form_constants.h"
21 #include "form_supply_interface.h"
22 #include "string_ex.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 /**
27  * Acquire to give back an ProviderFormInfo. This is sync API.
28  *
29  * @param want, The want of the form to create.
30  * @param callerToken, Caller ability token.
31  * @return none.
32  */
AcquireProviderFormInfo(const FormJsInfo & formJsInfo,const Want & want,const sptr<IRemoteObject> & callerToken)33 int MockFormProviderClient::AcquireProviderFormInfo(const FormJsInfo &formJsInfo, const Want &want,
34     const sptr<IRemoteObject> &callerToken)
35 {
36     // avoid the user modify the number in onCreate
37 
38     HILOG_DEBUG("Acquire provider form info");
39 
40     sptr<IFormSupply> formSupply = iface_cast<IFormSupply>(callerToken);
41     if (formSupply == nullptr) {
42         HILOG_ERROR("failed to get formSupplyProxy");
43         return ERR_OK;
44     }
45 
46     FormProviderInfo formProviderInfo;
47     Want newWant(want);
48     newWant.SetParam(Constants::ACQUIRE_TYPE, want.GetIntParam(Constants::ACQUIRE_TYPE, 0));
49     newWant.SetParam(Constants::FORM_CONNECT_ID, want.GetIntParam(Constants::FORM_CONNECT_ID, 0));
50     newWant.SetParam(Constants::FORM_SUPPLY_INFO, want.GetStringParam(Constants::FORM_SUPPLY_INFO));
51     newWant.SetParam(Constants::PROVIDER_FLAG, true);
52     newWant.SetParam(Constants::PARAM_FORM_IDENTITY_KEY, std::to_string(formJsInfo.formId));
53     formSupply->OnAcquire(formProviderInfo, newWant);
54     return ERR_OK;
55 }
56 
57 /**
58  * Notify provider when the form was deleted.
59  *
60  * @param formId, The Id of the form.
61  * @param callerToken, Caller ability token.
62  * @return none.
63  */
NotifyFormDelete(const int64_t formId,const Want & want,const sptr<IRemoteObject> & callerToken)64 int MockFormProviderClient::NotifyFormDelete(const int64_t formId, const Want &want,
65     const sptr<IRemoteObject> &callerToken)
66 {
67     HILOG_DEBUG("Notify form delete");
68     return ERR_OK;
69 }
70 /**
71  * Notify provider when the forms was deleted.
72  *
73  * @param formIds, The id list of forms.
74  * @param want Indicates the structure containing form info.
75  * @param callerToken, Caller ability token.
76  * @return none.
77  */
NotifyFormsDelete(const std::vector<int64_t> & formIds,const Want & want,const sptr<IRemoteObject> & callerToken)78 int MockFormProviderClient::NotifyFormsDelete(const std::vector<int64_t> &formIds, const Want &want,
79     const sptr<IRemoteObject> &callerToken)
80 {
81     HILOG_DEBUG("Notify forms delete");
82     return ERR_OK;
83 }
84 
85 /**
86  * @brief Notify provider when the form need update.
87  * @param formId The Id of the form.
88  * @param want Indicates the structure containing form info.
89  * @param callerToken Caller ability token.
90  */
NotifyFormUpdate(const int64_t formId,const Want & want,const sptr<IRemoteObject> & callerToken)91 int MockFormProviderClient::NotifyFormUpdate(const int64_t formId, const Want &want,
92     const sptr<IRemoteObject> &callerToken)
93 {
94     HILOG_DEBUG("Notify form update");
95     return ERR_OK;
96 }
97 
98 /**
99  * @brief Event notify when change the form visible.
100  *
101  * @param formEvents The vector of form ids.
102  * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE.
103  * @param want Indicates the structure containing form info.
104  * @param callerToken Caller ability token.
105  * @return Returns ERR_OK on success, others on failure.
106  */
EventNotify(const std::vector<int64_t> & formIds,const int32_t formVisibleType,const Want & want,const sptr<IRemoteObject> & callerToken)107 int MockFormProviderClient::EventNotify(const std::vector<int64_t> &formIds, const int32_t formVisibleType,
108     const Want &want, const sptr<IRemoteObject> &callerToken)
109 {
110     HILOG_DEBUG("Event notify");
111     return ERR_OK;
112 }
113 
114 /**
115  * Notify provider when the temp form was cast to normal form.
116  *
117  * @param formId, The Id of the form to update.
118  * @param callerToken, Caller ability token.
119  * @return none.
120  */
NotifyFormCastTempForm(const int64_t formId,const Want & want,const sptr<IRemoteObject> & callerToken)121 int MockFormProviderClient::NotifyFormCastTempForm(const int64_t formId, const Want &want,
122     const sptr<IRemoteObject> &callerToken)
123 {
124     HILOG_DEBUG("Notify cast temp form");
125     return ERR_OK;
126 }
127 /**
128  * @brief Fire message event to form provider.
129  * @param formId The Id of the from.
130  * @param message Event message.
131  * @param want The want of the request.
132  * @param callerToken Form provider proxy object.
133  * @return Returns ERR_OK on success, others on failure.
134  */
FireFormEvent(const int64_t formId,const std::string & message,const Want & want,const sptr<IRemoteObject> & callerToken)135 int MockFormProviderClient::FireFormEvent(const int64_t formId, const std::string &message, const Want &want,
136     const sptr<IRemoteObject> &callerToken)
137 {
138     HILOG_DEBUG("Fire form event");
139     return ERR_OK;
140 }
141 
142 /**
143  * @brief Acquire form state to form provider.
144  * @param wantArg The want of onAcquireFormState.
145  * @param provider The provider info.
146  * @param want The want of the request.
147  * @param callerToken Form provider proxy object.
148  * @return Returns ERR_OK on success, others on failure.
149  */
AcquireState(const Want & wantArg,const std::string & provider,const Want & want,const sptr<IRemoteObject> & callerToken)150 int MockFormProviderClient::AcquireState(const Want &wantArg, const std::string &provider, const Want &want,
151                                          const sptr<IRemoteObject> &callerToken)
152 {
153     HILOG_DEBUG("Acquire state");
154     return ERR_OK;
155 }
156 
AcquireShareFormData(int64_t formId,const std::string & remoteDeviceId,const sptr<IRemoteObject> & formSupplyCallback,int64_t requestCode)157 int32_t MockFormProviderClient::AcquireShareFormData(int64_t formId, const std::string &remoteDeviceId,
158     const sptr<IRemoteObject> &formSupplyCallback, int64_t requestCode)
159 {
160     HILOG_DEBUG("MockFormProviderClient::AcquireShareFormData");
161     acquireShareFormState_ = true;
162     return ERR_OK;
163 }
164 
AcquireFormData(int64_t formId,const sptr<IRemoteObject> & formSupplyCallback,int64_t requestCode)165 int32_t MockFormProviderClient::AcquireFormData(int64_t formId, const sptr<IRemoteObject> &formSupplyCallback,
166     int64_t requestCode)
167 {
168     HILOG_DEBUG("MockFormProviderClient::AcquireFormData");
169     return ERR_OK;
170 }
171 }  // namespace AppExecFwk
172 }  // namespace OHOS
173