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
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user