From d91cb3ea61ea5096637c5d2b5e3e6147d0d2cce3 Mon Sep 17 00:00:00 2001 From: Svetoslav Ganov Date: Sat, 12 Oct 2013 15:44:42 -0700 Subject: The list of active print jobs in print service retunring wrong result. 1. The getActivePrintJobs() method in print service is designed to return the active print job i.e. ones scheduled to be processed by the print service. Now the correct list is returned. 2. The listeners for observing the state of print jobs may be called even after being unregistered. Ex: state change occurs and we schedule a message on the app's main thread to make the notificaion. Now the app unregisretes the callback and on the next loop the notification message is handled. bug:11200258 Change-Id: I4a497b5c9a7287a22023cafe41ce966d14300ca6 --- core/java/android/print/PrintJobInfo.java | 7 +++++-- core/java/android/print/PrintManager.java | 23 ++++++++++++++++------ .../printspooler/NotificationController.java | 2 +- .../android/server/print/RemotePrintService.java | 2 +- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/core/java/android/print/PrintJobInfo.java b/core/java/android/print/PrintJobInfo.java index e571986..9f935c8 100644 --- a/core/java/android/print/PrintJobInfo.java +++ b/core/java/android/print/PrintJobInfo.java @@ -131,7 +131,7 @@ public final class PrintJobInfo implements Parcelable { /** The name of the printer - internally used */ private String mPrinterName; - /** The status of the print job. */ + /** The state of the print job. */ private int mState; /** The id of the app that created the job. */ @@ -555,7 +555,7 @@ public final class PrintJobInfo implements Parcelable { builder.append("PrintJobInfo{"); builder.append("label: ").append(mLabel); builder.append(", id: ").append(mId); - builder.append(", status: ").append(stateToString(mState)); + builder.append(", state: ").append(stateToString(mState)); builder.append(", printer: " + mPrinterId); builder.append(", tag: ").append(mTag); builder.append(", creationTime: " + mCreationTime); @@ -583,6 +583,9 @@ public final class PrintJobInfo implements Parcelable { case STATE_STARTED: { return "STATE_STARTED"; } + case STATE_BLOCKED: { + return "STATE_BLOCKED"; + } case STATE_FAILED: { return "STATE_FAILED"; } diff --git a/core/java/android/print/PrintManager.java b/core/java/android/print/PrintManager.java index 1233da2..dbd8278 100644 --- a/core/java/android/print/PrintManager.java +++ b/core/java/android/print/PrintManager.java @@ -146,11 +146,14 @@ public final class PrintManager { switch (message.what) { case MSG_NOTIFY_PRINT_JOB_STATE_CHANGED: { SomeArgs args = (SomeArgs) message.obj; - PrintJobStateChangeListener listener = - (PrintJobStateChangeListener) args.arg1; - PrintJobId printJobId = (PrintJobId) args.arg2; + PrintJobStateChangeListenerWrapper wrapper = + (PrintJobStateChangeListenerWrapper) args.arg1; + PrintJobStateChangeListener listener = wrapper.getListener(); + if (listener != null) { + PrintJobId printJobId = (PrintJobId) args.arg2; + listener.onPrintJobStateChanged(printJobId); + } args.recycle(); - listener.onPrintJobStateChanged(printJobId); } break; } } @@ -217,6 +220,7 @@ public final class PrintManager { if (mPrintJobStateChangeListeners.isEmpty()) { mPrintJobStateChangeListeners = null; } + wrappedListener.destroy(); try { mService.removePrintJobStateChangeListener(wrappedListener, mUserId); } catch (RemoteException re) { @@ -769,12 +773,19 @@ public final class PrintManager { PrintJobStateChangeListener listener = mWeakListener.get(); if (handler != null && listener != null) { SomeArgs args = SomeArgs.obtain(); - args.arg1 = listener; + args.arg1 = this; args.arg2 = printJobId; handler.obtainMessage(MSG_NOTIFY_PRINT_JOB_STATE_CHANGED, args).sendToTarget(); } } - } + public void destroy() { + mWeakListener.clear(); + } + + public PrintJobStateChangeListener getListener() { + return mWeakListener.get(); + } + } } diff --git a/packages/PrintSpooler/src/com/android/printspooler/NotificationController.java b/packages/PrintSpooler/src/com/android/printspooler/NotificationController.java index 4aa8686..968a8bf 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/NotificationController.java +++ b/packages/PrintSpooler/src/com/android/printspooler/NotificationController.java @@ -189,7 +189,7 @@ public class NotificationController { if (i == printJobCount - 1) { builder.setLargeIcon(((BitmapDrawable) mContext.getResources().getDrawable( computeNotificationIcon(printJob))).getBitmap()); - builder.setSmallIcon(com.android.internal.R.drawable.ic_print); + builder.setSmallIcon(computeNotificationIcon(printJob)); builder.setContentTitle(computeNotificationTitle(printJob)); builder.setContentText(printJob.getPrinterName()); } diff --git a/services/java/com/android/server/print/RemotePrintService.java b/services/java/com/android/server/print/RemotePrintService.java index 5b9dc28..1bb61d2 100644 --- a/services/java/com/android/server/print/RemotePrintService.java +++ b/services/java/com/android/server/print/RemotePrintService.java @@ -682,7 +682,7 @@ final class RemotePrintService implements DeathRecipient { final long identity = Binder.clearCallingIdentity(); try { return service.mSpooler.getPrintJobInfos(service.mComponentName, - PrintJobInfo.STATE_ANY_VISIBLE_TO_CLIENTS, PrintManager.APP_ID_ANY); + PrintJobInfo.STATE_ANY_SCHEDULED, PrintManager.APP_ID_ANY); } finally { Binder.restoreCallingIdentity(identity); } -- cgit v1.1