• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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] =
44         &PrintServiceStub::OnUpdatePrintJobStateOnlyForSystemApp;
45     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_UPDATEEXTENSIONINFO] = &PrintServiceStub::OnUpdateExtensionInfo;
46     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_REQUESTPREVIEW] = &PrintServiceStub::OnRequestPreview;
47     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_QUERYPRINTERCAPABILITY] =
48         &PrintServiceStub::OnQueryPrinterCapability;
49     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_ON] = &PrintServiceStub::OnEventOn;
50     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_OFF] = &PrintServiceStub::OnEventOff;
51     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_REG_EXT_CB] = &PrintServiceStub::OnRegisterExtCallback;
52     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_UNREG_EXT_CB] = &PrintServiceStub::OnUnregisterAllExtCallback;
53     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_LOAD_EXT] = &PrintServiceStub::OnLoadExtSuccess;
54     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_QUERYALLPRINTJOB] = &PrintServiceStub::OnQueryAllPrintJob;
55     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_QUERYPRINTJOBBYID] = &PrintServiceStub::OnQueryPrintJobById;
56     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_ADDPRINTERTOCUPS] = &PrintServiceStub::OnAddPrinterToCups;
57     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_QUERYPRINTERCAPABILITYBYURI] =
58         &PrintServiceStub::OnQueryPrinterCapabilityByUri;
59     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_STARTPRINTJOB_BY_ADAPTER] = &PrintServiceStub::OnPrintByAdapter;
60     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_START_GET_FILE] = &PrintServiceStub::OnStartGetPrintFile;
61     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_NOTIFY_PRINT_SERVICE] = &PrintServiceStub::OnNotifyPrintService;
62     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_START_SERVICE] = &PrintServiceStub::OnStartService;
63     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_REG_PRINTER_CB] = &PrintServiceStub::OnRegisterPrinterCallback;
64     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_UNREG_PRINTER_CB] = &PrintServiceStub::OnUnregisterPrinterCallback;
65     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_QUERYPRINTERINFOBYPRINTERID] =
66         &PrintServiceStub::OnQueryPrinterInfoByPrinterId;
67     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_QUERYADDEDPRINTER] = &PrintServiceStub::OnQueryAddedPrinter;
68     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_QUERYPRINTERPROPERTIES] =
69         &PrintServiceStub::OnQueryPrinterProperties;
70     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_STARTNATIVEPRINTJOB] = &PrintServiceStub::OnStartNativePrintJob;
71     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_NOTIFY_PRINT_SERVICE_EVENT] =
72         &PrintServiceStub::OnNotifyPrintServiceEvent;
73     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_GET_PRINTER_PREFERENCE] =
74         &PrintServiceStub::OnGetPrinterPreference;
75     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_SET_PRINTER_PREFERENCE] =
76         &PrintServiceStub::OnSetPrinterPreference;
77     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_SET_DEFAULT_PRINTERID] = &PrintServiceStub::OnSetDefaultPrinter;
78     cmdMap_[OHOS::Print::IPrintInterfaceCode::CMD_DELETE_PRINTER_FROM_CUPS] =
79         &PrintServiceStub::OnDeletePrinterFromCups;
80 }
81 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)82 int32_t PrintServiceStub::OnRemoteRequest(
83     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
84 {
85     PRINT_HILOGD("OnRemoteRequest started, code = %{public}d", code);
86     auto descriptorToken = data.ReadInterfaceToken();
87     if (descriptorToken != GetDescriptor()) {
88         PRINT_HILOGE("Remote descriptor not the same as local descriptor.");
89         return E_PRINT_RPC_FAILURE;
90     }
91 
92     auto itFunc = cmdMap_.find(code);
93     if (itFunc != cmdMap_.end()) {
94         auto requestFunc = itFunc->second;
95         if (requestFunc != nullptr) {
96             return (this->*requestFunc)(data, reply);
97         }
98     }
99     PRINT_HILOGW("default case, need check.");
100     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
101 }
102 
OnStartService(MessageParcel & data,MessageParcel & reply)103 bool PrintServiceStub::OnStartService(MessageParcel &data, MessageParcel &reply)
104 {
105     PRINT_HILOGD("nativePrint PrintServiceStub::OnStartService in");
106     int32_t ret = E_PRINT_NONE;
107     if (data.ReadString() == "nativePrint") {
108         std::string result = "";
109         ret = StartService();
110         reply.WriteInt32(ret);
111         PRINT_HILOGI("nativePrint PrintServiceStub::OnStartService out:%{public}d", ret);
112     }
113     return ret == E_PRINT_NONE;
114 }
115 
OnStartPrint(MessageParcel & data,MessageParcel & reply)116 bool PrintServiceStub::OnStartPrint(MessageParcel &data, MessageParcel &reply)
117 {
118     PRINT_HILOGD("PrintServiceStub::OnStartPrint in");
119     std::vector<std::string> fileList;
120     std::vector<uint32_t> fdList;
121     std::string result = "";
122 
123     if (data.ReadBool()) {
124         data.ReadStringVector(&fileList);
125         PRINT_HILOGD("Current file is %{public}zd", fileList.size());
126         CHECK_IS_EXCEED_PRINT_RANGE_BOOL(fileList.size());
127         for (auto file : fileList) {
128             PRINT_HILOGD("file is %{private}s", file.c_str());
129         }
130     }
131 
132     if (data.ReadBool()) {
133         int32_t len = data.ReadInt32();
134         CHECK_IS_EXCEED_PRINT_RANGE_BOOL(len);
135         for (int32_t index = 0; index < len; index++) {
136             uint32_t fd = static_cast<uint32_t>(data.ReadFileDescriptor());
137             PRINT_HILOGD("fdList[%{public}d] = %{public}d", index, fd);
138             fdList.emplace_back(fd);
139         }
140     }
141     std::string taskId = data.ReadString();
142     int32_t ret = StartPrint(fileList, fdList, taskId);
143     reply.WriteInt32(ret);
144     PRINT_HILOGD("PrintServiceStub::OnStartPrint out");
145     return ret == E_PRINT_NONE;
146 }
147 
OnStopPrint(MessageParcel & data,MessageParcel & reply)148 bool PrintServiceStub::OnStopPrint(MessageParcel &data, MessageParcel &reply)
149 {
150     PRINT_HILOGD("PrintServiceStub::OnStopPrint in");
151     std::string taskId = data.ReadString();
152     int32_t ret = StopPrint(taskId);
153     reply.WriteInt32(ret);
154     PRINT_HILOGD("PrintServiceStub::OnStopPrint out");
155     return ret == E_PRINT_NONE;
156 }
157 
OnConnectPrinter(MessageParcel & data,MessageParcel & reply)158 bool PrintServiceStub::OnConnectPrinter(MessageParcel &data, MessageParcel &reply)
159 {
160     PRINT_HILOGD("PrintServiceStub::OnConnectPrinter in");
161     int32_t ret = ConnectPrinter(data.ReadString());
162     reply.WriteInt32(ret);
163     PRINT_HILOGD("PrintServiceStub::OnConnectPrinter out");
164     return ret == E_PRINT_NONE;
165 }
166 
OnDisconnectPrinter(MessageParcel & data,MessageParcel & reply)167 bool PrintServiceStub::OnDisconnectPrinter(MessageParcel &data, MessageParcel &reply)
168 {
169     PRINT_HILOGD("PrintServiceStub::OnDisconnectPrinter in");
170     int32_t ret = DisconnectPrinter(data.ReadString());
171     reply.WriteInt32(ret);
172     PRINT_HILOGD("PrintServiceStub::OnDisconnectPrinter out");
173     return ret == E_PRINT_NONE;
174 }
175 
OnStartDiscoverPrinter(MessageParcel & data,MessageParcel & reply)176 bool PrintServiceStub::OnStartDiscoverPrinter(MessageParcel &data, MessageParcel &reply)
177 {
178     PRINT_HILOGD("PrintServiceStub::OnStartDiscoverPrinter in");
179     std::vector<std::string> extensionList;
180     data.ReadStringVector(&extensionList);
181     int32_t ret = StartDiscoverPrinter(extensionList);
182     reply.WriteInt32(ret);
183     PRINT_HILOGD("PrintServiceStub::OnStartDiscoverPrinter out");
184     return ret == E_PRINT_NONE;
185 }
186 
OnStopDiscoverPrint(MessageParcel & data,MessageParcel & reply)187 bool PrintServiceStub::OnStopDiscoverPrint(MessageParcel &data, MessageParcel &reply)
188 {
189     PRINT_HILOGD("PrintServiceStub::OnStopDiscoverPrint in");
190     int32_t ret = StopDiscoverPrinter();
191     reply.WriteInt32(ret);
192     PRINT_HILOGD("PrintServiceStub::OnStopDiscoverPrint out");
193     return ret == E_PRINT_NONE;
194 }
195 
OnQueryAllExtension(MessageParcel & data,MessageParcel & reply)196 bool PrintServiceStub::OnQueryAllExtension(MessageParcel &data, MessageParcel &reply)
197 {
198     PRINT_HILOGD("PrintServiceStub::OnQueryAllExtension in");
199     std::vector<PrintExtensionInfo> printerInfo;
200     int32_t ret = QueryAllExtension(printerInfo);
201     reply.WriteInt32(ret);
202     if (ret == E_PRINT_NONE) {
203         uint32_t size = static_cast<uint32_t>(printerInfo.size());
204         reply.WriteUint32(size);
205         for (uint32_t index = 0; index < size; index++) {
206             printerInfo[index].Marshalling(reply);
207         }
208     }
209     PRINT_HILOGD("PrintServiceStub::OnQueryAllExtension out");
210     return ret == E_PRINT_NONE;
211 }
212 
OnStartPrintJob(MessageParcel & data,MessageParcel & reply)213 bool PrintServiceStub::OnStartPrintJob(MessageParcel &data, MessageParcel &reply)
214 {
215     PRINT_HILOGD("PrintServiceStub::OnStartPrintJob in");
216     int32_t ret = E_PRINT_RPC_FAILURE;
217     auto jobInfoPtr = PrintJob::Unmarshalling(data);
218     if (jobInfoPtr != nullptr) {
219         jobInfoPtr->Dump();
220         ret = StartPrintJob(*jobInfoPtr);
221     }
222     reply.WriteInt32(ret);
223     PRINT_HILOGD("PrintServiceStub::OnStartPrintJob out");
224     return ret == E_PRINT_NONE;
225 }
226 
OnCancelPrintJob(MessageParcel & data,MessageParcel & reply)227 bool PrintServiceStub::OnCancelPrintJob(MessageParcel &data, MessageParcel &reply)
228 {
229     PRINT_HILOGD("PrintServiceStub::OnCancelPrintJob in");
230     int32_t ret = CancelPrintJob(data.ReadString());
231     reply.WriteInt32(ret);
232     PRINT_HILOGD("PrintServiceStub::OnStartPrintJob out");
233     return ret == E_PRINT_NONE;
234 }
235 
OnAddPrinters(MessageParcel & data,MessageParcel & reply)236 bool PrintServiceStub::OnAddPrinters(MessageParcel &data, MessageParcel &reply)
237 {
238     PRINT_HILOGD("PrintServiceStub::OnAddPrinters in");
239     std::vector<PrinterInfo> printerInfos;
240     uint32_t len = 0;
241     if (!data.ReadUint32(len)) {
242         PRINT_HILOGE("read data len failed.");
243         return false;
244     }
245     PRINT_HILOGD("OnStartDiscoverPrinter len = %{public}d", len);
246 
247     CHECK_IS_EXCEED_PRINT_RANGE_BOOL(len);
248     for (uint32_t i = 0; i < len; i++) {
249         auto infoPtr = PrinterInfo::Unmarshalling(data);
250         if (infoPtr == nullptr) {
251             PRINT_HILOGW("invalid printer object");
252             continue;
253         }
254         infoPtr->Dump();
255         printerInfos.emplace_back(*infoPtr);
256     }
257     int32_t ret = E_PRINT_RPC_FAILURE;
258     if (printerInfos.size() > 0) {
259         ret = AddPrinters(printerInfos);
260     }
261     reply.WriteInt32(ret);
262     PRINT_HILOGD("PrintServiceStub::OnAddPrinters out");
263     return ret == E_PRINT_NONE;
264 }
265 
OnQueryPrinterInfoByPrinterId(MessageParcel & data,MessageParcel & reply)266 bool PrintServiceStub::OnQueryPrinterInfoByPrinterId(MessageParcel &data, MessageParcel &reply)
267 {
268     PRINT_HILOGD("PrintServiceStub::OnQueryPrinterInfoByPrinterId in");
269     std::string printerId = data.ReadString();
270     PrinterInfo info;
271     int32_t ret = QueryPrinterInfoByPrinterId(printerId, info);
272     reply.WriteInt32(ret);
273     PRINT_HILOGI("PrintServiceStub::OnQueryPrinterInfoByPrinterId out %{public}s", info.GetPrinterName().c_str());
274     info.Marshalling(reply);
275     PRINT_HILOGI("PrintServiceStub::OnQueryPrinterInfoByPrinterId out");
276     return ret == E_PRINT_NONE;
277 }
278 
OnGetPrinterPreference(MessageParcel & data,MessageParcel & reply)279 bool PrintServiceStub::OnGetPrinterPreference(MessageParcel &data, MessageParcel &reply)
280 {
281     PRINT_HILOGD("PrintServiceStub::OnGetPrinterPreference in");
282     std::string printerId = data.ReadString();
283     std::string printPreference;
284     int32_t ret = GetPrinterPreference(printerId, printPreference);
285     reply.WriteInt32(ret);
286     reply.WriteString(printPreference);
287     return ret == E_PRINT_NONE;
288 }
289 
OnSetPrinterPreference(MessageParcel & data,MessageParcel & reply)290 bool PrintServiceStub::OnSetPrinterPreference(MessageParcel &data, MessageParcel &reply)
291 {
292     PRINT_HILOGI("PrintServiceStub::OnSetPrinterPreference in");
293     std::string printerId = data.ReadString();
294     std::string printPreference = data.ReadString();
295     int32_t ret = SetPrinterPreference(printerId, printPreference);
296     reply.WriteInt32(ret);
297     return ret == E_PRINT_NONE;
298 }
299 
OnQueryAddedPrinter(MessageParcel & data,MessageParcel & reply)300 bool PrintServiceStub::OnQueryAddedPrinter(MessageParcel &data, MessageParcel &reply)
301 {
302     PRINT_HILOGI("PrintServiceStub::OnQueryAddedPrinter in");
303     std::vector<std::string> printerNameList;
304 
305     int32_t ret = QueryAddedPrinter(printerNameList);
306     reply.WriteInt32(ret);
307     reply.WriteStringVector(printerNameList);
308 
309     PRINT_HILOGI("PrintServiceStub::OnQueryAddedPrinter out");
310     return ret == E_PRINT_NONE;
311 }
312 
OnQueryPrinterProperties(MessageParcel & data,MessageParcel & reply)313 bool PrintServiceStub::OnQueryPrinterProperties(MessageParcel &data, MessageParcel &reply)
314 {
315     PRINT_HILOGI("PrintServiceStub::OnQueryAddedPrinter in");
316     std::string printerId = data.ReadString();
317     std::vector<std::string> keyList;
318     data.ReadStringVector(&keyList);
319     std::vector<std::string> valueList;
320     int32_t ret = QueryPrinterProperties(printerId, keyList, valueList);
321     reply.WriteInt32(ret);
322     reply.WriteStringVector(valueList);
323     PRINT_HILOGI("PrintServiceStub::OnQueryAddedPrinter out");
324     return ret == E_PRINT_NONE;
325 }
326 
OnStartNativePrintJob(MessageParcel & data,MessageParcel & reply)327 bool PrintServiceStub::OnStartNativePrintJob(MessageParcel &data, MessageParcel &reply)
328 {
329     PRINT_HILOGI("PrintServiceStub::OnStartNativePrintJob in");
330     int32_t ret = E_PRINT_RPC_FAILURE;
331     auto printJobPtr = PrintJob::Unmarshalling(data);
332     if (printJobPtr != nullptr) {
333         printJobPtr->Dump();
334         ret = StartNativePrintJob(*printJobPtr);
335     }
336     reply.WriteInt32(ret);
337     PRINT_HILOGD("PrintServiceStub::OnStartPrintJob out");
338     return ret == E_PRINT_NONE;
339 }
340 
OnRemovePrinters(MessageParcel & data,MessageParcel & reply)341 bool PrintServiceStub::OnRemovePrinters(MessageParcel &data, MessageParcel &reply)
342 {
343     PRINT_HILOGD("PrintServiceStub::OnRemovePrinters in");
344     std::vector<std::string> printerIds;
345     data.ReadStringVector(&printerIds);
346     PRINT_HILOGD("OnStartDiscoverPrinter len = %{public}zd", printerIds.size());
347 
348     CHECK_IS_EXCEED_PRINT_RANGE_BOOL(printerIds.size());
349     int32_t ret = RemovePrinters(printerIds);
350     reply.WriteInt32(ret);
351 
352     PRINT_HILOGD("PrintServiceStub::OnRemovePrinters out");
353     return ret == E_PRINT_NONE;
354 }
355 
OnUpdatePrinters(MessageParcel & data,MessageParcel & reply)356 bool PrintServiceStub::OnUpdatePrinters(MessageParcel &data, MessageParcel &reply)
357 {
358     PRINT_HILOGD("PrintServiceStub::OnUpdatePrinters in");
359     std::vector<PrinterInfo> printerInfos;
360     uint32_t len = 0;
361     if (!data.ReadUint32(len)) {
362         PRINT_HILOGE("read data len failed.");
363         return false;
364     }
365     PRINT_HILOGD("OnUpdatePrinters len = %{public}d", len);
366 
367     CHECK_IS_EXCEED_PRINT_RANGE_BOOL(len);
368     for (uint32_t i = 0; i < len; i++) {
369         auto infoPtr = PrinterInfo::Unmarshalling(data);
370         if (infoPtr == nullptr) {
371             PRINT_HILOGW("invalid printer object");
372             continue;
373         }
374         infoPtr->Dump();
375         printerInfos.emplace_back(*infoPtr);
376     }
377     int32_t ret = E_PRINT_RPC_FAILURE;
378     if (printerInfos.size() > 0) {
379         ret = UpdatePrinters(printerInfos);
380     }
381     reply.WriteInt32(ret);
382     PRINT_HILOGD("PrintServiceStub::OnUpdatePrinters out");
383     return ret == E_PRINT_NONE;
384 }
385 
OnUpdatePrinterState(MessageParcel & data,MessageParcel & reply)386 bool PrintServiceStub::OnUpdatePrinterState(MessageParcel &data, MessageParcel &reply)
387 {
388     PRINT_HILOGD("PrintServiceStub::OnUpdatePrinterState in");
389     std::string printerId = data.ReadString();
390     uint32_t state = data.ReadUint32();
391     int32_t ret = UpdatePrinterState(printerId, state);
392     reply.WriteInt32(ret);
393     PRINT_HILOGD("PrintServiceStub::OnUpdatePrinterState out");
394     return ret == E_PRINT_NONE;
395 }
396 
OnUpdatePrintJobStateOnlyForSystemApp(MessageParcel & data,MessageParcel & reply)397 bool PrintServiceStub::OnUpdatePrintJobStateOnlyForSystemApp(MessageParcel &data, MessageParcel &reply)
398 {
399     PRINT_HILOGD("PrintServiceStub::OnUpdatePrintJobStateOnlyForSystemApp in");
400     std::string jobId = data.ReadString();
401     uint32_t state = data.ReadUint32();
402     uint32_t subState = data.ReadUint32();
403     PRINT_HILOGD("OnUpdatePrintJobStateOnlyForSystemApp jobId = %{public}s", jobId.c_str());
404     PRINT_HILOGD("OnUpdatePrintJobStateOnlyForSystemApp state = %{public}d", state);
405     PRINT_HILOGD("OnUpdatePrintJobStateOnlyForSystemApp subState = %{public}d", subState);
406 
407     int32_t ret = UpdatePrintJobStateOnlyForSystemApp(jobId, state, subState);
408     reply.WriteInt32(ret);
409     PRINT_HILOGD("PrintServiceStub::OnUpdatePrintJobStateOnlyForSystemApp out");
410     return ret == E_PRINT_NONE;
411 }
412 
OnUpdateExtensionInfo(MessageParcel & data,MessageParcel & reply)413 bool PrintServiceStub::OnUpdateExtensionInfo(MessageParcel &data, MessageParcel &reply)
414 {
415     PRINT_HILOGD("PrintServiceStub::OnUpdateExtensionInfo in");
416     std::string extInfo = data.ReadString();
417     PRINT_HILOGD("OnUpdateExtensionInfo extInfo = %{public}s", extInfo.c_str());
418 
419     int32_t ret = UpdateExtensionInfo(extInfo);
420     reply.WriteInt32(ret);
421     PRINT_HILOGD("PrintServiceStub::OnUpdateExtensionInfo out");
422     return ret == E_PRINT_NONE;
423 }
424 
OnRequestPreview(MessageParcel & data,MessageParcel & reply)425 bool PrintServiceStub::OnRequestPreview(MessageParcel &data, MessageParcel &reply)
426 {
427     PRINT_HILOGD("PrintServiceStub::OnRequestPreview in");
428     int32_t ret = E_PRINT_RPC_FAILURE;
429     std::string previewResult = "";
430     auto jobInfoPtr = PrintJob::Unmarshalling(data);
431     if (jobInfoPtr != nullptr) {
432         jobInfoPtr->Dump();
433         ret = RequestPreview(*jobInfoPtr, previewResult);
434     }
435     reply.WriteInt32(ret);
436     reply.WriteString(previewResult);
437     PRINT_HILOGD("PrintServiceStub::OnRequestPreview out");
438     return ret == E_PRINT_NONE;
439 }
440 
OnQueryPrinterCapability(MessageParcel & data,MessageParcel & reply)441 bool PrintServiceStub::OnQueryPrinterCapability(MessageParcel &data, MessageParcel &reply)
442 {
443     PRINT_HILOGD("PrintServiceStub::OnQueryPrinterCapability in");
444     std::string printerId = data.ReadString();
445     PRINT_HILOGD("printerId : %{private}s", printerId.c_str());
446     int32_t ret = QueryPrinterCapability(printerId);
447     reply.WriteInt32(ret);
448     PRINT_HILOGD("PrintServiceStub::OnQueryPrinterCapability out");
449     return ret == E_PRINT_NONE;
450 }
451 
OnQueryAllPrintJob(MessageParcel & data,MessageParcel & reply)452 bool PrintServiceStub::OnQueryAllPrintJob(MessageParcel &data, MessageParcel &reply)
453 {
454     PRINT_HILOGD("PrintServiceStub::OnQueryAllPrintJob in");
455     std::vector<PrintJob> printJob;
456     printJob.clear();
457     int32_t ret = QueryAllPrintJob(printJob);
458     reply.WriteInt32(ret);
459     if (ret == E_PRINT_NONE) {
460         uint32_t size = static_cast<uint32_t>(printJob.size());
461         reply.WriteUint32(size);
462         for (uint32_t index = 0; index < size; index++) {
463             printJob[index].Marshalling(reply);
464         }
465     }
466     PRINT_HILOGD("PrintServiceStub::OnQueryAllPrintJob out");
467     return ret == E_PRINT_NONE;
468 }
469 
OnQueryPrintJobById(MessageParcel & data,MessageParcel & reply)470 bool PrintServiceStub::OnQueryPrintJobById(MessageParcel &data, MessageParcel &reply)
471 {
472     PRINT_HILOGD("PrintServiceStub::OnQueryPrintJobById in");
473     PrintJob printJob;
474     std::string printJobId = data.ReadString();
475     int32_t ret = QueryPrintJobById(printJobId, printJob);
476     reply.WriteInt32(ret);
477     printJob.Marshalling(reply);
478     PRINT_HILOGD("PrintServiceStub::OnQueryPrintJobById out");
479     return ret == E_PRINT_NONE;
480 }
481 
OnAddPrinterToCups(MessageParcel & data,MessageParcel & reply)482 bool PrintServiceStub::OnAddPrinterToCups(MessageParcel &data, MessageParcel &reply)
483 {
484     PRINT_HILOGD("PrintServiceStub::OnAddPrinterToCups in");
485     std::string printerUri = data.ReadString();
486     std::string printerName = data.ReadString();
487     std::string printerMake = data.ReadString();
488     int32_t ret = AddPrinterToCups(printerUri, printerName, printerMake);
489     reply.WriteInt32(ret);
490     PRINT_HILOGD("PrintServiceStub::OnAddPrinterToCups out");
491     return ret == E_PRINT_NONE;
492 }
493 
OnQueryPrinterCapabilityByUri(MessageParcel & data,MessageParcel & reply)494 bool PrintServiceStub::OnQueryPrinterCapabilityByUri(MessageParcel &data, MessageParcel &reply)
495 {
496     PRINT_HILOGD("PrintServiceStub::OnQueryPrinterCapabilityByUri in");
497     PrinterCapability printerCaps;
498     std::string printerUri = data.ReadString();
499     std::string printerId = data.ReadString();
500     int32_t ret = QueryPrinterCapabilityByUri(printerUri, printerId, printerCaps);
501     reply.WriteInt32(ret);
502     printerCaps.Marshalling(reply);
503     PRINT_HILOGD("PrintServiceStub::OnQueryPrinterCapabilityByUri out");
504     return ret == E_PRINT_NONE;
505 }
506 
OnNotifyPrintServiceEvent(MessageParcel & data,MessageParcel & reply)507 bool PrintServiceStub::OnNotifyPrintServiceEvent(MessageParcel &data, MessageParcel &reply)
508 {
509     PRINT_HILOGD("PrintServiceStub::OnNotifyPrintServiceEvent in");
510     std::string jobId = data.ReadString();
511     uint32_t event = data.ReadUint32();
512     PRINT_HILOGD("OnNotifyPrintServiceEvent jobId = %{public}s, event = %{public}d", jobId.c_str(), event);
513     int32_t ret = NotifyPrintServiceEvent(jobId, event);
514     reply.WriteInt32(ret);
515     PRINT_HILOGD("PrintServiceStub::OnNotifyPrintServiceEvent out");
516     return ret == E_PRINT_NONE;
517 }
518 
OnSetDefaultPrinter(MessageParcel & data,MessageParcel & reply)519 bool PrintServiceStub::OnSetDefaultPrinter(MessageParcel &data, MessageParcel &reply)
520 {
521     PRINT_HILOGD("PrintServiceStub::OnSetDefaultPrinter in");
522     std::string printerId = data.ReadString();
523     uint32_t type = data.ReadUint32();
524     int32_t ret = SetDefaultPrinter(printerId, type);
525     reply.WriteInt32(ret);
526     PRINT_HILOGD("PrintServiceStub::OnSetDefaultPrinter out");
527     return ret == E_PRINT_NONE;
528 }
529 
OnDeletePrinterFromCups(MessageParcel & data,MessageParcel & reply)530 bool PrintServiceStub::OnDeletePrinterFromCups(MessageParcel &data, MessageParcel &reply)
531 {
532     PRINT_HILOGD("PrintServiceStub::OnDeletePrinterFromCups in");
533     std::string printerUri = data.ReadString();
534     std::string printerName = data.ReadString();
535     std::string printerMake = data.ReadString();
536     int32_t ret = DeletePrinterFromCups(printerUri, printerName, printerMake);
537     reply.WriteInt32(ret);
538     PRINT_HILOGD("PrintServiceStub::OnDeletePrinterFromCups out");
539     return ret == E_PRINT_NONE;
540 }
541 
OnEventOn(MessageParcel & data,MessageParcel & reply)542 bool PrintServiceStub::OnEventOn(MessageParcel &data, MessageParcel &reply)
543 {
544     std::string taskId = data.ReadString();
545     std::string type = data.ReadString();
546     PRINT_HILOGD("PrintServiceStub::OnEventOn type=%{public}s ", type.c_str());
547     if (type.empty()) {
548         PRINT_HILOGE("PrintServiceStub::OnEventOn type is null.");
549         reply.WriteInt32(E_PRINT_RPC_FAILURE);
550         return false;
551     }
552     sptr<IRemoteObject> remote = data.ReadRemoteObject();
553     if (remote == nullptr) {
554         PRINT_HILOGE("PrintServiceStub::OnEventOn remote is nullptr");
555         reply.WriteInt32(E_PRINT_RPC_FAILURE);
556         return false;
557     }
558     sptr<IPrintCallback> listener = iface_cast<IPrintCallback>(remote);
559     if (listener.GetRefPtr() == nullptr) {
560         PRINT_HILOGE("PrintServiceStub::OnEventOn listener is null");
561         reply.WriteInt32(E_PRINT_RPC_FAILURE);
562         return false;
563     }
564     int32_t ret = On(taskId, type, listener);
565     reply.WriteInt32(ret);
566     PRINT_HILOGD("PrintServiceStub::OnEventOn out");
567     return ret == E_PRINT_NONE;
568 }
569 
OnEventOff(MessageParcel & data,MessageParcel & reply)570 bool PrintServiceStub::OnEventOff(MessageParcel &data, MessageParcel &reply)
571 {
572     PRINT_HILOGD("PrintServiceStub::OnEventOff in");
573     std::string taskId = data.ReadString();
574     std::string type = data.ReadString();
575     PRINT_HILOGD("PrintServiceStub::OnEventOff type=%{public}s ", type.c_str());
576     int32_t ret = Off(taskId, type);
577     reply.WriteInt32(ret);
578     PRINT_HILOGD("PrintServiceStub::OnEventOff out");
579     return ret == E_PRINT_NONE;
580 }
581 
OnRegisterPrinterCallback(MessageParcel & data,MessageParcel & reply)582 bool PrintServiceStub::OnRegisterPrinterCallback(MessageParcel &data, MessageParcel &reply)
583 {
584     std::string type = data.ReadString();
585     if (type.empty()) {
586         PRINT_HILOGE("PrintServiceStub::OnEventOn type is null.");
587         reply.WriteInt32(E_PRINT_RPC_FAILURE);
588         return false;
589     }
590     PRINT_HILOGD("PrintServiceStub::OnRegisterPrinterCallback type=%{public}s ", type.c_str());
591     sptr<IRemoteObject> remote = data.ReadRemoteObject();
592     if (remote == nullptr) {
593         PRINT_HILOGE("PrintServiceStub::OnEventOn remote is nullptr");
594         reply.WriteInt32(E_PRINT_RPC_FAILURE);
595         return false;
596     }
597     sptr<IPrintCallback> listener = iface_cast<IPrintCallback>(remote);
598     if (listener.GetRefPtr() == nullptr) {
599         PRINT_HILOGE("PrintServiceStub::OnEventOn listener is null");
600         reply.WriteInt32(E_PRINT_RPC_FAILURE);
601         return false;
602     }
603     int32_t ret = RegisterPrinterCallback(type, listener);
604     reply.WriteInt32(ret);
605     PRINT_HILOGD("PrintServiceStub::OnRegisterPrinterCallback out");
606     return ret == E_PRINT_NONE;
607 }
608 
OnUnregisterPrinterCallback(MessageParcel & data,MessageParcel & reply)609 bool PrintServiceStub::OnUnregisterPrinterCallback(MessageParcel &data, MessageParcel &reply)
610 {
611     std::string type = data.ReadString();
612     if (type.empty()) {
613         reply.WriteInt32(E_PRINT_RPC_FAILURE);
614         return false;
615     }
616     PRINT_HILOGD("PrintServiceStub::OnUnregisterPrinterCallback type=%{public}s ", type.c_str());
617     int32_t ret = UnregisterPrinterCallback(type);
618     reply.WriteInt32(ret);
619     PRINT_HILOGD("PrintServiceStub::OnUnregisterPrinterCallback out");
620     return ret == E_PRINT_NONE;
621 }
622 
OnRegisterExtCallback(MessageParcel & data,MessageParcel & reply)623 bool PrintServiceStub::OnRegisterExtCallback(MessageParcel &data, MessageParcel &reply)
624 {
625     PRINT_HILOGD("PrintServiceStub::OnRegisterExtCallback in");
626     std::string extensionCID = data.ReadString();
627     sptr<IRemoteObject> remote = data.ReadRemoteObject();
628     if (remote == nullptr) {
629         PRINT_HILOGD("PrintServiceStub::OnRegisterExtCallback remote is nullptr");
630         reply.WriteInt32(E_PRINT_RPC_FAILURE);
631         return false;
632     }
633     sptr<IPrintExtensionCallback> listener = iface_cast<IPrintExtensionCallback>(remote);
634     if (listener.GetRefPtr() == nullptr) {
635         PRINT_HILOGD("PrintServiceStub::OnRegisterExtCallback listener is null");
636         reply.WriteInt32(E_PRINT_RPC_FAILURE);
637         return false;
638     }
639 
640     int32_t ret = RegisterExtCallback(extensionCID, listener);
641     reply.WriteInt32(ret);
642     PRINT_HILOGD("PrintServiceStub::OnRegisterExtCallback out");
643     return ret == E_PRINT_NONE;
644 }
645 
OnUnregisterAllExtCallback(MessageParcel & data,MessageParcel & reply)646 bool PrintServiceStub::OnUnregisterAllExtCallback(MessageParcel &data, MessageParcel &reply)
647 {
648     PRINT_HILOGD("PrintServiceStub::OnUnregisterAllExtCallback in");
649     std::string extensionId = data.ReadString();
650     int32_t ret = UnregisterAllExtCallback(extensionId);
651     reply.WriteInt32(ret);
652     PRINT_HILOGD("PrintServiceStub::OnUnregisterAllExtCallback out");
653     return ret == E_PRINT_NONE;
654 }
655 
OnLoadExtSuccess(MessageParcel & data,MessageParcel & reply)656 bool PrintServiceStub::OnLoadExtSuccess(MessageParcel &data, MessageParcel &reply)
657 {
658     PRINT_HILOGD("PrintServiceStub::OnLoadExtSuccess in");
659     std::string extensionId = data.ReadString();
660     int32_t ret = LoadExtSuccess(extensionId);
661     reply.WriteInt32(ret);
662     PRINT_HILOGD("PrintServiceStub::OnLoadExtSuccess out");
663     return ret == E_PRINT_NONE;
664 }
665 
OnPrintByAdapter(MessageParcel & data,MessageParcel & reply)666 bool PrintServiceStub::OnPrintByAdapter(MessageParcel &data, MessageParcel &reply)
667 {
668     PRINT_HILOGI("PrintServiceStub::OnPrintByAdapter in");
669     int32_t ret = E_PRINT_RPC_FAILURE;
670     std::string jobName = data.ReadString();
671     auto attrs = PrintAttributes::Unmarshalling(data);
672     std::string taskId = data.ReadString();
673     if (attrs != nullptr) {
674         attrs->Dump();
675         ret = PrintByAdapter(jobName, *attrs, taskId);
676     }
677     reply.WriteInt32(ret);
678     PRINT_HILOGI("PrintServiceStub::OnPrintByAdapter out");
679     return ret == E_PRINT_NONE;
680 }
681 
OnStartGetPrintFile(MessageParcel & data,MessageParcel & reply)682 bool PrintServiceStub::OnStartGetPrintFile(MessageParcel &data, MessageParcel &reply)
683 {
684     PRINT_HILOGI("PrintServiceStub::OnStartGetPrintFile in");
685     int32_t ret = E_PRINT_RPC_FAILURE;
686     std::string jobId = data.ReadString();
687     auto attrs = PrintAttributes::Unmarshalling(data);
688     uint32_t fd = static_cast<uint32_t>(data.ReadFileDescriptor());
689     if (attrs != nullptr) {
690         ret = StartGetPrintFile(jobId, *attrs, fd);
691     }
692     reply.WriteInt32(ret);
693     PRINT_HILOGI("PrintServiceStub::OnStartGetPrintFile out");
694     return ret == E_PRINT_NONE;
695 }
696 
OnNotifyPrintService(MessageParcel & data,MessageParcel & reply)697 bool PrintServiceStub::OnNotifyPrintService(MessageParcel &data, MessageParcel &reply)
698 {
699     PRINT_HILOGD("PrintServiceStub::OnNotifyPrintService in");
700     std::string jobId = data.ReadString();
701     std::string type = data.ReadString();
702     PRINT_HILOGD(
703         "PrintServiceStub::OnNotifyPrintService jobId=%{public}s type=%{public}s ", jobId.c_str(), type.c_str());
704     int32_t ret = NotifyPrintService(jobId, type);
705     reply.WriteInt32(ret);
706     PRINT_HILOGD("PrintServiceStub::OnNotifyPrintService out");
707     return ret == E_PRINT_NONE;
708 }
709 } // namespace OHOS::Print
710