From d23bfa9d42c477970189a96d4562d627d609e604 Mon Sep 17 00:00:00 2001 From: Svetoslav Date: Wed, 24 Sep 2014 13:19:49 -0700 Subject: [PATCH] Print spooler should not crash if fed non-PDF content. It is possible that a buggy app breaks the contract and provides content to be printed in format other than PDF. This was leading to a crash in the print spooler. This change fixes the crash and shows a user friendly error message. bug:17642690 Change-Id: I5a4acb06080a152562655da6851467b3e71d8658 --- .../android/printspooler/model/PageContentRepository.java | 6 ++---- .../printspooler/renderer/PdfManipulationService.java | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/PrintSpooler/src/com/android/printspooler/model/PageContentRepository.java b/packages/PrintSpooler/src/com/android/printspooler/model/PageContentRepository.java index eb2c9207e18db..85b2490c68fb1 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/model/PageContentRepository.java +++ b/packages/PrintSpooler/src/com/android/printspooler/model/PageContentRepository.java @@ -412,8 +412,6 @@ public final class PageContentRepository { } private static final class AsyncRenderer implements ServiceConnection { - private static final int MALFORMED_PDF_FILE_ERROR = -2; - private final Object mLock = new Object(); private final Context mContext; @@ -486,7 +484,7 @@ public final class PageContentRepository { return mRenderer.openDocument(source); } catch (RemoteException re) { Log.e(LOG_TAG, "Cannot open PDF document"); - return MALFORMED_PDF_FILE_ERROR; + return PdfManipulationService.MALFORMED_PDF_FILE_ERROR; } finally { // Close the fd as we passed it to another process // which took ownership. @@ -497,7 +495,7 @@ public final class PageContentRepository { @Override public void onPostExecute(Integer pageCount) { - if (pageCount == MALFORMED_PDF_FILE_ERROR) { + if (pageCount == PdfManipulationService.MALFORMED_PDF_FILE_ERROR) { mOnMalformedPdfFileListener.onMalformedPdfFile(); mPageCount = PrintDocumentInfo.PAGE_COUNT_UNKNOWN; } else { diff --git a/packages/PrintSpooler/src/com/android/printspooler/renderer/PdfManipulationService.java b/packages/PrintSpooler/src/com/android/printspooler/renderer/PdfManipulationService.java index 62716b2168514..00e505149d1de 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/renderer/PdfManipulationService.java +++ b/packages/PrintSpooler/src/com/android/printspooler/renderer/PdfManipulationService.java @@ -47,6 +47,8 @@ public final class PdfManipulationService extends Service { public static final String ACTION_GET_EDITOR = "com.android.printspooler.renderer.ACTION_GET_EDITOR"; + public static final int MALFORMED_PDF_FILE_ERROR = -2; + private static final String LOG_TAG = "PdfManipulationService"; private static final boolean DEBUG = false; @@ -88,7 +90,7 @@ public final class PdfManipulationService extends Service { } catch (IOException|IllegalStateException e) { IoUtils.closeQuietly(source); Log.e(LOG_TAG, "Cannot open file", e); - throw new RemoteException(e.toString()); + return MALFORMED_PDF_FILE_ERROR; } } }