OSDN Git Service

Send update notifications when the status of a print job updates and
authorPhilip P. Moltmann <moltmann@google.com>
Thu, 21 Apr 2016 22:17:58 +0000 (15:17 -0700)
committerPhilip P. Moltmann <moltmann@google.com>
Thu, 21 Apr 2016 22:33:42 +0000 (15:33 -0700)
make sure to only access mPrintServicesChangeListenerRecords when
locked.

Bug: 28315242
Change-Id: Ie41ee695e6b1b0394e55538b9d9edaee0610f1e0

packages/PrintSpooler/src/com/android/printspooler/model/PrintSpoolerService.java
services/print/java/com/android/server/print/UserState.java

index 9b1ab0e..ae4519e 100644 (file)
@@ -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);
+            }
         }
     }
 
index 026942e..7182161 100644 (file)
@@ -593,7 +593,11 @@ final class UserState implements PrintSpoolerCallbacks, PrintServiceCallbacks,
                     new ListenerRecord<IPrintServicesChangeListener>(listener) {
                         @Override
                         public void onBinderDied() {
-                            mPrintServicesChangeListenerRecords.remove(this);
+                            synchronized (mLock) {
+                                if (mPrintServicesChangeListenerRecords != null) {
+                                    mPrintServicesChangeListenerRecords.remove(this);
+                                }
+                            }
                         }
                     });
         }