Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9b6d3a15 authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

Fail only scheduled print jobs, i.e. handed to a service, if the service is disabled.

When a print service is disabled we assume all print jobs for it failed as we have
no way to know what happens to them. However we are also failing created print jobs,
i.e. ones not given to the service. Such jobs are in process of construction and
the print dialog is up. We should not fail such jobs as the dialog can still modify
their state and potentially select a print from a different service. Therefore, we
leave them alone and they will be failed if when constructed are passed to a
disabled/uninstalled service.

bug:11197432

Change-Id: Ie4fe54327e3e25776b1dd572be2dfafdd700c2e5
parent 5a783173
Loading
Loading
Loading
Loading
+8 −0
Original line number Original line Diff line number Diff line
@@ -47,6 +47,14 @@ public final class PrintJobInfo implements Parcelable {
     */
     */
    public static final int STATE_ANY_ACTIVE = -3;
    public static final int STATE_ANY_ACTIVE = -3;


    /**
     * Constant for matching any scheduled, i.e. delivered to a print
     * service, print job state.
     *
     * @hide
     */
    public static final int STATE_ANY_SCHEDULED = -4;

    /**
    /**
     * Print job state: The print job is being created but not yet
     * Print job state: The print job is being created but not yet
     * ready to be printed.
     * ready to be printed.
+9 −1
Original line number Original line Diff line number Diff line
@@ -268,7 +268,9 @@ public final class PrintSpoolerService extends Service {
                        || (state == PrintJobInfo.STATE_ANY_VISIBLE_TO_CLIENTS
                        || (state == PrintJobInfo.STATE_ANY_VISIBLE_TO_CLIENTS
                            && isStateVisibleToUser(printJob.getState()))
                            && isStateVisibleToUser(printJob.getState()))
                        || (state == PrintJobInfo.STATE_ANY_ACTIVE
                        || (state == PrintJobInfo.STATE_ANY_ACTIVE
                            && isActiveState(printJob.getState()));
                            && isActiveState(printJob.getState()))
                        || (state == PrintJobInfo.STATE_ANY_SCHEDULED
                            && isScheduledState(printJob.getState()));
                if (sameComponent && sameAppId && sameState) {
                if (sameComponent && sameAppId && sameState) {
                    if (foundPrintJobs == null) {
                    if (foundPrintJobs == null) {
                        foundPrintJobs = new ArrayList<PrintJobInfo>();
                        foundPrintJobs = new ArrayList<PrintJobInfo>();
@@ -554,6 +556,12 @@ public final class PrintSpoolerService extends Service {
                || printJobState == PrintJobInfo.STATE_QUEUED);
                || printJobState == PrintJobInfo.STATE_QUEUED);
    }
    }


    private boolean isScheduledState(int printJobState) {
        return printJobState == PrintJobInfo.STATE_QUEUED
                || printJobState == PrintJobInfo.STATE_STARTED
                || printJobState == PrintJobInfo.STATE_BLOCKED;
    }

    private boolean isActiveState(int printJobState) {
    private boolean isActiveState(int printJobState) {
        return printJobState == PrintJobInfo.STATE_CREATED
        return printJobState == PrintJobInfo.STATE_CREATED
                || printJobState == PrintJobInfo.STATE_QUEUED
                || printJobState == PrintJobInfo.STATE_QUEUED
+4 −4
Original line number Original line Diff line number Diff line
@@ -798,17 +798,17 @@ final class UserState implements PrintSpoolerCallbacks, PrintServiceCallbacks {
            BackgroundThread.getHandler().post(new Runnable() {
            BackgroundThread.getHandler().post(new Runnable() {
                @Override
                @Override
                public void run() {
                public void run() {
                    failActivePrintJobsForServiceInternal(serviceName);
                    failScheduledPrintJobsForServiceInternal(serviceName);
                }
                }
            });
            });
        } else {
        } else {
            failActivePrintJobsForServiceInternal(serviceName);
            failScheduledPrintJobsForServiceInternal(serviceName);
        }
        }
    }
    }


    private void failActivePrintJobsForServiceInternal(ComponentName serviceName) {
    private void failScheduledPrintJobsForServiceInternal(ComponentName serviceName) {
        List<PrintJobInfo> printJobs = mSpooler.getPrintJobInfos(serviceName,
        List<PrintJobInfo> printJobs = mSpooler.getPrintJobInfos(serviceName,
                PrintJobInfo.STATE_ANY_ACTIVE, PrintManager.APP_ID_ANY);
                PrintJobInfo.STATE_ANY_SCHEDULED, PrintManager.APP_ID_ANY);
        if (printJobs == null) {
        if (printJobs == null) {
            return;
            return;
        }
        }