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

Commit 2fbd2a7f authored by Svetoslav's avatar Svetoslav
Browse files

App UI freezes when printing. API clean up.

1. The UI of a printing app was freezing a little when calling the print
   method since the print manager service was waiting for it to bind to the
   print spooler which generated the print job id (and the initial print
   job info really). Now the print manager service is responsible for job
   id generation and does not not wait for the print spooler to spin. Hence,
   the app UI is not blocked at all. Note that the print manager initiates
   the binding to the spooler and as soon as it completes the spooler shows
   the print UI which is hosted in its process. It is not possible to show
   the print UI before the system is bound to the spooler since during this
   binding the system passes a callback to the spooler so the latter can
   talk to the system.

2. Changed the print job id to be an opaque class allowing us to vary the
   way we generate print job ids in the future.

3. The queued print job state was hidden but the print job returned by the
   print method of the print manager is in that state. Now now hidden.

4. We were incorrecly removing print job infos if they are completed or
   cancelled. Doing that is problematic since the print job returned by
   the print method allows the app to query for the job info after the
   job has been say completed. Hence, an app can initiate printing and
   get a print job whose state is "created" and hold onto it until after
   the job is completed, now if the app asks for the print job info it
   will get an info in "created" state even though the job is "completed"
   since the spooler was not retaining the completed jobs. Now the spooler
   removes the PDF files for the completed and cancelled print jobs but
   keeps around the infos (also persisting them to disc) so it can answer
   questions about them. On first boot or switch to a user we purge the
   persisted print jobs in completed/cancelled state since they
   are obsolete - no app can have a handle to them.

5. Removed the print method that takes a file since we have a public
   PrintDocumentAdapter implementation for printing files. Once can
   instantiate a PrintFileDocumentAdapter and pass it to the print
   method. This class also allows overriding of the finish method to
   know when the data is spooled and deleted the file if desired, etc.

6. Replaced the wrong code to slice a large list of parcelables to
   use ParceledListSlice class.

bug:10748093

Change-Id: I1ebeeb47576e88fce550851cdd3e401fcede6e2b
parent 3fb53d82
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -19174,15 +19174,21 @@ package android.print {
  public final class PrintJob {
    method public void cancel();
    method public int getId();
    method public android.print.PrintJobId getId();
    method public android.print.PrintJobInfo getInfo();
  }
  public final class PrintJobId implements android.os.Parcelable {
    method public int describeContents();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
  }
  public final class PrintJobInfo implements android.os.Parcelable {
    method public int describeContents();
    method public android.print.PrintAttributes getAttributes();
    method public int getCopies();
    method public int getId();
    method public android.print.PrintJobId getId();
    method public java.lang.String getLabel();
    method public android.print.PageRange[] getPages();
    method public android.print.PrinterId getPrinterId();
@@ -19194,6 +19200,7 @@ package android.print {
    field public static final int STATE_BLOCKED = 4; // 0x4
    field public static final int STATE_CANCELED = 7; // 0x7
    field public static final int STATE_COMPLETED = 5; // 0x5
    field public static final int STATE_CREATED = 1; // 0x1
    field public static final int STATE_FAILED = 6; // 0x6
    field public static final int STATE_QUEUED = 2; // 0x2
    field public static final int STATE_STARTED = 3; // 0x3
@@ -19201,7 +19208,6 @@ package android.print {
  public final class PrintManager {
    method public java.util.List<android.print.PrintJob> getPrintJobs();
    method public android.print.PrintJob print(java.lang.String, java.io.File, android.print.PrintDocumentInfo, android.print.PrintAttributes);
    method public android.print.PrintJob print(java.lang.String, android.print.PrintDocumentAdapter, android.print.PrintAttributes);
  }
@@ -19312,7 +19318,7 @@ package android.printservice {
    method public boolean complete();
    method public boolean fail(java.lang.String);
    method public android.printservice.PrintDocument getDocument();
    method public int getId();
    method public android.print.PrintJobId getId();
    method public android.print.PrintJobInfo getInfo();
    method public boolean isBlocked();
    method public boolean isCancelled();
+4 −3
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.print;
import android.print.IPrinterDiscoveryObserver;
import android.print.IPrintDocumentAdapter;
import android.print.IPrintClient;
import android.print.PrintJobId;
import android.print.PrinterId;
import android.print.PrintJobInfo;
import android.print.PrintAttributes;
@@ -31,12 +32,12 @@ import android.printservice.PrintServiceInfo;
 */
interface IPrintManager {
    List<PrintJobInfo> getPrintJobInfos(int appId, int userId);
    PrintJobInfo getPrintJobInfo(int printJobId, int appId, int userId);
    PrintJobInfo getPrintJobInfo(in PrintJobId printJobId, int appId, int userId);
    PrintJobInfo print(String printJobName, in IPrintClient client,
            in IPrintDocumentAdapter printAdapter, in PrintAttributes attributes,
            int appId, int userId);
    void cancelPrintJob(int printJobId, int appId, int userId);
    void restartPrintJob(int printJobId, int appId, int userId);
    void cancelPrintJob(in PrintJobId printJobId, int appId, int userId);
    void restartPrintJob(in PrintJobId printJobId, int appId, int userId);

    List<PrintServiceInfo> getEnabledPrintServices(int userId);

+10 −7
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ import android.print.IPrintSpoolerClient;
import android.print.IPrintSpoolerCallbacks;
import android.print.PrinterInfo;
import android.print.PrintAttributes;
import android.print.PrintJobId;
import android.print.PrintJobInfo;

/**
 * Interface for communication with the print spooler service.
@@ -33,17 +35,18 @@ import android.print.PrintAttributes;
 * @hide
 */
oneway interface IPrintSpooler {
    void removeObsoletePrintJobs();
    void forgetPrintJobs(in List<PrintJobId> printJob);
    void getPrintJobInfos(IPrintSpoolerCallbacks callback, in ComponentName componentName,
            int state, int appId, int sequence);
    void getPrintJobInfo(int printJobId, IPrintSpoolerCallbacks callback,
    void getPrintJobInfo(in PrintJobId printJobId, IPrintSpoolerCallbacks callback,
            int appId, int sequence);
    void createPrintJob(String printJobName, in IPrintClient client,
            in IPrintDocumentAdapter printAdapter, in PrintAttributes attributes,
            IPrintSpoolerCallbacks callback, int appId, int sequence);
    void setPrintJobState(int printJobId, int status, String error,
    void createPrintJob(in PrintJobInfo printJob, in IPrintClient client,
            in IPrintDocumentAdapter printAdapter);
    void setPrintJobState(in PrintJobId printJobId, int status, String stateReason,
            IPrintSpoolerCallbacks callback, int sequence);
    void setPrintJobTag(int printJobId, String tag, IPrintSpoolerCallbacks callback,
    void setPrintJobTag(in PrintJobId printJobId, String tag, IPrintSpoolerCallbacks callback,
            int sequence);
    void writePrintJobData(in ParcelFileDescriptor fd, int printJobId);
    void writePrintJobData(in ParcelFileDescriptor fd, in PrintJobId printJobId);
    void setClient(IPrintSpoolerClient client);
}
+0 −1
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import java.util.List;
 */
oneway interface IPrintSpoolerCallbacks {
    void onGetPrintJobInfosResult(in List<PrintJobInfo> printJob, int sequence);
    void onCreatePrintJobResult(in PrintJobInfo printJob, int sequence);
    void onCancelPrintJobResult(boolean canceled, int sequence);
    void onSetPrintJobStateResult(boolean success, int sequence);
    void onSetPrintJobTagResult(boolean success, int sequence);
+3 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.print;

import android.print.PrinterId;
import android.print.PrinterInfo;
import android.content.pm.ParceledListSlice;

/**
 * Interface for observing discovered printers by a discovery session.
@@ -25,6 +26,6 @@ import android.print.PrinterInfo;
 * @hide
 */
oneway interface IPrinterDiscoveryObserver {
    void onPrintersAdded(in List<PrinterInfo> printers);
    void onPrintersRemoved(in List<PrinterId> printerIds);
    void onPrintersAdded(in ParceledListSlice printers);
    void onPrintersRemoved(in ParceledListSlice printerIds);
}
Loading