There is a situation that getCurrentUsbFunctions callback function will
be invoked before mCurrentUsbFunctionsRequested flag updated, thus, gadget
will be reset during boot completed. Make sure mCurrentUsbFunctionsRequested
flag be updated before getCurrentUsbFunctions callback function invoked.
Bug: 119688133
Test: Verified that gadget reset does not happen
Change-Id: Id8b58d9ccd3f62c976d1292575a06554bef622a4
Merged-In: Id8b58d9ccd3f62c976d1292575a06554bef622a4
Signed-off-by: Howard Yen <howardyen@google.com>
This reverts commit 2473b08b07.
Reason for revert: Fixed build breakage
sysprop_cpp and sysprop_java directly have been linking against
libprotobuf-cpp-full and do not set proto.type field, which could
cause ASAN error due to linking against both libproto version of full
and lite.
Change-Id: I96eb47444d7b6f6b5fef092efc1514fcdd6f33b6
Merged-In: I8e04f643197b6c8a60cc38c6979e41c5de3469f5
Properties accessed across partitions are now schematized and will
become APIs to make explicit interfaces among partitions.
Bug: 117924132
Test: m -j
Change-Id: I8e04f643197b6c8a60cc38c6979e41c5de3469f5
Merged-In: I8e04f643197b6c8a60cc38c6979e41c5de3469f5
STORAGE_SERVICE is not ready or not available to use.
UsbDeviceManager will get null value and cause null object
reference exception. Check return value before use.
Test: No exception when start USBService
Change-Id: Icdbc532894d3ca1548f327d9f63d495baa549c68
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>
UsbDescriptorParser::parseDescriptors always returned true.
Remove the return value, and remove the one constructor that
doesn't parse descriptors so the device is always in a parsed state.
Bug: 74119682
Test: Built
Change-Id: I2dd8d439405867d78102a9591dd1db36fe3959dc
The current model for setting up a functionfs
function is:
UsbDeviceManager#setCurrentFunctions() ->
intent is sent to MtpReceiver to write the descriptors ->
init/hal waits for descriptors to write, then pulls up gadget ->
Gadget is configured, a USB_STATE intent starts MtpServer
The main downside of this is a lack of reliability because
the Mtp process could be killed at any point. Normally, a
gadget is unbound if its control endpoint is closed. no_disconnect
works around this, but is still a little janky. In addition, the
extra intent delays the startup of the gadget.
With the new model, UsbDeviceManager writes the descriptors
on initialization. Since it is a system service, it won't be killed.
UsbDeviceManager#setCurrentFunctions() ->
init/hal pulls up gadget ->
Gadget is configured, a USB_STATE intent starts MtpServer
MtpServer calls UsbManager#getControlFd to get a dup of the control
endpoint.
Also modify permissions so system server can access mtp files.
Bug: 72877174
Test: Change usb configurations to ptp/mtp
Change-Id: Id17d2b5930f4e1f37ec1b4f00add9d594174ad49
Since the callbacks are async, its possible that the callback gets
called before the systemReady flag is set.
Change-Id: I5752c097e25ef30a151461540dd7d5323cc927af
Terminal type is currently used to determine presence of audio input
or output capabilities on audio devices.
Broaden the set of terminal types accepted as inputs and outputs.
Test: Verified by playing with USB-C to 3.5mm adapter with
high impedance load, checked Terminal type reported as 0x0603.
Verified no audio on old build, audio on new build.
Checked with low impedance load with and without microphone.
Checked with no load.
Bug: 73813676
Change-Id: Ib9b291e4770dc3c03157df7ac4277da1692174d7
Since adb is being removed from the functions read
from sys.usb.config anyway, it makes more sense to
set it to NONE on boot. This prevents errors with
devices that already have oem functions in the config.
Bug: 73010922
Test: Power test passes
Change-Id: I855ba228dbdd9f8c8a91842a8beb68a789fdf1e9
Keep track of the currently selected UsbAlsaDevice in a
synchronized manner.
Allow it to notify AudioService that it has been disabled
prior to replacing it with a new Audio Device.
Test: verified audio worked as expected when using
both UAC2 and non-UAC2 3.5mm adapters, with 3.5mm
plugging/unplugging and USB-C plugging/unplugging.
Change-Id: I8b76145490da38d4eec25f4f2bdb6695afa151b9
Adds support for ALSA jack detection for USB.
Spawns a new thread for ALSA jack detection on device
insert. If the device doesn't support ALSA jack detection,
the thread terminates.
Test: UAC2 audio accessory and a kernel
which supports USB ALSA Jack detection, switching between
speaker and USB works perfectly with plug/unplug at jack.
Bug: 68337205
Bug: 70632415
Change-Id: I1800660ad4d2341f19ce7be6d6b01f81a7f2d1a6
If onRegistration is called before functions
are received, adb can be kicked on boot. To fix,
don't set functions if they are still being
requested.
Bug: 73168456
Test: adb logcat doesn't dc
Change-Id: I25bfe13604f0ce0c65c3eb82bcfafd9fcae0283f
Synchronize external access to UsbAlsaDevice fields.
Rename all playback fields to output, capture to input.
Move Alsa Device String generation to UsbAlsaDevice.
Test: Used Google Play Music to test audio output while
inserting & removing USB audio devices.
Bug: 68337205
Bug: 70632415
Change-Id: I77d413736253e28a33993f45e6e405209563f3e4
Add @GuardedBy for simple functions that require a single lock
and are named XYZLocked.
Derived by errorprone.
Bug: 73000847
Test: m
Test: m javac-check-framework RUN_ERROR_PRONE=true
Change-Id: Id1d9fbe5018250e3b9d1466fc5f670d5ad902fa3
This allows to dump the USB state as proto-buf. This in turn allows to
automatically process this data.
Test: adb shell dumpsys usb
incident_report usb
No automated test possible as no field is guaranteed to be set
Change-Id: Ifdf22bfaf9c78226c420b11c43278013ce69f849
Prevents crashes / loss of behavior when
user 0 is locked, but another user is
unlocked.
Bug: 72662661
Test: have lock on user 0, reboot, switch to and unlock user 10
Change-Id: I72767fc4726d3b316266a1499dbe51bd7d9830bc
Devices like bat still have oem functions
in the persist prop, so don't throw errors.
Test: device boots
Bug: 72765363
Change-Id: I7d1e334d7cafb1ba1f328ee4160da3b098f76fa1
New metrics constant and usb strings for the new
notification / details page.
Bug: 69333961
Test: Check notification
Change-Id: If9bde7f787e40e42bb991a99b032e1ff968a0a41
Change UsbManager apis to use long instead of string, to match
usb hal. Change UsbDeviceManager internals to match as well.
Remove isFunctionEnabled and add getEnabledFunctions. Callers
would often call isFunctionEnabled for every possible function
to get the list of functions, so getEnabledFunctions reduces the
number of aidl calls.
Separate out dependencies between UsbHandler and UsbDeviceManager
and staticize the UsbHandler classes. Add unit tests with
mocked out dependencies to test state transitions for UsbHandler.
Bug: 62876645
Test: atest UsbTests
Change-Id: I785c4c24121a70e725de9742c6af50a6bf1baea0
Tuned rates that we collect PSS, to reduce how much we do
that heavy operation. Added a new way to determine
whether a process has changed to a state for the
"first" time -- now this is when it has gone to that
state for the first time since it was in a lower state.
This will reduce the amount of time we consider a
process to be first to only when it has previously
gone into a higher state than it had before.
Keep track of more fine-grained information about why we
collect a PSS sample (not just internal, but for a single
process, all processes because of a mem state change, all
processes because of a poll).
Started collecting RSS in various places, so we can start
looking at that w.r.t. PSS and see about transitioning to
it is a new primary metric.
Added logging for many of the places where the system
writes its configuration files, so we can more easily
see any bad behavior going on in those areas.
Added some currently disabled code to read smaps directly
instead of using fgets(). Probably won't help, but want
tot test.
Bug: 70859548
Test: atest CtsAppTestCases
Change-Id: I400dba0f3ae9c024df51c946cfa592561028b598
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
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
Cherry-pick from 30b9adfad1
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
Cherry-pick from 83a0d6fa57
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
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
Also added tracing to android.UsbDevice creation.
Test: Try each dump command with CALYX Pat USB DAC & Dragonfly Red USB DAC
Change-Id: I2ec05dfa9c544d0c50ee59e3b990e9010cbe0aa0
Devices - Skylab, Mir, HTC dongle, Presonus AudioBox 44VSL, HP mouse
Hard coded class ID of 0xFF and subclass 0xFD to match b/68944518 symptoms.
Bug: 68944518
Test: Manual - see above
Change-Id: I7330c57b15278158a2eb449f0463b91244a3e176
Any USB devices that are of class VIDEO or have similar
interfaces should check whether the calling client has
camera permissions before granting access to the device.
The above restriction will apply for any packages that
target P or above.
Bug: 27367690
Test: Manual using 3-rd party USB webcam applications.
Change-Id: I7b4f808d344cae33fde93e6d81c7cceed523e24a
This reverts commit 513160fd80.
Bug: 68944518
Bug: 68008691
Bug: 68337205
Test: USB connection to audio device and laptop
Change-Id: If9223aae953581b2f2e3a6b1adf174528aa94132
Each USB device can have one default handler. This app is launched when
the device is plugged in. A default handler automatically gets
permission to access the device when launched.
All other apps have to request the permission to access the USB device
via UsbManager.requestPermission. In the permission dialog there is an
option to make the app the default app for the device. Of course this
only makes sense if this app declares the right properties to be
auto-launched. Hence check this and only then show this options.
Also made the string in the dialogs easier to understand.
AccessoryFilter and DeviceFilter needed to be copied so I can access
them from system-ui. No code change in these classes.
Test: requested permissions from app that could by the default for the
device and from an app that could not. Also tested "confirm" flow
that is executed when the device is plugged in and a app that
might be default is installed.
Bug: 67381583
Change-Id: I12eb7efed0ad107c70ae32433a5629108f252486
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