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 /**
129 * @brief Notify provider when the system configuration changed.
130 *
131 * @param configuration system Configuration.
132 * @param want Indicates the structure containing form info.
133 * @param callerToken Caller ability token.
134 * @return Returns ERR_OK on success, others on failure.
135 */
NotifyConfigurationUpdate(const AppExecFwk::Configuration & configuration,const Want & want,const sptr<IRemoteObject> & callerToken)136 int MockFormProviderClient::NotifyConfigurationUpdate(const AppExecFwk::Configuration &configuration,
137 const Want &want, const sptr<IRemoteObject> &callerToken)
138 {
139 HILOG_DEBUG("Notify Configuration Update");
140 return ERR_OK;
141 }
142
143 /**
144 * @brief Fire message event to form provider.
145 * @param formId The Id of the from.
146 * @param message Event message.
147 * @param want The want of the request.
148 * @param callerToken Form provider proxy object.
149 * @return Returns ERR_OK on success, others on failure.
150 */
FireFormEvent(const int64_t formId,const std::string & message,const Want & want,const sptr<IRemoteObject> & callerToken)151 int MockFormProviderClient::FireFormEvent(const int64_t formId, const std::string &message, const Want &want,
152 const sptr<IRemoteObject> &callerToken)
153 {
154 HILOG_DEBUG("Fire form event");
155 return ERR_OK;
156 }
157
158 /**
159 * @brief Acquire form state to form provider.
160 * @param wantArg The want of onAcquireFormState.
161 * @param provider The provider info.
162 * @param want The want of the request.
163 * @param callerToken Form provider proxy object.
164 * @return Returns ERR_OK on success, others on failure.
165 */
AcquireState(const Want & wantArg,const std::string & provider,const Want & want,const sptr<IRemoteObject> & callerToken)166 int MockFormProviderClient::AcquireState(const Want &wantArg, const std::string &provider, const Want &want,
167 const sptr<IRemoteObject> &callerToken)
168 {
169 HILOG_DEBUG("Acquire state");
170 return ERR_OK;
171 }
172
AcquireShareFormData(int64_t formId,const std::string & remoteDeviceId,const sptr<IRemoteObject> & formSupplyCallback,int64_t requestCode)173 int32_t MockFormProviderClient::AcquireShareFormData(int64_t formId, const std::string &remoteDeviceId,
174 const sptr<IRemoteObject> &formSupplyCallback, int64_t requestCode)
175 {
176 HILOG_DEBUG("MockFormProviderClient::AcquireShareFormData");
177 acquireShareFormState_ = true;
178 return ERR_OK;
179 }
180
AcquireFormData(int64_t formId,const sptr<IRemoteObject> & formSupplyCallback,int64_t requestCode)181 int32_t MockFormProviderClient::AcquireFormData(int64_t formId, const sptr<IRemoteObject> &formSupplyCallback,
182 int64_t requestCode)
183 {
184 HILOG_DEBUG("MockFormProviderClient::AcquireFormData");
185 return ERR_OK;
186 }
187 } // namespace AppExecFwk
188 } // namespace OHOS
189