Search in sources :

Example 46 with PrintJobInfo

use of android.print.PrintJobInfo in project android_frameworks_base by AOSPA.

the class PrintSpoolerService method setStatus.

/**
     * Set the status for a print job.
     *
     * @param printJobId ID of the print job to update
     * @param status the new status
     */
public void setStatus(@NonNull PrintJobId printJobId, @Nullable CharSequence status) {
    synchronized (mLock) {
        PrintJobInfo printJob = getPrintJobInfo(printJobId, PrintManager.APP_ID_ANY);
        if (printJob != null) {
            printJob.setStatus(status);
            notifyPrintJobUpdated(printJob);
        }
    }
}
Also used : PrintJobInfo(android.print.PrintJobInfo)

Example 47 with PrintJobInfo

use of android.print.PrintJobInfo in project android_frameworks_base by AOSPA.

the class PrintSpoolerService method setPrintJobTag.

public boolean setPrintJobTag(PrintJobId printJobId, String tag) {
    synchronized (mLock) {
        PrintJobInfo printJob = getPrintJobInfo(printJobId, PrintManager.APP_ID_ANY);
        if (printJob != null) {
            String printJobTag = printJob.getTag();
            if (printJobTag == null) {
                if (tag == null) {
                    return false;
                }
            } else if (printJobTag.equals(tag)) {
                return false;
            }
            printJob.setTag(tag);
            if (shouldPersistPrintJob(printJob)) {
                mPersistanceManager.writeStateLocked();
            }
            return true;
        }
    }
    return false;
}
Also used : PrintJobInfo(android.print.PrintJobInfo)

Example 48 with PrintJobInfo

use of android.print.PrintJobInfo in project android_frameworks_base by AOSPA.

the class PrintSpoolerService method updatePrintJobUserConfigurableOptionsNoPersistence.

public void updatePrintJobUserConfigurableOptionsNoPersistence(PrintJobInfo printJob) {
    synchronized (mLock) {
        final int printJobCount = mPrintJobs.size();
        for (int i = 0; i < printJobCount; i++) {
            PrintJobInfo cachedPrintJob = mPrintJobs.get(i);
            if (cachedPrintJob.getId().equals(printJob.getId())) {
                cachedPrintJob.setPrinterId(printJob.getPrinterId());
                cachedPrintJob.setPrinterName(printJob.getPrinterName());
                cachedPrintJob.setCopies(printJob.getCopies());
                cachedPrintJob.setDocumentInfo(printJob.getDocumentInfo());
                cachedPrintJob.setPages(printJob.getPages());
                cachedPrintJob.setAttributes(printJob.getAttributes());
                cachedPrintJob.setAdvancedOptions(printJob.getAdvancedOptions());
                return;
            }
        }
        throw new IllegalArgumentException("No print job with id:" + printJob.getId());
    }
}
Also used : PrintJobInfo(android.print.PrintJobInfo)

Example 49 with PrintJobInfo

use of android.print.PrintJobInfo in project android_frameworks_base by AOSPA.

the class PrintSpoolerService method handleReadPrintJobsLocked.

private void handleReadPrintJobsLocked() {
    // Make a map with the files for a print job since we may have
    // to delete some. One example of getting orphan files if the
    // spooler crashes while constructing a print job. We do not
    // persist partially populated print jobs under construction to
    // avoid special handling for various attributes missing.
    ArrayMap<PrintJobId, File> fileForJobMap = null;
    File[] files = getFilesDir().listFiles();
    if (files != null) {
        final int fileCount = files.length;
        for (int i = 0; i < fileCount; i++) {
            File file = files[i];
            if (file.isFile() && file.getName().startsWith(PRINT_JOB_FILE_PREFIX)) {
                if (fileForJobMap == null) {
                    fileForJobMap = new ArrayMap<PrintJobId, File>();
                }
                String printJobIdString = file.getName().substring(PRINT_JOB_FILE_PREFIX.length(), file.getName().indexOf('.'));
                PrintJobId printJobId = PrintJobId.unflattenFromString(printJobIdString);
                fileForJobMap.put(printJobId, file);
            }
        }
    }
    final int printJobCount = mPrintJobs.size();
    for (int i = 0; i < printJobCount; i++) {
        PrintJobInfo printJob = mPrintJobs.get(i);
        // We want to have only the orphan files at the end.
        if (fileForJobMap != null) {
            fileForJobMap.remove(printJob.getId());
        }
        switch(printJob.getState()) {
            case PrintJobInfo.STATE_QUEUED:
            case PrintJobInfo.STATE_STARTED:
            case PrintJobInfo.STATE_BLOCKED:
                {
                    // We have a print job that was queued or started or blocked in
                    // the past but the device battery died or a crash occurred. In
                    // this case we assume the print job failed and let the user
                    // decide whether to restart the job or just cancel it.
                    setPrintJobState(printJob.getId(), PrintJobInfo.STATE_FAILED, getString(R.string.no_connection_to_printer));
                }
                break;
        }
    }
    if (!mPrintJobs.isEmpty()) {
        // Update the notification.
        mNotificationController.onUpdateNotifications(mPrintJobs);
    }
    // Delete the orphan files.
    if (fileForJobMap != null) {
        final int orphanFileCount = fileForJobMap.size();
        for (int i = 0; i < orphanFileCount; i++) {
            File file = fileForJobMap.valueAt(i);
            file.delete();
        }
    }
}
Also used : PrintJobId(android.print.PrintJobId) PrintJobInfo(android.print.PrintJobInfo) AtomicFile(android.util.AtomicFile) File(java.io.File)

Example 50 with PrintJobInfo

use of android.print.PrintJobInfo in project android_frameworks_base by AOSPA.

the class PrintSpoolerService method writePrintJobData.

public void writePrintJobData(final ParcelFileDescriptor fd, final PrintJobId printJobId) {
    final PrintJobInfo printJob;
    synchronized (mLock) {
        printJob = getPrintJobInfo(printJobId, PrintManager.APP_ID_ANY);
    }
    new AsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackground(Void... params) {
            FileInputStream in = null;
            FileOutputStream out = null;
            try {
                if (printJob != null) {
                    File file = generateFileForPrintJob(PrintSpoolerService.this, printJobId);
                    in = new FileInputStream(file);
                    out = new FileOutputStream(fd.getFileDescriptor());
                }
                final byte[] buffer = new byte[8192];
                while (true) {
                    final int readByteCount = in.read(buffer);
                    if (readByteCount < 0) {
                        return null;
                    }
                    out.write(buffer, 0, readByteCount);
                }
            } catch (FileNotFoundException fnfe) {
                Log.e(LOG_TAG, "Error writing print job data!", fnfe);
            } catch (IOException ioe) {
                Log.e(LOG_TAG, "Error writing print job data!", ioe);
            } finally {
                IoUtils.closeQuietly(in);
                IoUtils.closeQuietly(out);
                IoUtils.closeQuietly(fd);
            }
            Log.i(LOG_TAG, "[END WRITE]");
            return null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
}
Also used : PrintJobInfo(android.print.PrintJobInfo) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) AtomicFile(android.util.AtomicFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

PrintJobInfo (android.print.PrintJobInfo)110 PrintJobId (android.print.PrintJobId)18 AtomicFile (android.util.AtomicFile)15 File (java.io.File)15 PrinterId (android.print.PrinterId)14 ArrayList (java.util.ArrayList)14 MainThread (android.annotation.MainThread)10 ComponentName (android.content.ComponentName)9 NonNull (android.annotation.NonNull)5 Notification (android.app.Notification)5 InboxStyle (android.app.Notification.InboxStyle)5 Message (android.os.Message)5 RemoteException (android.os.RemoteException)5 PageRange (android.print.PageRange)5 PrintAttributes (android.print.PrintAttributes)5 MediaSize (android.print.PrintAttributes.MediaSize)5 Resolution (android.print.PrintAttributes.Resolution)5 PrintDocumentInfo (android.print.PrintDocumentInfo)5 PrinterCapabilitiesInfo (android.print.PrinterCapabilitiesInfo)5 ArraySet (android.util.ArraySet)5