1/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17syntax = "proto2";
18package android.service.usb;
19
20option java_multiple_files = true;
21option java_outer_classname = "UsbServiceProto";
22
23import "frameworks/base/core/proto/android/content/component_name.proto";
24import "frameworks/base/core/proto/android/service/enums.proto";
25import "frameworks/base/core/proto/android/privacy.proto";
26
27message UsbServiceDumpProto {
28    option (android.msg_privacy).dest = DEST_AUTOMATIC;
29
30    optional UsbDeviceManagerProto device_manager = 1;
31    optional UsbHostManagerProto host_manager = 2;
32    optional UsbPortManagerProto port_manager = 3;
33    optional UsbAlsaManagerProto alsa_manager = 4;
34    optional UsbSettingsManagerProto settings_manager = 5;
35    optional UsbPermissionsManagerProto permissions_manager = 6;
36}
37
38message UsbDeviceManagerProto {
39    option (android.msg_privacy).dest = DEST_AUTOMATIC;
40
41    optional UsbHandlerProto handler = 1;
42    optional UsbDebuggingManagerProto debugging_manager = 2;
43}
44
45message UsbHandlerProto {
46    option (android.msg_privacy).dest = DEST_AUTOMATIC;
47
48    /* Same as android.hardware.usb.gadget.V1_0.GadgetFunction.* */
49    enum Function {
50        FUNCTION_ADB = 1;
51        FUNCTION_ACCESSORY = 2;
52        FUNCTION_MTP = 4;
53        FUNCTION_MIDI = 8;
54        FUNCTION_PTP = 16;
55        FUNCTION_RNDIS = 32;
56        FUNCTION_AUDIO_SOURCE = 64;
57    }
58
59    repeated Function current_functions = 1;
60    optional bool current_functions_applied = 2;
61    repeated Function screen_unlocked_functions = 3;
62    optional bool screen_locked = 4;
63    optional bool connected = 5;
64    optional bool configured = 6;
65    optional UsbAccessoryProto current_accessory = 7;
66    optional bool host_connected = 8;
67    optional bool source_power = 9;
68    optional bool sink_power = 10;
69    optional bool usb_charging = 11;
70    optional bool hide_usb_notification = 12;
71    optional bool audio_accessory_connected = 13;
72    optional bool adb_enabled = 14;
73    optional string kernel_state = 15;
74    optional string kernel_function_list = 16;
75}
76
77message UsbAccessoryProto {
78    option (android.msg_privacy).dest = DEST_AUTOMATIC;
79
80    optional string manufacturer = 1;
81    optional string model = 2;
82    // For "classical" USB-accessories the manufacturer bakes this into the
83    // firmware of the device. If an Android phone is configured as accessory, the
84    // app that sets up the accessory side of the connection set this. Either way,
85    // these are part of the detection protocol, and so they cannot be user set or
86    // unique.
87    optional string description = 3;
88    optional string version = 4;
89    optional string uri = 5 [ (android.privacy).dest = DEST_EXPLICIT ];
90    // Non-resettable hardware ID.
91    optional string serial = 6 [ (android.privacy).dest = DEST_LOCAL ];
92}
93
94message UsbDebuggingManagerProto {
95    option (android.msg_privacy).dest = DEST_AUTOMATIC;
96
97    optional bool connected_to_adb = 1;
98    // A workstation that connects to the phone for debugging is identified by
99    // this key.
100    optional string last_key_received = 2 [ (android.privacy).dest = DEST_EXPLICIT ];
101    optional string user_keys = 3 [ (android.privacy).dest = DEST_LOCAL ];
102    optional string system_keys = 4 [ (android.privacy).dest = DEST_LOCAL ];
103}
104
105message UsbHostManagerProto {
106    option (android.msg_privacy).dest = DEST_AUTOMATIC;
107
108    optional android.content.ComponentNameProto default_usb_host_connection_handler = 1;
109    repeated UsbDeviceProto devices = 2;
110    optional int32 num_connects = 3;
111    repeated UsbConnectionRecordProto connections = 4;
112}
113
114message UsbDeviceProto {
115    option (android.msg_privacy).dest = DEST_AUTOMATIC;
116
117    // Generic USB name, not user-provided.
118    optional string name = 1;
119    // ID specific to the vendor, not the device.
120    optional int32 vendor_id = 2;
121    // ID of this product type: Each vendor gives each product a unique ID. E.g.
122    // all mice of the same model would have the same ID.
123    optional int32 product_id = 3;
124    optional int32 class = 4;
125    optional int32 subclass = 5;
126    optional int32 protocol = 6;
127    optional string manufacturer_name = 7;
128    optional string product_name = 8;
129    optional string version = 9;
130    // Non-resettable hardware ID.
131    optional string serial_number = 10 [ (android.privacy).dest = DEST_LOCAL ];
132    repeated UsbConfigurationProto configurations = 11;
133}
134
135message UsbConfigurationProto {
136    option (android.msg_privacy).dest = DEST_AUTOMATIC;
137
138    // A single USB device can have several configurations and the app accessing
139    // the USB device can switch between them. At any time only one can be active.
140    // Each configuration can present completely different interfaces end
141    // endpoints, i.e. a completely different behavior.
142    optional int32 id = 1;
143    // Hardware-defined name, not set by the user.
144    optional string name = 2;
145    optional uint32 attributes = 3;
146    optional int32 max_power = 4;
147    repeated UsbInterfaceProto interfaces = 5;
148}
149
150message UsbInterfaceProto {
151    option (android.msg_privacy).dest = DEST_AUTOMATIC;
152
153    // Hardware defined. This is the id used by the app to identify the interface.
154    optional int32 id = 1;
155    optional int32 alternate_settings = 2;
156    optional string name = 3;
157    optional int32 class = 4;
158    optional int32 subclass = 5;
159    optional int32 protocol = 6;
160    repeated UsbEndPointProto endpoints = 7;
161}
162
163message UsbEndPointProto {
164    option (android.msg_privacy).dest = DEST_AUTOMATIC;
165
166    optional int32 endpoint_number = 1;
167    optional android.service.UsbEndPointDirection direction = 2;
168      // The address of the endpoint. Needed to read and write to the endpoint.
169    optional int32 address = 3;
170    optional android.service.UsbEndPointType type = 4;
171    optional uint32 attributes = 5;
172    optional int32 max_packet_size = 6;
173    optional int32 interval = 7;
174}
175
176message UsbConnectionRecordProto {
177    option (android.msg_privacy).dest = DEST_AUTOMATIC;
178
179    // usb device's address, e.g. 001/002, nothing about the phone
180    optional string device_address = 1;
181    optional android.service.UsbConnectionRecordMode mode = 2;
182    optional int64 timestamp = 3;
183    optional int32 manufacturer = 4;
184    optional int32 product = 5;
185    optional UsbIsHeadsetProto is_headset = 6;
186}
187
188message UsbIsHeadsetProto {
189    option (android.msg_privacy).dest = DEST_AUTOMATIC;
190
191    optional bool in = 1;
192    optional bool out = 2;
193}
194
195message UsbPortManagerProto {
196    option (android.msg_privacy).dest = DEST_AUTOMATIC;
197
198    optional bool is_simulation_active = 1;
199    repeated UsbPortInfoProto usb_ports = 2;
200}
201
202message UsbPortInfoProto {
203    option (android.msg_privacy).dest = DEST_AUTOMATIC;
204
205    optional UsbPortProto port = 1;
206    optional UsbPortStatusProto status = 2;
207    optional bool can_change_mode = 3;
208    optional bool can_change_power_role = 4;
209    optional bool can_change_data_role = 5;
210    optional int64 connected_at_millis = 6;
211    optional int64 last_connect_duration_millis = 7;
212}
213
214message UsbPortProto {
215    option (android.msg_privacy).dest = DEST_AUTOMATIC;
216
217    /* Same as android.hardware.usb.V1_1.Constants.PortMode_1_1 */
218    enum Mode {
219        MODE_NONE = 0;
220        MODE_UFP = 1;
221        MODE_DFP = 2;
222        MODE_DRP = 3;
223        MODE_AUDIO_ACCESSORY = 4;
224        MODE_DEBUG_ACCESSORY = 8;
225    }
226
227    // ID of the port. A device (eg: Chromebooks) might have multiple ports.
228    optional string id = 1;
229    repeated Mode supported_modes = 2;
230}
231
232/* Same as android.hardware.usb.V1_2.Constants.ContaminantPresenceStatus */
233enum ContaminantPresenceStatus {
234    CONTAMINANT_STATUS_UNKNOWN = 0;
235    CONTAMINANT_STATUS_NOT_SUPPORTED = 1;
236    CONTAMINANT_STATUS_DISABLED = 2;
237    CONTAMINANT_STATUS_NOT_DETECTED = 3;
238    CONTAMINANT_STATUS_DETECTED = 4;
239}
240
241message UsbPortStatusProto {
242    option (android.msg_privacy).dest = DEST_AUTOMATIC;
243
244    /* Same as android.hardware.usb.V1_0.Constants.PortPowerRole */
245    enum PowerRole {
246        POWER_ROLE_NONE = 0;
247        POWER_ROLE_SOURCE = 1;
248        POWER_ROLE_SINK = 2;
249    }
250
251    /* Same as android.hardware.usb.V1_0.Constants.PortDataRole */
252    enum DataRole {
253        DATA_ROLE_NONE = 0;
254        DATA_ROLE_HOST = 1;
255        DATA_ROLE_DEVICE = 2;
256    }
257
258    optional bool connected = 1;
259    optional UsbPortProto.Mode current_mode = 2;
260    optional PowerRole power_role = 3;
261    optional DataRole data_role = 4;
262    repeated UsbPortStatusRoleCombinationProto role_combinations = 5;
263    optional ContaminantPresenceStatus contaminant_presence_status = 6;
264}
265
266message UsbPortStatusRoleCombinationProto {
267    option (android.msg_privacy).dest = DEST_AUTOMATIC;
268
269    optional UsbPortStatusProto.PowerRole power_role = 1;
270    optional UsbPortStatusProto.DataRole data_role = 2;
271}
272
273message UsbAlsaManagerProto {
274    option (android.msg_privacy).dest = DEST_AUTOMATIC;
275
276    optional int32 cards_parser = 1;
277    repeated UsbAlsaDeviceProto alsa_devices = 2;
278    repeated UsbMidiDeviceProto midi_devices = 3;
279}
280
281message UsbAlsaDeviceProto {
282    option (android.msg_privacy).dest = DEST_AUTOMATIC;
283
284    optional int32 card = 1;
285    optional int32 device = 2;
286    optional string name = 3;
287    optional bool has_playback = 4;
288    optional bool has_capture = 5;
289    // usb device's address, e.g. 001/002, nothing about the phone
290    optional string address = 6;
291}
292
293message UsbMidiDeviceProto {
294    option (android.msg_privacy).dest = DEST_AUTOMATIC;
295
296    optional int32 card = 1;
297    optional int32 device = 2;
298    // usb device's address, e.g. 001/002, nothing about the phone
299    optional string device_address = 3;
300}
301
302message UsbSettingsManagerProto {
303    option (android.msg_privacy).dest = DEST_AUTOMATIC;
304
305    repeated UsbUserSettingsManagerProto user_settings = 1;
306    repeated UsbProfileGroupSettingsManagerProto profile_group_settings = 2;
307}
308
309message UsbUserSettingsManagerProto {
310    option (android.msg_privacy).dest = DEST_AUTOMATIC;
311
312    optional int32 user_id = 1;
313    reserved 2; // previously device_permissions, now unused
314    reserved 3; // previously accessory_permissions, now unused
315    repeated UsbDeviceAttachedActivities device_attached_activities = 4;
316    repeated UsbAccessoryAttachedActivities accessory_attached_activities = 5;
317}
318
319message UsbProfileGroupSettingsManagerProto {
320    option (android.msg_privacy).dest = DEST_AUTOMATIC;
321
322    // The user id of the personal profile if the device has a work profile.
323    optional int32 parent_user_id = 1;
324    repeated UsbSettingsDevicePreferenceProto device_preferences = 2;
325    repeated UsbSettingsAccessoryPreferenceProto accessory_preferences = 3;
326}
327
328message UsbSettingsDevicePreferenceProto {
329    option (android.msg_privacy).dest = DEST_AUTOMATIC;
330
331    optional UsbDeviceFilterProto filter = 1;
332    optional UserPackageProto user_package = 2;
333}
334
335message UsbPermissionsManagerProto {
336    option (android.msg_privacy).dest = DEST_AUTOMATIC;
337
338    repeated UsbUserPermissionsManagerProto user_permissions = 1;
339}
340
341message UsbUserPermissionsManagerProto {
342    option (android.msg_privacy).dest = DEST_AUTOMATIC;
343
344    optional int32 user_id = 1;
345
346    repeated UsbDevicePermissionProto device_permissions = 2;
347    repeated UsbAccessoryPermissionProto accessory_permissions = 3;
348
349    repeated UsbDevicePersistentPermissionProto device_persistent_permissions = 4;
350    repeated UsbAccessoryPersistentPermissionProto accessory_persistent_permissions = 5;
351}
352
353message UsbDevicePermissionProto {
354    option (android.msg_privacy).dest = DEST_AUTOMATIC;
355
356    // Name of device set by manufacturer
357    // All devices of the same model have the same name
358    optional string device_name = 1;
359    repeated int32 uids = 2;
360}
361
362message UsbAccessoryPermissionProto {
363    option (android.msg_privacy).dest = DEST_AUTOMATIC;
364
365    // Description of accessory set by manufacturer
366    // All accessories of the same model have the same description
367    optional string accessory_description = 1;
368    repeated int32 uids = 2;
369}
370
371message UsbDevicePersistentPermissionProto {
372    option (android.msg_privacy).dest = DEST_AUTOMATIC;
373
374    optional UsbDeviceFilterProto device_filter = 1;
375    repeated UsbUidPermissionProto permission_values = 2;
376}
377
378message UsbAccessoryPersistentPermissionProto {
379    option (android.msg_privacy).dest = DEST_AUTOMATIC;
380
381    optional UsbAccessoryFilterProto accessory_filter = 1;
382    repeated UsbUidPermissionProto permission_values = 2;
383}
384
385message UsbUidPermissionProto {
386    option (android.msg_privacy).dest = DEST_AUTOMATIC;
387
388    optional int32 uid = 1;
389    optional bool is_granted = 2;
390}
391
392message UsbDeviceFilterProto {
393    option (android.msg_privacy).dest = DEST_AUTOMATIC;
394
395    // Mirrors the vendor_id of UsbDeviceProto.
396    optional int32 vendor_id = 1;
397    optional int32 product_id = 2;
398    optional int32 class = 3;
399    optional int32 subclass = 4;
400    optional int32 protocol = 5;
401    optional string manufacturer_name = 6;
402    optional string product_name = 7;
403    optional string serial_number = 8 [ (android.privacy).dest = DEST_EXPLICIT ];
404}
405
406message UserPackageProto {
407    option (android.msg_privacy).dest = DEST_AUTOMATIC;
408
409    optional int32 user_id = 1;
410    optional string package_name =2;
411}
412
413message UsbSettingsAccessoryPreferenceProto {
414    option (android.msg_privacy).dest = DEST_AUTOMATIC;
415
416    optional UsbAccessoryFilterProto filter = 1;
417    optional UserPackageProto user_package = 2;
418}
419
420message UsbAccessoryFilterProto {
421    option (android.msg_privacy).dest = DEST_AUTOMATIC;
422
423    optional string manufacturer = 1;
424    optional string model = 2;
425    optional string version = 3;
426}
427
428message UsbDeviceAttachedActivities {
429    option (android.msg_privacy).dest = DEST_AUTOMATIC;
430
431    optional android.content.ComponentNameProto activity = 1;
432    repeated UsbDeviceFilterProto filters = 2;
433}
434
435message UsbAccessoryAttachedActivities {
436    option (android.msg_privacy).dest = DEST_AUTOMATIC;
437
438    optional android.content.ComponentNameProto activity = 1;
439    repeated UsbAccessoryFilterProto filters = 2;
440}
441