Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <h1>USB Devices</h1> | 1 <h1>USB Devices</h1> |
| 2 | 2 |
| 3 <p> | 3 <p> |
| 4 This document describes how to use the <a href="usb">USB API</a> to communicate | 4 This document describes how to use the <a href="usb">USB API</a> to communicate |
| 5 with USB devices. Some devices are not accessible through the USB API | 5 with USB devices. Some devices are not accessible through the USB API |
| 6 (see the <a href="#caveats">Caveats</a> section below for details). | 6 (see the <a href="#caveats">Caveats</a> section below for details). |
| 7 Chrome Apps can also connect to <a href="serial">serial</a> and | 7 Chrome Apps can also connect to <a href="serial">serial</a> and |
| 8 <a href="bluetooth">Bluetooth</a> devices. | 8 <a href="bluetooth">Bluetooth</a> devices. |
| 9 </p> | 9 </p> |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 | 35 |
| 36 <p>In addition, in order to prevent | 36 <p>In addition, in order to prevent |
| 37 <a href="http://en.wikipedia.org/wiki/Device_fingerprint">finger-printing</a>, | 37 <a href="http://en.wikipedia.org/wiki/Device_fingerprint">finger-printing</a>, |
| 38 you must declare all the device types you want to access in the manifest file. | 38 you must declare all the device types you want to access in the manifest file. |
| 39 Each type of USB device corresponds to a vendor id/product id (VID/PID) pair. | 39 Each type of USB device corresponds to a vendor id/product id (VID/PID) pair. |
| 40 You can use $(ref:usb.getDevices) to enumerate devices by their VID/PID | 40 You can use $(ref:usb.getDevices) to enumerate devices by their VID/PID |
| 41 pair. | 41 pair. |
| 42 </p> | 42 </p> |
| 43 <p> | 43 <p> |
| 44 You must declare the VID/PID pairs for each type of device you want to use | 44 You must declare the VID/PID pairs for each type of device you want to use |
| 45 under the "usbDevices" permission in your app's manifest file, as shown in the | 45 under the <code>usbDevices</code> permission in your app's manifest file, as |
| 46 example below:</p> | 46 shown in the example below:</p> |
| 47 | 47 |
| 48 <pre data-filename="manifest.json"> | 48 <pre data-filename="manifest.json"> |
| 49 "permissions": [ | 49 "permissions": [ |
| 50 { | 50 { |
| 51 "usbDevices": [ | 51 "usbDevices": [ |
| 52 { | 52 { |
| 53 "vendorId": 123, | 53 "vendorId": 123, |
| 54 "productId": 456 | 54 "productId": 456 |
| 55 } | 55 } |
| 56 ] | 56 ] |
| 57 } | 57 } |
| 58 ] | 58 ] |
| 59 </pre> | 59 </pre> |
| 60 | 60 |
| 61 <p class="note">Note that only decimal numbers are allowed in JSON format. | 61 <p class="note">Note that only decimal numbers are allowed in JSON format. |
| 62 You cannot use hexadecimal numbers in these fields.</p> | 62 You cannot use hexadecimal numbers in these fields.</p> |
| 63 | 63 |
| 64 <p>Since <b>Chrome 57</b>, requirement for declaring all the device types | |
|
Devlin
2017/01/10 15:56:50
*the* requirement
tbarzic
2017/01/10 17:42:25
Done.
| |
| 65 in the app manifest is relaxed for apps running as Chrome OS | |
| 66 <a href="apps/manifest/kiosk_enabled">kiosk apps</a>. | |
| 67 For kiosk apps, you can use <code>interfaceClass</code> permission property to | |
|
Devlin
2017/01/10 15:56:50
*the* <code>interfaceClass....
tbarzic
2017/01/10 17:42:25
Done.
| |
| 68 declare permission to access USB devices that: | |
|
Devlin
2017/01/10 15:56:50
s/declare/request?
tbarzic
2017/01/10 17:42:25
Done.
| |
| 69 <ul> | |
| 70 <li>implement a USB interface of a specific interface class</li> | |
| 71 <li>have a specific USB device class</li> | |
| 72 </ul> | |
| 73 For example, the following <code>usbDevices</code> permission would grant an | |
| 74 app access to all USB devices that implement a printer interface (interface | |
| 75 class code 7), and to USB hub devices (device class code 9):</p> | |
| 76 | |
| 77 <pre data-filename="manifest.json"> | |
| 78 "permissions": [ | |
| 79 { | |
| 80 "usbDevices": [ | |
| 81 {"interfaceClass": 7}, | |
| 82 {"interfaceClass": 9} | |
| 83 ] | |
| 84 } | |
| 85 ] | |
| 86 </pre> | |
| 87 | |
| 88 <p>For list of acceptable <code>interfaceClass</code> values, see | |
|
Devlin
2017/01/10 15:56:50
*the* list
tbarzic
2017/01/10 17:42:25
Done.
| |
| 89 <a href="http://www.usb.org/developers/defined_class">USB Class Codes</a>. | |
| 90 </p> | |
| 91 | |
| 92 <p><code>interfaceClass</code> property can be combined with | |
| 93 <code>vendorId</code> property to get access only to USB devices of a specific | |
| 94 vendor, as demonstrated by the following example:</p> | |
| 95 | |
| 96 <pre data-filename="manifest.json"> | |
| 97 "permissions": [ | |
| 98 { | |
| 99 "usbDevices": [ | |
| 100 { | |
| 101 "vendorId": 123, | |
| 102 "interfaceClass": 7 | |
| 103 } | |
| 104 ] | |
| 105 } | |
| 106 ] | |
| 107 </pre> | |
| 108 | |
| 109 <p class="note">Note that <code>usbDevices</code> permissions with | |
| 110 <code>interfaceClass</code> property have effect only when the app is running | |
| 111 in kiosk session - outside a kiosk session said permissions will be ignored. | |
|
Devlin
2017/01/10 15:56:50
s/said/these
tbarzic
2017/01/10 17:42:25
Done.
| |
| 112 </p> | |
| 113 | |
| 64 <h2 id="finding_device">Finding a device</h2> | 114 <h2 id="finding_device">Finding a device</h2> |
| 65 | 115 |
| 66 <p> | 116 <p> |
| 67 To determine whether one or more specific devices are connected to a user's | 117 To determine whether one or more specific devices are connected to a user's |
| 68 system, use the $(ref:usb.getDevices) method: | 118 system, use the $(ref:usb.getDevices) method: |
| 69 </p> | 119 </p> |
| 70 | 120 |
| 71 <pre> | 121 <pre> |
| 72 chrome.usb.getDevices(enumerateDevicesOptions, callback); | 122 chrome.usb.getDevices(enumerateDevicesOptions, callback); |
| 73 </pre> | 123 </pre> |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 665 owned by group "plugdev" and have group write permissions. | 715 owned by group "plugdev" and have group write permissions. |
| 666 </li> | 716 </li> |
| 667 </ul> | 717 </ul> |
| 668 | 718 |
| 669 <p>Your app cannot do this automatically since this this procedure requires root | 719 <p>Your app cannot do this automatically since this this procedure requires root |
| 670 access. We recommend that you provide instructions to end-users and link to the | 720 access. We recommend that you provide instructions to end-users and link to the |
| 671 <a href="#caveats">Caveats</a> section on this page for an explanation.</p> | 721 <a href="#caveats">Caveats</a> section on this page for an explanation.</p> |
| 672 | 722 |
| 673 <p>On Chrome OS, simply call $(ref:usb.requestAccess). The permission | 723 <p>On Chrome OS, simply call $(ref:usb.requestAccess). The permission |
| 674 broker does this for you.</p> | 724 broker does this for you.</p> |
| OLD | NEW |