OSDN Git Service

Small print API tweaks
authorSvetoslav <svetoslavganov@google.com>
Fri, 4 Oct 2013 23:20:00 +0000 (16:20 -0700)
committerSvetoslav <svetoslavganov@google.com>
Fri, 4 Oct 2013 23:21:12 +0000 (16:21 -0700)
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

api/current.txt
core/java/android/print/PrintFileDocumentAdapter.java
core/java/android/print/PrintJobInfo.java
core/java/android/printservice/PrintJob.java
services/java/com/android/server/print/UserState.java

index ed0d154..0c9c9d1 100644 (file)
@@ -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();
index c3a23a5..5d655bf 100644 (file)
@@ -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 {
 
index e5d06a2..ccb4f44 100644 (file)
@@ -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;
index 721e31e..d1dbedf 100644 (file)
@@ -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) {
index 3b0ee24..b3f0036 100644 (file)
@@ -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);
             }
         }