am c9f499d2: Merge "Print spooler crash when printing after a rotation." into lmp-mr1-dev
* commit 'c9f499d2f1cd598b90bfb8c13e505354555caea8': Print spooler crash when printing after a rotation.
This commit is contained in:
@@ -412,6 +412,8 @@ public final class PageContentRepository {
|
|||||||
@GuardedBy("mLock")
|
@GuardedBy("mLock")
|
||||||
private IPdfRenderer mRenderer;
|
private IPdfRenderer mRenderer;
|
||||||
|
|
||||||
|
private OpenTask mOpenTask;
|
||||||
|
|
||||||
private boolean mBoundToService;
|
private boolean mBoundToService;
|
||||||
private boolean mDestroyed;
|
private boolean mDestroyed;
|
||||||
|
|
||||||
@@ -439,75 +441,15 @@ public final class PageContentRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void open(final ParcelFileDescriptor source, final OpenDocumentCallback callback) {
|
public void open(ParcelFileDescriptor source, OpenDocumentCallback callback) {
|
||||||
// Opening a new document invalidates the cache as it has pages
|
// Opening a new document invalidates the cache as it has pages
|
||||||
// from the last document. We keep the cache even when the document
|
// from the last document. We keep the cache even when the document
|
||||||
// is closed to show pages while the other side is writing the new
|
// is closed to show pages while the other side is writing the new
|
||||||
// document.
|
// document.
|
||||||
mPageContentCache.invalidate();
|
mPageContentCache.invalidate();
|
||||||
|
|
||||||
new AsyncTask<Void, Void, Integer>() {
|
mOpenTask = new OpenTask(source, callback);
|
||||||
@Override
|
mOpenTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||||
protected void onPreExecute() {
|
|
||||||
if (mDestroyed) {
|
|
||||||
cancel(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Intent intent = new Intent(PdfManipulationService.ACTION_GET_RENDERER);
|
|
||||||
intent.setClass(mContext, PdfManipulationService.class);
|
|
||||||
intent.setData(Uri.fromParts("fake-scheme", String.valueOf(
|
|
||||||
AsyncRenderer.this.hashCode()), null));
|
|
||||||
mContext.bindService(intent, AsyncRenderer.this, Context.BIND_AUTO_CREATE);
|
|
||||||
mBoundToService = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Integer doInBackground(Void... params) {
|
|
||||||
synchronized (mLock) {
|
|
||||||
while (mRenderer == null) {
|
|
||||||
try {
|
|
||||||
mLock.wait();
|
|
||||||
} catch (InterruptedException ie) {
|
|
||||||
/* ignore */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return mRenderer.openDocument(source);
|
|
||||||
} catch (RemoteException re) {
|
|
||||||
Log.e(LOG_TAG, "Cannot open PDF document");
|
|
||||||
return PdfManipulationService.ERROR_MALFORMED_PDF_FILE;
|
|
||||||
} finally {
|
|
||||||
// Close the fd as we passed it to another process
|
|
||||||
// which took ownership.
|
|
||||||
IoUtils.closeQuietly(source);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPostExecute(Integer pageCount) {
|
|
||||||
switch (pageCount) {
|
|
||||||
case PdfManipulationService.ERROR_MALFORMED_PDF_FILE: {
|
|
||||||
mPageCount = PrintDocumentInfo.PAGE_COUNT_UNKNOWN;
|
|
||||||
if (callback != null) {
|
|
||||||
callback.onFailure(OpenDocumentCallback.ERROR_MALFORMED_PDF_FILE);
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
case PdfManipulationService.ERROR_SECURE_PDF_FILE: {
|
|
||||||
mPageCount = PrintDocumentInfo.PAGE_COUNT_UNKNOWN;
|
|
||||||
if (callback != null) {
|
|
||||||
callback.onFailure(OpenDocumentCallback.ERROR_SECURE_PDF_FILE);
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
default: {
|
|
||||||
mPageCount = pageCount;
|
|
||||||
if (callback != null) {
|
|
||||||
callback.onSuccess();
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close(final Runnable callback) {
|
public void close(final Runnable callback) {
|
||||||
@@ -549,6 +491,11 @@ public final class PageContentRepository {
|
|||||||
mBoundToService = false;
|
mBoundToService = false;
|
||||||
mContext.unbindService(AsyncRenderer.this);
|
mContext.unbindService(AsyncRenderer.this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mOpenTask != null) {
|
||||||
|
mOpenTask.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
mPageContentCache.invalidate();
|
mPageContentCache.invalidate();
|
||||||
mPageContentCache.clear();
|
mPageContentCache.clear();
|
||||||
mDestroyed = true;
|
mDestroyed = true;
|
||||||
@@ -687,6 +634,91 @@ public final class PageContentRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final class OpenTask extends AsyncTask<Void, Void, Integer> {
|
||||||
|
private final ParcelFileDescriptor mSource;
|
||||||
|
private final OpenDocumentCallback mCallback;
|
||||||
|
|
||||||
|
public OpenTask(ParcelFileDescriptor source, OpenDocumentCallback callback) {
|
||||||
|
mSource = source;
|
||||||
|
mCallback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
if (mDestroyed) {
|
||||||
|
cancel(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Intent intent = new Intent(PdfManipulationService.ACTION_GET_RENDERER);
|
||||||
|
intent.setClass(mContext, PdfManipulationService.class);
|
||||||
|
intent.setData(Uri.fromParts("fake-scheme", String.valueOf(
|
||||||
|
AsyncRenderer.this.hashCode()), null));
|
||||||
|
mContext.bindService(intent, AsyncRenderer.this, Context.BIND_AUTO_CREATE);
|
||||||
|
mBoundToService = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Integer doInBackground(Void... params) {
|
||||||
|
synchronized (mLock) {
|
||||||
|
while (mRenderer == null && !isCancelled()) {
|
||||||
|
try {
|
||||||
|
mLock.wait();
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return mRenderer.openDocument(mSource);
|
||||||
|
} catch (RemoteException re) {
|
||||||
|
Log.e(LOG_TAG, "Cannot open PDF document");
|
||||||
|
return PdfManipulationService.ERROR_MALFORMED_PDF_FILE;
|
||||||
|
} finally {
|
||||||
|
// Close the fd as we passed it to another process
|
||||||
|
// which took ownership.
|
||||||
|
IoUtils.closeQuietly(mSource);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPostExecute(Integer pageCount) {
|
||||||
|
switch (pageCount) {
|
||||||
|
case PdfManipulationService.ERROR_MALFORMED_PDF_FILE: {
|
||||||
|
mPageCount = PrintDocumentInfo.PAGE_COUNT_UNKNOWN;
|
||||||
|
if (mCallback != null) {
|
||||||
|
mCallback.onFailure(OpenDocumentCallback.ERROR_MALFORMED_PDF_FILE);
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case PdfManipulationService.ERROR_SECURE_PDF_FILE: {
|
||||||
|
mPageCount = PrintDocumentInfo.PAGE_COUNT_UNKNOWN;
|
||||||
|
if (mCallback != null) {
|
||||||
|
mCallback.onFailure(OpenDocumentCallback.ERROR_SECURE_PDF_FILE);
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
default: {
|
||||||
|
mPageCount = pageCount;
|
||||||
|
if (mCallback != null) {
|
||||||
|
mCallback.onSuccess();
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
}
|
||||||
|
|
||||||
|
mOpenTask = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCancelled(Integer integer) {
|
||||||
|
mOpenTask = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancel() {
|
||||||
|
cancel(true);
|
||||||
|
synchronized(mLock) {
|
||||||
|
mLock.notifyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private final class RenderPageTask extends AsyncTask<Void, Void, RenderedPage> {
|
private final class RenderPageTask extends AsyncTask<Void, Void, RenderedPage> {
|
||||||
final int mPageIndex;
|
final int mPageIndex;
|
||||||
final RenderSpec mRenderSpec;
|
final RenderSpec mRenderSpec;
|
||||||
|
|||||||
@@ -346,7 +346,6 @@ public final class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
|
|||||||
private List<PrinterInfo> mHistoricalPrinters = new ArrayList<>();
|
private List<PrinterInfo> mHistoricalPrinters = new ArrayList<>();
|
||||||
|
|
||||||
private boolean mReadHistoryCompleted;
|
private boolean mReadHistoryCompleted;
|
||||||
private boolean mReadHistoryInProgress;
|
|
||||||
|
|
||||||
private ReadTask mReadTask;
|
private ReadTask mReadTask;
|
||||||
|
|
||||||
@@ -358,7 +357,7 @@ public final class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isReadHistoryInProgress() {
|
public boolean isReadHistoryInProgress() {
|
||||||
return mReadHistoryInProgress;
|
return mReadTask != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isReadHistoryCompleted() {
|
public boolean isReadHistoryCompleted() {
|
||||||
@@ -366,9 +365,7 @@ public final class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean stopReadPrinterHistory() {
|
public boolean stopReadPrinterHistory() {
|
||||||
final boolean cancelled = mReadTask.cancel(true);
|
return mReadTask.cancel(true);
|
||||||
mReadTask = null;
|
|
||||||
return cancelled;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readPrinterHistory() {
|
public void readPrinterHistory() {
|
||||||
@@ -376,7 +373,6 @@ public final class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
|
|||||||
Log.i(LOG_TAG, "read history started "
|
Log.i(LOG_TAG, "read history started "
|
||||||
+ FusedPrintersProvider.this.hashCode());
|
+ FusedPrintersProvider.this.hashCode());
|
||||||
}
|
}
|
||||||
mReadHistoryInProgress = true;
|
|
||||||
mReadTask = new ReadTask();
|
mReadTask = new ReadTask();
|
||||||
mReadTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, (Void[]) null);
|
mReadTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, (Void[]) null);
|
||||||
}
|
}
|
||||||
@@ -534,15 +530,20 @@ public final class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
|
|||||||
mFavoritePrinters.clear();
|
mFavoritePrinters.clear();
|
||||||
mFavoritePrinters.addAll(computeFavoritePrinters(mHistoricalPrinters));
|
mFavoritePrinters.addAll(computeFavoritePrinters(mHistoricalPrinters));
|
||||||
|
|
||||||
mReadHistoryInProgress = false;
|
|
||||||
mReadHistoryCompleted = true;
|
mReadHistoryCompleted = true;
|
||||||
|
|
||||||
// Deliver the printers.
|
// Deliver the printers.
|
||||||
updatePrinters(mDiscoverySession.getPrinters(), mFavoritePrinters);
|
updatePrinters(mDiscoverySession.getPrinters(), mFavoritePrinters);
|
||||||
|
|
||||||
|
// We are done.
|
||||||
|
mReadTask = null;
|
||||||
|
|
||||||
// Loading the available printers if needed.
|
// Loading the available printers if needed.
|
||||||
loadInternal();
|
loadInternal();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCancelled(List<PrinterInfo> printerInfos) {
|
||||||
// We are done.
|
// We are done.
|
||||||
mReadTask = null;
|
mReadTask = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -291,6 +291,9 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
|
|||||||
if (isFinishing() || (isFinalState(mState) && !mPrintedDocument.isUpdating())) {
|
if (isFinishing() || (isFinalState(mState) && !mPrintedDocument.isUpdating())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (mPrintedDocument.isUpdating()) {
|
||||||
|
mPrintedDocument.cancel();
|
||||||
|
}
|
||||||
setState(STATE_PRINT_CANCELED);
|
setState(STATE_PRINT_CANCELED);
|
||||||
doFinish();
|
doFinish();
|
||||||
}
|
}
|
||||||
@@ -558,7 +561,9 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
|
|||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(Configuration newConfig) {
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
super.onConfigurationChanged(newConfig);
|
super.onConfigurationChanged(newConfig);
|
||||||
mPrintPreviewController.onOrientationChanged();
|
if (mPrintPreviewController != null) {
|
||||||
|
mPrintPreviewController.onOrientationChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user