15 Commits

Author SHA1 Message Date
Svetoslav
54adee86af 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
2013-10-11 12:39:47 -07:00
Svetoslav Ganov
f22a767e87 Merge "Added UI for errors during layout and write." into klp-dev 2013-10-11 17:06:12 +00:00
Svetoslav Ganov
caff38821a 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
2013-10-11 10:04:02 -07:00
Svetoslav
7bfbbcb04b 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
2013-10-11 09:11:24 -07:00
Svetoslav
2fbd2a7f07 App UI freezes when printing. API clean up.
1. The UI of a printing app was freezing a little when calling the print
   method since the print manager service was waiting for it to bind to the
   print spooler which generated the print job id (and the initial print
   job info really). Now the print manager service is responsible for job
   id generation and does not not wait for the print spooler to spin. Hence,
   the app UI is not blocked at all. Note that the print manager initiates
   the binding to the spooler and as soon as it completes the spooler shows
   the print UI which is hosted in its process. It is not possible to show
   the print UI before the system is bound to the spooler since during this
   binding the system passes a callback to the spooler so the latter can
   talk to the system.

2. Changed the print job id to be an opaque class allowing us to vary the
   way we generate print job ids in the future.

3. The queued print job state was hidden but the print job returned by the
   print method of the print manager is in that state. Now now hidden.

4. We were incorrecly removing print job infos if they are completed or
   cancelled. Doing that is problematic since the print job returned by
   the print method allows the app to query for the job info after the
   job has been say completed. Hence, an app can initiate printing and
   get a print job whose state is "created" and hold onto it until after
   the job is completed, now if the app asks for the print job info it
   will get an info in "created" state even though the job is "completed"
   since the spooler was not retaining the completed jobs. Now the spooler
   removes the PDF files for the completed and cancelled print jobs but
   keeps around the infos (also persisting them to disc) so it can answer
   questions about them. On first boot or switch to a user we purge the
   persisted print jobs in completed/cancelled state since they
   are obsolete - no app can have a handle to them.

5. Removed the print method that takes a file since we have a public
   PrintDocumentAdapter implementation for printing files. Once can
   instantiate a PrintFileDocumentAdapter and pass it to the print
   method. This class also allows overriding of the finish method to
   know when the data is spooled and deleted the file if desired, etc.

6. Replaced the wrong code to slice a large list of parcelables to
   use ParceledListSlice class.

bug:10748093

Change-Id: I1ebeeb47576e88fce550851cdd3e401fcede6e2b
2013-09-16 17:55:14 -07:00
Svetoslav Ganov
860f8a6b66 Spooler should not crash if print service config activities are not exported.
1. If a print service does not export its activities for settings and
   adding printers the print spooler ignores them instead of crashing.
   Also if the service is not enabled its activities are now ignored.

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

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

bug:10680224

Change-Id: I20b57d6622a15f9b2352ba78d04c44e67b316a15
2013-09-14 01:00:55 -07:00
Svetoslav
1a3ef4fafb Spooler broken on upgrade.
The spooler apk was signed with the platform certificate and used
a redundant shared user id. Now the spooler is signed with a default
certificate and uses the same share user id. Since the shared user
id is associated with the platform certificate the package manager
rejects the spooler apk because it requested the same shared user id
with a different certificate. This change removes the unnecessary
shared user id from the manifest.

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

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

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

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

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

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

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

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

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

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

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

2. Added save as PDF support.

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

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

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

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

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

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

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

2. Added most of the notification assets.

Change-Id: I84f35df5cb4f71b86a103c16ab87fd4d108b055b
2013-08-06 23:52:38 -07:00
Svetoslav Ganov
8c43376ea8 First cut of the print notifications.
1. Added notifications for a queued print job, for a started print job,
       for ongoing canceling a print job, and for a failed print job. The
       notifications for queued and started state have a cancel action. The
       notification for failed print job has a cancel and a restart action.

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

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

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

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

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

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

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

Change-Id: Iba2dd14b487f56e137b90d1da17c3033422ab5e6
2013-08-02 14:22:22 -07:00
Svetoslav
597945fd3a First pass of the print dialog UX
Change-Id: I315a16d7f68c73ca180c76e722847b4b1bdea55b
2013-07-19 16:23:12 -07:00
Svetoslav Ganov
4b9a4d1687 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
2013-06-21 18:43:17 -07:00