Commit graph

69 commits

Author SHA1 Message Date
Kuen-Han Tsai
f22f21191b Usb: Add status check to prevent NPE
This patch prevents a Null Pointer Exception in
queryMoistureDetectionStatus() when getPortStatusHelper() fails to open
the /sys/class/typec file. The failure results in an empty
currentPortStatus vector, causing the NPE when accessing its first
element.

Bug: 361097811
Flag: EXEMPT bugfix
Test: NPE does not occur when getPortStatusHelper() fails
Change-Id: I61c9f7647aafca28b777e53f170764ddd02c060f
Signed-off-by: Kuen-Han Tsai <khtsai@google.com>
2024-10-09 15:15:56 +08:00
Kuen-Han Tsai
0c1f69415f Limit hub tuning when enable_hub is enabled
Some external hubs have the same VID and PID as the internal hub,
causing unintended hub tuning and compatibility issues.

This patch restricts hub tuning to only the internal hub located on
bus 1, port 1 when enable_hub is set to 1.

Bug: 353650207
Test: Verified an external GL852G speakerphone dock works when docked.
Test: adb shell cmd android.hardware.usb.IUsb/default hub-vendor-cmd
<hex wValue> <hex wIndex>
Flag: EXEMPT bugfix
Change-Id: If2cfe6684e4f5fafaab34bf7a4e4b4cd464d6575
Signed-off-by: Kuen-Han Tsai <khtsai@google.com>
2024-08-07 12:27:59 +08:00
Roy Luo
7c074a6c3c Use absolute path for udc device
Avoid search in /sys/class/udc directory

Bug: 339241080
Test: tested on gs201
Flag: EXEMPT bugfix
Change-Id: Iad74cae0d6ad6887d79d705dc8478f1b44532503
2024-07-09 03:03:33 +00:00
Kyle Tso
cb51a640f4 usb: Log for retry on role switch
Add a log for the retry. Also define the sleep time in the header file.

Bug: 341996696
Change-Id: Ib3cc0c6ad576e7cda26b7f50cdc61d52e6349c78
Signed-off-by: Kyle Tso <kyletso@google.com>
(cherry picked from commit d17fdff5f81cff76adaa75d50f26318be8048123)
2024-06-13 17:09:11 +08:00
Kyle Tso
d8fffffda4 usb: Add retry on role switch
Bug: 341996696
Change-Id: I8caa65288af1588d24fea4aa6c5768d45d69bbd5
Signed-off-by: Kyle Tso <kyletso@google.com>
(cherry picked from commit ef5856a4474002cc35a51377adffddd4cb239796)
2024-06-13 17:07:23 +08:00
Dennis Shen
cab0d60115 switch over to use new storage read api instead of
server_configurable_flags, this new read api lib will be needed for new
codegened aconfig flag lib.

Bug: 321077378
Test m and avd

Change-Id: I908ccf51b59ef4f475d8680003cb4aec61bdd12c
2024-06-07 14:16:50 +00:00
Jacky Liu
8548e9b2be Update i2c device paths
Update i2c device paths with static bus numbers.
Also remove some redundant paths.

Bug: 323447554
Test: Boot to home
Change-Id: Id3f0fccd39b70d247c0d7a17a1944223619ec40e
2024-02-07 04:00:46 +00:00
Jacky Liu
21dc8acdaa Revert "usb: Select usb-service rc files based on kernel versions"
This reverts commit 2371ea7920.

Use the same i2c device paths across all kernel versions.

Bug: 323447554
Change-Id: I0f970347a09e01f272a54fc7c940ea576a9e510b
Signed-off-by: Jacky Liu <qsliu@google.com>
2024-02-06 16:18:27 +00:00
Kyle Tso
2371ea7920 usb: Select usb-service rc files based on kernel versions
The sysfs paths in the rc file differ across kernel versions or build
targets. Given that the path is static in the newer kernels (6.1+),
modify the paths for newer kernels in the original rc file and create
another rc file for older kernels (i.e kernel 5.10). Put the correct rc
file to the vendor partition based on kernel versions.

Bug: 317946158
Change-Id: Ie313664ee14c837bc9f33113e9341f6e06192401
Signed-off-by: Kyle Tso <kyletso@google.com>
2024-02-03 01:14:43 +00:00
Kyle Tso
9bafd5f134 usb: Runtime search the i2c path
The paths of sysfs nodes are different on multiple build targets and are
also different between the old kernel (5.10) and newer kernel (6.1).
Since usb HAL code is shared by those targets and different kernel
versions, Runtime search the correct paths.

Bug: 317946158
Change-Id: I676455145232fd71db1578bb7a9801fed7bb327f
Signed-off-by: Kyle Tso <kyletso@google.com>
2024-02-03 01:14:43 +00:00
Roy Luo
fc280685ca usb: dump flag value in the constructor
Dump flag value in the construtor for easier debugging. Feature flags
are not expected to change in runtime, dumping the value once should
be enough.

Bug: 296119135
Test: manual test
Change-Id: Ie5aca2dff23e59704fb306833cde0e592b9f430d
(cherry picked from commit 9164eae7cdee032381d8bf045fbbed33f62b00bf)
2024-01-10 11:47:02 +00:00
Roy Luo
5e14ba01be usb: adjust heuristics for flaky connection warning
The state count requirement is very specific to the case where the
signal integrity is the culprit of flaky connection. However,
there could be other cases such as bad receptacles causing data pins
to disconnect randomly.
Remove the state count requirement to cover more cases.

Bug: 296119135
Test: manually trigger the warnings
Change-Id: Ic2ae376ad6062d9930614381503f44e4a5ac760f
2023-12-26 21:49:19 +00:00
Roy Luo
42020dc458 usb: implement heuristics to flag data compliance warnings
Support flagging enum failure and flaky connection in device mode,
flagging enum failure and missing data lines in host mode.
No warning would be flagged until 5 secs after the data session
starts to give ample time for the connection to stabilize, a timer
is added to support it.

Bug: 296119135
Test: manually trigger the warnings
Change-Id: I25f08657e328913946add192b5ecb9ee50c3a1a8
2023-12-22 03:05:06 +00:00
Roy Luo
8d10e34fe0 Revert^2 "usb: introduce UsbDataSessionMonitor class"
a9ac5d5869

Bug: 297224564
Bug: 296119135
Change-Id: I0e15924ff133c8070c923f9072497bfda4370b5b
2023-12-09 00:22:03 +00:00
Qian-Hao Huang
a9ac5d5869 Revert "usb: introduce UsbDataSessionMonitor class"
Revert submission 25524752-usbDataSessionMonitor

Reason for revert: Test for gs101/gs201 boot blocking issue (b/314904288)

Reverted changes: /q/submissionid:25524752-usbDataSessionMonitor

Change-Id: I0f762a9ba8345d2963ebfb2d50cb8a7460885221
2023-12-05 17:13:31 +00:00
Roy Luo
3555bbe0a8 usb: introduce UsbDataSessionMonitor class
Migrate the usb data session event functions to the class with the
following additional functionalities;
- Support detecting gadget soft pulldown (usually done during configfs
  function switch) and report usb data session correctly.
- Support reporting usb data compliance warnings to the class USB
  by providing getDataComplianceWarnings call.
- Use boot_clock instead of steady_clock to measure time correctly in
  the case of system suspend.

UsbDataSessionMonitor is self-contained and can be migrated to pixel usb
library after feature maturation.

Bug: 297224564
Bug: 296119135
Test: usb data session upload in device and host mode
Change-Id: Iba001933e193935d64cf5fd0a1257d02a4274fb1
(cherry picked from commit ea65ca11f6fbb6f13b89ef9ed03015f47ec1cedb)
2023-12-01 16:43:41 +00:00
Roy Luo
a99d48c10e usb: update usb hal version to v3
Bug: 308700954
Test: atest vts_treble_vintf_vendor_test
Change-Id: I13c99d309b925520b529ec2e22a120adc5e834e7
2023-11-14 20:43:36 +00:00
Roy Luo
91c045df5b usb: update incompatible charger warning reason
Report COMPLIANCE_WARNING_INPUT_POWER_LIMITED instead of
COMPLIANCE_WARNING_OTHER to flag incompatible chargers. The underlying
logic that generates the warning remains the same, what's changed is
the enum that's being used.
The purpose of the change is to have a warning type that better
represents what actually happens and free up COMPLIANCE_WARNING_OTHER
that was intended to act as a fallback reason code.
The flag enable_input_power_limited_warning controls whether to switch
to the new enum, while the flag enable_usb_data_compliance_warning
controls the new enums that are added as FlaggedApi in the framework.
Both flags need to be on to enable the change.

Bug: 308700954
Test: manual tests with local flag override
Change-Id: I6595706d1b83d533fc2d3e29086773270e045ede
2023-11-09 22:55:07 +00:00
Roy Luo
26abdf4ee2 Usb: capture and upload Suez metric VendorUsbDataSessionEvent
Upload metrics for the last data session that just ends upon
data role changes. The change is purely metric collection and
does not change any business logic.
This is a direct CP from ag/24816727

Bug: 297224564
Test: Trigger metric upload for both host and device mode and
      verify it by statsd_testdrive
Change-Id: I823ae8712b7914cfc7f6c6379acb3749d13c0974
(cherry picked from commit ccb35c81ff0bbfb013136bae7a572280b196bd1a)
2023-10-05 23:50:03 +00:00
Roy Luo
99c4d0f276 usb: upgrade stats AIDL to v2
Upgrade stats AIDL to v2 following pixelstats lib.

Bug: 297224564
Test: Build
Change-Id: Ib40d1366402f06feeb853f3d6141f1595a1113ce
2023-10-03 20:49:32 +00:00
Kuen-Han Tsai
4156589ff6 Usb.cpp: Fix typos when unable to disable USB data am: f233bec505 am: 503f92156e
Original change: https://googleplex-android-review.googlesource.com/c/device/google/gs201/+/24792093

Change-Id: Ie4076b2db9569246c06c0dc29ff036f674f02885
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-21 11:31:00 +00:00
Kuen-Han Tsai
f233bec505 Usb.cpp: Fix typos when unable to disable USB data
If Usb.cpp cannot write a zero value to the USB_DATA_PATH file, display
the message of "Not able to turn off usb connection notification".

Test: refactoring CL. Existing tests still pass.
Bug: 301016122
Change-Id: I8e0f485e74d10a0154e4cd78af9f5ef5a22d328f
2023-09-21 09:54:59 +00:00
Amit Sunil Dhamne
6abde127eb UsbGadget: Update SDP enum timeout when gadget is pulled up am: d8e2a02998 am: 0cee151356
Original change: https://googleplex-android-review.googlesource.com/c/device/google/gs201/+/24740928

Change-Id: I52e0001e36e4099cce263b8ef531cc190f07d222
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-09-20 18:37:03 +00:00
Amit Sunil Dhamne
d8e2a02998 UsbGadget: Update SDP enum timeout when gadget is pulled up
Indicate to the kernel that the usb gadget is pulled up
by writing to `update_sdp_enum_timeout` sysfs node. Write
to this node will inform the kernel that it can lower the SDP
timeout alarm value which is used to detect an SDP port
vs a DCP.

Bug:275687235
Test: Check `update_sdp_enum_timeout` is written into after usb
gadget is pulled up. Verify that the alarm timeout lowers.

Change-Id: Id3ae7e7a20b236cec6604414a7f81860e868bdd0
Signed-off-by: Amit Sunil Dhamne <amitsd@google.com>
2023-09-20 16:24:35 +00:00
Roy Luo
b97e3d8cc4 Usb: Listen to USB sysfs attribute for device state
Poll the sysfs attributes that represents usb device state in
either of the following states: not attached, powered, default,
addressed, configured.
The information is useful in detecting non compliant USB cable,
which will be supported in later patch sets. This patch lays
the ground work to monitor the sysfs attributes in both device
and host modes.
The thread to poll uevent is re-used to poll sysfs because this
serialize type-C port events and usb device state changes, hence
prevent potential races.
Added a thin abstration layer and a map to keep epoll data so
that it's easier to dynamically add/delete files to epoll, which
is needed for usb devices in host mode.

Bug: 285199434
Test: trigger usb device state changes in device and host mode
Change-Id: Ie5389d051deb28dbb486c2f27319b3cc9e89312f
2023-08-04 17:25:06 +00:00
Badhri Jagan Sridharan
877a72ffdf Usb: Populate UsbDataStatus only when not populated
Do not override UsbDataStatus when already populated.
Compliance warnings such as missing Rp do not populate
UsbDataStatus and the port partner is detected.
Populate UsbDataStatus only when not populated.

Bug: 279251052
Change-Id: Ibe71bdd5c521ba90c124d89bd56af90087c0df18
(cherry picked from commit 47e1400c8fef8af1aea985795d7adfe3ff16871b)
(cherry picked from commit a778a7c3a82c98ec56f9e2b0c2a1dce343317b48)
2023-05-16 05:58:01 +00:00
Badhri Jagan Sridharan
74246dbc5f Revert "usb: Temporarily disable compliance warning"
This reverts commit 55082ca17e.

Bug: 279251052
Change-Id: Ic67b94da213357af05a5c6e14e15946a02af7fba
2023-05-16 05:57:52 +00:00
Kyle Tso
55082ca17e usb: Temporarily disable compliance warning
Revert me once the issue is fixed.

Bug: 278018111
Change-Id: I198c4a42aa8b64fef90817474710295d68497dda
Signed-off-by: Kyle Tso <kyletso@google.com>
2023-04-22 10:03:27 +00:00
Roy Luo
fdb65f4d14 Support GL852G USB hub JK level tuning
The JK level setting is configured to the hub via a vendor USB
command whenever the hub is enabled.
The shell command can be used to change the JK setting for testing
purpose, but the values take effect next time the hub is enumerated.

Bug: 261923350
Test: adb shell cmd android.hardware.usb.IUsb/default hub-vendor-cmd
<hex wValue> <hex wIndex>
Test: verify on user/userdebug builds the vendor command is triggered
      in the following scenarios.
      1. boot with Kolan docked
      2. undock and dock Kolan
      3. kill android.hardware.usb.IUsb/default

Change-Id: I8873695c42f362138d99b45ffa2ef637c357202b
2023-04-06 01:54:13 +00:00
Badhri Jagan Sridharan
1e3b4431f4 Usb: Update UsbDataStatus while being docked
Bug: 275150939
Change-Id: I09499642012c7e95bb5a5fef1ac6eb7b8c4e6832
Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
2023-03-27 05:57:47 +00:00
Chien Kun Niu
d72768a1fe usb: hal: add all the i2c nodes for tcpc functions
This change is to add all the possible i2c nodes for tcpc functions with the correct permission, due to the path may change with different android version.

Bug: 273391794
Test: limit 1.3A work when connect to Head Unit
Change-Id: Iefb44f37c5b42ae5579e928477efc927d270b724
2023-03-21 05:14:41 +00:00
Xiang Wang
59332ea7e9 Move thermal utils to hardware/interfaces
Bug: b/269370789
Test: m
Change-Id: If7628b88a0b5a8d933dd0431eac2d3663649e834
Merged-In: If7628b88a0b5a8d933dd0431eac2d3663649e834
2023-02-23 04:29:33 +00:00
Badhri Jagan Sridharan
7c2d62aafc Usb: Set connected status when connected to non compliant port partners
Set mode, power role and data role when connected to non compliant
port partners.

Bug: 268584498
Change-Id: I6c3e7df09a61e26f3b976a86bd65cb646edd653d
Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
2023-02-22 22:05:43 +00:00
RD Babiera
fb37a2a183 Usb non-compliant port partner gs201 implementation
Adds vendor code for non-compliant charger feature. Currently
updates service version.

Minor port of  commit 96ccf93453583642a15dd96b1e4d6bf0645fc10b

Test: atest VtsAidlUsbTargetTest
Bug: 236322506
Change-Id: Ie1a48b1acaaae9a53f3b9bfebcfee7a2f4814810
(cherry picked from commit 96ccf93453583642a15dd96b1e4d6bf0645fc10b)
2023-02-22 22:05:43 +00:00
Xiang Wang
5f6267c0b0 Update USB HAL clients to use Thermal stable AIDL
Bug: b/264594715
Test: boot test
Change-Id: I2ff6095e8ea6f0c5cc48b303585b65acc8a14f53
2023-02-14 22:24:23 +00:00
Roy Luo
4e38e3b8c3 Add shell command to send vendor command to GL852G
Bug: 261923350
Test: adb shell cmd android.hardware.usb.IUsb/default hub-vendor-cmd
<hex wValue> <hex wIndex>
Change-Id: I83b56d28cfd89dfaf51fce88f97020196402f972
Signed-off-by: Roy Luo <royluo@google.com>
2023-02-14 20:31:24 +00:00
Ricky Niu
f14cbd6370 Add resetCb
Add the resetCb to complete asynchronous

Bug: 267252826
Test: Boot to home and function work
Change-Id: I9d6624cbe15c86c63e28f8f176d7c560aed8446f
2023-02-09 02:02:50 +00:00
Ricky Niu
5c7e338667 Fix up open bugs from gs201 AIDL migration
1. Remove unused group "wakelock".
2. Correct the right return value on setCurrentUsbFunctions.

Bug: 266694076
Test: Boot to home and function work
Change-Id: If0925a61e481e4deca560dc8dfc1be80a76c148f
2023-02-07 08:55:20 +00:00
Avichal Rakesh
72dbe87c42 UsbGadget: Add support for UVC function
UVC is a new USB function supported in Android. This CL adds UVC as a
valid function and gives it a new pid of 0x4ee[de]. UVC function is
guarded by the property `ro.usb.uvc.enabled`. When this property is set
to false, UVC won't be considered as a valid gadget function.

Bug: 242344221
Test: Manually tested that the UVC function is successfully configured
Change-Id: I7ce1cc192c09b5f3cd7c73405fe54426a1311dfb
2023-02-06 21:20:59 +00:00
Avichal Rakesh
9ba92eed60 Migrate IUsbGadget implementation to AIDL
This change migrates IUsbGadget implementation to AIDL.
Port of commit <d6d0b7d2ca5066988ee90889dccd00c06d64b694>.

Bug: 218791946
Test: USB function switch success and AIDL service is running.
Change-Id: I9613178d3cd2f9abd5396e4af763a257a8ef62a7
2023-01-26 20:18:09 +00:00
Badhri Jagan Sridharan
694c890c33 Rename enable_usb dev node to move_data_to_usb
kernel dev attribute has now been renamed from enable_usb
to move_data_to_usb. Update the same.

Bug: 251381400
Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
Change-Id: I8e4aa0b2e09bfef807f0169eabb79e2fa2e4d2c7
2022-10-31 14:07:51 +00:00
Kyle Tso
d0c6349927 usb: Modify the permission of additional i2c-max77759tcpc path
Bug: 251106770
Signed-off-by: Kyle Tso <kyletso@google.com>
Change-Id: I8b9dcc4b3de7b390f752ee410022dd0d86be9c40
2022-10-11 05:48:54 +00:00
Ray Chi
bfb57fd23f usb: remove redundant changes for USB nodes
Bug: 248982089
Test: build pass
Change-Id: Ic93017c26aada15cb04fc2d5cbeb9c9b07c999fa
2022-09-30 08:35:05 +00:00
Kyle Tso
a83716ff8d usb: Remove the permission change of unused nodes
Bug: 248982089
Signed-off-by: Kyle Tso <kyletso@google.com>
Change-Id: I4707e3bbd7fa1d42e08577edba8d9bb52cc7c061
2022-09-30 08:35:05 +00:00
badhri
7d34263bf9 Set powerBrickStatus to not connected when sourcing power
Bug: 239755044
Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
Change-Id: I7720bfaa5876c058643c52525b488ba22b3e5121
2022-07-22 02:31:35 +00:00
Ricky Niu
6d0bb7f43d usb: Correct the i2c path
Correct the I2C path to match the new memory address setting.

Test: Connect to HU work
Bug: 233996502

Signed-off-by: Ricky Niu <rickyniu@google.com>
Change-Id: I27cca56698568e8a3060d9e40bad3a29ec072588
2022-05-30 03:06:56 +00:00
Jimmy Hu
3b1583d7a5 Write the pullup value only if new value applied
Bug: 226018845
Test: build, boot
Signed-off-by: Jimmy Hu <hhhuuu@google.com>
Change-Id: I636dc18dca123f88dbf10c4a17caa9a75cbb12f7
2022-05-26 02:42:33 +00:00
Ricky Niu
0eefbf303b usb: limit the current to 1.3A when connect to accessory am: e6cacbcff2
Original change: https://googleplex-android-review.googlesource.com/c/device/google/gs201/+/18527913

Change-Id: I33790e25c4d57d2af41492f2f263c8124ea2ebf3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-05-24 01:01:25 +00:00
Ricky Niu
e6cacbcff2 usb: limit the current to 1.3A when connect to accessory
For imporve USB stability, limit the current to 1.3A,
when connect to accessory.

Bug: 206635552
Signed-off-by: Ricky Niu <rickyniu@google.com>
Change-Id: I2c1091aa7111e6242cc949923fbc86f27e54e976
2022-05-23 23:59:44 +00:00
Ray Chi
ee5795e850 usb: change function sequence if debug functions are enabled
On Windows platforms, wrong function sequnce will cause usb
driver installing not working. This patch will modify the
function sequence when debug functions are enabled.

Bug: 228800277
Test: tethering is working when debug functions are enabled.
Change-Id: I9f8b02354617b08a34fb4641ac710f32dabc643e
2022-04-14 03:59:15 +00:00