451 Commits

Author SHA1 Message Date
Philip P. Moltmann
0ee6ee0a92 Expose UsbPort and UsbPortStatus as system API
This is needed by making the setup wizard use only system-api.

Test: Built, switched USB port state
Change-Id: I8e56859a5b36e7de91691522a34f7d6f62dcbb20
Fixes: 115301401
2018-12-18 08:50:46 -08:00
Badhri Jagan Sridharan
06353c6eb5 Merge "Log UsbDeviceAttached events for Audio devices" 2018-12-11 16:40:37 +00:00
Badhri Jagan Sridharan
5ec629f020 Log UsbDeviceAttached events for Audio devices
UsbDeviceAttached is logged when the device has an audio interface.
Info such as VID, PID, whether the device has hid or mass storage
interface and the duration for which the usb device was connected
would be logged as well.

Bug: 118783261
Test: Manually tested by running: adb shell cmd stats print-logs,
    adb logcat | grep statsd | grep \(77\)
Change-Id: I57bbfd22ef377553daa113968fe53c4fe0f8e4d2
2018-12-10 17:37:27 -08:00
Badhri Jagan Sridharan
faf6207163 Log connection duration.
last_connect_duration_millis will be set to 0 for a connect event.
last_connect_duration_millis will be set to the amount of time the port
was left connected for a disconnect event.

Bug: 118783261
Test: Manually tested by running: adb shell cmd stats print-logs,
    adb logcat | grep statsd | grep \(70\)
Change-Id: Ifd1df55fb6317e789a2b04236ce0a6e4665e3664
2018-12-04 12:14:12 -08:00
Badhri Jagan Sridharan
223b3c7999 Log UsbConnectorStateChanged events
The following would the logged:
1. Status of the connection - connected/disconnected.
2. Port id as a device could have multiple ports.

Bug: 118783261
Test: Manually tested by running: adb shell cmd stats print-logs,
adb logcat | grep statsd | grep \(70\)
Change-Id: Ideea36c7745293f5b6ec9cc35fd5f709f5175d5a
2018-12-04 10:14:14 -08:00
TreeHugger Robot
d1b8392a5b Merge "Check for preexisting flag before enabling the gadget" 2018-11-09 20:02:24 +00:00
Badhri Jagan Sridharan
222ed0fcf0 Check for preexisting flag before enabling the gadget
onRegistration callback gets triggered as soon has the
serviceNotification object is registered with registerForNotifications.
The preexisting flag in the callback is set if the gadget hal service dies
and restarts. Use this to differentiate between the onRegistration call
for the registerForNotifications vs actual gadget hal service restart.
Do not reset usb gadget if the onRegistration callback is called as a
result of registerForNotifications. This will overcome the occasional
reset of the usb gadget hence the connection during phone bootup.

Bug: 118678530
Test: Verified that gadget reset does not happen
Change-Id: I3b94e55289bb3a53eb9e083177fd4d54bec5f4da
2018-11-09 17:54:40 +00:00
Philip P. Moltmann
36f03d9d82 Pass down uid into requestPermissionDialog
As it is cleared further up in the call stack.

Test: Requested usb-device permissions from an app
Change-Id: Ib0e2b264086238785562f6f9da4800fb8f0a1590
2018-11-07 16:38:20 -08:00
Kenny Root
a5964c08bc Move AdbDebuggingManager to AdbService
Also remove the "Usb" from the AIDL function since it's not really
related to USB.

Test: make
Bug: 63820489
Change-Id: Ibf23964665a115a5bc835820dcff98aaf7ba610f
2018-10-31 16:11:02 +09:00
Kenny Root
473121834b AdbService: move source of truth for enabled
This makes the AdbService the source of truth for whether ADB is enabled
on the system or not. All UsbManager checks will now query the
AdbService.

Test: make
Bug: 63820489
Change-Id: I2965a15b5fa9f747fe0ae4dc791b5e357e78253f
2018-10-31 16:11:02 +09:00
Kenny Root
33504d7d4f Register USB as an ADB transport type
This doesn't do anything yet, but is needed to migrate functionality
from the USB service to the ADB service.

Bug: 63820489
Test: make
Change-Id: I402bb234a055cf0b199e0922bf92736aa659d46a
2018-10-31 16:11:01 +09:00
Kenny Root
8429eb923e Move ADB debugging manager to core
This service should not be in the USB module anymore. Move it to the
core services.

Bug: 63820489
Test: make
Change-Id: I6e07b8e3aa29fbd9d30d130ef0c882a84a12d30c
2018-10-31 16:11:01 +09:00
Kenny Root
7c4e66190e Rename to AdbDebuggingManager
Rename the UsbDebuggingManager to AdbDebuggingManager. It doesn't
technically depend on the USB stack, so rename to make the lack of
association more clear.

Bug: 63820489
Test: make
Change-Id: Ife83d3ec9701882781f5a9562ccc5435d51d246b
2018-10-31 16:11:01 +09:00
Kenny Root
e0e84084f0 Move UsbDebuggingManager to new package
First step in separating the USB and ADB stacks. The ADB functionality
does not logically need USB, so move it to its own package initially to
make further detangling more clear.

Bug: 63820489
Test: make
Change-Id: I6cf57c4ebc6ec8956cdd7ce817bdc4bcf7ff27a9
2018-10-31 16:11:01 +09:00
Pavel Maltsev
d530d10291 Fix security exception when reading usb serial num
Bug: 117881221
Test: run projection on mojave board
Change-Id: Ife4c5e18b6d8f7c20b363f40119dfefd8ab008ef
2018-10-17 16:38:39 -07:00
Philip P. Moltmann
0e8a7db66f Clear identity before calling deeper into USB code
This is needed as deeper in the code we call UsbAccessory.getSerial
which behaves differently depending on the caller. I.e. we have to make
sure to have the system server identity when we call this methods.

Fixes: 117547676
Test: - Started Android Auto
      - CtsVerifier USB Device and USB Accessory tests

Change-Id: I6d752ad5d2ff058dadf1e27e41247153c7db5ee6
2018-10-10 10:48:44 -07:00
Philip P. Moltmann
fca922976a Merge "Require permission to read USB device's serial number." 2018-10-08 20:22:07 +00:00
Eddie Hung
a4b1fe6547 Merge "Fix UsbDeviceManager null object reference" am: 9b1db24f6e am: ec5dd5f1dd
am: e419713dc8

Change-Id: Ie1c573d76c863684df360735d94796e7f0336cb6
2018-10-08 01:36:48 -07:00
Eddie Hung
ab87b44dca Fix UsbDeviceManager null object reference
STORAGE_SERVICE is not ready or not available to use.
UsbDeviceManager will get null value and cause null object
reference exception. Check return value before use.

Test: No exception when start USBService
Change-Id: Icdbc532894d3ca1548f327d9f63d495baa549c68
2018-09-28 13:14:23 +08:00
Pavel Maltsev
4f2be07902 Merge "Check black-listed USB class before descriptor" 2018-09-14 04:58:25 +00:00
Philip P. Moltmann
a2c6eea97f Require permission to read USB device's serial number.
Fixes: 110953952
Test: CtsVerifier USB Device test
Change-Id: I99b52bac6c800d869198e282e364f3a530336803
2018-09-07 14:23:57 -07:00
TreeHugger Robot
1a56d75fb4 Merge "USB permission and resolve activity refactor." 2018-09-05 20:05:50 +00:00
Paul Mclean
2e656695b3 Merge "Make single-USB-peripheral only mode a compile-time option." 2018-09-05 19:46:35 +00:00
Paul McLean
519c557eca Make single-USB-peripheral only mode a compile-time option.
Allow multi-usb work to continue without changes spinning out of control.

Bug: 111397675
Test: Set single-mode on and verify correct behavior.

Change-Id: I70f70bbb8edae6cbd1e73bee40fe821079cba9d8
2018-09-04 08:19:42 -06:00
lgcheng
2992e1c716 USB permission and resolve activity refactor.
Pure refactor of USB code for simple Arc logic injection.
Should have no behavior change for AOSP.

Bug: 74258201
Test: Run USB Accessory and USB Device test.
Change-Id: I8f7dace9155ceb75bc465fbb03a26f52694c8f93
2018-08-30 21:39:59 +00:00
Philip P. Moltmann
cf4ea753de Merge "UsbDeviceManager: Check PTP FileDescriptor properly" am: a0a67862aa am: 353543639f
am: 8ccef1b9f3

Change-Id: I70df6ac9cf0c39d4c59bbe79c18388dbe23419c2
2018-08-30 12:57:33 -07:00
Wang Han
e030a09023 UsbDeviceManager: Check PTP FileDescriptor properly
* A typo causes MTP one to be checked twice

Change-Id: If16bf5df43b6d51f6717aa7994b2f428fb3f1a69
2018-08-30 06:28:36 +00:00
Pavel Maltsev
e8c3a3e92c Check black-listed USB class before descriptor
Attempt to read USB descriptor of USB hub devices results in hanging
thread on getDescriptorString_native call.  Also check device
interface class/subclass as well.

Test: verified that usb host thread no longer stuch in getDescriptorString_native call on Mojave board with USB hub attached

Bug: 112657091

Change-Id: I46271dcc9c80168a650940fbde9218a54cafe8da
2018-08-16 13:59:40 -07:00
Jerry Zhang
626a5c69c7 Merge "UsbDescriptor: Add finite timeout to control transfer" am: 20dca26f41 am: 4bff76be80
am: db3a291e9d

Change-Id: Ibf2bc0673e156919baf77c0db2033aa521b08052
2018-07-17 15:09:35 -07:00
Jerry Zhang
4bff76be80 Merge "UsbDescriptor: Add finite timeout to control transfer"
am: 20dca26f41

Change-Id: I86a916694a497bedb7d2df8a64dd17e0e15ce332
2018-07-17 13:59:15 -07:00
sgopal1
58484d7c69 UsbDescriptor: Add finite timeout to control transfer
Using "0" as value for USB control transfer timeout
results in an unlimited timeout in case of bad USB
devices. In host kernels where hung task panic
is enabled, this results in device reboot.
So, add a finite timeout for USB control transfer.

Test: manual run and test with bad USB devices.

Change-Id: Ibc13ca4d8259a08ae7419bb3bcac9c161b1d3693
Signed-off-by: sgopal1 <saranya.gopal@intel.com>
2018-07-10 09:54:03 +05:30
Wale Ogunwale
9e4f3e077f Introduced WindowProcessController/Listener (10/n)
One heavy dependence between the current AMS service and activities
is process management which is heavy affected by activities and their
current state. We introduce WindowProcessController and WindowProcessListener
objects as a structured way for the process changes in AM package to
be communicated to the WM package and WindowProcessListner for activity
changes in the WM package to the communicated back to the AM package.
The ProcessRecord object in AM will own the WindowProcessController object
and also implement the WindowProcessListener.

Test: Existing tests pass
Test: go/wm-smoke-auto
Bug: 80414790
Change-Id: I9e96e841b0f95e99a597cb4629fa5d2fe45760b6
2018-06-22 14:26:24 -07:00
Wale Ogunwale
6767eaee94 Split internal interface activities from current AM interface (3/n)
3rd step in unifying the window hierarchy that is currently split
within AM and WM packages. We separate the the internal interface used
to communicate within system server dealing with activities and their
containers (tasks, stack, display) from the rest of AM internal
interface.

Test: Existing tests pass
Test: go/wm-smoke-auto
Bug: 80414790
Change-Id: Idad77721c1fe10621b9be5dced42a0a11f0183e5
2018-06-15 08:43:22 -07:00
Philip P. Moltmann
66c5a8d207 Dump activities that handle when USB devices get plugged in
When a USB device or accessory gets plugged in the system might
automatically start activities that have a device/accessory filter set
to include the plugged in USB device.

Unfortunately we seen too many apps setting too broad of a filter and it
annoys the user that this apps wants to start every time the device gets
plugged in.

This change dumps the acitivity names and their filters so debugging
such issues is much easier.

To do this, there is some mild refactoring:

1. Split packageMatchesLocked into
- getDeviceFilters to resolve all device filters
- getAccessoryFilterer to resolve all accessories
- Check if a filter matches after resolving all filters. This is no
  performance issue as usually there is only one or two filters per
  activity.

2. Split queryIntentActivitiesForAllProfiles into
- A per user part, so that we can use the exact same intent-resolution
  code for the dump-code
- And a loop over the per user part

Test: adb shell dumpsys usb
      + incident_report usb
      + verified that the output is as expected

Change-Id: I552c963b9a1b1c7df0adc6746af8cd42a4691cd6
2018-05-31 11:12:32 -07:00
Kweku Adams
3984cf625c Fixing typo in proto field.
Bug: 72814439
Bug: 74975371
Test: atest CtsIncidentHostTestCases:com.android.server.cts.UsbIncidentTest
Change-Id: Ia04c13b96bd1996e6e96f9b4e2e693af4cb97070
2018-04-11 16:35:50 -07:00
Jerry Zhang
df101a4596 Merge "Write descriptors for Mtp in UsbService" into pi-dev 2018-03-27 02:49:02 +00:00
Andrew Chant
608ec66d62 UsbHostManager: Restore inserted device logging
Restore logcat logging of newly-added USB devices.
Eliminate blacklist log lines.

Test: Connected USB Storage and USB audio devices.
Updated UsbDescriptorParserTests for device descriptor
version.

example output:
UsbHostManager: USB device attached: vidpid 03eb:2433 mfg/product/ver/serial Libratone/Libratone_INEAR/1.00/Inear_mcu_app_0.2.1_20160304 hasAudio/HID/Storage: true/true/false
UsbHostManager: USB device attached: vidpid 05dc:a82b mfg/product/ver/serial Lexar/ARA Storage /2.08/0024070163400215 hasAudio/HID/Storage: false/false/true
UsbHostManager: USB device attached: vidpid 18d1:5029 mfg/product/ver/serial Google/USB-C to 3.5mm-Headphone Adapter/22.80/201405280001 hasAudio/HID/Storage: false/true/false
UsbHostManager: USB device attached: vidpid 18d1:5025 mfg/product/ver/serial Google/USB-C to 3.5mm-Headphone Adapter/22.80/201405280001 hasAudio/HID/Storage: true/true/false

Bug: 74119682
Change-Id: I72688f651c819d4bdc48f6d6316570ca5fc54d1e
2018-03-26 20:55:54 +00:00
Andrew Chant
0491f5aa0f UsbDescriptorParser: always parse in constructor
UsbDescriptorParser::parseDescriptors always returned true.
Remove the return value, and remove the one constructor that
doesn't parse descriptors so the device is always in a parsed state.

Bug: 74119682
Test: Built
Change-Id: I2dd8d439405867d78102a9591dd1db36fe3959dc
2018-03-26 20:55:28 +00:00
Jerry Zhang
6d319b8aaa Write descriptors for Mtp in UsbService
The current model for setting up a functionfs
function is:

UsbDeviceManager#setCurrentFunctions() ->
intent is sent to MtpReceiver to write the descriptors ->
init/hal waits for descriptors to write, then pulls up gadget ->
Gadget is configured, a USB_STATE intent starts MtpServer

The main downside of this is a lack of reliability because
the Mtp process could be killed at any point. Normally, a
gadget is unbound if its control endpoint is closed. no_disconnect
works around this, but is still a little janky. In addition, the
extra intent delays the startup of the gadget.

With the new model, UsbDeviceManager writes the descriptors
on initialization. Since it is a system service, it won't be killed.

UsbDeviceManager#setCurrentFunctions() ->
init/hal pulls up gadget ->
Gadget is configured, a USB_STATE intent starts MtpServer
MtpServer calls UsbManager#getControlFd to get a dup of the control
endpoint.

Also modify permissions so system server can access mtp files.

Bug: 72877174
Test: Change usb configurations to ptp/mtp
Change-Id: Id17d2b5930f4e1f37ec1b4f00add9d594174ad49
2018-03-22 11:35:19 -07:00
TreeHugger Robot
ff1f7090c6 Merge "Set systemReady before querying the portStatus." 2018-02-28 02:52:31 +00:00
TreeHugger Robot
23aee1bbb5 Merge changes from topic "terminal_type_fix"
* changes:
  Add test for UsbDescriptorParser.java
  USB Audio: broaden Terminal Type interpretation
2018-02-28 00:09:15 +00:00
Badhri Jagan Sridharan
d399f2eaff Set systemReady before querying the portStatus.
Since the callbacks are async, its possible that the callback gets
called before the systemReady flag is set.

Change-Id: I5752c097e25ef30a151461540dd7d5323cc927af
2018-02-27 22:56:45 +00:00
Andrew Chant
0ef73801f5 USB Audio: broaden Terminal Type interpretation
Terminal type is currently used to determine presence of audio input
or output capabilities on audio devices.

Broaden the set of terminal types accepted as inputs and outputs.

Test: Verified by playing with USB-C to 3.5mm adapter with
high impedance load, checked Terminal type reported as 0x0603.
Verified no audio on old build, audio on new build.
Checked with low impedance load with and without microphone.
Checked with no load.

Bug: 73813676
Change-Id: Ib9b291e4770dc3c03157df7ac4277da1692174d7
2018-02-26 14:39:46 -08:00
Jerry Zhang
20b1414fe0 Initialize functions as NONE in legacy handler.
Since adb is being removed from the functions read
from sys.usb.config anyway, it makes more sense to
set it to NONE on boot. This prevents errors with
devices that already have oem functions in the config.

Bug: 73010922
Test: Power test passes
Change-Id: I855ba228dbdd9f8c8a91842a8beb68a789fdf1e9
2018-02-24 02:19:16 +00:00
Eric Laurent
aacda9d287 Merge "add OWNERS file to audio, media and usb services" 2018-02-15 23:02:45 +00:00
Eric Laurent
c8001253d3 add OWNERS file to audio, media and usb services
Added:
 services/core/java/com/android/server/audio/OWNERS
 services/core/java/com/android/server/media/OWNERS
 services/usb/OWNERS

Test: make
Change-Id: I292c3acbfa4163607ce5b9a440ad4d56406fbf9d
2018-02-14 16:06:58 -08:00
Andrew Chant
5f53db38b2 Merge changes from topic "uac_jackdetect"
* changes:
  Add a selected UsbAlsaDevice
  ALSA jack detection support
  Synchronize UsbAlsaDevice, rename playback/capture.
2018-02-14 19:00:23 +00:00
Andrew Chant
278f4c9a05 Add a selected UsbAlsaDevice
Keep track of the currently selected UsbAlsaDevice in a
synchronized manner.
Allow it to notify AudioService that it has been disabled
prior to replacing it with a new Audio Device.

Test: verified audio worked as expected when using
both UAC2 and non-UAC2 3.5mm adapters, with 3.5mm
plugging/unplugging and USB-C plugging/unplugging.

Change-Id: I8b76145490da38d4eec25f4f2bdb6695afa151b9
2018-02-13 16:51:34 -08:00
Andrew Chant
07a97da51f ALSA jack detection support
Adds support for ALSA jack detection for USB.
Spawns a new thread for ALSA jack detection on device
insert.  If the device doesn't support ALSA jack detection,
the thread terminates.

Test: UAC2 audio accessory and a kernel
which supports USB ALSA Jack detection, switching between
speaker and USB works perfectly with plug/unplug at jack.

Bug: 68337205
Bug: 70632415
Change-Id: I1800660ad4d2341f19ce7be6d6b01f81a7f2d1a6
2018-02-13 16:42:35 -08:00
Jerry Zhang
2135f41477 Don't set functions at registration on boot
If onRegistration is called before functions
are received, adb can be kicked on boot. To fix,
don't set functions if they are still being
requested.

Bug: 73168456
Test: adb logcat doesn't dc
Change-Id: I25bfe13604f0ce0c65c3eb82bcfafd9fcae0283f
2018-02-13 12:58:41 -08:00