OSDN Git Service

Fix print document with zero pages backwards compatibility.
authorSvetoslav <svetoslavganov@google.com>
Fri, 11 Jul 2014 00:36:27 +0000 (17:36 -0700)
committerSvetoslav Ganov <svetoslavganov@google.com>
Fri, 11 Jul 2014 00:43:28 +0000 (00:43 +0000)
Historically, we were allowing an app that prints to specify that
the printed document has zero pages. While this does not make any
sense we should keep the behavior as people may have apps that do
that. This change fixes this issue and now we treat zero the same
way as undefined page count and ask the app to write all pages to
check the written PDF for the page count.

bug:16199127

Change-Id: I4e7de66b669e9f783db0252244a6c1e5b24ffe28

core/java/android/print/PrintDocumentInfo.java

index 928be6c..e4e753e 100644 (file)
@@ -308,7 +308,7 @@ public final class PrintDocumentInfo implements Parcelable {
         public Builder setPageCount(int pageCount) {
             if (pageCount < 0 && pageCount != PAGE_COUNT_UNKNOWN) {
                 throw new IllegalArgumentException("pageCount"
-                        + " must be greater than or euqal to zero or"
+                        + " must be greater than or equal to zero or"
                         + " DocumentInfo#PAGE_COUNT_UNKNOWN");
             }
             mPrototype.mPageCount = pageCount;
@@ -338,6 +338,12 @@ public final class PrintDocumentInfo implements Parcelable {
          * @return The new instance.
          */
         public 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.
+            if (mPrototype.mPageCount == 0) {
+                mPrototype.mPageCount = PAGE_COUNT_UNKNOWN;
+            }
             return new PrintDocumentInfo(mPrototype);
         }
     }