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

Commit b450d0d4 authored by Svetoslav's avatar Svetoslav
Browse files

Small print API tweaks

1. Removed an unused public constant

2. Hide PrintFileDocumentAdapter which makes doing the wring
   thing easy.

3. We allow a print service to set a tag of a print job which is
   an arbitrary string it only knows how to interpret. Typically,
   this is the id of a remote print job. This tag was visible to
   applications which is wrong - this is data that should be
   private to the print service. Now the print service is the
   only one to see that.

bug:11084635

Change-Id: I763ea9ff0fdf647805bc36e1737d72263090714d
parent 5c126892
Loading
Loading
Loading
Loading
+1 −8
Original line number Diff line number Diff line
@@ -19367,12 +19367,6 @@ package android.print {
    method public android.print.PrintDocumentInfo.Builder setPageCount(int);
  }
  public class PrintFileDocumentAdapter extends android.print.PrintDocumentAdapter {
    ctor public PrintFileDocumentAdapter(android.content.Context, java.io.File, android.print.PrintDocumentInfo);
    method public void onLayout(android.print.PrintAttributes, android.print.PrintAttributes, android.os.CancellationSignal, android.print.PrintDocumentAdapter.LayoutResultCallback, android.os.Bundle);
    method public void onWrite(android.print.PageRange[], android.os.ParcelFileDescriptor, android.os.CancellationSignal, android.print.PrintDocumentAdapter.WriteResultCallback);
  }
  public final class PrintJob {
    method public void cancel();
    method public android.print.PrintJobId getId();
@@ -19402,10 +19396,8 @@ package android.print {
    method public android.print.PageRange[] getPages();
    method public android.print.PrinterId getPrinterId();
    method public int getState();
    method public java.lang.String getTag();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator CREATOR;
    field public static final int PRINT_JOB_ID_UNDEFINED = -1; // 0xffffffff
    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
@@ -19500,6 +19492,7 @@ package android.printservice {
    method public android.printservice.PrintDocument getDocument();
    method public android.print.PrintJobId getId();
    method public android.print.PrintJobInfo getInfo();
    method public java.lang.String getTag();
    method public boolean isBlocked();
    method public boolean isCancelled();
    method public boolean isCompleted();
+2 −0
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ import java.io.OutputStream;
 * spooling the data, so you can delete the file if it is a
 * temporary one. To achieve this one must override {@link #onFinish()}
 * and delete the file yourself.
 *
 * @hide
 */
public class PrintFileDocumentAdapter extends PrintDocumentAdapter {

+2 −3
Original line number Diff line number Diff line
@@ -26,9 +26,6 @@ import java.util.Arrays;
 */
public final class PrintJobInfo implements Parcelable {

    /** Undefined print job id. */
    public static final int PRINT_JOB_ID_UNDEFINED = -1;

    /**
     * Constant for matching any print job state.
     *
@@ -356,6 +353,8 @@ public final class PrintJobInfo implements Parcelable {
     * Gets the optional tag assigned by a print service.
     *
     * @return The tag.
     *
     * @hide
     */
    public String getTag() {
        return mTag;
+12 −0
Original line number Diff line number Diff line
@@ -301,6 +301,18 @@ public final class PrintJob {
        return false;
    }

    /**
     * Gets the print job tag.
     *
     * @return tag The tag or null.
     *
     * @see #setTag(String)
     */
    public String getTag() {
        PrintService.throwIfNotCalledOnMainThread();
        return getInfo().getTag();
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
+6 −0
Original line number Diff line number Diff line
@@ -205,6 +205,10 @@ final class UserState implements PrintSpoolerCallbacks, PrintServiceCallbacks {
        for (int i = 0; i < cachedPrintJobCount; i++) {
            PrintJobInfo cachedPrintJob = cachedPrintJobs.get(i);
            result.put(cachedPrintJob.getId(), cachedPrintJob);
            // Strip out the tag - it is visible only to print services.
            // Also the cached print jobs are delivered only to apps, so
            // stripping the tag of a cached print job is fine.
            cachedPrintJob.setTag(null);
        }

        // Add everything else the spooler knows about.
@@ -215,6 +219,8 @@ final class UserState implements PrintSpoolerCallbacks, PrintServiceCallbacks {
            for (int i = 0; i < printJobCount; i++) {
                PrintJobInfo printJob = printJobs.get(i);
                result.put(printJob.getId(), printJob);
                // Strip out the tag - it is visible only to print services.
                printJob.setTag(null);
            }
        }