Commit Graph

663 Commits

Author SHA1 Message Date
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
Eric Laurent
01f03c3d9f Revert "Add support for USB audio docks."
Revert submission 16691170-usb_doc

Reason for revert: 216248574
Reverted Changes:
I090e86b2e:Add support for USB audio docks.
I461661dd4:audio policy: implement routing policy for USB doc...

Change-Id: Ie28b74de7b8654cd199c86d06697bb52f0fa8f3d
2022-01-25 15:28:18 +00:00
Nathalie Le Clair
517a1327ca Add AudioDeviceAttributes as argument to AudioManager API
NoNonSdkCheck: This CL changes the arguments of an existing API that was
annotated already.
Bug: 199846845
Test: atest AidlConversionUnitTests

Change-Id: I90a24c0428d9c77ccd45dff65bbdad198aa81fb2
2022-01-25 08:00:59 +00:00
Ricky Niu
476cd2e3ca Support USB Port Reset
Verify the USB Gadget HAL already implement.

Bug: 197300598
Test: Verify the API working manually

Signed-off-by: Ricky Niu <rickyniu@google.com>
Change-Id: I8a4a4966237c925c87b32f74a382b7a56f82ab7d
2022-01-25 12:01:34 +08:00
Badhri Jagan Sridharan
d368d4ee67 Merge "Add systemApis to allow data transfer over USB-C while being docked" 2022-01-24 19:19:25 +00:00
Badhri Jagan Sridharan
7212c8fda4 Add systemApis to allow data transfer over USB-C while being docked
This change adds two systemApis to UsbPortStatus viz.,
a. getUsbDataStatus: Allows caller to infer whether USB data is enabled.
b. getPowerBrickStatus: Allows caller to infer whether a power brick
                        is connected to the USB port.

The change also adds enableUsbDataWhileDocked systemApi to UsbPort to
enable Usb data momentarily.

Bug: 211677613
Bug: 213312081
Test: Manually tested on tablet
CTS-Coverage-Bug: 215019881
Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
Change-Id: Ib7521f0f04b7f8e3e58dc253b28072d3631f21a7
2022-01-24 21:30:05 +08:00
Eric Laurent
846944e91e Merge "Add support for USB audio docks." 2022-01-24 12:30:31 +00:00
Eric Laurent
9b2b85c2bf Add support for USB audio docks.
Associate Android device type DEVICE_OUT_DGTL_DOCK_HEADSET with a UAC
peripheral with terminal type 0x602 to allow specific audio policy for
docking stations with speaker and USB connectivity.

Bug: 197584191
Test: make
Change-Id: I090e86b2e3e7666f3978ef904a922b040bcb44e4
2022-01-24 08:35:45 +00:00
Badhri Jagan Sridharan
da433c60c1 Merge changes from topics "199357330", "200993386"
* changes:
  Add limitPowerTransfer SystemAPI to UsbPort
  Support IUsb AIDL interface
2022-01-22 01:20:21 +00:00
Badhri Jagan Sridharan
bdbb2d15be Add limitPowerTransfer SystemAPI to UsbPort
limitPowerTransfer when invoked limits the power transfer
in and out of the USB port. limitPortTransfer is deactivated
either when limitPowerTransfer is deactivated by the caller
or when Usb disconnect event is observed by the Usb service.

limitPowerTransfer API is asynchronous and the caller gets
notified by invoking UsbOperationCallback.onUsbOperationComplete
callback to notify the status of the operation.

USB_PORT_CHANGED event is broadcasted when port's limitPowerTransfer
status changes. UsbPortStatus object is updated to reflect the
current status.

limitPowerTransfer is protected by android.permission.MANAGE_USB.

Bug: 199357330
Bug: 199358576
Test: Tested on Pixel
CTS-Coverage-Bug: 215019881
Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
Change-Id: Iabd1187f7527e14ed758abe355ba94a511d8c859
2022-01-21 16:06:04 +08:00
Badhri Jagan Sridharan
bbfa92e694 Support IUsb AIDL interface
UsbPortManager is made to support both AIDL & HIDL interface until
HIDL is deprecated eventually. UsbPortHal abstract class is defined
which the UsbPortManager grabs an instance of from UsbPortHalInstance
method to talk to the Hal implementation process. UsbPortHalInstance
queries the underlying hal implementation and instantiates UsbPortHal
with either UsbPortHidl or UsbPortAidl based on the IUsb interface
implemented by HAL implementation.

go/iusb-aidl-migrate.

Bug: 200993386
Bug: 199357330
Bug: 211677613
Bug: 213312081
Bug: 199358576
Test: Manually tested through UI.
CTS-Coverage-Bug: 215019881
Change-Id: I246fd6e5bee8138d3ad3b6994665a1d4788c8789
2022-01-21 16:04:33 +08:00
Robert Wu
008fcbd18c Merge "Add MIDI 2.0 host mode support" 2022-01-20 16:57:28 +00:00
Robert Wu
a936a25198 Add MIDI 2.0 host mode support
Adding MIDI 2.0 host mode support to Android. MIDI 2.0 peripherals
create an alternative setting for Universal Midi Packets (UMP).
UMP packets can be passed directly through as the host has full
control. Instead of going through the ALSA, UMP packets can be
sent directly through a UsbDeviceConnection.

This CL also adds public apis to expose whether the pipe supports
UMP. This for MidiDeviceInfo in Java and AMidi in c++.

Bug: 201003646
Bug: 214447324
Test: Verified that the MIDI 1.0 path still works as before.
Test: Tested that MIDI 2.0 packets are passed through the pipe
with MIDIScope and MIDIKeyboard
Test: atest MidiSoloTest
Test: atest CtsMidiTestCases
Test: NativeMidiEchoTest

Change-Id: Idff8a3b9bdd05857239260fc3e6af7253f8f992f
2022-01-20 00:50:41 +00:00
TreeHugger Robot
5fbbac520f Merge "USB: Adjust exception message in dealing with permission check #3" into sc-v2-dev am: ebe7d4996e am: 6008fe7995
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16240998

Change-Id: Iafde993260e85c53382726b2130f9c933fb7f453
2022-01-07 23:02:25 +00:00
TreeHugger Robot
6008fe7995 Merge "USB: Adjust exception message in dealing with permission check #3" into sc-v2-dev am: ebe7d4996e
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16240998

Change-Id: Id638e7e62599f06bbdecf5ff16d650a1f99dc348
2022-01-07 22:40:30 +00:00