diff --git a/core/java/android/print/PageRange.java b/core/java/android/print/PageRange.java
index 8bc157a9fcada..57c7718c33706 100644
--- a/core/java/android/print/PageRange.java
+++ b/core/java/android/print/PageRange.java
@@ -16,6 +16,8 @@
package android.print;
+import android.annotation.IntRange;
+import android.annotation.NonNull;
import android.os.Parcel;
import android.os.Parcelable;
@@ -42,7 +44,7 @@ public final class PageRange implements Parcelable {
* @throws IllegalArgumentException If start is less than zero or end
* is less than zero or start greater than end.
*/
- public PageRange(int start, int end) {
+ public PageRange(@IntRange(from = 0) int start, @IntRange(from = 0) int end) {
if (start < 0) {
throw new IllegalArgumentException("start cannot be less than zero.");
}
@@ -56,7 +58,7 @@ public final class PageRange implements Parcelable {
mEnd = end;
}
- private PageRange (Parcel parcel) {
+ private PageRange(@NonNull Parcel parcel) {
this(parcel.readInt(), parcel.readInt());
}
@@ -65,7 +67,7 @@ public final class PageRange implements Parcelable {
*
* @return The start page index.
*/
- public int getStart() {
+ public @IntRange(from = 0) int getStart() {
return mStart;
}
@@ -74,7 +76,7 @@ public final class PageRange implements Parcelable {
*
* @return The end page index.
*/
- public int getEnd() {
+ public @IntRange(from = 0) int getEnd() {
return mEnd;
}
diff --git a/core/java/android/print/PrintAttributes.java b/core/java/android/print/PrintAttributes.java
index 2afbb99b3a267..8892e3430fe48 100644
--- a/core/java/android/print/PrintAttributes.java
+++ b/core/java/android/print/PrintAttributes.java
@@ -16,6 +16,10 @@
package android.print;
+import android.annotation.IntDef;
+import android.annotation.IntRange;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources.NotFoundException;
@@ -27,6 +31,8 @@ import android.util.Log;
import com.android.internal.R;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
import java.util.Map;
/**
@@ -37,6 +43,13 @@ import java.util.Map;
* 10 mills (thousand of an inch) on all sides, and be black and white.
*/
public final class PrintAttributes implements Parcelable {
+ /** @hide */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef(flag = true, value = {
+ COLOR_MODE_MONOCHROME, COLOR_MODE_COLOR
+ })
+ public @interface ColorMode {
+ }
/** Color mode: Monochrome color scheme, for example one color is used. */
public static final int COLOR_MODE_MONOCHROME = 1 << 0;
/** Color mode: Color color scheme, for example many colors are used. */
@@ -45,6 +58,13 @@ public final class PrintAttributes implements Parcelable {
private static final int VALID_COLOR_MODES =
COLOR_MODE_MONOCHROME | COLOR_MODE_COLOR;
+ /** @hide */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef(flag = true, value = {
+ DUPLEX_MODE_NONE, DUPLEX_MODE_LONG_EDGE, DUPLEX_MODE_SHORT_EDGE
+ })
+ public @interface DuplexMode {
+ }
/** Duplex mode: No duplexing. */
public static final int DUPLEX_MODE_NONE = 1 << 0;
/** Duplex mode: Pages are turned sideways along the long edge - like a book. */
@@ -66,7 +86,7 @@ public final class PrintAttributes implements Parcelable {
/* hide constructor */
}
- private PrintAttributes(Parcel parcel) {
+ private PrintAttributes(@NonNull Parcel parcel) {
mMediaSize = (parcel.readInt() == 1) ? MediaSize.createFromParcel(parcel) : null;
mResolution = (parcel.readInt() == 1) ? Resolution.createFromParcel(parcel) : null;
mMinMargins = (parcel.readInt() == 1) ? Margins.createFromParcel(parcel) : null;
@@ -79,7 +99,7 @@ public final class PrintAttributes implements Parcelable {
*
* @return The media size or null if not set.
*/
- public MediaSize getMediaSize() {
+ public @Nullable MediaSize getMediaSize() {
return mMediaSize;
}
@@ -99,7 +119,7 @@ public final class PrintAttributes implements Parcelable {
*
* @return The resolution or null if not set.
*/
- public Resolution getResolution() {
+ public @Nullable Resolution getResolution() {
return mResolution;
}
@@ -127,7 +147,7 @@ public final class PrintAttributes implements Parcelable {
*
* @return The margins or null if not set.
*/
- public Margins getMinMargins() {
+ public @Nullable Margins getMinMargins() {
return mMinMargins;
}
@@ -158,7 +178,7 @@ public final class PrintAttributes implements Parcelable {
* @see #COLOR_MODE_COLOR
* @see #COLOR_MODE_MONOCHROME
*/
- public int getColorMode() {
+ public @ColorMode int getColorMode() {
return mColorMode;
}
@@ -199,7 +219,7 @@ public final class PrintAttributes implements Parcelable {
* @see #DUPLEX_MODE_LONG_EDGE
* @see #DUPLEX_MODE_SHORT_EDGE
*/
- public int getDuplexMode() {
+ public @DuplexMode int getDuplexMode() {
return mDuplexMode;
}
@@ -828,7 +848,8 @@ public final class PrintAttributes implements Parcelable {
* or the widthMils is less than or equal to zero or the heightMils is less
* than or equal to zero.
*/
- public MediaSize(String id, String label, int widthMils, int heightMils) {
+ public MediaSize(@NonNull String id, @NonNull String label,
+ @IntRange(from = 1) int widthMils, @IntRange(from = 1) int heightMils) {
if (TextUtils.isEmpty(id)) {
throw new IllegalArgumentException("id cannot be empty.");
}
@@ -872,7 +893,7 @@ public final class PrintAttributes implements Parcelable {
*
* @return The unique media size id.
*/
- public String getId() {
+ public @NonNull String getId() {
return mId;
}
@@ -882,7 +903,7 @@ public final class PrintAttributes implements Parcelable {
* @param packageManager The package manager for loading the label.
* @return The human readable label.
*/
- public String getLabel(PackageManager packageManager) {
+ public @NonNull String getLabel(@NonNull PackageManager packageManager) {
if (!TextUtils.isEmpty(mPackageName) && mLabelResId > 0) {
try {
return packageManager.getResourcesForApplication(
@@ -903,7 +924,7 @@ public final class PrintAttributes implements Parcelable {
*
* @return The media width.
*/
- public int getWidthMils() {
+ public @IntRange(from = 1) int getWidthMils() {
return mWidthMils;
}
@@ -912,7 +933,7 @@ public final class PrintAttributes implements Parcelable {
*
* @return The media height.
*/
- public int getHeightMils() {
+ public @IntRange(from = 1) int getHeightMils() {
return mHeightMils;
}
@@ -934,7 +955,7 @@ public final class PrintAttributes implements Parcelable {
* @return New instance in landscape orientation if this one
* is in landscape, otherwise this instance.
*/
- public MediaSize asPortrait() {
+ public @NonNull MediaSize asPortrait() {
if (isPortrait()) {
return this;
}
@@ -951,7 +972,7 @@ public final class PrintAttributes implements Parcelable {
* @return New instance in landscape orientation if this one
* is in portrait, otherwise this instance.
*/
- public MediaSize asLandscape() {
+ public @NonNull MediaSize asLandscape() {
if (!isPortrait()) {
return this;
}
@@ -1063,7 +1084,8 @@ public final class PrintAttributes implements Parcelable {
* or the horizontalDpi is less than or equal to zero or the verticalDpi is
* less than or equal to zero.
*/
- public Resolution(String id, String label, int horizontalDpi, int verticalDpi) {
+ public Resolution(@NonNull String id, @NonNull String label,
+ @IntRange(from = 1) int horizontalDpi, @IntRange(from = 1) int verticalDpi) {
if (TextUtils.isEmpty(id)) {
throw new IllegalArgumentException("id cannot be empty.");
}
@@ -1094,7 +1116,7 @@ public final class PrintAttributes implements Parcelable {
*
* @return The unique resolution id.
*/
- public String getId() {
+ public @NonNull String getId() {
return mId;
}
@@ -1103,7 +1125,7 @@ public final class PrintAttributes implements Parcelable {
*
* @return The human readable label.
*/
- public String getLabel() {
+ public @NonNull String getLabel() {
return mLabel;
}
@@ -1112,7 +1134,7 @@ public final class PrintAttributes implements Parcelable {
*
* @return The horizontal resolution.
*/
- public int getHorizontalDpi() {
+ public @IntRange(from = 1) int getHorizontalDpi() {
return mHorizontalDpi;
}
@@ -1121,7 +1143,7 @@ public final class PrintAttributes implements Parcelable {
*
* @return The vertical resolution.
*/
- public int getVerticalDpi() {
+ public @IntRange(from = 1) int getVerticalDpi() {
return mVerticalDpi;
}
@@ -1204,7 +1226,8 @@ public final class PrintAttributes implements Parcelable {
* @param rightMils The right margin in mils (thousands of an inch).
* @param bottomMils The bottom margin in mils (thousands of an inch).
*/
- public Margins(int leftMils, int topMils, int rightMils, int bottomMils) {
+ public Margins(@IntRange(from = 0) int leftMils, @IntRange(from = 0) int topMils,
+ @IntRange(from = 0) int rightMils, @IntRange(from = 0) int bottomMils) {
mTopMils = topMils;
mLeftMils = leftMils;
mRightMils = rightMils;
@@ -1216,7 +1239,7 @@ public final class PrintAttributes implements Parcelable {
*
* @return The left margin.
*/
- public int getLeftMils() {
+ public @IntRange(from = 0) int getLeftMils() {
return mLeftMils;
}
@@ -1225,7 +1248,7 @@ public final class PrintAttributes implements Parcelable {
*
* @return The top margin.
*/
- public int getTopMils() {
+ public @IntRange(from = 0) int getTopMils() {
return mTopMils;
}
@@ -1234,7 +1257,7 @@ public final class PrintAttributes implements Parcelable {
*
* @return The right margin.
*/
- public int getRightMils() {
+ public @IntRange(from = 0) int getRightMils() {
return mRightMils;
}
@@ -1243,7 +1266,7 @@ public final class PrintAttributes implements Parcelable {
*
* @return The bottom margin.
*/
- public int getBottomMils() {
+ public @IntRange(from = 0) int getBottomMils() {
return mBottomMils;
}
@@ -1368,7 +1391,7 @@ public final class PrintAttributes implements Parcelable {
* @param mediaSize The media size.
* @return This builder.
*/
- public Builder setMediaSize(MediaSize mediaSize) {
+ public @NonNull Builder setMediaSize(@NonNull MediaSize mediaSize) {
mAttributes.setMediaSize(mediaSize);
return this;
}
@@ -1379,7 +1402,7 @@ public final class PrintAttributes implements Parcelable {
* @param resolution The resolution.
* @return This builder.
*/
- public Builder setResolution(Resolution resolution) {
+ public @NonNull Builder setResolution(@NonNull Resolution resolution) {
mAttributes.setResolution(resolution);
return this;
}
@@ -1391,7 +1414,7 @@ public final class PrintAttributes implements Parcelable {
* @param margins The margins.
* @return This builder.
*/
- public Builder setMinMargins(Margins margins) {
+ public @NonNull Builder setMinMargins(@NonNull Margins margins) {
mAttributes.setMinMargins(margins);
return this;
}
@@ -1405,7 +1428,7 @@ public final class PrintAttributes implements Parcelable {
* @see PrintAttributes#COLOR_MODE_MONOCHROME
* @see PrintAttributes#COLOR_MODE_COLOR
*/
- public Builder setColorMode(int colorMode) {
+ public @NonNull Builder setColorMode(@ColorMode int colorMode) {
mAttributes.setColorMode(colorMode);
return this;
}
@@ -1420,7 +1443,7 @@ public final class PrintAttributes implements Parcelable {
* @see PrintAttributes#DUPLEX_MODE_LONG_EDGE
* @see PrintAttributes#DUPLEX_MODE_SHORT_EDGE
*/
- public Builder setDuplexMode(int duplexMode) {
+ public @NonNull Builder setDuplexMode(@DuplexMode int duplexMode) {
mAttributes.setDuplexMode(duplexMode);
return this;
}
@@ -1430,7 +1453,7 @@ public final class PrintAttributes implements Parcelable {
*
* @return The new instance.
*/
- public PrintAttributes build() {
+ public @NonNull PrintAttributes build() {
return mAttributes;
}
}
diff --git a/core/java/android/print/PrintDocumentInfo.java b/core/java/android/print/PrintDocumentInfo.java
index 44e6410f64d55..db3b6f47af431 100644
--- a/core/java/android/print/PrintDocumentInfo.java
+++ b/core/java/android/print/PrintDocumentInfo.java
@@ -16,10 +16,16 @@
package android.print;
+import android.annotation.IntDef;
+import android.annotation.IntRange;
+import android.annotation.NonNull;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
/**
* This class encapsulates information about a document for printing
* purposes. This meta-data is used by the platform and print services,
@@ -74,6 +80,13 @@ public final class PrintDocumentInfo implements Parcelable {
*/
public static final int PAGE_COUNT_UNKNOWN = -1;
+ /** @hide */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({
+ CONTENT_TYPE_UNKNOWN, CONTENT_TYPE_DOCUMENT, CONTENT_TYPE_PHOTO
+ })
+ public @interface ContentType {
+ }
/**
* Content type: unknown.
*/
@@ -116,9 +129,9 @@ public final class PrintDocumentInfo implements Parcelable {
/**
* Creates a new instance.
*
- * @param Prototype from which to clone.
+ * @param prototype from which to clone.
*/
- private PrintDocumentInfo(PrintDocumentInfo prototype) {
+ private PrintDocumentInfo(@NonNull PrintDocumentInfo prototype) {
mName = prototype.mName;
mPageCount = prototype.mPageCount;
mContentType = prototype.mContentType;
@@ -143,7 +156,7 @@ public final class PrintDocumentInfo implements Parcelable {
*
* @return The document name.
*/
- public String getName() {
+ public @NonNull String getName() {
return mName;
}
@@ -154,7 +167,7 @@ public final class PrintDocumentInfo implements Parcelable {
*
* @see #PAGE_COUNT_UNKNOWN
*/
- public int getPageCount() {
+ public @IntRange(from = -1) int getPageCount() {
return mPageCount;
}
@@ -167,7 +180,7 @@ public final class PrintDocumentInfo implements Parcelable {
* @see #CONTENT_TYPE_DOCUMENT
* @see #CONTENT_TYPE_PHOTO
*/
- public int getContentType() {
+ public @ContentType int getContentType() {
return mContentType;
}
@@ -176,7 +189,7 @@ public final class PrintDocumentInfo implements Parcelable {
*
* @return The data size.
*/
- public long getDataSize() {
+ public @IntRange(from = 0) long getDataSize() {
return mDataSize;
}
@@ -187,7 +200,7 @@ public final class PrintDocumentInfo implements Parcelable {
*
* @hide
*/
- public void setDataSize(long dataSize) {
+ public void setDataSize(@IntRange(from = 0) long dataSize) {
mDataSize = dataSize;
}
@@ -288,7 +301,7 @@ public final class PrintDocumentInfo implements Parcelable {
* is the file name if the content it describes is saved as a PDF.
* Cannot be empty.
*/
- public Builder(String name) {
+ public Builder(@NonNull String name) {
if (TextUtils.isEmpty(name)) {
throw new IllegalArgumentException("name cannot be empty");
}
@@ -302,10 +315,11 @@ public final class PrintDocumentInfo implements Parcelable {
* Default: {@link #PAGE_COUNT_UNKNOWN}
*
null if not set.
*/
- public PageRange[] getPages() {
+ public @Nullable PageRange[] getPages() {
return mPageRanges;
}
@@ -474,7 +488,7 @@ public final class PrintJobInfo implements Parcelable {
*
* @return The attributes.
*/
- public PrintAttributes getAttributes() {
+ public @NonNull PrintAttributes getAttributes() {
return mAttributes;
}
@@ -713,7 +727,7 @@ public final class PrintJobInfo implements Parcelable {
* @param prototype Prototype to use as a starting point.
* Can be null.
*/
- public Builder(PrintJobInfo prototype) {
+ public Builder(@Nullable PrintJobInfo prototype) {
mPrototype = (prototype != null)
? new PrintJobInfo(prototype)
: new PrintJobInfo();
@@ -724,7 +738,7 @@ public final class PrintJobInfo implements Parcelable {
*
* @param copies The number of copies.
*/
- public void setCopies(int copies) {
+ public void setCopies(@IntRange(from = 1) int copies) {
mPrototype.mCopies = copies;
}
@@ -733,7 +747,7 @@ public final class PrintJobInfo implements Parcelable {
*
* @param attributes The attributes.
*/
- public void setAttributes(PrintAttributes attributes) {
+ public void setAttributes(@NonNull PrintAttributes attributes) {
mPrototype.mAttributes = attributes;
}
@@ -742,7 +756,7 @@ public final class PrintJobInfo implements Parcelable {
*
* @param pages The included pages.
*/
- public void setPages(PageRange[] pages) {
+ public void setPages(@NonNull PageRange[] pages) {
mPrototype.mPageRanges = pages;
}
@@ -774,7 +788,7 @@ public final class PrintJobInfo implements Parcelable {
* @param key The option key.
* @param value The option value.
*/
- public void putAdvancedOption(String key, String value) {
+ public void putAdvancedOption(@NonNull String key, @Nullable String value) {
if (mPrototype.mAdvancedOptions == null) {
mPrototype.mAdvancedOptions = new Bundle();
}
@@ -787,7 +801,7 @@ public final class PrintJobInfo implements Parcelable {
* @param key The option key.
* @param value The option value.
*/
- public void putAdvancedOption(String key, int value) {
+ public void putAdvancedOption(@NonNull String key, int value) {
if (mPrototype.mAdvancedOptions == null) {
mPrototype.mAdvancedOptions = new Bundle();
}
@@ -799,7 +813,7 @@ public final class PrintJobInfo implements Parcelable {
*
* @return The new instance.
*/
- public PrintJobInfo build() {
+ public @NonNull PrintJobInfo build() {
return mPrototype;
}
}
diff --git a/core/java/android/print/PrintManager.java b/core/java/android/print/PrintManager.java
index 15af90c588432..3eb487461e5ca 100644
--- a/core/java/android/print/PrintManager.java
+++ b/core/java/android/print/PrintManager.java
@@ -16,6 +16,8 @@
package android.print;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.app.Activity;
import android.app.Application.ActivityLifecycleCallbacks;
import android.content.Context;
@@ -181,6 +183,8 @@ public final class PrintManager {
*
* @param context The current context in which to operate.
* @param service The backing system service.
+ * @param userId The user id in which to operate.
+ * @param appId The application id in which to operate.
* @hide
*/
public PrintManager(Context context, IPrintManager service, int userId, int appId) {
@@ -291,6 +295,7 @@ public final class PrintManager {
/**
* Gets a print job given its id.
*
+ * @param printJobId The id of the print job.
* @return The print job list.
* @see PrintJob
* @hide
@@ -340,7 +345,7 @@ public final class PrintManager {
* @return The print job list.
* @see PrintJob
*/
- public Listnull.
*/
- public Builder(PrinterId printerId) {
+ public Builder(@NonNull PrinterId printerId) {
if (printerId == null) {
throw new IllegalArgumentException("printerId cannot be null.");
}
@@ -446,7 +449,7 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
*
* @see PrintAttributes.MediaSize
*/
- public Builder addMediaSize(MediaSize mediaSize, boolean isDefault) {
+ public @NonNull Builder addMediaSize(@NonNull MediaSize mediaSize, boolean isDefault) {
if (mPrototype.mMediaSizes == null) {
mPrototype.mMediaSizes = new ArrayList- * This class computes the page width, page height, and content rectangle - * from the provided print attributes and these precomputed values can be - * accessed via {@link #getPageWidth()}, {@link #getPageHeight()}, and - * {@link #getPageContentRect()}, respectively. The {@link #startPage(int)} - * methods creates pages whose {@link PageInfo} is initialized with the - * precomputed values for width, height, and content rectangle. + * This class computes the page width, page height, and content rectangle from the provided print + * attributes and these precomputed values can be accessed via {@link #getPageWidth()}, + * {@link #getPageHeight()}, and {@link #getPageContentRect()}, respectively. The + * {@link #startPage(int)} methods creates pages whose + * {@link android.graphics.pdf.PdfDocument.PageInfo PageInfo} is initialized with the precomputed + * values for width, height, and content rectangle. *
* A typical use of the APIs looks like this: *
@@ -81,7 +80,7 @@ public class PrintedPdfDocument extends PdfDocument { * @param context Context instance for accessing resources. * @param attributes The print attributes. */ - public PrintedPdfDocument(Context context, PrintAttributes attributes) { + public PrintedPdfDocument(@NonNull Context context, @NonNull PrintAttributes attributes) { MediaSize mediaSize = attributes.getMediaSize(); // Compute the size of the target canvas from the attributes. @@ -105,28 +104,28 @@ public class PrintedPdfDocument extends PdfDocument { } /** - * Starts a new page. The page is created using width, height and content - * rectangle computed from the print attributes passed in the constructor - * and the given page number to create an appropriate {@link PageInfo}. + * Starts a new page. The page is created using width, height and content rectangle computed + * from the print attributes passed in the constructor and the given page number to create an + * appropriate {@link android.graphics.pdf.PdfDocument.PageInfo PageInfo}. *- * After the page is created you can draw arbitrary content on the page's - * canvas which you can get by calling {@link Page#getCanvas() Page.getCanvas()}. + * After the page is created you can draw arbitrary content on the page's canvas which you can + * get by calling {@link android.graphics.pdf.PdfDocument.Page#getCanvas() Page.getCanvas()}. * After you are done drawing the content you should finish the page by calling - * {@link #finishPage(Page)}. After the page is finished you should no longer - * access the page or its canvas. + * {@link #finishPage(Page)}. After the page is finished you should no longer access the page or + * its canvas. *
*- * Note: Do not call this method after {@link #close()}. - * Also do not call this method if the last page returned by this method - * is not finished by calling {@link #finishPage(Page)}. + * Note: Do not call this method after {@link #close()}. Also do not call this + * method if the last page returned by this method is not finished by calling + * {@link #finishPage(Page)}. *
* - * @param pageNumber The page number. Must be a positive value. + * @param pageNumber The page number. Must be a non negative. * @return A blank page. * * @see #finishPage(Page) */ - public Page startPage(int pageNumber) { + public @NonNull Page startPage(@IntRange(from = 0) int pageNumber) { PageInfo pageInfo = new PageInfo .Builder(mPageWidth, mPageHeight, pageNumber) .setContentRect(mContentRect) @@ -139,7 +138,7 @@ public class PrintedPdfDocument extends PdfDocument { * * @return The page width in PostScript points (1/72th of an inch). */ - public int getPageWidth() { + public @IntRange(from = 0) int getPageWidth() { return mPageWidth; } @@ -148,7 +147,7 @@ public class PrintedPdfDocument extends PdfDocument { * * @return The page height in PostScript points (1/72th of an inch). */ - public int getPageHeight() { + public @IntRange(from = 0) int getPageHeight() { return mPageHeight; } @@ -158,7 +157,7 @@ public class PrintedPdfDocument extends PdfDocument { * * @return The content rectangle. */ - public Rect getPageContentRect() { + public @NonNull Rect getPageContentRect() { return mContentRect; } } diff --git a/core/java/android/printservice/PrintDocument.java b/core/java/android/printservice/PrintDocument.java index e43f2a8363765..0121ae13e32f8 100644 --- a/core/java/android/printservice/PrintDocument.java +++ b/core/java/android/printservice/PrintDocument.java @@ -16,6 +16,8 @@ package android.printservice; +import android.annotation.NonNull; +import android.annotation.Nullable; import android.os.ParcelFileDescriptor; import android.os.RemoteException; import android.print.PrintDocumentInfo; @@ -54,7 +56,7 @@ public final class PrintDocument { * * @return The document info. */ - public PrintDocumentInfo getInfo() { + public @NonNull PrintDocumentInfo getInfo() { PrintService.throwIfNotCalledOnMainThread(); return mInfo; } @@ -69,7 +71,7 @@ public final class PrintDocument { * * @return A file descriptor for reading the data. */ - public ParcelFileDescriptor getData() { + public @Nullable ParcelFileDescriptor getData() { PrintService.throwIfNotCalledOnMainThread(); ParcelFileDescriptor source = null; ParcelFileDescriptor sink = null; diff --git a/core/java/android/printservice/PrintJob.java b/core/java/android/printservice/PrintJob.java index 86fc292cb003a..6414b6a2230c8 100644 --- a/core/java/android/printservice/PrintJob.java +++ b/core/java/android/printservice/PrintJob.java @@ -344,7 +344,7 @@ public final class PrintJob { * @return True if the tag was set, false otherwise. */ @MainThread - public boolean setTag(String tag) { + public boolean setTag(@NonNull String tag) { PrintService.throwIfNotCalledOnMainThread(); if (isInImmutableState()) { return false; @@ -364,7 +364,8 @@ public final class PrintJob { * * @see #setTag(String) */ - public String getTag() { + @MainThread + public @Nullable String getTag() { PrintService.throwIfNotCalledOnMainThread(); return getInfo().getTag(); } diff --git a/core/java/android/printservice/PrintService.java b/core/java/android/printservice/PrintService.java index acebd9d84a3ed..d0037b7625604 100644 --- a/core/java/android/printservice/PrintService.java +++ b/core/java/android/printservice/PrintService.java @@ -16,6 +16,7 @@ package android.printservice; +import android.annotation.Nullable; import android.app.Service; import android.content.ComponentName; import android.content.Context; @@ -191,30 +192,29 @@ public abstract class PrintService extends Service { /** * If you declared an optional activity with advanced print options via the - * {@link android.R.attr#advancedPrintOptionsActivity advancedPrintOptionsActivity} - * attribute, this extra is used to pass in the currently constructed {@link - * PrintJobInfo} to your activity allowing you to modify it. After you are - * done, you must return the modified {@link PrintJobInfo} via the same extra. + * {@link android.R.attr#advancedPrintOptionsActivity advancedPrintOptionsActivity} attribute, + * this extra is used to pass in the currently constructed {@link PrintJobInfo} to your activity + * allowing you to modify it. After you are done, you must return the modified + * {@link PrintJobInfo} via the same extra. *- * You cannot modify the passed in {@link PrintJobInfo} directly, rather you - * should build another one using the {@link PrintJobInfo.Builder} class. You - * can specify any standard properties and add advanced, printer specific, - * ones via {@link PrintJobInfo.Builder#putAdvancedOption(String, String) - * PrintJobInfo.Builder.putAdvancedOption(String, String)} and {@link - * PrintJobInfo.Builder#putAdvancedOption(String, int) - * PrintJobInfo.Builder.putAdvancedOption(String, int)}. The advanced options - * are not interpreted by the system, they will not be visible to applications, - * and can only be accessed by your print service via {@link - * PrintJob#getAdvancedStringOption(String) PrintJob.getAdvancedStringOption(String)} - * and {@link PrintJob#getAdvancedIntOption(String) PrintJob.getAdvancedIntOption(String)}. + * You cannot modify the passed in {@link PrintJobInfo} directly, rather you should build + * another one using the {@link android.print.PrintJobInfo.Builder PrintJobInfo.Builder} class. + * You can specify any standard properties and add advanced, printer specific, ones via + * {@link android.print.PrintJobInfo.Builder#putAdvancedOption(String, String) + * PrintJobInfo.Builder.putAdvancedOption(String, String)} and + * {@link android.print.PrintJobInfo.Builder#putAdvancedOption(String, int) + * PrintJobInfo.Builder.putAdvancedOption(String, int)}. The advanced options are not + * interpreted by the system, they will not be visible to applications, and can only be accessed + * by your print service via {@link PrintJob#getAdvancedStringOption(String) + * PrintJob.getAdvancedStringOption(String)} and {@link PrintJob#getAdvancedIntOption(String) + * PrintJob.getAdvancedIntOption(String)}. *
*- * If the advanced print options activity offers changes to the standard print - * options, you can get the current {@link android.print.PrinterInfo} using the - * {@link #EXTRA_PRINTER_INFO} extra which will allow you to present the user - * with UI options supported by the current printer. For example, if the current - * printer does not support a given media size, you should not offer it in the - * advanced print options UI. + * If the advanced print options activity offers changes to the standard print options, you can + * get the current {@link android.print.PrinterInfo PrinterInfo} using the + * {@link #EXTRA_PRINTER_INFO} extra which will allow you to present the user with UI options + * supported by the current printer. For example, if the current printer does not support a + * given media size, you should not offer it in the advanced print options UI. *
* * @see #EXTRA_PRINTER_INFO @@ -275,9 +275,10 @@ public abstract class PrintService extends Service { /** * Callback asking you to create a new {@link PrinterDiscoverySession}. * + * @return The created session. * @see PrinterDiscoverySession */ - protected abstract PrinterDiscoverySession onCreatePrinterDiscoverySession(); + protected abstract @Nullable PrinterDiscoverySession onCreatePrinterDiscoverySession(); /** * Called when cancellation of a print job is requested. The service @@ -368,6 +369,7 @@ public abstract class PrintService extends Service { mHandler.sendEmptyMessage(ServiceHandler.MSG_DESTROY_PRINTER_DISCOVERY_SESSION); } + @Override public void startPrinterDiscovery(List