199 Commits

Author SHA1 Message Date
Hugo Benichi
d6998d4bd6 Merge "Minor formatting cleanup to remove overlong line" 2017-03-13 07:23:06 +00:00
Badhri Jagan Sridharan
c584d77b93 Introduce debounce to filter rapidly toggling type-c ports
Type-c ports can quickly toggle between connected/disconnected
states. Introduce debounce to prevent sending spurious notifications.

Bug: 34972898
Test: notification should not be queued for a pixel-c charger not connected
to the power outlet.
Change-Id: I4aa19f9f864fe5b77e65f6a07a3184d8aba1f5fc
2017-02-15 10:21:19 -08:00
Badhri Jagan Sridharan
1b8e847a87 Fix handling usb dialog for wall chargers.
UsbPort.POWER_ROLE_SINK is orthogonal to the type of the charger
attached. POWER_ROLE_SINK would be the case for AC charging and
USB charging. Therefore query BatteryManager for the charger
type.

Bug: 34972898
Test: Charging notification should not show for pixel-c chargers.
Change-Id: I8dddcd7727b6af973bd173d2c6e325aa4be2ca3a
2017-02-15 10:21:02 -08:00
Hidenari Koshimae
87d66fd3f1 Minor formatting cleanup to remove overlong line
Change-Id: If0afb279552bc664ba579badaf35662effbd2a80
2017-02-15 11:41:34 +09: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
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
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
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
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
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
0135516153 Handle USB power role 'sink'
Fixes: 29963134
Change-Id: I7cfe042ed007d36cee5f8bc4c0fa33f8936cba3d
2016-07-15 13:21:29 -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
Vincent Palatin
a0116bf81f Fix notifications for USB PD enabled devices
The devices with USB PD support can have the data role and the power role of
their USB-C port reversed. Ensure the title of the notification and the content
of the USB selection dialog is correct in this case.

Testing done on Ryu with the following accessories:
- legacy A-C cable
- USB-C charger (5X)
- USB-PD charger (Zinger)
- Pixel 2 (in both roles)
- Type-C Macbook (in both roles)
- Nexus 5X (in both roles)
- Apple AV HDMI accessory
- LG USB-C screen/dock
- Honeybuns dock

Bug: 28310685
Bug: 24137353
Change-Id: Id7f358c40d8714fae68ca98a7eb067f62f18b0af
(cherry picked from commit 0be6800b0feba50fa2c1be7852ee2eb02c38afc0)
2016-05-19 20:46:21 +00:00
Phil Burk
de2922468b 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-04-05 11:30:00 -07:00
Paul McLean
c72239409b Added logging to USB Audio connect and disconnect.
This will let us see in bug reports if the USB device in question
is ACTUALLY recognized and added/removed from the audio system.

Bug: 27812441

Change-Id: Id3eb4d4f3f0b1e66a24999706ba589c0962eba58
2016-03-28 13:07:09 -06:00
Daichi Hirono
b6abccc8f3 Add new text for USB type C host.
If you use USB type C, you can charge Android from USB power or you can
supply power from Android to the other connected device.

Previously Android showed the notification saying "USB for charging".
The CL updates the text so that it shows the current power direction
explicitly.

Change-Id: Ic15ba70eaf8ade028283d8f490ac36e8d5e4db21
FIXED: 27706939
2016-03-28 10:52:17 +09:00
Daichi Hirono
618fa6ffc1 Add USB_HOST_CONNECTED extra to ACTION_USB_STATE sticky intent.
Previously UsbModeChooser activity is automatically closed when Android
is connected to another Android and works as host. This is because
ACTION_USB_STATE intent does not include the information whether Android
is connected as host and UsbModeChooser regards Android is not connected
USB devices.

The CL introduce the HOST_CONNECTED extra to ACTION_USB_STATE so that
UsbModeChooser can refer it.

BUG=27535640

Change-Id: Ie29583b78319078430f6d9a8390787780410ac8c
2016-03-17 14:14:32 +09:00
Daichi Hirono
f8a0c8536e Skip MTP launch notification for devices having FEATURE_AUTOMOTIVE.
BUG=27410621

Change-Id: I1fd2ad663d8e5c5507a8e5e93aafea9d4188ed02
2016-03-09 12:53:50 +09:00
Daichi Hirono
fda7474c5f Open MTP device on demand.
Previously MtpDocumentsProvider opens a device just after device is
connected to Android. But MtpDocumentsProvider should open MTP device on
demand so that other applications can open device if user starts to use
the application before using MtpDocumentsProvider.

BUG=26625708

Change-Id: I6083b8c7cef49ee6e9fb0d15ca4adc129734f3eb
2016-02-04 12:45:58 +09:00
Daichi Hirono
163e4b6ae8 Add launch notification for MTP devices.
The CL adds launch notification that are shown after MTP/PTP device is
connected to Android device. By tapping the notification, Users can
launch an applicaiton that can handle USB_DEVICE_ATTACHED intent of MTP
device.

BUG=26611224

Change-Id: I6fd179ccd436531dfff6ff9a50dc2b754c20f190
2016-02-01 13:28:01 +09:00
Julia Reynolds
d1d533610a Increase notification priority for adb connections.
Change-Id: I04ec4dac40737d59a32775e579f734a5460db25c
2016-01-08 16:12:13 -05:00
Daichi Hirono
4751880a4d Grant USB device permission by using system permission.
Previously it skips the device permission check by referring package
name. The CL removes the special case and use general MANAGE_USB
system-only permission to skip USB device permission dialog.

BUG=26048722

Change-Id: I3702393a50696209499d1e5f6549dab9fb2cefe4
2015-12-09 11:15:25 +09:00
Daichi Hirono
bc0a94055c Grant USB device permission for android.media UID always.
The UID is used by MtpDocumentsProvider that is a system component and
needs to access MTP devices.

BUG=25983848

Change-Id: Iaa20a849cb9e7a86bde6c5bf8abbb15e65ced6c3
2015-12-04 13:59:28 +09:00
Chris Wren
c35d7759d8 allow devs to turn off charging notifications
in the same was as we allow then to turn of debuging notificaitons
this is useful for screenshots and demos

Change-Id: I6e95addec2917abdd619086ed68910097fb5b8aa
2015-11-19 12:49:42 -05:00
Glenn Kasten
d1323e9b70 Merge "Built-in mic is not used when USB mic is disconnected" am: ebbdabdb82
am: 1104180301

* commit '110418030167702f29fa686616d68fc62f9c0995':
  Built-in mic is not used when USB mic is disconnected
2015-11-04 16:19:36 +00:00
Glenn Kasten
ebbdabdb82 Merge "Built-in mic is not used when USB mic is disconnected" 2015-11-04 16:03:41 +00:00
Alejandro Ochoa
46b434ff98 Built-in mic is not used when USB mic is disconnected
In some cases when the USB microphone is disconnected,
audio stack does not switch to the built-in microphone.
It gets stuck in a state where it still recognizes the
USB mic is still connected. Current device removal
implementation only considers USB output devices such
as headset. The same process should be used for input
USB devices (microphone).

Bug: 24932354
Change-Id: Ic2089ef5a9a318cb47336ade405f79eccd7129f8
Signed-off-by: Alejandro Ochoa <alejandro.ochoa@intel.com>
2015-11-04 15:58:09 +00:00
Nick Kralevich
853fde6915 UsbDeviceManager: set mUsbDataUnlocked=false on user switch am: 5701321701 am: aa330c0dc2 am: d33d66e26c
am: 581c1809c1

* commit '581c1809c1c617a39eae05aac481a114c70f09d2':
  UsbDeviceManager: set mUsbDataUnlocked=false on user switch
2015-10-29 21:57:12 +00:00
Nick Kralevich
aa330c0dc2 UsbDeviceManager: set mUsbDataUnlocked=false on user switch
am: 5701321701

* commit '5701321701a319d3f2d98365a82266eeddaed895':
  UsbDeviceManager: set mUsbDataUnlocked=false on user switch
2015-10-29 21:30:59 +00:00
Nick Kralevich
5701321701 UsbDeviceManager: set mUsbDataUnlocked=false on user switch
Make sure access to MTP data is relocked when a user switch occurs.

Bug: 25288494
Change-Id: I69dafc7f51b847f4dba1993a85fb1a51df1a5e37
2015-10-29 13:07:52 -07:00
Paul Mclean
438c220d78 Merge "Fixing problems with 1st connect of USB audio device to Fugu." 2015-10-29 13:40:47 +00:00
Paul McLean
c15f756443 Fixing problems with 1st connect of USB audio device to Fugu.
Also added some additional logging functions as we are not done
looking at connect/disconnect issues.

Leaving in tact the multi-device connect/disconnect logic (neeeds to
be revisited)

Bug: 24906368
Change-Id: Iff91c51a9c7013dde56182059f3747e1d6cd727b
2015-10-29 13:39:42 +00:00
Paul McLean
e3b077b1c6 Fixed capture-only devices not removed when disconnected.
I have brought shame upon my family.

Bug: 24932354
Change-Id: I0fce40a976f40e74f4fd87eb6f4aa93e847032cc
2015-10-28 13:39:44 -06:00
Fyodor Kupolov
dabd6b8f45 Restart USB stack only if data is unlocked
When switching users, USB stack shouldn't be restarted if mUsbDataUnlocked =
false, e.g. device is in charge only mode.

Bug: 24611765
Change-Id: I3b12f8c8926235546fe916a200aa57ed618193de
2015-10-02 15:41:46 -07:00
Xiaohui Chen
e4de5a0d3b Cleanup OWNER references.
Bug: 19913735
Change-Id: I2150c6baaab80fe11312e4401394a2a8da52e595
2015-09-23 18:50:11 +00:00
Tim Kilbourn
bcb80b03f1 am 880c6010: am 0c4050b0: am bdfbd821: am 0eb10ede: Merge "Always set the usb config when modifying it." into mnc-dr-dev
* commit '880c601013e3b58f004f65c6cacfb8e19e2ca863':
  Always set the usb config when modifying it.
2015-09-19 18:14:47 +00:00
Tim Kilbourn
bdfbd82154 am 0eb10ede: Merge "Always set the usb config when modifying it." into mnc-dr-dev
* commit '0eb10ede2364bf975721d95f7af7a1e4f4b617f8':
  Always set the usb config when modifying it.
2015-09-19 00:29:35 +00:00
Tim Kilbourn
823e805c1c Always set the usb config when modifying it.
On some devices, setting system properties takes too long and we end up
with races where adbd gets killed and never comes back. With this
change we avoid a small optimization that checks the previous value of
the config, instead opting to set it every time.

Bug: 23631400
Change-Id: I7567cc2efb3d5d15c45334bd66b28877a2af0ac3
2015-09-18 15:05:57 -07:00
Daniel Koulomzin
e4b3e61456 am 1a73ab76: am 4bf3dfea: am ffa2d691: Merge "Adds config flag for USB notification." into cw-e-dev
* commit '1a73ab760bedd371dbfb8850ac24555c33004ff6':
  Adds config flag for USB notification.
2015-09-10 22:06:52 +00:00
Gus Prevas
e753361508 Adds config flag for USB notification.
This change modifies UsbDeviceManager such that the ongoing
system notification for USB charging state is controlled by a
config flag.

Bug: 23409719
Change-Id: I2ef24fe74923170a6e8dd02375b973b4025281e4
2015-09-10 13:37:59 -04:00
Yasuhiro Matsuda
92386c42a8 Merge "Broadcast ACTION_USB_STATE only if necessary." 2015-08-26 09:36:40 +00:00