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

Commit 85b1f883 authored by Svetoslav Ganov's avatar Svetoslav Ganov
Browse files

Iteration on the print sub-system.

1.  API changes: Moved copies API from PrintAttributes to PrintJobInfo;
    Changed the PageRange list to an array in PrintDocumentAdapter#onWrite;
    Added onCancelled method to the layout and write callbacks.

2.  Refactored the serialization of remote layout and write commands. Now
    the commands are serialized by the code in the client instead in the spooler.
    The benefit is simple code since the client has to do a serialization to delegate
    to the main thread anyway. The increased IPC found is fine since these calls
    are quite unfrequent.

3.  Removed an unused file: IPrintSpoolerObserver.aidl

4.  Added equals and hasCode implementation to PageRange, PrintAttributes,
    MediaSize, Resolution, Margins, Tray, PrintDocumentInfo.

5.  Added shortcut path for query APIs on PrintJob that return cached values
    if the print job is in a uncuttable state, i.e. completed or cancelled. Failed
    print jobs can be restarted.

6.  PrintJobInfo was not properly serialized.

7.  Updated the look of the print dialog to be stable if there is and there isn't
    currently selected printer.

8.  PrintJobCOnfigActivity now calls onLayout on every print attributes change
    but requests a write only on print preview or print button press. Also if the
    layout did not change the content and it is already written no subsequent
    call is made. Also if the selected pages change and we already have them
    no subsequent call to write is made. Also the app is called with print preview
    attribute set when performing layout and with it cleared after the print button
    is pressed. A lot of changes making sure that only valid actions are enabled
    in the activity (looks like a dialog) at a given time frame. The print job config
    activity is also hidden after we got all the data, i.e. layout and write are done.

9.  The callback from the print spooler to the system are scheduled via messages
    to avoid lock being held during the call. It was hard to guarantee that since a
    method holding a lock may be calling one that would like to release the lock
    at some point to make the callbacks.

10. Print spooler state is persisted only if something changes in a completed
    print job, i.e. not one that is being constructed due the print job config dialog.

11. Fixed a potential race in the RemotePrintSpooler where it was possible that
    a client that got a handle to the remote spooler calls into an unbound spooler.
    E.g: the client gets the remote interface with a lock held, now the client releases
    the lock to avoid IPC with a lock, during the IPC scheduling the spooler has
    notified the system that it is done and the system unbinds from it, now the
    client's IPC is made to a spooler that is disconnected.

Change-Id: Ie9c42255940a27ecaed21a4d326a663a4788ac9d
parent 0d1daa50
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -18462,7 +18462,6 @@ package android.print {
    method public void clear();
    method public int describeContents();
    method public int getColorMode();
    method public int getCopies();
    method public int getDuplexMode();
    method public int getFittingMode();
    method public android.print.PrintAttributes.Tray getInputTray();
@@ -18488,7 +18487,6 @@ package android.print {
    ctor public PrintAttributes.Builder();
    method public android.print.PrintAttributes create();
    method public android.print.PrintAttributes.Builder setColorMode(int);
    method public android.print.PrintAttributes.Builder setCopyCount(int);
    method public android.print.PrintAttributes.Builder setDuplexMode(int);
    method public android.print.PrintAttributes.Builder setFittingMode(int);
    method public android.print.PrintAttributes.Builder setInputTray(android.print.PrintAttributes.Tray);
@@ -18574,18 +18572,20 @@ package android.print {
    method public void onFinish();
    method public abstract void onLayout(android.print.PrintAttributes, android.print.PrintAttributes, android.os.CancellationSignal, android.print.PrintDocumentAdapter.LayoutResultCallback, android.os.Bundle);
    method public void onStart();
    method public abstract void onWrite(java.util.List<android.print.PageRange>, java.io.FileDescriptor, android.os.CancellationSignal, android.print.PrintDocumentAdapter.WriteResultCallback);
    method public abstract void onWrite(android.print.PageRange[], java.io.FileDescriptor, android.os.CancellationSignal, android.print.PrintDocumentAdapter.WriteResultCallback);
    field public static final java.lang.String METADATA_KEY_PRINT_PREVIEW = "KEY_METADATA_PRINT_PREVIEW";
  }
  public static abstract class PrintDocumentAdapter.LayoutResultCallback {
    method public void onLayoutCancelled();
    method public void onLayoutFailed(java.lang.CharSequence);
    method public void onLayoutFinished(android.print.PrintDocumentInfo, boolean);
  }
  public static abstract class PrintDocumentAdapter.WriteResultCallback {
    method public void onWriteCancelled();
    method public void onWriteFailed(java.lang.CharSequence);
    method public void onWriteFinished(java.util.List<android.print.PageRange>);
    method public void onWriteFinished(android.print.PageRange[]);
  }
  public final class PrintDocumentInfo implements android.os.Parcelable {
@@ -18616,6 +18616,7 @@ package android.print {
  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 java.lang.CharSequence getLabel();
    method public android.print.PageRange[] getPages();
+2 −6
Original line number Diff line number Diff line
@@ -34,8 +34,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * Adapter for printing files.
@@ -69,7 +67,7 @@ final class FileDocumentAdapter extends PrintDocumentAdapter {
    }

    @Override
    public void onWrite(List<PageRange> pages, FileDescriptor destination,
    public void onWrite(PageRange[] pages, FileDescriptor destination,
            CancellationSignal cancellationSignal, WriteResultCallback callback) {
        mWriteFileAsyncTask = new WriteFileAsyncTask(destination, cancellationSignal, callback);
        mWriteFileAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,
@@ -127,9 +125,7 @@ final class FileDocumentAdapter extends PrintDocumentAdapter {

        @Override
        protected void onPostExecute(Void result) {
            List<PageRange> pages = new ArrayList<PageRange>();
            pages.add(PageRange.ALL_PAGES);
            mResultCallback.onWriteFinished(pages);
            mResultCallback.onWriteFinished(new PageRange[] {PageRange.ALL_PAGES});
        }

        @Override
+2 −4
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package android.print;

import android.os.ICancellationSignal;
import android.print.PrintDocumentInfo;

/**
@@ -25,7 +24,6 @@ import android.print.PrintDocumentInfo;
 * @hide
 */
oneway interface ILayoutResultCallback {
    void onLayoutStarted(ICancellationSignal cancellationSignal);
    void onLayoutFinished(in PrintDocumentInfo info, boolean changed);
    void onLayoutFailed(CharSequence error);
    void onLayoutFinished(in PrintDocumentInfo info, boolean changed, int sequence);
    void onLayoutFailed(CharSequence error, int sequence);
}
+3 −3
Original line number Diff line number Diff line
@@ -31,8 +31,8 @@ import android.print.PrintAttributes;
oneway interface IPrintDocumentAdapter {
    void start();
    void layout(in PrintAttributes oldAttributes, in PrintAttributes newAttributes,
            ILayoutResultCallback callback, in Bundle metadata);
    void write(in List<PageRange> pages, in ParcelFileDescriptor fd,
            IWriteResultCallback callback);
            ILayoutResultCallback callback, in Bundle metadata, int sequence);
    void write(in PageRange[] pages, in ParcelFileDescriptor fd,
            IWriteResultCallback callback, int sequence);
    void finish();
}
+0 −1
Original line number Diff line number Diff line
@@ -33,5 +33,4 @@ interface IPrintManager {
            in IPrintDocumentAdapter printAdapter, in PrintAttributes attributes,
            int appId, int userId);
    void cancelPrintJob(int printJobId, int appId, int userId);

}
Loading