Commit Graph

460 Commits

Author SHA1 Message Date
Philip P. Moltmann
e89688fcd7 Check USB device/accessory perms with sys identity
As checking the permissions might call UsbDevice/UsbAccessory.getSerial
again, we have to make sure that in this code paths we run with the
system's identity so that we can always resolve the serial number.

Test: CtsVerifier UsbAccessory/UsbDevice test
Fixes: 117606509
Change-Id: I777be10b806ab02046f99805806ae1a16ebb0203
2019-05-28 17:51:39 +00:00
Ying Zheng
b024059387 Fix usb service broadcasting for automotive.
Test: build
Bug: 132373192
Change-Id: I7017cfbe6ccdfa3a015f2165d10d9104046adc55
2019-05-22 16:56:03 -07:00
Paul McLean
bfae878d6f Implement a "blacklist" for ALSA devices.
Specifically for the Sony PS4 controller.
Bug: 129697606
Test: Build, install, plug in PS4 contoller, note audio continues to route to device speaker.

Change-Id: I20f5cafb616b4a673772f8e4614e1efa8ae0edb4
2019-05-09 08:43:09 -06:00
Priyank Singh
41efb403c8 "Charging this device via USB" notification isn't relevant for automotive.
Bug: 124302589
Test: Manual
Change-Id: Icaa56c5f9ead79ce0306a95229f915073d1b6a1f
2019-04-15 16:59:18 +00:00
Badhri Jagan Sridharan
883c2a4bef Only re-enable contaminant detection when port is present
Contaminant detection is re-enabled when the disconnected port's
portStatus has contaminant detection disabled. During port removal,
there is no reason why contamiant detection has to re-enabled since
the port is anyways being teared down.

Bug: 129696344
Test: dumpsys usb add-port "matrix" ufp;
dumpsys usb remove-port "matrix" ufp

Change-Id: Ie146db82d93414e90ee99b4d17ec0ba5ada2ce83
2019-04-01 12:17:03 -07:00
TreeHugger Robot
dec2604a16 Merge "Fix missing combination check SINK/DEVICE" 2019-03-26 23:29:25 +00:00
Badhri Jagan Sridharan
665eb216e5 Fix missing combination check SINK/DEVICE
While checking for possible role combinations, the SINK/HOST combination
seems to be mistakenly checked twice intead of SINK/DEVICE.
This CL fixes this. The code now checks for:
1. source & host
2. sink & host
3. source & device
4. sink & device

Cherrypicked from aosp:
https://android-review.googlesource.com/c/platform/frameworks/base/+/933377

Bug: 119142682
Test: Build success
Change-Id: I5e652fbf9313bd2c122fe728d58e577085632253
2019-03-26 18:50:54 +00:00
Badhri Jagan Sridharan
3df511319c UsbPortManager: Re-enable contaminant detection when port is unplugged
SystemUI disables contaminant detection when user wants to continue
using the port. Re-enable contaminant detection when the accessory
is unplugged.

Bug: 128534822
Test: Tested with the mock circuit.
Change-Id: I22a3c839264876409c68c6a3145c9fcc6278f381
2019-03-15 16:28:22 -07:00
Badhri Jagan Sridharan
26c490c568 Support contaminant detection disable workflow
Do not show "Safe to use USB port" when contaminant detection is
disabled by the user.

Bug: 128534822
Test: Tested with the mock circuit.
Change-Id: Iebd12f04a6d8bfd7be5d673cf5a6742cf3d6f281
2019-03-15 16:28:22 -07:00
Badhri Jagan Sridharan
397a98c806 Refactor actions that are needed to be taken during port status changes.
For any change in port status, the following needs to be done:
1. Send port changed Broadcast
2. Log to statsd
3. Update contaminant notification.

Bug: 128534822
Test: Tested with the mock circuit.
Change-Id: I2c279a2ea0255a69c0a74a98ebf5bf680cae1fe1
2019-03-15 16:28:22 -07:00
Badhri Jagan Sridharan
6f985da37f Store as V1.0 reference by default
Store IUsb as V1.0 instance by default and downcast when
calling V1.2 methods.

Bug: 123498520
Test: Checked dumpsys usb to reflect port status for
V1.0, V1.2, V1.3 implementations.
Change-Id: Id55d930252bff39b3b86283f3b6ab33a5e935b24
2019-01-29 18:42:35 -08:00
Badhri Jagan Sridharan
129c7297bb Log USB contaminant status
01-14 21:15:26.223   895  1046 I statsd  : { uid(1000) 1547529326000000000 235342687348 (117)0x10000->port0[S] 0x20000->2[I]  }
01-14 21:15:51.719   895  1046 I statsd  : { uid(1000) 1547529351000000000 260838630045 (117)0x10000->port0[S] 0x20000->3[I]  }
01-14 21:16:51.729   895  1046 I statsd  : { uid(1000) 1547529411000000000 320847794877 (117)0x10000->port0[S] 0x20000->2[I]  }
01-14 21:17:00.552   895  1046 I statsd  : { uid(1000) 1547529420000000000 329671167943 (117)0x10000->port0[S] 0x20000->3[I]  }
01-14 21:18:00.560   895  1046 I statsd  : { uid(1000) 1547529480000000000 389679730223 (117)0x10000->port0[S] 0x20000->2[I]  }

Bug: 119642987
Bug: 122595032
Test: Manually tested by running: adb shell cmd stats print-logs,
adb logcat | grep statsd | grep \(117\)

Change-Id: Idf98e4e5dfc44133112c48999eff7cccfd14550d
2019-01-23 18:41:10 -08:00
Badhri Jagan Sridharan
392b747d4b UsbContaminant dialog
Bug: 119642987
Bug: 117330206
Bug: 77606903

Test: Ran the following sequence:
1. Add simulated port: dumpsys usb add-port "matrix" ufp
2. Set contaminant present to true:
   dumpsys usb set-contaminant-status "matrix" true
   Contaminant present notifcation shows up and dialog pops up upon
   clicking the notification.
3. Set contaminant present to false:
   dumpsys usb set-contaminant-status "matrix" false
   Contaminant present notification is dismissed and the safe to use
   notification shows up.

Change-Id: I33d22caafbedb2a21a0f61f663ebddf5c9e3f84b
2019-01-23 10:43:15 -08:00
Badhri Jagan Sridharan
34d358c388 Add test commands to spoof presence of contaminants
This CL simulates contaminant presence through simulated port.

1. Add a port: dumpsys usb add-port "matrix" ufp
2. Set contaminant presence to true: dumpsys usb set-contaminant-status "matrix" true
3. Set contaminant presence to false: dumpsys usb set-contaminant-status "matrix" false

Bug: 119642987
Bug: 117330206
Bug: 77606903
Test: Made sure that dumpsys usb reflected the correct contaminant
status.
Change-Id: Iadb0ea92db65afdb25dbd32c02d9fb778bd4ec8c
2019-01-23 10:43:15 -08:00
Badhri Jagan Sridharan
cd9a661c9b Contaminant detection notification
Bug: 119642987
Bug: 117330206
Bug: 77606903

Test: Manually tested for contaminant notification to show up
Change-Id: If22215df1e6127aa67190f72328fbc32b9477bc2
2019-01-23 10:41:02 -08:00
Badhri Jagan Sridharan
e966a38b67 Support USB V1.2 HAL
USB V1.2 HAL supports contaminant detection interface.

Bug: 119642987
Bug: 117330206
Bug: 77606903

Test: Manually tested for notification pop-up
Change-Id: I304fb4933ba8b8eaa08c32c9e8c116cba7aa6380
2019-01-23 10:41:02 -08:00
Badhri Jagan Sridharan
0fbae8b3c1 Log all Usb accessories
Logs when connecting/disconnect thumbdrive.

01-14 19:58:45.370   918  1009 I statsd  : { uid(1000) 1547524725000000000 338323224430 (77)0x10000->1921[I] 0x20000->21889[I] 0x30000->0[I] 0x40000->0[I] 0x50000->1[I] 0x60000->0[I] 0x70000->10724[L]  }
01-14 20:00:27.471   918  1009 I statsd  : { uid(1000) 1547524827000000000 440424268612 (77)0x10000->1921[I] 0x20000->21889[I] 0x30000->0[I] 0x40000->0[I] 0x50000->1[I] 0x60000->1[I] 0x70000->0[L]  }
01-14 20:00:36.198   918  1009 I statsd  : { uid(1000) 1547524836000000000 449151666148 (77)0x10000->1921[I] 0x20000->21889[I] 0x30000->0[I] 0x40000->0[I] 0x50000->1[I] 0x60000->0[I] 0x70000->8727[L]  }
01-14 20:00:39.401   918  1009 I statsd  : { uid(1000) 1547524839000000000 452354416467 (77)0x10000->1921[I] 0x20000->21889[I] 0x30000->0[I] 0x40000->0[I] 0x50000->1[I] 0x60000->1[I] 0x70000->0[L]  }
01-14 20:00:48.348   918  1009 I statsd  : { uid(1000) 1547524848000000000 461301290587 (77)0x10000->1921[I] 0x20000->21889[I] 0x30000->0[I] 0x40000->0[I] 0x50000->1[I] 0x60000->0[I] 0x70000->8947[L]  }

Bug: 120566491
Test: Manually tested by running: adb shell cmd stats print-logs,
    adb logcat | grep statsd | grep \(77\)
Change-Id: I172964ad592b910fcadf88c84f9cbd9d47f44131
2019-01-14 20:01:31 -08:00
TreeHugger Robot
a79bdc0d93 Merge "Make sure mCurrentUsbFunctionsRequested flag be updated currectly" 2019-01-07 02:26:59 +00:00
Howard Yen
3b747d3138 Make sure mCurrentUsbFunctionsRequested flag be updated currectly
There is a situation that getCurrentUsbFunctions callback function will
be invoked before mCurrentUsbFunctionsRequested flag updated, thus, gadget
will be reset during boot completed. Make sure mCurrentUsbFunctionsRequested
flag be updated before getCurrentUsbFunctions callback function invoked.

Bug: 119688133
Test: Verified that gadget reset does not happen
Change-Id: Id8b58d9ccd3f62c976d1292575a06554bef622a4
Signed-off-by: Howard Yen <howardyen@google.com>
2019-01-03 23:07:41 +08:00
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