• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 "form_supply_stub.h"
17 
18 #include "appexecfwk_errors.h"
19 #include "fms_log_wrapper.h"
20 #include "form_constants.h"
21 #include "form_mgr_errors.h"
22 #include "form_supply_stub.h"
23 #include "ipc_skeleton.h"
24 #include "ipc_types.h"
25 #include "iremote_object.h"
26 
27 namespace OHOS {
28 namespace AppExecFwk {
FormSupplyStub()29 FormSupplyStub::FormSupplyStub()
30 {}
31 
~FormSupplyStub()32 FormSupplyStub::~FormSupplyStub()
33 {}
34 /**
35  * @brief handle remote request.
36  * @param data input param.
37  * @param reply output param.
38  * @param option message option.
39  * @return Returns ERR_OK on success, others on failure.
40  */
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)41 int FormSupplyStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
42 {
43     HILOG_DEBUG("FormSupplyStub::OnReceived,code= %{public}u,flags= %{public}d", code, option.GetFlags());
44     std::u16string descriptor = FormSupplyStub::GetDescriptor();
45     std::u16string remoteDescriptor = data.ReadInterfaceToken();
46     if (descriptor != remoteDescriptor) {
47         HILOG_ERROR("localDescriptor not equal to remote");
48         return ERR_APPEXECFWK_FORM_INVALID_PARAM;
49     }
50 
51     switch (code) {
52         case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_ACQUIRED):
53             return HandleOnAcquire(data, reply);
54         case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_EVENT_HANDLE):
55             return HandleOnEventHandle(data, reply);
56         case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_STATE_ACQUIRED):
57             return HandleOnAcquireStateResult(data, reply);
58         case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_SHARE_ACQUIRED):
59             return HandleOnShareAcquire(data, reply);
60         case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_RENDER_TASK_DONE):
61             return HandleOnRenderTaskDone(data, reply);
62         case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_STOP_RENDERING_TASK_DONE):
63             return HandleOnStopRenderingTaskDone(data, reply);
64         case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_ACQUIRED_DATA):
65             return HandleOnAcquireDataResult(data, reply);
66         case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_RENDERING_BLOCK):
67             return HandleOnRenderingBlock(data, reply);
68         case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_RECYCLE_FORM):
69             return HandleOnRecycleForm(data, reply);
70         case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_RECOVER_FORM_BY_CONFIG_UPDATE):
71             return HandleOnRecoverFormsByConfigUpdate(data, reply);
72         case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_NOTIFY_REFRESH):
73             return HandleOnNotifyRefreshForm(data, reply);
74         case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_RENDER_FORM_DONE):
75             return HandleOnRenderFormDone(data, reply);
76         case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_RECOVER_FORM_DONE):
77             return HandleOnRecoverFormDone(data, reply);
78         case static_cast<uint32_t>(IFormSupply::Message::TRANSACTION_FORM_RECYCLE_FORM_DONE):
79             return HandleOnRecycleFormDone(data, reply);
80         default:
81             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
82     }
83 }
84 /**
85  * @brief handle OnAcquire message.
86  * @param data input param.
87  * @param reply output param.
88  * @return Returns ERR_OK on success, others on failure.
89  */
HandleOnAcquire(MessageParcel & data,MessageParcel & reply)90 int FormSupplyStub::HandleOnAcquire(MessageParcel &data, MessageParcel &reply)
91 {
92     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
93     if (!want) {
94         HILOG_ERROR("ReadParcelable<Want> failed");
95         reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
96         return ERR_APPEXECFWK_PARCEL_ERROR;
97     }
98 
99     int errCode = ERR_OK;
100     do {
101         errCode = want->GetIntParam(Constants::PROVIDER_FLAG, ERR_OK);
102         if (errCode != ERR_OK) {
103             HILOG_ERROR("get providerParam failed");
104             break;
105         }
106         std::unique_ptr<FormProviderInfo> formInfo(data.ReadParcelable<FormProviderInfo>());
107         if (formInfo == nullptr) {
108             HILOG_ERROR("fail ReadParcelable<FormProviderInfo>");
109             errCode = ERR_APPEXECFWK_PARCEL_ERROR;
110             break;
111         }
112         int32_t result = OnAcquire(*formInfo, *want);
113         reply.WriteInt32(result);
114         return result;
115     } while (false);
116 
117     FormProviderInfo formProviderInfo;
118     want->SetParam(Constants::PROVIDER_FLAG, errCode);
119     OnAcquire(formProviderInfo, *want);
120     reply.WriteInt32(errCode);
121     return errCode;
122 }
123 /**
124  * @brief handle OnEventHandle message.
125  * @param data input param.
126  * @param reply output param.
127  * @return Returns ERR_OK on success, others on failure.
128  */
HandleOnEventHandle(MessageParcel & data,MessageParcel & reply)129 int FormSupplyStub::HandleOnEventHandle(MessageParcel &data, MessageParcel &reply)
130 {
131     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
132     if (!want) {
133         HILOG_ERROR("ReadParcelable<Want> failed");
134         reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
135         return ERR_APPEXECFWK_PARCEL_ERROR;
136     }
137 
138     int32_t result = OnEventHandle(*want);
139     reply.WriteInt32(result);
140     return result;
141 }
142 
143 /**
144  * @brief handle OnAcquireStateResult message.
145  * @param data input param.
146  * @param reply output param.
147  * @return Returns ERR_OK on success, others on failure.
148  */
HandleOnAcquireStateResult(MessageParcel & data,MessageParcel & reply)149 int FormSupplyStub::HandleOnAcquireStateResult(MessageParcel &data, MessageParcel &reply)
150 {
151     auto state = (FormState) data.ReadInt32();
152     std::string provider = data.ReadString();
153     std::unique_ptr<Want> wantArg(data.ReadParcelable<Want>());
154     if (!wantArg) {
155         HILOG_ERROR("ReadParcelable<Want> failed");
156         reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
157         return ERR_APPEXECFWK_PARCEL_ERROR;
158     }
159 
160     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
161     if (!want) {
162         HILOG_ERROR("ReadParcelable<Want> failed");
163         reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
164         return ERR_APPEXECFWK_PARCEL_ERROR;
165     }
166 
167     int32_t result = OnAcquireStateResult(state, provider, *wantArg, *want);
168     reply.WriteInt32(result);
169     return result;
170 }
171 
HandleOnShareAcquire(MessageParcel & data,MessageParcel & reply)172 int32_t FormSupplyStub::HandleOnShareAcquire(MessageParcel &data, MessageParcel &reply)
173 {
174     auto formId = data.ReadInt64();
175     if (formId <= 0) {
176         HILOG_ERROR("ReadInt64<formId> failed");
177         return ERR_APPEXECFWK_PARCEL_ERROR;
178     }
179 
180     auto remoteDeviceId = data.ReadString();
181     if (remoteDeviceId.empty()) {
182         HILOG_ERROR("fail ReadString<DeviceId>");
183         return ERR_APPEXECFWK_PARCEL_ERROR;
184     }
185 
186     std::shared_ptr<AAFwk::WantParams> wantParams(data.ReadParcelable<AAFwk::WantParams>());
187     if (wantParams == nullptr) {
188         HILOG_ERROR("error to ReadParcelable<wantParams>");
189         return ERR_APPEXECFWK_PARCEL_ERROR;
190     }
191 
192     auto requestCode = data.ReadInt64();
193     if (requestCode <= 0) {
194         HILOG_ERROR("error to ReadInt64<requestCode>");
195         return ERR_APPEXECFWK_PARCEL_ERROR;
196     }
197 
198     auto result = data.ReadBool();
199     OnShareAcquire(formId, remoteDeviceId, *wantParams, requestCode, result);
200     return ERR_OK;
201 }
202 
HandleOnAcquireDataResult(MessageParcel & data,MessageParcel & reply)203 int32_t FormSupplyStub::HandleOnAcquireDataResult(MessageParcel &data, MessageParcel &reply)
204 {
205     std::shared_ptr<AAFwk::WantParams> wantParams(data.ReadParcelable<AAFwk::WantParams>());
206     if (wantParams == nullptr) {
207         HILOG_ERROR("ReadParcelable<wantParams> failed");
208         return ERR_APPEXECFWK_PARCEL_ERROR;
209     }
210 
211     auto requestCode = data.ReadInt64();
212     if (requestCode <= 0) {
213         HILOG_ERROR("fail ReadInt64<requestCode>");
214         return ERR_APPEXECFWK_PARCEL_ERROR;
215     }
216 
217     OnAcquireDataResult(*wantParams, requestCode);
218     return ERR_OK;
219 }
220 
HandleOnRenderTaskDone(MessageParcel & data,MessageParcel & reply)221 int32_t FormSupplyStub::HandleOnRenderTaskDone(MessageParcel &data, MessageParcel &reply)
222 {
223     auto formId = data.ReadInt64();
224     if (formId <= 0) {
225         HILOG_ERROR("ReadInt64<formId> failed");
226         return ERR_APPEXECFWK_PARCEL_ERROR;
227     }
228 
229     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
230     if (!want) {
231         HILOG_ERROR("ReadParcelable<Want> failed");
232         reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
233         return ERR_APPEXECFWK_PARCEL_ERROR;
234     }
235 
236     int32_t result = OnRenderTaskDone(formId, *want);
237     reply.WriteInt32(result);
238     return result;
239 }
240 
HandleOnStopRenderingTaskDone(MessageParcel & data,MessageParcel & reply)241 int32_t FormSupplyStub::HandleOnStopRenderingTaskDone(MessageParcel &data, MessageParcel &reply)
242 {
243     auto formId = data.ReadInt64();
244     if (formId <= 0) {
245         HILOG_ERROR("ReadInt64<formId> failed");
246         return ERR_APPEXECFWK_PARCEL_ERROR;
247     }
248 
249     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
250     if (!want) {
251         HILOG_ERROR("ReadParcelable<Want> failed");
252         reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
253         return ERR_APPEXECFWK_PARCEL_ERROR;
254     }
255 
256     int32_t result = OnStopRenderingTaskDone(formId, *want);
257     reply.WriteInt32(result);
258     return result;
259 }
260 
HandleOnRenderingBlock(MessageParcel & data,MessageParcel & reply)261 int32_t FormSupplyStub::HandleOnRenderingBlock(MessageParcel &data, MessageParcel &reply)
262 {
263     auto bundleName = data.ReadString();
264     if (bundleName.empty()) {
265         HILOG_ERROR("fail ReadString<bundleName>");
266         return ERR_APPEXECFWK_PARCEL_ERROR;
267     }
268 
269     int32_t result = OnRenderingBlock(bundleName);
270     reply.WriteInt32(result);
271     return result;
272 }
273 
HandleOnRecycleForm(MessageParcel & data,MessageParcel & reply)274 int32_t FormSupplyStub::HandleOnRecycleForm(MessageParcel &data, MessageParcel &reply)
275 {
276     int64_t formId = data.ReadInt64();
277     if (formId <= 0) {
278         HILOG_ERROR("ReadInt64<formId> failed");
279         return ERR_APPEXECFWK_PARCEL_ERROR;
280     }
281 
282     std::unique_ptr<Want> want(data.ReadParcelable<Want>());
283     if (!want) {
284         HILOG_ERROR("ReadParcelable<Want> failed");
285         reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
286         return ERR_APPEXECFWK_PARCEL_ERROR;
287     }
288 
289     int32_t result = OnRecycleForm(formId, *want);
290     reply.WriteInt32(result);
291     return result;
292 }
293 
HandleOnRecoverFormsByConfigUpdate(MessageParcel & data,MessageParcel & reply)294 int32_t FormSupplyStub::HandleOnRecoverFormsByConfigUpdate(MessageParcel &data, MessageParcel &reply)
295 {
296     std::vector<int64_t> formIds;
297 
298     if (!data.ReadInt64Vector(&formIds)) {
299         HILOG_ERROR("ReadInt64Vector failed");
300         return ERR_APPEXECFWK_PARCEL_ERROR;
301     }
302 
303     if (formIds.empty()) {
304         HILOG_ERROR("empty formIds");
305         return ERR_APPEXECFWK_PARCEL_ERROR;
306     }
307 
308     int32_t result = OnRecoverFormsByConfigUpdate(formIds);
309     reply.WriteInt32(result);
310     return result;
311 }
312 
HandleOnNotifyRefreshForm(MessageParcel & data,MessageParcel & reply)313 int32_t FormSupplyStub::HandleOnNotifyRefreshForm(MessageParcel &data, MessageParcel &reply)
314 {
315     int64_t formId = data.ReadInt64();
316     if (formId <= 0) {
317         HILOG_ERROR("ReadInt64<formId> failed");
318         return ERR_APPEXECFWK_PARCEL_ERROR;
319     }
320 
321     int32_t result = OnNotifyRefreshForm(formId);
322     reply.WriteInt32(result);
323     return ERR_OK;
324 }
325 
HandleOnRenderFormDone(MessageParcel & data,MessageParcel & reply)326 int32_t FormSupplyStub::HandleOnRenderFormDone(MessageParcel &data, MessageParcel &reply)
327 {
328     auto formId = data.ReadInt64();
329     if (formId <= 0) {
330         HILOG_ERROR("ReadInt64<formId> failed");
331         return ERR_APPEXECFWK_PARCEL_ERROR;
332     }
333 
334     int32_t result = OnRenderFormDone(formId);
335     reply.WriteInt32(result);
336     return result;
337 }
338 
HandleOnRecoverFormDone(MessageParcel & data,MessageParcel & reply)339 int32_t FormSupplyStub::HandleOnRecoverFormDone(MessageParcel &data, MessageParcel &reply)
340 {
341     auto formId = data.ReadInt64();
342     if (formId <= 0) {
343         HILOG_ERROR("ReadInt64<formId> failed");
344         return ERR_APPEXECFWK_PARCEL_ERROR;
345     }
346 
347     int32_t result = OnRecoverFormDone(formId);
348     reply.WriteInt32(result);
349     return result;
350 }
351 
HandleOnRecycleFormDone(MessageParcel & data,MessageParcel & reply)352 int32_t FormSupplyStub::HandleOnRecycleFormDone(MessageParcel &data, MessageParcel &reply)
353 {
354     auto formId = data.ReadInt64();
355     if (formId <= 0) {
356         HILOG_ERROR("ReadInt64<formId> failed");
357         return ERR_APPEXECFWK_PARCEL_ERROR;
358     }
359 
360     int32_t result = OnRecycleFormDone(formId);
361     reply.WriteInt32(result);
362     return result;
363 }
364 }  // namespace AppExecFwk
365 }  // namespace OHOS