diff options
author | Svetoslav <svetoslavganov@google.com> | 2013-11-13 17:31:11 -0800 |
---|---|---|
committer | Svetoslav <svetoslavganov@google.com> | 2013-11-13 17:31:15 -0800 |
commit | afd19675030801fb64d32ff101d1da651edf87bc (patch) | |
tree | 8c58690d63785bedc81b7e53147e0a85e2364cba /core/java/android/print | |
parent | a951fa56f1855cd0337bddacc01e35868c6d66d6 (diff) | |
download | frameworks_base-afd19675030801fb64d32ff101d1da651edf87bc.zip frameworks_base-afd19675030801fb64d32ff101d1da651edf87bc.tar.gz frameworks_base-afd19675030801fb64d32ff101d1da651edf87bc.tar.bz2 |
Avoid NPE and add a warning log if a printing app misbehaves.
An app can print only from an activity. If the activity is finished
before printing completes we destroy the PrintDocumentAdapter. The
app may however invoke some of the print callbacks after destruction
resulting in a NPE. This change checks if the adapter is destroyed
and if so does not crash while printing a meaningful log error with
the mistake of the app developer.
bug:11675274
Change-Id: I66539cfbd7583f52cb863a84ef8e40856f92ceed
Diffstat (limited to 'core/java/android/print')
-rw-r--r-- | core/java/android/print/PrintManager.java | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/core/java/android/print/PrintManager.java b/core/java/android/print/PrintManager.java index d6d56bb..d1bb8fd 100644 --- a/core/java/android/print/PrintManager.java +++ b/core/java/android/print/PrintManager.java @@ -860,6 +860,11 @@ public final class PrintManager { } final ILayoutResultCallback callback; synchronized (mLock) { + if (mDestroyed) { + Log.e(LOG_TAG, "PrintDocumentAdapter is destroyed. Did you " + + "finish the printing activity before print completion?"); + return; + } callback = mCallback; clearLocked(); } @@ -876,6 +881,11 @@ public final class PrintManager { public void onLayoutFailed(CharSequence error) { final ILayoutResultCallback callback; synchronized (mLock) { + if (mDestroyed) { + Log.e(LOG_TAG, "PrintDocumentAdapter is destroyed. Did you " + + "finish the printing activity before print completion?"); + return; + } callback = mCallback; clearLocked(); } @@ -891,6 +901,11 @@ public final class PrintManager { @Override public void onLayoutCancelled() { synchronized (mLock) { + if (mDestroyed) { + Log.e(LOG_TAG, "PrintDocumentAdapter is destroyed. Did you " + + "finish the printing activity before print completion?"); + return; + } clearLocked(); } } @@ -918,6 +933,11 @@ public final class PrintManager { public void onWriteFinished(PageRange[] pages) { final IWriteResultCallback callback; synchronized (mLock) { + if (mDestroyed) { + Log.e(LOG_TAG, "PrintDocumentAdapter is destroyed. Did you " + + "finish the printing activity before print completion?"); + return; + } callback = mCallback; clearLocked(); } @@ -940,6 +960,11 @@ public final class PrintManager { public void onWriteFailed(CharSequence error) { final IWriteResultCallback callback; synchronized (mLock) { + if (mDestroyed) { + Log.e(LOG_TAG, "PrintDocumentAdapter is destroyed. Did you " + + "finish the printing activity before print completion?"); + return; + } callback = mCallback; clearLocked(); } @@ -955,6 +980,11 @@ public final class PrintManager { @Override public void onWriteCancelled() { synchronized (mLock) { + if (mDestroyed) { + Log.e(LOG_TAG, "PrintDocumentAdapter is destroyed. Did you " + + "finish the printing activity before print completion?"); + return; + } clearLocked(); } } |