Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c80814e7 authored by Svet Ganov's avatar Svet Ganov Committed by Svetoslav Ganov
Browse files

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
parent 760cfb02
Loading
Loading
Loading
Loading
+20 −6
Original line number Diff line number Diff line
@@ -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;
+3 −3
Original line number Diff line number Diff line
@@ -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();
+8 −2
Original line number Diff line number Diff line
@@ -1635,10 +1635,16 @@ 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();
        }
    }

    private final class SpinnerItem<T> {
        final T value;
+2 −2
Original line number Diff line number Diff line
@@ -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