Merge "Crash in print spooler if printing app killed from recents." into lmp-mr1-dev
This commit is contained in:
@@ -110,13 +110,12 @@ public final class PageContentRepository {
|
|||||||
mRenderer.close(callback);
|
mRenderer.close(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy(Runnable callback) {
|
public void destroy() {
|
||||||
throwIfNotClosed();
|
|
||||||
mState = STATE_DESTROYED;
|
mState = STATE_DESTROYED;
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.i(LOG_TAG, "STATE_DESTROYED");
|
Log.i(LOG_TAG, "STATE_DESTROYED");
|
||||||
}
|
}
|
||||||
doDestroy(callback);
|
mRenderer.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startPreload(int firstShownPage, int lastShownPage) {
|
public void startPreload(int firstShownPage, int lastShownPage) {
|
||||||
@@ -163,21 +162,13 @@ public final class PageContentRepository {
|
|||||||
try {
|
try {
|
||||||
if (mState != STATE_DESTROYED) {
|
if (mState != STATE_DESTROYED) {
|
||||||
mCloseGuard.warnIfOpen();
|
mCloseGuard.warnIfOpen();
|
||||||
doDestroy(null);
|
destroy();
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
super.finalize();
|
super.finalize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doDestroy(Runnable callback) {
|
|
||||||
mState = STATE_DESTROYED;
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.i(LOG_TAG, "STATE_DESTROYED");
|
|
||||||
}
|
|
||||||
mRenderer.destroy(callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void throwIfNotOpened() {
|
private void throwIfNotOpened() {
|
||||||
if (mState != STATE_OPENED) {
|
if (mState != STATE_OPENED) {
|
||||||
throw new IllegalStateException("Not opened");
|
throw new IllegalStateException("Not opened");
|
||||||
@@ -428,6 +419,7 @@ public final class PageContentRepository {
|
|||||||
private IPdfRenderer mRenderer;
|
private IPdfRenderer mRenderer;
|
||||||
|
|
||||||
private boolean mBoundToService;
|
private boolean mBoundToService;
|
||||||
|
private boolean mDestroyed;
|
||||||
|
|
||||||
public AsyncRenderer(Context context, OnMalformedPdfFileListener malformedPdfFileListener) {
|
public AsyncRenderer(Context context, OnMalformedPdfFileListener malformedPdfFileListener) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -441,7 +433,6 @@ public final class PageContentRepository {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||||
mBoundToService = true;
|
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
mRenderer = IPdfRenderer.Stub.asInterface(service);
|
mRenderer = IPdfRenderer.Stub.asInterface(service);
|
||||||
mLock.notifyAll();
|
mLock.notifyAll();
|
||||||
@@ -465,9 +456,14 @@ public final class PageContentRepository {
|
|||||||
new AsyncTask<Void, Void, Integer>() {
|
new AsyncTask<Void, Void, Integer>() {
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
|
if (mDestroyed) {
|
||||||
|
cancel(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
Intent intent = new Intent(PdfManipulationService.ACTION_GET_RENDERER);
|
Intent intent = new Intent(PdfManipulationService.ACTION_GET_RENDERER);
|
||||||
intent.setClass(mContext, PdfManipulationService.class);
|
intent.setClass(mContext, PdfManipulationService.class);
|
||||||
mContext.bindService(intent, AsyncRenderer.this, Context.BIND_AUTO_CREATE);
|
mContext.bindService(intent, AsyncRenderer.this, Context.BIND_AUTO_CREATE);
|
||||||
|
mBoundToService = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -512,6 +508,14 @@ public final class PageContentRepository {
|
|||||||
cancelAllRendering();
|
cancelAllRendering();
|
||||||
|
|
||||||
new AsyncTask<Void, Void, Void>() {
|
new AsyncTask<Void, Void, Void>() {
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
if (mDestroyed) {
|
||||||
|
cancel(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
@@ -534,27 +538,14 @@ public final class PageContentRepository {
|
|||||||
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy(final Runnable callback) {
|
public void destroy() {
|
||||||
new AsyncTask<Void, Void, Void>() {
|
|
||||||
@Override
|
|
||||||
protected Void doInBackground(Void... params) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPostExecute(Void result) {
|
|
||||||
if (mBoundToService) {
|
if (mBoundToService) {
|
||||||
mBoundToService = false;
|
mBoundToService = false;
|
||||||
mContext.unbindService(AsyncRenderer.this);
|
mContext.unbindService(AsyncRenderer.this);
|
||||||
}
|
}
|
||||||
mPageContentCache.invalidate();
|
mPageContentCache.invalidate();
|
||||||
mPageContentCache.clear();
|
mPageContentCache.clear();
|
||||||
if (callback != null) {
|
mDestroyed = true;
|
||||||
callback.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startPreload(int firstShownPage, int lastShownPage, RenderSpec renderSpec) {
|
public void startPreload(int firstShownPage, int lastShownPage, RenderSpec renderSpec) {
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ public final class PrintSpoolerService extends Service {
|
|||||||
|
|
||||||
private static final boolean DEBUG_PERSISTENCE = false;
|
private static final boolean DEBUG_PERSISTENCE = false;
|
||||||
|
|
||||||
private static final boolean PERSISTNECE_MANAGER_ENABLED = true;
|
private static final boolean PERSISTENCE_MANAGER_ENABLED = true;
|
||||||
|
|
||||||
private static final long CHECK_ALL_PRINTJOBS_HANDLED_DELAY = 5000;
|
private static final long CHECK_ALL_PRINTJOBS_HANDLED_DELAY = 5000;
|
||||||
|
|
||||||
@@ -728,7 +728,7 @@ public final class PrintSpoolerService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void writeStateLocked() {
|
public void writeStateLocked() {
|
||||||
if (!PERSISTNECE_MANAGER_ENABLED) {
|
if (!PERSISTENCE_MANAGER_ENABLED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mWriteStateScheduled) {
|
if (mWriteStateScheduled) {
|
||||||
@@ -935,7 +935,7 @@ public final class PrintSpoolerService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void readStateLocked() {
|
public void readStateLocked() {
|
||||||
if (!PERSISTNECE_MANAGER_ENABLED) {
|
if (!PERSISTENCE_MANAGER_ENABLED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FileInputStream in = null;
|
FileInputStream in = null;
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ public final class RemotePrintDocument {
|
|||||||
private final DeathRecipient mDeathRecipient = new DeathRecipient() {
|
private final DeathRecipient mDeathRecipient = new DeathRecipient() {
|
||||||
@Override
|
@Override
|
||||||
public void binderDied() {
|
public void binderDied() {
|
||||||
notifyPrintingAppDied();
|
onPrintingAppDied();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -268,7 +268,7 @@ public final class RemotePrintDocument {
|
|||||||
mPrintDocumentAdapter.finish();
|
mPrintDocumentAdapter.finish();
|
||||||
mState = STATE_FINISHED;
|
mState = STATE_FINISHED;
|
||||||
} catch (RemoteException re) {
|
} catch (RemoteException re) {
|
||||||
Log.e(LOG_TAG, "Error calling finish()", re);
|
Log.e(LOG_TAG, "Error calling finish()");
|
||||||
mState = STATE_FAILED;
|
mState = STATE_FAILED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1108,7 +1108,8 @@ public final class RemotePrintDocument {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyPrintingAppDied() {
|
private void onPrintingAppDied() {
|
||||||
|
mState = STATE_FAILED;
|
||||||
new Handler(mLooper).post(new Runnable() {
|
new Handler(mLooper).post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -1129,7 +1130,7 @@ public final class RemotePrintDocument {
|
|||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
final RemotePrintDocument document = mWeakDocument.get();
|
final RemotePrintDocument document = mWeakDocument.get();
|
||||||
if (document != null) {
|
if (document != null) {
|
||||||
document.notifyPrintingAppDied();
|
document.onPrintingAppDied();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -484,9 +484,13 @@ public final class PageAdapter extends Adapter implements
|
|||||||
return selectedPages;
|
return selectedPages;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy(Runnable callback) {
|
public void destroy() {
|
||||||
throwIfNotClosed();
|
mPageContentRepository.destroy();
|
||||||
doDestroy(callback);
|
mCloseGuard.close();
|
||||||
|
mState = STATE_DESTROYED;
|
||||||
|
if (DEBUG) {
|
||||||
|
Log.i(LOG_TAG, "STATE_DESTROYED");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -494,7 +498,7 @@ public final class PageAdapter extends Adapter implements
|
|||||||
try {
|
try {
|
||||||
if (mState != STATE_DESTROYED) {
|
if (mState != STATE_DESTROYED) {
|
||||||
mCloseGuard.warnIfOpen();
|
mCloseGuard.warnIfOpen();
|
||||||
doDestroy(null);
|
destroy();
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
super.finalize();
|
super.finalize();
|
||||||
@@ -741,15 +745,6 @@ public final class PageAdapter extends Adapter implements
|
|||||||
mPageContentRepository.stopPreload();
|
mPageContentRepository.stopPreload();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doDestroy(Runnable callback) {
|
|
||||||
mPageContentRepository.destroy(callback);
|
|
||||||
mCloseGuard.close();
|
|
||||||
mState = STATE_DESTROYED;
|
|
||||||
if (DEBUG) {
|
|
||||||
Log.i(LOG_TAG, "STATE_DESTROYED");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void throwIfNotOpened() {
|
private void throwIfNotOpened() {
|
||||||
if (mState != STATE_OPENED) {
|
if (mState != STATE_OPENED) {
|
||||||
throw new IllegalStateException("Not opened");
|
throw new IllegalStateException("Not opened");
|
||||||
|
|||||||
@@ -1616,16 +1616,10 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
|
|||||||
mSpoolerProvider.destroy();
|
mSpoolerProvider.destroy();
|
||||||
mPrintedDocument.finish();
|
mPrintedDocument.finish();
|
||||||
mPrintedDocument.destroy();
|
mPrintedDocument.destroy();
|
||||||
mPrintPreviewController.destroy(new Runnable() {
|
mPrintPreviewController.destroy();
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
finish();
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
} else {
|
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private final class SpinnerItem<T> {
|
private final class SpinnerItem<T> {
|
||||||
final T value;
|
final T value;
|
||||||
|
|||||||
@@ -192,15 +192,10 @@ class PrintPreviewController implements MutexFileProvider.OnReleaseRequestCallba
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy(Runnable callback) {
|
public void destroy() {
|
||||||
if (mPageAdapter.isOpened()) {
|
mHandler.cancelQueuedOperations();
|
||||||
Message operation = mHandler.obtainMessage(MyHandler.MSG_CLOSE);
|
mRecyclerView.setAdapter(null);
|
||||||
mHandler.enqueueOperation(operation);
|
mPageAdapter.destroy();
|
||||||
}
|
|
||||||
|
|
||||||
Message operation = mHandler.obtainMessage(MyHandler.MSG_DESTROY);
|
|
||||||
operation.obj = callback;
|
|
||||||
mHandler.enqueueOperation(operation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -226,7 +221,6 @@ class PrintPreviewController implements MutexFileProvider.OnReleaseRequestCallba
|
|||||||
private final class MyHandler extends Handler {
|
private final class MyHandler extends Handler {
|
||||||
public static final int MSG_OPEN = 1;
|
public static final int MSG_OPEN = 1;
|
||||||
public static final int MSG_CLOSE = 2;
|
public static final int MSG_CLOSE = 2;
|
||||||
public static final int MSG_DESTROY = 3;
|
|
||||||
public static final int MSG_UPDATE = 4;
|
public static final int MSG_UPDATE = 4;
|
||||||
public static final int MSG_START_PRELOAD = 5;
|
public static final int MSG_START_PRELOAD = 5;
|
||||||
|
|
||||||
@@ -246,6 +240,10 @@ class PrintPreviewController implements MutexFileProvider.OnReleaseRequestCallba
|
|||||||
super(looper, null, false);
|
super(looper, null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void cancelQueuedOperations() {
|
||||||
|
mPendingOperations.clear();
|
||||||
|
}
|
||||||
|
|
||||||
public void enqueueOperation(Message message) {
|
public void enqueueOperation(Message message) {
|
||||||
mPendingOperations.add(message);
|
mPendingOperations.add(message);
|
||||||
handleNextOperation();
|
handleNextOperation();
|
||||||
@@ -294,13 +292,6 @@ class PrintPreviewController implements MutexFileProvider.OnReleaseRequestCallba
|
|||||||
});
|
});
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case MSG_DESTROY: {
|
|
||||||
Runnable callback = (Runnable) message.obj;
|
|
||||||
mRecyclerView.setAdapter(null);
|
|
||||||
mPageAdapter.destroy(callback);
|
|
||||||
handleNextOperation();
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case MSG_UPDATE: {
|
case MSG_UPDATE: {
|
||||||
SomeArgs args = (SomeArgs) message.obj;
|
SomeArgs args = (SomeArgs) message.obj;
|
||||||
PageRange[] writtenPages = (PageRange[]) args.arg1;
|
PageRange[] writtenPages = (PageRange[]) args.arg1;
|
||||||
|
|||||||
Reference in New Issue
Block a user