Commit Graph

342 Commits

Author SHA1 Message Date
Paul McLean
f148e8ecce Merge "Catch exception in descriptor parser causes device connection to be skipped." into oc-dr1-dev am: 22d4bf2283
am: 702d82fdc0

Change-Id: Ia45c777b095ff8c29042145fd11b29dcace24366
2017-07-11 00:58:17 +00:00
Paul McLean
b82963f3e0 Catch exception in descriptor parser causes device connection to be skipped.
Bug: 63538159

Test: Manual - force an exception and verify the the device is still available.
Change-Id: I4f4c59d4d0f73b664fac8bc74a64414d0e9d9a24
2017-07-10 14:57:20 -06:00
Jerry Zhang
b60c48a6a2 Merge "Broadcast only if boot complete" into oc-dr1-dev 2017-07-06 16:52:04 +00:00
Jerry Zhang
885b9e7133 Broadcast only if boot complete
Accessory connects / disconnects can occur before
boot complete, so don't broadcast intents if that
is the case.

Bug: 63114621
Test: connect/disconnect an accessory
Change-Id: Ib8f9eb97ce1630004511fcc1fb84594ccc812c06
2017-07-05 10:44:59 -07:00
Colin Cross
6bad7044f5 Merge changes I09ecc525,I83e7e8ef
* changes:
  Revert "Do not use lambda as it breaks javac"
  Add missing dependency to services for desugaring
2017-06-30 15:52:02 +00:00
Jerry Zhang
ed0cc81212 Merge "Broadcast only if boot complete" 2017-06-29 21:54:39 +00:00
Paul McLean
e3bb95dddb Merge "Adding USB Headset awareness." into oc-dr1-dev am: f56b57781e
am: 1ae4273154

Change-Id: I24ffbb79b965df15a22dbc5d6ce3ae90ddb27b50
2017-06-29 19:42:04 +00:00
Jerry Zhang
dc0c14f169 Broadcast only if boot complete
Accessory connects / disconnects can occur before
boot complete, so don't broadcast intents if that
is the case.

Bug: 63114621
Test: connect/disconnect an accessory
Change-Id: Ib8f9eb97ce1630004511fcc1fb84594ccc812c06
2017-06-29 11:14:30 -07:00
Colin Cross
03196cdf2e Revert "Do not use lambda as it breaks javac"
This reverts commit e37eda7b41.

I83e7e8efdff9cd662e179240336abebedf859c62 adds the missing
dependency to let desugar work.

Bug: 63078196
Test: m -j ANDROID_COMPILE_WITH_JACK=false
2017-06-29 10:35:22 -07:00
Paul McLean
b5eaa809da Adding USB Headset awareness.
Bug: 36220140
Bug: 62043095
Test: Manual
Change-Id: Ic4636e3dc2dfce0154e6405848bea7752cf2d07b
2017-06-29 10:30:05 -06:00
Philip P. Moltmann
e37eda7b41 Do not use lambda as it breaks javac
Bug: 63078196
Test: Built
Change-Id: I6f195ad127e95b76b85ad7417f31ac19af0ac5bc
2017-06-27 23:58:33 +00:00
Philip P. Moltmann
bee04d08b5 Clean up USB*Manager.
Just automatic cleanup.

Test: Built
Change-Id: I1da09d6b43503a6b77a3619f0f8513ef39cf2d75
2017-06-26 16:04:10 -07:00
TreeHugger Robot
31f5b6875c Merge "Enable MTP or ADB when default functions are enabled" 2017-06-05 23:16:46 +00:00
Jerry Zhang
42f4815eff Merge "Remove ptp from persist config on boot" into oc-dev am: 1d1cf13056
am: 8d5570b9e1

Change-Id: I792ed0959e5a24ef8893a1bd63e3a33278462556
2017-06-05 18:54:08 +00:00
Jerry Zhang
6032c354d9 Remove ptp from persist config on boot
We got a report from a user in which ptp was set in the
persistent config, likely from a previous version.
This causes errors in the usb state and is not removed
by an ota. To fix, remove ptp in the same place that mtp
is removed from the persistent config.

Bug: 62202885
Test: Add ptp to persistent config, verify removed.
Change-Id: I5ebd93b9c8a49bcaca5a3362e49ed1e1acf50a9b
2017-06-02 12:05:03 -07:00
Badhri Jagan Sridharan
7f3047e6b6 Enable MTP or ADB when default functions are enabled
Clients (viz. Tethering) use UsbManager@setCurrentFunction(null, ..)
to make the device switch to default functions. While in OemMode,
this gets set to the last enabled functions list. Instead,
enable MTP or ADB depending on whether ADB is enabled or not.
This is the expected behavior for normal boot as well.

Bug: 37491031
Test: Verified that the device falls back to either mtp or adb while
in OemOverride mode.
Change-Id: I1c26d1d0ee3c015b597d40771cd765b783cd91bb
2017-05-25 10:30:22 -07:00
Jerry Zhang
3a958a09d2 Merge "Revert "Upgrade logging for UsbDeviceManager to narrow down bugs."" into oc-dev 2017-05-22 23:13:58 +00:00
Jerry Zhang
daa9c19dae Revert "Upgrade logging for UsbDeviceManager to narrow down bugs."
This reverts commit c889b4f4eb.

Merged-In: I74306bacad2a61471a9b8c9fd881229b22b6975e
Change-Id: I74306bacad2a61471a9b8c9fd881229b22b6975e
2017-05-22 10:57:08 -07:00
Jerry Zhang
b2dac52391 Revert "Upgrade logging for UsbDeviceManager to narrow down bugs."
This reverts commit c889b4f4eb.

Change-Id: I74306bacad2a61471a9b8c9fd881229b22b6975e
2017-05-15 13:24:23 -07:00
Jerry Zhang
653fbeeec4 Merge "Only force reset when adb is not enabled (i.e. mtp is)" into oc-dev am: f874fd319e
am: c5a4576cab

Change-Id: I153a5ad3e4bd0de9a62ef39ebc7579f4916b79e3
2017-05-12 20:31:51 +00:00
Philip P. Moltmann
278685d468 Merge "Remove forward matches before checking for default" into oc-dev am: d53cbfd0dc
am: ba8b3f05b6

Change-Id: Ic35779f6b6ad97dc1a6f83356dfa45e0d5b5f406
2017-05-12 20:29:15 +00:00
TreeHugger Robot
f874fd319e Merge "Only force reset when adb is not enabled (i.e. mtp is)" into oc-dev 2017-05-12 19:41:52 +00:00
Jerry Zhang
ad962a923c Only force reset when adb is not enabled (i.e. mtp is)
Some users depended on adbd continuing to run after disconnect
in order to use scripts with nohup. This change allows this
use case to keep working since only mtp has to be force
set.

Bug: 38227228
Test: adb shell "nohup sh /sdcard/script" where script contains
"sleep 5; touch /sdcard/done" and verified file still appears even if
disconnected during sleep.
Test: am force-stop com.android.providers.media, still connects

Change-Id: I25ae2b922fa4d06109ac8cf5e43e1c47a33c46a6
2017-05-11 13:50:28 -07:00
Philip P. Moltmann
0d78363a39 Remove forward matches before checking for default
A forward match is a intent-target (aka. match) that switches between the
personal and work profile's intent resolver.

This can be unnecessary if there are no work profile matches.

We need to remove these unnecessary matches early as the default activity
resolution code considers a system app as default _only_ if it is the only
match. Before there could still the an unnecessary forward match under
consideration.

Test: Connected USB accessory that only matches a system app on the personal
      profile.
      Before we showed a confirm-dialog, now we consider the system app
      as default and automatically launch it.
Fixes: 37530439

Change-Id: I7bc9b969fc0b9abae4d15dd3f268783d05b91f9a
2017-05-11 10:23:41 -07:00
Philip P. Moltmann
16bcd7219d Merge "Merge "Fixes for handling users + default for USB" into oc-dev am: 5262ae9b87" into oc-dev-plus-aosp
am: bc535b11b6

Change-Id: I6e20b889abbb7d2c037d71c271a733e0639b3e1e
2017-05-10 02:32:54 +00:00
TreeHugger Robot
5262ae9b87 Merge "Fixes for handling users + default for USB" into oc-dev 2017-05-10 01:39:33 +00:00
Jerry Zhang
9507d70718 Merge "Always force set functions on disconnect" into oc-dev am: bf783e24cf
am: 4fdcb5d6fe

Change-Id: I8d7656a046fe2e649c73f4ad1505e9b7cf2625f0
2017-05-09 21:38:00 +00:00
Philip P. Moltmann
d4b09d4e16 Fixes for handling users + default for USB
Once a user plugs in a USB device (or accessory) the user can decide
which app should be started by default once the device is plugged in.
I.e. this app becomes the "default" for this USB device. If the user has
a work profile the default app is set for all profiles of the current
profile group (i.e. personal and work profile) as at any point in time
one profile group is visible on the screen.

There were some issues in the code:
- fix small obvious bugs

- use userPackage (==packageName + user) everywhere instead of only
  packageName as we have to distinguish between apps of different
  profiles.
- Stop accessing userPackage.packageName whereever possible to avoid
  mistakenly ignoring the user

- Monitor packages of all users and deal only with users of the current
  profile group.
- Do not react to package changes/updates/modifications. While it is
  possible that an app gained the ability to deal with new USB devices on
  update, we should not clear the default app for a default device. This
  is because (1) this situation is exceedingly rare and (2) we do not
  easily know when an app gained the ability to deal with a device. The
  user can still manually clear the USB default app via Settings.

- The old DeviceFilter.matches code did not make sense. An app that
  wanted to replace the previous default app would have needed to know
  the serial number of the device.

Test: - Searched for access to UserPackage.packageName and we only use it
        directly three times now. I checked these occurances and it is save
        to use.
      - Ran the following test
        - Install app that can handle a USB device in personal profile
	- make this app the default for this USB device
	- Install same app in work profile -> default was be cleared as
                                              it is not clear if the user
					      might prefer the other app
	- make the work app the default for this USB device
	- update non-work app -> default should not be cleared as the the
                                 update is usually not triggered by the
				 user and we should just keep the
				 selection the user made before
	- update work app -> App is already default
	- uninstall work app -> default should be cleared as the default
                                app was removed
Fixes: 36610004
Change-Id: I294b582c36228169ac12a02d8007a4541e386d57
2017-05-09 10:18:41 -07:00
Jerry Zhang
f706fe2f60 Always force set functions on disconnect
Functionfs no_disconnect mode will close the function on
disconnect so the current handling won't suffice for cases
where the mtp process is killed while MtpService is running.
This can happen when anything in Media/DownloadProvider ANRs
or similar.

Solve this by always setting the config at disconnect time.

Bug: 38010151
Test: Connect with MTP, am force-stop com.android.providers.media,
reconnect

Change-Id: Iaf012f6e2f11151f34d834efe08777dd02c0aec5
2017-05-08 15:17:17 -07:00
Badhri Jagan Sridharan
405ce17abb Notify the user when an unsupported accessory is attached
This CL pops up a notification to the user when the device does not
support Analog Type-C headphones but the user connects one.
i.e when the Usb port status reports currentMode=audio_acc, but
audio_acc is not present in the supportedModes list.

Bug: 36604276
Test: Manually test inserting an Audio accessory
Change-Id: If514b9f238da196a7157e1aacb6d7690fde66f21
2017-05-01 10:30:49 -07:00
Glenn Kasten
20137dc148 USB audio: increase protection of member fields
Replace public by private or package access in field declarations,
and add getters and setters as needed.

Test: compiles OK
Change-Id: Ief3fffb6a21d2e4d05153839f444617ea5e70846
2017-04-28 09:13:14 -07:00
Glenn Kasten
f9e6e70687 Merge "Add comments" 2017-04-27 16:33:17 +00:00
Julia Reynolds
d6247427ac Merge "Api updates" into oc-dev am: f84467e19f
am: 7ee513c27b

Change-Id: Iafbf2f2ca92b288de7bded40772cd15eca2012ee
2017-04-27 05:15:11 +00:00
TreeHugger Robot
f84467e19f Merge "Api updates" into oc-dev 2017-04-27 04:51:46 +00:00
Thierry Strudel
ece721f8cd Merge "Update UsbService to V1_1 usb hal" 2017-04-27 03:28:12 +00:00
Badhri Jagan Sridharan
ef4b303fc2 Update UsbService to V1_1 usb hal
This CL adapts Usb service to V1_1 hal.
V1_1 hal supports reporting audio_adapter accessory
and debug accessory.

Bug: 36604276
Test: Manually test inserting an Audio accessory.
Also tested to made sure that change is compatible with V1_0
implementations
Change-Id: I8e44f5e9ae14b0e41965e8d355c99ac42af93f23
2017-04-26 21:43:07 +00:00
Julia Reynolds
bad4297600 Api updates
- Better documentation on DEFAULT_CHANNEL_ID
- Renaming getChannel/setChannel/getTimeout/setTimeout
- Add documentation to getShortcutId
- @hide parcel constructors

Test: make, make cts
Bug: 37672218

Change-Id: I695b2620c51638a84930e9d1c5fbfd6d85699b55
2017-04-25 17:00:05 -04:00
Jerry Zhang
6f9dbb1203 Reorder USB_STATE updates so config_changed is not replaced.
Because of flag INTENT.ACTION_REPLACE_PENDING, intents
sent in rapid succession could replace previous intents
that have not been processed, and it is unreliable when
or whether this happens. Since CONFIG_CHANGED cannot afford
to be lost, make sure it is sent last, so it is always
processed.

Bug: 34873000
Test: lots of unplugging/plugging
Change-Id: I9264d5129139cf3f433bbcd068e8b292fec6cd31
2017-04-24 16:58:06 -07:00
Jerry Zhang
740ca0f9f0 Don't skip intents where config changed.
Since we are adding ffs.mtp.ready to the init
scripts, we can no longer skip intents that cause
that property to be set.

This fixes the case where device is disconnected
and adb is repeatedly enabled/disabled.

Test: enable/disable adb, usb mtp
Bug: 33220530
Change-Id: I48e687c1af3f9da9e522ebe879285877c0168da8
2017-04-24 14:46:32 -07:00
Jerry Zhang
768dd994f3 Reorder USB_STATE updates so config_changed is not replaced.
Because of flag INTENT.ACTION_REPLACE_PENDING, intents
sent in rapid succession could replace previous intents
that have not been processed, and it is unreliable when
or whether this happens. Since CONFIG_CHANGED cannot afford
to be lost, make sure it is sent last, so it is always
processed.

Bug: 34873000
Test: lots of unplugging/plugging
Change-Id: I9264d5129139cf3f433bbcd068e8b292fec6cd31
2017-04-24 12:40:41 -07:00
Jerry Zhang
58bffb24d7 Merge "Upgrade logging for UsbDeviceManager to narrow down bugs." into oc-dev am: 6d3747ebe2
am: 7f986ba87b

Change-Id: I45d4b1f7fbf9268206e0c90636f02bf0d3ae5d66
2017-04-22 01:45:19 +00:00
Jerry Zhang
c889b4f4eb Upgrade logging for UsbDeviceManager to narrow down bugs.
Will be reverted once bugs are caught.

Bug: 34873000
Test: None
Change-Id: Ia43e0ccb1c22c767c6ef3edbf04cef024662cd15
2017-04-21 16:22:13 -07:00
Jerry Zhang
2c284916d7 Merge "Only send HOST_STATE intents when host mode is used." into oc-dev am: a73f9f874a
am: bf51f836ae

Change-Id: Ie358c38f98d186ed0197248fcf82db2913cfe97d
2017-04-20 13:11:48 +00:00
Jerry Zhang
41ebde2bb3 Only send HOST_STATE intents when host mode is used.
Previously HOST_STATE update intents would broadcast if the
device was in gadget mode but not configured. This would
override the sticky intent, causing MtpReceiver to fail.

This is fixed by only updating host state if host is connected
or if host is being disconnected (was connected before).

Bug: 34873000
Test: set up lockscreen, reboot device while plugged in, unplug before
unlocking, verify usb works.

Change-Id: Ic424e678ba72401ee8ec975e915727272edf3767
2017-04-18 12:06:27 -07:00
Badhri Jagan Sridharan
82d49dfbef Repost USB and ADB notification when locale changes
Bug: 37266276
Test: Manually tested the language of active notifications after
switching language.

Change-Id: I0cef61fbd155e0c9789f52a140561c71969fbab7
2017-04-14 12:01:59 -07:00
Glenn Kasten
19d6c7a9cd Add comments
Test: builds OK
Change-Id: I3745b04473d0a3878845708c9847001d936ba9b2
2017-04-13 11:32:59 -07:00
David Stevens
9a2b5e9828 Merge "Reset the default usb package less often" into oc-dev am: 1654143680
am: 8e40723876

Change-Id: I041f7fdaf689fde58f7853af075f708b30418201
2017-04-12 01:23:07 +00:00
David Stevens
1654143680 Merge "Reset the default usb package less often" into oc-dev 2017-04-12 00:12:15 +00:00
puma_hsu
6040887f78 Just broadcast intent to bring up MTP/PTP as soon as switching function
Bug: 36113457
Bug: 34451451
Test: Turn on tethering
Change-Id: I3a7ab6fdcd157740b8e55ded67b3d5dddf15b0e0
Signed-off-by: puma_hsu <puma_hsu@htc.com>
(cherry picked from commit 4b3e46c787)
2017-04-07 12:35:21 -07:00
David Stevens
f4a2e1df94 Reset the default usb package less often
This CL makes logic for resetting the default package for handling USB
intents less agressive (added in ag/101452). First, instead of listening
for package changed events, we now listen for package replaced
broadcasts. Second, we don't reset the default package if the app being
added/updated is already the default package.

Bug: 35491880
Test: Manually tested with a work profile
Change-Id: Id1992239b5d8ace87fefeb4acd6ca1031c3c1085
2017-04-06 22:51:05 -07:00