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

Commit e6cd19d9 authored by krhardeep's avatar krhardeep Committed by Hardeep Kaur
Browse files

Handle malformed PDFs gracefully in PrintSpooler

The PrintSpooler now handles malformed PDFs by marking the print job as failed and calling finish(), preventing RuntimeException

Bug: 367448551
Flag: EXEMPT bug fix
Test: atest IPrintManagerParametersTest, tested in test app on a physical device

Change-Id: I54d14b270741172eff7e4147ad59b2e0d39ab188
parent 882509d8
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -37,5 +37,4 @@ oneway interface IPrintDocumentAdapter {
    void write(in PageRange[] pages, in ParcelFileDescriptor fd,
            IWriteResultCallback callback, int sequence);
    void finish();
    void kill(String reason);
}
+0 −20
Original line number Diff line number Diff line
@@ -945,17 +945,6 @@ public final class PrintManager {
            }
        }

        @Override
        public void kill(String reason) {
            synchronized (mLock) {
                // If destroyed the handler is null.
                if (!isDestroyedLocked()) {
                    mHandler.obtainMessage(MyHandler.MSG_ON_KILL,
                            reason).sendToTarget();
                }
            }
        }

        @Override
        public void onActivityPaused(Activity activity) {
            /* do nothing */
@@ -1118,15 +1107,6 @@ public final class PrintManager {
                        }
                    } break;

                    case MSG_ON_KILL: {
                        if (DEBUG) {
                            Log.i(LOG_TAG, "onKill()");
                        }

                        String reason = (String) message.obj;
                        throw new RuntimeException(reason);
                    }

                    default: {
                        throw new IllegalArgumentException("Unknown message: "
                                + message.what);
+0 −12
Original line number Diff line number Diff line
@@ -329,18 +329,6 @@ public final class RemotePrintDocument {
        disconnectFromRemoteDocument();
    }

    public void kill(String reason) {
        if (DEBUG) {
            Log.i(LOG_TAG, "[CALLED] kill()");
        }

        try {
            mPrintDocumentAdapter.kill(reason);
        } catch (RemoteException re) {
            Log.e(LOG_TAG, "Error calling kill()", re);
        }
    }

    public boolean isUpdating() {
        return mState == STATE_UPDATING || mState == STATE_CANCELING;
    }
+6 −2
Original line number Diff line number Diff line
@@ -514,8 +514,12 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
        ensureErrorUiShown(null, PrintErrorFragment.ACTION_RETRY);

        setState(STATE_UPDATE_FAILED);

        mPrintedDocument.kill(message);
        if (DEBUG) {
            Log.i(LOG_TAG, "PrintJob state[" +  PrintJobInfo.STATE_FAILED + "] reason: " + message);
        }
        PrintSpoolerService spooler = mSpoolerProvider.getSpooler();
        spooler.setPrintJobState(mPrintJob.getId(), PrintJobInfo.STATE_FAILED, message);
        mPrintedDocument.finish();
    }

    @Override