• Home
  • History
  • Annotate
  • only in /frameworks/base/packages/PrintSpooler/src/com/android/printspooler/
History log of /frameworks/base/packages/PrintSpooler/src/com/android/printspooler/
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
dcc34fd8a3f718e5e5cfaccb87eeffd64ac80f63 30-Jul-2015 Chris Wren <cwren@android.com> Instrument printing service for metrics collection.

Bug: 22837316
Change-Id: I8bf62940f5eb495d8d7a10df958d9bc8ad76662a
odel/PrintSpoolerService.java
i/PrintActivity.java
f12b393ff406a3bb8967b69a9be2dd27b0725b33 25-Jul-2015 Svet Ganov <svetoslavganov@google.com> Pass correct extras to the custom print options activity

bug:22734138

Change-Id: Iea1bc32c3e863072b2021b823bef2cefa54fa540
i/PrintActivity.java
5772b5c671a13d9c4bbc1e3803667166f811cb33 11-Jun-2015 Svet Ganov <svetoslavganov@google.com> Propagete document meta-data to custom print UI.

Change-Id: I3f122224e1b311a222969253ae0336177989a414
i/PrintActivity.java
9e9e2e73c6ec7bece20268196dc89ad0c8bafad4 08-May-2015 Wojciech Staszkiewicz <staszkiewicz@google.com> Pass charset to XmlPullParser.setInput instead of null

Passing null to XmlPullParser.setInput forces it to do additional
work, which can be easily avoided if we know the charset beforehand.

bug: b/20849543

Change-Id: Iaff97be9df2d0f99d7af8f19f65934439c9658e2
odel/PrintSpoolerService.java
i/FusedPrintersProvider.java
4a357cd2e55293402d7172766f7f9419815fc1e8 19-Mar-2015 Alan Viverette <alanv@google.com> Replace usages of deprecated Resources.getColor() and getColorStateList()

Change-Id: I8f64fe6c4c44a92ff6d07250223ba590a1d691b0
odel/NotificationController.java
idget/PrintContentView.java
08c7116ab9cd04ad6dd3c04aa1017237e7f409ac 28-Feb-2015 John Spurlock <jspurlock@google.com> Remove unused imports in frameworks/base.

Change-Id: I031443de83f93eb57a98863001826671b18f3b17
odel/PrintSpoolerProvider.java
a7bb6fbeab933326d58aa806d8194b7b13239d34 04-Feb-2015 Dianne Hackborn <hackbod@google.com> First quick implementation of auto assist data.

Introduce new AssistData class that contains all data
the framework automatically generates for assist. Currently
populated with a very simple tree structure representing
the app's view hierarchy.

Reworked how we populate the class name for accessibility
info, so this is provided through a new method call on View
that subclasses can override. This method is also used
to populate the class name in AssistData.

Change-Id: Ibd0acdc8354727d4291473283b5e4b70894905dc
idget/PreviewPageFrame.java
948c9a6393e0995a4d988d5d164998aa0e12b25d 03-Feb-2015 Svetoslav <svetoslavganov@google.com> Add duplex mode support.

This change adds support for duplex printing. The print UI now has a duplex
option which allows the user to choose one of the supported duplex options
by the currently selected printer. The chosen duplex mode is propaged to the
print service that manages this printer.

Change-Id: I807ba9da2723531535c0e1e33f2f4e1b503a54b0
odel/PrintSpoolerService.java
i/PrintActivity.java
eaaf0512fcbf03b926cdbbbb7f54df474ecf861a 26-Nov-2014 Svet Ganov <svetoslavganov@google.com> Crash in print spooler when back pressed before content update complted.

We are updating the printed content asynchronously. If the user cancels
printing before the first update is complete the spooler components are
in a destroyed state but we attempt to handle the completed update resulting
in a crash. Now if printing is cancelled we ignore the update result.

bug:18525491

Change-Id: I1ef47a17de19896cba2c7a1dd2bfc205065e0a5a
odel/PageContentRepository.java
i/PrintActivity.java
c80814e70aea8940d0d43cd7170baae8c0c4e8e3 24-Nov-2014 Svet Ganov <svetoslavganov@google.com> Lockup in the print spooler.

A recent change modified the way we destroy the remote renderer from
asynchronous to synchronous. This caused problems since it was possible
that the remote rendering service is unbound while we are reading the
contents of a rendered page. As a result the reader was blocking on I/O
and the print spooler was getting into a locked state that required a
restart of its process. Now the remote renderer is destroyed
asynchronously.

bug:18498626

Change-Id: I1312bf808f30430728b4038dd4be43c55d2be825
odel/PageContentRepository.java
i/PageAdapter.java
i/PrintActivity.java
i/PrintPreviewController.java
f6cd14dbc99b38af7afe1e5f72347395603d7de2 20-Nov-2014 Svet Ganov <svetoslavganov@google.com> Print spooler crash when printing after a rotation.

1. Available printers are provided by a loader driven by the activity
lifecycle. After a rotation of an app that does not handle rotation
the print activity is destroyed in a delayed fashion. When another
print task is started the loader of the destroed activity gets two
cancellations, one when the activity is stopped and one when it is
destroyed but when the second cancellation happens the loader has a
bad state that it is loading while it is not and a NPE occurs.

2. If a rotation happens early before the print activity is fully initialized
(there are asyncrconous operations that take place) we get a NPE as
the print preview controller is not created yet.

3. A lockup of the print preview process occurs if the print print
activity is destroyed after we initiated binding to the rendering
service but before we receive the remote interface. In this case no
remote service is received as exepcted since we already unbound from
it resulting in a missed signal.

bug:18238590

Change-Id: I81817d81702f649ded97dfbab7d7bba28f22fa91
odel/PageContentRepository.java
i/FusedPrintersProvider.java
i/PrintActivity.java
fce84f035c35606c5707e735f503f7bdcfd5b2a1 01-Nov-2014 Svet Ganov <svetoslavganov@google.com> Crash apps that print malformed or password protected PDFs.

If apps are writing malformed content (typically not a PDF file) or if the
PDF content they provide to the print system is password protected, are now
crashed as both of these are app bugs.

bug:17636435

Change-Id: Ifce6a3199e587448dd38f6a84290a965c24b698b
odel/OpenDocumentCallback.java
odel/PageContentRepository.java
odel/RemotePrintDocument.java
enderer/PdfManipulationService.java
i/PageAdapter.java
i/PrintActivity.java
93134ce87e7b33e599c9ef9ed8b19ec2556ca8f1 31-Oct-2014 Svetoslav <svetoslavganov@google.com> Merge "Save to a PDF file should look like print preview." into lmp-mr1-dev
bec22beb99b279d381f720d761ca75fe3e7414dc 25-Sep-2014 Svetoslav <svetoslavganov@google.com> Save to a PDF file should look like print preview.

When rendering a PDF file for print preview we take into account
the selected print options such as paper size, orientation, etc
without modifying the document. To print we send the doc in its
original form and the print options so the print service can apply
the necessary transforms in addition to the optional custom options
it supports. When saving to PDF we have to actually change the
document as we act as a print service.

bug:13545980

Change-Id: Icdcecf962bec6ff742cc6015df5af9d9086ce760
enderer/IPdfEditor.aidl
enderer/PdfManipulationService.java
i/PrintActivity.java
7c053c1e414c77ae28adb90390027e21ce57bc5e 29-Oct-2014 Svetoslav <svetoslavganov@google.com> Print preview disappearing if printer is changed.

This is a regression caused by my previous patch.

Change-Id: I80a0b4d880fd4e48e6a44fac303a4c8204e8ec0d
odel/PageContentRepository.java
b32f04b785306f06d7d07b824fb8dcc1b4a61aa6 25-Oct-2014 Svet Ganov <svetoslavganov@google.com> Merge "Printing from two apps at the same time not working." into lmp-mr1-dev
99a82437ed8e0537d9a355a124d2bb30aea46ad8 25-Oct-2014 Svet Ganov <svetoslavganov@google.com> Printing from two apps at the same time not working.

When printing from two apps at the same time the second print UI is
getting stuck. There were a couple of issues here:

AdapterView was not notifying for item selection if the data changes
after scheduling a dalayed selection notification and the notification
execution. The code assumed that a layout pass will occur and posponed
the notification after the layout pass but it is not guaranteed that
such a layout pass will occur. Now we delay only if a layout pass is
being scheduled.

Also when binding to the PDF rendering service the print spooler was
using the same intent and as a result two print activites were getting
the same renderer instance while they should get separate ones. Now
we use different data in the intent to ensure we get separate renderer
instances.

Change-Id: I6aa7c7b041957804b4273549dd837a6d70064efc
odel/PageContentRepository.java
7cf7c364386d18b94d212d98072e97c1c3d87e26 24-Oct-2014 Svet Ganov <svetoslavganov@google.com> Merge "Crash in print spooler if printing app killed from recents." into lmp-mr1-dev
4237c92d850b7fb0fa0be15df94e4d1689e353fc 24-Oct-2014 Svet Ganov <svetoslavganov@google.com> Crash in print spooler if printing app killed from recents.

If the printing app with the print UI on top is killed from recents we get
a crash because: 1) the remote print document was not transitioned to a
failed state if the printing app dies (this is an unrecoverable failure);
2) the print preview controller was destroyed asyncronosly during which it
also asynchronously disconnects from the rendering service which however
happens after the system has already cleaned up all connections of the print
UI activity as it is being destoryed.

bug:18109386

Change-Id: If6200b14a8aa90622228bbb659e9c4962226f561
odel/PageContentRepository.java
odel/PrintSpoolerService.java
odel/RemotePrintDocument.java
i/PageAdapter.java
i/PrintActivity.java
i/PrintPreviewController.java
2916f658c9a55aa5b08a3bbe3056dbfd78e0e1b0 24-Oct-2014 Svet Ganov <svetoslavganov@google.com> Sometimes historical printers not properly ordered.

We order printers based on past usage. In some cases the ordering
does not work. The reason for that was an incorrect assumption that
the entries in an ArrayMap are ordered in the order they are added.

bug:18109283

Change-Id: Ie367e4ca5e6bd79f335a060074c9211054e3a931
i/FusedPrintersProvider.java
9920a0dcf15ba2036cdcc5d6548efa6b4a8bc944 24-Oct-2014 Svet Ganov <svetoslavganov@google.com> Merge "Set copies to one when saving to PDF." into lmp-mr1-dev
45e50e99cdb10b43b062612c2e87e75841f2c424 23-Oct-2014 Svet Ganov <svetoslavganov@google.com> Set copies to one when saving to PDF.

One can save only one copy to PDF. Showing more that one copy when saving
to PDF enven in a disabled input box is confusing to the user. We now set
the copies to one when the PDF printer is selected.

bug:17631303

Change-Id: Ia04d144efc899e7f3836c19349d9c87f3ae8f0f0
i/PrintActivity.java
0c8e15c016efa64cc8db6a1f1fbcade34543cf3f 15-Oct-2014 Svetoslav <svetoslavganov@google.com> am 60cdb909: am 0a1ffdb3: Merge "Handle if the printing app is killed while saving to PDF." into lmp-dev

* commit '60cdb909304f0d4b93a1a17228bdcc888f16cf41':
Handle if the printing app is killed while saving to PDF.
05e041b013d8750a66787f5f7eb77c7ec95a670f 14-Oct-2014 Svetoslav <svetoslavganov@google.com> Handle if the printing app is killed while saving to PDF.

When saving to PDF we bring up the file picker UI which covers
the print UI. In this case the printing app may get killed as
it is not in the forground (the system is bound to the print
spooler so it cannot get killed). If that happens we are ending
up with an empty file. However, if the file chooser UI is up
we already have everything from the app we need and it dying
does not matter. This change takes care if ignoring printing
app death while saving to PDF.

bug:17922948

Change-Id: I10d808e3c3e93e850dbc2a948f2482381a887928
i/PrintActivity.java
2eb7fadcd64120f0e94ebb0f91188900e916c559 02-Oct-2014 Svet Ganov <svetoslavganov@google.com> Custom print settings cannot change resolution.

bug:17677133

Change-Id: Ib8a24101f12d431fe221c1e91711d93a6a517273
i/PrintActivity.java
922fcc2f9e2370b34672af0e91e5754c6f8d6da7 28-Sep-2014 Svetoslav <svetoslavganov@google.com> Merge "Crash in print spooler if save to PDF selected early." into lmp-dev
e1dcb397d595c110faadaae6bab861bae97717b8 27-Sep-2014 Svetoslav <svetoslavganov@google.com> Crash in print spooler if save to PDF selected early.

The first issue is that the save to pdf button is enabled
before the first layout completed and at this point we do
not know anything about the document. The second is that
if a layout is in progress and we select save to pdf we
end up starting the documents UI twice and finishing the
second instance carshes the spooler.

bug:17676878

Change-Id: Id0b1f06e4d377347286c2dde09669d431441234b
i/PrintActivity.java
528424c26cb118a68f77cef94992a0282cfdc12c 27-Sep-2014 Svetoslav <svetoslavganov@google.com> Fix carsh in print spooler if custom print setings return bad pages.

The custom settings activity of a print serivce can change the selected
pages and the spooler was not checking whether the returned pages were
valid leading to a crash.

bug:17678553

Change-Id: Id8ea3d482d2909b97a06752d61b416dfe5948483
i/PrintActivity.java
d23bfa9d42c477970189a96d4562d627d609e604 24-Sep-2014 Svetoslav <svetoslavganov@google.com> Print spooler should not crash if fed non-PDF content.

It is possible that a buggy app breaks the contract and provides
content to be printed in format other than PDF. This was leading
to a crash in the print spooler. This change fixes the crash and
shows a user friendly error message.

bug:17642690

Change-Id: I5a4acb06080a152562655da6851467b3e71d8658
odel/PageContentRepository.java
enderer/PdfManipulationService.java
2bac6129a46b89c5e361fafc2c23b16c5716f847 24-Sep-2014 Svetoslav <svetoslavganov@google.com> Merge "Missing pages in print preview when scorolling." into lmp-dev
237806bbc540938a87a26b53f117c82ce75025fa 24-Sep-2014 Svetoslav <svetoslavganov@google.com> Missing pages in print preview when scorolling.

It is possible that two providers for the same page are assigned
to two preview views despite temporariliy while rebinding. We were
however releasing the provider from the view which is being bound
if not for the same page which as a result was cancelling rendering
of this page which is provided to another view via another provider.
Hence, having an empty page. Removed the unnecessary code to release
a provider when binding the view - release is happening only if the
view holder is recycled.

bug:17515670

Change-Id: I197438c16cfdb363f521cd1320f154da54eea5f5
i/PageAdapter.java
09eb0b203329b1d846de227a8b03774c903b86f0 24-Sep-2014 Svetoslav <svetoslavganov@google.com> Merge "Fix ANR in print spooler." into lmp-dev
56683481381003325481143af15d519c1bf0148f 24-Sep-2014 Svetoslav <svetoslavganov@google.com> Fix ANR in print spooler.

Saving to PDF a subset of the pages requires trimming the
undesired pages and when this is done writing the ready doc
to a URI. To write the file to URI we have to obtain it but
it is aquired by the shredding task and never released. Now
we are releasing the document immediately after trimming it.

bug:17631301

Change-Id: I4db7966c65c75f0f14c3cb52fd83b4d8fd5a4687
i/PrintActivity.java
254361f136aa9461e16f11f0170fde05e83a1b92 24-Sep-2014 Svetoslav <svetoslavganov@google.com> Print spooler crash on back before first layout is complete.

If the user presses back before the remote print document
update has completed we get a crash. The reason is that
after the update completion we were trying to finish the
activity if we are in a cancelled state but this is not
needed as we aready handled the back key so we will finish.
Handling finish twice was creating the problem as classes
with lifecycles are not designed to be used after being
finished. In particular, we were calling doFinish() twice.

bug:17630561

Change-Id: If418f237a2def7c8e4a072ac8826283f4dd7fc85
odel/PageContentRepository.java
i/PrintActivity.java
cf3a86b55981313e1fdfafbef89ab5ba7276a862 22-Sep-2014 Svetoslav <svetoslavganov@google.com> Loosen the constraint for releasing a shared file.

In the spooler we have the renderer reading a file to visualize
content and the app writing a file to produce the content. Since
we have to swap the file under the renderer we have a mutex file
provider that both parties can request, use when released, and
release when required. This enables us to request the file which
closes the renderer and when the renderer is closed ask the app
to write some more pages, then open the renderer, and so on. The
mutex file provider was throwing of a thread that does not own
the file thries to relase it which is not needed, this should be
just a nop.

bug:17607134

Change-Id: Id6a2ce92d70077f57978b95315648faf02c13c68
odel/MutexFileProvider.java
9424b733c7f777fc806a751a7f00d234c11c0e7c 19-Sep-2014 Svetoslav <svetoslavganov@google.com> Fix a print spooler crash when printing.

The spooler communicates with he remote PDF renderer asynchronously.
When print is confirmed we close the renderer, destroy it, and unbind
from its service. If we unbind from the service after the print activiy
is finished we get a crash. The bug was that we did not wait until we
disconnect from the remote renderer before finishing the print activity.

bug:17583115

Change-Id: I55b0135f9c5658b3a4fda2901b8b3bdef044e211
odel/PageContentRepository.java
i/PageAdapter.java
i/PrintActivity.java
i/PrintPreviewController.java
b75632c7366d3c848a5d31782d9942dd2818adcb 18-Sep-2014 Svetoslav <svetoslavganov@google.com> Print UI stuck when backing out of documents UI.

When user chooses to save to PDF we open the document chooser UI.
Now if the user now backs to the print UI without choosing a file,
the print UI has all options disabled and the back button does
not work - the user is stuck. This is because we were not
transitioning the print UI in the correct state.

bug:17557454

Change-Id: I385129e106ed41564b89137ca54d409127ba8ff0
i/PrintActivity.java
0d2d9637ed4f46062d508cfa7da0e9776fc444f8 18-Sep-2014 Svetoslav <svetoslavganov@google.com> Page content sometimes missing in preview when scrolling.

Removed the restriction for the page content providers to
be singletons as the RecyclerView may hold on views with
providers and ask us to bind other views for the same page.
Note that the views that RecyclerView is holding will be
soon rebound or recycled just they are not at the time we
bind other views for the same position. We were guarding
against this but caused some pages not appearing sometimes
on scrolling. Also now keeping the media size and magins
of recycled page view (will be updated if needed on
rebinding) or avoid changes of the background to null as
setting it to not null later causes an undesired layout pass.

bug:17537922

Change-Id: If029f6c413e15d4f5c1ba1ac5e4d52ad2cad5904
odel/PageContentRepository.java
i/PageAdapter.java
7fd5ada98aa9e035682531d9fe25633fdd24a058 16-Sep-2014 Svetoslav <svetoslavganov@google.com> Page content sometimes disappears when scrolling a long doc in print preview.

The operations of the remote renderer have to be performed in order, open,
render some pages, close. One of the tasks was executed on the wrong executor
resuling in a race and an occassional bad state.

Also fixed a NPE if the preview list is flinged and then the user presses
back.

bug:17537922

Change-Id: I5048078ba2b875a2a8335f3a4324afaa34d014a2
odel/PageContentRepository.java
i/PageAdapter.java
i/PrintActivity.java
i/PrintPreviewController.java
idget/PageContentView.java
e9f275d309bfe314921dba51dd7c90686f2748bf 16-Sep-2014 Svetoslav <svetoslavganov@google.com> Merge "Print preview disappearing on screen off/on." into lmp-dev
d724a40136f168251f6f62e5a51ad73bf8fe5d1e 16-Sep-2014 Svetoslav <svetoslavganov@google.com> Print preview disappearing on screen off/on.

We were not clearing the tracked printer when the print activity is
paused and then not setting the tracked printer when the activity
is resumed.

bug:17525271

Change-Id: Ib0fb29006bfcf5ad03dce24b3407cd96dc421442
i/PrintActivity.java
23d3361e1747ee286157f9c61c3d02e6e20cac58 16-Sep-2014 Svetoslav <svetoslavganov@google.com> Do not change fragments if print activity finishing.

It is possible that we try to switch framents after the print
activity finish method is called. In this state the activity
is going away and trying to perform a fragment operation throws.
Now if we are finishing no fragment opration is performed.

bug:17520007

Change-Id: I0dd935d3cdaeddca31fccf49bd5de97e878abb9d
i/PrintActivity.java
e3cdd4dc6cc3188d5d1fdecb37798e49887f6d5f 16-Sep-2014 Svetoslav <svetoslavganov@google.com> Merge "Missing or wrong pages in preview when scorlling large docs." into lmp-dev
f3f963b0bebea91b17f7e60d9b826c458bfde38c 16-Sep-2014 Svetoslav <svetoslavganov@google.com> Missing or wrong pages in preview when scorlling large docs.

The bound pages in the adapter were not properly tracked, more
specifically we did not remove pages from the bound set ending
up in a bad state. Also when the printer changes and if the
new one has different page size the content disappears due to
us not notifying for the data set change.

bug:17515670

Change-Id: Iac74e864609012f6804584fa133e87c27dc186a5
i/PageAdapter.java
i/PrintPreviewController.java
56bdeeeb80d31d2c299a7e55b233658b5bc6fe01 16-Sep-2014 Svetoslav <svetoslavganov@google.com> Merge "Page shredder callback invoked on the wrong thread." into lmp-dev
fb3532eea391574cda69cae274915e9e1a7b6cf2 16-Sep-2014 Svetoslav <svetoslavganov@google.com> Page shredder callback invoked on the wrong thread.

The code executed in the shredder completion callback must
be called on the main thread but instead it was called on
another one. This led to a crash.

bug:17514533

Change-Id: Id9e86d38a90fedadc60f967b193470fd83eb3362
i/PrintActivity.java
e0fa06c088ea95a01c0219e9711c3bcc93ad2685 16-Sep-2014 Svetoslav <svetoslavganov@google.com> Update print preview when a printer becomes available

We laizily request printer capabilities and when they are reported
we were not updating the preview and as a result the content was not
rendered, hence pages showing an empty state.

bug:17514117

Change-Id: Icfee7eaa1ab63f5e4d7655d4057ef2110c27cd43
i/PrintActivity.java
e771caf332bb3f2b668aaf249b30f37f13755553 15-Sep-2014 Svet Ganov <svetoslavganov@google.com> Fix a crash in pring spooler.

If the printer capabilities are reported with a delay which is pretty
common we were trying to evaluate the preview page dimensions without
having a media size resulting in a NPE.

bug:17501953

Change-Id: I6765137f61b8fd060e9eabff07e632875d934963
i/PageAdapter.java
2047df6f5f6af14cdb93f220c0329f1bff7a43ff 13-Sep-2014 Svetoslav <svetoslavganov@google.com> Merge "Page content sometimes missing while scrolling." into lmp-dev
05ff998fd86eff15e91694bc205ea0af0de83284 13-Sep-2014 Svet Ganov <svetoslavganov@google.com> Fix a crash in print spooler.

A recent bug fix exposed another one where we were not updating
the internal state of the remote print document after it finishes
updating. This resulted in a crash on every print.

bug:16966145

Change-Id: I398ff7976533241e3d4cb6cd27f69cdc25e67be9
odel/RemotePrintDocument.java
e6ecba59fd618b80dd13f581b625eea420672a0a 12-Sep-2014 Svetoslav <svetoslavganov@google.com> Page content sometimes missing while scrolling.

The logic when a page view to request the content had a logical
error and it was getting in a bad state where it never requested
the content anymore. This change simplifies the logic and minimizes
the kept state.

Removed unnecessary calls to recycle for a bitmap as according
to the graphics folks we should not be calling this API anymore.

bug:16966145

Change-Id: Idda8314b43343136d3b867167261790481116fac
odel/PageContentRepository.java
idget/PageContentView.java
2fb64a5cb160a2615f07ed669aa5738dbb74ad6c 12-Sep-2014 Svetoslav <svetoslavganov@google.com> Fix crash in spooler if printing app dies.

bug:16966145

Change-Id: I092c489a7f1b4000a96d3f12f2996ccabf734b9a
odel/RemotePrintDocument.java
139ba7fb0ed976bdbc7c283e3f7fe9980eed22a6 12-Sep-2014 Svetoslav <svetoslavganov@google.com> Fix a crash in print preview on multiple rotations.

bug:16966145

Change-Id: I8266315bd9253953cb6c3b9dab1ba36f104a74a5
i/PageAdapter.java
i/PrinterRegistry.java
36f6951e325feb32f9fe61a80e120dacfd41d473 12-Sep-2014 Svetoslav <svetoslavganov@google.com> Merge "Fix back button behavior and clean up in print preview activity." into lmp-dev
c946e9ab465fd363dc996efbffcf58f354266aaa 12-Sep-2014 Svet Ganov <svetoslavganov@google.com> Merge "Fix edit text error state in the print UI." into lmp-dev
e17123dd6d3666c88b47172b8efc995523b47346 11-Sep-2014 Svetoslav <svetoslavganov@google.com> Fix back button behavior and clean up in print preview activity.

The print preview UI owns and drives the lifecycle of several objects.
These objects were torn down too late resulting in an attempt to use
the activity as a context when it was no longer valid and service unbind
resulting in causing a crash.

Fixed a bug where if the back button is pressed mutiple times when
the print UI is being initialized a crash occurs.

bug:17454041

Change-Id: Ic1455b467586f0ad65f907e2160ec5cfb2d17d05
odel/PrintSpoolerProvider.java
odel/RemotePrintDocument.java
i/PrintActivity.java
i/PrinterRegistry.java
43212264dd0eaa5deea6539b8d4eb3a3edd7d22d 11-Sep-2014 Svet Ganov <svetoslavganov@google.com> Fix edit text error state in the print UI.

If the user input in the print UI is invalid we show an error icon
next to it. The design requires no error message being shown in a
popup but TextView does show the popup all the time.

bug:16966145

Change-Id: I7aa1ec8093bc76e2f440bcb243609e92e049786b
idget/CustomErrorEditText.java
e03ddd0bcc683b31f155bfd96f543c38539abf44 11-Sep-2014 Svetoslav <svetoslavganov@google.com> Merge "Fix a crash in print spooler." into lmp-dev
c65510a7bc0a1519c5633940bce52d7f2334b640 11-Sep-2014 Svetoslav <svetoslavganov@google.com> Merge "Accessibilty support for the print UI." into lmp-dev
3ef8e203c887a0cf6c121fdbb428e2fcef21758a 10-Sep-2014 Svetoslav <svetoslavganov@google.com> Fix a crash in print spooler.

1. Leftover code was setting the state to configuring
before initialization is complete.

2. We were not cancelling the print job if cancelled
when initializing.

3. The remote print document was cancelled even if
doing nothing.

bug:17451600

Change-Id: I79a80b723af8537da260012470748b4e8831fd9e
i/PrintActivity.java
fc81bfe3fb43296ca7040b8f259e1cbec50898ca 10-Sep-2014 Svetoslav <svetoslavganov@google.com> Merge "RTL support for print UI." into lmp-dev
e652b02d45bbda11c9cb8f663fa7f25903b90225 10-Sep-2014 Svetoslav <svetoslavganov@google.com> Accessibilty support for the print UI.

bug:15816751

Change-Id: I5dcdbdd0357843b870ddd47d7c41cfba114d194c
i/PageAdapter.java
i/PrintActivity.java
idget/PageContentView.java
idget/PreviewPageFrame.java
idget/PrintContentView.java
3ab1ec05491d5da8eea070889c03b6ea4f2af5bc 10-Sep-2014 Svetoslav <svetoslavganov@google.com> RTL support for print UI.

bug:16966145

Change-Id: I488d11f1941545630d52eea4c4d48c43667c6067
idget/PrintContentView.java
idget/PrintOptionsLayout.java
dfa3e7c6fd4e8a28ba51b54c769b891191459012 10-Sep-2014 Svetoslav <svetoslavganov@google.com> Fix page spacing in preview list.

bug:16966145

Change-Id: I2c4bde3a50ee0fc202fc169a63d4eeeb43c5f4ae
i/PageAdapter.java
62ce332c141cf7bc7200c4c87d63e395874fc3ec 05-Sep-2014 Svetoslav <svetoslavganov@google.com> Trim unnecessary pages when printing.

A user may request a subset of the document's pages to be printed.
In this case the expectation is that the resulting document does
not include not selected pages. While print serivices can do the
trimming themselves or the printer may do so, moving, potantually
many, redundant pages is inefficient. The real problem is when
saving to a PDF file where the saved file must not have the pages
the user did not select. This change adds shredding of undesired
pages from the PDF before saving it or passing it to a print service.
:
bug:17285994

Change-Id: I7deba535af99457bea3c118202314f0f3812e809
odel/PageContentRepository.java
enderer/IPdfEditor.aidl
enderer/IPdfRenderer.aidl
enderer/PdfManipulationService.java
enderer/PdfRendererService.java
i/PrintActivity.java
i/PrintPreviewController.java
6552bf3da60159607d9266eb295ee3c448f6c3de 04-Sep-2014 Svetoslav <svetoslavganov@google.com> Print spooler UI polish and bug fixes.

1. Added an empty state for pages that are being rendered.

2. Fixed a NPA on a binder thread when destoroying the
remote print adapter.

3. Fixed a rare crash when the print activity gets an
activity class callback while initializing.

4. Changed the preview pages on phone in land to four.

5. Fixed a flicker from a list of pages to an empty state
and then back to the list of pages.

bug:15704969
bug:16966145

Change-Id: I0eea2f30a102d8fefcbf90187fa6d8612fb19434

Conflicts:
packages/PrintSpooler/src/com/android/printspooler/widget/PageContentView.java
odel/RemotePrintDocument.java
i/PageAdapter.java
i/PrintActivity.java
i/PrintPreviewController.java
idget/PageContentView.java
d0c362de1c23b6113fc35236c2908d71cfad7877 05-Sep-2014 Svetoslav <svetoslavganov@google.com> Fix broken aidl

Change-Id: I2187abd75b4f60e790b747a492ad610592f2ef53
enderer/IPdfRenderer.aidl
53dcd394aa389e1e80aa1113be38255716bf2e4c 05-Sep-2014 Svetoslav <svetoslavganov@google.com> Update FrameStats API per api-council request.

bug:17390382

Change-Id: I50518834569f4d0ec394709294537256f03530e0
enderer/IPdfRenderer.aidl
def58cbffc32d12445b60ed1a0d8bb81d8dc6625 04-Sep-2014 Svet Ganov <svetoslavganov@google.com> Merge "Switching to raw byte copy of bitmaps for print preview." into lmp-dev
8c07e8d2a370a6d59dfe5150af3b07ff031ac165 04-Sep-2014 Svetoslav <svetoslavganov@google.com> Merge "Fix some print UI issues." into lmp-dev
9e795e19c7f900fb2636c5dff3ba30098da65f1b 03-Sep-2014 Svetoslav <svetoslavganov@google.com> Unregister from the remote renderer only if bound.

bug:8213791

Change-Id: Ia9efa33331437c4db447acf0c510d4cb4932a593
odel/PageContentRepository.java
df6444931b030d3cdd9769e23f16f0a16fe9c654 30-Aug-2014 Svet Ganov <svetoslavganov@google.com> Switching to raw byte copy of bitmaps for print preview.

Using compression and decompression for moving bitmap data
acorss processes is slow as compression is expensive. This
change switches to using direct streaming of the bitmap
data.

bug:15938254

Change-Id: I78bc450031ee60ada4c3b66f14586a73c72ce34f
odel/PageContentRepository.java
enderer/PdfRendererService.java
til/BitmapSerializeUtils.java
idget/PageContentView.java
6f249835a4ff9e7e7e3ca0190b7ecf72e689656d 03-Sep-2014 Svetoslav <svetoslavganov@google.com> Fix some print UI issues.

1. Fixed a crash when orientation changes and the content
is scrolled due to wrong size bitmap being requested.

2. Closed a file dscriptior that was being left open.

3. Clearing the bitmap before passing it to the renderer to
ensure it is white for pixels not touched when rendering.

4. Removed debug logs.

5. Switched to the correct layout manager for RecyclerView.

bug:16966145

Change-Id: I8ab9d22635c93cac5ff85c6f4b5d82e58cd8df5c
odel/PageContentRepository.java
odel/RemotePrintDocument.java
enderer/PdfRendererService.java
i/PrintPreviewController.java
idget/PageContentView.java
561b8931742503d58ae842edea790e86f359870f 02-Sep-2014 Svet Ganov <svetoslavganov@google.com> Merge "Move print rendering in an isolated process." into lmp-dev
13f542cabd635c55ade5442764cc4a3d2f7880ea 30-Aug-2014 Svet Ganov <svetoslavganov@google.com> Move print rendering in an isolated process.

Security review of the PDF rendering code revealed that it is
not sercure. Therefore, this code must be run in a sandbox.
This change moves the rendering code in an isolated process.

bug:16897933

Change-Id: I711ce42a56892db1837950137bfaa79e1d61a7c4
odel/PageContentRepository.java
enderer/IPdfRenderer.aidl
enderer/PdfRendererService.java
i/PrintActivity.java
i/PrintPreviewController.java
idget/PageContentView.java
c404cacd3a480776dd625fb300810ffccc5f51b0 28-Aug-2014 Svetoslav <svetoslavganov@google.com> Print UI polish.

1. Fixed an issue where input focus is given to the copies
edit text every other time we expand the options UI. We
want focus there only if the user touches the control.

bug:16966145

2. Fixed the all printers list view to have item dividers
reaching the left and right ends of the list view.

bug:17288761

3. Fixed an issue where the user can deselect all pages
which is not only an invalid state but also causes a crash.

bug:17286198

4. Tweaked the minimal size of the preview in landscape on
phone to better accomodate the page.

bug:17288904

5. Fixed a regression introduced by a change from the UI folks.

Change-Id: Ida7dad7eea413295a840028060810b2619c616e8
i/PageAdapter.java
i/PrintActivity.java
idget/FirstFocusableEditText.java
idget/PrintContentView.java
9c9888b8c59e35717ecfc32e9b96fb8702ceb480 27-Aug-2014 Svetoslav <svetoslavganov@google.com> Fix a crash in PrintSpooler.

If the user cancels printing we cancel the current
pring operation in the RemotePrintDocument which is
a state machine enforcing valid state transitions.
A valid transition was not allowed: finishing after
canceled.

bug:17182301

Change-Id: Iccf3a78d7dc736a64bf5c44941a8f8064dcd0ec3
odel/RemotePrintDocument.java
3c238245eb3c0a7371fb25b6e96be0a0056a638d 19-Aug-2014 Svetoslav <svetoslavganov@google.com> Update the "More options" button in printing.

The "More options" button needed changes to match the
new UX spec. Also fixed some identation issues as well
as a missing marging in the erorr UI.

bug:16301066

Change-Id: I29f0d41915d1816d754f2c6288a7387aafeba2c2
i/PrintActivity.java
idget/PrintContentView.java
255dd04271088590fedc46c8e22b2fd4ab142d39 19-Aug-2014 Selim Cinek <cinek@google.com> Added notification color to all system notifications

Bug: 17128331
Change-Id: I81a94510ef51b99916f314c0dd65852426a1fbeb
odel/NotificationController.java
309f6a0e1b2ec39bd516fdfe217a526fe4b8acf6 19-Aug-2014 Svetoslav <svetoslavganov@google.com> Update the print spooler icon.

Removed a duplicate resource also defined in the platform
resources. Added a tint to the print spooler icon.

bug:16568027

Change-Id: I1c0b9a7bd75bc59d1d86653c05d8fc2bb77056c1
i/SelectPrinterActivity.java
38781bd2c2c61385651314098b4a615cb8e8efa1 12-Aug-2014 Svet Ganov <svetoslavganov@google.com> Fix some minor print UX bugs.

1. The last row of print options was not visible on a phone.

2. The preview page size on a phone in landscape unusably small.

3. Updated the Save to PDF icon.

bug:16966145

Change-Id: I25ce1572758c62f34344683af2452fb045bb857e
i/PageAdapter.java
i/PrintActivity.java
idget/PageContentView.java
idget/PrintOptionsLayout.java
b59555ca743118c45103c0c11aedeefb8893f0f0 24-Jul-2014 Svetoslav <svetoslavganov@google.com> Print to PDF putting a pring job in a wrong state.

When printing to a PDF file we get a Uri from the storage APIs
and write the content. Once the file is written to storage the
print job is completed and there is print service involved. Th
spooler was wrongly putting the job in a failed state instead
of a complete state.

bug:16522267

Change-Id: I4741c9b9eb763e118e7dfb2c7c502bd7fc13f7a1
i/PrintActivity.java
5ef522bc19cc9fc1af48cccd2865744228c5ec02 24-Jul-2014 Svetoslav <svetoslavganov@google.com> Handle wrong file format when printing.

PDF is the only format suppored for printing but a buggy app
can write content in another format which was crashing the
print spooler. Now we are generating an error instead of
crashing.

bug:16487161

Change-Id: Ic59d2ac6d57213f4e8f364659d8dc7df2140e61d
odel/PageContentRepository.java
i/PageAdapter.java
i/PrintActivity.java
f8ffa567b5ac418b72268ae01fe8401b801268c7 24-Jul-2014 Svetoslav <svetoslavganov@google.com> Updating the save to PDF button icon.

Change-Id: Ie62a22d6e16d15426f10afa0512b0083c52ff507
i/PrintActivity.java
753c114d84328219a0ccbffdd462a69e04ef8c4f 15-Jul-2014 Yigit Boyar <yboyar@google.com> Update RecyclerView scroll listener to the new API

Bug: 16054949
Change-Id: I264a701e8b298a08f09bb30284099734054d518c
i/PrintPreviewController.java
cc2b210ff8d4aefc890c016e4d352f069a5d3eef 16-Jul-2014 Svetoslav <svetoslavganov@google.com> Merge "Update the promoted action background color per UX spec" into lmp-dev
4bcc4a042c760a776ef52a0f727331db3fa315d2 16-Jul-2014 Svetoslav <svetoslavganov@google.com> Update the promoted action background color per UX spec

bug:16303010

Change-Id: I54663a0be79b232a29d8fced4a772a32b4d83ae5
i/PageAdapter.java
e323dcc31d403085d6ede0f8884c816f4420ef25 16-Jul-2014 Svetoslav <svetoslavganov@google.com> Drop of the final UX assets for printing.

bug:15705610

Change-Id: I82104a2c0b3d1f4e34f71357b10bed24c0583e71
i/PageAdapter.java
73764e347d387657b3e2f8027d135de612cf454f 16-Jul-2014 Svetoslav <svetoslavganov@google.com> Update the page count in the print UI to meet new UX.

bug:15912257

Change-Id: I1aa3eb4f7e28d3d9c955f60a570c2f8800fdb88d
i/PrintActivity.java
38408ff5b7203f811644961637fde85eb7a34387 15-Jul-2014 Svetoslav <svetoslavganov@google.com> Remove text selector and hide ime on print options close.

bug:16301754

Change-Id: I69bf09df9976b12c611821737eb4abb794c1df80
idget/PrintContentView.java
41233447f9c2368946ef1266ae339c71cbe310b1 16-Jul-2014 Svetoslav <svetoslavganov@google.com> Merge "Drop of the final UX assets for printing." into lmp-dev
67eb5bbd5374fe96209cf7b68543cb48ee959b96 16-Jul-2014 Svetoslav <svetoslavganov@google.com> Merge "Update the page count in the print UI to meet new UX." into lmp-dev
5150bcba8e72165baa061d7648e4f2f1e49fc424 15-Jul-2014 Svetoslav <svetoslavganov@google.com> Merge "Remove text selector and hide ime on print options close." into lmp-dev
17d734fee434ca4a37104b783a78fabcda0ac2a5 14-Jul-2014 Svetoslav <svetoslavganov@google.com> Page size not always adjusted

A user can select the pages to print by selecting a range from the
UI after which the selected pages appear in the preview list. Now
the user can further prune pages by clicking on them. If the number
of pages change to two or one the page position and size were not
adjusted. Now after the constraints of desected by clicking pages
are propafated the page size position is also computed.

bug:16297811

Change-Id: I62c0ae8ab5b1d91b120cbf9faa9653ef4ccbd97f
i/PageAdapter.java
25885ecbe4306165872c1b24628e9646778a0535 14-Jul-2014 Svet Ganov <svetoslavganov@google.com> Rename historical records if printer name changed.

We keep track of previously used printers. It is possible that the name
of a previously used printer changed. In this case we want to change
this printer's name in the historical records to be able to show the
correct name in the UI when loading the history.

bug:13524346

Change-Id: I0a37bd52a564df5a84c816abfcf03db83de93b97
i/FusedPrintersProvider.java
a4ab780877808dbee334f7c7cc4acefa0aa313b2 14-Jul-2014 Svet Ganov <svetoslavganov@google.com> Fix broken actions in print notifications.

The notification handling broadcast receiver was renamed but the
manifest was not updated, hence the receiver was not registered.

bug:16289408

Change-Id: I094e20e472abff1f926e1dbfbac32f422f498f74
odel/NotificationController.java
6f60e56b3c37839dfec1a9fb61c52fa2c631a5cb 14-Jul-2014 Svet Ganov <svetoslavganov@google.com> Improve print options click to open behavior.

When print options are closed we show a summary and a handle to open
the options panel. Often the user instinctively clicks on the summary
and also the expand handle is a somehow small target. To improve user
experience clicking on the summary also opens the print options.

Change-Id: Ia2f3b80f5acf11b40af864729f67fa29e82729fc
idget/PrintContentView.java
9fb7b07c6cbdd1c6f394bfc456ccc034619b6727 14-Jul-2014 Svet Ganov <svetoslavganov@google.com> Dimming deselected preview pages

For print preview we show the pages the user selected in the range
affordance but the user can optionally further prune pages to be
printed by deselecting them in the preview. The deselected pages
change elevation and now also are dimmed.

bug:15912256

Change-Id: I53357b8e8b592387bbc26b937eda786bb4660d85
i/PageAdapter.java
48fec5c9a3e4d78bc4cd175fae05be153ac587af 14-Jul-2014 Svet Ganov <svetoslavganov@google.com> Top printer not properly selected.

We keep track of historically used printers and when the print dialog
is opened we load them. We were selecting the first printer before the
historical ones are loaded which led to a case where the PDF printer
is selected and then a better printer appears but we have the PDF one
selected.

Also we were asking the printer spinner for the current printer but
if the data set of the adapter changes and we ask the spinner for the
selection we get a wrong answer because the adapter and the view are
off sync since the view is updated on the next message.

Change-Id: I0c12d2d3b19227a8f6af6e421b92013ec06cc021
i/FusedPrintersProvider.java
i/PrintActivity.java
i/PrinterRegistry.java
39afc200f299ffd7e6a2a507017c3de2a548f877 12-Jul-2014 Svetoslav <svetoslavganov@google.com> Remove commented out dead code

Change-Id: I3e59d0ee55fd864ea0d8bc5f99cdb74d9b0e49bb
odel/PageContentRepository.java
1710e0318db5db833974e390eb4bde54ab2f3c62 12-Jul-2014 Svetoslav <svetoslavganov@google.com> Fix print preview rendered page preloading.

After the preview list is scrolled we are preloading the
pages around the ones that are shown, so now if the user
does a slight adjustment (expected after a scroll) the
pages around are rendered. There was an off by one error
and one of the bitmaps of the shown pages was reused and
as a result the wrong content was shown.

Change-Id: If04aebf46bcc637491221c6218005ecc1a7253d2
odel/PageContentRepository.java
i/PageAdapter.java
15cbc8a03250eafdf947cd8ad4e77f34444d5ba4 11-Jul-2014 Svetoslav <svetoslavganov@google.com> Addressing comments for the print preview feature.

Change-Id: Ib72140a912e22f859258d970e0d1c4ef06e807d5
odel/PageContentRepository.java
i/PageAdapter.java
i/PrintActivity.java
i/PrintPreviewController.java
idget/PageContentView.java
idget/PrintContentView.java
525a66b2bb5abf844aff2109bdc9ed819566bece 15-Jun-2014 Svet Ganov <svetoslavganov@google.com> Adding print preview.

This change adds the pring preview part of the new print UX. The
UI has two parts, the top section is the print options and the
bottom section print preview with a list of pages. The user can
interact only with one of them. When print options are expanded
they cover the preview content and a scrim is laid out on top of
the preview. Tapping the scrim collapses the print options. When
the user types in page ranges and closes the options to look at
the preview, the latter is updated to show only these pages. In
the list of pages the user can further prune pages by deselecting
them.

Change-Id: I0b23d2c598afe2a34400ccfa43e4e935af83c72f
odel/MutexFileProvider.java
odel/NotificationController.java
odel/PageContentRepository.java
odel/RemotePrintDocument.java
i/PageAdapter.java
i/PrintActivity.java
i/PrintErrorFragment.java
i/PrintPreviewController.java
i/PrintPreviewFragment.java
i/PrintProgressFragment.java
til/PageRangeUtils.java
idget/ContentView.java
idget/EmbeddedContentContainer.java
idget/PageContentView.java
idget/PrintContentView.java
idget/PrintOptionsLayout.java
e3bbb3d6c09a29cddeb544308e5b3210908fa256 12-Jun-2014 Svetoslav <svetoslavganov@google.com> Fix NPE in PrintActivity.

It is possible that the orientation is chosen before the media size.
The code handling orientation change was wrognly expecting to have
a selected media size all the time resulting in a NPE.

bug:15512333

Change-Id: I9f2786af314641144a24c1d1363c8d2590b0df57
i/PrintActivity.java
a798c0a984f29f7180883a61839f68d2cbf0c6ce 15-May-2014 Svetoslav <svetoslavganov@google.com> Refactor printing

Change-Id: I19850154ef2798afff511e4490a268ce38e8cbae
usedPrintersProvider.java
ediaSizeUtils.java
otificationController.java
rintDialogFrame.java
rintJobConfigActivity.java
rintSpoolerService.java
emotePrintDocumentAdapter.java
electPrinterActivity.java
electPrinterFragment.java
odel/NotificationController.java
odel/PrintSpoolerProvider.java
odel/PrintSpoolerService.java
odel/RemotePrintDocument.java
i/FusedPrintersProvider.java
i/PrintActivity.java
i/PrintErrorFragment.java
i/PrintPreviewFragment.java
i/PrintProgressFragment.java
i/PrinterRegistry.java
i/SelectPrinterActivity.java
til/MediaSizeUtils.java
til/PageRangeUtils.java
til/PrintOptionUtils.java
idget/ContentView.java
idget/FirstFocusableEditText.java
idget/PrintOptionsLayout.java
b0d97b87ba5f23ee867f381a4e5916ebb2e5f762 02-Jan-2014 Svetoslav <svetoslavganov@google.com> PrintSpooler crash if printer is reported to have only one color mode.

bug:11993304

Change-Id: I4932cf1b5b9b89f0cbf97011782ede037e7d814c
rintJobConfigActivity.java
2c1b177dcfbf140eb1409c646eefb8b0507fa534 21-Dec-2013 Svetoslav <svetoslavganov@google.com> Sometimes write may be called twice in a row for the same content.

In a rare case it is possible that on write of a print document
adapter is called twice for the same pages with nothing being
changed. This happens if while doing a write we get an update
request which correctly avoids calling layout on the adapter
but does call on write as we ignore that we are waining for the
requested pages to be written. Fun.

Change-Id: I33d7d26c7c4b083dc7b66bf762697b6dafd1ccc4
rintJobConfigActivity.java
c04aa87e4ac41b6c65dceb7b20d7a7f92c2efec1 19-Nov-2013 Dave Langemak <dlangemak@google.com> Merge "Fix incorrent page range parsing when custom print options used." into klp-dev
1a85d9fb243aae3750001094aa1514d4303cb3e0 16-Nov-2013 Svetoslav Ganov <svetoslavganov@google.com> Fix incorrent page range parsing when custom print options used.

We have APIs for a print service to declare an activity with custom
print options. In this activity the service can add custom properties
as well as change the standard ones such as pages to print. The ranges
of selected pages from the custom activity was incorrectly parsed
resulting in an off by one error in what is shown to the user and as a
result getting an exception when trying to print.

bug:11719051

Change-Id: Id04c94608178895f1d47381a63133f0eba7645e1
rintJobConfigActivity.java
885810de69d75979df4299d21fa236490767eae4 15-Nov-2013 Svetoslav <svetoslavganov@google.com> Created print jobs should not be persisted until they are queued.

Print jobs in a created state should not be persisted. However,
if a print service sets the tag to a print job that is queued,
we were persisting even print jobs in a created state. This
change adds a simple check while persisting to avoid storing
created print jobs.

bug:11696785

Change-Id: Idf28f3634b91fd5bf345f376114af4ed478ed3c6
rintSpoolerService.java
c445b3f2cba67b7dbb8f926ef5e80ec14fb2f8d4 05-Nov-2013 Svetoslav <svetoslavganov@google.com> Merge "Add missing null pointer check in PrintSpoolerService." into klp-dev
75d28505c8f73a977cc7ae0cc08a60120f7c92b2 05-Nov-2013 Svetoslav <svetoslavganov@google.com> Add missing null pointer check in PrintSpoolerService.

bug:11474389

Change-Id: I80ea01ba04ab71a212c1f78af62b377110ed072a
rintSpoolerService.java
1c664b6defd20ab4a83c4a83d01b9ed8603f7c2c 04-Nov-2013 Svetoslav <svetoslavganov@google.com> Add way for the user to forget previously used printers.

We keep track of historical printers but some of them may disappear
forever, say the user changes his printer. In such a case the print
system has no idea that the previous printer will never appear so
this change allows the user to remove historical printers.

In the all printers list the user can now long press on a printer
and if the printer is available he can select it from the context
menu. If the printer was used before regardless if it is active the
user may choose to forget it.

bug:11282742

Change-Id: Idc2dda70920ad045149eea1bcfc75ad1992827e9
usedPrintersProvider.java
rintJobConfigActivity.java
electPrinterFragment.java
d270cb9264f762257d1aadbeba9c4b38866e171c 31-Oct-2013 Svetoslav <svetoslavganov@google.com> Cancel current work in PrintDocumentAdatper if printing is cancelled.

Layout and write may take some time during which the user can
cancel printing. Currently we wait for the last operation,
being write or layout, to complete before closing the print
dialog. Now in such a scenario we request a cancellation of
the ongoing operation.

bug:11329523

Change-Id: Ia9d747163cc73509369a86c8b5afc83b7ee54859
rintJobConfigActivity.java
emotePrintDocumentAdapter.java
b4fda134761c9521a7e127db3806a07a18763b77 26-Oct-2013 Svetoslav <svetoslavganov@google.com> Complete implementation of the advanced print options.

1. Implemented the advanced printer options integration. Now a print service
may declare an advanced print options activity which may be launched by
the user if the current printer supports advanced print options. These options
are visible only to the print service that added them and it is the only party
that will interpret the options.

2. Fixed a couple of bugs in the saved print jobs parsing. One was that if there
are more than one page range, a half of the print job properties was not
properly parsed. The other was that the media size constructor was using
incorrect argument order, thus creating a media size with wring width.

3. Fixed and edge case where old print jobs and their docs can get stuck in
the spooler. If the app did not write the requested pages we were not showing
an error message, rather just finish the activity without canceling the print
job and this print job is stuck in the spooler. Now we show an error message
and the user may retry, cancel. If the user cancels the print job is also
cancelled, thus no leftover in the spooler.

4. Fixed the background color of the print dialog to meet UX spec.

bug:11241800

Change-Id: I352440bc86aec824a805883fc9579d96a06d11e6
rintJobConfigActivity.java
rintSpoolerService.java
4d4c66dd38e940082e385b49a33f4022ab04c738 25-Oct-2013 Svetoslav Ganov <svetoslavganov@google.com> Update the documentaton of the android.print package.

bug:10551786
bug:10551697
bug:10705082
bug:10741641
bug:11318976
bug:10550979
bug:10551761

Change-Id: I46ceb66a69b6d32d6b417356178f67f2e25e891a
rintJobConfigActivity.java
237575278de8cae5d20ee333fcb2ccceee257d67 19-Oct-2013 Svetoslav Ganov <svetoslavganov@google.com> Merge "Hide the print dialog if the printing activity is destroyed." into klp-dev
30d9161b8e84652d9ac504b70adacaf729fdb58b 18-Oct-2013 Svetoslav <svetoslavganov@google.com> Merge "Printer list items have wrong width." into klp-dev
858a1850e2e1c4516129d27ecdf54aaeade606ca 18-Oct-2013 Svetoslav Ganov <svetoslavganov@google.com> Hide the print dialog if the printing activity is destroyed.

1. For an app to print it creates a PrintDocumentAdapter implementation
which is passed to the print dialog activity. If the activity that
created the adapter is destroyed then the adapter, which may rely on
the activity state, may be in an invalid state. For example, an app
creates an adapter and calls print resuting in the app activity and
the print dialog activity being stacked. Now the user rotates the
device which triggers the recreating of the activity stack (assume the
app does not handle rotation). The recreated print dialog activity
receives the intent that originally created it with containing the
adapter that was constructed in the context of the old, now destroyed,
app activity instance.

To handle this we are limiting an app to be able to print only from
and activity and when this activity is destroyed we mark the adapter
as invalid which will result in hiding the print dialog activity. Note
that if the app process is killed we already handle this in the print
dialog activiy by registering a death recipient on the adapter binder.

2. In the PrintManager.PrintDocumentAdapterDelegate some of the state is
accessed only on the main thread and some from miltiple threads. The
code was trying to avoid locking for state that is not accessed by
multiple threads but this is error prone and the benefit does not
justify the complexity and added fragility. Now grabbing a lock all
the time.

3. The PrintJobConfigActivity waits for it to bind to the print spooler
service before instantiating its print controller and editor. However,
these can be accessed by invoking some of the activity cycle callbacks.
This change is adding null checks for the case where the activity
callbacks are called before the binding to the spooler is completed.

bug:11242661

Change-Id: Id906b3170e4f0a0553772dfa62686f06fdca0eaf
rintJobConfigActivity.java
ed513d7e4a624a9f82e15923a7052d4c18a020a7 17-Oct-2013 Svetoslav Ganov <svetoslavganov@google.com> All printers list has incorrect padding and item height.

1. We were using the layout for the printer drop down from the
print dialog as the list item in the all printers activity.
This layout was not high enough. Now we have a separate
layout for the drop down and for the list. Note that they
are almost identical but this is better that writing java
code to lookup the height from the theme and change it
programatically since the java code is almost half the size
of the layout and leads to spreading the logic in both the
layout file and the java code.

2. The padding of the printers list was not correct. Now it
mimics the bahavior in settings where we change the padding
based on orientation.

bug:11261157

Change-Id: I8507c4ee86e9196fe1777cf9577f1886ccfbb1ad
electPrinterFragment.java
b196106a43355ec56bc2354cae1d1bbf21ab9b4b 17-Oct-2013 Svetoslav <svetoslavganov@google.com> Printer list items have wrong width.

1. There was leftover code in the printers adapter that was
hard coding the item width with no reason to do so.

2. Changed the icon view visibility to invisible to allow
the text of all list items including save to PDF and all
printers to be left aligned.

bug:11225340

Change-Id: I5b51d0d30577699f5cd73c7c58521358653d135b
rintJobConfigActivity.java
2fa010cf5bf76af826776ada8a35cf8fe2945b64 15-Oct-2013 Svetoslav <svetoslavganov@google.com> Update the message for unavailable printers.

If a printer disappears or we do not get its capabilities, we
show the user a message that the printer is unavailable. This
message was appended after the printer name but they tend to
be very long and the user does not see that the printer is not
available due to ellipsis. Now we append the message after the
subtitle which tends to be much shorter.

bug:10983508

Change-Id: Ib3f7ad3bd82ff6decd49dc45461fb5131338e8c2
rintJobConfigActivity.java
2f0ec7af06e206b1747b93efbd65d88189fc2df1 14-Oct-2013 Svetoslav Ganov <svetoslavganov@google.com> Update the print spooler action bar icon.

1. Updated the print spooler icon shown in the action bar
when searching for printers in the all printers activity.

2. If the current printer's capabilities are not immediately
available the page count label in the dialog contained the
argument placeholders.

bug:10983508

Change-Id: Id4f78d6cc31647f043f8e3044ab54f30584d1ebe
electPrinterFragment.java
9d843e09caa8c32a3fec22bb66cba8e6d4dfa5b1 14-Oct-2013 Svetoslav <svetoslavganov@google.com> Layout may be called with invalid print attributes.

If a print service reports a printer with no capabilities and then
removes and adds the same printer again with no capabilities we can
call layout with invalid attributes. While the print service should
not do that we must not crash. The reason is that the print dialog
code was lacking a check whether something changed before handling
the change of the current printer. This resulted in calling layout
even though we still do not have the printer capabilities resulting
in passing bogus print attributes to the app.

bug:11216402

Change-Id: Icb9161930a70a7f9ead589a0ab0b4eb35091666f
rintJobConfigActivity.java
7ff610ee029d990a6b9b6d8c90a79fe79fbd8368 13-Oct-2013 Svetoslav Ganov <svetoslavganov@google.com> The print dialog in bad state after pressing back from prnt to PDF.

When selecting print to PDF and then pressing back to return from the
storage UI activity, the print dialog was in a state where nothing
is selected.

bug:10983508

Change-Id: I9c14b5fa18e812104ade6a2eacd626b5f7387111
rintJobConfigActivity.java
d91cb3ea61ea5096637c5d2b5e3e6147d0d2cce3 13-Oct-2013 Svetoslav Ganov <svetoslavganov@google.com> The list of active print jobs in print service retunring wrong result.

1. The getActivePrintJobs() method in print service is designed to return
the active print job i.e. ones scheduled to be processed by the print
service. Now the correct list is returned.

2. The listeners for observing the state of print jobs may be called even
after being unregistered. Ex: state change occurs and we schedule a
message on the app's main thread to make the notificaion. Now the app
unregisretes the callback and on the next loop the notification message
is handled.

bug:11200258

Change-Id: I4a497b5c9a7287a22023cafe41ce966d14300ca6
otificationController.java
d3c197d97250af93041e6aa05ef0dfca323f1767 12-Oct-2013 Svetoslav Ganov <svetoslavganov@google.com> The callbacks for tracking a printer called more than once without printer change.

When the user selectes a printer in the UI we ask the print service to start tracking
the printer, i.e. to observe changes of the printer state and capabilities. The callback
for the initially selected printer is called twice which breaks the contract and also
may trigger potentially expensive operations on the print service side.

More precisely the printer does not change and we ask the service to start tracking,
stop tracking, and again start tracking.

bug:11199851

Change-Id: Ib761e6da03f670b3098c69b1c0927177a8e4ae6b
usedPrintersProvider.java
7d7888d1c7daa78ee0ad24a24c8dd54b01749259 12-Oct-2013 Svetoslav Ganov <svetoslavganov@google.com> Printed document size not persisted.

We persist ongoing print jobs so they can be restarted if the device
dies. The data size of the printed document was not persisted to disc.

bug:11199352

Change-Id: I53ef1ee285aa4808917dd6a5c7335226aba1ef0a
rintSpoolerService.java
9b6d3a153f44010a75907c6a9742c89a57d4e5ee 12-Oct-2013 Svetoslav Ganov <svetoslavganov@google.com> Fail only scheduled print jobs, i.e. handed to a service, if the service is disabled.

When a print service is disabled we assume all print jobs for it failed as we have
no way to know what happens to them. However we are also failing created print jobs,
i.e. ones not given to the service. Such jobs are in process of construction and
the print dialog is up. We should not fail such jobs as the dialog can still modify
their state and potentially select a print from a different service. Therefore, we
leave them alone and they will be failed if when constructed are passed to a
disabled/uninstalled service.

bug:11197432

Change-Id: Ie4fe54327e3e25776b1dd572be2dfafdd700c2e5
rintSpoolerService.java
89ed9fcf9b2fe061626c910701a35f1ea576a370 12-Oct-2013 Svetoslav <svetoslavganov@google.com> Putting the cursor at the end of the copies and range inputs.

bug:10983508

Change-Id: I767876fada2f28b00283ed9140fca1a40729f38f
rintJobConfigActivity.java
02dded1a63bb5ae2968fb9df0c29bad115416a28 11-Oct-2013 Svetoslav <svetoslavganov@google.com> Adding timeout if the current printer or its capabilities disappear.

If the current printer becomes unavailable or its capabilities
go away we are scheduling a timeout to declare the printer as
unavailable.

bug:10983508

Change-Id: Iab85cfd35fc0cecc3dd4abac6232347f9da18fb0
rintJobConfigActivity.java
54adee86af495311fc9ef62d65e035605043413f 11-Oct-2013 Svetoslav <svetoslavganov@google.com> Print spooler not starting.

1. In my previous change I fixed a typo in the Java constant with
intent action to launch the print dialog but failed to updated
the print spooler manifest.

2. Removed dead code - the user id is no longer needed since the
spooler is an app that runs per user. Every user has its spooler.
This code was not referenced from anywhere.

3. Added a default icon to the print spooler.

4. Fixed a bug where if the print history is empty the UI goes
to the all pritners activity.

bug:11059554

Change-Id: If74c23b418a8c67620ba14435ee7f3b2c4527099
rintJobConfigActivity.java
rintSpoolerService.java
f22a767e872ec8f5c2531a88819e0f4574c78fe3 11-Oct-2013 Svetoslav Ganov <svetoslavganov@google.com> Merge "Added UI for errors during layout and write." into klp-dev
caff38821ad81389b5baf2053ba851c38272ec63 09-Oct-2013 Svetoslav Ganov <svetoslavganov@google.com> Added UI for errors during layout and write.

1. If an error happens during layout or write we show an error
message with the string provided by the application which
has an OK button to retry or tap outside to cancel.

2. Updated the targed and min SDK version for the PrintSpooler.

bug:11127269

Change-Id: I4301cf3716119b1e33b95347a8451fc1c128343b
rintJobConfigActivity.java
7bfbbcb04bf4ba8f3069b2df136f708c9849bacf 10-Oct-2013 Svetoslav <svetoslavganov@google.com> Refactor how the print dialog activity is started.

1. Before the print job activity was started asyncronously with
respect to the print call on to the print manager. This was
creating a situation where the starting activity may finish
before the print dialog appears which may lead to an orphaned
print document adapter with no data to print (as the UI is
is gone), or strange behaviors where the print dialog starts
on as a separate task.

To address this the pending intent for starting the print
dialog is not started by the print spooler since we cannot
call into it synchronously as we have to start its process
and bind to the spooler service which leads to jankyness in
the client app. Now the pending intent is created by the
print manager service in the synchronous print call so
from an app's perspective calling print starts the activity.

The side effect of this design is that the print dialog
activity may start before the system is bound to the spooler
service. In such a case the print activity cannot start
poking the print spooler state as the system registers
callback to observe the spooler state. To address this
the print spooler activity disables the UI and also binds
to the spooler service which happenes immediately after it
is started. As soon as the print dialog binds to the
service it starts the UI.

2. Fixed an bug in the printer adapter of the print dialog that
was leading to a crash if the only item in the adater is the
all pritners option and it is selected.

3. Piping the package name that started the printing so we can
pass it to the storage UI as a hint to open the last location
the app used.

bug:11127269

Change-Id: Ia93820bdae0b0e7600a0930b1f10d9708bd86b68
rintJobConfigActivity.java
rintSpoolerService.java
3aa2e2b3ab21fda7045fbe2bb142e7a6830340e5 11-Oct-2013 Svetoslav <svetoslavganov@google.com> Fixing jank when transition from print dialog to generating one.

Initially we show the print dialog and when the user presses print
we show a generating dialog with an indefinite spinner and a cancel
button. The transition between the two UIs which are really different
layouts show in the print activity is animated. In the middle of
the animation from print to generating UI there was a jump of the
content and an undesired window animation kicking in. This is a
side effect of changing the activity to floating so now changing the
container size was causing window resize and hence animation. Fun!

bug:10983508

Change-Id: I7d88e073c55863b945cdb50822401592f32d44c3
rintDialogFrame.java
rintJobConfigActivity.java
ebec46847d4bbd72161fb32282ab7a68effa00a7 09-Oct-2013 Svetoslav <svetoslavganov@google.com> Sometimes the print button not enabled and an accessibility fix.

1. Sometimes the print button is not enabled after selecting a printer
from the all printers activity. This was happening after a printer
was selected, we had to do a layout due to changed print attributes
(because of the new printer's capabilities), and the content did not
change. In this case we did not call the updateUi function which
enables the print button after layout is completed.

2. The accessibility code in the all printers activity was not checking
whether accessibility is on and doing some unnecessary work - not sending
events though but still. Further, the delayed runnable that was
doing the accessibilty announcements was not removed when the activity
was paused.

bug:10983508

Change-Id: Ib263116a3e21e4c75a25aa051cecbd9194417319
rintJobConfigActivity.java
electPrinterFragment.java
a18661d5922e5ae24ccce8e815aeba437a2fba82 10-Oct-2013 Svetoslav Ganov <svetoslavganov@google.com> Coalescing multiple print job notifications.

1. We used to show a single notificaiton for every print job but
this is against th UX guidelines. Since we have to lead by
example, this change adds coalescing of multiple notifications.

bug:11155212

2. Print job state callback in the PrintManager now correctly
invoked on the main thread.

bug:10983508

Change-Id: I906e9e62198fa37cb4d2f71fce07ed475d61e1bd
otificationController.java
rintSpoolerService.java
53e8a26d6178c41c59c3dcad4a8a04ce2449f246 08-Oct-2013 Svetoslav <svetoslavganov@google.com> Fix a crash in the select printers activity.

When the search view is attached and detached we announce that
for accessibility. The trouble is that if the activity is being
torn down we are trying to access resources from a fragment that
is detached and the qcrash occurs. This change does not try to
access resources if the activity is finishing and also we do not
load resource strings if accessibility is not enabled.

bug:11127814

Change-Id: I4a47a8ed3b6a13544cf17b4395560246a33f0e2d
electPrinterFragment.java
69b91e0ecb8cef95c030f5076779e07d363a45f2 08-Oct-2013 Svetoslav Ganov <svetoslavganov@google.com> Show unavailable printers disabled and grayed out.

1. If a printer is not available it has to disabled and grayed out.

2. Cancle a print job if the app does not provide the requested pages.

3. Fix current printer selection flicker when the print dialog is
showing up. Often the current printer is initially set to the user's
favorite and then it is changed back to the PDF one.

bug:10983508

Change-Id: I8d53eb992cf1c92675ec09f61b2ec272b962fa68
rintJobConfigActivity.java
electPrinterFragment.java
56ddf1ffa5b7bd3b8d4b8b7d5c68d7e0e99e5e15 06-Oct-2013 Svetoslav Ganov <svetoslavganov@google.com> Polish print dialog accessibility.

bug:10983508

Change-Id: I7391e06b661caac18d04ae279639ff447701f151
rintJobConfigActivity.java
electPrinterFragment.java
24c686b8b56950d5a1881cc660e53816d47e5e03 06-Oct-2013 Svetoslav Ganov <svetoslavganov@google.com> Update all printers activity's empty state and avoid selected printer flicker.

1. Updated the empty state of the all printers activity to show no printers message
if the user is searching and there are no matches and a searching for printers
message if the user is not filtering the printers list.

2. Adding the fake PDF printer after the historical printers are loaded to avoid the case
where we select the PDF printer and immediately after that the most used printer is
selected resulting in an undesirable UI flicker.

3. Fixed a bug where if the most used printer which is initially considered unavailable
is reported by the print service as available but the UI is not properly updated
leaving the user in no way to click on the print button.

bug: 10983508

Change-Id: I60fdb7761332850fd5b9ffc0cb572a6213024dba
usedPrintersProvider.java
rintJobConfigActivity.java
electPrinterFragment.java
264c566a7f7d829de48131ac6d811b3db6f520bc 05-Oct-2013 Svetoslav Ganov <svetoslavganov@google.com> Update the empty state for the "all printers activity"

The empty state is now showing searching for printers hint if
the user is not searching, otherwise the empty state's hint is
a searching for printers message.

bug:10983508

Change-Id: I3df79c167546998c8055d9ff85efa8b460a15e48
electPrinterFragment.java
0ea7d1e869ad618a7c8c2bbbb7f96729e7d84ed3 05-Oct-2013 Svetoslav Ganov <svetoslavganov@google.com> Update the "add print service" dialog as per UX spec.

The dialog button is now the last item in the adapter if the
search for print service settings is not empty and resolves
to an intent.

bug:10983508

Change-Id: I348e1ede1097d6f3b78c72e871bf3097b99004b6
electPrinterFragment.java
5ab717f21a2dbcd78fb37d40e31393d129743599 05-Oct-2013 Svetoslav <svetoslavganov@google.com> Print UI tweaks.

1. The refresh button in a print notification was using
wrong asset.

2. If the page count is unknown, just not show the page
count instead unknown.

bug:10983508

Change-Id: I15f1fcbff60fe1f30d37868864da41550bb14487
otificationController.java
rintJobConfigActivity.java
331f9e79ad16e7d9d51e8481e6bc21642a51c340 05-Oct-2013 Svetoslav Ganov <svetoslavganov@google.com> Merge "Print attributes hint not honored." into klp-dev
7be27acac922b5ea66ec6b464ded6f057bd6f1e5 30-Sep-2013 Svetoslav Ganov <svetoslavganov@google.com> Print attributes hint not honored.

1. Initially we have a single printer, the fake PDF printer, and
wait for printers to be discovered. This printer was handling
only a couple of media sizes. Hence, if the app provides a
media size hint and the PDF printer does not support it, we
were essentially ignoring the suggested media size since it
was not supported by the selected printer and we fell back to
the default paper size for that printer. The fake PDF printer
should support all predefined media sizes.

2. The list of available paper sizes was shown in the order they
are added ignoring the current locale. It is much better user
experience if the media sizes used in the current locale are
shown at the top and all others after that. Also the media
sizes for the current locale should be alphabetically ordered
so the user can quickly find the desired one.

3. The orientation was reset on media size or printer change.

bug:10564537

Change-Id: Iaa0d42242730ce69cea3effd4d0f4bc087068804
ediaSizeUtils.java
rintJobConfigActivity.java
6bf1029900d09d0432fb82f8c076bdb3eefc1f6c 04-Oct-2013 Svetoslav Ganov <svetoslavganov@google.com> Merge "Deleting print job files when we do not have to." into klp-dev
2b40c83ae1ec17ea9371c3fd3ac6c79c156faa1d 04-Oct-2013 Svetoslav Ganov <svetoslavganov@google.com> Deleting print job files when we do not have to.

The print job file name was not properly parsed. This resulted
in incorrect mapping from file to print job, thus deleting the
file when we do not have to.

bug:11069354

Change-Id: I7b8a7a7f98dd77b34119f2a9cd16a6ec3c22b63b
rintSpoolerService.java
39e71de6b49d1cb67ce30b411cede8d4f40dc765 03-Oct-2013 Svetoslav <svetoslavganov@google.com> Print UI tweaks as per UX request.

1. Limit the width of the dropdown of the printers list.

2. Add icons the the list in the all pritners activity.

3. Update the empty state view for the all printers activity.

bug:10983508

Change-Id: I19effcf32770fdda278009a060b5170a3f29988e
rintJobConfigActivity.java
electPrinterFragment.java
913f87ef637fc1d9a006c543833b6815090b94e8 03-Oct-2013 Svetoslav <svetoslavganov@google.com> Merge "IndexOutOfBoundsException in the PrintSpoolerService dump." into klp-dev
b67a637e60c356ab520050b2bd09a95ae47f3017 02-Oct-2013 Svetoslav <svetoslavganov@google.com> IndexOutOfBoundsException in the PrintSpoolerService dump.

The dump code in PrintSpoolerService was relying on being
called only as a result of "adb shell dumpsys print" which
is apparently wrong. As a result the code was making wrong
assumption about the input arguments.

bug:11046234

Change-Id: Ie38f3cc5f17cac98b808fef6d6bbeaca22a62ef0
rintSpoolerService.java
228a7d2a157c4e6ceee5fdea389f207bbf4990ba 02-Oct-2013 Svetoslav <svetoslavganov@google.com> Merge "Sometimes printer selection from all printers activity does not work." into klp-dev
4e4874bb71ddebc80fd10b7b3f0ec6b13aca25ec 02-Oct-2013 Svetoslav <svetoslavganov@google.com> 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
rintJobConfigActivity.java
976b4e6312ca7a4cca56211fa5b347b018dd305a 01-Oct-2013 Svetoslav <svetoslavganov@google.com> Adding an empty state UI for the printer search activity in the spooler.

The user can select all printers from the print dropdown to get to
a search for printers activity where one can filter out the list
of a available printers. We did not have an empty state UI for the
case when the query yields no printers.

bug:11009053

Change-Id: I6b45517b8a7b319992019a1bf65858319a19a0de
electPrinterFragment.java
d8dbc13b47bec3248a86a505a30af9d0474240dc 28-Sep-2013 Svetoslav <svetoslavganov@google.com> 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
usedPrintersProvider.java
b415525a16074b6dc8e295655648b7c7c1074bbb 28-Sep-2013 Svetoslav Ganov <svetoslavganov@google.com> Merge "Print job files and print job records not always cleaned up." into klp-dev
c783f6738f0f6d2cb57702cfbc9219c59a3410a3 28-Sep-2013 Svetoslav Ganov <svetoslavganov@google.com> Merge "Adding a timeout for waiting to get the selected printer's capabilities." into klp-dev
dd68da2741fa63070d5ad206020dcccb9f429a5a 27-Sep-2013 Svetoslav Ganov <svetoslavganov@google.com> 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
rintSpoolerService.java
6be4c76441ecdc11ee4db7211edc421d26a78f1f 27-Sep-2013 Svetoslav Ganov <svetoslavganov@google.com> 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
rintJobConfigActivity.java
c335eb411503154cf475903eb6c5c67575769112 27-Sep-2013 Svetoslav <svetoslavganov@google.com> 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
rintJobConfigActivity.java
0ce3e8743c9127a688f007eed17a5ed18081d0fc 26-Sep-2013 Svetoslav Ganov <svetoslavganov@google.com> Choosing default paper size for the "Save to PDF" fake printer

Change-Id: I1e2eb73fd1eb3b1e9812155b69b94cba261243c2
rintJobConfigActivity.java
5cab967bf2bab49777bfa86dff8b0f892192ede6 26-Sep-2013 Svetoslav Ganov <svetoslavganov@google.com> Merge "Adding hidden APIs for observing the print jobs state." into klp-dev
3adc49c6780633b8bccc3b5b8dca10788c2288bc 26-Sep-2013 Svetoslav Ganov <svetoslavganov@google.com> Merge "Disallow range selection if the document has unknown page count." into klp-dev
c9cfd605a24cf20df5248d73804c584168db64c9 26-Sep-2013 Svetoslav Ganov <svetoslavganov@google.com> Merge "Missed signal in FusedPrintersLoader." into klp-dev
953c4143e846b071da4869cb7cfd8039a086b1da 26-Sep-2013 Svetoslav Ganov <svetoslavganov@google.com> 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
usedPrintersProvider.java
ab051baea5560e0c71397771e53bd74d4a36024d 26-Sep-2013 Svetoslav Ganov <svetoslavganov@google.com> 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
rintJobConfigActivity.java
b0e68fdc9cb6ba292adc4590f406d921abea08d5 21-Sep-2013 Svetoslav Ganov <svetoslavganov@google.com> Disallow range selection if the document has unknown page count.

bug:10741878

Change-Id: Ibf2272125e81f14ede3fdfec86aee10b908ade01
rintJobConfigActivity.java
704697b6197262678e930daa831a1916ddee4dcf 22-Sep-2013 Svetoslav Ganov <svetoslavganov@google.com> Adding hidden APIs for observing the print jobs state.

This is needed for implementing the print job settigns UI.

bug:10935736

Change-Id: I63b42cbf4ce6a259fa1af47fa368b148ca5621c1
otificationController.java
rintSpoolerService.java
2a708617dfdc0b6dbf9b39baebbdc55d19aa7728 25-Sep-2013 Svetoslav <svetoslavganov@google.com> 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
rintJobConfigActivity.java
b5f180608db6de123b54ae94de569ff1ebca705c 24-Sep-2013 Svetoslav <svetoslavganov@google.com> 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
usedPrintersProvider.java
rintSpoolerService.java
5dfccc3c0d142765b04f9cd8b2513a6b9db22426 24-Sep-2013 Svetoslav Ganov <svetoslavganov@google.com> Merge "The current is printer not refreshed when selected." into klp-dev
307a0d4db23d8d9705fb2d87d304cb7e9a90f476 24-Sep-2013 Svetoslav Ganov <svetoslavganov@google.com> 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
rintJobConfigActivity.java
a4f6409c974363a6bb1eddd5c88048d88e868640 21-Sep-2013 Svetoslav <svetoslavganov@google.com> 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
rintJobConfigActivity.java
b39ce63d2807c9d5c68d3be052dee7e9da7ec3be 21-Sep-2013 Svetoslav <svetoslavganov@google.com> Merge "Offer to enable a print service after it is installed." into klp-dev
d8f391b4e0e8d876ec7216d34f86a9b3e8bab7e5 21-Sep-2013 Svetoslav <svetoslavganov@google.com> 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
otificationController.java
5559c368a96c56d55c581c88d9978c59c5212bf1 20-Sep-2013 Svetoslav <svetoslavganov@google.com> 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
rintJobConfigActivity.java
b206f1271d17164c3f2f65219eee7a0b4b4fa6dc 20-Sep-2013 Svetoslav <svetoslavganov@google.com> Null not handled when parsing media size resource id attribute.

bug:10835715

Change-Id: I0c9c1120c26e68b4c582599bbda3753d0e443d8c
rintSpoolerService.java
6811f4e92cbb64e72a0d13eb9b99b5894bd59c76 19-Sep-2013 Svetoslav <svetoslavganov@google.com> 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
rintJobConfigActivity.java
ac7297bdc04e2097e39b791064e5ed6ee92680ea 19-Sep-2013 Svetoslav <svetoslavganov@google.com> Merge "Fixes in the page range selection and verification logic." into klp-dev
f0c48a72fd8476afd063d4ef593b473b8cf9a9d0 18-Sep-2013 Svetoslav <svetoslavganov@google.com> 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
rintJobConfigActivity.java
7b3990ec81fc218f655d44624758e15ce378968e 18-Sep-2013 Svetoslav <svetoslavganov@google.com> Merge "Update the print dialog." into klp-dev
013b816ac7d723a0116c039e6266d93d13851fe1 18-Sep-2013 Svetoslav <svetoslavganov@google.com> 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
rintDialogFrame.java
10ee84ba18255f259edf6fa2e3aa33c02ac5340d 18-Sep-2013 Svetoslav Ganov <svetoslavganov@google.com> 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
usedPrintersProvider.java
0cfebec522539722f294a99bc32437b5d9e4b27d 17-Sep-2013 Svetoslav <svetoslavganov@google.com> Merge "Print pooler crashes for some page ranges." into klp-dev
c3484024e1117b518f06b39c406ba20f961d592e 17-Sep-2013 Svetoslav <svetoslavganov@google.com> 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
rintJobConfigActivity.java
2fbd2a7f070f246ddafd9de94efa9a98861e9136 17-Sep-2013 Svetoslav <svetoslavganov@google.com> 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
otificationController.java
rintJobConfigActivity.java
rintSpoolerService.java
860f8a6b663ca96d30d17da09eca8caf065aae62 14-Sep-2013 Svetoslav Ganov <svetoslavganov@google.com> 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
rintJobConfigActivity.java
electPrinterFragment.java
651dd4e6ee6510caf9f15c51094a11121af17ec2 12-Sep-2013 Svetoslav <svetoslavganov@google.com> 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
usedPrintersProvider.java
rintJobConfigActivity.java
rintSpoolerService.java
cc65b0c325b88c466763712f76148a6f5b8a5b3f 11-Sep-2013 Svetoslav <svetoslavganov@google.com> 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
rintJobConfigActivity.java
c6066799ad130140159230d14451b429eb828755 11-Sep-2013 Svetoslav <svetoslavganov@google.com> 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
usedPrintersProvider.java
rintSpoolerService.java
emotePrintDocumentAdapter.java
a36285f3f2f74b1d2d5d0336ffe519ab9f6e062a 05-Sep-2013 Svetoslav <svetoslavganov@google.com> 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
usedPrintersProvider.java
rintJobConfigActivity.java
a76233ae845da4bc9e3bcd89821701a747215e7b 05-Sep-2013 Svetoslav <svetoslavganov@google.com> 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
rintSpoolerService.java
773f54de3de9bce7b6f915aa47ed686b161d77aa 03-Sep-2013 Svetoslav <svetoslavganov@google.com> 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
rintJobConfigActivity.java
rintSpoolerService.java
9186d0cb2bd325d9b52da15dbd513937c1e42caa 03-Sep-2013 Svetoslav Ganov <svetoslavganov@google.com> 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
usedPrintersProvider.java
rintJobConfigActivity.java
d26d4898fcc9b78f4b66118895c375384098205e 28-Aug-2013 Svetoslav Ganov <svetoslavganov@google.com> 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
usedPrintersProvider.java
otificationController.java
rintJobConfigActivity.java
rintSpoolerService.java
aec1417ca9eb63209668ac17da90cf8a07c6076c 27-Aug-2013 Svetoslav Ganov <svetoslavganov@google.com> 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
rintJobConfigActivity.java
44720af55a8fdf991929983dad5d53c02851dd1e 21-Aug-2013 Svetoslav Ganov <svetoslavganov@google.com> 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
usedPrintersProvider.java
rintJobConfigActivity.java
rintSpoolerService.java
269403b032f965ff3847eb982c2f697229dc5a92 15-Aug-2013 Svetoslav <svetoslavganov@google.com> 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
vailablePrinterProvider.java
hoosePrinterActivity.java
ataLoader.java
ataProvider.java
avoritePrinterProvider.java
usedPrintersProvider.java
rintJobConfigActivity.java
rintSpooler.java
rintSpoolerService.java
electPrinterActivity.java
electPrinterFragment.java
66160bb881470a691005c8ad4e9c31c41fd5f810 13-Aug-2013 Svetoslav <svetoslavganov@google.com> 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
vailablePrinterProvider.java
hoosePrinterActivity.java
ataLoader.java
ataProvider.java
avoritePrinterProvider.java
rintJobConfigActivity.java
rintSpooler.java
55daead3c53a83ac300d76200dd4144f154e07d3 12-Aug-2013 Svetoslav Ganov <svetoslavganov@google.com> Fix the build

Change-Id: Icf3b339f7b300cc8673443fa8afd38ce78964683
rintJobConfigActivity.java
798bed6cc7d273e72b0253288605db9cd2b57740 11-Aug-2013 Svetoslav Ganov <svetoslavganov@google.com> 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
otificationController.java
rintJobConfigActivity.java
rintSpooler.java
rintSpoolerService.java
695c7fa7a320f1e5b4b56aa7ed6a64c6220f6502 08-Aug-2013 Svetoslav Ganov <svetoslavganov@google.com> 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
rintJobConfigActivity.java
32c5eb3bf89938ba2221e67362571628e1efd520 07-Aug-2013 Svetoslav Ganov <svetoslavganov@google.com> 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
otificationController.java
rintJobConfigActivity.java
14db9654f6c31e94fe9272776f1f1b8602a17fdc 06-Aug-2013 Svetoslav Ganov <svetoslavganov@google.com> 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
otificationController.java
rintJobConfigActivity.java
rintSpooler.java
55b5f8028a72d1da58835b6766798d781ad92b97 05-Aug-2013 Svetoslav Ganov <svetoslavganov@google.com> Disable print dialog spinners if there is only one option.

Change-Id: Ic9a46c737b592aeb6f78c962a7f9d53391a2b164
rintJobConfigActivity.java
835835ee6f913408ac91678d6056896a2c5b25e3 05-Aug-2013 Svetoslav Ganov <svetoslavganov@google.com> 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
otificationController.java
rintJobConfigActivity.java
rintSpooler.java
rintSpoolerService.java
8c43376ea83a67414bd6823a472b76d41160239e 02-Aug-2013 Svetoslav Ganov <svetoslavganov@google.com> 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
otificationController.java
rintJobConfigActivity.java
rintSpooler.java
rintSpoolerService.java
55b409a97cf6376399a0940313ea852368727d6f 01-Aug-2013 Svetoslav Ganov <svetoslavganov@google.com> 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
rintJobConfigActivity.java
rintSpooler.java
85b1f883056a1d74473fd9ce774948878f389ab6 25-Jul-2013 Svetoslav Ganov <svetoslavganov@google.com> 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
rintJobConfigActivity.java
rintSpooler.java
rintSpoolerService.java
emotePrintDocumentAdapter.java
0d1daa50f6d180c57f92596501e2e5c0b5ef9997 23-Jul-2013 Svetoslav Ganov <svetoslavganov@google.com> 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
rintJobConfigActivity.java
emotePrintDocumentAdapter.java
88d199130d44c6bacb383a7757e782cf97483c68 22-Jul-2013 Svetoslav Ganov <svetoslavganov@google.com> 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
rintSpooler.java
rintSpoolerService.java
597945fd3a6b52ac70bb9afc5ec8c59039fffd77 18-Jul-2013 Svetoslav <svetoslavganov@google.com> First pass of the print dialog UX

Change-Id: I315a16d7f68c73ca180c76e722847b4b1bdea55b
rintJobConfigActivity.java
rintSpooler.java
rintSpoolerService.java
emotePrintDocumentAdapter.java
6283608e0bd40548742839f5a8b02f7e5c9c5c7c 17-Jul-2013 Svetoslav <svetoslavganov@google.com> Tweak the print APIs.

1. Adding bundle with metadata to PrintDocumentAdapter#onLayout
with one key for now to specify whether this is for a preview.

2. Cleaned up docs.

Change-Id: I89380781bf3ae41aa89f8a0347d74516a210394c
rintJobConfigActivity.java
emotePrintDocumentAdapter.java
17b7f6e6d4ec9f5e9597bfd283f1c017b6c66275 25-Jun-2013 Svetoslav <svetoslavganov@google.com> Clean up of the print APIs.

1. Fixed a case in which the onPrintCompleted callback may not be invoked.

2. Added string resulrces for the different error messages for failed
printing in OnPrintCompletedCallback

3. Fixed the string comments for the MediaSize constants.

4. Added APIs to create certain print attributes by passing in a
string label instead of resource and package name since in some cases
a print service may be getting already internationalized lables
or it may not know all possible values.

5. Fixed a crash in PrintJobConfigActivity if there is no input or
output tray.

Change-Id: Ie877b7dc669051606394aa290e6d2b979a42db4c
rintJobConfigActivity.java
a00271533f639c8ed36429c663889ac9f654bc72 25-Jun-2013 Svetoslav Ganov <svetoslavganov@google.com> Refactoring of the print sub-system and API clean up.

1. Now a user state has ins own spooler since the spooler app is
running per user. The user state registers an observer for the state
of the spooler to get information needed to orchestrate unbinding
from print serivces that have no work and eventually unbinding from
the spooler when all no service has any work.

2. Abstracted a remote print service from the perspective of the system
in a class that is transparently managing binding and unbinding to
the remote instance.

3. Abstracted the remote print spooler to transparently manage binding
and unbinding to the remote instance when there is work and when
there is no work, respectively.

4. Cleaned up the print document adapter (ex-PrintAdapter) APIs to
enable implementing the all callbacks on a thread of choice. If
the document is really small, using the main thread makes sense.

Now if an app that does not need the UI state to layout the printed
content, it can schedule all the work for allocating resources, laying
out, writing, and releasing resources on a dedicated thread.

5. Added info class for the printed document that is now propagated
the the print services. A print service gets an instance of a
new document class that encapsulates the document info and a method
to access the document's data.

6. Added APIs for describing the type of a document to the new document
info class. This allows a print service to do smarts based on the
doc type. For now we have only photo and document types.

7. Renamed the systemReady method for system services that implement
it with different semantics to systemRunning. Such methods assume
the the service can run third-party code which is not the same as
systemReady.

8. Cleaned up the print job configuration activity.

9. Sigh... code clean up here and there. Factoring out classes to
improve readability.

Change-Id: I637ba28412793166cbf519273fdf022241159a92
rintJobConfigActivity.java
rintSpooler.java
rintSpoolerService.java
emotePrintAdapter.java
emotePrintDocumentAdapter.java
fd90651cfcc7e2b75254666fd6861038b72fb4ac 24-Jun-2013 Svetoslav <svetoslavganov@google.com> Print APIs documentation update

Change-Id: I0df438e45ef540cc42c9ee5baafc816ebafa1c7b
emotePrintAdapter.java
4b9a4d16872bbb50712e007b419ac0b35ff1582d 12-Jun-2013 Svetoslav Ganov <svetoslavganov@google.com> Print - platform APIs

Related changes:
Skia (inlcude PDF APIs): https://googleplex-android-review.googlesource.com/#/c/305814/
Canvas to PDF: https://googleplex-android-review.googlesource.com/#/c/319367/
Settings (initial version): https://googleplex-android-review.googlesource.com/#/c/306077/
Build: https://googleplex-android-review.googlesource.com/#/c/292437/
Sample print services: https://googleplex-android-review.googlesource.com/#/c/281785/

Change-Id: I104d12efd12577f05c7b9b2a5e5e49125c0f09da
rintJobConfigActivity.java
rintSpooler.java
rintSpoolerService.java
emotePrintAdapter.java