diff options
author | Svet Ganov <svetoslavganov@google.com> | 2014-10-23 20:04:44 -0700 |
---|---|---|
committer | Svet Ganov <svetoslavganov@google.com> | 2014-10-23 20:10:10 -0700 |
commit | 2916f658c9a55aa5b08a3bbe3056dbfd78e0e1b0 (patch) | |
tree | a40f2a0f04b18ecbe6236172b8c91394bba0b7e8 /packages/PrintSpooler/src | |
parent | bd6fabe2ae535cf5d31fc7a1952e43ad6e653e2e (diff) | |
download | frameworks_base-2916f658c9a55aa5b08a3bbe3056dbfd78e0e1b0.zip frameworks_base-2916f658c9a55aa5b08a3bbe3056dbfd78e0e1b0.tar.gz frameworks_base-2916f658c9a55aa5b08a3bbe3056dbfd78e0e1b0.tar.bz2 |
Sometimes historical printers not properly ordered.
We order printers based on past usage. In some cases the ordering
does not work. The reason for that was an incorrect assumption that
the entries in an ArrayMap are ordered in the order they are added.
bug:18109283
Change-Id: Ie367e4ca5e6bd79f335a060074c9211054e3a931
Diffstat (limited to 'packages/PrintSpooler/src')
-rw-r--r-- | packages/PrintSpooler/src/com/android/printspooler/ui/FusedPrintersProvider.java | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/packages/PrintSpooler/src/com/android/printspooler/ui/FusedPrintersProvider.java b/packages/PrintSpooler/src/com/android/printspooler/ui/FusedPrintersProvider.java index 8a65a2e..02d2715 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/ui/FusedPrintersProvider.java +++ b/packages/PrintSpooler/src/com/android/printspooler/ui/FusedPrintersProvider.java @@ -48,6 +48,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -91,14 +92,14 @@ public final class FusedPrintersProvider extends Loader<List<PrinterInfo>> { mPersistenceManager.addPrinterAndWritePrinterHistory(printer); } - private void computeAndDeliverResult(ArrayMap<PrinterId, PrinterInfo> discoveredPrinters, - ArrayMap<PrinterId, PrinterInfo> favoritePrinters) { + private void computeAndDeliverResult(Map<PrinterId, PrinterInfo> discoveredPrinters, + List<PrinterInfo> favoritePrinters) { List<PrinterInfo> printers = new ArrayList<>(); // Add the updated favorite printers. final int favoritePrinterCount = favoritePrinters.size(); for (int i = 0; i < favoritePrinterCount; i++) { - PrinterInfo favoritePrinter = favoritePrinters.valueAt(i); + PrinterInfo favoritePrinter = favoritePrinters.get(i); PrinterInfo updatedPrinter = discoveredPrinters.remove( favoritePrinter.getId()); if (updatedPrinter != null) { @@ -215,21 +216,14 @@ public final class FusedPrintersProvider extends Loader<List<PrinterInfo>> { // printer to use its current name instead of the historical one. mPersistenceManager.updatePrintersHistoricalNamesIfNeeded(printers); - ArrayMap<PrinterId, PrinterInfo> printersMap = new ArrayMap<>(); + Map<PrinterId, PrinterInfo> printersMap = new LinkedHashMap<>(); final int printerCount = printers.size(); for (int i = 0; i < printerCount; i++) { PrinterInfo printer = printers.get(i); printersMap.put(printer.getId(), printer); } - ArrayMap<PrinterId, PrinterInfo> favoritePrintersMap = new ArrayMap<>(); - final int favoritePrinterCount = favoritePrinters.size(); - for (int i = 0; i < favoritePrinterCount; i++) { - PrinterInfo favoritePrinter = favoritePrinters.get(i); - favoritePrintersMap.put(favoritePrinter.getId(), favoritePrinter); - } - - computeAndDeliverResult(printersMap, favoritePrintersMap); + computeAndDeliverResult(printersMap, favoritePrinters); } @Override @@ -544,7 +538,7 @@ public final class FusedPrintersProvider extends Loader<List<PrinterInfo>> { mReadHistoryCompleted = true; // Deliver the printers. - updatePrinters(mDiscoverySession.getPrinters(), mHistoricalPrinters); + updatePrinters(mDiscoverySession.getPrinters(), mFavoritePrinters); // Loading the available printers if needed. loadInternal(); |