diff options
Diffstat (limited to 'packages/PrintSpooler')
7 files changed, 94 insertions, 42 deletions
diff --git a/packages/PrintSpooler/Android.mk b/packages/PrintSpooler/Android.mk index 8ae0302..f65fe4b 100644 --- a/packages/PrintSpooler/Android.mk +++ b/packages/PrintSpooler/Android.mk @@ -24,8 +24,6 @@ LOCAL_PACKAGE_NAME := PrintSpooler LOCAL_JAVA_LIBRARIES := framework-base -LOCAL_CERTIFICATE := platform - LOCAL_PROGUARD_ENABLED := disabled include $(BUILD_PACKAGE) diff --git a/packages/PrintSpooler/AndroidManifest.xml b/packages/PrintSpooler/AndroidManifest.xml index ab7ea09..6fa3ed4 100644 --- a/packages/PrintSpooler/AndroidManifest.xml +++ b/packages/PrintSpooler/AndroidManifest.xml @@ -20,18 +20,22 @@ package="com.android.printspooler" android:sharedUserId="android.uid.printspooler" android:versionName="1" - android:versionCode="1" - coreApp="true"> + android:versionCode="1"> - <uses-sdk android:minSdkVersion="18" android:targetSdkVersion="18"/> + <!-- Allows an application to call APIs that give it access to all print jobs + on the device. Usually an app can access only the print jobs it created. + --> + <permission + android:name="com.android.printspooler.permission.ACCESS_ALL_PRINT_JOBS" + android:label="@string/permlab_accessAllPrintJobs" + android:description="@string/permdesc_accessAllPrintJobs" + android:protectionLevel="signature" /> + <uses-permission android:name="com.android.printspooler.permission.ACCESS_ALL_PRINT_JOBS"/> <uses-permission android:name="android.permission.ACCESS_ALL_PRINT_JOBS"/> <uses-permission android:name="android.permission.WAKE_LOCK"/> - <permission android:name="android.permission.BIND_PRINT_SPOOLER_SERVICE" - android:label="@string/permlab_bindPrintSpoolerService" - android:description="@string/permdesc_bindPrintSpoolerService" - android:protectionLevel="signature" /> + <uses-sdk android:minSdkVersion="18" android:targetSdkVersion="18"/> <application android:allowClearUserData="false" diff --git a/packages/PrintSpooler/res/values/strings.xml b/packages/PrintSpooler/res/values/strings.xml index ee3cf84..235a7a1 100644 --- a/packages/PrintSpooler/res/values/strings.xml +++ b/packages/PrintSpooler/res/values/strings.xml @@ -94,6 +94,9 @@ <!-- Template for the notificaiton label for a failed print job. [CHAR LIMIT=25] --> <string name="failed_notification_title_template">Printer error <xliff:g id="print_job_name" example="foo.jpg">%1$s</xliff:g></string> + <!-- Template for the notificaiton label for a blocked print job. [CHAR LIMIT=25] --> + <string name="blocked_notification_title_template">Printer blocked <xliff:g id="print_job_name" example="foo.jpg">%1$s</xliff:g></string> + <!-- Label for the notification button for cancelling a print job. [CHAR LIMIT=25] --> <string name="cancel">Cancel</string> @@ -103,6 +106,9 @@ <!-- Message that there is no connection to a printer. [CHAR LIMIT=40] --> <string name="no_connection_to_printer">No connection to printer</string> + <!-- Label for an unknown reason for failed or blocked print job. [CHAR LIMIT=25] --> + <string name="reason_unknown">unknown</string> + <!-- Arrays --> <!-- Color mode labels. --> @@ -129,12 +135,14 @@ <item>Range</item> </string-array> - <!-- Title of an application permission, listed so the user can choose - whether they want to allow the application to do this. --> - <string name="permlab_bindPrintSpoolerService">bind to a print spooler service</string> - <!-- Description of an application permission, listed so the user can - choose whether they want to allow the application to do this. --> - <string name="permdesc_bindPrintSpoolerService">Allows the holder to bind to the top-level - interface of a print spooler service. Should never be needed for normal apps.</string> + <!-- Permissions --> + + <!-- Title of an application permission, listed so the user can choose whether they want + to allow the application to do this. --> + <string name="permlab_accessAllPrintJobs">access all print jobs</string> + <!-- Description of an application permission, listed so the user can choose whether + they want to allow the application to do this. --> + <string name="permdesc_accessAllPrintJobs">Allows the holder to access print jobs + created by another app. Should never be needed for normal apps.</string> </resources> diff --git a/packages/PrintSpooler/src/com/android/printspooler/FusedPrintersProvider.java b/packages/PrintSpooler/src/com/android/printspooler/FusedPrintersProvider.java index 28fd0e0..ad8d95a 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/FusedPrintersProvider.java +++ b/packages/PrintSpooler/src/com/android/printspooler/FusedPrintersProvider.java @@ -75,6 +75,8 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> { private List<PrinterInfo> mFavoritePrinters; + private PrinterId mTrackedPrinter; + public FusedPrintersProvider(Context context) { super(context); mPersistenceManager = new PersistenceManager(context); @@ -166,6 +168,10 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> { private boolean cancelInternal() { if (mDiscoverySession != null && mDiscoverySession.isPrinterDiscoveryStarted()) { + if (mTrackedPrinter != null) { + mDiscoverySession.stopPrinterStateTracking(mTrackedPrinter); + mTrackedPrinter = null; + } mDiscoverySession.stopPrinterDiscovery(); return true; } else if (mPersistenceManager.isReadHistoryInProgress()) { @@ -195,10 +201,14 @@ public class FusedPrintersProvider extends Loader<List<PrinterInfo>> { onStopLoading(); } - public void refreshPrinter(PrinterId printerId) { + public void setTrackedPrinter(PrinterId printerId) { if (isStarted() && mDiscoverySession != null && mDiscoverySession.isPrinterDiscoveryStarted()) { - mDiscoverySession.requestPrinterUpdate(printerId); + if (mTrackedPrinter != null) { + mDiscoverySession.stopPrinterStateTracking(mTrackedPrinter); + } + mTrackedPrinter = printerId; + mDiscoverySession.startPrinterStateTracking(printerId); } } diff --git a/packages/PrintSpooler/src/com/android/printspooler/NotificationController.java b/packages/PrintSpooler/src/com/android/printspooler/NotificationController.java index c116d37..43a751c 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/NotificationController.java +++ b/packages/PrintSpooler/src/com/android/printspooler/NotificationController.java @@ -32,6 +32,7 @@ import android.os.UserHandle; import android.print.IPrintManager; import android.print.PrintJobInfo; import android.print.PrintManager; +import android.text.TextUtils; import android.util.Log; /** @@ -64,22 +65,27 @@ public class NotificationController { + " state:" + PrintJobInfo.stateToString(printJob.getState())); } switch (printJob.getState()) { - case PrintJobInfo.STATE_QUEUED: { - createPrintingNotificaiton(printJob); + case PrintJobInfo.STATE_QUEUED: + case PrintJobInfo.STATE_STARTED: { + createPrintingNotification(printJob); } break; case PrintJobInfo.STATE_FAILED: { - createFailedNotificaiton(printJob); + createFailedNotification(printJob); } break; case PrintJobInfo.STATE_COMPLETED: case PrintJobInfo.STATE_CANCELED: { removeNotification(printJob.getId()); } break; + + case PrintJobInfo.STATE_BLOCKED: { + createBlockedNotification(printJob); + } break; } } - private void createPrintingNotificaiton(PrintJobInfo printJob) { + private void createPrintingNotification(PrintJobInfo printJob) { Notification.Builder builder = new Notification.Builder(mContext) .setSmallIcon(R.drawable.stat_notify_print) .setContentTitle(mContext.getString(R.string.printing_notification_title_template, @@ -93,17 +99,36 @@ public class NotificationController { mNotificationManager.notify(printJob.getId(), builder.build()); } - private void createFailedNotificaiton(PrintJobInfo printJob) { + private void createFailedNotification(PrintJobInfo printJob) { + String reason = !TextUtils.isEmpty(printJob.getStateReason()) + ? printJob.getStateReason() : mContext.getString(R.string.reason_unknown); + Notification.Builder builder = new Notification.Builder(mContext) .setSmallIcon(R.drawable.stat_notify_error) .setContentTitle(mContext.getString(R.string.failed_notification_title_template, printJob.getLabel())) .addAction(R.drawable.stat_notify_cancelling, mContext.getString(R.string.cancel), createCancelIntent(printJob)) - // TODO: Use appropriate icon when assets are ready .addAction(android.R.drawable.ic_secure, mContext.getString(R.string.restart), createRestartIntent(printJob.getId())) - .setContentText(printJob.getFailureReason()) + .setContentText(reason) + .setWhen(System.currentTimeMillis()) + .setOngoing(true) + .setShowWhen(true); + mNotificationManager.notify(printJob.getId(), builder.build()); + } + + private void createBlockedNotification(PrintJobInfo printJob) { + String reason = !TextUtils.isEmpty(printJob.getStateReason()) + ? printJob.getStateReason() : mContext.getString(R.string.reason_unknown); + + Notification.Builder builder = new Notification.Builder(mContext) + .setSmallIcon(R.drawable.stat_notify_error) + .setContentTitle(mContext.getString(R.string.blocked_notification_title_template, + printJob.getLabel())) + .addAction(R.drawable.stat_notify_cancelling, mContext.getString(R.string.cancel), + createCancelIntent(printJob)) + .setContentText(reason) .setWhen(System.currentTimeMillis()) .setOngoing(true) .setShowWhen(true); diff --git a/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java b/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java index 607be90..520331c 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java +++ b/packages/PrintSpooler/src/com/android/printspooler/PrintJobConfigActivity.java @@ -473,6 +473,11 @@ public class PrintJobConfigActivity extends Activity { mControllerState = CONTROLLER_STATE_WRITE_COMPLETED; + // Update the document size. + File file = PrintSpoolerService.peekInstance() + .generateFileForPrintJob(mPrintJobId); + mDocument.info.setDataSize(file.length()); + // Update which pages we have fetched. mDocument.pages = PageRangeUtils.normalize(pages); @@ -1117,7 +1122,7 @@ public class PrintJobConfigActivity extends Activity { (Loader<?>) getLoaderManager().getLoader( LOADER_ID_PRINTERS_LOADER); if (printersLoader != null) { - printersLoader.refreshPrinter(printer.getId()); + printersLoader.setTrackedPrinter(printer.getId()); } } } @@ -1351,10 +1356,6 @@ public class PrintJobConfigActivity extends Activity { return mEditorState == EDITOR_STATE_CONFIRMED_PRINT; } -// public void confirmPreview() { -// mEditorState = EDITOR_STATE_CONFIRMED_PREVIEW; -// } - public PageRange[] getRequestedPages() { if (hasErrors()) { return null; @@ -1374,7 +1375,7 @@ public class PrintJobConfigActivity extends Activity { toIndex = Integer.parseInt(range.substring( dashIndex + 1, range.length())) - 1; } else { - fromIndex = toIndex = Integer.parseInt(range); + fromIndex = toIndex = Integer.parseInt(range) - 1; } PageRange pageRange = new PageRange(fromIndex, toIndex); diff --git a/packages/PrintSpooler/src/com/android/printspooler/PrintSpoolerService.java b/packages/PrintSpooler/src/com/android/printspooler/PrintSpoolerService.java index c1f4180..dd2598c 100644 --- a/packages/PrintSpooler/src/com/android/printspooler/PrintSpoolerService.java +++ b/packages/PrintSpooler/src/com/android/printspooler/PrintSpoolerService.java @@ -335,7 +335,9 @@ public final class PrintSpoolerService extends Service { final boolean sameState = (state == printJob.getState()) || (state == PrintJobInfo.STATE_ANY) || (state == PrintJobInfo.STATE_ANY_VISIBLE_TO_CLIENTS - && printJob.getState() > PrintJobInfo.STATE_CREATED); + && isStateVisibleToUser(printJob.getState())) + || (state == PrintJobInfo.STATE_ANY_ACTIVE + && isActiveState(printJob.getState())); if (sameComponent && sameAppId && sameState) { if (foundPrintJobs == null) { foundPrintJobs = new ArrayList<PrintJobInfo>(); @@ -347,6 +349,11 @@ public final class PrintSpoolerService extends Service { return foundPrintJobs; } + private boolean isStateVisibleToUser(int state) { + return (isActiveState(state) && (state == PrintJobInfo.STATE_FAILED + || state == PrintJobInfo.STATE_COMPLETED|| state == PrintJobInfo.STATE_CANCELED)); + } + public PrintJobInfo getPrintJobInfo(int printJobId, int appId) { synchronized (mLock) { final int printJobCount = mPrintJobs.size(); @@ -389,14 +396,12 @@ public final class PrintSpoolerService extends Service { switch (printJob.getState()) { case PrintJobInfo.STATE_QUEUED: - case PrintJobInfo.STATE_STARTED: { - // We have a print job that was queued or started 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 + 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)); } @@ -501,7 +506,7 @@ public final class PrintSpoolerService extends Service { success = true; printJob.setState(state); - printJob.setFailureReason(error); + printJob.setStateReason(error); mNotificationController.onPrintJobStateChanged(printJob); if (DEBUG_PRINT_JOB_LIFECYCLE) { @@ -568,7 +573,8 @@ public final class PrintSpoolerService extends Service { private boolean isActiveState(int printJobState) { return printJobState == PrintJobInfo.STATE_CREATED || printJobState == PrintJobInfo.STATE_QUEUED - || printJobState == PrintJobInfo.STATE_STARTED; + || printJobState == PrintJobInfo.STATE_STARTED + || printJobState == PrintJobInfo.STATE_BLOCKED; } public boolean setPrintJobTag(int printJobId, String tag) { |