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

Commit d454beb8 authored by Svetoslav's avatar Svetoslav Committed by Android Git Automerger
Browse files

am 0d38d0b4: Merge "Multiple printer discovery session instances and other bugs." into klp-dev

* commit '0d38d0b4':
  Multiple printer discovery session instances and other bugs.
parents 173ef6aa 0d38d0b4
Loading
Loading
Loading
Loading
+40 −0
Original line number Original line Diff line number Diff line
@@ -383,6 +383,10 @@ public abstract class PrintService extends Service {
            final int action = message.what;
            final int action = message.what;
            switch (action) {
            switch (action) {
                case MSG_CREATE_PRINTER_DISCOVERY_SESSION: {
                case MSG_CREATE_PRINTER_DISCOVERY_SESSION: {
                    if (DEBUG) {
                        Log.i(LOG_TAG, "MSG_CREATE_PRINTER_DISCOVERY_SESSION "
                                + getPackageName());
                    }
                    PrinterDiscoverySession session = onCreatePrinterDiscoverySession();
                    PrinterDiscoverySession session = onCreatePrinterDiscoverySession();
                    if (session == null) {
                    if (session == null) {
                        throw new NullPointerException("session cannot be null");
                        throw new NullPointerException("session cannot be null");
@@ -396,6 +400,10 @@ public abstract class PrintService extends Service {
                } break;
                } break;


                case MSG_DESTROY_PRINTER_DISCOVERY_SESSION: {
                case MSG_DESTROY_PRINTER_DISCOVERY_SESSION: {
                    if (DEBUG) {
                        Log.i(LOG_TAG, "MSG_DESTROY_PRINTER_DISCOVERY_SESSION "
                                + getPackageName());
                    }
                    if (mDiscoverySession != null) {
                    if (mDiscoverySession != null) {
                        mDiscoverySession.destroy();
                        mDiscoverySession.destroy();
                        mDiscoverySession = null;
                        mDiscoverySession = null;
@@ -403,6 +411,10 @@ public abstract class PrintService extends Service {
                } break;
                } break;


                case MSG_START_PRINTER_DISCOVERY: {
                case MSG_START_PRINTER_DISCOVERY: {
                    if (DEBUG) {
                        Log.i(LOG_TAG, "MSG_START_PRINTER_DISCOVERY "
                                + getPackageName());
                    }
                    if (mDiscoverySession != null) {
                    if (mDiscoverySession != null) {
                        List<PrinterId> priorityList = (ArrayList<PrinterId>) message.obj;
                        List<PrinterId> priorityList = (ArrayList<PrinterId>) message.obj;
                        mDiscoverySession.startPrinterDiscovery(priorityList);
                        mDiscoverySession.startPrinterDiscovery(priorityList);
@@ -410,12 +422,20 @@ public abstract class PrintService extends Service {
                } break;
                } break;


                case MSG_STOP_PRINTER_DISCOVERY: {
                case MSG_STOP_PRINTER_DISCOVERY: {
                    if (DEBUG) {
                        Log.i(LOG_TAG, "MSG_STOP_PRINTER_DISCOVERY "
                                + getPackageName());
                    }
                    if (mDiscoverySession != null) {
                    if (mDiscoverySession != null) {
                        mDiscoverySession.stopPrinterDiscovery();
                        mDiscoverySession.stopPrinterDiscovery();
                    }
                    }
                } break;
                } break;


                case MSG_VALIDATE_PRINTERS: {
                case MSG_VALIDATE_PRINTERS: {
                    if (DEBUG) {
                        Log.i(LOG_TAG, "MSG_VALIDATE_PRINTERS "
                                + getPackageName());
                    }
                    if (mDiscoverySession != null) {
                    if (mDiscoverySession != null) {
                        List<PrinterId> printerIds = (List<PrinterId>) message.obj;
                        List<PrinterId> printerIds = (List<PrinterId>) message.obj;
                        mDiscoverySession.validatePrinters(printerIds);
                        mDiscoverySession.validatePrinters(printerIds);
@@ -423,6 +443,10 @@ public abstract class PrintService extends Service {
                } break;
                } break;


                case MSG_START_PRINTER_STATE_TRACKING: {
                case MSG_START_PRINTER_STATE_TRACKING: {
                    if (DEBUG) {
                        Log.i(LOG_TAG, "MSG_START_PRINTER_STATE_TRACKING "
                                + getPackageName());
                    }
                    if (mDiscoverySession != null) {
                    if (mDiscoverySession != null) {
                        PrinterId printerId = (PrinterId) message.obj;
                        PrinterId printerId = (PrinterId) message.obj;
                        mDiscoverySession.startPrinterStateTracking(printerId);
                        mDiscoverySession.startPrinterStateTracking(printerId);
@@ -430,6 +454,10 @@ public abstract class PrintService extends Service {
                } break;
                } break;


                case MSG_STOP_PRINTER_STATE_TRACKING: {
                case MSG_STOP_PRINTER_STATE_TRACKING: {
                    if (DEBUG) {
                        Log.i(LOG_TAG, "MSG_STOP_PRINTER_STATE_TRACKING "
                                + getPackageName());
                    }
                    if (mDiscoverySession != null) {
                    if (mDiscoverySession != null) {
                        PrinterId printerId = (PrinterId) message.obj;
                        PrinterId printerId = (PrinterId) message.obj;
                        mDiscoverySession.stopPrinterStateTracking(printerId);
                        mDiscoverySession.stopPrinterStateTracking(printerId);
@@ -437,11 +465,19 @@ public abstract class PrintService extends Service {
                } break;
                } break;


                case MSG_ON_REQUEST_CANCEL_PRINTJOB: {
                case MSG_ON_REQUEST_CANCEL_PRINTJOB: {
                    if (DEBUG) {
                        Log.i(LOG_TAG, "MSG_ON_REQUEST_CANCEL_PRINTJOB "
                                + getPackageName());
                    }
                    PrintJobInfo printJobInfo = (PrintJobInfo) message.obj;
                    PrintJobInfo printJobInfo = (PrintJobInfo) message.obj;
                    onRequestCancelPrintJob(new PrintJob(printJobInfo, mClient));
                    onRequestCancelPrintJob(new PrintJob(printJobInfo, mClient));
                } break;
                } break;


                case MSG_ON_PRINTJOB_QUEUED: {
                case MSG_ON_PRINTJOB_QUEUED: {
                    if (DEBUG) {
                        Log.i(LOG_TAG, "MSG_ON_PRINTJOB_QUEUED "
                                + getPackageName());
                    }
                    PrintJobInfo printJobInfo = (PrintJobInfo) message.obj;
                    PrintJobInfo printJobInfo = (PrintJobInfo) message.obj;
                    if (DEBUG) {
                    if (DEBUG) {
                        Log.i(LOG_TAG, "Queued: " + printJobInfo);
                        Log.i(LOG_TAG, "Queued: " + printJobInfo);
@@ -450,6 +486,10 @@ public abstract class PrintService extends Service {
                } break;
                } break;


                case MSG_SET_CLEINT: {
                case MSG_SET_CLEINT: {
                    if (DEBUG) {
                        Log.i(LOG_TAG, "MSG_SET_CLEINT "
                                + getPackageName());
                    }
                    mClient = (IPrintServiceClient) message.obj;
                    mClient = (IPrintServiceClient) message.obj;
                    if (mClient != null) {
                    if (mClient != null) {
                        onConnected();
                        onConnected();
+4 −6
Original line number Original line Diff line number Diff line
@@ -86,10 +86,6 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
    }
    }


    private void computeAndDeliverResult(Map<PrinterId, PrinterInfo> discoveredPrinters) {
    private void computeAndDeliverResult(Map<PrinterId, PrinterInfo> discoveredPrinters) {
        if (!isStarted()) {
            return;
        }

        List<PrinterInfo> printers = new ArrayList<PrinterInfo>();
        List<PrinterInfo> printers = new ArrayList<PrinterInfo>();


        // Add the updated favorite printers.
        // Add the updated favorite printers.
@@ -123,9 +119,11 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> {
        mPrinters.clear();
        mPrinters.clear();
        mPrinters.addAll(printers);
        mPrinters.addAll(printers);


        if (isStarted()) {
            // Deliver the printers.
            // Deliver the printers.
            deliverResult(printers);
            deliverResult(printers);
        }
        }
    }


    @Override
    @Override
    protected void onStartLoading() {
    protected void onStartLoading() {
+1 −1
Original line number Original line Diff line number Diff line
@@ -74,7 +74,7 @@ public final class PrintSpoolerService extends Service {


    private static final String LOG_TAG = "PrintSpoolerService";
    private static final String LOG_TAG = "PrintSpoolerService";


    private static final boolean DEBUG_PRINT_JOB_LIFECYCLE = true;
    private static final boolean DEBUG_PRINT_JOB_LIFECYCLE = false;


    private static final boolean DEBUG_PERSISTENCE = false;
    private static final boolean DEBUG_PERSISTENCE = false;


+8 −9
Original line number Original line Diff line number Diff line
@@ -85,7 +85,7 @@ final class RemotePrintService implements DeathRecipient {


    private boolean mHasPrinterDiscoverySession;
    private boolean mHasPrinterDiscoverySession;


    private boolean mServiceDead;
    private boolean mServiceDied;


    private List<PrinterId> mDiscoveryPriorityList;
    private List<PrinterId> mDiscoveryPriorityList;


@@ -107,7 +107,6 @@ final class RemotePrintService implements DeathRecipient {
        mSpooler = spooler;
        mSpooler = spooler;
        mHandler = new MyHandler(context.getMainLooper());
        mHandler = new MyHandler(context.getMainLooper());
        mPrintServiceClient = new RemotePrintServiceClient(this);
        mPrintServiceClient = new RemotePrintServiceClient(this);
        mServiceDead = true;
    }
    }


    public ComponentName getComponentName() {
    public ComponentName getComponentName() {
@@ -157,7 +156,7 @@ final class RemotePrintService implements DeathRecipient {
    private void handleBinderDied() {
    private void handleBinderDied() {
        mPrintService.asBinder().unlinkToDeath(this, 0);
        mPrintService.asBinder().unlinkToDeath(this, 0);
        mPrintService = null;
        mPrintService = null;
        mServiceDead = true;
        mServiceDied = true;
        mCallbacks.onServiceDied(this);
        mCallbacks.onServiceDied(this);
    }
    }


@@ -171,7 +170,7 @@ final class RemotePrintService implements DeathRecipient {
        if (!isBound()) {
        if (!isBound()) {
            // The service is dead and neither has active jobs nor discovery
            // The service is dead and neither has active jobs nor discovery
            // session, so ensure we are unbound since the service has no work.
            // session, so ensure we are unbound since the service has no work.
            if (mServiceDead && !mHasPrinterDiscoverySession) {
            if (mServiceDied && !mHasPrinterDiscoverySession) {
                ensureUnbound();
                ensureUnbound();
                return;
                return;
            }
            }
@@ -286,7 +285,7 @@ final class RemotePrintService implements DeathRecipient {
        if (!isBound()) {
        if (!isBound()) {
            // The service is dead and neither has active jobs nor discovery
            // The service is dead and neither has active jobs nor discovery
            // session, so ensure we are unbound since the service has no work.
            // session, so ensure we are unbound since the service has no work.
            if (mServiceDead && !mHasActivePrintJobs) {
            if (mServiceDied && !mHasActivePrintJobs) {
                ensureUnbound();
                ensureUnbound();
                return;
                return;
            }
            }
@@ -556,15 +555,15 @@ final class RemotePrintService implements DeathRecipient {
                return;
                return;
            }
            }
            // If the service died and there is a discovery session, recreate it.
            // If the service died and there is a discovery session, recreate it.
            if (mServiceDead && mHasPrinterDiscoverySession) {
            if (mServiceDied && mHasPrinterDiscoverySession) {
                handleCreatePrinterDiscoverySession();
                handleCreatePrinterDiscoverySession();
            }
            }
            // If the service died and there is discovery started, restart it.
            // If the service died and there is discovery started, restart it.
            if (mServiceDead && mDiscoveryPriorityList != null) {
            if (mServiceDied && mDiscoveryPriorityList != null) {
                handleStartPrinterDiscovery(mDiscoveryPriorityList);
                handleStartPrinterDiscovery(mDiscoveryPriorityList);
            }
            }
            // If the service died and printers were tracked, start tracking.
            // If the service died and printers were tracked, start tracking.
            if (mServiceDead && mTrackedPrinterList != null) {
            if (mServiceDied && mTrackedPrinterList != null) {
                final int trackedPrinterCount = mTrackedPrinterList.size();
                final int trackedPrinterCount = mTrackedPrinterList.size();
                for (int i = 0; i < trackedPrinterCount; i++) {
                for (int i = 0; i < trackedPrinterCount; i++) {
                    handleStartPrinterStateTracking(mTrackedPrinterList.get(i));
                    handleStartPrinterStateTracking(mTrackedPrinterList.get(i));
@@ -581,7 +580,7 @@ final class RemotePrintService implements DeathRecipient {
            if (!mHasPrinterDiscoverySession && !mHasActivePrintJobs) {
            if (!mHasPrinterDiscoverySession && !mHasActivePrintJobs) {
                ensureUnbound();
                ensureUnbound();
            }
            }
            mServiceDead = false;
            mServiceDied = false;
        }
        }


        @Override
        @Override
+15 −2
Original line number Original line Diff line number Diff line
@@ -1007,12 +1007,25 @@ final class UserState implements PrintSpoolerCallbacks, PrintServiceCallbacks {
            mHandler.obtainMessage(
            mHandler.obtainMessage(
                    SessionHandler.MSG_CREATE_PRINTER_DISCOVERY_SESSION,
                    SessionHandler.MSG_CREATE_PRINTER_DISCOVERY_SESSION,
                    service).sendToTarget();
                    service).sendToTarget();
            // If there are some observers that started discovery - tell the service.
            // Start printer discovery if necessary.
            if (mDiscoveryObservers.getRegisteredCallbackCount() > 0) {
            if (!mStartedPrinterDiscoveryTokens.isEmpty()) {
                mHandler.obtainMessage(
                mHandler.obtainMessage(
                        SessionHandler.MSG_START_PRINTER_DISCOVERY,
                        SessionHandler.MSG_START_PRINTER_DISCOVERY,
                        service).sendToTarget();
                        service).sendToTarget();
            }
            }
            // Start tracking printers if necessary
            final int trackedPrinterCount = mStateTrackedPrinters.size();
            for (int i = 0; i < trackedPrinterCount; i++) {
                PrinterId printerId = mStateTrackedPrinters.get(i);
                if (printerId.getServiceName().equals(service.getComponentName())) {
                    SomeArgs args = SomeArgs.obtain();
                    args.arg1 = service;
                    args.arg2 = printerId;
                    mHandler.obtainMessage(SessionHandler
                            .MSG_START_PRINTER_STATE_TRACKING, args)
                            .sendToTarget();
                }
            }
        }
        }


        public void dump(PrintWriter pw, String prefix) {
        public void dump(PrintWriter pw, String prefix) {