diff options
author | Philip P. Moltmann <moltmann@google.com> | 2017-03-24 16:17:13 -0700 |
---|---|---|
committer | Philip P. Moltmann <moltmann@google.com> | 2017-03-29 16:13:32 +0000 |
commit | d0e44c5ee32976b24b9b1377d9ece94a59db7df5 (patch) | |
tree | 621f9a9daef34cffbbce4b6c6a3f3311d1837ded /packages/PrintSpooler/src | |
parent | 1af2928767af7ffd95ce61946b95a7b5ef877bd5 (diff) |
Do not allow printing until preview is updated
Otherwise we might end up in the situation where we print something that
was not previewed.
This is of course bad for the user as he prints something he has not seen.
It is also bad for the print spooler as in the case the layout did not
describe the amount of pages, we do not know the number of pages available
until the update is complete.
We now allow changing of printer at any time unless printing is in final
stage. If we don't allow this the changing of printer would be blocked
until the intial document was written which might take some time.
Fixes: 36599750
Test: cts-tradefed run cts-dev -m Print
Change-Id: I93e910c02f2a770008b845028f0adf17b3d410e2
(cherry picked from commit 378cddbc41dae55e9a11faaa251b80fb90878b34)
Diffstat (limited to 'packages/PrintSpooler/src')
-rw-r--r-- | packages/PrintSpooler/src/com/android/printspooler/model/RemotePrintDocument.java | 6 | ||||
-rw-r--r-- | packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java | 23 |
2 files changed, 11 insertions, 18 deletions
diff --git a/packages/PrintSpooler/src/com/android/printspooler/model/RemotePrintDocument.java b/packages/PrintSpooler/src/com/android/printspooler/model/RemotePrintDocument.java index 187e35ac842c..f11a9cde9520 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/model/RemotePrintDocument.java +++ b/packages/PrintSpooler/src/com/android/printspooler/model/RemotePrintDocument.java @@ -113,12 +113,14 @@ public final class RemotePrintDocument { } // Notify we are done. mState = STATE_UPDATED; + mDocumentInfo.updated = true; notifyUpdateCompleted(); } } } else { // We always notify after a write. mState = STATE_UPDATED; + mDocumentInfo.updated = true; notifyUpdateCompleted(); } runPendingCommand(); @@ -229,6 +231,7 @@ public final class RemotePrintDocument { mDocumentInfo, oldAttributes, attributes, preview, mCommandResultCallback); scheduleCommand(command); + mDocumentInfo.updated = false; mState = STATE_UPDATING; // If no layout in progress and we don't have all pages - schedule a write. } else if ((!(mCurrentCommand instanceof LayoutCommand) @@ -249,6 +252,7 @@ public final class RemotePrintDocument { mDocumentInfo.fileProvider, mCommandResultCallback); scheduleCommand(command); + mDocumentInfo.updated = false; mState = STATE_UPDATING; } else { willUpdate = false; @@ -396,7 +400,7 @@ public final class RemotePrintDocument { private void notifyUpdateFailed(CharSequence error) { if (DEBUG) { - Log.i(LOG_TAG, "[CALLING] onUpdateCompleted()"); + Log.i(LOG_TAG, "[CALLING] notifyUpdateFailed()"); } mUpdateCallbacks.onUpdateFailed(error); } diff --git a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java index f6df9953bf0f..4cce166db645 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java +++ b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java @@ -491,8 +491,6 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat setState(STATE_UPDATE_FAILED); - updateOptionsUi(); - mPrintedDocument.kill(message); } @@ -502,7 +500,6 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat && canUpdateDocument() && updateDocument(true)) { ensurePreviewUiShown(); setState(STATE_CONFIGURING); - updateOptionsUi(); } } @@ -579,7 +576,6 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat updatePrintPreviewController(document.changed); setState(STATE_CONFIGURING); - updateOptionsUi(); } break; } } @@ -600,8 +596,6 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat } setState(STATE_UPDATE_FAILED); - - updateOptionsUi(); } @Override @@ -734,7 +728,6 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat updateOptionsUi(); } else { setState(STATE_CREATE_FILE_FAILED); - updateOptionsUi(); // Calling finish here does not invoke lifecycle callbacks but we // update the print job in onPause if finishing, hence post a message. mDestinationSpinner.post(new Runnable() { @@ -958,12 +951,14 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat Log.i(LOG_TAG, "[state]" + state); } mState = state; + updateOptionsUi(); } } else { if (DEBUG) { Log.i(LOG_TAG, "[state]" + state); } mState = state; + updateOptionsUi(); } } @@ -1230,6 +1225,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat final boolean willUpdate = mPrintedDocument.update(mPrintJob.getAttributes(), pages, preview); + updateOptionsUi(); if (willUpdate && !mPrintedDocument.hasLaidOutPages()) { // When the update is done we update the print preview. @@ -1254,7 +1250,6 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat private void cancelPrint() { setState(STATE_PRINT_CANCELED); - updateOptionsUi(); mPrintedDocument.cancel(true); doFinish(); } @@ -1274,7 +1269,6 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat private void confirmPrint() { setState(STATE_PRINT_CONFIRMED); - updateOptionsUi(); addCurrentPrinterToHistory(); setUserPrinted(); @@ -1629,6 +1623,8 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat // Always update the summary. updateSummary(); + mDestinationSpinner.setEnabled(!isFinalState(mState)); + if (mState == STATE_PRINT_CONFIRMED || mState == STATE_PRINT_COMPLETED || mState == STATE_PRINT_CANCELED @@ -1636,9 +1632,6 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat || mState == STATE_CREATE_FILE_FAILED || mState == STATE_PRINTER_UNAVAILABLE || mState == STATE_UPDATE_SLOW) { - if (mState != STATE_PRINTER_UNAVAILABLE) { - mDestinationSpinner.setEnabled(false); - } disableOptionsUi(isFinalState(mState)); return; } @@ -1927,7 +1920,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat mPrintButton.setImageResource(R.drawable.ic_menu_savetopdf); mPrintButton.setContentDescription(getString(R.string.savetopdf_button)); } - if (!mPrintedDocument.getDocumentInfo().laidout + if (!mPrintedDocument.getDocumentInfo().updated ||(mRangeOptionsSpinner.getSelectedItemPosition() == 1 && (TextUtils.isEmpty(mPageRangeEditText.getText()) || hasErrors())) || (mRangeOptionsSpinner.getSelectedItemPosition() == 0 @@ -2048,7 +2041,6 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat updateDocument(false); } ensurePreviewUiShown(); - updateOptionsUi(); } } @@ -2058,7 +2050,6 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat mPrintedDocument.cancel(false); ensureErrorUiShown(getString(R.string.print_error_printer_unavailable), PrintErrorFragment.ACTION_NONE); - updateOptionsUi(); } } @@ -3038,7 +3029,6 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat if (mState == STATE_UPDATE_SLOW) { setState(STATE_UPDATE_SLOW); ensureProgressUiShown(); - updateOptionsUi(); return; } else if (mPosted) { @@ -3080,7 +3070,6 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat mPreviousState = mState; setState(STATE_UPDATE_SLOW); ensureProgressUiShown(); - updateOptionsUi(); } } |