diff options
author | Philip P. Moltmann <moltmann@google.com> | 2018-02-21 13:59:47 -0800 |
---|---|---|
committer | Philip P. Moltmann <moltmann@google.com> | 2018-02-21 14:40:17 -0800 |
commit | e65a9b8ebe464c52c565802a4a24232cc108dffe (patch) | |
tree | 469c9ca5e63a4faf6b9c402e51ede382eaf4ff25 | |
parent | 9131b2f1c833270096e85744fbf14e3a2e6af85b (diff) |
Create print job when print activity starts
This guarantees that the print job is created before the print activity
deals with it.
Test: CtsPrintTestCases
Change-Id: I3451fff71bd981beb45882b7b42d4cc49d63a91c
Fixes: 73127052
3 files changed, 19 insertions, 24 deletions
diff --git a/packages/PrintSpooler/src/com/android/printspooler/model/PrintSpoolerProvider.java b/packages/PrintSpooler/src/com/android/printspooler/model/PrintSpoolerProvider.java index 06723c33814d..24449fd393a0 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/model/PrintSpoolerProvider.java +++ b/packages/PrintSpooler/src/com/android/printspooler/model/PrintSpoolerProvider.java @@ -16,6 +16,8 @@ package com.android.printspooler.model; +import static android.content.Context.BIND_AUTO_CREATE; + import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -32,7 +34,7 @@ public class PrintSpoolerProvider implements ServiceConnection { mContext = context; mCallback = callback; Intent intent = new Intent(mContext, PrintSpoolerService.class); - mContext.bindService(intent, this, 0); + mContext.bindService(intent, this, BIND_AUTO_CREATE); } public PrintSpoolerService getSpooler() { diff --git a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java index d73a5d73e5bf..83d7e1666809 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java +++ b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java @@ -306,19 +306,22 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat // This will take just a few milliseconds, so just wait to // bind to the local service before showing the UI. mSpoolerProvider = new PrintSpoolerProvider(this, - new Runnable() { - @Override - public void run() { - if (isFinishing() || isDestroyed()) { - // onPause might have not been able to cancel the job, see PrintActivity#onPause - // To be sure, cancel the job again. Double canceling does no harm. - mSpoolerProvider.getSpooler().setPrintJobState(mPrintJob.getId(), - PrintJobInfo.STATE_CANCELED, null); - } else { - onConnectedToPrintSpooler(adapter); - } - } - }); + () -> { + if (isFinishing() || isDestroyed()) { + if (savedInstanceState != null) { + // onPause might have not been able to cancel the job, see + // PrintActivity#onPause + // To be sure, cancel the job again. Double canceling does no harm. + mSpoolerProvider.getSpooler().setPrintJobState(mPrintJob.getId(), + PrintJobInfo.STATE_CANCELED, null); + } + } else { + if (savedInstanceState == null) { + mSpoolerProvider.getSpooler().createPrintJob(mPrintJob); + } + onConnectedToPrintSpooler(adapter); + } + }); getLoaderManager().initLoader(LOADER_ID_ENABLED_PRINT_SERVICES, null, this); } diff --git a/services/print/java/com/android/server/print/UserState.java b/services/print/java/com/android/server/print/UserState.java index 84c1bb272b5a..3c09cb193af3 100644 --- a/services/print/java/com/android/server/print/UserState.java +++ b/services/print/java/com/android/server/print/UserState.java @@ -38,7 +38,6 @@ import android.content.pm.ParceledListSlice; import android.content.pm.ResolveInfo; import android.graphics.drawable.Icon; import android.net.Uri; -import android.os.AsyncTask; import android.os.Binder; import android.os.Bundle; import android.os.Handler; @@ -236,15 +235,6 @@ final class UserState implements PrintSpoolerCallbacks, PrintServiceCallbacks, return null; } - // Spin the spooler to add the job and show the config UI. - new AsyncTask<Void, Void, Void>() { - @Override - protected Void doInBackground(Void... params) { - mSpooler.createPrintJob(printJob); - return null; - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null); - final long identity = Binder.clearCallingIdentity(); try { Intent intent = new Intent(PrintManager.ACTION_PRINT_DIALOG); |