Search in sources :

Example 81 with PrintJobInfo

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

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 82 with PrintJobInfo

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

the class UserState method getPrintJobInfo.

public PrintJobInfo getPrintJobInfo(@NonNull PrintJobId printJobId, int appId) {
    PrintJobInfo printJob = mPrintJobForAppCache.getPrintJob(printJobId, appId);
    if (printJob == null) {
        printJob = mSpooler.getPrintJobInfo(printJobId, appId);
    }
    if (printJob != null) {
        // Strip out the tag and the advanced print options.
        // They are visible only to print services.
        printJob.setTag(null);
        printJob.setAdvancedOptions(null);
    }
    return printJob;
}
Also used : PrintJobInfo(android.print.PrintJobInfo)

Example 83 with PrintJobInfo

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

the class UserState method restartPrintJob.

public void restartPrintJob(@NonNull PrintJobId printJobId, int appId) {
    PrintJobInfo printJobInfo = getPrintJobInfo(printJobId, appId);
    if (printJobInfo == null || printJobInfo.getState() != PrintJobInfo.STATE_FAILED) {
        return;
    }
    mSpooler.setPrintJobState(printJobId, PrintJobInfo.STATE_QUEUED, null);
}
Also used : PrintJobInfo(android.print.PrintJobInfo)

Example 84 with PrintJobInfo

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

the class UserState method print.

@SuppressWarnings("deprecation")
public Bundle print(@NonNull String printJobName, @NonNull IPrintDocumentAdapter adapter, @Nullable PrintAttributes attributes, @NonNull String packageName, int appId) {
    // Create print job place holder.
    final PrintJobInfo printJob = new PrintJobInfo();
    printJob.setId(new PrintJobId());
    printJob.setAppId(appId);
    printJob.setLabel(printJobName);
    printJob.setAttributes(attributes);
    printJob.setState(PrintJobInfo.STATE_CREATED);
    printJob.setCopies(1);
    printJob.setCreationTime(System.currentTimeMillis());
    // Track this job so we can forget it when the creator dies.
    if (!mPrintJobForAppCache.onPrintJobCreated(adapter.asBinder(), appId, printJob)) {
        // Not adding a print job means the client is dead - done.
        return null;
    }
    // Spin the spooler to add the job and show the config UI.
    new AsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackground(Void... params) {
            mSpooler.createPrintJob(printJob);
            return null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
    final long identity = Binder.clearCallingIdentity();
    try {
        Intent intent = new Intent(PrintManager.ACTION_PRINT_DIALOG);
        intent.setData(Uri.fromParts("printjob", printJob.getId().flattenToString(), null));
        intent.putExtra(PrintManager.EXTRA_PRINT_DOCUMENT_ADAPTER, adapter.asBinder());
        intent.putExtra(PrintManager.EXTRA_PRINT_JOB, printJob);
        intent.putExtra(DocumentsContract.EXTRA_PACKAGE_NAME, packageName);
        IntentSender intentSender = PendingIntent.getActivityAsUser(mContext, 0, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE, null, new UserHandle(mUserId)).getIntentSender();
        Bundle result = new Bundle();
        result.putParcelable(PrintManager.EXTRA_PRINT_JOB, printJob);
        result.putParcelable(PrintManager.EXTRA_PRINT_DIALOG_INTENT, intentSender);
        return result;
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
Also used : PrintJobId(android.print.PrintJobId) Bundle(android.os.Bundle) PrintJobInfo(android.print.PrintJobInfo) UserHandle(android.os.UserHandle) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) IntentSender(android.content.IntentSender)

Example 85 with PrintJobInfo

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

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)

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