diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2019-11-11 21:18:32 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2019-11-11 21:18:32 +0000 |
commit | c07d55ffdae901907becfd42e63fe3e4219e3def (patch) | |
tree | 0bf19a11bda6667376eb288a25320cfa10664e73 | |
parent | d522149b9b76f0d72945edf36fefe5b491c1320d (diff) | |
parent | 3963120ed75b10f434c1a775f6b47ca1c5946ea3 (diff) | |
download | BuiltInPrintService-android10-mainline-resolv-release.tar.gz |
Snap for 6001391 from 3963120ed75b10f434c1a775f6b47ca1c5946ea3 to qt-aml-resolv-releaseandroid-mainline-10.0.0_r8android10-mainline-resolv-release
Change-Id: I4a87dee4a813bebaf18258130310fe610ccd13cb
-rw-r--r-- | jni/lib/lib_wprint.c | 124 |
1 files changed, 54 insertions, 70 deletions
diff --git a/jni/lib/lib_wprint.c b/jni/lib/lib_wprint.c index 508c47f..a30d74c 100644 --- a/jni/lib/lib_wprint.c +++ b/jni/lib/lib_wprint.c @@ -827,9 +827,9 @@ static void *_job_thread(void *param) { // wait for the printer to be idle if ((jq->status_ifc != NULL) && (jq->status_ifc->get_status != NULL)) { int retry = 0; - int loop = 1; + bool idle = false; printer_state_dyn_t printer_state; - do { + while (!idle) { print_status_t status; jq->status_ifc->get_status(jq->status_ifc, &printer_state); status = printer_state.printer_status & ~PRINTER_IDLE_BIT; @@ -838,79 +838,63 @@ static void *_job_thread(void *param) { cb_param.certificate = jq->certificate; cb_param.certificate_len = jq->certificate_len; - switch (status) { - case PRINT_STATUS_IDLE: - printer_state.printer_status = PRINT_STATUS_IDLE; - jq->blocked_reasons = 0; - loop = 0; - break; - case PRINT_STATUS_UNKNOWN: - if (printer_state.printer_reasons[0] == PRINT_STATUS_UNKNOWN) { - LOGE("PRINTER STATUS UNKNOWN - Ln 747 libwprint.c"); - // no status available, break out and hope for the best - printer_state.printer_status = PRINT_STATUS_IDLE; - loop = 0; - break; - } - case PRINT_STATUS_SVC_REQUEST: - if ((printer_state.printer_reasons[0] == PRINT_STATUS_UNABLE_TO_CONNECT) - || (printer_state.printer_reasons[0] == PRINT_STATUS_OFFLINE)) { - if (_is_certificate_allowed(jq)) { - LOGD("_job_thread: Received an Unable to Connect message"); - jq->blocked_reasons = BLOCKED_REASON_UNABLE_TO_CONNECT; - } else { - LOGD("_job_thread: Bad certificate"); - jq->blocked_reasons = BLOCKED_REASON_BAD_CERTIFICATE; - } - loop = 0; + // Presume we found an idle state + idle = true; + if (status == PRINT_STATUS_IDLE) { + printer_state.printer_status = PRINT_STATUS_IDLE; + jq->blocked_reasons = 0; + } else if (status == PRINT_STATUS_UNKNOWN + && printer_state.printer_reasons[0] == PRINT_STATUS_UNKNOWN) { + // no status available, break out and hope for the best + printer_state.printer_status = PRINT_STATUS_IDLE; + } else if (status == PRINT_STATUS_SVC_REQUEST + && ((printer_state.printer_reasons[0] == PRINT_STATUS_UNABLE_TO_CONNECT) + || (printer_state.printer_reasons[0] == PRINT_STATUS_OFFLINE))) { + if (_is_certificate_allowed(jq)) { + LOGD("%s: Received an Unable to Connect message", __func__); + jq->blocked_reasons = BLOCKED_REASON_UNABLE_TO_CONNECT; + } else { + LOGD("%s: Bad certificate", __func__); + jq->blocked_reasons = BLOCKED_REASON_BAD_CERTIFICATE; + } + } else if (printer_state.printer_status & PRINTER_IDLE_BIT) { + LOGD("%s: printer blocked but appears to be in an idle state. " + "Allowing job to proceed", __func__); + printer_state.printer_status = PRINT_STATUS_IDLE; + } else if (retry >= MAX_IDLE_WAIT) { + jq->blocked_reasons |= BLOCKED_REASONS_PRINTER_BUSY; + } else if (!jq->job_params.cancelled) { + // Printer still appears busy, so stay in loop, notify, and poll again. + idle = false; + int blocked_reasons = 0; + for (i = 0; i <= PRINT_STATUS_MAX_STATE; i++) { + if (printer_state.printer_reasons[i] == PRINT_STATUS_MAX_STATE) { break; } - default: - if (printer_state.printer_status & PRINTER_IDLE_BIT) { - LOGD("printer blocked but appears to be in an idle state. " - "Allowing job to proceed"); - printer_state.printer_status = PRINT_STATUS_IDLE; - loop = 0; - break; - } else if (retry >= MAX_IDLE_WAIT) { - jq->blocked_reasons |= BLOCKED_REASONS_PRINTER_BUSY; - loop = 0; - } else if (!jq->job_params.cancelled) { - int blocked_reasons = 0; - for (i = 0; i <= PRINT_STATUS_MAX_STATE; i++) { - if (printer_state.printer_reasons[i] == - PRINT_STATUS_MAX_STATE) { - break; - } - blocked_reasons |= (1 << printer_state.printer_reasons[i]); - } - if (blocked_reasons == 0) { - blocked_reasons |= BLOCKED_REASONS_PRINTER_BUSY; - } + blocked_reasons |= (1 << printer_state.printer_reasons[i]); + } + if (blocked_reasons == 0) { + blocked_reasons |= BLOCKED_REASONS_PRINTER_BUSY; + } - if ((jq->job_state != JOB_STATE_BLOCKED) || - (jq->blocked_reasons != blocked_reasons)) { - jq->job_state = JOB_STATE_BLOCKED; - jq->blocked_reasons = blocked_reasons; - if (jq->cb_fn) { - cb_param.state = JOB_BLOCKED; - cb_param.blocked_reasons = blocked_reasons; - cb_param.job_done_result = OK; - - jq->cb_fn(jq->job_handle, (void *) &cb_param); - } - } - _unlock(); - sleep(1); - _lock(); - retry++; + if ((jq->job_state != JOB_STATE_BLOCKED) + || (jq->blocked_reasons != blocked_reasons)) { + jq->job_state = JOB_STATE_BLOCKED; + jq->blocked_reasons = blocked_reasons; + if (jq->cb_fn) { + cb_param.state = JOB_BLOCKED; + cb_param.blocked_reasons = blocked_reasons; + cb_param.job_done_result = OK; + + jq->cb_fn(jq->job_handle, (void *) &cb_param); } - break; - } - if (jq->job_params.cancelled) { - loop = 0; + } + _unlock(); + sleep(1); + _lock(); + retry++; } - } while (loop); + } if (jq->job_params.cancelled) { job_result = CANCELLED; |