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 #include "form_provider_stub.h"
16 #include "appexecfwk_errors.h"
17 #include "app_scheduler_interface.h"
18 #include "errors.h"
19 #include "fms_log_wrapper.h"
20 #include "form_mgr_errors.h"
21 #include "ipc_skeleton.h"
22 #include "ipc_types.h"
23 #include "iremote_object.h"
24
25 namespace OHOS {
26 namespace AppExecFwk {
FormProviderStub()27 FormProviderStub::FormProviderStub()
28 {}
29
~FormProviderStub()30 FormProviderStub::~FormProviderStub()
31 {}
32 /**
33 * @brief handle remote request.
34 * @param data input param.
35 * @param reply output param.
36 * @param option message option.
37 * @return Returns ERR_OK on success, others on failure.
38 */
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)39 int FormProviderStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
40 {
41 HILOG_INFO("code:%{public}u, flags:%{public}d", code, option.GetFlags());
42 std::u16string descriptor = FormProviderStub::GetDescriptor();
43 std::u16string remoteDescriptor = data.ReadInterfaceToken();
44 if (descriptor != remoteDescriptor) {
45 HILOG_ERROR("localDescribe not equal to remote");
46 return ERR_APPEXECFWK_FORM_INVALID_PARAM;
47 }
48
49 switch (code) {
50 case static_cast<uint32_t>(IFormProvider::Message::FORM_ACQUIRE_PROVIDER_FORM_INFO):
51 return HandleAcquireProviderFormInfo(data, reply);
52 case static_cast<uint32_t>(IFormProvider::Message::FORM_PROVIDER_NOTIFY_FORM_DELETE):
53 return HandleNotifyFormDelete(data, reply);
54 case static_cast<uint32_t>(IFormProvider::Message::FORM_PROVIDER_NOTIFY_FORMS_DELETE):
55 return HandleNotifyFormsDelete(data, reply);
56 case static_cast<uint32_t>(IFormProvider::Message::FORM_PROVIDER_NOTIFY_FORM_UPDATE):
57 return HandleNotifyFormUpdate(data, reply);
58 case static_cast<uint32_t>(IFormProvider::Message::FORM_PROVIDER_EVENT_NOTIFY):
59 return HandleEventNotify(data, reply);
60 case static_cast<uint32_t>(IFormProvider::Message::FORM_PROVIDER_NOTIFY_TEMP_FORM_CAST):
61 return HandleNotifyFormCastTempForm(data, reply);
62 case static_cast<uint32_t>(IFormProvider::Message::FORM_PROVIDER_EVENT_MESSAGE):
63 return HandleFireFormEvent(data, reply);
64 case static_cast<uint32_t>(IFormProvider::Message::FORM_PROVIDER_NOTIFY_STATE_ACQUIRE):
65 return HandleAcquireState(data, reply);
66 case static_cast<uint32_t>(IFormProvider::Message::FORM_ACQUIRE_PROVIDER_SHARE_FOMR_INFO):
67 return HandleAcquireShareFormData(data, reply);
68 case static_cast<uint32_t>(IFormProvider::Message::FORM_ACQUIRE_PROVIDER_FOMR_DATA):
69 return HandleAcquireFormData(data, reply);
70 default:
71 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
72 }
73 }
74
HandleAcquireProviderFormInfo(MessageParcel & data,MessageParcel & reply)75 int FormProviderStub::HandleAcquireProviderFormInfo(MessageParcel &data, MessageParcel &reply)
76 {
77 std::unique_ptr<FormJsInfo> formJsInfo(data.ReadParcelable<FormJsInfo>());
78 if (!formJsInfo) {
79 HILOG_ERROR("ReadParcelable<FormJsInfo> failed");
80 return ERR_APPEXECFWK_PARCEL_ERROR;
81 }
82 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
83 if (!want) {
84 HILOG_ERROR("ReadParcelable<Want> failed");
85 return ERR_APPEXECFWK_PARCEL_ERROR;
86 }
87
88 sptr<IRemoteObject> client = data.ReadRemoteObject();
89 if (client == nullptr) {
90 HILOG_ERROR("get remote object failed");
91 return ERR_APPEXECFWK_PARCEL_ERROR;
92 }
93
94 int32_t result = AcquireProviderFormInfo(*formJsInfo, *want, client);
95 reply.WriteInt32(result);
96 return result;
97 }
98 /**
99 * @brief handle NotifyFormDelete message.
100 * @param data input param.
101 * @param reply output param.
102 * @return Returns ERR_OK on success, others on failure.
103 */
HandleNotifyFormDelete(MessageParcel & data,MessageParcel & reply)104 int FormProviderStub::HandleNotifyFormDelete(MessageParcel &data, MessageParcel &reply)
105 {
106 int64_t formId = data.ReadInt64();
107 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
108 if (!want) {
109 HILOG_ERROR("ReadParcelable<FormReqInfo> failed");
110 return ERR_APPEXECFWK_PARCEL_ERROR;
111 }
112
113 sptr<IRemoteObject> client = data.ReadRemoteObject();
114 if (client == nullptr) {
115 HILOG_ERROR("get remote object failed");
116 return ERR_APPEXECFWK_PARCEL_ERROR;
117 }
118
119 int32_t result = NotifyFormDelete(formId, *want, client);
120 reply.WriteInt32(result);
121 return result;
122 }
123 /**
124 * @brief handle NotifyFormsDelete message.
125 * @param data input param.
126 * @param reply output param.
127 * @return Returns ERR_OK on success, others on failure.
128 */
HandleNotifyFormsDelete(MessageParcel & data,MessageParcel & reply)129 int FormProviderStub::HandleNotifyFormsDelete(MessageParcel &data, MessageParcel &reply)
130 {
131 std::vector<int64_t> formIds;
132 bool ret = data.ReadInt64Vector(&formIds);
133 if (ret) {
134 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
135 if (!want) {
136 HILOG_ERROR("ReadParcelable<FormReqInfo> failed");
137 return ERR_APPEXECFWK_PARCEL_ERROR;
138 }
139
140 sptr<IRemoteObject> client = data.ReadRemoteObject();
141 if (client == nullptr) {
142 HILOG_ERROR("get remote object failed");
143 return ERR_APPEXECFWK_PARCEL_ERROR;
144 }
145
146 int32_t result = NotifyFormsDelete(formIds, *want, client);
147 reply.WriteInt32(result);
148 return result;
149 }
150
151 return ERR_INVALID_DATA;
152 }
153 /**
154 * @brief handle NotifyFormUpdate message.
155 * @param data input param.
156 * @param reply output param.
157 * @return Returns ERR_OK on success, others on failure.
158 */
HandleNotifyFormUpdate(MessageParcel & data,MessageParcel & reply)159 int FormProviderStub::HandleNotifyFormUpdate(MessageParcel &data, MessageParcel &reply)
160 {
161 int64_t formId = data.ReadInt64();
162
163 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
164 if (!want) {
165 HILOG_ERROR("ReadParcelable<Want> failed");
166 return ERR_APPEXECFWK_PARCEL_ERROR;
167 }
168
169 sptr<IRemoteObject> client = data.ReadRemoteObject();
170 if (client == nullptr) {
171 HILOG_ERROR("get remote object failed");
172 return ERR_APPEXECFWK_PARCEL_ERROR;
173 }
174
175 int32_t result = NotifyFormUpdate(formId, *want, client);
176 reply.WriteInt32(result);
177 return result;
178 }
179
180 /**
181 * @brief handle EventNotify message.
182 * @param data input param.
183 * @param reply output param.
184 * @return Returns ERR_OK on success, others on failure.
185 */
HandleEventNotify(MessageParcel & data,MessageParcel & reply)186 int FormProviderStub::HandleEventNotify(MessageParcel &data, MessageParcel &reply)
187 {
188 std::vector<int64_t> formIds;
189 bool ret = data.ReadInt64Vector(&formIds);
190 if (ret) {
191 int32_t formVisibleType = data.ReadInt32();
192
193 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
194 if (!want) {
195 HILOG_ERROR("ReadParcelable<Want> failed");
196 return ERR_APPEXECFWK_PARCEL_ERROR;
197 }
198
199 sptr<IRemoteObject> client = data.ReadRemoteObject();
200 if (client == nullptr) {
201 HILOG_ERROR("get remote object failed");
202 return ERR_APPEXECFWK_PARCEL_ERROR;
203 }
204
205 int32_t result = EventNotify(formIds, formVisibleType, *want, client);
206 reply.WriteInt32(result);
207 return result;
208 }
209
210 return ERR_INVALID_DATA;
211 }
212
213 /**
214 * @brief handle NotifyFormCastTempForm message.
215 * @param data input param.
216 * @param reply output param.
217 * @return Returns ERR_OK on success, others on failure.
218 */
HandleNotifyFormCastTempForm(MessageParcel & data,MessageParcel & reply)219 int FormProviderStub::HandleNotifyFormCastTempForm(MessageParcel &data, MessageParcel &reply)
220 {
221 int64_t formId = data.ReadInt64();
222
223 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
224 if (!want) {
225 HILOG_ERROR("ReadParcelable<Want> failed");
226 return ERR_APPEXECFWK_PARCEL_ERROR;
227 }
228
229 sptr<IRemoteObject> client = data.ReadRemoteObject();
230 if (client == nullptr) {
231 HILOG_ERROR("get remote object failed");
232 return ERR_APPEXECFWK_PARCEL_ERROR;
233 }
234
235 int32_t result = NotifyFormCastTempForm(formId, *want, client);
236 reply.WriteInt32(result);
237 return result;
238 }
239 /**
240 * @brief handle NotifyFormCastTempForm message.
241 * @param data input param.
242 * @param reply output param.
243 * @return Returns ERR_OK on success, others on failure.
244 */
HandleFireFormEvent(MessageParcel & data,MessageParcel & reply)245 int FormProviderStub::HandleFireFormEvent(MessageParcel &data, MessageParcel &reply)
246 {
247 int64_t formId = data.ReadInt64();
248 std::string message = data.ReadString();
249 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
250 if (!want) {
251 HILOG_ERROR("get want failed");
252 return ERR_APPEXECFWK_PARCEL_ERROR;
253 }
254
255 sptr<IRemoteObject> client = data.ReadRemoteObject();
256 if (client == nullptr) {
257 HILOG_ERROR("get remote object failed");
258 return ERR_APPEXECFWK_PARCEL_ERROR;
259 }
260
261 int32_t result = FireFormEvent(formId, message, *want, client);
262 reply.WriteInt32(result);
263 return result;
264 }
265 /**
266 * @brief handle AcquireState message.
267 * @param data input param.
268 * @param reply output param.
269 * @return Returns ERR_OK on success, others on failure.
270 */
HandleAcquireState(MessageParcel & data,MessageParcel & reply)271 int FormProviderStub::HandleAcquireState(MessageParcel &data, MessageParcel &reply)
272 {
273 std::unique_ptr<Want> wantArg(data.ReadParcelable<Want>());
274 if (!wantArg) {
275 HILOG_ERROR("ReadParcelable<Want> failed");
276 return ERR_APPEXECFWK_PARCEL_ERROR;
277 }
278 std::string provider = data.ReadString();
279 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
280 if (!want) {
281 HILOG_ERROR("ReadParcelable<Want> failed");
282 return ERR_APPEXECFWK_PARCEL_ERROR;
283 }
284 sptr<IRemoteObject> client = data.ReadRemoteObject();
285 if (client == nullptr) {
286 HILOG_ERROR("get remote object failed");
287 return ERR_APPEXECFWK_PARCEL_ERROR;
288 }
289 int32_t result = AcquireState(*wantArg, provider, *want, client);
290 reply.WriteInt32(result);
291 return result;
292 }
293
HandleAcquireShareFormData(MessageParcel & data,MessageParcel & reply)294 int32_t FormProviderStub::HandleAcquireShareFormData(MessageParcel &data, MessageParcel &reply)
295 {
296 auto formId = data.ReadInt64();
297 auto remoteDeviceId = data.ReadString();
298 auto remoteObj = data.ReadRemoteObject();
299 if (remoteObj == nullptr) {
300 HILOG_ERROR("get remoteObject failed");
301 return ERR_APPEXECFWK_PARCEL_ERROR;
302 }
303
304 auto requestCode = data.ReadInt64();
305 auto result = AcquireShareFormData(formId, remoteDeviceId, remoteObj, requestCode);
306 if (!reply.WriteInt32(result)) {
307 HILOG_ERROR("write result failed");
308 return ERR_APPEXECFWK_PARCEL_ERROR;
309 }
310
311 return ERR_OK;
312 }
313
HandleAcquireFormData(MessageParcel & data,MessageParcel & reply)314 int32_t FormProviderStub::HandleAcquireFormData(MessageParcel &data, MessageParcel &reply)
315 {
316 auto formId = data.ReadInt64();
317 auto remoteObj = data.ReadRemoteObject();
318 if (remoteObj == nullptr) {
319 HILOG_ERROR("get remoteObject failed");
320 return ERR_APPEXECFWK_PARCEL_ERROR;
321 }
322
323 auto requestCode = data.ReadInt64();
324 auto result = AcquireFormData(formId, remoteObj, requestCode);
325 if (!reply.WriteInt32(result)) {
326 HILOG_ERROR("write result failed");
327 return ERR_APPEXECFWK_PARCEL_ERROR;
328 }
329
330 return ERR_OK;
331 }
332 } // namespace AppExecFwk
333 } // namespace OHOS