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 default:
75 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
76 }
77 }
78 /**
79 * @brief handle OnAcquire message.
80 * @param data input param.
81 * @param reply output param.
82 * @return Returns ERR_OK on success, others on failure.
83 */
HandleOnAcquire(MessageParcel & data,MessageParcel & reply)84 int FormSupplyStub::HandleOnAcquire(MessageParcel &data, MessageParcel &reply)
85 {
86 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
87 if (!want) {
88 HILOG_ERROR("ReadParcelable<Want> failed");
89 reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
90 return ERR_APPEXECFWK_PARCEL_ERROR;
91 }
92
93 int errCode = ERR_OK;
94 do {
95 errCode = want->GetIntParam(Constants::PROVIDER_FLAG, ERR_OK);
96 if (errCode != ERR_OK) {
97 HILOG_ERROR("get providerParam failed");
98 break;
99 }
100 std::unique_ptr<FormProviderInfo> formInfo(data.ReadParcelable<FormProviderInfo>());
101 if (formInfo == nullptr) {
102 HILOG_ERROR("fail ReadParcelable<FormProviderInfo>");
103 errCode = ERR_APPEXECFWK_PARCEL_ERROR;
104 break;
105 }
106 int32_t result = OnAcquire(*formInfo, *want);
107 reply.WriteInt32(result);
108 return result;
109 } while (false);
110
111 FormProviderInfo formProviderInfo;
112 want->SetParam(Constants::PROVIDER_FLAG, errCode);
113 OnAcquire(formProviderInfo, *want);
114 reply.WriteInt32(errCode);
115 return errCode;
116 }
117 /**
118 * @brief handle OnEventHandle message.
119 * @param data input param.
120 * @param reply output param.
121 * @return Returns ERR_OK on success, others on failure.
122 */
HandleOnEventHandle(MessageParcel & data,MessageParcel & reply)123 int FormSupplyStub::HandleOnEventHandle(MessageParcel &data, MessageParcel &reply)
124 {
125 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
126 if (!want) {
127 HILOG_ERROR("ReadParcelable<Want> failed");
128 reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
129 return ERR_APPEXECFWK_PARCEL_ERROR;
130 }
131
132 int32_t result = OnEventHandle(*want);
133 reply.WriteInt32(result);
134 return result;
135 }
136
137 /**
138 * @brief handle OnAcquireStateResult message.
139 * @param data input param.
140 * @param reply output param.
141 * @return Returns ERR_OK on success, others on failure.
142 */
HandleOnAcquireStateResult(MessageParcel & data,MessageParcel & reply)143 int FormSupplyStub::HandleOnAcquireStateResult(MessageParcel &data, MessageParcel &reply)
144 {
145 auto state = (FormState) data.ReadInt32();
146 std::string provider = data.ReadString();
147 std::unique_ptr<Want> wantArg(data.ReadParcelable<Want>());
148 if (!wantArg) {
149 HILOG_ERROR("ReadParcelable<Want> failed");
150 reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
151 return ERR_APPEXECFWK_PARCEL_ERROR;
152 }
153
154 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
155 if (!want) {
156 HILOG_ERROR("ReadParcelable<Want> failed");
157 reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
158 return ERR_APPEXECFWK_PARCEL_ERROR;
159 }
160
161 int32_t result = OnAcquireStateResult(state, provider, *wantArg, *want);
162 reply.WriteInt32(result);
163 return result;
164 }
165
HandleOnShareAcquire(MessageParcel & data,MessageParcel & reply)166 int32_t FormSupplyStub::HandleOnShareAcquire(MessageParcel &data, MessageParcel &reply)
167 {
168 auto formId = data.ReadInt64();
169 if (formId <= 0) {
170 HILOG_ERROR("ReadInt64<formId> failed");
171 return ERR_APPEXECFWK_PARCEL_ERROR;
172 }
173
174 auto remoteDeviceId = data.ReadString();
175 if (remoteDeviceId.empty()) {
176 HILOG_ERROR("fail ReadString<DeviceId>");
177 return ERR_APPEXECFWK_PARCEL_ERROR;
178 }
179
180 std::shared_ptr<AAFwk::WantParams> wantParams(data.ReadParcelable<AAFwk::WantParams>());
181 if (wantParams == nullptr) {
182 HILOG_ERROR("error to ReadParcelable<wantParams>");
183 return ERR_APPEXECFWK_PARCEL_ERROR;
184 }
185
186 auto requestCode = data.ReadInt64();
187 if (requestCode <= 0) {
188 HILOG_ERROR("error to ReadInt64<requestCode>");
189 return ERR_APPEXECFWK_PARCEL_ERROR;
190 }
191
192 auto result = data.ReadBool();
193 OnShareAcquire(formId, remoteDeviceId, *wantParams, requestCode, result);
194 return ERR_OK;
195 }
196
HandleOnAcquireDataResult(MessageParcel & data,MessageParcel & reply)197 int32_t FormSupplyStub::HandleOnAcquireDataResult(MessageParcel &data, MessageParcel &reply)
198 {
199 std::shared_ptr<AAFwk::WantParams> wantParams(data.ReadParcelable<AAFwk::WantParams>());
200 if (wantParams == nullptr) {
201 HILOG_ERROR("ReadParcelable<wantParams> failed");
202 return ERR_APPEXECFWK_PARCEL_ERROR;
203 }
204
205 auto requestCode = data.ReadInt64();
206 if (requestCode <= 0) {
207 HILOG_ERROR("fail ReadInt64<requestCode>");
208 return ERR_APPEXECFWK_PARCEL_ERROR;
209 }
210
211 OnAcquireDataResult(*wantParams, requestCode);
212 return ERR_OK;
213 }
214
HandleOnRenderTaskDone(MessageParcel & data,MessageParcel & reply)215 int32_t FormSupplyStub::HandleOnRenderTaskDone(MessageParcel &data, MessageParcel &reply)
216 {
217 auto formId = data.ReadInt64();
218 if (formId <= 0) {
219 HILOG_ERROR("ReadInt64<formId> failed");
220 return ERR_APPEXECFWK_PARCEL_ERROR;
221 }
222
223 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
224 if (!want) {
225 HILOG_ERROR("ReadParcelable<Want> failed");
226 reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
227 return ERR_APPEXECFWK_PARCEL_ERROR;
228 }
229
230 int32_t result = OnRenderTaskDone(formId, *want);
231 reply.WriteInt32(result);
232 return result;
233 }
234
HandleOnStopRenderingTaskDone(MessageParcel & data,MessageParcel & reply)235 int32_t FormSupplyStub::HandleOnStopRenderingTaskDone(MessageParcel &data, MessageParcel &reply)
236 {
237 auto formId = data.ReadInt64();
238 if (formId <= 0) {
239 HILOG_ERROR("ReadInt64<formId> failed");
240 return ERR_APPEXECFWK_PARCEL_ERROR;
241 }
242
243 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
244 if (!want) {
245 HILOG_ERROR("ReadParcelable<Want> failed");
246 reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
247 return ERR_APPEXECFWK_PARCEL_ERROR;
248 }
249
250 int32_t result = OnStopRenderingTaskDone(formId, *want);
251 reply.WriteInt32(result);
252 return result;
253 }
254
HandleOnRenderingBlock(MessageParcel & data,MessageParcel & reply)255 int32_t FormSupplyStub::HandleOnRenderingBlock(MessageParcel &data, MessageParcel &reply)
256 {
257 auto bundleName = data.ReadString();
258 if (bundleName.empty()) {
259 HILOG_ERROR("fail ReadString<bundleName>");
260 return ERR_APPEXECFWK_PARCEL_ERROR;
261 }
262
263 int32_t result = OnRenderingBlock(bundleName);
264 reply.WriteInt32(result);
265 return result;
266 }
267
HandleOnRecycleForm(MessageParcel & data,MessageParcel & reply)268 int32_t FormSupplyStub::HandleOnRecycleForm(MessageParcel &data, MessageParcel &reply)
269 {
270 int64_t formId = data.ReadInt64();
271 if (formId <= 0) {
272 HILOG_ERROR("ReadInt64<formId> failed");
273 return ERR_APPEXECFWK_PARCEL_ERROR;
274 }
275
276 std::unique_ptr<Want> want(data.ReadParcelable<Want>());
277 if (!want) {
278 HILOG_ERROR("ReadParcelable<Want> failed");
279 reply.WriteInt32(ERR_APPEXECFWK_PARCEL_ERROR);
280 return ERR_APPEXECFWK_PARCEL_ERROR;
281 }
282
283 int32_t result = OnRecycleForm(formId, *want);
284 reply.WriteInt32(result);
285 return result;
286 }
287
HandleOnRecoverFormsByConfigUpdate(MessageParcel & data,MessageParcel & reply)288 int32_t FormSupplyStub::HandleOnRecoverFormsByConfigUpdate(MessageParcel &data, MessageParcel &reply)
289 {
290 std::vector<int64_t> formIds;
291
292 if (!data.ReadInt64Vector(&formIds)) {
293 HILOG_ERROR("ReadInt64Vector failed");
294 return ERR_APPEXECFWK_PARCEL_ERROR;
295 }
296
297 if (formIds.empty()) {
298 HILOG_ERROR("empty formIds");
299 return ERR_APPEXECFWK_PARCEL_ERROR;
300 }
301
302 int32_t result = OnRecoverFormsByConfigUpdate(formIds);
303 reply.WriteInt32(result);
304 return result;
305 }
306
HandleOnNotifyRefreshForm(MessageParcel & data,MessageParcel & reply)307 int32_t FormSupplyStub::HandleOnNotifyRefreshForm(MessageParcel &data, MessageParcel &reply)
308 {
309 int64_t formId = data.ReadInt64();
310 if (formId <= 0) {
311 HILOG_ERROR("ReadInt64<formId> failed");
312 return ERR_APPEXECFWK_PARCEL_ERROR;
313 }
314
315 int32_t result = OnNotifyRefreshForm(formId);
316 reply.WriteInt32(result);
317 return ERR_OK;
318 }
319 } // namespace AppExecFwk
320 } // namespace OHOS