75 Commits

Author SHA1 Message Date
Svetoslav
4e4874bb71 Sometimes printer selection from all printers activity does not work.
1. Sometimes selecting a printer from the full printer list does not
   work if the selected printer was not in the initial drop down list
   of the print dialog.

   The reason was that there is a race. We use loaders in the print
   dialog activity and the all printers one. When these loaders are
   stopped we stop printer discovery since we do not want to keep this
   potentially expensive process on going if the activity is paused
   because say the user decide to press home and start playing his
   favorite game while the printers dialog is up. As a result the
   loader does not get printer updates until it is started.

   The loader of the print dialog activity is stopped while the user is
   selecting a printer from the all printers activity whose loader is
   getting discovered recent printers. Now when the user selects a printer
   the loader of the print dialog activity is started but may not get
   the latest printers by the time onActivityResult is called with the
   selected printer. Now we cache the selected printer id and if the
   loader reports it we select that printer.

2. In the print dialog we show only a few of the discovered printers.
   If the user selects a printer from the all printers activity that
   is not in the initial list we shuffle the adapter data to make sure
   the selected printer is in the shown subset. Now if the printers
   change, i.e. the printers loader reports new result we were not
   respecting the reshuffling made before so the short list of
   printers changes yet again.

bug:11034216

Change-Id: I54fe3619e3328b65839d9f4b02309699eae7f8eb
2013-10-01 19:12:27 -07:00
Baligh Uddin
dd4ce7119f Import translations. DO NOT MERGE
Change-Id: Ie40b704529f71e71f5c384450a79923c68354bb9
Auto-generated-cl: translation import
2013-09-30 09:28:55 -07:00
Svetoslav
d8dbc13b47 Ignore historical printer records for installed services
When loading historical records for previously used printers we
now ignore the ones whose target print service is not installed.

bug:10955652

Change-Id: Ib295e7d88ed3c308ef6d8a11bdc1792ebbb6d526
2013-09-27 18:46:24 -07:00
Svetoslav Ganov
b415525a16 Merge "Print job files and print job records not always cleaned up." into klp-dev 2013-09-28 01:06:51 +00:00
Svetoslav Ganov
c783f6738f Merge "Adding a timeout for waiting to get the selected printer's capabilities." into klp-dev 2013-09-28 00:28:08 +00:00
Svetoslav Ganov
dd68da2741 Print job files and print job records not always cleaned up.
1. We want the files for a print job to be removed as early as possible
   typically because the print job was cancelled, completed, the app
   or the spooler crashed during print job construction. We were keeping
   around in the spooler and hence to disc infos for jobs that are in
   final state since the app that created them may hold a reference to
   a local print job objec whose info it can access to get the latest
   print job state potentially after the job reached final state. The
   issue was that we were persisting to disc created print jobs which
   were during construction which requires careful handling for the
   various cases above. This is tricky and error prone.

   We used to tell the spooler to forget the print jobs infos when the
   app that created them died. The implementation to forget a print
   job was not careful and was nuking currently running print jobs in
   addition to the ones in a terminal state. Further, if the app dies
   before a print job is completed we were left with a stale print
   job in the spooler since we missed the signal to forget it (assuming
   we forget only inactive jobs). These issues suggest that the approach
   is problematic.

   Now we have a cache of print job infos for the jobs an app created.
   This cache is updated when the state of a print jobs changes using
   the new print job state observation code. When the app dies we
   remove the cached jobs for that app. Now if the app calls to get
   the print jobs it gets the cached ones, i.e. the print jobs it
   created during its lifetime, plus the print jobs that are still
   active fetched from the spooler. Note that transient state cannot
   be kept in the spooler since we unbind from it if there is no
   work and it may get killed.

2. Improved the print sub-system logging code to show the cached
   print job infos for apps and also dump the print job PDF file
   names.

bug:10958357

Change-Id: I6f7c1968b6b7ba5be182a10df044ff7ea1fc3a61
2013-09-27 17:26:44 -07:00
Svetoslav Ganov
6be4c76441 Adding a timeout for waiting to get the selected printer's capabilities.
A print service may choose to provide only the printer info and then when
it is requested to start tracking the state of the printer, the service
should provide the printer capabilities. If the capabilities are not
received within ten seconds we mark the printer as unavailable and stop
tracking it.

bug:10748639

Change-Id: I9171cb5dc116fd321c23a8e4ab55109448e2fc6a
2013-09-27 09:43:32 -07:00
Svetoslav
c335eb4115 Printers in the list of printers change position.
1. The printers in the printers list of settings change position if
   they are updated. The settings app is using hidden platform APIs
   the this change fixes.

2. Enable ProGuard for the PrintSpooler.

3. Added icons on the list of printers so the user knows which
   print service used the printer. Now the user can know when
   he is using cloud print and maybe incurring data costs vs
   local printer discovered by a vendor plug in.

bug:10955751

Change-Id: I292f48b424cb561218fdb424d0388f4d786d8339
2013-09-26 18:49:10 -07:00
Svetoslav Ganov
0ce3e8743c Choosing default paper size for the "Save to PDF" fake printer
Change-Id: I1e2eb73fd1eb3b1e9812155b69b94cba261243c2
2013-09-26 13:54:49 -07:00
Svetoslav Ganov
5cab967bf2 Merge "Adding hidden APIs for observing the print jobs state." into klp-dev 2013-09-26 19:22:20 +00:00
Svetoslav Ganov
3adc49c678 Merge "Disallow range selection if the document has unknown page count." into klp-dev 2013-09-26 19:21:06 +00:00
Svetoslav Ganov
c9cfd605a2 Merge "Missed signal in FusedPrintersLoader." into klp-dev 2013-09-26 19:20:28 +00:00
Svetoslav Ganov
027ff3855d Merge "Page range validation edge case handling." into klp-dev 2013-09-26 19:19:39 +00:00
Svetoslav Ganov
953c4143e8 Missed signal in FusedPrintersLoader.
1. In the FusedPrintersLoader we start observing the printers on
   the device and if they change we send the result. If however,
   the printers are already loaded in our session (because it
   joined an ongoing printer discovery) and the pritners do not
   change, the loader never sends its result. Now we are registring
   the callback only after historical printers are loaded. We
   also immediately check after starting discovery whether the
   there are printers in the discovery session and if so deliver
   them.

2. Improved logging in the FusedPrintersLoader.

bug:10940712

Change-Id: Ieb9b897d64780742125b29309462dea3eda170a6
2013-09-26 08:14:27 -07:00
Svetoslav Ganov
ab051baea5 Page range validation edge case handling.
The regular expression for validating range input was missing a
coupe of edge cases.

bug:10906805

Change-Id: Ie793588ecb6697aff3d8d85124a8faeda58c69e5
2013-09-26 00:35:04 -07:00
Svetoslav Ganov
b0e68fdc9c Disallow range selection if the document has unknown page count.
bug:10741878

Change-Id: Ibf2272125e81f14ede3fdfec86aee10b908ade01
2013-09-25 18:32:25 -07:00
Svetoslav Ganov
704697b619 Adding hidden APIs for observing the print jobs state.
This is needed for implementing the print job settigns UI.

bug:10935736

Change-Id: I63b42cbf4ce6a259fa1af47fa368b148ca5621c1
2013-09-25 17:57:07 -07:00
Baligh Uddin
df79953527 Import translations. DO NOT MERGE
Change-Id: I4842b7afb76ee393c19a39d0818f3f2066616803
Auto-generated-cl: translation import
2013-09-25 16:33:59 -07:00
Baligh Uddin
46485d6df6 Import translations. DO NOT MERGE
Change-Id: Id5391f651538cc46ad7455dedaa3426e29efc9c9
Auto-generated-cl: translation import
2013-09-25 08:42:54 -07:00
Svetoslav
2a708617df User should not be able to select unavailable printers.
1. If the printer is unavailable we should not allow the user
   to select it. Rather, show it grayed out.

2. Some string changes requeted by translators.

bug:10917222

Change-Id: I370f05f9c8e70e3f077db7eb02cf48e19a59925d
2013-09-24 15:46:17 -07:00
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