| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.printservice; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.os.ParcelFileDescriptor; |
| 22 |
import android.os.RemoteException; |
| 23 |
import android.print.PrintDocumentInfo; |
| 24 |
import android.print.PrintJobId; |
| 25 |
import android.util.Log; |
| 26 |
|
| 27 |
import java.io.IOException; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public final class PrintDocument { |
| 38 |
|
| 39 |
private static final String LOG_TAG = "PrintDocument"; |
| 40 |
|
| 41 |
private final PrintJobId mPrintJobId; |
| 42 |
|
| 43 |
private final IPrintServiceClient mPrintServiceClient; |
| 44 |
|
| 45 |
private final PrintDocumentInfo mInfo; |
| 46 |
|
| 47 |
PrintDocument(PrintJobId printJobId, IPrintServiceClient printServiceClient, |
| 48 |
PrintDocumentInfo info) { |
| 49 |
mPrintJobId = printJobId; |
| 50 |
mPrintServiceClient = printServiceClient; |
| 51 |
mInfo = info; |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public @NonNull PrintDocumentInfo getInfo() { |
| 60 |
PrintService.throwIfNotCalledOnMainThread(); |
| 61 |
return mInfo; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public @Nullable ParcelFileDescriptor getData() { |
| 75 |
PrintService.throwIfNotCalledOnMainThread(); |
| 76 |
ParcelFileDescriptor source = null; |
| 77 |
ParcelFileDescriptor sink = null; |
| 78 |
try { |
| 79 |
ParcelFileDescriptor[] fds = ParcelFileDescriptor.createPipe(); |
| 80 |
source = fds[0]; |
| 81 |
sink = fds[1]; |
| 82 |
mPrintServiceClient.writePrintJobData(sink, mPrintJobId); |
| 83 |
return source; |
| 84 |
} catch (IOException ioe) { |
| 85 |
Log.e(LOG_TAG, "Error calling getting print job data!", ioe); |
| 86 |
} catch (RemoteException re) { |
| 87 |
Log.e(LOG_TAG, "Error calling getting print job data!", re); |
| 88 |
} finally { |
| 89 |
if (sink != null) { |
| 90 |
try { |
| 91 |
sink.close(); |
| 92 |
} catch (IOException ioe) { |
| 93 |
|
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
return null; |
| 98 |
} |
| 99 |
} |