use of android.print.PrintJobInfo in project android_frameworks_base by AOSPA.
the class PrintSpoolerService method setPrintJobState.
public boolean setPrintJobState(PrintJobId printJobId, int state, String error) {
boolean success = false;
synchronized (mLock) {
PrintJobInfo printJob = getPrintJobInfo(printJobId, PrintManager.APP_ID_ANY);
if (printJob != null) {
final int oldState = printJob.getState();
if (oldState == state) {
return false;
}
success = true;
printJob.setState(state);
printJob.setStatus(error);
printJob.setCancelling(false);
if (DEBUG_PRINT_JOB_LIFECYCLE) {
Slog.i(LOG_TAG, "[STATE CHANGED] " + printJob);
}
MetricsLogger.histogram(this, "print_job_state", state);
switch(state) {
case PrintJobInfo.STATE_COMPLETED:
case PrintJobInfo.STATE_CANCELED:
mPrintJobs.remove(printJob);
removePrintJobFileLocked(printJob.getId());
case PrintJobInfo.STATE_FAILED:
{
PrinterId printerId = printJob.getPrinterId();
if (printerId != null) {
ComponentName service = printerId.getServiceName();
if (!hasActivePrintJobsForServiceLocked(service)) {
sendOnAllPrintJobsForServiceHandled(service);
}
}
}
break;
case PrintJobInfo.STATE_QUEUED:
{
sendOnPrintJobQueued(new PrintJobInfo(printJob));
}
break;
}
if (shouldPersistPrintJob(printJob)) {
mPersistanceManager.writeStateLocked();
}
if (!hasActivePrintJobsLocked()) {
notifyOnAllPrintJobsHandled();
}
notifyPrintJobUpdated(printJob);
}
}
return success;
}
use of android.print.PrintJobInfo in project android_frameworks_base by AOSPA.
the class NotificationController method updateNotifications.
/**
* Update notifications for the given print jobs, remove all other notifications.
*
* @param printJobs The print job that we want to create notifications for.
*/
private void updateNotifications(List<PrintJobInfo> printJobs) {
ArraySet<PrintJobId> removedPrintJobs = new ArraySet<>(mNotifications);
final int numPrintJobs = printJobs.size();
// Create summary notification
if (numPrintJobs > 1) {
createStackedNotification(printJobs);
} else {
mNotificationManager.cancel(PRINT_JOB_NOTIFICATION_SUMMARY, 0);
}
// Create per print job notification
for (int i = 0; i < numPrintJobs; i++) {
PrintJobInfo printJob = printJobs.get(i);
PrintJobId printJobId = printJob.getId();
removedPrintJobs.remove(printJobId);
mNotifications.add(printJobId);
createSimpleNotification(printJob);
}
// Remove notifications for print jobs that do not exist anymore
final int numRemovedPrintJobs = removedPrintJobs.size();
for (int i = 0; i < numRemovedPrintJobs; i++) {
PrintJobId removedPrintJob = removedPrintJobs.valueAt(i);
mNotificationManager.cancel(removedPrintJob.flattenToString(), 0);
mNotifications.remove(removedPrintJob);
}
}
use of android.print.PrintJobInfo in project android_frameworks_base by ResurrectionRemix.
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 ResurrectionRemix.
the class PrintSpoolerService method dump.
@Override
protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
String prefix = (args.length > 0) ? args[0] : "";
String tab = " ";
synchronized (mLock) {
pw.append(prefix).append("print jobs:").println();
final int printJobCount = mPrintJobs.size();
for (int i = 0; i < printJobCount; i++) {
PrintJobInfo printJob = mPrintJobs.get(i);
pw.append(prefix).append(tab).append(printJob.toString());
pw.println();
}
pw.append(prefix).append("print job files:").println();
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)) {
pw.append(prefix).append(tab).append(file.getName()).println();
}
}
}
}
pw.append(prefix).append("approved print services:").println();
Set<String> approvedPrintServices = (new ApprovedPrintServices(this)).getApprovedServices();
if (approvedPrintServices != null) {
for (String approvedService : approvedPrintServices) {
pw.append(prefix).append(tab).append(approvedService).println();
}
}
}
use of android.print.PrintJobInfo in project android_frameworks_base by ResurrectionRemix.
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);
}
Aggregations