228 Commits

Author SHA1 Message Date
TreeHugger Robot
45c87d943d Merge "Enabling USB Debugging Connected notification on Android TV" 2017-02-02 21:57:28 +00:00
Dmitri Plotnikov
d7ee7d4b34 Enabling USB Debugging Connected notification on Android TV
Bug: 34859109
Test: verified that the notification showed up in LeanbackLauncher
Change-Id: I2d5798e994df74b7d3211ccf7f22a6aff44bd681
2017-02-02 10:24:27 -08:00
Badhri Jagan Sridharan
26b6130282 Check and send usb state broadcast when devices boots am: af6d473ab0 am: 061bceafee am: df1df40f91
am: 307a387f38

Change-Id: Icf4b4e4f48fea450b71bd7ccd88db7d089ea286e
2017-01-31 01:14:33 +00:00
Jerry Zhang
ed642e81b4 Only send usb disconnect intents after boot. am: c1bc0a844d am: dc9c094deb am: 9877c70d9d
am: 1064ee66d5

Change-Id: If501641b5a7cbb4264f40f3bcf2add35e0851f78
2017-01-31 01:13:20 +00:00
Badhri Jagan Sridharan
af6d473ab0 Check and send usb state broadcast when devices boots
Broadcasts are not sent until BOOT_COMPLETED is received.
When the device boots with usb plugged, the UPDATE_STATE
for connted and configured would be received way before
BOOT_COMPLETED is received. Since, devices can continue
to stay in same usb configuration(set through persistent
property trigger), check and send a usb state broadcast
if needed.

BUG: 34451258
Test: Manually checked to verify the broadcasts sent.
Change-Id: I8eca5f241ad758f5c4f1afa6c9807868dfd6195a
2017-01-31 00:41:49 +00:00
Jerry Zhang
c1bc0a844d Only send usb disconnect intents after boot.
This prevents cases where the device starts up and attempts
to change the config, but intents cannot yet be sent.

A patch to resend this skipped intent is necessary to
finish fixing the bug.

Bug: 34451258
Test: Check that usb state is properly handled on boot
Change-Id: I9d79c67ce8982fd5b43fa40781b66bb9ae820694
2017-01-30 14:34:57 -08:00
Badhri Jagan Sridharan
d979398983 Merge "Refactor UsbPortManager to use the binderised USB HAL" 2017-01-24 23:46:25 +00:00
Badhri Jagan Sridharan
823287d28e Refactor UsbPortManager to use the binderised USB HAL
Move to a USB HAL to handle type-c ports as upstream is
considering in merging a generic type-c interface to mainline
kernel. However, the new sysfs interface can see minor changes
in the future as the sysfs interface is sitll going to land
in testing and it is still under review.

Bug: 31015010
Test: Manually tested on Angler and sailfish for type-c role switches.
Change-Id: I26771074c4b4f79a133e519bc6d35a4864a696d8
2017-01-23 17:13:15 -08:00
Christopher Tate
4ca071da28 Send USB_STATE broadcast to manifest receivers
Bug 34594920

Change-Id: I5d026f469710960b792dcf1bfebc1c07f90c6182
2017-01-23 14:35:28 -08:00
Christopher Tate
42a386b771 Enable background restrictions
Apps that target O+ are always subject to background restrictions.
Legacy apps' background restriction is subject to the OP_RUN_IN_BACKGROUND
app op.

Apps with these properties are exempted from background restrictions:
  - persistent process
  - currently on the idle battery whitelist
  - global whitelist for things like bluetooth services

Bug 30953212

Change-Id: Icc19b2fbc05f40dcf8c3fc4abf718c373dc8d4f6
2017-01-19 16:23:02 -08:00
Chris Tate
9e83cbbc10 Revert "Enable background restrictions"
This reverts commit 21f778060badb1e78bffde05e8de7662d275003d.

Change-Id: I65586f9739da84fb32b51b0ea166b8288c41d1b3
2017-01-19 01:12:19 +00:00
Christopher Tate
21f778060b Enable background restrictions
Apps that target O+ are always subject to background restrictions.
Legacy apps' background restriction is subject to the OP_RUN_IN_BACKGROUND
app op.

Apps with these properties are exempted from background restrictions:
  - persistent process
  - currently on the idle battery whitelist
  - global whitelist for things like bluetooth services

Bug 30953212

Change-Id: Ib444829a2d222125f64ff19e8218823fa78373f9
2017-01-18 11:30:41 -08:00
David Stevens
1e87ae5c8e Merge "Exit accessory mode more aggressively" 2016-12-14 22:29:39 +00:00
David Stevens
4f9e88a4af Exit accessory mode more aggressively
The debouncing of USB disconnects means that the disconnect caused
by resetting the connection without unplugging the device does not make
it to the handler, and thus doesn't exit accessory mode. Therefore we
must exit accessory mode even for connect events after we have left the
entering accessory mode state.

Test: Manual testing with desktop head unit
Change-Id: Ia028ff28783fa777a9f8bcd86b523d01f633a140
2016-12-13 20:44:32 -08:00
Jerry Zhang
d9291d55f6 Merge "Modify UsbDeviceManager stack to allow MtpServer to use FunctionFS drivers." am: 1975240f17 am: 830874dbe7 am: 88672d7d29
am: 11dc0eccfb

Change-Id: Ibafebe4877052595cb34626bde9ac6fba1983fb0
2016-12-13 01:02:55 +00:00
Jerry Zhang
bb598ee16f Modify UsbDeviceManager stack to allow MtpServer to use FunctionFS drivers.
Functionfs requires MtpServer to write descriptors before the device can be
configured. This adds a new configure call that will occur only when
functions are changed (new argument added to updateUsbStateBroadcast for this)
and be called after sys.usb.config is changed but before the waitForState
call to ensure compatibility with configfs devices.

Bug: 30976142
Change-Id: I7e94a5847d3b19c0fd75139e1b15a3f2a1cea01d
Test: Manual
2016-12-12 11:05:32 -08:00
David Stevens
049c718684 Exit accessory mode after debounce timeout when necessary
Change-Id: I1e7c1f4f31a310ff0369690a25859b33aaed14fc
Fixes: 29377436
Test: manual testing with 2011 ADK and multiple Android Auto headunits
2016-11-29 12:10:30 -08:00
Jerry Zhang
bb2965d239 Merge commit '6bb98d85a0a0790ed2b600f4a165ab79ad536f04' into manual_merge_6bb98d8
Change-Id: I43ad588644c03a2174146525ad62b3d512d66074
2016-11-16 17:37:54 -08:00
Jerry Zhang
5cbd151d40 Refactored setCurrentFunction and setUsbDataUnlocked into single method.
am: 935372bfd6

Change-Id: I5436278e092f691c9179f7cc3709c4578b544e74
2016-11-17 00:12:50 +00:00
Jerry Zhang
b15490ac4d Clean up persistent usb state on boot.
am: dfacad026d

Change-Id: I762306bc76e304c6491c8af18e82bf2e0c4b433e
2016-11-17 00:11:15 +00:00
Jerry Zhang
4389cb6c9a Fixed handling of usb state during adb changes.
am: 0269ebe0fe

Change-Id: I2fc3674c4d5cc63febe2ebf47576f3cf1bcd1da2
2016-11-17 00:10:25 +00:00
Jerry Zhang
935372bfd6 Refactored setCurrentFunction and setUsbDataUnlocked into single method.
This gets rid of an extraneous configuration change when going from
adb to adb + file transfer as previously the config would have been
reset once for functions and once for data unlocked.

It also simplifies some of the code.

Test: manually changing usb configurations
Change-Id: Ica10a195338b2189db13113f44657393db110bee
(cherry picked from commit 7a396be6d5ba8914933a54b5bfac25e118db0e9f)
2016-11-15 15:29:45 -08:00
Jerry Zhang
dfacad026d Clean up persistent usb state on boot.
b/31814300 was fixed, but mtp can still stick around in the
persistent config even after flashing. This block of code
will only run once, but will ensure that mtp is not in
the config after the update.

Bug: 31814300
Test: Manual
Change-Id: Icf02be38c9e1f769412ac963ed6afc14e6092bfb
(cherry-picked from commit a45dac0e83f4f907b6b42f453181a7d5c01f65f3)
2016-11-15 15:29:36 -08:00
Jerry Zhang
0269ebe0fe Fixed handling of usb state during adb changes.
When changing state to adb from mtp (charging), we want to disable
the old mtp function. Similarly when change to away from adb to
charging, enable the mtp function.

Also the mtp function should never be persisted.

Bug: 31818377
Bug: 31814300
Test: Manually verify that the correct usb configuration is displayed.
Test: Manually verify that logcat is not kicked during boot.
Change-Id: Idcb7f53be39ea38712d5de45b323d8daeb552129
(cherry-picked from commit 58018d01a3c384b954275d15bee7f9c52a1c7c0a)
2016-11-15 15:29:22 -08:00
TreeHugger Robot
9717839a1f Merge "Revert "Exit enteringAccessoryMode when entered."" 2016-11-02 00:29:27 +00:00
Philip P. Moltmann
7d6e325b6c Revert "Exit enteringAccessoryMode when entered."
This reverts commit a025c8985887e3a6dd87ffcd74a7097b4cef327d.

Change-Id: I550583606444a2d79ec911adf5b14b8783b03286
2016-11-01 22:36:12 +00:00
Jerry Zhang
2d2346e094 Revert: Remove the kick from config switches in UsbDeviceManager
Test: Manual
Bug: 32197840
Change-Id: Id2e939a57e170fbb4c06e55dc79c5d35ce95486f
2016-10-17 17:41:36 -07:00
Jerry Zhang
a45dac0e83 Clean up persistent usb state on boot.
b/31814300 was fixed, but mtp can still stick around in the
persistent config even after flashing. This block of code
will only run once, but will ensure that mtp is not in
the config after the update.

Bug: 31814300
Test: Manual
Change-Id: Icf02be38c9e1f769412ac963ed6afc14e6092bfb
2016-10-17 17:41:36 -07:00
Philip P. Moltmann
f2d83edc26 Clarify which props of USB devices are optional
Test: Compiles, manually inspected object creation code, ran USB CTS
verifier tests
Fixes: 32209658
Change-Id: I738c0cea5a0f37484e986f0a01c8ed9c46b639ed
2016-10-17 12:14:45 -07:00
Jerry Zhang
069c348945 Automatically turn on adb for userdebug and eng builds.
Test: flash on a userdebug build, verify adb is on.
Change-Id: If9a46ca2291c034839ec1d297d20e4e6e3fefd77
2016-10-13 17:32:21 -07:00
Jerry Zhang
58018d01a3 Fixed handling of usb state during adb changes.
When changing state to adb from mtp (charging), we want to disable
the old mtp function. Similarly when change to away from adb to
charging, enable the mtp function.

Also the mtp function should never be persisted.

Bug: 31818377
Bug: 31814300
Test: Manually verify that the correct usb configuration is displayed.
Test: Manually verify that logcat is not kicked during boot.
Change-Id: Idcb7f53be39ea38712d5de45b323d8daeb552129
2016-10-13 17:32:21 -07:00
Jerry Zhang
7a396be6d5 Refactored setCurrentFunction and setUsbDataUnlocked into single method.
This gets rid of an extraneous configuration change when going from
adb to adb + file transfer as previously the config would have been
reset once for functions and once for data unlocked.

It also simplifies some of the code.

Test: manually changing usb configurations
Change-Id: Ica10a195338b2189db13113f44657393db110bee
2016-10-13 17:32:21 -07:00
Jerry Zhang
67a769e18a Remove the kick from config switches in UsbDeviceManager
Configuration switches already kick the stack due to
triggers in init scripts. The switch to none config
is unnecessary

Test: Manually change usb configurations
Change-Id: I65e530b1fa46e4f0123cb951fdd3a20ab7589bc6
2016-10-13 17:32:21 -07:00
Philip P. Moltmann
880389e6cc Clear USB device defaults when user is removed
If a user is removed it is either the parent user of the profile or a
child user. If the parent is removed the whole profile group settings
are removed, but if only a child user is removed we have to remove the
user settings from the groups settings.

Test: Registered a USB device default for a child and parent user and
removed them. Checked dumpsys usb before and after
Fixes: 31995672

Change-Id: I984cd294dc01437b042687684c058eb79332f520
2016-10-11 10:10:53 -07:00
Philip P. Moltmann
a6bf206649 Make default USB handling apps per profile group.
If a USB device is plugged in a default app might be started. As the
user does not indicate which profile he is interested in by pluggin in a
USB device, all handling of this operation has to be per default group.

To do this Split UsbUserSettingsManager into UsbUserSettingsManager and
UsbProfileGroupSettingsManager and modify
UsbProfileGroupSettingsManager.

Bug: 29233186
Change-Id: I8e56b621eeb802966504360d372a8a0140106114
2016-09-15 15:40:39 -07:00
Philip P. Moltmann
031cee90a3 Allow connection from secondary profiles
... and send device-attached broadcasts to all apps instead of just the
current user.

Note: Usb*Manager.open* needs to be called with the identity of the
app.

Bug: 29233186
Change-Id: I225c47bdb409eee1c8fe0499d600fded470aa101
2016-09-08 10:59:18 -07:00
Keun-young Park
badbbae6fa allow external USB host management
- Setting config_UsbDeviceConnectionHandling_component leads into
  launching specified Activity whenever USB device is connected.
- This allows external Activity to manage USB device based on
  its own setup and settings.
- Device access can be passed to other app with permission update
  by UsbManager.grantPermission.
- added UsbDeviceConnection.resetDevice() to reset USB device connected.
  This is necessary to get device out from AOAP.
- Test requires installing UsbHostExternalManagmentTestApp and
  AoapTestHost to USB host, and AoapTestDevice to USB Device.

bug: 26404209
Change-Id: I8e77ddc646c15454d9b2ecf1356924cf6351fc28
2016-08-24 15:00:08 -07:00
Glenn Kasten
d21cb15584 resolve merge conflicts of c76a3ac to stage-aosp-master am: 67ffd5e617
am: f7b4fd24e3

Change-Id: Ib06db403955ae0056c1fee0e09f9249d0b887ea1
2016-08-17 21:10:59 +00:00
Glenn Kasten
67ffd5e617 resolve merge conflicts of c76a3ac to stage-aosp-master
Change-Id: Ifff16bdc42e8326f3f60cf4b92688c445cb4db25
2016-08-17 13:28:04 -07:00
Glenn Kasten
1fda533936 Squashed commit of the following:
commit efa6f355b06675aa4d0879fd279e22c16d5c046c
Author: Mikhail Naganov <mnaganov@google.com>
Date:   Wed Aug 10 12:25:13 2016 -0700

    MIDI: Use server-side socket in blocking mode for virtual devices

    Since virtual MIDI servers may misbehave, blocking mode will throttle
    them if clients are not coping with their sending speed.

    Bug: 29413812
    Change-Id: I9c4a2a7a7ea3ea060c93fedc7d0f033427c557c9

commit 755dfb5f83749d3963c63d98d692307f8271c804
Author: Mikhail Naganov <mnaganov@google.com>
Date:   Fri Jul 8 13:26:19 2016 -0700

    Protect MIDI framework against client blocks in MidiReceiver.onSend

    Make the server-side socket non-blocking when creating MidiOutputPort
    for clients. Thus if a client ceases to read from its side of the
    socket pair, the server will just fail to write instead of blocking.

    One drawback is that the MidiOutputPort on the client can't indicate
    that it has become dysfunctional, but it's not possible without
    changing the API.

    Bug: 29413812
    Change-Id: I9dfcbdd214a815cea8fd1365324fd78ca459268a

commit c740b13953761f58233ac651a0b5227733b1bdcc
Author: Mikhail Naganov <mnaganov@google.com>
Date:   Fri Jun 17 04:11:25 2016 -0700

    UsbMidiDevice: Clean up terminology and fix comments

    When working with physical MIDI devices, an *input* stream is used
    for reading from *output* port of the device, and vice versa. Thus,
    using "input" and "output" without specifying whether it's a stream
    or a port is confusing.

    Clarify names of counter variables, and fix a couple of comments
    that were incorrect due to this confusion. No functional changes.

    Change-Id: If561eaca4bade94e9296d2c703c9fcebc91296e2

commit 4269c6417287737624f6165a8bbeb5aa427de9a0
Author: Glenn Kasten <gkasten@google.com>
Date:   Thu May 5 18:49:16 2016 -0700

    Update MIDI package summary

    Bug: 28625060
    Change-Id: If552ca8e1a0666d402b5f536699bf3fb09c1e324

commit 862d40b73168bde7d0be5280d997985c18061014
Author: Phil Burk <philburk@google.com>
Date:   Tue Apr 19 15:56:24 2016 -0700

    MidiDevice: do not open ports on closed device

    Fix involves client side mIsDeviceClosed flag.

    Bug: 24949216
    Change-Id: I666284a787fbb9a710d2372fb424e8e54f6a2825
    Signed-off-by: Phil Burk <philburk@google.com>

commit 6f1de358b9f2616e03f4655f01454770915ddd66
Author: Phil Burk <philburk@google.com>
Date:   Mon Apr 18 16:05:28 2016 -0700

    MidiService: fix resource leak

    The proxy object was being used to match when adding or removing objects.
    But they are different each time. So now we use an asBinder() object.

    Bug: 28153736
    Change-Id: I1bccebf1e9464668db757ff08b41902d0cf0e3a7
    Signed-off-by: Phil Burk <philburk@google.com>

commit f7386bd535bb8a1d7f8df8f44a1748ab770c991a
Author: Phil Burk <philburk@google.com>
Date:   Tue Apr 5 14:19:53 2016 -0700

    MidiDevice: fix connectPorts for same Process

    If connectPorts() was called for a device in the same process then
    the connection would die when the ParcelFileDescriptor was closed.

    Bug: 26406775
    Change-Id: Id0538452593b4761ac2a93d366ade76d2e35ce73
    Signed-off-by: Phil Burk <philburk@google.com>

Change-Id: I4dfc2a2cbaf04bf1a790ae2cb39bf74fb5bb16ac
2016-08-17 08:45:39 -07:00
Phil Burk
2f2bf4014a UsbMidiDevice: fix MIDI flush()
The proxy MidiReceiver in the USB device was not forwarding the flush
command to the event scheduler.

Bug: 25511696
Change-Id: I6a4759b71bc8f9ae3e20aed1238f62a2ed405e24
Signed-off-by: Phil Burk <philburk@google.com>
2016-08-16 16:57:36 -07:00
Philip P. Moltmann
a025c89858 Exit enteringAccessoryMode when entered.
... so that a quick usb plug -> unplug actually causes both enter and
exit. Before the second update was treated as another enter.

Admittedly treating any first update as connect and any second update as
disconnect is sketchy, but this was the intention of the current code,
so just fix that for now.

Fixes: 29377436
Change-Id: Ib6bcc23ce5ec9979edcc38952a9414683513ca0c
2016-08-09 17:23:48 -07:00
Philip P. Moltmann
905c924196 Add (corrected) usb power sink handling am: 9ebf2a5683 am: 78ae5ebe58
am: df2277d66b

Change-Id: I5c53c4c84cfd08cc80c5e48f6e258b99d6b4cdd0
2016-08-04 21:01:47 +00:00
Philip P. Moltmann
9ebf2a5683 Add (corrected) usb power sink handling
This is a resubmit of change 01355161536787a55190ff3d2595fbf6c8056fe3 .
The previous change did not handle the case where the device was plugged
into a wall charger correctly.

Fixes: 30418683
Change-Id: Ia155f2230bdd3576c8fb8eb8cff11f544047c35a
2016-07-29 08:39:10 -07:00
Philip P. Moltmann
9979be916b Revert \\"Handle USB power role \\'sink\\'\\" am: 47e8089bf4
am: 4022d582d7

Change-Id: I203f5920b4346cfea4e47cef4d2b2f0f39e92a35
2016-07-27 21:34:15 +00:00
Philip P. Moltmann
47e8089bf4 Revert "Handle USB power role 'sink'"
This patch treats AC wall chargers like phones supplying power. We only want to show the notification when connected to another phone, not to a AC wall charger.

Bug: 30418683
This reverts commit 01355161536787a55190ff3d2595fbf6c8056fe3.

Change-Id: I304c3f78916896ddb12129b11a0e691b3ef77819
2016-07-27 16:32:59 +00:00
Philip P. Moltmann
76eb4b1a6c Handle USB power role \\'sink\\' am: 0135516153
am: 6d0ea86fec

Change-Id: I6dd5eb7a328bd4071c4c40a2a982ec4b7de0b785
2016-07-26 15:07:50 +00:00
Philip P. Moltmann
0135516153 Handle USB power role 'sink'
Fixes: 29963134
Change-Id: I7cfe042ed007d36cee5f8bc4c0fa33f8936cba3d
2016-07-15 13:21:29 -07:00
Mikhail Naganov
aab4c1ad48 UsbMidiDevice: Clean up terminology and fix comments
When working with physical MIDI devices, an *input* stream is used
for reading from *output* port of the device, and vice versa. Thus,
using "input" and "output" without specifying whether it's a stream
or a port is confusing.

Clarify names of counter variables, and fix a couple of comments
that were incorrect due to this confusion. No functional changes.

Change-Id: If561eaca4bade94e9296d2c703c9fcebc91296e2
2016-06-17 08:04:28 -07:00
Philip P. Moltmann
236b9e8eb4 Handle the uncommon case that a name is null
Bug: 29037588
Change-Id: I697184bd1ae4d519f8f29bf612ba13843e6662cb
2016-05-31 10:16:30 -07:00