Search in sources :

Example 46 with PrinterId

use of android.print.PrinterId in project android_frameworks_base by crdroidandroid.

the class PrintSpoolerService method getPrintJobInfos.

public List<PrintJobInfo> getPrintJobInfos(ComponentName componentName, int state, int appId) {
    List<PrintJobInfo> foundPrintJobs = null;
    synchronized (mLock) {
        final int printJobCount = mPrintJobs.size();
        for (int i = 0; i < printJobCount; i++) {
            PrintJobInfo printJob = mPrintJobs.get(i);
            PrinterId printerId = printJob.getPrinterId();
            final boolean sameComponent = (componentName == null || (printerId != null && componentName.equals(printerId.getServiceName())));
            final boolean sameAppId = appId == PrintManager.APP_ID_ANY || printJob.getAppId() == appId;
            final boolean sameState = (state == printJob.getState()) || (state == PrintJobInfo.STATE_ANY) || (state == PrintJobInfo.STATE_ANY_VISIBLE_TO_CLIENTS && isStateVisibleToUser(printJob.getState())) || (state == PrintJobInfo.STATE_ANY_ACTIVE && isActiveState(printJob.getState())) || (state == PrintJobInfo.STATE_ANY_SCHEDULED && isScheduledState(printJob.getState()));
            if (sameComponent && sameAppId && sameState) {
                if (foundPrintJobs == null) {
                    foundPrintJobs = new ArrayList<>();
                }
                foundPrintJobs.add(printJob);
            }
        }
    }
    return foundPrintJobs;
}
Also used : PrintJobInfo(android.print.PrintJobInfo) PrinterId(android.print.PrinterId)

Example 47 with PrinterId

use of android.print.PrinterId in project android_frameworks_base by crdroidandroid.

the class UserState method cancelPrintJob.

public void cancelPrintJob(@NonNull PrintJobId printJobId, int appId) {
    PrintJobInfo printJobInfo = mSpooler.getPrintJobInfo(printJobId, appId);
    if (printJobInfo == null) {
        return;
    }
    // Take a note that we are trying to cancel the job.
    mSpooler.setPrintJobCancelling(printJobId, true);
    if (printJobInfo.getState() != PrintJobInfo.STATE_FAILED) {
        PrinterId printerId = printJobInfo.getPrinterId();
        if (printerId != null) {
            ComponentName printServiceName = printerId.getServiceName();
            RemotePrintService printService = null;
            synchronized (mLock) {
                printService = mActiveServices.get(printServiceName);
            }
            if (printService == null) {
                return;
            }
            printService.onRequestCancelPrintJob(printJobInfo);
        }
    } else {
        // If the print job is failed we do not need cooperation
        // from the print service.
        mSpooler.setPrintJobState(printJobId, PrintJobInfo.STATE_CANCELED, null);
    }
}
Also used : PrintJobInfo(android.print.PrintJobInfo) ComponentName(android.content.ComponentName) PrinterId(android.print.PrinterId)

Example 48 with PrinterId

use of android.print.PrinterId in project android_frameworks_base by crdroidandroid.

the class PrintService method generatePrinterId.

/**
     * Generates a global printer id given the printer's locally unique one.
     *
     * @param localId A locally unique id in the context of your print service.
     * @return Global printer id.
     */
@NonNull
public final PrinterId generatePrinterId(String localId) {
    throwIfNotCalledOnMainThread();
    localId = Preconditions.checkNotNull(localId, "localId cannot be null");
    return new PrinterId(new ComponentName(getPackageName(), getClass().getName()), localId);
}
Also used : ComponentName(android.content.ComponentName) PrinterId(android.print.PrinterId) NonNull(android.annotation.NonNull)

Example 49 with PrinterId

use of android.print.PrinterId in project android_frameworks_base by crdroidandroid.

the class PrinterDiscoverySession method sendOutOfDiscoveryPeriodPrinterChanges.

private void sendOutOfDiscoveryPeriodPrinterChanges() {
    // Noting changed since the last discovery period - nothing to do.
    if (mLastSentPrinters == null || mLastSentPrinters.isEmpty()) {
        mLastSentPrinters = null;
        return;
    }
    // Determine the added printers.
    List<PrinterInfo> addedPrinters = null;
    for (PrinterInfo printer : mPrinters.values()) {
        PrinterInfo sentPrinter = mLastSentPrinters.get(printer.getId());
        if (sentPrinter == null || !sentPrinter.equals(printer)) {
            if (addedPrinters == null) {
                addedPrinters = new ArrayList<PrinterInfo>();
            }
            addedPrinters.add(printer);
        }
    }
    // Send the added printers, if such.
    if (addedPrinters != null) {
        try {
            mObserver.onPrintersAdded(new ParceledListSlice<PrinterInfo>(addedPrinters));
        } catch (RemoteException re) {
            Log.e(LOG_TAG, "Error sending added printers", re);
        }
    }
    // Determine the removed printers.
    List<PrinterId> removedPrinterIds = null;
    for (PrinterInfo sentPrinter : mLastSentPrinters.values()) {
        if (!mPrinters.containsKey(sentPrinter.getId())) {
            if (removedPrinterIds == null) {
                removedPrinterIds = new ArrayList<PrinterId>();
            }
            removedPrinterIds.add(sentPrinter.getId());
        }
    }
    // Send the removed printers, if such.
    if (removedPrinterIds != null) {
        try {
            mObserver.onPrintersRemoved(new ParceledListSlice<PrinterId>(removedPrinterIds));
        } catch (RemoteException re) {
            Log.e(LOG_TAG, "Error sending removed printers", re);
        }
    }
    mLastSentPrinters = null;
}
Also used : PrinterId(android.print.PrinterId) PrinterInfo(android.print.PrinterInfo) RemoteException(android.os.RemoteException)

Aggregations

PrinterId (android.print.PrinterId)49 PrinterInfo (android.print.PrinterInfo)30 RemoteException (android.os.RemoteException)15 ArrayList (java.util.ArrayList)15 ComponentName (android.content.ComponentName)14 PrintJobInfo (android.print.PrintJobInfo)14 NonNull (android.annotation.NonNull)5 Location (android.location.Location)5 PrintManager (android.print.PrintManager)5 OnPrintersChangeListener (android.print.PrinterDiscoverySession.OnPrintersChangeListener)5 HashSet (java.util.HashSet)5 LinkedHashMap (java.util.LinkedHashMap)5