From c43639c3067dda5df189fb3cbf14f256c17e677d Mon Sep 17 00:00:00 2001
From: "Philip P. Moltmann"
Date: Fri, 18 Dec 2015 13:58:40 -0800
Subject: [PATCH] Clean up print subsystem
- Stop using deprecated APIs
- Fix all public and some internal javadoc
- Add @Decorations to public APIs
- Some minor cleanup, e.g. don't use variables with overlapping names in same scope
- remove unnecessary properties from manifest (they are set by the build
system)
Change-Id: I0ce8849a516414763fe9de76c3a18ce17d896816
---
core/java/android/print/PageRange.java | 10 ++-
core/java/android/print/PrintAttributes.java | 81 ++++++++++++-------
.../java/android/print/PrintDocumentInfo.java | 42 ++++++----
core/java/android/print/PrintJob.java | 7 +-
core/java/android/print/PrintJobId.java | 5 +-
core/java/android/print/PrintJobInfo.java | 54 ++++++++-----
core/java/android/print/PrintManager.java | 12 ++-
.../print/PrinterCapabilitiesInfo.java | 31 ++++---
core/java/android/print/PrinterId.java | 3 +-
core/java/android/print/PrinterInfo.java | 35 +++++---
.../android/print/pdf/PrintedPdfDocument.java | 53 ++++++------
.../android/printservice/PrintDocument.java | 6 +-
core/java/android/printservice/PrintJob.java | 5 +-
.../android/printservice/PrintService.java | 46 ++++++-----
.../printservice/PrintServiceInfo.java | 7 +-
.../printservice/PrinterDiscoverySession.java | 30 +++----
packages/PrintSpooler/AndroidManifest.xml | 4 +-
.../model/PrintSpoolerService.java | 4 +-
.../model/RemotePrintDocument.java | 10 +--
.../ui/FusedPrintersProvider.java | 7 +-
.../android/printspooler/ui/PageAdapter.java | 4 +-
.../printspooler/ui/PrintActivity.java | 9 ++-
.../ui/PrintPreviewController.java | 12 ++-
.../printspooler/widget/PrintContentView.java | 4 +
24 files changed, 286 insertions(+), 195 deletions(-)
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}
*
*
- * @param pageCount The number of pages. Must be greater than
- * or equal to zero or {@link PrintDocumentInfo#PAGE_COUNT_UNKNOWN}.
+ * @param pageCount The number of pages. Must be greater than or equal to zero or
+ * {@link PrintDocumentInfo#PAGE_COUNT_UNKNOWN}.
+ * @return This builder.
*/
- public Builder setPageCount(int pageCount) {
+ public @NonNull Builder setPageCount(@IntRange(from = -1) int pageCount) {
if (pageCount < 0 && pageCount != PAGE_COUNT_UNKNOWN) {
throw new IllegalArgumentException("pageCount"
+ " must be greater than or equal to zero or"
@@ -322,12 +336,12 @@ public final class PrintDocumentInfo implements Parcelable {
*
*
* @param type The content type.
- *
+ * @return This builder.
* @see #CONTENT_TYPE_UNKNOWN
* @see #CONTENT_TYPE_DOCUMENT
* @see #CONTENT_TYPE_PHOTO
*/
- public Builder setContentType(int type) {
+ public @NonNull Builder setContentType(@ContentType int type) {
mPrototype.mContentType = type;
return this;
}
@@ -337,7 +351,7 @@ public final class PrintDocumentInfo implements Parcelable {
*
* @return The new instance.
*/
- public PrintDocumentInfo build() {
+ public @NonNull PrintDocumentInfo build() {
// Zero pages is the same as unknown as in this case
// we will have to ask for all pages and look a the
// wiritten PDF file for the page count.
diff --git a/core/java/android/print/PrintJob.java b/core/java/android/print/PrintJob.java
index 0abe2193249ee..777baabd955a8 100644
--- a/core/java/android/print/PrintJob.java
+++ b/core/java/android/print/PrintJob.java
@@ -16,6 +16,9 @@
package android.print;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+
/**
* This class represents a print job from the perspective of an
* application. It contains behavior methods for performing operations
@@ -41,7 +44,7 @@ public final class PrintJob {
*
* @return The id.
*/
- public PrintJobId getId() {
+ public @NonNull PrintJobId getId() {
return mCachedInfo.getId();
}
@@ -55,7 +58,7 @@ public final class PrintJob {
*
* @return The print job info.
*/
- public PrintJobInfo getInfo() {
+ public @Nullable PrintJobInfo getInfo() {
if (isInImmutableState()) {
return mCachedInfo;
}
diff --git a/core/java/android/print/PrintJobId.java b/core/java/android/print/PrintJobId.java
index 01550e2a74136..a2ee02b7bc490 100644
--- a/core/java/android/print/PrintJobId.java
+++ b/core/java/android/print/PrintJobId.java
@@ -16,6 +16,7 @@
package android.print;
+import android.annotation.NonNull;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
@@ -91,14 +92,14 @@ public final class PrintJobId implements Parcelable {
*
* @hide
*/
- public String flattenToString() {
+ public @NonNull String flattenToString() {
return mValue;
}
/**
* Unflattens a print job id from a string.
*
- * @string The string.
+ * @param string The string.
* @return The unflattened id, or null if the string is malformed.
*
* @hide
diff --git a/core/java/android/print/PrintJobInfo.java b/core/java/android/print/PrintJobInfo.java
index 7148c87578302..21836b3a61097 100644
--- a/core/java/android/print/PrintJobInfo.java
+++ b/core/java/android/print/PrintJobInfo.java
@@ -17,6 +17,9 @@
package android.print;
import android.annotation.FloatRange;
+import android.annotation.IntDef;
+import android.annotation.IntRange;
+import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.TestApi;
import android.os.Bundle;
@@ -25,6 +28,8 @@ import android.os.Parcelable;
import com.android.internal.util.Preconditions;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
/**
@@ -35,6 +40,15 @@ import java.util.Arrays;
*/
public final class PrintJobInfo implements Parcelable {
+ /** @hide */
+ @IntDef({
+ STATE_CREATED, STATE_QUEUED, STATE_STARTED, STATE_BLOCKED, STATE_COMPLETED,
+ STATE_FAILED, STATE_CANCELED
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface State {
+ }
+
/**
* Constant for matching any print job state.
*
@@ -200,7 +214,7 @@ public final class PrintJobInfo implements Parcelable {
mAdvancedOptions = other.mAdvancedOptions;
}
- private PrintJobInfo(Parcel parcel) {
+ private PrintJobInfo(@NonNull Parcel parcel) {
mId = parcel.readParcelable(null);
mLabel = parcel.readString();
mPrinterId = parcel.readParcelable(null);
@@ -230,7 +244,7 @@ public final class PrintJobInfo implements Parcelable {
*
* @return The id.
*/
- public PrintJobId getId() {
+ public @NonNull PrintJobId getId() {
return mId;
}
@@ -241,7 +255,7 @@ public final class PrintJobInfo implements Parcelable {
*
* @hide
*/
- public void setId(PrintJobId id) {
+ public void setId(@NonNull PrintJobId id) {
this.mId = id;
}
@@ -250,7 +264,7 @@ public final class PrintJobInfo implements Parcelable {
*
* @return The label.
*/
- public String getLabel() {
+ public @NonNull String getLabel() {
return mLabel;
}
@@ -261,7 +275,7 @@ public final class PrintJobInfo implements Parcelable {
*
* @hide
*/
- public void setLabel(String label) {
+ public void setLabel(@NonNull String label) {
mLabel = label;
}
@@ -270,7 +284,7 @@ public final class PrintJobInfo implements Parcelable {
*
* @return The target printer id.
*/
- public PrinterId getPrinterId() {
+ public @Nullable PrinterId getPrinterId() {
return mPrinterId;
}
@@ -281,7 +295,7 @@ public final class PrintJobInfo implements Parcelable {
*
* @hide
*/
- public void setPrinterId(PrinterId printerId) {
+ public void setPrinterId(@NonNull PrinterId printerId) {
mPrinterId = printerId;
}
@@ -292,7 +306,7 @@ public final class PrintJobInfo implements Parcelable {
*
* @hide
*/
- public String getPrinterName() {
+ public @Nullable String getPrinterName() {
return mPrinterName;
}
@@ -303,7 +317,7 @@ public final class PrintJobInfo implements Parcelable {
*
* @hide
*/
- public void setPrinterName(String printerName) {
+ public void setPrinterName(@NonNull String printerName) {
mPrinterName = printerName;
}
@@ -320,7 +334,7 @@ public final class PrintJobInfo implements Parcelable {
* @see #STATE_FAILED
* @see #STATE_CANCELED
*/
- public int getState() {
+ public @State int getState() {
return mState;
}
@@ -431,7 +445,7 @@ public final class PrintJobInfo implements Parcelable {
*
* @return The number of copies or zero if not set.
*/
- public int getCopies() {
+ public @IntRange(from = 0) int getCopies() {
return mCopies;
}
@@ -454,7 +468,7 @@ public final class PrintJobInfo implements Parcelable {
*
* @return The included pages or 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 List getPrintJobs() {
+ public @NonNull List getPrintJobs() {
if (mService == null) {
Log.w(LOG_TAG, "Feature android.software.print not available");
return Collections.emptyList();
@@ -435,8 +440,9 @@ public final class PrintManager {
*
* @see PrintJob
*/
- public PrintJob print(String printJobName, PrintDocumentAdapter documentAdapter,
- PrintAttributes attributes) {
+ public @NonNull PrintJob print(@NonNull String printJobName,
+ @NonNull PrintDocumentAdapter documentAdapter,
+ @Nullable PrintAttributes attributes) {
if (mService == null) {
Log.w(LOG_TAG, "Feature android.software.print not available");
return null;
diff --git a/core/java/android/print/PrinterCapabilitiesInfo.java b/core/java/android/print/PrinterCapabilitiesInfo.java
index 96f318526384d..d13879ba69147 100644
--- a/core/java/android/print/PrinterCapabilitiesInfo.java
+++ b/core/java/android/print/PrinterCapabilitiesInfo.java
@@ -16,8 +16,11 @@
package android.print;
+import android.annotation.NonNull;
import android.os.Parcel;
import android.os.Parcelable;
+import android.print.PrintAttributes.ColorMode;
+import android.print.PrintAttributes.DuplexMode;
import android.print.PrintAttributes.Margins;
import android.print.PrintAttributes.MediaSize;
import android.print.PrintAttributes.Resolution;
@@ -121,7 +124,7 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
*
* @return The media sizes.
*/
- public List getMediaSizes() {
+ public @NonNull List getMediaSizes() {
return Collections.unmodifiableList(mMediaSizes);
}
@@ -130,7 +133,7 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
*
* @return The resolutions.
*/
- public List getResolutions() {
+ public @NonNull List getResolutions() {
return Collections.unmodifiableList(mResolutions);
}
@@ -140,7 +143,7 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
*
* @return The minimal margins.
*/
- public Margins getMinMargins() {
+ public @NonNull Margins getMinMargins() {
return mMinMargins;
}
@@ -152,7 +155,7 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
* @see PrintAttributes#COLOR_MODE_COLOR
* @see PrintAttributes#COLOR_MODE_MONOCHROME
*/
- public int getColorModes() {
+ public @ColorMode int getColorModes() {
return mColorModes;
}
@@ -165,7 +168,7 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
* @see PrintAttributes#DUPLEX_MODE_LONG_EDGE
* @see PrintAttributes#DUPLEX_MODE_SHORT_EDGE
*/
- public int getDuplexModes() {
+ public @DuplexMode int getDuplexModes() {
return mDuplexModes;
}
@@ -174,7 +177,7 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
*
* @return The default attributes.
*/
- public PrintAttributes getDefaults() {
+ public @NonNull PrintAttributes getDefaults() {
PrintAttributes.Builder builder = new PrintAttributes.Builder();
builder.setMinMargins(mMinMargins);
@@ -425,7 +428,7 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
*
* @throws IllegalArgumentException If the printer id is null.
*/
- 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();
}
@@ -474,7 +477,7 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
*
* @see PrintAttributes.Resolution
*/
- public Builder addResolution(Resolution resolution, boolean isDefault) {
+ public @NonNull Builder addResolution(@NonNull Resolution resolution, boolean isDefault) {
if (mPrototype.mResolutions == null) {
mPrototype.mResolutions = new ArrayList();
}
@@ -502,7 +505,7 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
*
* @see PrintAttributes.Margins
*/
- public Builder setMinMargins(Margins margins) {
+ public @NonNull Builder setMinMargins(@NonNull Margins margins) {
if (margins == null) {
throw new IllegalArgumentException("margins cannot be null");
}
@@ -532,7 +535,8 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
* @see PrintAttributes#COLOR_MODE_COLOR
* @see PrintAttributes#COLOR_MODE_MONOCHROME
*/
- public Builder setColorModes(int colorModes, int defaultColorMode) {
+ public @NonNull Builder setColorModes(@ColorMode int colorModes,
+ @ColorMode int defaultColorMode) {
int currentModes = colorModes;
while (currentModes > 0) {
final int currentMode = (1 << Integer.numberOfTrailingZeros(currentModes));
@@ -562,7 +566,8 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
* @see PrintAttributes#DUPLEX_MODE_LONG_EDGE
* @see PrintAttributes#DUPLEX_MODE_SHORT_EDGE
*/
- public Builder setDuplexModes(int duplexModes, int defaultDuplexMode) {
+ public @NonNull Builder setDuplexModes(@DuplexMode int duplexModes,
+ @DuplexMode int defaultDuplexMode) {
int currentModes = duplexModes;
while (currentModes > 0) {
final int currentMode = (1 << Integer.numberOfTrailingZeros(currentModes));
@@ -589,7 +594,7 @@ public final class PrinterCapabilitiesInfo implements Parcelable {
*
* @throws IllegalStateException If a required attribute was not specified.
*/
- public PrinterCapabilitiesInfo build() {
+ public @NonNull PrinterCapabilitiesInfo build() {
if (mPrototype.mMediaSizes == null || mPrototype.mMediaSizes.isEmpty()) {
throw new IllegalStateException("No media size specified.");
}
diff --git a/core/java/android/print/PrinterId.java b/core/java/android/print/PrinterId.java
index a3f3b2bfee11b..83efe8020d984 100644
--- a/core/java/android/print/PrinterId.java
+++ b/core/java/android/print/PrinterId.java
@@ -16,6 +16,7 @@
package android.print;
+import android.annotation.NonNull;
import android.content.ComponentName;
import android.os.Parcel;
import android.os.Parcelable;
@@ -65,7 +66,7 @@ public final class PrinterId implements Parcelable {
*
* @return The printer name.
*/
- public String getLocalId() {
+ public @NonNull String getLocalId() {
return mLocalId;
}
diff --git a/core/java/android/print/PrinterInfo.java b/core/java/android/print/PrinterInfo.java
index e83c44aba39db..3ac78eabb1b1b 100644
--- a/core/java/android/print/PrinterInfo.java
+++ b/core/java/android/print/PrinterInfo.java
@@ -16,6 +16,7 @@
package android.print;
+import android.annotation.IntDef;
import android.annotation.DrawableRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -32,6 +33,9 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
/**
* This class represents the description of a printer. Instances of
* this class are created by print services to report to the system
@@ -42,6 +46,13 @@ import android.text.TextUtils;
*/
public final class PrinterInfo implements Parcelable {
+ /** @hide */
+ @IntDef({
+ STATUS_IDLE, STATUS_BUSY, STATUS_UNAVAILABLE
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface Status {
+ }
/** Printer status: the printer is idle and ready to print. */
public static final int STATUS_IDLE = 1;
@@ -112,7 +123,7 @@ public final class PrinterInfo implements Parcelable {
*
* @return The printer id.
*/
- public PrinterId getId() {
+ public @NonNull PrinterId getId() {
return mId;
}
@@ -169,7 +180,7 @@ public final class PrinterInfo implements Parcelable {
*
* @return The printer name.
*/
- public String getName() {
+ public @Nullable String getName() {
return mName;
}
@@ -182,7 +193,7 @@ public final class PrinterInfo implements Parcelable {
* @see #STATUS_IDLE
* @see #STATUS_UNAVAILABLE
*/
- public int getStatus() {
+ public @Status int getStatus() {
return mStatus;
}
@@ -191,7 +202,7 @@ public final class PrinterInfo implements Parcelable {
*
* @return The description.
*/
- public String getDescription() {
+ public @Nullable String getDescription() {
return mDescription;
}
@@ -212,7 +223,7 @@ public final class PrinterInfo implements Parcelable {
*
* @return The capabilities.
*/
- public PrinterCapabilitiesInfo getCapabilities() {
+ public @Nullable PrinterCapabilitiesInfo getCapabilities() {
return mCapabilities;
}
@@ -363,7 +374,7 @@ public final class PrinterInfo implements Parcelable {
* @throws IllegalArgumentException If the printer id is null, or the
* printer name is empty or the status is not a valid one.
*/
- public Builder(PrinterId printerId, String name, int status) {
+ public Builder(@NonNull PrinterId printerId, @NonNull String name, @Status int status) {
if (printerId == null) {
throw new IllegalArgumentException("printerId cannot be null.");
}
@@ -384,7 +395,7 @@ public final class PrinterInfo implements Parcelable {
*
* @param other Other info from which to start building.
*/
- public Builder(PrinterInfo other) {
+ public Builder(@NonNull PrinterInfo other) {
mPrototype = new PrinterInfo();
mPrototype.copyFrom(other);
}
@@ -399,7 +410,7 @@ public final class PrinterInfo implements Parcelable {
* @see PrinterInfo#STATUS_BUSY
* @see PrinterInfo#STATUS_UNAVAILABLE
*/
- public Builder setStatus(int status) {
+ public @Nullable Builder setStatus(@Status int status) {
mPrototype.mStatus = status;
return this;
}
@@ -441,7 +452,7 @@ public final class PrinterInfo implements Parcelable {
* @param name The name.
* @return This builder.
*/
- public Builder setName(String name) {
+ public @NonNull Builder setName(@NonNull String name) {
mPrototype.mName = name;
return this;
}
@@ -453,7 +464,7 @@ public final class PrinterInfo implements Parcelable {
* @param description The description.
* @return This builder.
*/
- public Builder setDescription(String description) {
+ public @NonNull Builder setDescription(@NonNull String description) {
mPrototype.mDescription = description;
return this;
}
@@ -476,7 +487,7 @@ public final class PrinterInfo implements Parcelable {
* @param capabilities The capabilities.
* @return This builder.
*/
- public Builder setCapabilities(PrinterCapabilitiesInfo capabilities) {
+ public @NonNull Builder setCapabilities(@NonNull PrinterCapabilitiesInfo capabilities) {
mPrototype.mCapabilities = capabilities;
return this;
}
@@ -486,7 +497,7 @@ public final class PrinterInfo implements Parcelable {
*
* @return A new {@link PrinterInfo}.
*/
- public PrinterInfo build() {
+ public @NonNull PrinterInfo build() {
return mPrototype;
}
diff --git a/core/java/android/print/pdf/PrintedPdfDocument.java b/core/java/android/print/pdf/PrintedPdfDocument.java
index 2d8aafa1a573a..df7c05477a1ad 100644
--- a/core/java/android/print/pdf/PrintedPdfDocument.java
+++ b/core/java/android/print/pdf/PrintedPdfDocument.java
@@ -16,26 +16,25 @@
package android.print.pdf;
+import android.annotation.IntRange;
+import android.annotation.NonNull;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.pdf.PdfDocument;
-import android.graphics.pdf.PdfDocument.Page;
-import android.graphics.pdf.PdfDocument.PageInfo;
import android.print.PrintAttributes;
import android.print.PrintAttributes.Margins;
import android.print.PrintAttributes.MediaSize;
/**
- * This class is a helper for creating a PDF file for given print
- * attributes. It is useful for implementing printing via the native
- * Android graphics APIs.
+ * This class is a helper for creating a PDF file for given print attributes. It is useful for
+ * implementing printing via the native Android graphics APIs.
*
- * 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 priorityList) {
mHandler.obtainMessage(ServiceHandler.MSG_START_PRINTER_DISCOVERY,
priorityList).sendToTarget();
diff --git a/core/java/android/printservice/PrintServiceInfo.java b/core/java/android/printservice/PrintServiceInfo.java
index a2c6c09e4932f..b33ef83045560 100644
--- a/core/java/android/printservice/PrintServiceInfo.java
+++ b/core/java/android/printservice/PrintServiceInfo.java
@@ -98,8 +98,7 @@ public final class PrintServiceInfo implements Parcelable {
*
* @param resolveInfo The service resolve info.
* @param context Context for accessing resources.
- * @throws XmlPullParserException If a XML parsing error occurs.
- * @throws IOException If a I/O error occurs.
+ * @return The created instance.
*/
public static PrintServiceInfo create(ResolveInfo resolveInfo, Context context) {
String settingsActivityName = null;
@@ -220,10 +219,12 @@ public final class PrintServiceInfo implements Parcelable {
/**
* {@inheritDoc}
*/
+ @Override
public int describeContents() {
return 0;
}
+ @Override
public void writeToParcel(Parcel parcel, int flagz) {
parcel.writeString(mId);
parcel.writeParcelable(mResolveInfo, 0);
@@ -275,10 +276,12 @@ public final class PrintServiceInfo implements Parcelable {
public static final Parcelable.Creator CREATOR =
new Parcelable.Creator() {
+ @Override
public PrintServiceInfo createFromParcel(Parcel parcel) {
return new PrintServiceInfo(parcel);
}
+ @Override
public PrintServiceInfo[] newArray(int size) {
return new PrintServiceInfo[size];
}
diff --git a/core/java/android/printservice/PrinterDiscoverySession.java b/core/java/android/printservice/PrinterDiscoverySession.java
index 739cd139ef601..cd5a903c4e696 100644
--- a/core/java/android/printservice/PrinterDiscoverySession.java
+++ b/core/java/android/printservice/PrinterDiscoverySession.java
@@ -139,7 +139,7 @@ public abstract class PrinterDiscoverySession {
* @see #removePrinters(List)
* @see #isDestroyed()
*/
- public final List getPrinters() {
+ public final @NonNull List getPrinters() {
PrintService.throwIfNotCalledOnMainThread();
if (mIsDestroyed) {
return Collections.emptyList();
@@ -162,7 +162,7 @@ public abstract class PrinterDiscoverySession {
* @see #getPrinters()
* @see #isDestroyed()
*/
- public final void addPrinters(List printers) {
+ public final void addPrinters(@NonNull List printers) {
PrintService.throwIfNotCalledOnMainThread();
// If the session is destroyed - nothing do to.
@@ -226,7 +226,7 @@ public abstract class PrinterDiscoverySession {
* @see #getPrinters()
* @see #isDestroyed()
*/
- public final void removePrinters(List printerIds) {
+ public final void removePrinters(@NonNull List printerIds) {
PrintService.throwIfNotCalledOnMainThread();
// If the session is destroyed - nothing do to.
@@ -351,7 +351,7 @@ public abstract class PrinterDiscoverySession {
* @see #removePrinters(List)
* @see #isPrinterDiscoveryStarted()
*/
- public abstract void onStartPrinterDiscovery(List priorityList);
+ public abstract void onStartPrinterDiscovery(@NonNull List priorityList);
/**
* Callback notifying you that you should stop printer discovery.
@@ -373,10 +373,10 @@ public abstract class PrinterDiscoverySession {
*
* @param printerIds The printers to validate.
*
- * @see PrinterInfo.Builder#setCapabilities(PrinterCapabilitiesInfo)
+ * @see android.print.PrinterInfo.Builder#setCapabilities(PrinterCapabilitiesInfo)
* PrinterInfo.Builder.setCapabilities(PrinterCapabilitiesInfo)
*/
- public abstract void onValidatePrinters(List printerIds);
+ public abstract void onValidatePrinters(@NonNull List printerIds);
/**
* Callback asking you to start tracking the state of a printer. Tracking
@@ -401,10 +401,10 @@ public abstract class PrinterDiscoverySession {
* @param printerId The printer to start tracking.
*
* @see #onStopPrinterStateTracking(PrinterId)
- * @see PrinterInfo.Builder#setCapabilities(PrinterCapabilitiesInfo)
+ * @see android.print.PrinterInfo.Builder#setCapabilities(PrinterCapabilitiesInfo)
* PrinterInfo.Builder.setCapabilities(PrinterCapabilitiesInfo)
*/
- public abstract void onStartPrinterStateTracking(PrinterId printerId);
+ public abstract void onStartPrinterStateTracking(@NonNull PrinterId printerId);
/**
* Request the custom icon for a printer. Once the icon is available use
@@ -429,7 +429,7 @@ public abstract class PrinterDiscoverySession {
*
* @see #onStartPrinterStateTracking(PrinterId)
*/
- public abstract void onStopPrinterStateTracking(PrinterId printerId);
+ public abstract void onStopPrinterStateTracking(@NonNull PrinterId printerId);
/**
* Gets the printers that should be tracked. These are printers that are
@@ -449,7 +449,7 @@ public abstract class PrinterDiscoverySession {
* @see #onStopPrinterStateTracking(PrinterId)
* @see #isDestroyed()
*/
- public final List getTrackedPrinters() {
+ public final @NonNull List getTrackedPrinters() {
PrintService.throwIfNotCalledOnMainThread();
if (mIsDestroyed) {
return Collections.emptyList();
@@ -491,7 +491,7 @@ public abstract class PrinterDiscoverySession {
return mIsDiscoveryStarted;
}
- void startPrinterDiscovery(List priorityList) {
+ void startPrinterDiscovery(@NonNull List priorityList) {
if (!mIsDestroyed) {
mIsDiscoveryStarted = true;
sendOutOfDiscoveryPeriodPrinterChanges();
@@ -509,13 +509,13 @@ public abstract class PrinterDiscoverySession {
}
}
- void validatePrinters(List printerIds) {
+ void validatePrinters(@NonNull List printerIds) {
if (!mIsDestroyed && mObserver != null) {
onValidatePrinters(printerIds);
}
}
- void startPrinterStateTracking(PrinterId printerId) {
+ void startPrinterStateTracking(@NonNull PrinterId printerId) {
if (!mIsDestroyed && mObserver != null
&& !mTrackedPrinters.contains(printerId)) {
mTrackedPrinters.add(printerId);
@@ -529,7 +529,7 @@ public abstract class PrinterDiscoverySession {
* @param printerId The printer to icon belongs to.
* @see android.print.PrinterInfo.Builder#setHasCustomPrinterIcon()
*/
- void requestCustomPrinterIcon(PrinterId printerId) {
+ void requestCustomPrinterIcon(@NonNull PrinterId printerId) {
if (!mIsDestroyed && mObserver != null) {
CustomPrinterIconCallback callback = new CustomPrinterIconCallback(printerId,
mObserver);
@@ -537,7 +537,7 @@ public abstract class PrinterDiscoverySession {
}
}
- void stopPrinterStateTracking(PrinterId printerId) {
+ void stopPrinterStateTracking(@NonNull PrinterId printerId) {
if (!mIsDestroyed && mObserver != null
&& mTrackedPrinters.remove(printerId)) {
onStopPrinterStateTracking(printerId);
diff --git a/packages/PrintSpooler/AndroidManifest.xml b/packages/PrintSpooler/AndroidManifest.xml
index 5a6f1d1f1a311..937eb157268c7 100644
--- a/packages/PrintSpooler/AndroidManifest.xml
+++ b/packages/PrintSpooler/AndroidManifest.xml
@@ -17,9 +17,7 @@
*/
-->
+ package="com.android.printspooler">
diff --git a/packages/PrintSpooler/src/com/android/printspooler/model/PrintSpoolerService.java b/packages/PrintSpooler/src/com/android/printspooler/model/PrintSpoolerService.java
index e160f83198604..496a0b09b905d 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/model/PrintSpoolerService.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/model/PrintSpoolerService.java
@@ -1303,7 +1303,7 @@ public final class PrintSpoolerService extends Service {
}
private void expect(XmlPullParser parser, int type, String tag)
- throws IOException, XmlPullParserException {
+ throws XmlPullParserException {
if (!accept(parser, type, tag)) {
throw new XmlPullParserException("Exepected event: " + type
+ " and tag: " + tag + " but got event: " + parser.getEventType()
@@ -1320,7 +1320,7 @@ public final class PrintSpoolerService extends Service {
}
private boolean accept(XmlPullParser parser, int type, String tag)
- throws IOException, XmlPullParserException {
+ throws XmlPullParserException {
if (parser.getEventType() != type) {
return false;
}
diff --git a/packages/PrintSpooler/src/com/android/printspooler/model/RemotePrintDocument.java b/packages/PrintSpooler/src/com/android/printspooler/model/RemotePrintDocument.java
index 1b6e9ce2db370..ea11ae40aea87 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/model/RemotePrintDocument.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/model/RemotePrintDocument.java
@@ -870,7 +870,7 @@ public final class RemotePrintDocument {
private final MutexFileProvider mFileProvider;
private final IWriteResultCallback mRemoteResultCallback;
- private final CommandDoneCallback mDoneCallback;
+ private final CommandDoneCallback mWriteDoneCallback;
private final Context mContext;
private final Handler mHandler;
@@ -885,7 +885,7 @@ public final class RemotePrintDocument {
mPageCount = pageCount;
mPages = Arrays.copyOf(pages, pages.length);
mFileProvider = fileProvider;
- mDoneCallback = callback;
+ mWriteDoneCallback = callback;
}
@Override
@@ -997,7 +997,7 @@ public final class RemotePrintDocument {
mCancellation = null;
// Done.
- mDoneCallback.onDone();
+ mWriteDoneCallback.onDone();
}
private void handleOnWriteFailed(CharSequence error, int sequence) {
@@ -1015,7 +1015,7 @@ public final class RemotePrintDocument {
mCancellation = null;
// Done.
- mDoneCallback.onDone();
+ mWriteDoneCallback.onDone();
}
private void handleOnWriteCanceled(int sequence) {
@@ -1033,7 +1033,7 @@ public final class RemotePrintDocument {
mCancellation = null;
// Done.
- mDoneCallback.onDone();
+ mWriteDoneCallback.onDone();
}
private final class WriteHandler extends Handler {
diff --git a/packages/PrintSpooler/src/com/android/printspooler/ui/FusedPrintersProvider.java b/packages/PrintSpooler/src/com/android/printspooler/ui/FusedPrintersProvider.java
index 733dd42a448f4..c3c118ac943d8 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/ui/FusedPrintersProvider.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/ui/FusedPrintersProvider.java
@@ -668,7 +668,7 @@ public final class FusedPrintersProvider extends Loader> {
}
private void expect(XmlPullParser parser, int type, String tag)
- throws IOException, XmlPullParserException {
+ throws XmlPullParserException {
if (!accept(parser, type, tag)) {
throw new XmlPullParserException("Exepected event: " + type
+ " and tag: " + tag + " but got event: " + parser.getEventType()
@@ -685,7 +685,7 @@ public final class FusedPrintersProvider extends Loader> {
}
private boolean accept(XmlPullParser parser, int type, String tag)
- throws IOException, XmlPullParserException {
+ throws XmlPullParserException {
if (parser.getEventType() != type) {
return false;
}
@@ -702,7 +702,8 @@ public final class FusedPrintersProvider extends Loader> {
private final class WriteTask extends AsyncTask, Void, Void> {
@Override
- protected Void doInBackground(List... printers) {
+ protected Void doInBackground(
+ @SuppressWarnings("unchecked") List... printers) {
doWritePrinterHistory(printers[0]);
return null;
}
diff --git a/packages/PrintSpooler/src/com/android/printspooler/ui/PageAdapter.java b/packages/PrintSpooler/src/com/android/printspooler/ui/PageAdapter.java
index 2757b816db409..606f4eb79c2e9 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/ui/PageAdapter.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/ui/PageAdapter.java
@@ -52,7 +52,7 @@ import java.util.List;
/**
* This class represents the adapter for the pages in the print preview list.
*/
-public final class PageAdapter extends Adapter {
+public final class PageAdapter extends Adapter {
private static final String LOG_TAG = "PageAdapter";
private static final int MAX_PREVIEW_PAGES_BATCH = 50;
@@ -409,7 +409,7 @@ public final class PageAdapter extends Adapter {
- horizontalPaddingAndMargins) / columnCount) + 0.5f);
// Compute max page height.
- final int pageContentDesiredHeight = (int) (((float) pageContentDesiredWidth
+ final int pageContentDesiredHeight = (int) ((pageContentDesiredWidth
/ pageAspectRatio) + 0.5f);
// If the page does not fit entirely in a vertical direction,
diff --git a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java
index 3ca07b5a5080c..9c1cf645320d2 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java
@@ -461,6 +461,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
}
}
+ @Override
public void onUpdateCanceled() {
if (DEBUG) {
Log.i(LOG_TAG, "onUpdateCanceled()");
@@ -1737,8 +1738,9 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
}
private void updatePageRangeOptions(int pageCount) {
+ @SuppressWarnings("unchecked")
ArrayAdapter> rangeOptionsSpinnerAdapter =
- (ArrayAdapter) mRangeOptionsSpinner.getAdapter();
+ (ArrayAdapter>) mRangeOptionsSpinner.getAdapter();
rangeOptionsSpinnerAdapter.clear();
final int[] rangeOptionsValues = getResources().getIntArray(
@@ -1927,6 +1929,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
this.label = label;
}
+ @Override
public String toString() {
return label.toString();
}
@@ -2186,7 +2189,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
if (position == 0 && getPdfPrinter() != null) {
PrinterHolder printerHolder = (PrinterHolder) getItem(position);
title = printerHolder.printer.getName();
- icon = getResources().getDrawable(R.drawable.ic_menu_savetopdf);
+ icon = getResources().getDrawable(R.drawable.ic_menu_savetopdf, null);
} else if (position == 1) {
title = getString(R.string.all_printers);
}
@@ -2194,7 +2197,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
if (position == 1 && getPdfPrinter() != null) {
PrinterHolder printerHolder = (PrinterHolder) getItem(position);
title = printerHolder.printer.getName();
- icon = getResources().getDrawable(R.drawable.ic_menu_savetopdf);
+ icon = getResources().getDrawable(R.drawable.ic_menu_savetopdf, null);
} else if (position == getCount() - 1) {
title = getString(R.string.all_printers);
} else {
diff --git a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintPreviewController.java b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintPreviewController.java
index 8716fd21cdb84..ce54204ef870b 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintPreviewController.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintPreviewController.java
@@ -78,8 +78,8 @@ class PrintPreviewController implements MutexFileProvider.OnReleaseRequestCallba
mRecyclerView.setLayoutManager(mLayoutManger);
mRecyclerView.setAdapter(mPageAdapter);
mRecyclerView.setItemViewCacheSize(0);
- mPreloadController = new PreloadController(mRecyclerView);
- mRecyclerView.setOnScrollListener(mPreloadController);
+ mPreloadController = new PreloadController();
+ mRecyclerView.addOnScrollListener(mPreloadController);
mContentView = (PrintContentView) activity.findViewById(R.id.options_content);
mEmbeddedContentContainer = (EmbeddedContentContainer) activity.findViewById(
@@ -314,12 +314,9 @@ class PrintPreviewController implements MutexFileProvider.OnReleaseRequestCallba
}
private final class PreloadController extends RecyclerView.OnScrollListener {
- private final RecyclerView mRecyclerView;
-
private int mOldScrollState;
- public PreloadController(RecyclerView recyclerView) {
- mRecyclerView = recyclerView;
+ public PreloadController() {
mOldScrollState = mRecyclerView.getScrollState();
}
@@ -371,7 +368,8 @@ class PrintPreviewController implements MutexFileProvider.OnReleaseRequestCallba
View lastChild = layoutManager.getChildAt(layoutManager.getChildCount() - 1);
ViewHolder lastHolder = mRecyclerView.getChildViewHolder(lastChild);
- return new PageRange(firstHolder.getPosition(), lastHolder.getPosition());
+ return new PageRange(firstHolder.getLayoutPosition(),
+ lastHolder.getLayoutPosition());
}
return null;
}
diff --git a/packages/PrintSpooler/src/com/android/printspooler/widget/PrintContentView.java b/packages/PrintSpooler/src/com/android/printspooler/widget/PrintContentView.java
index e6613faebae56..0bb4bfa185138 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/widget/PrintContentView.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/widget/PrintContentView.java
@@ -415,6 +415,7 @@ public final class PrintContentView extends ViewGroup implements View.OnClickLis
onDragProgress(progress);
}
+ @Override
public void onViewReleased(View child, float velocityX, float velocityY) {
final int childTop = child.getTop();
@@ -435,14 +436,17 @@ public final class PrintContentView extends ViewGroup implements View.OnClickLis
invalidate();
}
+ @Override
public int getOrderedChildIndex(int index) {
return getChildCount() - index - 1;
}
+ @Override
public int getViewVerticalDragRange(View child) {
return mDraggableContent.getHeight();
}
+ @Override
public int clampViewPositionVertical(View child, int top, int dy) {
final int staticOptionBottom = mStaticContent.getBottom();
return Math.max(Math.min(top, getOpenedOptionsY()), getClosedOptionsY());