diff options
author | Svetoslav Ganov <svetoslavganov@google.com> | 2013-09-26 19:20:28 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-09-26 19:20:28 +0000 |
commit | c9cfd605a24cf20df5248d73804c584168db64c9 (patch) | |
tree | 1556f25606e538a2a66f561f5ec71e460c4322dd | |
parent | 027ff3855d257e5179d43a1859bf56530d0f975a (diff) | |
parent | 953c4143e846b071da4869cb7cfd8039a086b1da (diff) | |
download | frameworks_base-c9cfd605a24cf20df5248d73804c584168db64c9.zip frameworks_base-c9cfd605a24cf20df5248d73804c584168db64c9.tar.gz frameworks_base-c9cfd605a24cf20df5248d73804c584168db64c9.tar.bz2 |
Merge "Missed signal in FusedPrintersLoader." into klp-dev
-rw-r--r-- | packages/PrintSpooler/src/com/android/printspooler/FusedPrintersProvider.java | 61 |
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 b4eb08a..3a1a3c4 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 { |