use of android.print.PrintJobInfo in project android_frameworks_base by DirtyUnicorns.
the class UserState method getPrintJobInfos.
public List<PrintJobInfo> getPrintJobInfos(int appId) {
List<PrintJobInfo> cachedPrintJobs = mPrintJobForAppCache.getPrintJobs(appId);
// Note that the print spooler is not storing print jobs that
// are in a terminal state as it is non-trivial to properly update
// the spooler state for when to forget print jobs in terminal state.
// Therefore, we fuse the cached print jobs for running apps (some
// jobs are in a terminal state) with the ones that the print
// spooler knows about (some jobs are being processed).
ArrayMap<PrintJobId, PrintJobInfo> result = new ArrayMap<PrintJobId, PrintJobInfo>();
// Add the cached print jobs for running apps.
final int cachedPrintJobCount = cachedPrintJobs.size();
for (int i = 0; i < cachedPrintJobCount; i++) {
PrintJobInfo cachedPrintJob = cachedPrintJobs.get(i);
result.put(cachedPrintJob.getId(), cachedPrintJob);
// Strip out the tag and the advanced print options.
// They are visible only to print services.
cachedPrintJob.setTag(null);
cachedPrintJob.setAdvancedOptions(null);
}
// Add everything else the spooler knows about.
List<PrintJobInfo> printJobs = mSpooler.getPrintJobInfos(null, PrintJobInfo.STATE_ANY, appId);
if (printJobs != null) {
final int printJobCount = printJobs.size();
for (int i = 0; i < printJobCount; i++) {
PrintJobInfo printJob = printJobs.get(i);
result.put(printJob.getId(), printJob);
// Strip out the tag and the advanced print options.
// They are visible only to print services.
printJob.setTag(null);
printJob.setAdvancedOptions(null);
}
}
return new ArrayList<PrintJobInfo>(result.values());
}
use of android.print.PrintJobInfo in project android_frameworks_base by DirtyUnicorns.
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);
}
use of android.print.PrintJobInfo in project android_frameworks_base by DirtyUnicorns.
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);
}
}
use of android.print.PrintJobInfo in project android_frameworks_base by AOSPA.
the class PrintActivity method onAdvancedPrintOptionsActivityResult.
private void onAdvancedPrintOptionsActivityResult(int resultCode, Intent data) {
if (resultCode != RESULT_OK || data == null) {
return;
}
PrintJobInfo printJobInfo = data.getParcelableExtra(PrintService.EXTRA_PRINT_JOB_INFO);
if (printJobInfo == null) {
return;
}
// Take the advanced options without interpretation.
mPrintJob.setAdvancedOptions(printJobInfo.getAdvancedOptions());
if (printJobInfo.getCopies() < 1) {
Log.w(LOG_TAG, "Cannot apply return value from advanced options activity. Copies " + "must be 1 or more. Actual value is: " + printJobInfo.getCopies() + ". " + "Ignoring.");
} else {
mCopiesEditText.setText(String.valueOf(printJobInfo.getCopies()));
mPrintJob.setCopies(printJobInfo.getCopies());
}
PrintAttributes currAttributes = mPrintJob.getAttributes();
PrintAttributes newAttributes = printJobInfo.getAttributes();
if (newAttributes != null) {
// Take the media size only if the current printer supports is.
MediaSize oldMediaSize = currAttributes.getMediaSize();
MediaSize newMediaSize = newAttributes.getMediaSize();
if (newMediaSize != null && !oldMediaSize.equals(newMediaSize)) {
final int mediaSizeCount = mMediaSizeSpinnerAdapter.getCount();
MediaSize newMediaSizePortrait = newAttributes.getMediaSize().asPortrait();
for (int i = 0; i < mediaSizeCount; i++) {
MediaSize supportedSizePortrait = mMediaSizeSpinnerAdapter.getItem(i).value.asPortrait();
if (supportedSizePortrait.equals(newMediaSizePortrait)) {
currAttributes.setMediaSize(newMediaSize);
mMediaSizeSpinner.setSelection(i);
if (currAttributes.getMediaSize().isPortrait()) {
if (mOrientationSpinner.getSelectedItemPosition() != 0) {
mOrientationSpinner.setSelection(0);
}
} else {
if (mOrientationSpinner.getSelectedItemPosition() != 1) {
mOrientationSpinner.setSelection(1);
}
}
break;
}
}
}
// Take the resolution only if the current printer supports is.
Resolution oldResolution = currAttributes.getResolution();
Resolution newResolution = newAttributes.getResolution();
if (!oldResolution.equals(newResolution)) {
PrinterCapabilitiesInfo capabilities = mCurrentPrinter.getCapabilities();
if (capabilities != null) {
List<Resolution> resolutions = capabilities.getResolutions();
final int resolutionCount = resolutions.size();
for (int i = 0; i < resolutionCount; i++) {
Resolution resolution = resolutions.get(i);
if (resolution.equals(newResolution)) {
currAttributes.setResolution(resolution);
break;
}
}
}
}
// Take the color mode only if the current printer supports it.
final int currColorMode = currAttributes.getColorMode();
final int newColorMode = newAttributes.getColorMode();
if (currColorMode != newColorMode) {
final int colorModeCount = mColorModeSpinner.getCount();
for (int i = 0; i < colorModeCount; i++) {
final int supportedColorMode = mColorModeSpinnerAdapter.getItem(i).value;
if (supportedColorMode == newColorMode) {
currAttributes.setColorMode(newColorMode);
mColorModeSpinner.setSelection(i);
break;
}
}
}
// Take the duplex mode only if the current printer supports it.
final int currDuplexMode = currAttributes.getDuplexMode();
final int newDuplexMode = newAttributes.getDuplexMode();
if (currDuplexMode != newDuplexMode) {
final int duplexModeCount = mDuplexModeSpinner.getCount();
for (int i = 0; i < duplexModeCount; i++) {
final int supportedDuplexMode = mDuplexModeSpinnerAdapter.getItem(i).value;
if (supportedDuplexMode == newDuplexMode) {
currAttributes.setDuplexMode(newDuplexMode);
mDuplexModeSpinner.setSelection(i);
break;
}
}
}
}
// Handle selected page changes making sure they are in the doc.
PrintDocumentInfo info = mPrintedDocument.getDocumentInfo().info;
final int pageCount = (info != null) ? getAdjustedPageCount(info) : 0;
PageRange[] pageRanges = printJobInfo.getPages();
if (pageRanges != null && pageCount > 0) {
pageRanges = PageRangeUtils.normalize(pageRanges);
List<PageRange> validatedList = new ArrayList<>();
final int rangeCount = pageRanges.length;
for (int i = 0; i < rangeCount; i++) {
PageRange pageRange = pageRanges[i];
if (pageRange.getEnd() >= pageCount) {
final int rangeStart = pageRange.getStart();
final int rangeEnd = pageCount - 1;
if (rangeStart <= rangeEnd) {
pageRange = new PageRange(rangeStart, rangeEnd);
validatedList.add(pageRange);
}
break;
}
validatedList.add(pageRange);
}
if (!validatedList.isEmpty()) {
PageRange[] validatedArray = new PageRange[validatedList.size()];
validatedList.toArray(validatedArray);
updateSelectedPages(validatedArray, pageCount);
}
}
// Update the content if needed.
if (canUpdateDocument()) {
updateDocument(false);
}
}
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 as a string resource
* @param appPackageName app package the resource belongs to
*/
public void setStatus(@NonNull PrintJobId printJobId, @StringRes int status, @Nullable CharSequence appPackageName) {
synchronized (mLock) {
PrintJobInfo printJob = getPrintJobInfo(printJobId, PrintManager.APP_ID_ANY);
if (printJob != null) {
printJob.setStatus(status, appPackageName);
notifyPrintJobUpdated(printJob);
}
}
}
Aggregations