From dcc84ad75b38aa65a3120c82cc27f77c3e8ebf71 Mon Sep 17 00:00:00 2001 From: zheng_zhi_hao Date: Sat, 19 Oct 2024 12:13:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=89=E6=96=B9=E6=8B=93?= =?UTF-8?q?=E5=B1=95=E6=89=93=E5=8D=B0=E6=9C=BA=E7=8A=B6=E6=80=81=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zheng_zhi_hao --- interfaces/kits/napi/print_napi/src/print_module.cpp | 2 ++ services/print_service/src/print_cups_client.cpp | 12 +++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/interfaces/kits/napi/print_napi/src/print_module.cpp b/interfaces/kits/napi/print_napi/src/print_module.cpp index 9353a31..cfbd70d 100644 --- a/interfaces/kits/napi/print_napi/src/print_module.cpp +++ b/interfaces/kits/napi/print_napi/src/print_module.cpp @@ -61,6 +61,7 @@ static constexpr const char *FUNCTION_ADD_PRINTER_TO_DISCOVERY = "addPrinterToDi static constexpr const char *FUNCTION_UPDATE_PRINTER_IN_DISCOVERY = "updatePrinterInDiscovery"; static constexpr const char *FUNCTION_REMOVE_PRINTER_FROM_DISCOVERY = "removePrinterFromDiscovery"; static constexpr const char *FUNCTION_GET_ADDED_PRINTER_INFO_BY_ID = "getAddedPrinterInfoById"; +static constexpr const char *FUNCTION_GET_PRINTER_INFORMATION_BY_ID = "getPrinterInformationById"; #define PRINT_NAPI_METHOD(name, func) \ { \ @@ -355,6 +356,7 @@ static napi_value Init(napi_env env, napi_value exports) PRINT_NAPI_METHOD(FUNCTION_UPDATE_PRINTER_IN_DISCOVERY, NapiPrintExt::UpdatePrinterInDiscovery), PRINT_NAPI_METHOD(FUNCTION_REMOVE_PRINTER_FROM_DISCOVERY, NapiPrintExt::RemovePrinterFromDiscovery), PRINT_NAPI_METHOD(FUNCTION_GET_ADDED_PRINTER_INFO_BY_ID, NapiInnerPrint::GetAddedPrinterInfoById), + PRINT_NAPI_METHOD(FUNCTION_GET_PRINTER_INFORMATION_BY_ID, NapiInnerPrint::GetAddedPrinterInfoById), }; napi_status status = napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), desc); diff --git a/services/print_service/src/print_cups_client.cpp b/services/print_service/src/print_cups_client.cpp index 62e697e..26959dc 100644 --- a/services/print_service/src/print_cups_client.cpp +++ b/services/print_service/src/print_cups_client.cpp @@ -122,6 +122,8 @@ static const std::string P2P_PRINTER = "p2p"; static const std::string USB_PRINTER = "usb"; static const std::string PRINTER_ID_USB_PREFIX = "USB"; static const std::string PRINTER_MAKE_UNKNOWN = "Unknown"; +static const std::string SPOOLER_BUNDLE_NAME = "com.ohos.spooler"; +static const std::string VENDOR_MANAGER_PREFIX = "fwk."; static const std::vector IGNORE_STATE_LIST = {PRINTER_STATE_WAITING_COMPLETE, PRINTER_STATE_NONE, PRINTER_STATE_EMPTY, @@ -510,7 +512,6 @@ int32_t PrintCupsClient::AddPrinterToCups(const std::string &printerUri, const s ippAddInteger(request, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state", IPP_PRINTER_IDLE); ippAddString(request, IPP_TAG_PRINTER, IPP_TAG_NAME, "ppd-name", NULL, ppd.c_str()); ippAddBoolean(request, IPP_TAG_PRINTER, "printer-is-accepting-jobs", 1); - ippAddBoolean(request, IPP_TAG_PRINTER, "printer-is-shared", 1); PRINT_HILOGD("IPP_OP_CUPS_ADD_MODIFY_PRINTER cupsDoRequest"); ippDelete(printAbility_->DoRequest(NULL, request, "/admin/")); if (cupsLastError() > IPP_STATUS_OK_EVENTS_COMPLETE) { @@ -1432,10 +1433,11 @@ bool PrintCupsClient::CheckPrinterOnline(JobMonitorParam *param, const uint32_t const char* printerUri = param->printerUri.c_str(); const std::string printerId = param->printerId; PRINT_HILOGD("CheckPrinterOnline printerId: %{public}s", printerId.c_str()); - - if (param->printerUri.length() > USB_PRINTER.length() && - param->printerUri.substr(INDEX_ZERO, INDEX_THREE) == USB_PRINTER && - param->serviceAbility != nullptr) { + bool isUsbPrinter = param->printerUri.length() > USB_PRINTER.length() && + param->printerUri.substr(INDEX_ZERO, INDEX_THREE) == USB_PRINTER; + bool isCustomizedExtension = !(PrintUtil::startsWith(printerId, SPOOLER_BUNDLE_NAME) || + PrintUtil::startsWith(printerId, VENDOR_MANAGER_PREFIX)); + if ((isUsbPrinter || isCustomizedExtension) && param->serviceAbility != nullptr) { if (param->serviceAbility->QueryDiscoveredPrinterInfoById(printerId) == nullptr) { PRINT_HILOGI("printer offline"); return false;