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
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
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
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
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
Adding MIDI info to USB dumpsys so developers can debug better.
Bug: 229122603
Test: adb shell dumpsys usb
Change-Id: Ic3c7ab21865457b1e1f0f97fdd1827bb0b442481
Bug: 200323450
Test: Function work with reboot connect to PC and HU
Signed-off-by: Ricky Niu <rickyniu@google.com>
Change-Id: I9bdfcda195c30d71d9d39e1170bbf66a7021c39b
Original patch: aosp/1539944
Bug: 209342433
Test: See details in b/209342433
Change-Id: I7ff58a1a9755939ccb26dad61969902ec91f2225
Signed-off-by: James Wei <jameswei@google.com>
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
Fixed the operationID when the operationID collisions, create another key
Bug: 217369748
Signed-off-by: Ricky Niu <rickyniu@google.com>
Change-Id: I22126b4c04b5c92bc9fc9db7405e7ee9d2806b49
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
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
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
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
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
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
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
NoNonSdkCheck: This CL changes the arguments of an existing API that was
annotated already.
Bug: 199846845
Test: atest AidlConversionUnitTests
Change-Id: I90a24c0428d9c77ccd45dff65bbdad198aa81fb2
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
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
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
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
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
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