Refinement of the print service APIs.

1. Factored out the printer discovery APIs of a print service in a
   dedicated session object that is created by the print service on
   demand. This ensures that added/removed/updated printers from
   one session do not interfere with another session.

2. Updated the app facing APIs to pass in a document info along
   with a printed file. Also exposed the print file adapter so
   apps that create a temporary file for printing can intercept
   when it is read by the system so the file can be deleted.

3. Updated the print service documentation.

Change-Id: I3473d586c26d8bda1cf7e2bdacb441aa9df982ed
diff --git a/core/java/android/printservice/PrintJob.java b/core/java/android/printservice/PrintJob.java
index 64c079e..5f9a730 100644
--- a/core/java/android/printservice/PrintJob.java
+++ b/core/java/android/printservice/PrintJob.java
@@ -21,9 +21,9 @@
 import android.util.Log;
 
 /**
- * This class represents a print job from the perspective of a
- * print service. It provides APIs for observing the print job
- * state and performing operations on the print job.
+ * This class represents a print job from the perspective of a print
+ * service. It provides APIs for observing the print job state and
+ * performing operations on the print job.
  */
 public final class PrintJob {
 
@@ -38,7 +38,8 @@
     PrintJob(PrintJobInfo jobInfo, IPrintServiceClient client) {
         mCachedInfo = jobInfo;
         mPrintServiceClient = client;
-        mDocument = new PrintDocument(mCachedInfo.getId(), client, jobInfo.getDocumentInfo());
+        mDocument = new PrintDocument(mCachedInfo.getId(), client,
+                jobInfo.getDocumentInfo());
     }
 
     /**
@@ -77,7 +78,7 @@
     }
 
     /**
-     * Gets the document of this print job.
+     * Gets the printed document.
      *
      * @return The document.
      */
@@ -87,11 +88,12 @@
 
     /**
      * Gets whether this print job is queued. Such a print job is
-     * ready to be printed and can be started.
+     * ready to be printed and can be started or cancelled.
      *
      * @return Whether the print job is queued.
      *
      * @see #start()
+     * @see #cancel()
      */
     public boolean isQueued() {
         return getInfo().getState() == PrintJobInfo.STATE_QUEUED;
@@ -112,6 +114,42 @@
     }
 
     /**
+     * Gets whether this print job is completed. Such a print job
+     * is successfully printed. This is a final state.
+     *
+     * @return Whether the print job is completed.
+     *
+     * @see #complete()
+     */
+    public boolean isCompleted() {
+        return getInfo().getState() == PrintJobInfo.STATE_COMPLETED;
+    }
+
+    /**
+     * Gets whether this print job is failed. Such a print job is
+     * not successfully printed due to an error. This is a final state.
+     *
+     * @return Whether the print job is failed.
+     *
+     * @see #fail(CharSequence)
+     */
+    public boolean isFailed() {
+        return getInfo().getState() == PrintJobInfo.STATE_FAILED;
+    }
+
+    /**
+     * Gets whether this print job is cancelled. Such a print job was
+     * cancelled as a result of a user request. This is a final state.
+     *
+     * @return Whether the print job is cancelled.
+     *
+     * @see #cancel()
+     */
+    public boolean isCancelled() {
+        return getInfo().getState() == PrintJobInfo.STATE_FAILED;
+    }
+
+    /**
      * Starts the print job. You should call this method if {@link
      * #isQueued()} returns true and you started printing.
      *
@@ -163,12 +201,13 @@
     /**
      * Cancels the print job. You should call this method if {@link
      * #isQueued()} or {@link #isStarted()} returns true and you canceled
-     * the print job as a response to a call to {@link PrintService
-     * #onRequestCancelPrintJob(PrintJob)}.
+     * the print job as a response to a call to {@link
+     * PrintService#onRequestCancelPrintJob(PrintJob)}.
      *
-     * @return Whether the job as canceled.
+     * @return Whether the job is canceled.
      *
      * @see #isStarted()
+     * @see #isQueued()
      */
     public boolean cancel() {
         if (isQueued() || isStarted()) {