summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Svetoslav Ganov <svetoslavganov@google.com> 2013-09-25 23:28:12 -0700
committer Svetoslav Ganov <svetoslavganov@google.com> 2013-09-26 08:14:27 -0700
commit953c4143e846b071da4869cb7cfd8039a086b1da (patch)
tree04007d1b005054d4105a33db19729bf35ef50d9b
parenta53b854103c06f194a1883275d5cdfd78882a248 (diff)
Missed signal in FusedPrintersLoader.
1. In the FusedPrintersLoader we start observing the printers on the device and if they change we send the result. If however, the printers are already loaded in our session (because it joined an ongoing printer discovery) and the pritners do not change, the loader never sends its result. Now we are registring the callback only after historical printers are loaded. We also immediately check after starting discovery whether the there are printers in the discovery session and if so deliver them. 2. Improved logging in the FusedPrintersLoader. bug:10940712 Change-Id: Ieb9b897d64780742125b29309462dea3eda170a6
-rw-r--r--packages/PrintSpooler/src/com/android/printspooler/FusedPrintersProvider.java61
1 files changed, 40 insertions, 21 deletions
diff --git a/packages/PrintSpooler/src/com/android/printspooler/FusedPrintersProvider.java b/packages/PrintSpooler/src/com/android/printspooler/FusedPrintersProvider.java
index b4eb08a566d2..3a1a3c40662c 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/FusedPrintersProvider.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/FusedPrintersProvider.java
@@ -128,7 +128,7 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
@Override
protected void onStartLoading() {
if (DEBUG) {
- Log.i(LOG_TAG, "onStartLoading()" + FusedPrintersProvider.this.hashCode());
+ Log.i(LOG_TAG, "onStartLoading() " + FusedPrintersProvider.this.hashCode());
}
// The contract is that if we already have a valid,
// result the we have to deliver it immediately.
@@ -143,7 +143,7 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
@Override
protected void onStopLoading() {
if (DEBUG) {
- Log.i(LOG_TAG, "onStopLoading()" + FusedPrintersProvider.this.hashCode());
+ Log.i(LOG_TAG, "onStopLoading() " + FusedPrintersProvider.this.hashCode());
}
onCancelLoad();
}
@@ -151,7 +151,7 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
@Override
protected void onForceLoad() {
if (DEBUG) {
- Log.i(LOG_TAG, "onForceLoad()" + FusedPrintersProvider.this.hashCode());
+ Log.i(LOG_TAG, "onForceLoad() " + FusedPrintersProvider.this.hashCode());
}
loadInternal();
}
@@ -161,37 +161,52 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
PrintManager printManager = (PrintManager) getContext()
.getSystemService(Context.PRINT_SERVICE);
mDiscoverySession = printManager.createPrinterDiscoverySession();
+ mPersistenceManager.readPrinterHistory();
+ }
+ if (mPersistenceManager.isReadHistoryCompleted()
+ && !mDiscoverySession.isPrinterDiscoveryStarted()) {
mDiscoverySession.setOnPrintersChangeListener(new OnPrintersChangeListener() {
@Override
public void onPrintersChanged() {
- ArrayMap<PrinterId, PrinterInfo> printersMap =
- new ArrayMap<PrinterId, PrinterInfo>();
- List<PrinterInfo> printers = mDiscoverySession.getPrinters();
- final int printerCount = printers.size();
- for (int i = 0; i < printerCount; i++) {
- PrinterInfo printer = printers.get(i);
- printersMap.put(printer.getId(), printer);
+ if (DEBUG) {
+ Log.i(LOG_TAG, "onPrintersChanged() count:"
+ + mDiscoverySession.getPrinters().size()
+ + " " + FusedPrintersProvider.this.hashCode());
}
- computeAndDeliverResult(printersMap);
+ updatePrinters(mDiscoverySession.getPrinters());
}
});
- mPersistenceManager.readPrinterHistory();
- }
- if (mPersistenceManager.isReadHistoryCompleted()
- && !mDiscoverySession.isPrinterDiscoveryStarted()) {
final int favoriteCount = mFavoritePrinters.size();
List<PrinterId> printerIds = new ArrayList<PrinterId>(favoriteCount);
for (int i = 0; i < favoriteCount; i++) {
printerIds.add(mFavoritePrinters.get(i).getId());
}
mDiscoverySession.startPrinterDisovery(printerIds);
+ List<PrinterInfo> printers = mDiscoverySession.getPrinters();
+ if (!printers.isEmpty()) {
+ updatePrinters(printers);
+ }
+ }
+ }
+
+ private void updatePrinters(List<PrinterInfo> printers) {
+ if (mPrinters.equals(printers)) {
+ return;
+ }
+ ArrayMap<PrinterId, PrinterInfo> printersMap =
+ new ArrayMap<PrinterId, PrinterInfo>();
+ final int printerCount = printers.size();
+ for (int i = 0; i < printerCount; i++) {
+ PrinterInfo printer = printers.get(i);
+ printersMap.put(printer.getId(), printer);
}
+ computeAndDeliverResult(printersMap);
}
@Override
protected boolean onCancelLoad() {
if (DEBUG) {
- Log.i(LOG_TAG, "onCancelLoad()" + FusedPrintersProvider.this.hashCode());
+ Log.i(LOG_TAG, "onCancelLoad() " + FusedPrintersProvider.this.hashCode());
}
return cancelInternal();
}
@@ -214,7 +229,7 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
@Override
protected void onReset() {
if (DEBUG) {
- Log.i(LOG_TAG, "onReset()" + FusedPrintersProvider.this.hashCode());
+ Log.i(LOG_TAG, "onReset() " + FusedPrintersProvider.this.hashCode());
}
onStopLoading();
mPrinters.clear();
@@ -227,7 +242,7 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
@Override
protected void onAbandon() {
if (DEBUG) {
- Log.i(LOG_TAG, "onAbandon()" + FusedPrintersProvider.this.hashCode());
+ Log.i(LOG_TAG, "onAbandon() " + FusedPrintersProvider.this.hashCode());
}
onStopLoading();
}
@@ -288,7 +303,8 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
public void readPrinterHistory() {
if (DEBUG) {
- Log.i(LOG_TAG, "read history started");
+ Log.i(LOG_TAG, "read history started "
+ + FusedPrintersProvider.this.hashCode());
}
mReadHistoryInProgress = true;
mReadTask = new ReadTask();
@@ -364,7 +380,7 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
@Override
protected void onPostExecute(List<PrinterInfo> printers) {
if (DEBUG) {
- Log.i(LOG_TAG, "read history completed"
+ Log.i(LOG_TAG, "read history completed "
+ FusedPrintersProvider.this.hashCode());
}
@@ -393,7 +409,10 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
try {
in = mStatePersistFile.openRead();
} catch (FileNotFoundException fnfe) {
- Log.i(LOG_TAG, "No existing printer history.");
+ if (DEBUG) {
+ Log.i(LOG_TAG, "No existing printer history "
+ + FusedPrintersProvider.this.hashCode());
+ }
return new ArrayList<PrinterInfo>();
}
try {