use of android.print.PrintJobId in project platform_frameworks_base by android.
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.PrintJobId in project platform_frameworks_base by android.
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.PrintJobId in project android_frameworks_base by ResurrectionRemix.
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.PrintJobId in project android_frameworks_base by ResurrectionRemix.
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();
}
}
}
use of android.print.PrintJobId in project android_frameworks_base by DirtyUnicorns.
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);
}
}
Aggregations