Commit Graph

677 Commits

Author SHA1 Message Date
Alex Dadukin
ba6d3a2681 Migrate UsbDeviceLogger to EventLogger
It looks like UsbDeviceLogger is a fork of EventLogger,
therefore it would be better to deduplicate it.

Bug: b/254234346
Test: N/A
Change-Id: I20da7bb0bbf83888f4c448742326a3cb54462a4d
2022-11-01 18:14:51 +00:00
Hai Zhang
e55b8eeb28 Move TypedXml{Parser,Serializer} to modules utils package.
A subsequent change will actually move the files to the other git
project.

Bug: 243194720
Test: presubmit
Change-Id: If126bb68f74852528c4da8df79831b49b5129983
2022-10-21 04:28:13 -07:00
Robert Wu
8c7028e838 USB MIDI: Extend bulkTransfer timeout
If a UsbDeviceConnection is used both for sending and receiving data,
bulkTransfer may time out.

The solution is to extend the timeout from 10ms to a second.

Also, we need to split the packet into multiple packets if they are
greater than the endpoint's max packet size. Linux would do this for
us, but with the new retry code, we may be sending some parts of the
packet multiple times otherwise.

This is because if Linux would split the packet into 3 packets and
only the third packet fails, the first and second packets would resend
if we don't split the packets.

Bug: 250616636
Bug: 251551233
Change-Id: Ic4dc2d4434731d34b26b0e073221e4ef5ebbd920
Test: CTS Verifier MIDI tests
2022-10-13 17:11:12 +00:00
Khoa Hong
a13e37793f Show charging notification when device is being charged via USB, with USB data disabled.
Bug: 239184431
Test: Use TestDPC to enroll device and disable USB data, then verify that the behavior of charging notifications is identical to another phone with USB data enabled:
 - Notification shows up when connecting to laptop, another phone before/after power swap.
 - Notification does not show up when connecting to a wall charger.

Change-Id: I016f65dcdd478d3429efe871bf99aee2f1653c45
2022-09-07 08:56:07 +00:00
Robert Wu
e5f330f8fd MIDI: Power Boost when MIDI hardware sends data
When USB MIDI hardware sends bytes to Android, Android should set
power boost as if an interaction event just happened.

This change reduces the number of audio underruns.

Bug: 122678281
Test: Connect Akai MIDI USB Keyboard to MIDI Synth Ex
Test: Connect another Android phone as host to MIDI Synth Ex
Test: Collect perfetto traces and verify a difference
Change-Id: Ic95283813beb16e55d941f85f876124afa2f2794
2022-09-01 22:22:44 +00:00
Jimmy Hu
989e4d30a0 Merge "usb: Don't show the notification when no USB device is connected" 2022-08-11 02:40:25 +00:00
RD Babiera
e61d7fbd91 Merge "Swap hal query order" into tm-qpr-dev am: 4c5ec9874c am: 78bf1dade5
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19533073

Change-Id: I81be0f07d6a9a595bfedb982d25f88fb9895238c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2022-08-09 01:39:02 +00:00
Jimmy Hu
eae5eacdd6 usb: Don't show the notification when no USB device is connected
Currently, the "Charging connected device via USB" notification appears
and then disappears when a USB device is disconnected. The notification
should not appear when no USB device is connected. This CL prevents
this.

Also prevents the notification from showing up when a mouse is
connected.

Bug: 234548453
Test: Peripheral mode, host mode, and Power/Data role swap
Signed-off-by: Jimmy Hu <hhhuuu@google.com>
Change-Id: Ie4c67c639d8633361e5a3675502283cae4e35bd9
2022-08-08 08:00:21 +00:00
RD
86813d40d7 Swap hal query order
USBPortManager now checks for AIDL post-migration, stops redundant error message for HIDL checks

Bug: 241042174
Test: Checked to see USBPortManager Error no longer present in System Logcat after order swap
Change-Id: I4f0092a68e0cc0dd42dcf2d16f4cdfa646cb72f4
2022-08-04 22:28:44 +00:00
Hani Kazmi
4f221e5c51 Migrate Bundle/Intent APIs to new, type checked, variants
Part of go/safer-parcel. Follow up to ag/16639043. Migrates the following unsafe APIs:

* Parcel.readArray()
* Parcel.readParcelableArray()
* Bundle.getSerializable()
* Bundle.getParcelable()
* Bundle.getParcelableArrayList()
* Bundle.getParcelableArray()
* Bundle.getSparseParcelableArray()
* Intent.getSerializableExtra()
* Intent.getParcelableExtra()
* Intent.getParcelableArrayExtra()
* Intent.getParcelableArrayListExtra

Bug: 227458983
Test: m and presubmit pass
Change-Id: I72f206cb18eb5c669a7fff07a6845bed1c433fdb
2022-07-01 10:53:53 +00:00
jiabin
89d0c84990 Update logic for determining if an USB device is a headset or not.
Update the function of calculating likelihood of being an output
headset.
1. Change the function name from probability to likelihood. It is fine
   to have the value be negative or greater than 1.0f.
2. If there is an output terminal with type as HEADPHONES or
   BIDIR_HEADSET, likelihood += 0.75, goto 5. Otherwise, goto 2.
3. If there is an output terminal with type as SPEAKER,
   likelihood += 0.5. Goto 3.
4. If there is associated input terminal for an output terminal exists,
   likelihood += 0.25. Goto 4.
5. If multiple channels are supported, likelihood -= 0.25. Goto 5.
6. If there is an output terminal with type as SPEAKER, HEADPHONES or
   BIDIR_HEADSET and there is HID interface, likelihood += 0.25.

Test: connect USB devices and check the reported device type.
Bug: 231973571
Change-Id: I98e433b5333f8bb317b6ae89bd65fee2c42236eb
2022-06-22 16:24:48 +00:00
Robert Wu
f0acf2884f Merge "USB MIDI: Only use first USB Configuration" into tm-dev 2022-06-09 03:45:12 +00:00
Robert Wu
186b9e447b USB MIDI: Reset counter after unique codes full
Some tests continously plug and unplug MIDI devices.
After 1000 operations, there is an infinite while loop.

This CL clears up the hashset if it is nearly full.

Bug: 234688233
Test: Plug and unplug MIDI devices
Change-Id: Ie0c6359c07694e3f6cc4a3011fd39a525314ab94
2022-06-03 22:22:45 +00:00
Robert Wu
9043a28e0c USB MIDI: Only use first USB Configuration
The parser returns USB descriptors for multiple configurations.
Only one configuration should be used at once.
The first configuration is the default config.

Bug: 234607936
Bug: 223316278
Test: CTS Verifier on AudioBox 96
Test: MIDI Scope on MIDI 2.0 device
Change-Id: I9169faa2ea5cf9fd516834f7802963245762e74b
2022-06-02 23:01:09 +00:00
Robert Wu
5aec766419 USB MIDI: Null check for mUsbMidiPacketConverter
Add null checks for mUsbMidiPacketConverter and
other variables inside input/output threads.

Also adding a NullPointerException catch for more
protection.

Also changing a timeout from 50ms to 200ms.

Bug: 233409535
Test: MidiScope and MidiKeyboard for MIDI 1.0/2.0
Change-Id: Ib73060d05ba8cbad9ab9b4d0e37a892d8916c0d9
2022-05-23 02:03:23 +00:00
Robert Wu
6cd937c488 USB MIDI: Use Thread.interrupt() to close threads
We start input threads before setting mIsOpen.
This means that sometimes, input threads immediately exit
due to a race condition.

The fix here is to remove the use of mIsOpen and use a new
mechanism with Thread.interrupt() and Thread.interrupted()
to mark a thread to be closed.

Bug: 223316278
Test: MidiScope/MidiKeyboard
Test: CTS Verifier Bluetooth Tests
Change-Id: I7c221504ae8a8814c1aa5598552494c80c202eb2
2022-05-19 16:01:52 +00:00
Robert Wu
5a5ccbe0f2 Merge "USB MIDI: Don't call openLocked on device unplug" into tm-dev 2022-05-13 14:25:26 +00:00
Robert Wu
139be68185 USB MIDI: Don't call openLocked on device unplug
When a USB MIDI device with multiple ports is
unplugged, onDeviceStatusChanged gets called
multiple times. The first time ends up opening a
port since there are still other open ports.

The fix here is to ignore onDeviceStatusChanged()
if close() was called before.

Also changed a continue to a break since that
condition almost never gets hit.

Bug: 232142589
Bug: 231496864
Test: Midi Keyboard that opens both input and output
for both peripheral and host mode

Change-Id: I973d55371cd16803ede192081531ca5f59847a51
2022-05-12 22:05:34 +00:00
Robert Wu
0656f1c02a Merge "USB MIDI: Replace bulkTransfer with requestWait" into tm-dev 2022-05-10 17:53:49 +00:00
Robert Wu
9228e50119 USB MIDI: Replace bulkTransfer with requestWait
When getting data from a device, bulkTransfer loses
~1-2% of data. The recommended approach is to use
requestWait as done in this CL.

This method also lets us remove a lock. Removing
this lock speeds up initialization, fixing a timeout
bug with CTS Verifier.

Also add a null check for UsbDeviceConnection

Bug: 231496864
Bug: 223316278
Bug: 231973034

Test: MidiKeyboard/MidiSynth to multiple keyboards
Test: CTS Verifier with AudioBox USB96

Change-Id: Ib841fd0b092e93ac5fdb7a65221ec5c2958f6171
2022-05-09 17:14:04 +00:00
Ricky Niu
37ffba8d74 usb: Add the boot completed check before broadcasting intent
Broadcasting intent is not allowed before boot completed.
Check if boot completed to broadcast accessory time out
intent to avoid exception.

Bug:229387375
Test: Reboot with head unit connected

Signed-off-by: Ricky Niu <rickyniu@google.com>
Change-Id: I34bc7625bbcb9525ad25cb1538ed4138fcae8ead
2022-04-21 10:34:32 +00:00
TreeHugger Robot
b45f0e8ac6 Merge "Add MIDI info to USB dumpsys" into tm-dev 2022-04-20 01:13:19 +00:00
Robert Wu
b83ae06adf Add MIDI info to USB dumpsys
Adding MIDI info to USB dumpsys so developers can debug better.

Bug: 229122603
Test: adb shell dumpsys usb
Change-Id: Ic3c7ab21865457b1e1f0f97fdd1827bb0b442481
2022-04-14 01:57:04 +00:00
TreeHugger Robot
eb1eb03859 Merge "usb: Fixed the null pointer issue" into tm-dev 2022-04-13 08:12:14 +00:00
Ricky Niu
975608fa09 usb: Fixed the null pointer issue
Bug: 200323450
Test: Function work with reboot connect to PC and HU

Signed-off-by: Ricky Niu <rickyniu@google.com>
Change-Id: I9bdfcda195c30d71d9d39e1170bbf66a7021c39b
2022-04-12 11:27:29 +00:00
Steven Moreland
1b46333208 Implement getInterfaceHash/Version (USB)
As these interfaces get frozen, java services
implementing the interfaces are required to implement getInterfaceHash
and getInterfaceVersion [1]

[1]
https://source.android.com/devices/architecture/aidl/stable-aidl#new-meta-interface-methods

Bug: 190577319
Test: m
Change-Id: I00ced32a26fd1af7bc8cc23749d92ae90d5a5a0f
2022-04-04 22:11:35 +00:00
Ricky Niu
dc74aff111 Asynchronous the resetUsbPort
Modify the resetUsbPort be asynchronous

Bug: 217369748
Signed-off-by: Ricky Niu <rickyniu@google.com>
Change-Id: I5d799691f2f3fce4df97a960c8628194236d9f81
2022-04-01 18:13:32 +00:00
James Wei
06626cef7a USB: Increase debounce time for DISCONNECT processing (revised)
Original patch: aosp/1539944

Bug: 209342433
Test: See details in b/209342433
Change-Id: I7ff58a1a9755939ccb26dad61969902ec91f2225
Signed-off-by: James Wei <jameswei@google.com>
2022-03-25 15:35:15 +00:00
Robert Wu
8720291658 Merge "USB MIDI: Create encoder per output port" into tm-dev 2022-03-24 22:23:24 +00:00
Robert Wu
d338c3c8f8 USB MIDI: Create encoder per output port
UsbMidiEncoder is not thread-safe. Therefore, each output port
should use its own encoder.

Bug: 225884009
Test: MidiKeyboard/MidiScope on both MIDI 2.0 and MIDI 1.0 paths.
Test: Verified M-Audio Keyboard with only input has the correct logs.
Change-Id: I43bd7381982403766b7f37c22d55ef5d19013120
2022-03-24 16:42:25 +00:00
Ricky Niu
01f255bbf3 Correct the operationID in resetUsbPort
Fixed the operationID when the operationID collisions, create another key

Bug: 217369748
Signed-off-by: Ricky Niu <rickyniu@google.com>
Change-Id: I22126b4c04b5c92bc9fc9db7405e7ee9d2806b49
2022-03-22 13:41:02 +00:00
Robert Wu
b6a1953f21 USB MIDI: Add null check on device removal
In I0b86f9bd26e4c9a50576f704deb6b53fc9a5c130,
we introduced a bug by forgetting a null check.
This CL adds the null check back.

Bug: 223481435
Change-Id: I62e9b1135306b2d952f7fddace656a938545e74f
Test: MidiKeyboard/MidiScope
2022-03-18 17:38:21 +00:00
Treehugger Robot
4ed510e47a Merge "Avoid removing USB state changes during CONFIGURED uevent" am: 6b8b9efad1 am: da70fd1af3 am: a87ed3d36b
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1898830

Change-Id: I82b80ef0e935f8cafba2d3b9ec527b55cbde8e5a
2022-03-07 18:21:50 +00:00
Treehugger Robot
da70fd1af3 Merge "Avoid removing USB state changes during CONFIGURED uevent" am: 6b8b9efad1
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1898830

Change-Id: Ia1a792ea55cff7136c3dc133c4deb5caf7c96809
2022-03-07 17:26:54 +00:00
Treehugger Robot
6b8b9efad1 Merge "Avoid removing USB state changes during CONFIGURED uevent" 2022-03-07 17:11:26 +00:00
Paul Murphy
ea89c0e71d Allow apps with MANAGE_USB_STATE permission access to all USB
accessories.

Test: Manually tested
Bug: b/220200798
Change-Id: I8c574e18192a768a4a202acd891ec258c106deae
Merged-In: I8c574e18192a768a4a202acd891ec258c106deae
(cherry picked from commit e22c826cf2)
2022-02-28 17:36:18 +00:00
Robert Wu
ec3e6791f4 Merge "Rewrite MIDI 1.0 USB Host mode in Java" 2022-02-17 16:21:07 +00:00
Robert Wu
750a3496d5 Rewrite MIDI 1.0 USB Host mode in Java
ALSA has multiple bugs related to MIDI 1.0. This CL removes
Android's dependency on ALSA for MIDI 1.0 USB Host mode. MIDI to
USB MIDI conversion is done in UsbMidiPacketConverter.java

ALSA is still used for peripheral mode.

Bug: 217392573
Test: Ran local unit tests with UsbMidiPacketConverter
Test: MidiScope/MidiKeyboard with multiple MIDI keyboards
Change-Id: I0b86f9bd26e4c9a50576f704deb6b53fc9a5c130
2022-02-17 00:06:58 +00:00
Treehugger Robot
8a5e698aa1 Merge "Fix handling usb notification after pr_swap complete" am: b681fec035 am: d68e9ab715 am: 2ac83c4e47
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1984546

Change-Id: Ic6901932eaa7d410700be980dc37ae37621d24e6
2022-02-16 05:25:58 +00:00
Treehugger Robot
d68e9ab715 Merge "Fix handling usb notification after pr_swap complete" am: b681fec035
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1984546

Change-Id: I2df61f61b2ce2ff7934286e8e04d572f2042a523
2022-02-16 04:45:07 +00:00
Kevin Jeon
85a04c0b0f Merge "Annotate dump methods with @NeverCompile [5/5]" 2022-02-16 01:22:50 +00:00
Badhri Jagan Sridharan
9c80283f83 Convert @UsbDataStatus into bit field flags.
getUsbDataStatus now returns bit field values of @UsbDataStatus.

Also renaming from USB_DATA_STATUS_* to DATA_STATUS_* based on
review comments.

Bug: 216640242
Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
Change-Id: I96ade3dd7041a4094e57907069a872909a62e72f
2022-02-15 03:17:46 +00:00
Ray Chi
2424262814 Fix handling usb notification after pr_swap complete
After the device (USB host) finished the pr_swap and the power
role is changed from Source to Sink, the notification should be
updated with different messages. However, the notification may be
ignored since the charger type is not USB. Users may get
confused when the notification is gone.

If the peripheral device is still connected, UsbDeviceManager
should push new notification.

Bug: 212189038
Test: notification is updated
Change-Id: I772c8c06a1e3a8770d0bf132c5e8fdf313bb2685
2022-02-14 07:12:15 +00:00
Kevin Jeon
5e57f64c1b Annotate dump methods with @NeverCompile [5/5]
This change annotates dump/debug methods in services.odex that are
larger than 10000 bytes with NeverCompile so that they will not be
compiled. This results in an overall ~1% decrease in the size of
services.odex.

Bug: 215417388
Test: Build and check that these methods are not called during boot or
      app startup.
Change-Id: Ic14b273a66a30ad63ba9a82c0b45fac9beb7589a
2022-02-10 19:59:33 +00:00
Nathalie Le Clair
dbad339f5f Merge changes from topics "AudioDeviceAttributes_update", "ShortAudioDescriptors"
* changes:
  Inform AudioManager about ARC SADs
  Add AudioDeviceAttributes as argument to AudioManager API
  Add fields to AudioDeviceAttributes class
2022-02-04 14:11:19 +00:00
Robert Wu
19f083cda7 Merge "Don't call setInterface when querying protocol" 2022-01-27 19:30:59 +00:00
Robert Wu
4c6239b156 Don't call setInterface when querying protocol
calculateDefaultMidiProtocol() is a function that figures out the block
type of a specific MIDI device. This function is used whenever a MIDI 2.0
device is added.

Currently, connection.setInterface() is always called in this function.
When a different interface is set, the MIDI 1.0 interface in ALSA just stops.
/dev/snd/midiC1D0 is no longer exposed.

The solution in this CL is that Android should not call
connection.setInterface() until the MIDI 2.0 interface has opened. This
means that querying protocol on startup should not use setInterface.

This way, the MIDI 1.0 interface should work up until the MIDI 2.0
interface is actually used.

Bug: 216178160
Test: MidiScope and MidiKeyboard
Change-Id: I53d7792d6d331abcddea2d1aedb394ff4dee0a9c
2022-01-26 23:14:31 +00:00
Eric Laurent
c807bd2b19 Revert "Revert "Add support for USB audio docks.""
This reverts commit 01f03c3d9f.

Bug: 197584191
Test: make

Change-Id: I9eee0c20b663e590ba5c9400a8685015245ce80a
2022-01-26 11:44:41 +00:00
TreeHugger Robot
5d4ad0c22c Merge "Support USB Port Reset" 2022-01-26 08:13:08 +00:00
Eric Laurent
fd01586915 Merge "Revert "Add support for USB audio docks."" 2022-01-25 20:09:03 +00:00