From 4bd8fac48ed28494ca24e456e20b3058f78e8fe9 Mon Sep 17 00:00:00 2001 From: "Philip P. Moltmann" Date: Thu, 21 Apr 2016 15:17:58 -0700 Subject: [PATCH] Send update notifications when the status of a print job updates and make sure to only access mPrintServicesChangeListenerRecords when locked. Bug: 28315242 Change-Id: Ie41ee695e6b1b0394e55538b9d9edaee0610f1e0 --- .../model/PrintSpoolerService.java | 35 +++++++++++++------ .../com/android/server/print/UserState.java | 6 +++- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/packages/PrintSpooler/src/com/android/printspooler/model/PrintSpoolerService.java b/packages/PrintSpooler/src/com/android/printspooler/model/PrintSpoolerService.java index 9b1ab0e5f671e..ae4519e2495cb 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/model/PrintSpoolerService.java +++ b/packages/PrintSpooler/src/com/android/printspooler/model/PrintSpoolerService.java @@ -497,6 +497,20 @@ public final class PrintSpoolerService extends Service { } } + /** + * Notify all interested parties that a print job has been updated. + * + * @param printJob The updated print job. + */ + private void notifyPrintJobUpdated(PrintJobInfo printJob) { + Message message = mHandlerCaller.obtainMessageO( + HandlerCallerCallback.MSG_ON_PRINT_JOB_STATE_CHANGED, + printJob); + mHandlerCaller.executeOrSendMessage(message); + + mNotificationController.onUpdateNotifications(mPrintJobs); + } + public boolean setPrintJobState(PrintJobId printJobId, int state, String error) { boolean success = false; @@ -549,12 +563,7 @@ public final class PrintSpoolerService extends Service { notifyOnAllPrintJobsHandled(); } - Message message = mHandlerCaller.obtainMessageO( - HandlerCallerCallback.MSG_ON_PRINT_JOB_STATE_CHANGED, - printJob); - mHandlerCaller.executeOrSendMessage(message); - - mNotificationController.onUpdateNotifications(mPrintJobs); + notifyPrintJobUpdated(printJob); } } @@ -584,9 +593,12 @@ public final class PrintSpoolerService extends Service { */ public void setStatus(@NonNull PrintJobId printJobId, @Nullable CharSequence status) { synchronized (mLock) { - getPrintJobInfo(printJobId, PrintManager.APP_ID_ANY).setStatus(status); + PrintJobInfo printJob = getPrintJobInfo(printJobId, PrintManager.APP_ID_ANY); - mNotificationController.onUpdateNotifications(mPrintJobs); + if (printJob != null) { + printJob.setStatus(status); + notifyPrintJobUpdated(printJob); + } } } @@ -600,9 +612,12 @@ public final class PrintSpoolerService extends Service { public void setStatus(@NonNull PrintJobId printJobId, @StringRes int status, @Nullable CharSequence appPackageName) { synchronized (mLock) { - getPrintJobInfo(printJobId, PrintManager.APP_ID_ANY).setStatus(status, appPackageName); + PrintJobInfo printJob = getPrintJobInfo(printJobId, PrintManager.APP_ID_ANY); - mNotificationController.onUpdateNotifications(mPrintJobs); + if (printJob != null) { + printJob.setStatus(status, appPackageName); + notifyPrintJobUpdated(printJob); + } } } diff --git a/services/print/java/com/android/server/print/UserState.java b/services/print/java/com/android/server/print/UserState.java index 026942e11e405..71821613c889f 100644 --- a/services/print/java/com/android/server/print/UserState.java +++ b/services/print/java/com/android/server/print/UserState.java @@ -593,7 +593,11 @@ final class UserState implements PrintSpoolerCallbacks, PrintServiceCallbacks, new ListenerRecord(listener) { @Override public void onBinderDied() { - mPrintServicesChangeListenerRecords.remove(this); + synchronized (mLock) { + if (mPrintServicesChangeListenerRecords != null) { + mPrintServicesChangeListenerRecords.remove(this); + } + } } }); }