优化三方拓展打印机状态刷新问题

Signed-off-by: zheng_zhi_hao <zhengzhihao3@huawei.com>
This commit is contained in:
zheng_zhi_hao 2024-10-19 12:13:18 +08:00
parent e3079de4d8
commit dcc84ad75b
2 changed files with 9 additions and 5 deletions

View File

@ -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_UPDATE_PRINTER_IN_DISCOVERY = "updatePrinterInDiscovery";
static constexpr const char *FUNCTION_REMOVE_PRINTER_FROM_DISCOVERY = "removePrinterFromDiscovery"; 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_ADDED_PRINTER_INFO_BY_ID = "getAddedPrinterInfoById";
static constexpr const char *FUNCTION_GET_PRINTER_INFORMATION_BY_ID = "getPrinterInformationById";
#define PRINT_NAPI_METHOD(name, func) \ #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_UPDATE_PRINTER_IN_DISCOVERY, NapiPrintExt::UpdatePrinterInDiscovery),
PRINT_NAPI_METHOD(FUNCTION_REMOVE_PRINTER_FROM_DISCOVERY, NapiPrintExt::RemovePrinterFromDiscovery), 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_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); napi_status status = napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), desc);

View File

@ -122,6 +122,8 @@ static const std::string P2P_PRINTER = "p2p";
static const std::string USB_PRINTER = "usb"; static const std::string USB_PRINTER = "usb";
static const std::string PRINTER_ID_USB_PREFIX = "USB"; static const std::string PRINTER_ID_USB_PREFIX = "USB";
static const std::string PRINTER_MAKE_UNKNOWN = "Unknown"; 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<std::string> IGNORE_STATE_LIST = {PRINTER_STATE_WAITING_COMPLETE, static const std::vector<std::string> IGNORE_STATE_LIST = {PRINTER_STATE_WAITING_COMPLETE,
PRINTER_STATE_NONE, PRINTER_STATE_NONE,
PRINTER_STATE_EMPTY, 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); 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()); 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-accepting-jobs", 1);
ippAddBoolean(request, IPP_TAG_PRINTER, "printer-is-shared", 1);
PRINT_HILOGD("IPP_OP_CUPS_ADD_MODIFY_PRINTER cupsDoRequest"); PRINT_HILOGD("IPP_OP_CUPS_ADD_MODIFY_PRINTER cupsDoRequest");
ippDelete(printAbility_->DoRequest(NULL, request, "/admin/")); ippDelete(printAbility_->DoRequest(NULL, request, "/admin/"));
if (cupsLastError() > IPP_STATUS_OK_EVENTS_COMPLETE) { 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 char* printerUri = param->printerUri.c_str();
const std::string printerId = param->printerId; const std::string printerId = param->printerId;
PRINT_HILOGD("CheckPrinterOnline printerId: %{public}s", printerId.c_str()); PRINT_HILOGD("CheckPrinterOnline printerId: %{public}s", printerId.c_str());
bool isUsbPrinter = param->printerUri.length() > USB_PRINTER.length() &&
if (param->printerUri.length() > USB_PRINTER.length() && param->printerUri.substr(INDEX_ZERO, INDEX_THREE) == USB_PRINTER;
param->printerUri.substr(INDEX_ZERO, INDEX_THREE) == USB_PRINTER && bool isCustomizedExtension = !(PrintUtil::startsWith(printerId, SPOOLER_BUNDLE_NAME) ||
param->serviceAbility != nullptr) { PrintUtil::startsWith(printerId, VENDOR_MANAGER_PREFIX));
if ((isUsbPrinter || isCustomizedExtension) && param->serviceAbility != nullptr) {
if (param->serviceAbility->QueryDiscoveredPrinterInfoById(printerId) == nullptr) { if (param->serviceAbility->QueryDiscoveredPrinterInfoById(printerId) == nullptr) {
PRINT_HILOGI("printer offline"); PRINT_HILOGI("printer offline");
return false; return false;