diff options
| author | Svetoslav <svetoslavganov@google.com> | 2013-09-16 17:53:51 -0700 |
|---|---|---|
| committer | Svetoslav <svetoslavganov@google.com> | 2013-09-16 17:55:14 -0700 |
| commit | 2fbd2a7f070f246ddafd9de94efa9a98861e9136 (patch) | |
| tree | 2a918b4226106a2350277ae8fa73a9e2ce79d697 /core/java/android/printservice/PrinterDiscoverySession.java | |
| parent | 3fb53d8238c0ccec275237cf4f4962f2a00eab7e (diff) | |
| download | frameworks_base-2fbd2a7f070f246ddafd9de94efa9a98861e9136.zip frameworks_base-2fbd2a7f070f246ddafd9de94efa9a98861e9136.tar.gz frameworks_base-2fbd2a7f070f246ddafd9de94efa9a98861e9136.tar.bz2 | |
App UI freezes when printing. API clean up.
1. The UI of a printing app was freezing a little when calling the print
method since the print manager service was waiting for it to bind to the
print spooler which generated the print job id (and the initial print
job info really). Now the print manager service is responsible for job
id generation and does not not wait for the print spooler to spin. Hence,
the app UI is not blocked at all. Note that the print manager initiates
the binding to the spooler and as soon as it completes the spooler shows
the print UI which is hosted in its process. It is not possible to show
the print UI before the system is bound to the spooler since during this
binding the system passes a callback to the spooler so the latter can
talk to the system.
2. Changed the print job id to be an opaque class allowing us to vary the
way we generate print job ids in the future.
3. The queued print job state was hidden but the print job returned by the
print method of the print manager is in that state. Now now hidden.
4. We were incorrecly removing print job infos if they are completed or
cancelled. Doing that is problematic since the print job returned by
the print method allows the app to query for the job info after the
job has been say completed. Hence, an app can initiate printing and
get a print job whose state is "created" and hold onto it until after
the job is completed, now if the app asks for the print job info it
will get an info in "created" state even though the job is "completed"
since the spooler was not retaining the completed jobs. Now the spooler
removes the PDF files for the completed and cancelled print jobs but
keeps around the infos (also persisting them to disc) so it can answer
questions about them. On first boot or switch to a user we purge the
persisted print jobs in completed/cancelled state since they
are obsolete - no app can have a handle to them.
5. Removed the print method that takes a file since we have a public
PrintDocumentAdapter implementation for printing files. Once can
instantiate a PrintFileDocumentAdapter and pass it to the print
method. This class also allows overriding of the finish method to
know when the data is spooled and deleted the file if desired, etc.
6. Replaced the wrong code to slice a large list of parcelables to
use ParceledListSlice class.
bug:10748093
Change-Id: I1ebeeb47576e88fce550851cdd3e401fcede6e2b
Diffstat (limited to 'core/java/android/printservice/PrinterDiscoverySession.java')
| -rw-r--r-- | core/java/android/printservice/PrinterDiscoverySession.java | 75 |
1 files changed, 27 insertions, 48 deletions
diff --git a/core/java/android/printservice/PrinterDiscoverySession.java b/core/java/android/printservice/PrinterDiscoverySession.java index b0bf3da..17cb68f 100644 --- a/core/java/android/printservice/PrinterDiscoverySession.java +++ b/core/java/android/printservice/PrinterDiscoverySession.java @@ -16,6 +16,7 @@ package android.printservice; +import android.content.pm.ParceledListSlice; import android.os.RemoteException; import android.print.PrinterCapabilitiesInfo; import android.print.PrinterId; @@ -80,8 +81,6 @@ import java.util.List; public abstract class PrinterDiscoverySession { private static final String LOG_TAG = "PrinterDiscoverySession"; - private static final int MAX_ITEMS_PER_CALLBACK = 50; - private static int sIdCounter = 0; private final int mId; @@ -112,7 +111,11 @@ public abstract class PrinterDiscoverySession { // If some printers were added in the method that // created the session, send them over. if (!mPrinters.isEmpty()) { - sendAddedPrinters(mObserver, getPrinters()); + try { + mObserver.onPrintersAdded(new ParceledListSlice<PrinterInfo>(getPrinters())); + } catch (RemoteException re) { + Log.e(LOG_TAG, "Error sending added printers", re); + } } } @@ -184,7 +187,11 @@ public abstract class PrinterDiscoverySession { // Send the added printers, if such. if (addedPrinters != null) { - sendAddedPrinters(mObserver, addedPrinters); + try { + mObserver.onPrintersAdded(new ParceledListSlice<PrinterInfo>(addedPrinters)); + } catch (RemoteException re) { + Log.e(LOG_TAG, "Error sending added printers", re); + } } } else { // Remember the last sent printers if needed. @@ -203,27 +210,6 @@ public abstract class PrinterDiscoverySession { } } - private static void sendAddedPrinters(IPrintServiceClient observer, - List<PrinterInfo> printers) { - try { - final int printerCount = printers.size(); - if (printerCount <= MAX_ITEMS_PER_CALLBACK) { - observer.onPrintersAdded(printers); - } else { - // Send the added printers in chunks avoiding the binder transaction limit. - final int transactionCount = (printerCount / MAX_ITEMS_PER_CALLBACK) + 1; - for (int i = 0; i < transactionCount; i++) { - final int start = i * MAX_ITEMS_PER_CALLBACK; - final int end = Math.min(start + MAX_ITEMS_PER_CALLBACK, printerCount); - List<PrinterInfo> subPrinters = printers.subList(start, end); - observer.onPrintersAdded(subPrinters); - } - } - } catch (RemoteException re) { - Log.e(LOG_TAG, "Error sending added printers", re); - } - } - /** * Removes added printers. Removing an already removed or never added * printer has no effect. Removed printers can be added again. You can @@ -261,7 +247,12 @@ public abstract class PrinterDiscoverySession { // Send the removed printers, if such. if (!removedPrinterIds.isEmpty()) { - sendRemovedPrinters(mObserver, removedPrinterIds); + try { + mObserver.onPrintersRemoved(new ParceledListSlice<PrinterId>( + removedPrinterIds)); + } catch (RemoteException re) { + Log.e(LOG_TAG, "Error sending removed printers", re); + } } } else { // Remember the last sent printers if needed. @@ -278,26 +269,6 @@ public abstract class PrinterDiscoverySession { } } - private static void sendRemovedPrinters(IPrintServiceClient observer, - List<PrinterId> printerIds) { - try { - final int printerIdCount = printerIds.size(); - if (printerIdCount <= MAX_ITEMS_PER_CALLBACK) { - observer.onPrintersRemoved(printerIds); - } else { - final int transactionCount = (printerIdCount / MAX_ITEMS_PER_CALLBACK) + 1; - for (int i = 0; i < transactionCount; i++) { - final int start = i * MAX_ITEMS_PER_CALLBACK; - final int end = Math.min(start + MAX_ITEMS_PER_CALLBACK, printerIdCount); - List<PrinterId> subPrinterIds = printerIds.subList(start, end); - observer.onPrintersRemoved(subPrinterIds); - } - } - } catch (RemoteException re) { - Log.e(LOG_TAG, "Error sending removed printers", re); - } - } - private void sendOutOfDiscoveryPeriodPrinterChanges() { // Noting changed since the last discovery period - nothing to do. if (mLastSentPrinters == null || mLastSentPrinters.isEmpty()) { @@ -319,7 +290,11 @@ public abstract class PrinterDiscoverySession { // Send the added printers, if such. if (addedPrinters != null) { - sendAddedPrinters(mObserver, addedPrinters); + try { + mObserver.onPrintersAdded(new ParceledListSlice<PrinterInfo>(addedPrinters)); + } catch (RemoteException re) { + Log.e(LOG_TAG, "Error sending added printers", re); + } } // Determine the removed printers. @@ -335,7 +310,11 @@ public abstract class PrinterDiscoverySession { // Send the removed printers, if such. if (removedPrinterIds != null) { - sendRemovedPrinters(mObserver, removedPrinterIds); + try { + mObserver.onPrintersRemoved(new ParceledListSlice<PrinterId>(removedPrinterIds)); + } catch (RemoteException re) { + Log.e(LOG_TAG, "Error sending removed printers", re); + } } mLastSentPrinters = null; |
