Merge "Send update notifications when the status of a print job updates and make sure to only access mPrintServicesChangeListenerRecords when locked." into nyc-dev
diff --git a/packages/PrintSpooler/src/com/android/printspooler/model/PrintSpoolerService.java b/packages/PrintSpooler/src/com/android/printspooler/model/PrintSpoolerService.java
index 9b1ab0e..ae4519e 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 @@
}
}
+ /**
+ * 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 @@
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 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 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 026942e..7182161 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 @@
new ListenerRecord<IPrintServicesChangeListener>(listener) {
@Override
public void onBinderDied() {
- mPrintServicesChangeListenerRecords.remove(this);
+ synchronized (mLock) {
+ if (mPrintServicesChangeListenerRecords != null) {
+ mPrintServicesChangeListenerRecords.remove(this);
+ }
+ }
}
});
}