Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5146ea2b authored by Svetoslav Ganov's avatar Svetoslav Ganov Committed by The Android Automerger
Browse files

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
parent 8eba0e1a
Loading
Loading
Loading
Loading
+40 −21
Original line number Original line Diff line number Diff line
@@ -161,33 +161,48 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
            PrintManager printManager = (PrintManager) getContext()
            PrintManager printManager = (PrintManager) getContext()
                    .getSystemService(Context.PRINT_SERVICE);
                    .getSystemService(Context.PRINT_SERVICE);
            mDiscoverySession = printManager.createPrinterDiscoverySession();
            mDiscoverySession = printManager.createPrinterDiscoverySession();
            mPersistenceManager.readPrinterHistory();
        }
        if (mPersistenceManager.isReadHistoryCompleted()
                && !mDiscoverySession.isPrinterDiscoveryStarted()) {
            mDiscoverySession.setOnPrintersChangeListener(new OnPrintersChangeListener() {
            mDiscoverySession.setOnPrintersChangeListener(new OnPrintersChangeListener() {
                @Override
                @Override
                public void onPrintersChanged() {
                public void onPrintersChanged() {
                    ArrayMap<PrinterId, PrinterInfo> printersMap =
                    if (DEBUG) {
                            new ArrayMap<PrinterId, PrinterInfo>();
                        Log.i(LOG_TAG, "onPrintersChanged() count:"
                    List<PrinterInfo> printers = mDiscoverySession.getPrinters();
                                + mDiscoverySession.getPrinters().size()
                    final int printerCount = printers.size();
                                + " " + FusedPrintersProvider.this.hashCode());
                    for (int i = 0; i < printerCount; i++) {
                        PrinterInfo printer = printers.get(i);
                        printersMap.put(printer.getId(), printer);
                    }
                    }
                    computeAndDeliverResult(printersMap);
                    updatePrinters(mDiscoverySession.getPrinters());
                }
                }
            });
            });
            mPersistenceManager.readPrinterHistory();
        }
        if (mPersistenceManager.isReadHistoryCompleted()
                && !mDiscoverySession.isPrinterDiscoveryStarted()) {
            final int favoriteCount = mFavoritePrinters.size();
            final int favoriteCount = mFavoritePrinters.size();
            List<PrinterId> printerIds = new ArrayList<PrinterId>(favoriteCount);
            List<PrinterId> printerIds = new ArrayList<PrinterId>(favoriteCount);
            for (int i = 0; i < favoriteCount; i++) {
            for (int i = 0; i < favoriteCount; i++) {
                printerIds.add(mFavoritePrinters.get(i).getId());
                printerIds.add(mFavoritePrinters.get(i).getId());
            }
            }
            mDiscoverySession.startPrinterDisovery(printerIds);
            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
    @Override
    protected boolean onCancelLoad() {
    protected boolean onCancelLoad() {
        if (DEBUG) {
        if (DEBUG) {
@@ -288,7 +303,8 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {


        public void readPrinterHistory() {
        public void readPrinterHistory() {
            if (DEBUG) {
            if (DEBUG) {
                Log.i(LOG_TAG, "read history started");
                Log.i(LOG_TAG, "read history started "
                        + FusedPrintersProvider.this.hashCode());
            }
            }
            mReadHistoryInProgress = true;
            mReadHistoryInProgress = true;
            mReadTask = new ReadTask();
            mReadTask = new ReadTask();
@@ -393,7 +409,10 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
                try {
                try {
                    in = mStatePersistFile.openRead();
                    in = mStatePersistFile.openRead();
                } catch (FileNotFoundException fnfe) {
                } 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>();
                    return new ArrayList<PrinterInfo>();
                }
                }
                try {
                try {