1 /*
2 * Copyright (c) 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 "print_service_stub.h"
17 #include "ipc_skeleton.h"
18 #include "iprint_service.h"
19 #include "message_parcel.h"
20 #include "print_constant.h"
21 #include "print_extension_info.h"
22 #include "print_job.h"
23 #include "print_log.h"
24
25 namespace OHOS::Print {
26 using namespace OHOS::HiviewDFX;
27
PrintServiceStub()28 PrintServiceStub::PrintServiceStub()
29 {
30 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_START_PRINT] = &PrintServiceStub::OnStartPrint;
31 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_STOP_PRINT] = &PrintServiceStub::OnStopPrint;
32 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_CONNECTPRINTER] = &PrintServiceStub::OnConnectPrinter;
33 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_DISCONNECTPRINTER] = &PrintServiceStub::OnDisconnectPrinter;
34 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_STARTDISCOVERPRINTER] = &PrintServiceStub::OnStartDiscoverPrinter;
35 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_STOPDISCOVERPRINTER] = &PrintServiceStub::OnStopDiscoverPrint;
36 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_QUERYALLEXTENSION] = &PrintServiceStub::OnQueryAllExtension;
37 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_STARTPRINTJOB] = &PrintServiceStub::OnStartPrintJob;
38 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_CANCELPRINTJOB] = &PrintServiceStub::OnCancelPrintJob;
39 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_ADDPRINTERS] = &PrintServiceStub::OnAddPrinters;
40 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_REMOVEPRINTERS] = &PrintServiceStub::OnRemovePrinters;
41 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_UPDATEPRINTERS] = &PrintServiceStub::OnUpdatePrinters;
42 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_UPDATEPRINTERSTATE] = &PrintServiceStub::OnUpdatePrinterState;
43 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_UPDATEPRINTJOBSTATE] = &PrintServiceStub::OnUpdatePrintJobState;
44 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_UPDATEEXTENSIONINFO] = &PrintServiceStub::OnUpdateExtensionInfo;
45 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_REQUESTPREVIEW] = &PrintServiceStub::OnRequestPreview;
46 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_QUERYPRINTERCAPABILITY] = &PrintServiceStub::OnQueryPrinterCapability;
47 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_ON] = &PrintServiceStub::OnEventOn;
48 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_OFF] = &PrintServiceStub::OnEventOff;
49 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_REG_EXT_CB] = &PrintServiceStub::OnRegisterExtCallback;
50 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_UNREG_EXT_CB] = &PrintServiceStub::OnUnregisterAllExtCallback;
51 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_LOAD_EXT] = &PrintServiceStub::OnLoadExtSuccess;
52 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_QUERYALLPRINTJOB] = &PrintServiceStub::OnQueryAllPrintJob;
53 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_QUERYPRINTJOBBYID] = &PrintServiceStub::OnQueryPrintJobById;
54 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_ADDPRINTERTOCUPS] = &PrintServiceStub::OnAddPrinterToCups;
55 cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_QUERYPRINTERCAPABILITYBYURI] =
56 &PrintServiceStub::OnQueryPrinterCapabilityByUri;
57 }
58
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)59 int32_t PrintServiceStub::OnRemoteRequest(
60 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
61 {
62 PRINT_HILOGD("OnRemoteRequest started, code = %{public}d", code);
63 auto descriptorToken = data.ReadInterfaceToken();
64 if (descriptorToken != GetDescriptor()) {
65 PRINT_HILOGE("Remote descriptor not the same as local descriptor.");
66 return E_PRINT_RPC_FAILURE;
67 }
68
69 auto itFunc = cmdMap_.find(code);
70 if (itFunc != cmdMap_.end()) {
71 auto requestFunc = itFunc->second;
72 if (requestFunc != nullptr) {
73 return (this->*requestFunc)(data, reply);
74 }
75 }
76 PRINT_HILOGW("default case, need check.");
77 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
78 }
79
OnStartPrint(MessageParcel & data,MessageParcel & reply)80 bool PrintServiceStub::OnStartPrint(MessageParcel &data, MessageParcel &reply)
81 {
82 PRINT_HILOGD("PrintServiceStub::OnStartPrint in");
83 std::vector<std::string> fileList;
84 std::vector<uint32_t> fdList;
85 std::string result = "";
86
87 if (data.ReadBool()) {
88 data.ReadStringVector(&fileList);
89 PRINT_HILOGD("Current file is %{public}zd", fileList.size());
90 CHECK_IS_EXCEED_PRINT_RANGE_BOOL(fileList.size());
91 for (auto file : fileList) {
92 PRINT_HILOGD("file is %{private}s", file.c_str());
93 }
94 }
95
96 if (data.ReadBool()) {
97 int32_t len = data.ReadInt32();
98 CHECK_IS_EXCEED_PRINT_RANGE_BOOL(len);
99 for (int32_t index = 0; index < len; index++) {
100 uint32_t fd = static_cast<uint32_t>(data.ReadFileDescriptor());
101 PRINT_HILOGD("fdList[%{public}d] = %{public}d", index, fd);
102 fdList.emplace_back(fd);
103 }
104 }
105
106 sptr<IRemoteObject> token = data.ReadRemoteObject();
107 PRINT_HILOGI("OnStartPrint read token %{public}s", token != nullptr ? "success" : "failed");
108 int32_t ret = E_PRINT_NONE;
109 if (token == nullptr) {
110 ret = StartPrint(fileList, fdList, result);
111 } else {
112 ret = StartPrint(fileList, fdList, result, token);
113 }
114 reply.WriteInt32(ret);
115 reply.WriteString(result);
116 PRINT_HILOGD("PrintServiceStub::OnStartPrint out");
117 return ret == E_PRINT_NONE;
118 }
119
OnStopPrint(MessageParcel & data,MessageParcel & reply)120 bool PrintServiceStub::OnStopPrint(MessageParcel &data, MessageParcel &reply)
121 {
122 PRINT_HILOGD("PrintServiceStub::OnStopPrint in");
123 std::string taskId = data.ReadString();
124 int32_t ret = StopPrint(taskId);
125 reply.WriteInt32(ret);
126 PRINT_HILOGD("PrintServiceStub::OnStopPrint out");
127 return ret == E_PRINT_NONE;
128 }
129
OnConnectPrinter(MessageParcel & data,MessageParcel & reply)130 bool PrintServiceStub::OnConnectPrinter(MessageParcel &data, MessageParcel &reply)
131 {
132 PRINT_HILOGD("PrintServiceStub::OnConnectPrinter in");
133 int32_t ret = ConnectPrinter(data.ReadString());
134 reply.WriteInt32(ret);
135 PRINT_HILOGD("PrintServiceStub::OnConnectPrinter out");
136 return ret == E_PRINT_NONE;
137 }
138
OnDisconnectPrinter(MessageParcel & data,MessageParcel & reply)139 bool PrintServiceStub::OnDisconnectPrinter(MessageParcel &data, MessageParcel &reply)
140 {
141 PRINT_HILOGD("PrintServiceStub::OnDisconnectPrinter in");
142 int32_t ret = DisconnectPrinter(data.ReadString());
143 reply.WriteInt32(ret);
144 PRINT_HILOGD("PrintServiceStub::OnDisconnectPrinter out");
145 return ret == E_PRINT_NONE;
146 }
147
OnStartDiscoverPrinter(MessageParcel & data,MessageParcel & reply)148 bool PrintServiceStub::OnStartDiscoverPrinter(MessageParcel &data, MessageParcel &reply)
149 {
150 PRINT_HILOGD("PrintServiceStub::OnStartDiscoverPrinter in");
151 std::vector<std::string> extensionList;
152 data.ReadStringVector(&extensionList);
153 int32_t ret = StartDiscoverPrinter(extensionList);
154 reply.WriteInt32(ret);
155 PRINT_HILOGD("PrintServiceStub::OnStartDiscoverPrinter out");
156 return ret == E_PRINT_NONE;
157 }
158
OnStopDiscoverPrint(MessageParcel & data,MessageParcel & reply)159 bool PrintServiceStub::OnStopDiscoverPrint(MessageParcel &data, MessageParcel &reply)
160 {
161 PRINT_HILOGD("PrintServiceStub::OnStopDiscoverPrint in");
162 int32_t ret = StopDiscoverPrinter();
163 reply.WriteInt32(ret);
164 PRINT_HILOGD("PrintServiceStub::OnStopDiscoverPrint out");
165 return ret == E_PRINT_NONE;
166 }
167
OnQueryAllExtension(MessageParcel & data,MessageParcel & reply)168 bool PrintServiceStub::OnQueryAllExtension(MessageParcel &data, MessageParcel &reply)
169 {
170 PRINT_HILOGD("PrintServiceStub::OnQueryAllExtension in");
171 std::vector<PrintExtensionInfo> printerInfo;
172 int32_t ret = QueryAllExtension(printerInfo);
173 reply.WriteInt32(ret);
174 if (ret == E_PRINT_NONE) {
175 uint32_t size = static_cast<uint32_t>(printerInfo.size());
176 reply.WriteUint32(size);
177 for (uint32_t index = 0; index < size; index++) {
178 printerInfo[index].Marshalling(reply);
179 }
180 }
181 PRINT_HILOGD("PrintServiceStub::OnQueryAllExtension out");
182 return ret == E_PRINT_NONE;
183 }
184
OnStartPrintJob(MessageParcel & data,MessageParcel & reply)185 bool PrintServiceStub::OnStartPrintJob(MessageParcel &data, MessageParcel &reply)
186 {
187 PRINT_HILOGD("PrintServiceStub::OnStartPrintJob in");
188 int32_t ret = E_PRINT_RPC_FAILURE;
189 auto jobInfoPtr = PrintJob::Unmarshalling(data);
190 if (jobInfoPtr != nullptr) {
191 jobInfoPtr->Dump();
192 ret = StartPrintJob(*jobInfoPtr);
193 }
194 reply.WriteInt32(ret);
195 PRINT_HILOGD("PrintServiceStub::OnStartPrintJob out");
196 return ret == E_PRINT_NONE;
197 }
198
OnCancelPrintJob(MessageParcel & data,MessageParcel & reply)199 bool PrintServiceStub::OnCancelPrintJob(MessageParcel &data, MessageParcel &reply)
200 {
201 PRINT_HILOGD("PrintServiceStub::OnCancelPrintJob in");
202 int32_t ret = CancelPrintJob(data.ReadString());
203 reply.WriteInt32(ret);
204 PRINT_HILOGD("PrintServiceStub::OnStartPrintJob out");
205 return ret == E_PRINT_NONE;
206 }
207
OnAddPrinters(MessageParcel & data,MessageParcel & reply)208 bool PrintServiceStub::OnAddPrinters(MessageParcel &data, MessageParcel &reply)
209 {
210 PRINT_HILOGD("PrintServiceStub::OnAddPrinters in");
211 std::vector<PrinterInfo> printerInfos;
212 uint32_t len = data.ReadUint32();
213 PRINT_HILOGD("OnStartDiscoverPrinter len = %{public}d", len);
214
215 CHECK_IS_EXCEED_PRINT_RANGE_BOOL(len);
216 for (uint32_t i = 0; i < len; i++) {
217 auto infoPtr = PrinterInfo::Unmarshalling(data);
218 if (infoPtr == nullptr) {
219 PRINT_HILOGW("invalid printer object");
220 continue;
221 }
222 infoPtr->Dump();
223 printerInfos.emplace_back(*infoPtr);
224 }
225 int32_t ret = E_PRINT_RPC_FAILURE;
226 if (printerInfos.size() > 0) {
227 ret = AddPrinters(printerInfos);
228 }
229 reply.WriteInt32(ret);
230 PRINT_HILOGD("PrintServiceStub::OnAddPrinters out");
231 return ret == E_PRINT_NONE;
232 }
233
OnRemovePrinters(MessageParcel & data,MessageParcel & reply)234 bool PrintServiceStub::OnRemovePrinters(MessageParcel &data, MessageParcel &reply)
235 {
236 PRINT_HILOGD("PrintServiceStub::OnRemovePrinters in");
237 std::vector<std::string> printerIds;
238 data.ReadStringVector(&printerIds);
239 PRINT_HILOGD("OnStartDiscoverPrinter len = %{public}zd", printerIds.size());
240
241 CHECK_IS_EXCEED_PRINT_RANGE_BOOL(printerIds.size());
242 int32_t ret = RemovePrinters(printerIds);
243 reply.WriteInt32(ret);
244
245 PRINT_HILOGD("PrintServiceStub::OnRemovePrinters out");
246 return ret == E_PRINT_NONE;
247 }
248
OnUpdatePrinters(MessageParcel & data,MessageParcel & reply)249 bool PrintServiceStub::OnUpdatePrinters(MessageParcel &data, MessageParcel &reply)
250 {
251 PRINT_HILOGD("PrintServiceStub::OnUpdatePrinters in");
252 std::vector<PrinterInfo> printerInfos;
253 uint32_t len = data.ReadUint32();
254 PRINT_HILOGD("OnStartDiscoverPrinter len = %{public}d", len);
255
256 CHECK_IS_EXCEED_PRINT_RANGE_BOOL(len);
257 for (uint32_t i = 0; i < len; i++) {
258 auto infoPtr = PrinterInfo::Unmarshalling(data);
259 if (infoPtr == nullptr) {
260 PRINT_HILOGW("invalid printer object");
261 continue;
262 }
263 infoPtr->Dump();
264 printerInfos.emplace_back(*infoPtr);
265 }
266 int32_t ret = E_PRINT_RPC_FAILURE;
267 if (printerInfos.size() > 0) {
268 ret = UpdatePrinters(printerInfos);
269 }
270 reply.WriteInt32(ret);
271 PRINT_HILOGD("PrintServiceStub::OnUpdatePrinters out");
272 return ret == E_PRINT_NONE;
273 }
274
OnUpdatePrinterState(MessageParcel & data,MessageParcel & reply)275 bool PrintServiceStub::OnUpdatePrinterState(MessageParcel &data, MessageParcel &reply)
276 {
277 PRINT_HILOGD("PrintServiceStub::OnUpdatePrinterState in");
278 std::string printerId = data.ReadString();
279 uint32_t state = data.ReadUint32();
280 int32_t ret = UpdatePrinterState(printerId, state);
281 reply.WriteInt32(ret);
282 PRINT_HILOGD("PrintServiceStub::OnUpdatePrinterState out");
283 return ret == E_PRINT_NONE;
284 }
285
OnUpdatePrintJobState(MessageParcel & data,MessageParcel & reply)286 bool PrintServiceStub::OnUpdatePrintJobState(MessageParcel &data, MessageParcel &reply)
287 {
288 PRINT_HILOGD("PrintServiceStub::OnUpdatePrintJobState in");
289 std::string jobId = data.ReadString();
290 uint32_t state = data.ReadUint32();
291 uint32_t subState = data.ReadUint32();
292 PRINT_HILOGD("OnUpdatePrintJobState jobId = %{public}s", jobId.c_str());
293 PRINT_HILOGD("OnUpdatePrintJobState state = %{public}d", state);
294 PRINT_HILOGD("OnUpdatePrintJobState subState = %{public}d", subState);
295
296 int32_t ret = UpdatePrintJobState(jobId, state, subState);
297 reply.WriteInt32(ret);
298 PRINT_HILOGD("PrintServiceStub::OnUpdatePrintJobState out");
299 return ret == E_PRINT_NONE;
300 }
301
OnUpdateExtensionInfo(MessageParcel & data,MessageParcel & reply)302 bool PrintServiceStub::OnUpdateExtensionInfo(MessageParcel &data, MessageParcel &reply)
303 {
304 PRINT_HILOGD("PrintServiceStub::OnUpdateExtensionInfo in");
305 std::string extInfo = data.ReadString();
306 PRINT_HILOGD("OnUpdateExtensionInfo extInfo = %{public}s", extInfo.c_str());
307
308 int32_t ret = UpdateExtensionInfo(extInfo);
309 reply.WriteInt32(ret);
310 PRINT_HILOGD("PrintServiceStub::OnUpdateExtensionInfo out");
311 return ret == E_PRINT_NONE;
312 }
313
OnRequestPreview(MessageParcel & data,MessageParcel & reply)314 bool PrintServiceStub::OnRequestPreview(MessageParcel &data, MessageParcel &reply)
315 {
316 PRINT_HILOGD("PrintServiceStub::OnRequestPreview in");
317 int32_t ret = E_PRINT_RPC_FAILURE;
318 std::string previewResult = "";
319 auto jobInfoPtr = PrintJob::Unmarshalling(data);
320 if (jobInfoPtr != nullptr) {
321 jobInfoPtr->Dump();
322 ret = RequestPreview(*jobInfoPtr, previewResult);
323 }
324 reply.WriteInt32(ret);
325 reply.WriteString(previewResult);
326 PRINT_HILOGD("PrintServiceStub::OnRequestPreview out");
327 return ret == E_PRINT_NONE;
328 }
329
OnQueryPrinterCapability(MessageParcel & data,MessageParcel & reply)330 bool PrintServiceStub::OnQueryPrinterCapability(MessageParcel &data, MessageParcel &reply)
331 {
332 PRINT_HILOGD("PrintServiceStub::OnQueryPrinterCapability in");
333 std::string printerId = data.ReadString();
334 PRINT_HILOGD("printerId : %{private}s", printerId.c_str());
335 int32_t ret = QueryPrinterCapability(printerId);
336 reply.WriteInt32(ret);
337 PRINT_HILOGD("PrintServiceStub::OnQueryPrinterCapability out");
338 return ret == E_PRINT_NONE;
339 }
340
OnQueryAllPrintJob(MessageParcel & data,MessageParcel & reply)341 bool PrintServiceStub::OnQueryAllPrintJob(MessageParcel &data, MessageParcel &reply)
342 {
343 PRINT_HILOGD("PrintServiceStub::OnQueryAllPrintJob in");
344 std::vector<PrintJob> printJob;
345 printJob.clear();
346 int32_t ret = QueryAllPrintJob(printJob);
347 reply.WriteInt32(ret);
348 if (ret == E_PRINT_NONE) {
349 uint32_t size = static_cast<uint32_t>(printJob.size());
350 reply.WriteUint32(size);
351 for (uint32_t index = 0; index < size; index++) {
352 printJob[index].Marshalling(reply);
353 }
354 }
355 PRINT_HILOGD("PrintServiceStub::OnQueryAllPrintJob out");
356 return ret == E_PRINT_NONE;
357 }
358
OnQueryPrintJobById(MessageParcel & data,MessageParcel & reply)359 bool PrintServiceStub::OnQueryPrintJobById(MessageParcel &data, MessageParcel &reply)
360 {
361 PRINT_HILOGD("PrintServiceStub::OnQueryPrintJobById in");
362 PrintJob printJob;
363 std::string printJobId = data.ReadString();
364 int32_t ret = QueryPrintJobById(printJobId, printJob);
365 reply.WriteInt32(ret);
366 printJob.Marshalling(reply);
367 PRINT_HILOGD("PrintServiceStub::OnQueryPrintJobById out");
368 return ret == E_PRINT_NONE;
369 }
370
OnAddPrinterToCups(MessageParcel & data,MessageParcel & reply)371 bool PrintServiceStub::OnAddPrinterToCups(MessageParcel &data, MessageParcel &reply)
372 {
373 PRINT_HILOGD("PrintServiceStub::OnAddPrinterToCups in");
374 std::string printerUri = data.ReadString();
375 std::string printerName = data.ReadString();
376 int32_t ret = AddPrinterToCups(printerUri, printerName);
377 reply.WriteInt32(ret);
378 PRINT_HILOGD("PrintServiceStub::OnAddPrinterToCups out");
379 return ret == E_PRINT_NONE;
380 }
381
OnQueryPrinterCapabilityByUri(MessageParcel & data,MessageParcel & reply)382 bool PrintServiceStub::OnQueryPrinterCapabilityByUri(MessageParcel &data, MessageParcel &reply)
383 {
384 PRINT_HILOGD("PrintServiceStub::OnQueryPrinterCapabilityByUri in");
385 PrinterCapability printerCaps;
386 std::string printerUri = data.ReadString();
387 int32_t ret = QueryPrinterCapabilityByUri(printerUri, printerCaps);
388 reply.WriteInt32(ret);
389 printerCaps.Marshalling(reply);
390 PRINT_HILOGD("PrintServiceStub::OnQueryPrinterCapabilityByUri out");
391 return ret == E_PRINT_NONE;
392 }
393
OnEventOn(MessageParcel & data,MessageParcel & reply)394 bool PrintServiceStub::OnEventOn(MessageParcel &data, MessageParcel &reply)
395 {
396 std::string taskId = data.ReadString();
397 std::string type = data.ReadString();
398 PRINT_HILOGD("PrintServiceStub::OnEventOn type=%{public}s ", type.c_str());
399 if (type.empty()) {
400 PRINT_HILOGE("PrintServiceStub::OnEventOn type is null.");
401 reply.WriteInt32(E_PRINT_RPC_FAILURE);
402 return false;
403 }
404 sptr<IRemoteObject> remote = data.ReadRemoteObject();
405 if (remote == nullptr) {
406 PRINT_HILOGE("PrintServiceStub::OnEventOn remote is nullptr");
407 reply.WriteInt32(E_PRINT_RPC_FAILURE);
408 return false;
409 }
410 sptr<IPrintCallback> listener = iface_cast<IPrintCallback>(remote);
411 if (listener.GetRefPtr() == nullptr) {
412 PRINT_HILOGE("PrintServiceStub::OnEventOn listener is null");
413 reply.WriteInt32(E_PRINT_RPC_FAILURE);
414 return false;
415 }
416 int32_t ret = On(taskId, type, listener);
417 reply.WriteInt32(ret);
418 PRINT_HILOGD("PrintServiceStub::OnEventOn out");
419 return ret == E_PRINT_NONE;
420 }
421
OnEventOff(MessageParcel & data,MessageParcel & reply)422 bool PrintServiceStub::OnEventOff(MessageParcel &data, MessageParcel &reply)
423 {
424 PRINT_HILOGD("PrintServiceStub::OnEventOff in");
425 std::string taskId = data.ReadString();
426 std::string type = data.ReadString();
427 PRINT_HILOGD("PrintServiceStub::OnEventOff type=%{public}s ", type.c_str());
428 int32_t ret = Off(taskId, type);
429 reply.WriteInt32(ret);
430 PRINT_HILOGD("PrintServiceStub::OnEventOff out");
431 return ret == E_PRINT_NONE;
432 }
433
OnRegisterExtCallback(MessageParcel & data,MessageParcel & reply)434 bool PrintServiceStub::OnRegisterExtCallback(MessageParcel &data, MessageParcel &reply)
435 {
436 PRINT_HILOGD("PrintServiceStub::OnRegisterExtCallback in");
437 std::string extensionCID = data.ReadString();
438 sptr<IRemoteObject> remote = data.ReadRemoteObject();
439 if (remote == nullptr) {
440 PRINT_HILOGD("PrintServiceStub::OnRegisterExtCallback remote is nullptr");
441 reply.WriteInt32(E_PRINT_RPC_FAILURE);
442 return false;
443 }
444 sptr<IPrintExtensionCallback> listener = iface_cast<IPrintExtensionCallback>(remote);
445 if (listener.GetRefPtr() == nullptr) {
446 PRINT_HILOGD("PrintServiceStub::OnRegisterExtCallback listener is null");
447 reply.WriteInt32(E_PRINT_RPC_FAILURE);
448 return false;
449 }
450
451 int32_t ret = RegisterExtCallback(extensionCID, listener);
452 reply.WriteInt32(ret);
453 PRINT_HILOGD("PrintServiceStub::OnRegisterExtCallback out");
454 return ret == E_PRINT_NONE;
455 }
456
OnUnregisterAllExtCallback(MessageParcel & data,MessageParcel & reply)457 bool PrintServiceStub::OnUnregisterAllExtCallback(MessageParcel &data, MessageParcel &reply)
458 {
459 PRINT_HILOGD("PrintServiceStub::OnUnregisterAllExtCallback in");
460 std::string extensionId = data.ReadString();
461 int32_t ret = UnregisterAllExtCallback(extensionId);
462 reply.WriteInt32(ret);
463 PRINT_HILOGD("PrintServiceStub::OnUnregisterAllExtCallback out");
464 return ret == E_PRINT_NONE;
465 }
466
OnLoadExtSuccess(MessageParcel & data,MessageParcel & reply)467 bool PrintServiceStub::OnLoadExtSuccess(MessageParcel &data, MessageParcel &reply)
468 {
469 PRINT_HILOGD("PrintServiceStub::OnLoadExtSuccess in");
470 std::string extensionId = data.ReadString();
471 int32_t ret = LoadExtSuccess(extensionId);
472 reply.WriteInt32(ret);
473 PRINT_HILOGD("PrintServiceStub::OnLoadExtSuccess out");
474 return ret == E_PRINT_NONE;
475 }
476 } // namespace OHOS::Print
477