Lockup in the print spooler.

A recent change modified the way we destroy the remote renderer from
asynchronous to synchronous. This caused problems since it was possible
that the remote rendering service is unbound while we are reading the
contents of a rendered page. As a result the reader was blocking on I/O
and the print spooler was getting into a locked state that required a
restart of its process.  Now the remote renderer is destroyed
asynchronously.

bug:18498626

Change-Id: I1312bf808f30430728b4038dd4be43c55d2be825
This commit is contained in:
Svet Ganov
2014-11-24 02:01:37 -08:00
committed by Svetoslav Ganov
parent 760cfb02de
commit c80814e70a
4 changed files with 33 additions and 13 deletions

View File

@@ -106,12 +106,26 @@ public final class PageContentRepository {
mRenderer.close(callback);
}
public void destroy() {
public void destroy(final Runnable callback) {
if (mState == STATE_OPENED) {
close(new Runnable() {
@Override
public void run() {
destroy(callback);
}
});
return;
}
mState = STATE_DESTROYED;
if (DEBUG) {
Log.i(LOG_TAG, "STATE_DESTROYED");
}
mRenderer.destroy();
if (callback != null) {
callback.run();
}
}
public void startPreload(int firstShownPage, int lastShownPage) {
@@ -158,7 +172,7 @@ public final class PageContentRepository {
try {
if (mState != STATE_DESTROYED) {
mCloseGuard.warnIfOpen();
destroy();
destroy(null);
}
} finally {
super.finalize();
@@ -455,6 +469,10 @@ public final class PageContentRepository {
public void close(final Runnable callback) {
cancelAllRendering();
if (mOpenTask != null) {
mOpenTask.cancel();
}
new AsyncTask<Void, Void, Void>() {
@Override
protected void onPreExecute() {
@@ -492,10 +510,6 @@ public final class PageContentRepository {
mContext.unbindService(AsyncRenderer.this);
}
if (mOpenTask != null) {
mOpenTask.cancel();
}
mPageContentCache.invalidate();
mPageContentCache.clear();
mDestroyed = true;

View File

@@ -493,13 +493,13 @@ public final class PageAdapter extends Adapter {
return selectedPages;
}
public void destroy() {
mPageContentRepository.destroy();
public void destroy(Runnable callback) {
mCloseGuard.close();
mState = STATE_DESTROYED;
if (DEBUG) {
Log.i(LOG_TAG, "STATE_DESTROYED");
}
mPageContentRepository.destroy(callback);
}
@Override
@@ -507,7 +507,7 @@ public final class PageAdapter extends Adapter {
try {
if (mState != STATE_DESTROYED) {
mCloseGuard.warnIfOpen();
destroy();
destroy(null);
}
} finally {
super.finalize();

View File

@@ -1635,9 +1635,15 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
mSpoolerProvider.destroy();
mPrintedDocument.finish();
mPrintedDocument.destroy();
mPrintPreviewController.destroy();
mPrintPreviewController.destroy(new Runnable() {
@Override
public void run() {
finish();
}
});
} else {
finish();
}
finish();
}
private final class SpinnerItem<T> {

View File

@@ -192,10 +192,10 @@ class PrintPreviewController implements MutexFileProvider.OnReleaseRequestCallba
});
}
public void destroy() {
public void destroy(Runnable callback) {
mHandler.cancelQueuedOperations();
mRecyclerView.setAdapter(null);
mPageAdapter.destroy();
mPageAdapter.destroy(callback);
}
@Override