369 Commits

Author SHA1 Message Date
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
Badhri Jagan Sridharan
5eb97dcf50 Add support for UsbDeviceManager to talk to USB GADGET HAL
Till now, Init scripts(property tiggers) are used define the
operation that needs to be performed when a certain gadget
composition needs to be enabled. Based on the user preference,
usb service sets the sys.usb.config which triggers the
corresponding property triggers in init scripts and usbservice
polls on sys.usb.state to infer whether the property triggers
have completed executing.

This CL makes UsbHandler class abstract to make init scripts
based legacy implementation and HAL based implementation to
share the common logic. The legacy init script based logic is
implemented by UsbHandlerLegacy and HAL based logic is implemented
by UsbHandlerHal. The decision on which one to initialize is
made depending on whether the device has Gadget HAL impelemented.

Since HIDL supports asynch calbacks, usb state management is moved
to the message queue to avoid polling incase of HAL based
implementation.

To switch to a new configuration:
1. UsbService calls setCurrentUsbFunctions and queues
   MSG_SET_FUNCTIONS_TIMEOUT
2. If the  setCurrentUsbFunctionsCb arrives on time,
   then  MSG_SET_FUNCTIONS_TIMEOUT is cancelled and
   default functions are retried by queueing
   MSG_SET_DEFAULT_FUNCTIONS if SUCCESS is not signalled.
3. If MSG_SET_FUNCTIONS_TIMEOUT gets executed, then,
   default functions are retried by calling
   setEnabledFunctions(null, false, mUsbDataUnlocked);

Also, for HAL based implementation config_oemUsbModeOverride is no
longer needed as hal can take of enabling oem specific functions.

Bug: 63669128
Test: Tested usb gadget configuration for both cases:
1. When gadget hal is present
2. When gadget hal is not present
Change-Id: Ifcef464a0b97b265872696346a76162f8e84d6c0
2018-01-22 17:02:25 -08:00
Jerry Zhang
7ca5d3a334 DO NOT MERGE: Add setScreenUnlockedFunctions method to UsbManager
Cherry-pick from 30b9adfad1c5055044f0b585782b10f764e0ddf9

The screen unlocked functions save effort on setting
the usb config during each connection. These
functions persist between connections and between
boots. When the screen is unlocked and these
functions are set, the current functions will
be automatically set to the screen unlocked functions.

Also added svc command for this so it can be
used and tested while the UI is worked on.

Bug: 62876645
Test: svc usb setScreenUnlockedFunctions mtp
Test: Test functions with locking, unlocking, and
disconnecting, with no lockscreen, swipe, and pattern

Change-Id: Ia05e095917166d25398c4d310b02971e3a1bb12a
2018-01-12 15:35:43 +00:00
Badhri Jagan Sridharan
65a6237243 Overcome disconnect during oem override
Cherry-pick from 83a0d6fa577fab4d45aba38e3eb52b08b8123c17

While bootup, usb gets configured when the property triggers are
run. While in oemOverride, the current configuration is persisted
in sys.usb.<bootmode>.config. Do not reconfigure the stack if the
current configuration is same as the new configuration.

Bug: 64225494
Change-Id: Id35d110bf3fa8f58d05e14941716d4ad2b196f8d
2018-01-10 16:45:32 -08:00
Colin Cross
eb652a47a1 Convert services to Android.bp
See build/soong/README.md for more information.

Test: m checkbuild
Change-Id: I417409281c928ea667d937090d2a0d9d72a449a2
Merged-In: I417409281c928ea667d937090d2a0d9d72a449a2
Exempt-From-Owner-Approval: trivial conversion
(cherry-picked from commit e0b2ee52d2f274a2d46b2e6695e42d2764c39fa7)
2017-12-12 23:22:25 +00:00
Xin Li
220871a697 Merge commit '98e12851336b7db16e583f9afac63ecc97465980' from
oc-mr1-dev-plus-aosp-without-vendor into stage-aosp-master.

Change-Id: Ia7b8da4a00d215160e4a4fa40f6044208d1297b7
Merged-In: I19846d2a3ee27aecbae2367a74ee49082eea154d
2017-11-14 12:31:11 -08:00
Selim Gurun
c5bd3d3bb8 Respect Accessory timeout value when restoring defaults
Android accessory mode timeout value is a lot larger than default
timeout value (10 seconds vs. 1 second). The large timeout
value is needed to accomodate for HUs that are not quick
to respond after MTP to Accessory mode change.

Bug: 68819844
Test: Manual
Change-Id: I665e1001f8df66fb00cbfcbf6c58d97c372797fc
2017-11-02 18:39:31 -07:00
Paul McLean
53215d1f7d Add dump of USB descriptors to the dumpsys for UsbHostManager service.
Cleaned up text formatting.

Bug: 65158441
Change-Id: Ie6531d42bb0d78f2b8af382329a973e629f23c5f
Test: Manual - connected USB headset, ran adb shell dumpsys usb. Examined output.
2017-09-05 14:30:01 -06:00
Paul Mclean
87cb6d806e Merge "Adding USB audio-class 2.0 spec descriptors." into oc-mr1-dev 2017-08-30 22:13:36 +00:00
Paul McLean
fd7cb85fef Adding USB audio-class 2.0 spec descriptors.
Added USB audio-class 2.0 format type descriptors.
Added Tree parsing.
Rearchitected reporting (again) to better support reuse and scale.

Bug: 64301464

Test: Run code against representative USB audio peripherals and verify
that each correctly handles or ignores all descriptors and the correct
device semantics (headset / not-headset) are still calculated.

Change-Id: I1b3b01ab1cd804ed876bf6427c3afba15eea6a6e
2017-08-30 10:29:16 -06:00
Jerry Zhang
e537a83139 Reset functions to null when user changes.
When MTP or PTP is in the config and user changes,
it clears dataUnlocked but sets the functions to
mCurrentFunctions which will leave MTP or PTP in the
config. If dataUnlocked is false, we want to remove
MTP/PTP from the config when adb is enabled, and leave
them in otherwise. This is done automatically by
setting functions to null.

Bug: 64822515
Test: Change users while adb  / mtp connected.
Change-Id: I82561f82e06f247c967438a473b08b5098d39ccb
2017-08-23 11:10:44 -07:00
Badhri Jagan Sridharan
fb80072f99 Merge "Reword analog audio not supported notification" into oc-dr1-dev
am: 69840ca338

Change-Id: I6a9a611c13de7a63e6d5bdbf4718827f2295a28b
2017-08-01 19:03:55 +00:00
TreeHugger Robot
69840ca338 Merge "Reword analog audio not supported notification" into oc-dr1-dev 2017-08-01 18:51:53 +00:00
Paul Mclean
18d64cf8fe Merge "Fix exceptions causing HTC dongle (and JBL headset) to fail connection logic." into oc-dr1-dev
am: f3562ffdfb

Change-Id: I0304bf7c72a340f4bebebea89d2e934ae5830b33
2017-08-01 15:35:05 +00:00
Badhri Jagan Sridharan
30c8efa66b Reword analog audio not supported notification
New title: Analog audio accessory detected
New message: The attached device is not compatible with this
phone. Tap to learn more.

Also switch to bigTextStyle as the notification message
takes more than one line to display.

Bug: 63962800
Test: Attached analog audio accessory to verify the notification
manually. Also verified that the charging notification remians
untouched.
Change-Id: I5c395bdf3c3dd11f3be8835ec773f087afdc85d9
2017-07-31 17:05:17 -07:00
Paul McLean
7d545bef60 Fix exceptions causing HTC dongle (and JBL headset) to fail connection logic.
Bug: 64108509
Test: Manual

Change-Id: I9574f34cea4ff9ef3e18553a138f1a8b95b1b108
2017-07-28 17:47:54 -07:00
Badhri Jagan Sridharan
1e249aeafa Merge "Always reevaluate whether to show the notification for USB_DEVICE_* intents" into oc-dr1-dev am: d5f442d65b
am: 19ad4c2055

Change-Id: I4b6edbefd70585302959aa830f5a6d50f4f01a4d
2017-07-19 18:16:40 +00:00
Badhri Jagan Sridharan
5e79cbb291 Always reevaluate whether to show the notification for USB_DEVICE_* intents
The decision whether to show or hide the "Usb supplying power.."
notification is based on two different broadcasts
1. USB_DEVICE_ATTACHED/DETACHED
2. USB_PORT_CHANGED

Depending on how long the port takes to enumerate, the required
intents might arrive in different order. Previously, it was assumed
that the ATTACHED broadcast would arrive before the PORT_CHANGED
broadcast and the code was aggressive to reduce the number of
times the decision to display/hide the notification is made.
This might cause the notification to be displayed in some instances
when it is not supposed to be displayed. This CL makes the usb service
to always reevaluate whenever USB_DEVICE_ATTACHED/DETACHED is
received.

Also, adding logs to print whenever the notification in enqueued/
dequeued.

Bug: 63785369
Test: Verified that the notification is displayed when connecting
to another pixel device and hidden when mouse or headset is
connected.
Change-Id: I30650a2d9923d01a1fce4b9450e65ec7f4e6557b
2017-07-18 17:44:47 -07:00
Paul McLean
39c9e18721 Merge "More fine-grained exception handling so we can still use non-excepting descriptors." into oc-dr1-dev am: 84a60bf9e8
am: 6899fa6c81

Change-Id: Ic70707c334e9765e7f196bdcb0d2d753ce17b0fb
2017-07-13 18:09:17 +00:00
Paul McLean
20568917af More fine-grained exception handling so we can still use non-excepting descriptors.
Bug: 63655391
Test: Manual - connect various devices and verify the connection state is correct.
Change-Id: Iae6143d2e853e916c8588e0c6f771c00714b3a8a
2017-07-13 15:53:42 +00:00
Badhri Jagan Sridharan
6276bb899e Clear mCurrentAccessory if accessory function is no longer enabled
Accessory mode implements debounce timeout ACCESSORY_REQUEST_TIMEOUT
within which when a disconnect is seen, the accessory function would
be removed from the usb configuration but mCurrentAccessory would
not be set to NULL until the timeout expires.

Also, setEnabledFunctions(null, false, false) does not force an
additional disconnect when accessory function has already been
removed from usb configuration.

BUG: 62241238
Change-Id: I25973475fb02d613e11396bcad5e88656ad8940a
2017-07-12 18:47:07 +00:00
Paul McLean
f148e8ecce Merge "Catch exception in descriptor parser causes device connection to be skipped." into oc-dr1-dev am: 22d4bf2283
am: 702d82fdc0

Change-Id: Ia45c777b095ff8c29042145fd11b29dcace24366
2017-07-11 00:58:17 +00:00
Paul McLean
b82963f3e0 Catch exception in descriptor parser causes device connection to be skipped.
Bug: 63538159

Test: Manual - force an exception and verify the the device is still available.
Change-Id: I4f4c59d4d0f73b664fac8bc74a64414d0e9d9a24
2017-07-10 14:57:20 -06:00
Jerry Zhang
b60c48a6a2 Merge "Broadcast only if boot complete" into oc-dr1-dev 2017-07-06 16:52:04 +00:00
Jerry Zhang
885b9e7133 Broadcast only if boot complete
Accessory connects / disconnects can occur before
boot complete, so don't broadcast intents if that
is the case.

Bug: 63114621
Test: connect/disconnect an accessory
Change-Id: Ib8f9eb97ce1630004511fcc1fb84594ccc812c06
2017-07-05 10:44:59 -07:00
Colin Cross
6bad7044f5 Merge changes I09ecc525,I83e7e8ef
* changes:
  Revert "Do not use lambda as it breaks javac"
  Add missing dependency to services for desugaring
2017-06-30 15:52:02 +00:00
Jerry Zhang
ed0cc81212 Merge "Broadcast only if boot complete" 2017-06-29 21:54:39 +00:00
Paul McLean
e3bb95dddb Merge "Adding USB Headset awareness." into oc-dr1-dev am: f56b57781e
am: 1ae4273154

Change-Id: I24ffbb79b965df15a22dbc5d6ce3ae90ddb27b50
2017-06-29 19:42:04 +00:00
Jerry Zhang
dc0c14f169 Broadcast only if boot complete
Accessory connects / disconnects can occur before
boot complete, so don't broadcast intents if that
is the case.

Bug: 63114621
Test: connect/disconnect an accessory
Change-Id: Ib8f9eb97ce1630004511fcc1fb84594ccc812c06
2017-06-29 11:14:30 -07:00
Colin Cross
03196cdf2e Revert "Do not use lambda as it breaks javac"
This reverts commit e37eda7b413099f881f348aeafc5d2d33639484e.

I83e7e8efdff9cd662e179240336abebedf859c62 adds the missing
dependency to let desugar work.

Bug: 63078196
Test: m -j ANDROID_COMPILE_WITH_JACK=false
2017-06-29 10:35:22 -07:00
Paul McLean
b5eaa809da Adding USB Headset awareness.
Bug: 36220140
Bug: 62043095
Test: Manual
Change-Id: Ic4636e3dc2dfce0154e6405848bea7752cf2d07b
2017-06-29 10:30:05 -06:00
Philip P. Moltmann
e37eda7b41 Do not use lambda as it breaks javac
Bug: 63078196
Test: Built
Change-Id: I6f195ad127e95b76b85ad7417f31ac19af0ac5bc
2017-06-27 23:58:33 +00:00
Philip P. Moltmann
bee04d08b5 Clean up USB*Manager.
Just automatic cleanup.

Test: Built
Change-Id: I1da09d6b43503a6b77a3619f0f8513ef39cf2d75
2017-06-26 16:04:10 -07:00
TreeHugger Robot
31f5b6875c Merge "Enable MTP or ADB when default functions are enabled" 2017-06-05 23:16:46 +00:00
Jerry Zhang
42f4815eff Merge "Remove ptp from persist config on boot" into oc-dev am: 1d1cf13056
am: 8d5570b9e1

Change-Id: I792ed0959e5a24ef8893a1bd63e3a33278462556
2017-06-05 18:54:08 +00:00
Jerry Zhang
6032c354d9 Remove ptp from persist config on boot
We got a report from a user in which ptp was set in the
persistent config, likely from a previous version.
This causes errors in the usb state and is not removed
by an ota. To fix, remove ptp in the same place that mtp
is removed from the persistent config.

Bug: 62202885
Test: Add ptp to persistent config, verify removed.
Change-Id: I5ebd93b9c8a49bcaca5a3362e49ed1e1acf50a9b
2017-06-02 12:05:03 -07:00
Badhri Jagan Sridharan
7f3047e6b6 Enable MTP or ADB when default functions are enabled
Clients (viz. Tethering) use UsbManager@setCurrentFunction(null, ..)
to make the device switch to default functions. While in OemMode,
this gets set to the last enabled functions list. Instead,
enable MTP or ADB depending on whether ADB is enabled or not.
This is the expected behavior for normal boot as well.

Bug: 37491031
Test: Verified that the device falls back to either mtp or adb while
in OemOverride mode.
Change-Id: I1c26d1d0ee3c015b597d40771cd765b783cd91bb
2017-05-25 10:30:22 -07:00
Jerry Zhang
3a958a09d2 Merge "Revert "Upgrade logging for UsbDeviceManager to narrow down bugs."" into oc-dev 2017-05-22 23:13:58 +00:00
Jerry Zhang
daa9c19dae Revert "Upgrade logging for UsbDeviceManager to narrow down bugs."
This reverts commit c889b4f4eb62ae7ad8de3ff3d98768e71cb3ad5a.

Merged-In: I74306bacad2a61471a9b8c9fd881229b22b6975e
Change-Id: I74306bacad2a61471a9b8c9fd881229b22b6975e
2017-05-22 10:57:08 -07:00
Jerry Zhang
b2dac52391 Revert "Upgrade logging for UsbDeviceManager to narrow down bugs."
This reverts commit c889b4f4eb62ae7ad8de3ff3d98768e71cb3ad5a.

Change-Id: I74306bacad2a61471a9b8c9fd881229b22b6975e
2017-05-15 13:24:23 -07:00
Jerry Zhang
653fbeeec4 Merge "Only force reset when adb is not enabled (i.e. mtp is)" into oc-dev am: f874fd319e
am: c5a4576cab

Change-Id: I153a5ad3e4bd0de9a62ef39ebc7579f4916b79e3
2017-05-12 20:31:51 +00:00
Philip P. Moltmann
278685d468 Merge "Remove forward matches before checking for default" into oc-dev am: d53cbfd0dc
am: ba8b3f05b6

Change-Id: Ic35779f6b6ad97dc1a6f83356dfa45e0d5b5f406
2017-05-12 20:29:15 +00:00
TreeHugger Robot
f874fd319e Merge "Only force reset when adb is not enabled (i.e. mtp is)" into oc-dev 2017-05-12 19:41:52 +00:00
TreeHugger Robot
d53cbfd0dc Merge "Remove forward matches before checking for default" into oc-dev 2017-05-12 19:17:37 +00:00
TreeHugger Robot
81e8d4b340 Merge "Prevent multiple copies of android.hidl.manager-V1.0-java" into oc-dev 2017-05-12 19:07:41 +00:00
Jerry Zhang
ad962a923c Only force reset when adb is not enabled (i.e. mtp is)
Some users depended on adbd continuing to run after disconnect
in order to use scripts with nohup. This change allows this
use case to keep working since only mtp has to be force
set.

Bug: 38227228
Test: adb shell "nohup sh /sdcard/script" where script contains
"sleep 5; touch /sdcard/done" and verified file still appears even if
disconnected during sleep.
Test: am force-stop com.android.providers.media, still connects

Change-Id: I25ae2b922fa4d06109ac8cf5e43e1c47a33c46a6
2017-05-11 13:50:28 -07:00
Philip P. Moltmann
0d78363a39 Remove forward matches before checking for default
A forward match is a intent-target (aka. match) that switches between the
personal and work profile's intent resolver.

This can be unnecessary if there are no work profile matches.

We need to remove these unnecessary matches early as the default activity
resolution code considers a system app as default _only_ if it is the only
match. Before there could still the an unnecessary forward match under
consideration.

Test: Connected USB accessory that only matches a system app on the personal
      profile.
      Before we showed a confirm-dialog, now we consider the system app
      as default and automatically launch it.
Fixes: 37530439

Change-Id: I7bc9b969fc0b9abae4d15dd3f268783d05b91f9a
2017-05-11 10:23:41 -07:00
Badhri Jagan Sridharan
e5bf826525 Prevent multiple copies of android.hidl.manager-V1.0-java
Link to android.hidl.manager-V1.0-java shared libraryto prevent
duplicate copies of the library present in process address
space.

Bug: 38036660
Test: Verified that the UsbService reports status of the ports through
dumpsys usb.
Change-Id: Ie3de4f9bbe28061e7cc464fa3cab2f6bd6fe6995
2017-05-10 07:27:24 -07:00
Philip P. Moltmann
16bcd7219d Merge "Merge "Fixes for handling users + default for USB" into oc-dev am: 5262ae9b87" into oc-dev-plus-aosp
am: bc535b11b6

Change-Id: I6e20b889abbb7d2c037d71c271a733e0639b3e1e
2017-05-10 02:32:54 +00:00
TreeHugger Robot
5262ae9b87 Merge "Fixes for handling users + default for USB" into oc-dev 2017-05-10 01:39:33 +00:00