OSDN Git Service

The callbacks for tracking a printer called more than once without printer change.
authorSvetoslav Ganov <svetoslavganov@google.com>
Sat, 12 Oct 2013 21:28:41 +0000 (14:28 -0700)
committerSvetoslav Ganov <svetoslavganov@google.com>
Sat, 12 Oct 2013 21:28:47 +0000 (14:28 -0700)
When the user selectes a printer in the UI we ask the print service to start tracking
the printer, i.e. to observe changes of the printer state and capabilities. The callback
for the initially selected printer is called twice which breaks the contract and also
may trigger potentially expensive operations on the print service side.

More precisely the printer does not change and we ask the service to start tracking,
stop tracking, and again start tracking.

bug:11199851

Change-Id: Ib761e6da03f670b3098c69b1c0927177a8e4ae6b

packages/PrintSpooler/src/com/android/printspooler/FusedPrintersProvider.java

index 8aa290c..0601467 100644 (file)
@@ -254,6 +254,9 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
         if (isStarted() && mDiscoverySession != null
                 && mDiscoverySession.isPrinterDiscoveryStarted()) {
             if (mTrackedPrinter != null) {
+                if (mTrackedPrinter.equals(printerId)) {
+                    return;
+                }
                 mDiscoverySession.stopPrinterStateTracking(mTrackedPrinter);
             }
             mTrackedPrinter = printerId;