Print spooler security and some new print service facing APIs.

1. Updated the security mode of the print spooler. Now the spooler
   is not signed with the system key, it is not a privileged app so if
   it gets compromised (PDF rendering is a potential attack vector)
   it cannot access dangerous permissions. Also only the system
   can bind to the spooler.

2. Added APIs for asking a print service to start and stop tracking
   a given printer. This is need for the case when the user selects
   the printer and the print service should do a best effort to keep
   the system updated for the current state of the printer.

3. Added APIs for putting a print job in a blocked state. A print
   service would report the print job as blocked if for some reason
   the printer cannot proceed, e.g. 99 pages are printed but there
   is no paper for the last one. The user has to add more paper
   and the print service can resume the job.

4. Changed the read/write APIs to use ParcelFileDescriptor instead
   of FileDescriptor since the latter does not have a clean API for
   detaching the wrapped Linux file descriptor when one wants to
   push it to native.

5. Added API for getting the size of the printed document so the
   print service can avoid handling big filed over cellular network
   or ask the user if needed.

6. Now the print services that are preinstalled on the system image
   are automatically enabled.

Change-Id: Ia06c311d3d21cabb9e1368f13928e11cd0030918
diff --git a/core/java/android/printservice/PrintDocument.java b/core/java/android/printservice/PrintDocument.java
index 7437dc5..8292cfbc 100644
--- a/core/java/android/printservice/PrintDocument.java
+++ b/core/java/android/printservice/PrintDocument.java
@@ -21,12 +21,15 @@
 import android.print.PrintDocumentInfo;
 import android.util.Log;
 
-import java.io.FileDescriptor;
 import java.io.IOException;
 
 /**
  * This class represents a printed document from the perspective of a print
  * service. It exposes APIs to query the document and obtain its data.
+ * <p>
+ * <strong>Note: </strong> All methods of this class must be executed on the
+ * main application thread.
+ * </p>
  */
 public final class PrintDocument {
 
@@ -51,6 +54,7 @@
      * @return The document info.
      */
     public PrintDocumentInfo getInfo() {
+        PrintService.throwIfNotCalledOnMainThread();
         return mInfo;
     }
 
@@ -64,7 +68,8 @@
      *
      * @return A file descriptor for reading the data.
      */
-    public FileDescriptor getData() {
+    public ParcelFileDescriptor getData() {
+        PrintService.throwIfNotCalledOnMainThread();
         ParcelFileDescriptor source = null;
         ParcelFileDescriptor sink = null;
         try {
@@ -72,7 +77,7 @@
             source = fds[0];
             sink = fds[1];
             mPrintServiceClient.writePrintJobData(sink, mPrintJobId);
-            return source.getFileDescriptor();
+            return source;
         } catch (IOException ioe) {
             Log.e(LOG_TAG, "Error calling getting print job data!", ioe);
         } catch (RemoteException re) {