From d365f695d2941c4fc7e550d4498006a5012a32f5 Mon Sep 17 00:00:00 2001 From: "Philip P. Moltmann" Date: Mon, 29 Feb 2016 13:06:14 -0800 Subject: [PATCH] Fix three bugs in the handling of the advanced options activity - The selected pages is not stored in the print job. But this is used to communicate with the advanced options activity. Hence patch it up before sending it out. - If no media size is set in the returned attributes, do not try to get the portait size of this null-media size - The copies can be 0 if the PrintJobInfo was created via PrintJobInfo.Builder() Change-Id: Ic75c1db0cd5ffad663d87913dfe23e3f5a729bbf --- .../printspooler/ui/PrintActivity.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java index 64f5cc62201ec..4b62f24754566 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java +++ b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java @@ -731,7 +731,10 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat // The activity is a component name, therefore it is one or none. if (resolvedActivities.get(0).activityInfo.exported) { - intent.putExtra(PrintService.EXTRA_PRINT_JOB_INFO, mPrintJob); + PrintJobInfo.Builder printJobBuilder = new PrintJobInfo.Builder(mPrintJob); + printJobBuilder.setPages(mSelectedPages); + + intent.putExtra(PrintService.EXTRA_PRINT_JOB_INFO, printJobBuilder.build()); intent.putExtra(PrintService.EXTRA_PRINTER_INFO, printer); intent.putExtra(PrintService.EXTRA_PRINT_DOCUMENT_INFO, mPrintedDocument.getDocumentInfo().info); @@ -759,10 +762,14 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat // Take the advanced options without interpretation. mPrintJob.setAdvancedOptions(printJobInfo.getAdvancedOptions()); - // Take copies without interpretation as the advanced print dialog - // cannot create a print job info with invalid copies. - mCopiesEditText.setText(String.valueOf(printJobInfo.getCopies())); - mPrintJob.setCopies(printJobInfo.getCopies()); + if (printJobInfo.getCopies() < 1) { + Log.w(LOG_TAG, "Cannot apply return value from advanced options activity. Copies " + + "must be 1 or more. Actual value is: " + printJobInfo.getCopies() + ". " + + "Ignoring."); + } else { + mCopiesEditText.setText(String.valueOf(printJobInfo.getCopies())); + mPrintJob.setCopies(printJobInfo.getCopies()); + } PrintAttributes currAttributes = mPrintJob.getAttributes(); PrintAttributes newAttributes = printJobInfo.getAttributes(); @@ -771,7 +778,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat // Take the media size only if the current printer supports is. MediaSize oldMediaSize = currAttributes.getMediaSize(); MediaSize newMediaSize = newAttributes.getMediaSize(); - if (!oldMediaSize.equals(newMediaSize)) { + if (newMediaSize != null && !oldMediaSize.equals(newMediaSize)) { final int mediaSizeCount = mMediaSizeSpinnerAdapter.getCount(); MediaSize newMediaSizePortrait = newAttributes.getMediaSize().asPortrait(); for (int i = 0; i < mediaSizeCount; i++) {