Masaryk University Faculty of Informatics

Protocols for printing from mobile devices

Master’s Thesis

Bc. Petr Bartoň

Brno, Spring 2016

Replace this page with a copy of the official signed thesis assignment and the copy of the Statement of an Author.

Declaration

Hereby I declare that this paper is my original authorial work, which I have worked out on my own. All sources, references, and literature used or excerpted during elaboration of this work are properly cited and listed in complete reference to the due source.

Bc. Petr Bartoň

Advisor: Mgr. Juraj Michálek

i

Acknowledgement

I would love to thank my supervisor Mgr. Juraj Michálek, and all employees of Y Soft Corporation, who helped me with consultations, comments and a lot of useful advice during the creation of this thesis.

iii Abstract

This thesis investigates possibilities of printing on mobile platforms and describes available protocols for printing and discovery. The first part of this thesis covers the printing and discovery protocols in general and the second part describes the mobile operating systems Android, iOS, Windows 10 Mobile, Firefox OS and Ubuntu Touch. The main emphasis is put on Android because it is the most popular platform and does not have a full native printing solution.

iv Keywords print, printing, protocols, IPP, Internet Printing Protocol, WS-Print, Zeroconf, mDNS, DNS-SD, WS-Discovery, Android, iOS, Windows 10 Mobile, Windows Phone, Ubuntu Touch, Ubuntu Phone, Ubuntu Tablet, Firefox OS

v

Contents

1 Introduction 1

2 Printing protocols 3 2.1 Line Printer Daemon Protocol ...... 3 2.1.1 Structure of messages ...... 3 2.1.2 Available messages ...... 4 2.1.3 Summary ...... 4 2.2 Internet Printing Protocol ...... 4 2.2.1 Structure of messages ...... 4 2.3 WS-Print ...... 6 2.3.1 Structure of messages ...... 6 2.4 Summary ...... 7

3 Printer discovery 9 3.1 Zero Configuration Networking ...... 9 3.1.1 Individual parts of Zeroconf ...... 9 3.2 Zero Configuration Networking solutions ...... 12 3.3 WS-Discovery ...... 12 3.4 Comparison of discovery protocols ...... 14

4 IPP Everywhere 15

5 Android 17 5.1 Printing prior to Android 4.4 ...... 17 5.2 Printing on Android 4.4 and later ...... 18 5.3 Custom printservice ...... 18 5.3.1 Requirements and limitations ...... 19 5.3.2 Manifest file ...... 19 5.3.3 PrintService class ...... 20 5.3.4 Managing printers in Android print service . . . 21 5.3.5 Handling the print job ...... 22 5.3.6 IPP implementation ...... 22 5.3.7 Authentication ...... 24 5.3.8 Ignoring the server certificate ...... 27 5.3.9 Testing the print service ...... 27 5.4 Existing print services ...... 28

vii 5.4.1 Let’s Print Droid ...... 28 5.4.2 PrintBot ...... 29 5.4.3 Mopria print service ...... 29 5.4.4 Google cloud print ...... 30 5.4.5 HP ePrint ...... 30 5.5 Printing application ...... 31 5.5.1 Printing a bitmap image ...... 31 5.5.2 Printing an HTML document ...... 31 5.5.3 Printing a PDF document...... 32 5.5.4 Printing a custom document ...... 32 5.6 Summary ...... 32

6 iOS 33 6.1 AirPrint ...... 33 6.2 Alternatives to AirPrint ...... 34 6.3 Custom printing application ...... 36 6.4 Summary ...... 36

7 Windows 10 Mobile 37 7.1 Printing before Windows 10 Mobile ...... 37 7.2 Printing since Windows 10 mobile ...... 37 7.3 Alternatives to native printing ...... 38 7.4 Differences between the desktop and mobile version ofWin- dows 10 ...... 39 7.5 Summary ...... 39

8 Ubuntu Touch 41 8.1 Printing on Ubuntu Touch ...... 41 8.1.1 Printing dialog ...... 42 8.2 Summary ...... 43

9 Firefox OS 45 9.1 Printing from Firefox OS ...... 45 9.2 Testing of Firefox OS ...... 45

10 Conclusion 47

viii List of Tables

2.1 Beginning of IPP message attribute 5 2.2 IPP job-name opperation attribute 5

ix

List of Figures

3.1 Message exchanges between a Target service and a Client. Source WS-Discovery documentation [15, p. 10] 13 5.1 System settings of a printing dialog on Android 20 5.2 Setting of the custom print service 23 6.1 Printing from iPhone 6s with iOS 9.3 34 6.2 Printing with HP ePrint from iPhone 6s with iOS 9.3 35 7.1 Printing from the Office application in Windows 10 Mobile 38 8.1 The initial draft of the printing dialog on Ubuntu phone 42

xi

1 Introduction

The goal of this thesis is to map the possibilities of printing from mobile devices like smartphones and tablets. The main focus is on An- droid devices as Android is currently the most used operating system on mobile devices[1], but also less used operating systems or even new, not yet widely used, systems such as Firefox OS and Ubuntu Touch will be covered. Some people could question the necessity for mobile printing at all and argue that printing on mobile devices is not important. Since working with documents is more natural on computer or tablet, it is also better to print them from there. But there are also cases when users appreciate the ability to print from mobile devices, like printing an email they just received, or photo they just took without the need to go back to the computer. There are many reasons but finding the importance of mobile printing is not the goal of this thesis. The focus is on technical details of mobile printing and description of printing on each platform to- gether with the description of existing printing applications. In cases where printing is not yet available, the focus is on proposing possible solutions. First will be a brief description of printing protocols such as Line Printer Daemon Protocol, Internet Printing Protocol and WS-Print, to- gether with the comparison of parts of their communication and description of their differences. The next chapter will describe protocols used for printer discov- ery, which is of particular importance in the mobile world, because unlike with desktop computers, mobile devices are more likely to be used with different printers and manual set up of printers couldbe challenging for some users. The third chapter will be about IPP Everywhere[2] as a general standard for mobile printing. The focus will then aim at each platform individually starting with Android, describing specifics for different versions. A small imple- mentation of printing service, which can discover printers and also print to them, will be included as well. Because the thesis is realized

1 1. Introduction in cooperation with Y Soft Corporation, a.s., the printing service will be tested with IPP endpoint provided by Y Soft. The next platforms will be iOS, as the second most used mobile op- erating system[1] and Windows 10 Mobile1 by as the third. Both these systems have a native printing solution in their latest ver- sion, so the work will focus on how the solutions work and also on other alternative printing applications. Last two chapters will briefly describe Ubuntu Touch by Canonical and Firefox OS by Mozilla. As these operating systems don’t have any native printing solution, the focus will be on the description of what was already done to achieve the print functionality and what is miss- ing.

1. It is specified in the assignment as the Windows Phone version, which is thename of the previous version of Windows 10 Mobile.

2 2 Printing protocols

“Network Protocol is a set of rules that defines the format and the order of messages exchanged among two or more communicating entities, as well as the actions performed during sending/receiving that mes- sages.” [3, p. 13] Printing protocols are then just a special form of network protocols describing communication between printer, print server or the device the user is using to print. In the scope of mobile printing, these devices are smartphones or tablets. It is also possible to send a print job directly to the printer, often referred as RAW protocol, Jetdirect or 9100[4]. In reality, it is not a print- ing protocol but rather a way to send raw data of a print job to the printer on the port 9100. The data must be formatted using a Page Description Language supported by the printer. The following section describes LPR as one of the most basic print- ing protocols followed with IPP used by Apple in iOS and WS-Print used by Microsoft in Windows 10.

2.1 Line Printer Daemon Protocol

Line Printer Daemon Protocol (further as LPR) is a TCP-based protocol described in RFC 1179 [5]. A line printer daemon is located on printer or print server and it is receiving messages on port 515. For every message new connection must be made, as these messages represent commands, which should be interpreted as statements.

2.1.1 Structure of messages

The LPR messages always begin with a single octet code, represent- ing the requested function. After the command code, printer queue name has to be specified. Some commands then have another infor- mation which is located after the queue name. These are separated from the queue name with ASCII white space. End of the message is specified with ASCII line feed character.

3 2. Printing protocols

2.1.2 Available messages As LPR offers only limited control of the printing, the list of avail- able commands is relatively small. The main operations are Print any waiting jobs, Receive a printer job, Send queue state, Remove jobs. The pur- pose of these operations is self-explanatory, only Receive a printer job operation is special because printer expects to receive subcommands containing the job data file or control file. These subcommands have a similar structure as main LPR commands.

2.1.3 Summary LPR is a relatively small protocol which does not allow advanced con- trol of print jobs. Another disadvantage is that LPR is not bidirectional and thus the sender of the job does not receive any feedback when sending messages to the printer. LPR also does not provide any means for authentication used by modern printers.

2.2 Internet Printing Protocol

As well as LPR, the Internet Printing Protocols (further as IPP) is a TCP based printing protocol using the HTTP for communication on Well Known Port 631[6, p. 19]. The communication is distinguished with Content-Type property of the HTTP connection set to application/ipp. An important difference to LPR is that IPP messages are bidirectional and that is why a response is sent for every received request. Another advantage is the possibility to use IPP with TLS within HTTP/1.1. The latest IPP standard was released in 2015 [7]. It contains a de- scription of IPP version 2.0, 2.1 and 2.2 and also their differences. The first version of IPP (IPP 1.0)[8] dates back to the year 1999.

2.2.1 Structure of messages The IPP operations are, as in LPR, encoded using a simple binary encoding. This subsection will show an example of the "print-job" IPP operation. The message could be split into four sections.

4 2. Printing protocols

Attribute name Value Byte representation in hexa IPP version 1.1 01 01 Operation id Print-Job 00 02 Request id Request id 00 00 00 01

Table 2.1: Beginning of IPP message attribute

Attribute name Value Byte representation in hexa Value Tag nameWithoutLanguage 42 Name length 8 00 08 Name job-name 6A 6F 62 2D 6E 61 6D 65 Value length 7 00 07 Value testjob 74 65 73 74 6A 6F 62

Table 2.2: IPP job-name opperation attribute

The first section contains IPP version, Operation id and Request id as described in the table 2.1.

The second section starts with byte 01 which specifies operation attributes. Each attribute is made from five parts. The first attribute is value tag, identifying the type or syntax of the operation, then there is name length, specifying the length in bytes of the following value called name. The name is then the textual rep- resentation of the requested operation. The fourth is the value length in bytes of the value followed by the value itself. The table 2.2 describes the job-name operation attribute. But there are more attributes used when printing the job. For example printer-uri and attributes-natural-language.

The third section of IPP message operation starts with the byte 02 and represents job attributes. This section contains the job details like

5 2. Printing protocols the number of copies or whether the job is one sided or two sided. The job attributes are in the same format as operation attributes.

The fourth section starts after the end of the IPP attributes which is set with byte 03. This section represents the attached print job data already formatted in supported Printer Description Language (PDL). The third and fourth section are present only in a case of the print- job operation. Otherwise, the byte 03 is already located after the second section.

2.3 WS-Print

WS-Print, which stands for Web services on devices for printing, provides a connection protocol for printing and scanning.[9] Two most important components of web services, in order to be able to introduce the WS-Print functionalities, are SOAP and WSDL. SOAP (Simple Object Access Protocol) is used for the communica- tion between the printer or the print server and the printing device. The SOAP protocol defines its messages using the XML format[10]. WSDL (Web Services Description Language) serves as a language for describing Web Services which also uses the XML syntax. Web Services are then specified in files called WSDL Documents. WS-Print is available since 2007 but the support for mobile print- ing was introduced in 2015 in the version 2.0, when new functions which enabled the driverless printing were added[11, p. 120]. Together with the WS-Print specification, there are also WSDL Documents avail- able for each version, which can be used for creating the WS-Print compatible applications.

2.3.1 Structure of messages As with the IPP protocol, the following example describes the printing operation of WS-Print. Printing of the job is divided into two operations. First is Cre- atePrintJob which sends to the printer basic information about the job like the job name, the username of the sender and other job and docu- ment processing information. The printer must respond to this mes-

6 2. Printing protocols

sage with a print job ID which is then used when sending the actual job with the operation SendDocument or sending a URL reference to the data with the AddDocument operation. Both of these operations must be sent within 60 seconds after the printer received the CreatePrintJob operation. The following example shows a part of a body of CreatePrintJob request. Example Job Smith 3 50 ... Landscape Draft OneSided ...

The whole example of creating and sending print job is available in the WS-Print documentation. [11, p. 67, p. 70, p. 74]

2.4 Summary

When choosing a printing protocols, it should be decided on the re- quired level of the printing control, which protocols should be used and also on the protocols required printers support.

7 2. Printing protocols

The easiest option is to send the job using the RAW "protocol" which doesn’t require any additional work. But for more advanced functionality, either IPP or WS-Print should be used. When talking about the mobile environment, there are usually a few additional requirements in comparison to desktop comput- ers. The main requirement is lowering the demands of applications on hardware and thus saving the battery. However, even in the case of IPP or WS-Print the additional power required is so minimal that there is no reason not to use IPP or WS-Print in mobile environments.

8 3 Printer discovery

There are a few options how to discover printers on the network. Printers can be added manually when the IP address is known, but that is not the preferred way for mobile devices. The expected behavior is to see all the available printers nearby. Furthermore, the discovery should be cross-platform, so it is possible to find and connect to the same device from each operating system.

3.1 Zero Configuration Networking

Zero Configuration Networking, further as Zeroconf, is maintained by IETF Zeroconf Working Group, which was chartered in 1999[12]. The main purpose of Zeroconf is to enable the creation of network products which costs of setting up, configuring and maintaining a network would be otherwise too high. The side effect of this purpose is also less work for users as no additional action is required from the user. In short, Zeroconf is the ability to find a device in the network without user intervention.

3.1.1 Individual parts of Zeroconf There are four main requirements of Zeroconf[13]. Zeroconf is looking to improve name-to-address translation and IP interface configura- tion and also to introduce service discovery and multicast address allocation.

Name resolution The name-to-address translation requires the abil- ity to obtain the address associated with a name and on the other hand, determine the name assigned to an address. This can be easily achieved by using a DNS server, but this is not an option for the Ze- roconf environment where it is possible that the DNS server is not installed[13, p. 10]. This problem has been solved with multicast DNS (further as mDNS), described in RFC 67621.

1. http://www.ietf.org/rfc/rfc6762.txt

9 3. Printer discovery

The important thing is realizing that the existing DNS, that the de- vices support, can be used to send the DNS query over multicast. So instead of designing whole new protocol mDNS is using the existing DNS protocol.

IP interface configuration The IP interface configuration is solved with Dynamic Configuration of IPv4 Link-Local Addresses specified in RFC 39272 which is addressing the issue of assigning the IP address without user intervention and without DHCP server. In short there are few steps required for dynamic assignment of an IP address. First, the node will self-assign random address, then it uses ARP to find out whether somebody is already using the address. Ifno one is using it, then the node keeps the address. Otherwise, the node will repeat the process until he finds an unused address.

Service Discovery Services can be discovered using the DNS Ser- vice Discovery, further as DNS-SD, specified in RFC 67633 which allows to browse the network and discover its content. DNS-SD is using the DNS SRV records to describe the service instance and DNS TXT records to provide additional information, which are stored as key/value pairs. The DNS TXT records should not replace description available through protocols which are later used for communication with the devices. For example in the case of printers are advertised just basic access, identity and capability information. That is, for instance, name and page description language (PDL) of our printer, allowing to filter only printers (or print servers), that use supported protocol. Additional information, like color support and page margins, is then provided with some printing protocol. DNS-SD used together with mDNS provides zero-configuration functionality. DNS-SD/mDNS devices are advertised with its services on the network with no user interaction[14, p. 3]. When discovering printers, instead of records of type DNS SRV, records of type PTR are requested. This returns list of all available

2. http://www.ietf.org/rfc/rfc3927.txt 3. http://www.ietf.org/rfc/rfc6763.txt

10 3. Printer discovery printers on the network instead of just one random available printer[14, p. 6]. The following query is a sent to local network when discovering printer: _ipp._tcp.local.

This request discovers devices on the local network implementing the _ipp._tcp service type and as a result expect one or more records with discovered instances. The following responses are possible responses from two printers. Printer A._ipp._tcp.local Printer B._ipp._tcp.local

Structure of these responses is as follows:

∙ user friendly instance name (Printer A)

∙ service type (._ipp._tcp)

∙ domain (.local.)

Additionally to the PTR records, TXT records are also sent. The following example shows a structure of an additional TXT record specifying the PDL of the printer. .pdl=application/postscript.

The "." represents line feed symbol from ascii table. (0A symbol in hexa)

Multicast address allocation There are three requirements[13, p. 14] specified for the multicast address allocation protocol. The selected address must be a multicast address, has to prevent conflicting alloca- tion of an address and allow the address to become available after it is no longer in use. The multicast address allocation is still marked as future work on the Zeroconf homepage[12].

11 3. Printer discovery 3.2 Zero Configuration Networking solutions

The following implementations implement the DNS-SD/mDNS dis- covery.

Bonjour is Apple’s Zero Configuration Networking solution. The original version was called Rendezvous and was released in 2002 but three years later in 2005 the "Rendezvous 2" was released under the name Bonjour. Bonjour is open source and licensed under the Apache 2.0 license. It’s not only available for OS X and iOS but also for Windows operating system.

Java implementations The biggest is jmDNS, which also works on Android. Another implementation of mDNS discovery is by Mopria Alliance. Its initial version was released in 2.2. 2016 in experimen- tal packages section for Android and as jmDNS is licensed under the Apache 2.0 license. One more Java implementation is natively in Android and is called NsdManager. These implementations will be discussed more with their advan- tages and disadvantages under the section describing printer discovery in Android.

Avahi implementation In 2005, a complete implementation of DNS- SD/mDNS was also made for Linux by Avahi. It is licensed under LGPL license and used for example by CUPS.

3.3 WS-Discovery

The next discovery protocol covered in this thesis is WS-Discovery. WS-Discovery as well as WS-Print uses web services functionality and sends SOAP messages to a multicast address which enables services to be discovered by the client. For communication, WS-Discovery defines six messages Hello, Bye, Probe, Probe Match, Resolve and Resolve Match message, as shown in the Figure 3.1 on page 13.

12 3. Printer discovery

Figure 3.1: Message exchanges between a Target service and a Client. Source WS-Discovery documentation [15, p. 10]

The purpose of the Hello message is to announce the availability of the web service on the network. So when some application using WS-Discovery is started, it sends first the Hello message. On the other hand, when this application is properly shut down, it sends the Bye message that announces the departure of the device from the network. Both of these messages have no specific receiver as they are sent with multicast using UDP and port 3702 and are very simple as they contain no additional information. Furthermore, Hello and Bye messages also contain sequencing information which is used to maintain correct sequence of messages even if they are received out of order. The Probe message is also sent using multicast by the client applica- tion, and its goal is to search for services. The content of this message is identification as Probe message, Message ID, WS-Discovery types, and scopes. The Probe Match response is sent using unicast to the Probe message sender. There are up to two constraints according to which it is decided if the Probe matches. One of them is the type of the Target Service, and the other one is Scope of the Target Service. These constraints can be combined and also, none has to be sent in the Probe message.

13 3. Printer discovery

In the case of printer discovery, the Probe message contains the type wsdp:Device. The Resolve message and the Resolve Match response work in a simi- lar way but their responsibility is to locate the Target Service for known Endpoint Reference and thus retrieve its transport address.[15, p. 23]

3.4 Comparison of discovery protocols

When comparing Zeroconf and WS-Discovery, there is no big ad- vantage of any of these protocols over the other. A small advantage of mentioned Zeroconf implementations could be a minimalistic form of messages sent through the network, but the same functionality can be achieved with both of these protocols.

14 4 IPP Everywhere

Printing and discovery protocols themselves are general technologies used for printing. IPP Everywhere [2] specification was released by the Printer Working Group in order to suit the needs of mobile printing. For example Android devices since Android 4.4 come with native support for IPP Everywhere[16]. This is not yet another protocol but more of a specification of a set of existing protocols and document formats with the focus on mobile printing. IPP Everywhere is, therefore, extending the IPP specifica- tion with printer discovery and document formats and thus enabling printing without vendor specific software such as drivers for printers. IPP Everywhere mentions five discovery protocols where DNS- SD and WS-Discovery based discovery must be supported. [2, p. 20] Optionally also LDAP, SLP and SSDP discovery protocols may be used. Beyond that, it also specifies a minimal subset of printer description attributes for each of the protocols. As for the IPP protocol used for printing, IPP Everywhere specifies operations and attributes which must be implemented and also states that version IPP/2.0, IPP/2.1 and/or IPP/2.2 must be supported. [2, p. 33] IPP Everywhere defines support for three document formats. Printer must support documents in PWG Raster Format [17] ("image/pwg- raster") and JPEG File Information Format in version 1.02 [18] ("im- age/jpeg") and printers supporting IPP/2.1 and IPP/2.2 must support documents in "Portable document format" in version 1.7 [19]. This is not mandatory for printers supporting IPP/2.0 though it’s recom- mended. Furthermore, printers should support Open XML Paper Specifica- tion format [20] which defines layout and appearance of the document using XML.

15

5 Android

In this chapter, I focus on the development of a custom printing solu- tion for Android, examining existing printing solutions and the devel- opment of an application which is able to use the printing solution. Furthermore, I describe the possibility of using username and pass- word, or user certificates for authentication. During the creation of this thesis I also published a blog post on the YSofters blog which describes how to make the custom print service on Android1. Printing in Android is supported natively since Android KitKat (4.4)[21], allowing existing application just to use the system API which handles printing itself with an additional application called PrintService. However, because almost 25%[22] of devices has still an earlier Android version, the first section is about the situation before the release of Android KitKat.

5.1 Printing prior to Android 4.4

Printing in Android version before Android KitKat was also possible, but it had a few drawbacks. On his own, the user had to install an application which was able to send the print job. I will call this appli- cation a printing application. Then there were usually two options how to use the printing application. The first is that in the application from which the user wanted to print, he had to use the share button and share the document into the printing application which he downloaded beforehand. In the end, he could only hope that the application he shared the document from used file format which the printing application understood and could parse. Depending on how advanced the printing application was, the user could then select printing options like page ranges, copies, etc. The second option, the printing applications usually provided, was to open the printing application which usually contained a file explorer and the file could be selected from there.

1. https://www.ysofters.com/2015/10/09/printing-on-android-devices/

17 5. Android

This process may seem straightforward, but another drawback of this approach is that the printing applications were usually designed differently which could be confusing for the user.

5.2 Printing on Android 4.4 and later

Android 4.4 brought a lot of easement into the printing area. Google created a system API, which allowed the communication between the printing application and the application from which the user wants to print and thus provided a native and consistent look and control to the printing solution. The printing applications using the printing API are then called print services. The print service is able to show the preview and simple settings to the user, and it doesn’t matter who created the actual printing application. This functionality was introduced in Android KitKat in API 19[21] in 2013. Later with API 23 in Android 6 Google also added the possibility to set simplex or duplex printing[23]. Available options should always be set according to the selected printer by the printing application. It is required from the developer of a print service to ensure the dis- covery of available printers on the network or allow the user to set them manually and provide them to the printing API. Then, correct commu- nication with the printer must be ensured with any printing protocol. Besides, Android uses PDF as the primary printing format[24] for files, so the developer has to make sure that the printer will understand the file format.

5.3 Custom printservice

This section describes the creation of a custom print service which uses mDNS discovery and an IPP protocol. Although Google provides two simple examples2 of a print service, both of them have only statically added printers and they don’t actually send the jobs to the printers.

2. https://android.googlesource.com/platform/packages/experimental/ +/master/PrintService/ and https://android.googlesource.com/platform/ packages/experimental/+/master/PrintService2/

18 5. Android

5.3.1 Requirements and limitations When I wanted to create my custom Print Service, the first thing I dis- covered was that Android doesn’t contain any printing protocols on its own. I didn’t find any available implementations in the current An- droid version (API 23), so I had to create my own. I decided to imple- ment a very small subset of IPP protocol, just to be able to send a job and confirm that this approach will work. In the next step, I was focusing on printer discovery. I chose mDNS because Android has a native implementation of this protocol called NsdManager which allows printer discovery natively. Little did I know about problems with this implementation. The main issue with NsdManager is reading TXT records. To put it simply, it’s not possible. The function is present in the NsdManager, so theoretically it should work, but there is a bug and the returned result of that function is always empty. This problem has been already reported3, but it is present in the Android system since version 4.1 released in 2012. For support of even older system an implementation called RxBonjour can be used. It is a wrapper around Android’s net- work services[25] which adds support for mDNS discovery down to Android 2.3 (API 9). Luckily, there are other libraries which can be used to enable mDNS discovery on Android such as JmDNS. There was also one issue I en- countered which didn’t allow to discover printers with white charac- ters in their name, but it was fixed in the following version (3.4.2).

5.3.2 Manifest file The manifest file in Android applications is used to setup permission and activities of its applications. When using the print service, a handling Intent with the action android.printservice.PrintService must be declared in the Manifest file as well as the request for the android.permission.BIND_PRINT_SERVICE permission. This will allow the system to identify the print service. Furthermore, optionally in the manifest file meta-data can be set with resource name, where activity for adding printers and addi-

3. Report of the bug in NsdManager: https://code.google.com/p/android/ issues/detail?id=136099

19 5. Android

Figure 5.1: System settings of a printing dialog on Android tional settings can be specified. This will appear in the printing dialog as a MORE OPTIONS button, which can be seen in the Figure 5.1. The whole manifest file is in the attached custom print service project.

5.3.3 PrintService class

The first step when implementing Android print service is to extend the PrintService class and implement its abstract methods. The PrintService class has two responsibilities. The first is to dis- cover and manage the printers, and the other responsibility is to handle the print job.

20 5. Android

For managing printers, abstract method onCreatePrinterDiscovery- Session must be implemented, whereas abstract methods onRequest- CancelPrintJob and onPrintJobQueued are used for handling the job.

5.3.4 Managing printers in Android print service When implementing the onCreatePrinterDiscoverySession method, the returned object must be an instance of implementation of a Printer- DiscoverySession class, which is responsible for managing the printers. That includes adding and removing printers and tracking print state. PrinterDiscoverySession has six abstract methods which must be implemented. The first method executed by the Android operating system is onStartPrinterDiscovery. This method is called when the user opens the list of available printers and is responsible for getting at least the minimum information needed so that the printer can be added to the list of printers. It is better to discover and add concrete printer capabilities later when a printer is selected because otherwise it would slow down the whole discovery process in environments with more printers. This also stands for the onValidatePrinters method which is called after the onStartPrinterDiscovery method and is responsible for checking if the printer exists. When the printer is already added and selected by the user, then the onStartPrinterStateTracking method is called. Its responsibility is to add the printer capabilities. Printer without set capabilities will be otherwise ignored. Another responsibility is to regularly check the state of the printer and update the system until the method on- StopPrinterStateTracking is called. When the printer discovery is no longer needed, the onStopPrin- terDiscovery method is called, thus stopping the discovery. In this state, the print service is still ready to start the discovery again with calling the onStartPrinterDiscovery method but when the print service is finally terminated, the onDestroy method is called which frees all the used resources. In the example project included in the attachment of this thesis, there are two small implementations of the PrinterDiscoverySession class. One is using the Android native NsdManager and the other one uses the JmDNS library. It is possible to switch between used discovery

21 5. Android method with the More button in the printer discovery section. Selection of a printer discovery method can be seen in the Figure 5.2 on page 23. It should be noted that this implementation just statically adds the printer capabilities because the IPP operation which should be able to load these capabilities is not implemented.

5.3.5 Handling the print job Once the user selects the required printer, the printing options and then tries to print, the method onPrintJobQueued is called. This method is responsible for handling the print job saved on the system spooler from another application, so when the user tries to print, the print job is spooled by the system and its data can be retrieved by calling the getDocument method. The instance of the PrintDocument class re- ceived by the getDocument method also contains additional settings set by the user in the printing dialog. Furthermore, the job has different states. At first, when the job is sent to print, its queued but when starting to print, it is changed to started with the start method. If the job is printed, then it should be either marked complete with the complete method or failed with the fail method, according to the result of printing. It is also possible to cancel the print job with the cancel method. Handling the canceled job is a responsibility of the onRequestCancel- PrintJob method of the PrintService class.

5.3.6 IPP implementation Once the print job is started, it is necessary to use a printing protocol to send the job to the printer. As a protocol for printing, I choose IPP because it is easy to create a function that is able to send a job and I could also test the implementation with the IPP endpoint used for YSoft SafeQ and a CUPS server. But as the creation of a full implemen- tation of IPP is not in the scope of this thesis, the used implementation is very simple and is intended mostly as a proof of concept than an actual implementation. The only implemented function of IPP protocol is Print-Job with methods which could create the header with correct settings and then just append the job data to the end.

22 5. Android

Figure 5.2: Setting of the custom print service

23 5. Android

A full example is attached to this thesis in the IPPMessage.java file of the Android custom print service project. Once the job is created, it might be possible to send the job directly to the printer, but in some cases, it is also possible that some authenti- cation will be necessary for the used print or print server. It is usually a login dialog asking for username and password or a user certificate. This can also be handled in the handleQueuedPrintJob method and will be discussed in more detail in the following chapter.

5.3.7 Authentication Username and password When authenticating with username and password, the simplest way is to send the information directly in the HTTP/HTTPS connection property. The following example contains Java code with the creation of an HTTPS connection with username and password on Android. HttpsURLConnection connection; URL url = new URL("https", serverAddress,severPort,"/"); connection = (HttpsURLConnection) url.openConnection(); String userPass = userName +":" + password; String encoded = Base64.encodeToString(userPass.getBytes(), Base64.DEFAULT); connection.setRequestProperty("Authorization","Basic"+ encoded);

User certificates Another way to authenticate the user is to use a user certificate. Importing a user certificate into Android can be done infew steps and in case it is enabled on the server side in can be used for user authentication. The first step is to import the user certificate. This can slightly differ according to changes made by the device manufacturer and Android version. The following steps describe adding user certificate in Android 4.4: 1. Save the client certificate file (.pfx) somewhere on your Android device. 2. Go to Settings -> Security -> Install from storage

24 5. Android

3. Find the certificate file and click on it.

4. Set the password when prompted, confirm the Common name, and then the certificate will be imported.

Note that the certificate can be added only when the user set apass- word for his lock screen. If no password is set, then the user is asked to set one.

Selecting the user certificate When using the user certificate authen- tication in an application, the user must be asked which certificate he wants to use for the authentication. To demonstrate the user certificate authentication, another sim- ple application called Certificate Sender is included in the attachment of this thesis. When selecting the certificate, the goal is to call the static function choosePrivateKeyAlias from the KeyChain class which starts a dialog for selecting imported client certificate. Note that in the Certificate Sender application the certificate is not saved. Nevertheless, when using the user certificate in a real applica- tion it is supposed to be saved, so that the user is not asked every time which certificate should be used.

Sending the certificate Once the certificate was selected, the request can be sent. In the user certificate prototype, there is for this purpose an asynchronous task because all of the network work must be done outside of the main thread. The following steps describe how to send the user certificate.

1. Create an instance of TrustManager class which handles trust data used to make trust decisions[26].

2. Load the stored certificate and its private key.

3. Initialize instances of KeyStore and KeyManagerFactory classes.

4. Create SSL context and initialize it with the TrustManager and KeyManagerFactory instance.

5. Create the connection

25 5. Android

The full example can be seen in the Certificate Sender project at- tached to this thesis.

Testing server accepting the user certificate Providing user certifi- cate is useful in cases when there is a print server with connected printers. This print server then authenticates the user with his certifi- cate and sends the job to the printer when needed. For testing purposes, I have created an Owin4 middleware which can check the certificate and eventually, in the case of successful au- thentication, send the job to the next middleware. The following example considers a Katana server, which is an im- plementation of Owin. The Katana server could be already working printing server without the certificate authentication. Adding the mid- dleware is then done without interference with the original code. The following pseudo-code shows very simple check of the sent certificate: public override async Task Invoke(IOwinContext context) { if (no there are no certificate errors) { load the~certificate from the~context if (the certificate is equal to~one of~the user certificates) { await Next.Invoke(context); } } } }

The complete class can be seen in the Katana Certificate Authen- ticator project attached to this thesis but when used in a real world application it would still require some extension. Primarily, it is - essary to have the user certificates stored on our server, so that itis possible to compare the received certificate with our list of certificates

4. “Open Web Interface for .NET (OWIN) defines an abstraction between .NET web servers and web applications.”[27]

26 5. Android

and then only if the certificate is valid, the next middleware will be invoked. As this project was only used to test if the certificate is sent cor- rectly from an android application, the rest of the print server is not implemented, but the project shows how easy it is to extend an existing Katana print server with new functionality and eventually completely restrict an unauthorized user from accessing the server.

5.3.8 Ignoring the server certificate During the testing of the custom print service, I encountered a problem with server certificate when using HTTPS connection, as the server was not certified with any trusted certificate authority. This can be solved either by using a server with a valid server cer- tificate or ignoring this certificate. As this is just a prototype ofaprint service, I chose to ignore the server certificate in this implementation. The attached custom print service project allows to switch between the HTTP and HTTPS connection in the settings5. Entire example of how the certificate can be ignored can be seen in the class PrintTask in method setTrustedCertificates. In the final solution, the server certificate should not be ignored.

5.3.9 Testing the print service This thesis is done in cooperation with Y Soft Corporation and thanks to that, I had the opportunity to test the application in the company. Y Soft, among other products, creates a print server which can be discovered using the mDNS discovery and is able to receive print jobs using the IPP protocol. The received job is then sent to another product called YSoft SafeQ which later ensures the communication with printers. The print service was placed under the beta testing program in the Google Play store and made available to the Y Soft employees who installed the application on 15 devices. Most of the users encountered no problems, but for some the job did not complete successfully and they tried to restart the print job from a system printing dialog, which resulted in a java.lang.NullPointerException.

5. See the Figure 5.2 on page 23 27 5. Android

This problem happened because when the job was restarted and placed again into the queued state, it tried to acquire the printer infor- mation from a map of discovered printers, but this map was already destroyed and thus the NullPointerException was thrown. I handled the exception just by catching it and marking the job as complete. How- ever, in a real application it would be necessary to store the printer de- tails and in case a print job is restarted, one needs to check if the printer is still present in the network and eventually send the job again.

5.4 Existing print services

There are a lot of implementations of print services on the Google Play which could be separated into three partially overlapping groups. The first group would contain print services made by printer manu- facturers. Few examples are Canon Print Service, Samsung Print Service Plugin and Print Service Plugin. The advantage of these print services is that they should work without problems with supported printers. On the other hand, the print services usually discover only printers for each manufacturer, and that is why the user needs to have more print services installed in a case when he uses printers made by different manufacturers. The second group of print services tries to be universal and cover as many printers as possible. Few examples are Let’s Print Droid, Print- Bot and PrinterShare. The obvious advantage is the ability to cover all the printers with just one print service. The disadvantage is that the cre- ators of these applications usually cannot test the print service with all printers before releasing the application. The third group covers the cloud print services. The advantage for these print services is the ability to print from anywhere to the cloud-connected printer. On the other hand, the user has to rely on the trustworthiness of the cloud owner and that his data will not be mis- used.

5.4.1 Let’s Print Droid Let’s Print Droid (further as LPD) is one of the most advanced print ser- vice application available on the Google Play and it currently supports

28 5. Android

Android 2.3 and higher. For the printer discovery, the mDNS discovery is used and it is able to print over the LPR, IPP and JetDirect/RAW protocols [28]. But LPD is not just a casual print service. It has also the ability to act as a Print Server; it can receive a print job from an iPhone or iPad with iOS or another device and then send the job to the printer which might not be supported by the original device sending the job. LPD also supports cloud printing using the Google Cloud Print which can be added to the list of printers.

5.4.2 PrintBot The PrintBot application by zenofx.com supports automatic discovery of printers on the local network or adding the printers manually. The supported printing protocols are IPP, LPR and JetDirect/Raw which can be selected when adding the printer. Unlike the other mentioned print servers, PrintBot uses the printer drivers and currently supports more than 3800 printers[29]. The PrintBot application, of course, does not install all of these drivers on the device, but it is using a render- ing server[30]. This server receives the print job from the print ser- vice, converts the file into a specific printer language, and then sends the converted job back to the print service. Thanks to that, the actual size of the application in the latest version 3.1.0 is less than 10 MBs. The benefit of this approach is that drivers make sure, that thefile sent will be properly formatted for each of the printers and thus this allows support for more legacy printers which can’t communicate with a universal file format like PDF. The disadvantage of using a third party server is that the user has to trust that the communication with the server will be secured and that the owner of the server won’t misuse the documents. Furthermore, printing with PrintBot will not work without the Internet connection.

5.4.3 Mopria print service Because of the diversity and uncertainties in mobile printing, a new organization called Mopria was established in 2013[31, p. 11]. Mopria is an alliance of print manufacturers, trying to unify printing from mobile devices, which is achieved with releasing of mopria certified

29 5. Android printers. These printers must support mDNS discovery and IPP 2.0. The original founders were Canon, HP, Samsung, and Xerox, but very soon other manufacturers joined. Currently, the only supported platform for mopria certified print- ers is Android with the Mopria Print Service. All the supported printers can be found on the Mopria home page6 and Mopria already supports more than 800 devices by 16 manufacturers[31, p. 11]. The Mopria Print Service is also slowly being preinstalled on new devices. The first smartphone with preinstalled Mopria Print Service was Huawei Mate S.

5.4.4 Google cloud print Google also has one print service implementation on his own. It’s called Google cloud print and as the name indicates, it’s more than casual print service. Google Cloud Print connects cloud with printer and with that can be used from any device to any printer connected to the cloud. The printer must be added to the cloud manually, and then the user can print from anywhere in the world no matter if he is on desktop or smartphone. The main advantage, except the described mobility, is that prac- tically every printer is supported by this service because the Google Cloud Print uses drivers for the printer and thus removes the need for PDF file support. And in case the printer doesn’t support printing from the cloud, the user can connect it to the cloud through his per- sonal computer. Due to this, even simple USB printers are supported by the Google Cloud Print. The only limitation is that the personal computer must be running so that the printing can start.

5.4.5 HP ePrint HP ePrint is another cloud-based technology for printing. The job is received via a unique email address assigned to the printer which enables to print with e-print practically from anywhere. Furthermore, because an email is used, there is no need to use the print service, though it is more user-friendly than sending the job via an email application. Supported file formats are Microsoft Word, Microsoft

6. List of Mopria certified printers http://mopria.org/certified-products 30 5. Android

PowerPoint, Microsoft Excel, text files (.txt), PDF’s HTML, and images (BMP, JPG, PNG, GIF, TIFF)[32].

5.5 Printing application

This section describes how to use the Printing API to create an appli- cation from which the user will print. As the android uses the PDF document format, every application with the ability to print must be able to convert its output in PDF format. For this purpose, Android has classes which are able to perform this task so that all of the data which the application can draw, can be also exported to PDF.

5.5.1 Printing a bitmap image For printing bitmaps, Android provides a class called PrintHelper. Thanks to this class, the only requirement is to decide whether the page will be scaled to fill or to fit[24]. Scale to fit ensures that the image will be scaled in a waythat the whole image fits on the printed page and nothing is left out,but because the image size ratio is preserved, there may be empty spaces on the sides. On the other hand, scale to fill scales the image in a way that the whole printed page will be filled, but because it also preserves the image size ratio, some parts of the image won’t be printed.

5.5.2 Printing an HTML document When printing HTML it must be loaded as a WebView object which can be either local or generated on a server. Some limitations were also introduced[33] with release of the An- droid version 4.4:

1. Headers or footers, including page numbers, cannot be added to the document.

2. Printing page ranges are not supported for the HTML document.

3. An instance of WebView can only process one print job at a time.

31 5. Android

4. An HTML document with CSS print attributes is not supported.

5. JavaScript in a HTML document cannot trigger printing.

5.5.3 Printing a PDF document. Android provides a PdfDocument class which is able to load the docu- ment. The task is then to draw this document and print it.

5.5.4 Printing a custom document It is also possible to create a custom printing document, which can be completely customized including the fonts, headers, footers etc. Once the document is prepared, it can be printed as a PDF file described in the previous subsection. Android training guide provides7 detailed description of all parts which must be implemented to create the custom printing document.

5.6 Summary

Printing on Android offers enormous potential. Google is not forcing anyone to use their printing solution, which allows the user to choose the most suitable solution for them. On the other hand, it requires a little more work from the user, to find the most suitable printing service, but that could be eventually solved by the work of the Mopria alliance, once the print service will be preinstalled on more devices.

7. http://developer.android.com/training/printing/custom-docs.html

32 6 iOS

The iOS by Apple supports printing natively with a technology called AirPrint since iOS version 4.2 released in 2010[34]. The goal of AirPrint is to be able to send jobs from devices without the need to install addi- tional drivers. Overall functionality is similar to the IPP Everywhere specification, but unlike Google, Apple doesn’t provide the ability to connect custom services with their printing API. On the other hand, there is no need to install additional software, like print services in An- droid, to make the printing work.

6.1 AirPrint

There are only a few requirements for printing with AirPrint. First of all, the user has to be connected to some wifi network and either printer supporting AirPrint natively or some print server which can resend the print jobs to connected printers must be located on this network. In the case when the printer is not AirPrint compatible, it is possi- ble to use third party application for printing. The drawback of this approach is not being able to provide the feeling of a native system application for the user. So the user is not able to print with a print button from an open application. From a technical point of view, Apple uses mDNS for printer dis- covery and IPP as a printing protocol[35], but because AirPrint speci- fication is not public, there are no further details as to how arethese protocols used and if there are any changes from other implementa- tions. The workflow when using AirPrint is very simple. After opening a printable document like pdf, it is necessary to click on the share button located in the bottom left corner. There, among other options, is the Print button as can be seen in the Figure 6.1. In the following dialog the number of copies and page ranges can be set and after selecting a printer, other advanced options like double sided and black & white printing can be specified. An example of selected document can be seen in the Figure 6.1 on the right side.

33 6. iOS

Figure 6.1: Printing from iPhone 6s with iOS 9.3

After pressing the Print button, the job is either immediately sent, or when authentication is required on the printer, then the user is asked to enter his username and password. This login information is then stored for future printing and unfortunately cannot be reset on the phone.

6.2 Alternatives to AirPrint

Other implementations of printing applications are available on the App Store. Some of them are also available for the Android operating systems and are described there. This is mainly true for the appli- cations made by printer manufacturers which can be used for their printers but also for some of the universal applications and cloud applications.

34 6. iOS

Figure 6.2: Printing with HP ePrint from iPhone 6s with iOS 9.3

There are usually, but not always, two options how these applica- tions can be used. One is to open the document and share it to the printing application and the other is to open the application and find the file using a file explorer there. On the left side of the Figure6.2 the option to share an open PDF document to the HP ePrint applica- tion can be seen, which is located just next to the Print button used for the AirPrint. On the right side of the Figure 6.2, there is a preview of the PDF document. This document looks very different to the native AirPrint solution and is unlike any printing application and thus can be confusing to the user.

35 6. iOS 6.3 Custom printing application

As can be seen in the previous chapter, a custom printing application can be also created. Apple also provides libraries for mDNS/DNS-SD discovery which is also used by AirPrint, but the IPP implementa- tion in AirPrint is not available for other applications in the system. Therefore, creating a printing application would require another im- plementation of some printing protocol as in the Android custom print service. Because this would be just rewriting of the code created for the IPP implementation created for Android, I have decided not to create the printing application, because it would not provide any additional information.

6.4 Summary

When compared to the Android operating system, iOS has the ad- vantage of a built-in printing solution, which does not require addi- tional setting up by the user. Even though this solution forces users to have AirPrint certified printers, the fact that AirPrint is used already on more than 2000 thousand printers1 reduces this limitation.

1. Montly updated list of AirPrint certified printers https://support.apple.com/ en-us/HT201311 Latest update was on Apr 28, 2016

36 7 Windows 10 Mobile

Windows 10 Mobile is the third[1] most widely used operating system on mobile devices. This chapter will focus mostly on the Windows 10 Mobile version where the printing support became native, but the situation in the previous version, called Windows Phone, will be also mentioned.

7.1 Printing before Windows 10 Mobile

The situation in Windows phones before Windows 10 was released is similar to the Android environment before the Android 4.4 (Kit Kat) release. There were applications that allowed users to print but the user either had to go through the printing application and find the file he wanted to print or share the document to the printing application. There was also application supporting the Google Cloud Print and offering the same experience as described in the section with Android operating system.

7.2 Printing since Windows 10 mobile

Microsoft started to support native printing in 2015 with the release of Windows 10 Mobile and they used WS-Print as a printing protocol and WS-Discovery for printer discovery. The same technology is used for printing in the desktop version of Windows, which is available since the year 2007 in Windows Vista[9]. When compared to other iOS and Android, the system of printing is more similar to printing in iOS than to printing in Android devices, because Microsoft doesn’t offer printing API for the creation of custom print services as Android does. With the native printing the option to print as pdf to Windows 10 Mobile[36] was also added. The native printing solution supports over 1900 printers[36] by different manufacturers. In the Figure 7.1, example of Printing from Microsoft Office ap- plication can be seen on the left side and on the right side there is

37 7. Windows 10 Mobile

Figure 7.1: Printing from the Office application in Windows 10 Mobile a dialog with preview, printer selection and printer setting. Note that on the picture there is preselected printing to PDF file.

7.3 Alternatives to native printing

On the Windows Market there are a few applications with printing sup- port. For the Brother and Samsung printers are there a by their printer manufacturers both of these applications offer automatic discovery as well as manual setting up of the printer. Another free application are the Custom Print and WinPhonePrint. The Custom Print application supports discovery of wifi as well as Bluetooth printers but doesnot allow to setup printers manually. The WinPhonePrint supports print- ing with HP ePrint printers which can be either manually added or automatically discovered if they are located on the local network.

38 7. Windows 10 Mobile

There are also some paid applications. For example PrintHand, which is available also for iOS and Android, supports discovery of wifi and Bluetooth printers and also allows printing to Google Cloud Printers. Unfortunately, all of the free printing applications, except Win- PhonePrint, did not provide the option to share a document into the printing application, but the document must have been selected from the printing application.

7.4 Differences between the desktop and mobile version of Windows 10

Even though the desktop and mobile version of Windows is using the same technology for printing, they work differently. The mobile version can immediately print to the discovered printer whereas in the desktop it is necessary to install the drivers for the printer first. Using the drivers allows the user to use advanced printing features and ensures that the documents are printed correctly. Furthermore, on the desktop there is enough disk space, stable Internet connection in case it’s necessary to download the drivers and the printers are usually installed ahead of time. In the mobile world are printers added only on demand because the environment changes much more often and they must support correct PDL which limits the number of supported printers.

7.5 Summary

Microsoft took the same approach as Apple with AirPrint and only implemented their solution with different technology, but the func- tionality is practically the same. Windows 10 Mobile does not allow using another printing appli- cations with their API, so even though other applications for printing are available, they must be used separately. Because Windows 10 Mobile was released only recently, the num- ber of printers supporting the selected printing technology is not as big as a number of printers supporting AirPrint, but it will grow over

39 7. Windows 10 Mobile time and later users will not see a difference between printing from Windows 10 Mobile or iOS.

40 8 Ubuntu Touch

Ubuntu Touch, sometimes called Ubuntu for devices or Ubuntu phone or Ubuntu tablet, is a Linux operating system made by Canonical announces in 2013[37]. Currently, in 2016, there are three smartphones with preinstalled Ubuntu Touch and two officially supported ports for Nexus 4 and Nexus 7[38]. Because the Ubuntu on phones runs on the same core as the desk- top version, applications can be run on both of these versions with just small changes to the user interface. Furthermore, Ubuntu is able to act as the desktop version of Ubuntu when a mouse is connected to the system.[39]

8.1 Printing on Ubuntu Touch

Printing from Ubuntu phones is not yet possible, but some work has been done in this area. It is intended that the IPP Everywhere specifi- cation will be used. In the blueprint, related to printing from Ubuntu phone, three levels of printing stack are specified which could be available on the Ubuntu phone[40]: 1. Only CUPS daemon and cups-browsed, no filters, no web inter- face, no printer setup tool, prints only on remote CUPS queues (1MB) 2. Level 1 plus filters to print on IPP Everywhere (CUPS Raster), PDF, PostScript, and PCL printers, discover supported network printers automatically and just print on them (some two-digit amount of MB) 3. The full printing stack which we always shipped for the desktop (200-300 MB) As a printer discovery method, the mDNS (Bonjour) discovery will be used which will add all printers with known page description language (IPP Everywhere/CUPS Raster, PDF, PostScript, PCL). In order to preserve battery, all printing related daemons should be started on demand when the print dialog is opened.

41 8. Ubuntu Touch

Figure 8.1: The initial draft of the printing dialog on Ubuntu phone

8.1.1 Printing dialog

Furthermore an initial draft of a Printing dialog, shown in Figure 8.11 on page 42, was already created[41]. Under the "More..." button there are more advanced options like the media size and the print quality. There is also one more proposal of a printing dialog in a specifi- cation of printing in Ubuntu2. This specification also contains which cups events are used for specific printing operations.

1. This is compiled version of code attached to the printing dialog blueprint [41]. 2. "Living specification of printing in Ubuntu" https://wiki.ubuntu.com/ Printing

42 8. Ubuntu Touch 8.2 Summary

Canonical is taking the path of reusing existing printing solutions and just updating them so they can be used also on the mobile devices, which greatly reduces the cost of development. On the other hand, most of the work mentioned in this Ubuntu section was already done in years 2013 and 2014 but the printing is still not available. I tried to contact Till Kamppeter, who is the person behind the blueprint about printing, Ubuntu printing maintainer and leader of the OpenPrinting project[42], but without success. Hopefully, the printing support will be finished.

43

9 Firefox OS

Firefox OS is an open-source operating system for smartphones and tablets. For the development, Firefox OS is using web technologies like HTML5, JavaScript, and CSS for application development[43]. Therefore, even the user interface of the Firefox OS is a web application. The focus of Firefox OS was on the low-end devices and there are 18 smartphones currently (27.4. 2016) listed on the Mozilla homepage with preinstalled Firefox OS.1

9.1 Printing from Firefox OS

As with Ubuntu Touch, printing on Firefox OS is not yet possible, but there has been some work done to achieve it. In the source codes of Firefox OS 2 exists a printing component implementing the printing dialog, progress and print job options. For printer discovery, there is an mDNS/DNS-SD implementation present in the system. The only missing component necessary for printing is a printing protocol, but there is an implementation of the IPP protocol in JavaScript. So, in theory, it should be easy to implement a printing application for Firefox OS, as all the components are available. Unfortunately, during the preparation of this thesis Mozilla de- cided to shut down the development of Firefox OS [44] and it will continue under the original name "B2G OS" as an open-source commu- nity project. For the uncertainness of the future development of Firefox OS and the low market share, I have decided not to pursue the devel- opment of custom printing application.

9.2 Testing of Firefox OS

All work on the Firefox OS was done in emulators. Mozilla introduced a new and innovative WebIDE which is a plugin for Firefox. This IDE

1. See https://www.mozilla.org/cs/firefox/os/devices/ 2. See https://dxr.mozilla.org/mozilla-central/source/toolkit/ components/printing/content.

45 9. Firefox OS provides highlighting and completion for HTML, JavaScript, and CSS files, together with automatic download and installation of different releases of Firefox OS. The WebIDE also provides means to debug ap- plication real devices connected through the USB or Android devices with installed Firefox OS as an application. Firefox OS for Android is available as a debug preview and exists for the version 2.6 of Firefox OS.

46 10 Conclusion

There are big differences in printing between different mobile plat- forms. From the described operating platforms, iOS was the first one with built-in printing solution called AirPrint which requires AirPrint compatible printers in order to be able to print. Google took another approach with the Android operating system, and only prepared API which can be connected with more printing solutions and thus didn’t force users to use only printers using their native printing solu- tion. Microsoft used a similar approach as Apple with AirPrint and implemented their native printing solution for printers supporting the WS-Print technology. At the beginning of this work, I have described protocols used for printing and printer discovery, but because it would be impossible to include all the details, how these protocols work, I have focused more on differences between them. Because Android is the platform with the biggest market share and also because iOS and Windows 10 Mobile already had native printing solutions, the main focus of this work was on the Android operating system. I have implemented a prototype of a printing ap- plication which is able to connect to the Android printing API. This prototype demonstrates usage of two implementations of printer dis- covery protocol, authentication with using username and password and printing over the Internet Printing Protocol. The whole printing application was tested against an IPP Endpoint used with the YSoft SafeQ and with a CUPS print server and was placed into the Google Play under a beta testing program and tested in the company without more serious problems. Furthermore, I created an application that was able to use a user certificate on Android, which can be used for authentication onaprint server. To simulate the print server, I have created a possible implemen- tation of an Owin middleware, which is able to check the certificate. This print server was discussed only briefly as it was beyond the scope of this thesis. As a bonus, there were also two optional operating systems in the as- signment, Ubuntu Touch and Firefox OS, which were briefly covered.

47 10. Conclusion

None of these systems has a native printing solution, but on both of these systems there are traces of work on this feature. From the perspective of a future research, it would be interesting to create a print server similar to CUPS but some that would be able to communicate with the native Windows 10 printing technology, because it would work not only for mobile operating systems but also with a desktop version of Windows. Another possible work could be to finish printing on Ubuntu Touch. Native printing is there still in a development state and it doesn’t seem to be currently actively developed, but the description of what is missing and what is done is nicely documented.

48 Bibliography

[1] IDC. Smartphone OS Market Share, 2015 Q2. [online]. http:// www.idc.com/prodserv/smartphone-os-market-share.jsp. Accessed Feb 19, 2016. 2015. [2] The Printer Working Group. IPP Everywhere. [online]. http:// ftp.pwg.org/pub/pwg/candidates/cs-ippeve10-20130128- 5100.14.pdf. 2013. [3] Ph.D. doc. RNDr. Eva Hladká. 1. Introduction - Recapitulation of assumed knowledge PA159: Net-Centric Computing I. 2015. [4] Frank Worsley. Printing directly to a network printer. [online]. http: //www.frankworsley.com/blog/2011/1/23/printing-directly- to-a-network-printer. Accessed Dec 13, 2015. 2011. [5] Leo J. McLaughlin III. Line Printer Daemon Protocol. [online]. http: //www.rfc-editor.org/rfc/rfc1179.txt. 1990. [6] Network Working Group. Internet Printing Protocol/1.1: Encod- ing and Transport. [online]. https://tools.ietf.org/html/ rfc2910. 2000. [7] The Printer Working Group. IPP Version 2.0, 2.1, and 2.2. [on- line]. http://ftp.pwg.org/pub/pwg/standards/std-ipp20- 20151030-5100.12.pdf. 2015. [8] Network Working Group. Internet Printing Protocol/1.0: Encod- ing and Transport. [online]. https://tools.ietf.org/html/ rfc2565. 1999. [9] Inc. Microsoft Corporation. Web Services on Devices for Print- ing (WS-Print). [online]. https://msdn.microsoft.com/en- us/library/windows/hardware/jj659908(v=vs.85).aspx. Accessed Dec 14, 2015. [10] W3C. SOAP Version 1.2 Part 1: Messaging Framework (Second Edi- tion). [online]. https://www.w3.org/TR/soap12/. Accessed Dec 14, 2015. 2007. [11] Inc. Microsoft Corporation. Version 2.0 For Web Services on De- vices. [online]. go.microsoft.com/fwlink/p/?LinkId=534008. 2015. [12] Stuart Cheshire. Zero Configuration Networking (Zeroconf). [on- line]. http://www.zeroconf.org/. Accessed Nov 25, 2015.

49 BIBLIOGRAPHY

[13] A. Williams. Requirements for Automatic Configuration of IP Hosts. [online]. http://files.zeroconf.org/draft-ietf-zeroconf- reqts-12.txt. 2002. [14] Internet Engineering Task Force (IETF). DNS-Based Service Dis- covery. [online]. http://www.ietf.org/rfc/rfc6763.txt. 2013. [15] Inc. Microsoft Corporation. Web Services Dynamic Discovery (WS- Discovery). [online]. http://specs.xmlsoap.org/ws/2005/04/ discovery/ws-discovery.pdf. 2005. [16] The Printer Working Group. IPP Everywhere Frequently Asked Questions. [online]. https://www.pwg.org/ipp/evefaq.html. Accessed May 3, 2016. [17] The Printer Working Group. PWG Raster Format. [online]. ftp: / / ftp . pwg . org / pub / pwg / candidates / cs - ippraster10 - 20120420-5102.4.pdf. 2012. [18] Eric Hamilton. JPEG File Interchange Format Verion 1.02. [online]. https://www.w3.org/Graphics/JPEG/jfif3.pdf. 1992. [19] Adobe Systems Incorporated. Document management - Portable document format - Part 1: PDF 1.7. [online]. http://wwwimages. adobe . com / content / dam / Adobe / en / devnet / pdf / pdfs / PDF32000_2008.pdf. 2008. [20] Ecma International. Open XML Paper Specification. [online]. http: //www.ecma-international.org/publications/standards/ Ecma-388.htm. 2009. [21] Google. Android KitKat. [online]. https://developer.android. com/about/versions/kitkat.html. Accessed Apr 18, 2016. [22] Google. Platform Versions. [online]. https://developer.android. com/about/dashboards/index.html#Platform. Data collected during a 7-day period ending on May 2, 2016. Accessed May, 19, 2016. [23] Google. Class android.print.PrintAttributes. [online]. https : / / developer.android.com/sdk/api_diff/23/changes.html. Accessed May 19, 2016. [24] Nazmul Idris. DevBytes: Android 4.4 Printing API. [online]. https: //www.youtube.com/watch?v=Iub67ic87KI. Accessed Feb 13, 2016. [25] Marcel Schnelle. RxBonjour. [online]. https : / / github . com / aurae/RxBonjour/blob/master/README.md. Accessed May 3, 2016.

50 BIBLIOGRAPHY

[26] Google and Open Handset Alliance n.d. Android documentation - TrustManager. [online]. http : / / developer . android . com / reference/javax/net/ssl/TrustManager.html. Accessed Mar 1, 2016. [27] Mike Wasson. Getting Started with OWIN and Katana. [online]. http://www.asp.net/aspnet/overview/owin-and-katana/ getting-started-with-owin-and-katana. Accessed May 19, 2016. 2013. [28] BlackSpruce Software. Let’s Print Droid. [online]. https://play. google.com/store/apps/details?id=com.blackspruce.lpd. Accessed May 3, 2016. [29] zenofx.com. What is PrintBot? [online]. http://www.zenofx. com/printbot/. Accessed May 3, 2016. [30] zenofx.com. PrintBot FAQ. [online]. http://www.zenofx.com/ printbot/faq/. Accessed May 3, 2016. [31] Mopria Alliance. Mopria Alliance. [online]. http://mopria.org/ Portals/0/Mopria-Alliance-OverviewJan-2016-FINAL.pdf. Accessed May 19, 2016. 2016. [32] L.P. Hewlett-Packard Development Company. Using ePrint. [on- line]. support.hp.com/us-en/document/c03721293. Accessed Apr 25, 2016. [33] Google. Printing HTML Documents. [online]. http://developer. android.com/training/printing/html-docs.html. Accessed Feb 8, 2016. [34] Apple. Apple’s iOS 4.2 Available Today for iPad, iPhone & iPod touch. [online]. http : / / www . apple . com / pr / library / 2010 / 11 / 22Apples - iOS - 4 - 2 - Available - Today - for - iPad - iPhone - iPod-touch.html. Accessed Oct 20, 2015. 2010. [35] Luis Gómez-Miralles and Joan Arnedo-Moreno. “Analysis of the forensic traces left by AirPrint in Apple iOS devices”. In: Ad- vanced Information Networking and Applications Workshops (WAINA), 2013 27th International Conference on. IEEE. 2013, pp. 703–708. [36] Justin Hutchhings. Printing from your Windows Phone in Win- dows 10 Mobile. [online]. https://www.youtube.com/watch?v= OkK4xFlaeUc. 2015. [37] Joe Sheddon. Ubuntu Phone OS Unveiled by Canonical. [online]. http://www.omgubuntu.co.uk/2013/01/ubuntu-phone-os- unveiled-by-canonical. Accessed Nov 19, 2015. 2013.

51 BIBLIOGRAPHY

[38] Canonical Ltd. Supported and reference devices. [online]. http:// www.omgubuntu.co.uk/2013/01/ubuntu-phone-os-unveiled- by-canonical. Accessed May 10, 2016. [39] Nathan Haines. “The Future of Ubuntu”. In: Beginning Ubuntu for Windows and Mac Users. Springer, 2015, pp. 205–209. [40] Till Kamppeter. Printing Stack with Mobile in Mind. [online]. https: //blueprints.launchpad.net/ubuntu/+spec/client-1305- printing - stack - with - mobile - in - mind. Accessed Nov 20, 2015. 2013. [41] Till Kamppeter. Print Dialog Design for Ubuntu Touch. [online]. https://blueprints.launchpad.net/ubuntu/+spec/client- 1311-mobile-print-dialog. Accessed Nov 20, 2015. 2013. [42] Till Kamppeter. [online]. https://launchpad.net/~till-kamppeter. Accessed May 19, 2016. [43] Ewa Janczukowicz. Firefox OS Overview. [online]. https://hal- univ-rennes1.archives-ouvertes.fr/hal-00961321/document. Accessed Apr 25, 2016. 2013. [44] George Roter. Firefox OS/Connected Devices Announcement. [on- line]. https://discourse.mozilla-community.org/t/firefox- os-connected-devices-announcement/6864. Accessed Apr 20, 2016. 2016.

52