55 Commits

Author SHA1 Message Date
Svetoslav
0d38d0b42f Merge "Multiple printer discovery session instances and other bugs." into klp-dev 2013-09-24 20:37:59 +00:00
Baligh Uddin
87ac87a5e5 Merge "Import translations. DO NOT MERGE" into klp-dev 2013-09-24 14:58:07 +00:00
Svetoslav
b5f180608d Multiple printer discovery session instances and other bugs.
1. The fused printers provider was dropping on the floor received printers
    if it was not active. It is in fact a loaded and if not active it should compute
    the printers and not deliver them until activated. This fixes an issue where
    opening the print dialog, then enabling a print service results in the printers
    reported by the service not showing up in the print dialog.

2. Printer discovery session was created twice which leads to incorrect behavior
    as the pint system is designed around the contract that there is a single
    printer discovery session per service at a time. This was possible due to an
    incorrect initialization of a member variable resulting in double session creation
    when the print service is connected.

3. When a print service is enabled during discovery we did not use the correct
    condition to start printer discovery resulting in starting it all the time even if
    not needed. Also if some of the printers that had to be tracked are reported
    by the service just enabled (typically historical printers) we did not ask the
    service to start tracking them.

4. Removed some logging.

bug:10903343

Change-Id: I46c049471a4b099fc668df3aee2aaedc8d7786ac
2013-09-23 23:41:12 -07:00
Svetoslav Ganov
5dfccc3c0d Merge "The current is printer not refreshed when selected." into klp-dev 2013-09-23 23:04:32 +00:00
Svetoslav Ganov
307a0d4db2 The current is printer not refreshed when selected.
Every time a printer is selected we have to refresh it by telling
the print service to stop tracking the previously selected printer
if such and start tracking the current one. As a result of start
tracking the print service has to give us the capabilities too. A
previous patch caused a regression and we do not refresh printers
when needed.

bug:10898968

Change-Id: I9d5413e324fdb8856ef61849d36a161470eb204d
2013-09-23 15:51:06 -07:00
Baligh Uddin
e209e27112 Import translations. DO NOT MERGE
Change-Id: Ia5c6ae14529080f176a14f5b8b2307cc2aa39fed
Auto-generated-cl: translation import
2013-09-23 09:10:23 -07:00
Svetoslav
a4f6409c97 Page ranges not correct in come cases.
1. The algorithm that determines whether a page range contains
   another one had a bug and in some cases misbehaved.

2. When print is pressed we do a final layout and if nothing
   changes and we have the requeted pages we skip the final
   write. However, in this case we did not update the print
   job with the pages to be printed but we have to since in
   the previous write we did not ask for all selected pages,
   rather for the first one to be shown as a preview. Now if
   we have all pages and nothing changed we update the print
   job pages.

bug:10530142

Change-Id: I10fb62ae5ae07b8e54d547fd4dca555a12451bc5
2013-09-21 11:25:36 -07:00
Svetoslav
b39ce63d28 Merge "Offer to enable a print service after it is installed." into klp-dev 2013-09-21 01:15:47 +00:00
Svetoslav
d8f391b4e0 Offer to enable a print service after it is installed.
The user has to explicitly enable a print service from the settings UI
before using it. Usually, users very rarely if at all interact with print
services, therefore all print service management task are performed from
the print settings. We also have to get user consent warning that the
user's data is about to be given to a third-party app. We now post a
notification allowing the user to go directly to the settings screen to
turn the service on.

bug:10447510

Change-Id: Iea56c0825f0bf38328ad94912f0ea5576e9339b3
2013-09-20 17:40:25 -07:00
Svetoslav
5559c368a9 PrintDocumentAdapter contract not followed on print.
1. Layout was not called after pressing the print button if the
   print attributes did not change. This is not correct since the
   previous layout calls were for preview purposes and the one
   after pressing print is not for preview. Hence, we always have
   to do this layout.

2. After layout we decide whether to ask the app to write some
   pages. We ask for a write if we do not have the pages selected
   by the user or the document changed (if the page count changed,
   the document type changed, or the app told us that the content
   changed). We were not computing correctly whether the document
   changed since we compared the size but the document info the
   app passes in after a layout does not have the size yet. We set
   the size after a write. So for layout purposes we should ignore
   the size. We only care if the page count, document type, or
   content changed where the latter is reported by the app in
   the layout callback.

3. We were not updating the PrintJob after setting the data
   size of the printed document.

4. Disabled debugging.

bug:10835370

Change-Id: Ic3b2871b4e954cdf610f8cf806de5fc6588a6bec
2013-09-20 12:15:22 -07:00
Svetoslav
b206f1271d Null not handled when parsing media size resource id attribute.
bug:10835715

Change-Id: I0c9c1120c26e68b4c582599bbda3753d0e443d8c
2013-09-20 10:43:29 -07:00
Svetoslav
6811f4e92c Move PdfDocument to android.graphics.pdf
1. Move PdfDocument to android.graphics.pdf.

2. Changed the PdfDocument as per API concil request.

3. Updated the documentation.

bug:10461180
bug:10552565
bug:10681585
bug:10552336

Change-Id: I08e15b34cf37bb064248c887e6f59808019cafe8
2013-09-19 17:12:47 -07:00
Svetoslav
ac7297bdc0 Merge "Fixes in the page range selection and verification logic." into klp-dev 2013-09-19 02:16:11 +00:00
Svetoslav
f0c48a72fd Fixes in the page range selection and verification logic.
1. Typing a range where the start is greater than the end was
   leading to a crash.

2. Typing the same single range, e.g. "2,2", was leading to a crash.

3. If two ranges are non-overlapping but consecutive they were
   not merged

4. Typing multiple times a digit that is less than the page count,
   e.g. page count "2" and typing "11", was not caught by the input
   verification.

bug:10812904

Change-Id: I754715b5d792a1a6c3a4f9f644edfa9aea7ac127
2013-09-18 14:13:06 -07:00
Svetoslav
7b3990ec81 Merge "Update the print dialog." into klp-dev 2013-09-18 21:08:49 +00:00
Svetoslav
013b816ac7 Update the print dialog.
1. The print dialog was resizable and as a result when printers
   come and go its size changes which looks bad. The dialog is
   now trying to be maximally large limited by a max size or the
   screen - whichever is smaller. This required moving from
   GridLayout to several LinearLayouts since the former does not
   support distribution of empty space evently between the items
   in a row. Also we want all items in a column of inputs to be
   of equal size (the spinners specifically).

2. Added labeledBy attribute to associate a view with another one
   that serves as its label for accessibility purposes. We have
   lebelFor attribute but it is not useful in most layout files
   since it has to refer the auto-generated id of a view which
   usually appears later in the layout file, thus generating a
   compilation error. This was needed for the accessibility support
   of the print dialog.

bug:10631660

2. Disabling the spinners or the print button did not produce
   visual feedback leading to user frustration.

bug:10741907

Change-Id: I0c12eddabc4035bc7becd1b86c1f1b8fdcf4289c
2013-09-18 12:31:26 -07:00
Svetoslav Ganov
10ee84ba18 The printers in print dialog should not change position.
The FusedPrintersProvider was not ensuring the existing printers
are at the same position when a new dataset is loaded. As a result
the printers were moving in the UI and sometimes the currently
selected one changed. Now the provider makes sure printers are in
the same position.

bug:10748884

Change-Id: I7c6cd5b1b38fdb615ceaae87806b413272ffba18
2013-09-18 11:34:24 -07:00
Svetoslav
0cfebec522 Merge "Print pooler crashes for some page ranges." into klp-dev 2013-09-17 20:46:35 +00:00
Svetoslav
c3484024e1 Print pooler crashes for some page ranges.
1. The print spooler fails to parse page ranges that end with
   a dash, e,g, "1-", which are however valid inputs since the
   user can continue typing to end up with a well-fromed range.

2. After a layout we are asking for the first selected page
   to be written emulating print preview, thus increasing the
   changes that apps will correctly implement the APIs.

bug:10743632

Change-Id: Ia74172d4fa6bce6ad93a0bc53da1aaa3fe8bef42
2013-09-16 19:13:25 -07:00
Svetoslav
2fbd2a7f07 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
2013-09-16 17:55:14 -07:00
Svetoslav Ganov
860f8a6b66 Spooler should not crash if print service config activities are not exported.
1. If a print service does not export its activities for settings and
   adding printers the print spooler ignores them instead of crashing.
   Also if the service is not enabled its activities are now ignored.

2. Added a dedicated permission for a print service to optionally
   protect its settings and add printer activities such that only the
   system can bind to them.

3. Fixed a crash in the print dialog if its content is detached
   from the window and animators are running.

bug:10680224

Change-Id: I20b57d6622a15f9b2352ba78d04c44e67b316a15
2013-09-14 01:00:55 -07:00
Svetoslav
651dd4e6ee Remove unneeded print APIs and update the min margins APIs.
1. Removed unneeded code in Resolution that was storing its
   label as resource and package name. We do not have predefined
   resolutions, therefore we always persist the label.

2. Renamed the print attribute margins to minMargins to reflect
   that these are the minimal margins the printer support. Updated
   the docs as well.

3. Renamed the create method of all builder to build.

bug:10727487

Change-Id: Ie72ab8aaa5215b8bd2853885011b3b4efa4deb2e
2013-09-12 16:58:58 -07:00
Svetoslav
cc65b0c325 Not change the print options on printer change if possible.
If the user selects some print options from the dialog and then
changes the printer to one that has the same capabilities the
selections in the UI should not change.

bug:10631856

Change-Id: Ia76ce58c446815e3498d2f4b4739dee62d11d96a
2013-09-12 14:29:53 -07:00
Svetoslav
c6066799ad Handle print serivce crashes.
1. Now after a print service crashes we are bringing it to the same
    state of its lifecycle. For example, if a service does a discovery
    and crashes we recreate the discovery session call the start
    discovery method and so on.

2. Turned off debugging logs since we have fully fledged state dump.

bug:10697779

Change-Id: Id790537461428e96b197eef12258996bda2bd1ce
2013-09-12 10:52:26 -07:00
Svetoslav
23e2bba4e1 Merge "Spooler broken on upgrade." into klp-dev 2013-09-06 00:00:22 +00:00
Svetoslav
1a3ef4fafb Spooler broken on upgrade.
The spooler apk was signed with the platform certificate and used
a redundant shared user id. Now the spooler is signed with a default
certificate and uses the same share user id. Since the shared user
id is associated with the platform certificate the package manager
rejects the spooler apk because it requested the same shared user id
with a different certificate. This change removes the unnecessary
shared user id from the manifest.

Change-Id: I208ef17fc6c25e67338682e56f9ce0e7e9d65642
2013-09-05 16:19:19 -07:00
Svetoslav Ganov
56960fbd39 Merge "Fixing some minor RTL bugs in print dialog" into klp-dev 2013-09-05 21:37:26 +00:00
Svetoslav
a36285f3f2 Bug fixes in the print dialog
1. Read/write async tasks of the persistence manger used by
   the FusedPrintersProvider could be run more that once, so
   create a new one every time.

2. The fake printer used to save to PDF should not be added
   to printer history.

3. Removed print preview leftover code from the print dialog.

4. Save to PDF was not working on the second consecutive attempt.

5. The fisrt time the orientation change was ignored - regression

Change-Id: I8960ef2cf92dfeeec22fa8751ba8475092b5b65c
2013-09-05 11:34:32 -07:00
Svetoslav
a76233ae84 Hiding some unneeded APIs,
1. Hide the MediaSize and Resolution constructors that take
   package and resource Id.

2. Fix a bug and docs in creating portrait and landscape media
   size.

Change-Id: If59992e355391de6ad6d14d4f7b3be8c8b6cc0e0
2013-09-05 09:50:28 -07:00
Svetoslav
773f54de3d Print API updated.
1. Removed the updatePrinters API on PrinterDiscoverySession.
   Now re-adding a printer updates it.

2. Added getTrackedPrinters() API to allow a print service to
   figure out which printers' state should be tracked by the
   service.

3. Removed the APIs on PrintDocumentInfo that describe the
   layout of the content as they are not needed. For example,
   if the print attributes passed in layout require landscape
   mode, the the app should just create a PDF page with the
   wider side up and draw its content in portrait. The printer
   will then rotate the page.

Change-Id: Idd72c6e9c129e8b17eef1236573a99773f8ff0a2
2013-09-04 21:06:12 -07:00
Svetoslav Ganov
4cff92ac5b Fixing some minor RTL bugs in print dialog
Change-Id: I164e3d3b643c885e9d6e65c24b1f5e2323e42c97
2013-09-04 14:47:24 -07:00
Svetoslav Ganov
9186d0cb2b Bug fixes in the printer dialog activity and fused printer loader.
1. Fused printers loader was not using the discovered printers to update the
    historical ones. Now if a historical printer is discovered we update its state
    with the discovered, i.e. most recent, information.

2. Fixed a bug in the destination adapter of the print job config dialog that
    was leading to a crash if all printers item is selected when there are no
    discovered printers.

3.  Updated the add printers asset in the all printers screen.

4. Historical printers were not persisted by the print dialog activity.

5. Reduced the number of printers we send per transation to avoid the binder
   transaction size limit. Added sending of printers in chunks in a place
   this was missing.

Change-Id: I88b54888360bc0e53b06bd260c2b832d0d6454b6
2013-09-03 08:42:17 -07:00
Svetoslav Ganov
d26d4898fc Print spooler security and some new print service facing APIs.
1. Updated the security mode of the print spooler. Now the spooler
   is not signed with the system key, it is not a privileged app so if
   it gets compromised (PDF rendering is a potential attack vector)
   it cannot access dangerous permissions. Also only the system
   can bind to the spooler.

2. Added APIs for asking a print service to start and stop tracking
   a given printer. This is need for the case when the user selects
   the printer and the print service should do a best effort to keep
   the system updated for the current state of the printer.

3. Added APIs for putting a print job in a blocked state. A print
   service would report the print job as blocked if for some reason
   the printer cannot proceed, e.g. 99 pages are printed but there
   is no paper for the last one. The user has to add more paper
   and the print service can resume the job.

4. Changed the read/write APIs to use ParcelFileDescriptor instead
   of FileDescriptor since the latter does not have a clean API for
   detaching the wrapped Linux file descriptor when one wants to
   push it to native.

5. Added API for getting the size of the printed document so the
   print service can avoid handling big filed over cellular network
   or ask the user if needed.

6. Now the print services that are preinstalled on the system image
   are automatically enabled.

Change-Id: Ia06c311d3d21cabb9e1368f13928e11cd0030918
2013-08-29 15:39:44 -07:00
Svetoslav Ganov
aec1417ca9 Print APIs update.
1. Added scale to fit and scale to fill fitting modes.

2. Added APIs for a print app to specify which constraints imposed
   by the print attributes were satsified during a layout so they
   are not handled by the printer again, e.g. if the content is to
   be in landscape the the app generated such content the printer
   should rotate the content again.

3. Added some printer statuses.

4. Added a helper class that generates PDF documents with correct
   size based on the passed in print attributes.

5. Exposed a ctor for PageRange which was hidden by mistake and apps
   could not create page ranges. Added API for changing the printer
   status.

Change-Id: If1334a61d2d931027b98075f653018d456b1b768
2013-08-27 11:56:18 -07:00
Svetoslav Ganov
44720af55a Print UI bug fixing and printer discovery refactoring.
1. Added support for selecting a printer from the all printers activity
   that is not in the initial printer selection drop down. The user
   initially sees a sub set of the printers in the drop down and the
   last option is to see all printers in a separate activity. Some
   of the printers in the all printers activity are not shown in the
   initial drop down.

2. Refactored printer discovery by adding (private for now) printer
   discovery app facing APIs. These APIs are needed to support multiple
   printer selection activities (print dialog and all printers activities)
   and also the settings for showing all printers for a service.

   Now multiple apps can request observing for printers and there is
   a centralized mediator that ensures the same printer discovery
   session is used. The mediator dispatches printer discovery specific
   requests to print services. It also aggregates discovered printers
   and delivers them to the interested apps. The mediator minimizes
   printer discovery session creation and starting and stopping discovery
   by sharing the same discovery session and discovery window with
   multiple apps. Lastly, the mediator takes care of print services
   enabled during discovery by bringing them up to the current
   discovery state (create discovery session and start discovery if
   needed). The mediator also reports disappearing of the printers
   of a service removed during discovery and notifies a newly
   registered observers for the currnet printers if the observers are
   added during an active printer discovery session.

3. Fixed bugs in the print UI and implemented some UX tweaks.

Change-Id: I4d0b0c5a6c6f1809b2ba5dbc8e9d63ab3d48f1ef
2013-08-23 18:36:33 +00:00
Svetoslav
269403b032 Implemented advanced printer selection and API refactoring.
1. Added past printer history tracking and merging favorite printers
   with discovered printers.

2. Added save as PDF support.

3. Added all printers activity with search capability and optional
   add printers chooser (if any print service provides add printers
   activity)

4. Refactored the printer discovery session APIs. Now one session
   can have multiple window discovery windows and the session stores
   the printers found during past discovery periods.

5. Merged the print spooler and the print spooler service - much
   simpler and easier to maintain.

Change-Id: I4830b0eb6367e1c748b768a5ea9ea11baf36cfad
2013-08-19 13:24:11 -07:00
Svetoslav
66160bb881 Partial implementation for the favorite and available printer tracking.
1. Added a dedicated class that keeps track of the user's favorite printers
   based on past usage. We keep the last 50 uses and assign a decreasing weight
   to older historical use records. The printer whose records' sum is the
   largest is considered the favorite for the user and so on.

2. Factored out the printer discovery logic from the print job config activity
   into a separate available printers provider class. It encapsulates all the
   logic to communicated with the remote print services to discover printers,
   keep track of added, updated, and removed printers.

3. Preliminary scetch of the printer chooser acitivty that will show all the
   printers.

Change-Id: I5524665f2a9a565f186db85214d5e41a44f4812e
2013-08-14 00:06:53 -07:00
Svetoslav Ganov
55daead3c5 Fix the build
Change-Id: Icf3b339f7b300cc8673443fa8afd38ce78964683
2013-08-11 15:26:13 -07:00
Svetoslav Ganov
798bed6cc7 Refinement of the print service APIs.
1. Factored out the printer discovery APIs of a print service in a
   dedicated session object that is created by the print service on
   demand. This ensures that added/removed/updated printers from
   one session do not interfere with another session.

2. Updated the app facing APIs to pass in a document info along
   with a printed file. Also exposed the print file adapter so
   apps that create a temporary file for printing can intercept
   when it is read by the system so the file can be deleted.

3. Updated the print service documentation.

Change-Id: I3473d586c26d8bda1cf7e2bdacb441aa9df982ed
2013-08-11 14:40:05 -07:00
Svetoslav Ganov
695c7fa7a3 Print UI polish based on UX feedback.
1. Refreshed the print UI based on UX redlines.

2. Implemented tap outside cancel for the print job config activity
   which is full-screen but pretends to be a dialog.

Change-Id: I5afc7cd40c696109d70af31536898cfcad91b2ab
2013-08-07 19:47:05 -07:00
Svetoslav Ganov
32c5eb3bf8 Update the print job dialog and added notification assets.
1. Update the transition between the print job edit dialog and the
   generating print job dialog. Now the former shrinks into the
   latter.

2. Added most of the notification assets.

Change-Id: I84f35df5cb4f71b86a103c16ab87fd4d108b055b
2013-08-06 23:52:38 -07:00
Svetoslav Ganov
14db9654f6 Print UI polish (a.k.a. just the next iteration))
1. Added a dialog to show a spinner while the app is writing the
   printed content.

2. Fixed print job config acitivity leaking.

3. Updated the notifications a bit.

Change-Id: I8314390135a49605ee11ab4ed14b210a29566745
2013-08-06 15:07:17 -07:00
Svetoslav Ganov
55b5f8028a Disable print dialog spinners if there is only one option.
Change-Id: Ic9a46c737b592aeb6f78c962a7f9d53391a2b164
2013-08-05 11:26:16 -07:00
Svetoslav Ganov
835835ee6f Polish the print spooler loading of stored print jobs.
1. The singleton print spooler isntance is created when the print spooler
   service gets a connection to the system and is destroyed when this
   connection is removed. Note that if the spooler has work, then the
   connection to the system will not be removed.

   When the spooler is created, it reads the stored state and notifies the
   system which in turn dispatches this to the print services.

   When the system connects to the spooler and passes it a connection, we
   schedule a delayed check whether there is work for the spooler. We do
   not handle this immediately to avoid intermitted spinning on and off
   of the spooler process if a client makes a sequence of queries while
   the spooler has really no work.

2. Fixed a bug in the NotificationManagerService where adding a notification
   and removing it immediately after that does not remove the notification.
   The code that is adding a notification is run on a handler thread while
   the code to remove it on the calling thread. This creates a race and
   erroneous results. Now the removal is also scheduled on the handler.

3. Many small fixes here and there.

Change-Id: I6415c253139fa6616393fbe23c659d031a29e1f6
2013-08-04 20:45:10 -07:00
Svetoslav Ganov
8c43376ea8 First cut of the print notifications.
1. Added notifications for a queued print job, for a started print job,
       for ongoing canceling a print job, and for a failed print job. The
       notifications for queued and started state have a cancel action. The
       notification for failed print job has a cancel and a restart action.

    2. Propagating failure message from the print service to the notifications.

    3. PrintJobConfigActivity was not setting the initial value for the
       print job copies and was not updating the UI immediately after creation.

    4. Refactored PrintJobConfigActivity to avoid using the hack to avoid
       reaction for item selection change in a spinner for an event that
       happened before the callback was registered.

    5. Removed the label attribute from PrinterInfo and now PrinterId is
       composed of the printer name and the service component name. This
       is nice since for restarting print jobs we do not need to store
       information about the printer except the printer id which is
       already part of the PrintJobInfo's data. Also the printer name
       is not expected to change anyway.

    6. Allowing cancellation of a queued print job. Also no print job is
       cancelled without asking the managing print service to do that.
       Before we were immediately canceling print jobs in queued state
       but it was possible for a buggy print service to not set the
       print job state to started before starting to do expensive work
       that will not be canceled.

    7. PrintServiceInfo was throwing an exception the the meta-data
       XML for the print service was not well-formed which would crash
       the system process. Now we just ignore not well-formed meta-data.

    8. Removed unused permissions from the PrintSpooler's manifest.

Change-Id: Iba2dd14b487f56e137b90d1da17c3033422ab5e6
2013-08-02 14:22:22 -07:00
Svetoslav Ganov
55b409a97c Iteration of the print sub-system.
1. Added APIs for adding partially initialized PrintInfo objects
   enabling light-weight lookps for print serivces that want to
   populate the list of available printers without querying each
   of them for its capabilities. This includes APIs for the system
   to request from a print service to update certain printers.

2. Fixed a bug in PrinterId#equals().

3. Added equals and hasCode implementaion to PrinterInfo. Also
   the defaul in PrinterInfo are now an array instead of a
   SparseArray - cheaper.

4. Now PrintJobConfigActivity works with partially specified
   printers. Specifically, if such a printer is selected the
   activity is requesting from the print service to update
   the printer. We are currently not handling the timeout case.
   It also handles udpated pritners.

Change-Id: I5e83e924ef597c9e22cbd06a971d4f4d3bd3a9c1
2013-07-31 18:59:53 -07:00
Svetoslav Ganov
85b1f88305 Iteration on the print sub-system.
1.  API changes: Moved copies API from PrintAttributes to PrintJobInfo;
    Changed the PageRange list to an array in PrintDocumentAdapter#onWrite;
    Added onCancelled method to the layout and write callbacks.

2.  Refactored the serialization of remote layout and write commands. Now
    the commands are serialized by the code in the client instead in the spooler.
    The benefit is simple code since the client has to do a serialization to delegate
    to the main thread anyway. The increased IPC found is fine since these calls
    are quite unfrequent.

3.  Removed an unused file: IPrintSpoolerObserver.aidl

4.  Added equals and hasCode implementation to PageRange, PrintAttributes,
    MediaSize, Resolution, Margins, Tray, PrintDocumentInfo.

5.  Added shortcut path for query APIs on PrintJob that return cached values
    if the print job is in a uncuttable state, i.e. completed or cancelled. Failed
    print jobs can be restarted.

6.  PrintJobInfo was not properly serialized.

7.  Updated the look of the print dialog to be stable if there is and there isn't
    currently selected printer.

8.  PrintJobCOnfigActivity now calls onLayout on every print attributes change
    but requests a write only on print preview or print button press. Also if the
    layout did not change the content and it is already written no subsequent
    call is made. Also if the selected pages change and we already have them
    no subsequent call to write is made. Also the app is called with print preview
    attribute set when performing layout and with it cleared after the print button
    is pressed. A lot of changes making sure that only valid actions are enabled
    in the activity (looks like a dialog) at a given time frame. The print job config
    activity is also hidden after we got all the data, i.e. layout and write are done.

9.  The callback from the print spooler to the system are scheduled via messages
    to avoid lock being held during the call. It was hard to guarantee that since a
    method holding a lock may be calling one that would like to release the lock
    at some point to make the callbacks.

10. Print spooler state is persisted only if something changes in a completed
    print job, i.e. not one that is being constructed due the print job config dialog.

11. Fixed a potential race in the RemotePrintSpooler where it was possible that
    a client that got a handle to the remote spooler calls into an unbound spooler.
    E.g: the client gets the remote interface with a lock held, now the client releases
    the lock to avoid IPC with a lock, during the IPC scheduling the spooler has
    notified the system that it is done and the system unbinds from it, now the
    client's IPC is made to a spooler that is disconnected.

Change-Id: Ie9c42255940a27ecaed21a4d326a663a4788ac9d
2013-07-30 17:15:11 -07:00
Svetoslav Ganov
0d1daa50f6 Updating the print dialog and its interactinos with the printing app.
1. Added support for reporting the old print attributes during layout.
   Now we keep track of the old print attributes, so the app can
   compute the delta and decide whether re-layout work is needed.

2. Fixed PrintDocumentAdapter callback interleavings. Layout callbacks
   were intermixing with write ones - a mess. Now we make an attempt
   to cancel layout and write if they respond to cancellation, otherwise
   we wait but do not interleave them.

3. Refactored the PrintJobConfigActivity for easier maintenance and
   to have a single update UI method that does the minimal amount
   of work.

Change-Id: I31ada1a0550882e6185018e6f17f923aed165d15
2013-07-23 18:05:53 -07:00
Svetoslav Ganov
88d199130d Implement persistence/restoring of print spooler state.
1. Implemented the persistence and restoring of the print spooler state.
   The print spooler state is saved as an XML on every print job change
   and is restored when we bind to the spooler. The system does not
   unbind from the spooler until the state persistence completes. We
   are now storing the entire state, i.e. all print jobs, when a single
   one changes. This is not optimal but we are not expecting to have
   many such at the same time, so for now we err for simplicity of
   implementation.

2. Enforcing a non-empty print job name.

3. Hidden the STATE_CREATED print job state which should never be visible to a
   client since this is the state of a print job during construction, i.e. the
   print dialog is up and we are doing back and forth with the app.

4. Fixed some PrintAttributes APIs that were incorrectly taking in a PackageManager
   instance.

5. Updated the PrintSpooler build file due to splitting the framework into multiple
   jars.

Change-Id: I52c88eaa1ec9c64920359cc143c79832a4c3d25b
2013-07-22 13:07:09 -07:00
Svetoslav
597945fd3a First pass of the print dialog UX
Change-Id: I315a16d7f68c73ca180c76e722847b4b1bdea55b
2013-07-19 16:23:12 -07:00