Commit Graph

290 Commits

Author SHA1 Message Date
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
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
TreeHugger Robot
5262ae9b87 Merge "Fixes for handling users + default for USB" into oc-dev 2017-05-10 01:39:33 +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
TreeHugger Robot
f84467e19f Merge "Api updates" into oc-dev 2017-04-27 04:51:46 +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
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
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
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
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
TreeHugger Robot
82331f7f73 Merge "Not send switch intents if there is no real intent" into oc-dev 2017-04-03 23:44:45 +00:00
Philip P. Moltmann
ebc8ee266c Not send switch intents if there is no real intent
When resolving activtities for the USB device/accessory connection UI a
special intent that allows to switch between profiles get added. This
also gets added if there is no activity in the secondary profile that
can be started.

Fixes: 36544815
Test: Added work profile. Add USB handling app only to personal profile
      and plugged in USB device -> no crash anymore

Change-Id: I311ddd53b3ff0c8406e62bac57972d4b790ebddc
2017-04-03 09:06:09 -07:00
Jeff Sharkey
fe9a53bc45 Consistent dump() permission checking.
This change introduces new methods on DumpUtils that can check if the
caller has DUMP and/or PACKAGE_USAGE_STATS access.  It then moves all
existing dump() methods to use these checks so that we emit
consistent error messages.

Test: cts-tradefed run commandAndExit cts-dev -m CtsSecurityTestCases -t android.security.cts.ServicePermissionsTest
Bug: 32806790
Change-Id: Iaff6b9506818ee082b1e169c89ebe1001b3bfeca
2017-04-02 22:29:07 -06:00
Chris Wren
a71b5918b0 restore the title string un UsbDeviceManager
Bug: 32584866
Test: make
Change-Id: I4e4dea064a1af194db5660b0765cc4c4b666584a
2017-03-31 15:39:12 -04:00
Chris Wren
282cfefea0 standardize system notification IDs
All the trivial cases, plus some fixes to try to
mitigate collisions with the complex ones.

Complex services to follow in another CL,

Bug: 32584866
Test: make framework services
Change-Id: Ie9663600171d8ede11676e9d66f009dbb06def03
2017-03-31 11:44:05 -04:00
Esteban Talavera
f934d17bfb Restart USB stack if data transfer becomes unavailable
If DISALLOW_USB_FILE_TRANSFER is set while the device is
connected via USB and data transfer is enabled, restart
the USB stack to make sure that data cannot be transferred any more

Fix: 34487750
Bug: 34054991

Test: Checked that files cannot be transferred any more as soon as the user restriction is set
Test: cts-tradefed run cts-dev --module DevicePolicyManager --test com.android.cts.devicepolicy.UserRestrictionsTest

Change-Id: I129c226e57da2d0be356f93436b36b3303cb604c
2017-03-28 16:47:18 +01:00
Badhri Jagan Sridharan
dca36e4e27 Persist functions for oemOverride across reboot
persist OEM specific functions across boot using overlays when
ro.bootmode is NOT unknown
i.e. when phone boots up into a predefined Oem mode.

The overlay tuple has 4 columns instead of three where the fourth column
is optional. When the fourth column is present, the functions mentioned
there would be persisted across reboot along with adb(if enabled).
The fourth column is read during USB device manager set up
@readOemUsbOverrideConfig.

When trySetEnabled function is called, the override function is applied
and the actual oem functions are persisted in
persist.sys.usb.<bootmode>.config.
This property is used in an "on boot" property trigger to set up the
persistent function early in the boot.
(Similar to the way persist.sys.usb.config is used to setup the
USB functions during normal boot).
persist.sys.usb.<bootMode>.func tracks the functions without override.

For example, when the following tuple,

usbradio:adb:diag,serial_cdev,rmnet_gsi,adb:diag,serial_cdev,rmnet_gsi

when ro.bootmode is usbradio, and mCurrentFunctions is adb,
the actual functions enabled would be diag,serial_cdev,rmnet_gsi,adb
(sys.usb.config) and diag,serial_cdev,rmnet_gsi would be
persisted across reboots through persist.sys.usb.usbradio.config and
the functions would be saved in persist.sys.usb.usbradio.func

Bug: 31947358
Change-Id: Ifaef17f6943c1e70721cdc8489f17e3ece03bbfc
2017-03-20 21:48:55 +00:00
Yifan Hong
60968b9783 Merge "IUsb uses "default" service name" 2017-03-20 17:51:14 +00:00
TreeHugger Robot
b234748565 Merge "format cleanup(intellij)" 2017-03-17 23:24:00 +00:00
Yifan Hong
e67d3bb2ba IUsb uses "default" service name
The getService() and registerAsService() methods of interface objects
now have default parameters of "default" for the service name. HALs
will not have to use any service name unless they want to register
more than one service.

Test: pass

Bug: 33844934
Change-Id: I7c1691daf029fb426873be79553a235c43df9f42
2017-03-17 00:40:01 +00:00
Glenn Kasten
24b7831f8b Merge "USB audio: fix imports" 2017-03-16 23:37:42 +00:00
Glenn Kasten
967e832200 Merge "Add units to variable names" 2017-03-16 23:00:29 +00:00
Badhri Jagan Sridharan
eb26052f3c format cleanup(intellij)
Change-Id: Idfa4cc769ec6726be86086879541476d9ed1d12e
2017-03-16 15:08:40 -07:00
Glenn Kasten
8066b89c48 USB audio: fix imports
Test: builds OK
Change-Id: I122e885def74b0f26786eb92a26a8cafed2f65f4
2017-03-13 09:26:11 -07:00
Hugo Benichi
a5af24cd02 Merge "Minor formatting cleanup to remove overlong line" am: d6998d4bd6 am: cc935f5e6d
am: 3d61c89305

Change-Id: I1a4311525a7b9674daa3713ca3ec7001d4bb30fe
2017-03-13 07:40:25 +00:00
Hugo Benichi
cc935f5e6d Merge "Minor formatting cleanup to remove overlong line"
am: d6998d4bd6

Change-Id: I3a4582ebfc1cb7436e570e37cacbc3cabf8c0182
2017-03-13 07:31:54 +00:00
Hugo Benichi
d6998d4bd6 Merge "Minor formatting cleanup to remove overlong line" 2017-03-13 07:23:06 +00:00
Badhri Jagan Sridharan
9fd6645637 Merge "Introduce debounce to filter rapidly toggling type-c ports" 2017-03-10 23:23:51 +00:00
TreeHugger Robot
7e86a8ebf9 Merge "Fix handling usb dialog for wall chargers." 2017-03-10 23:22:43 +00:00
Badhri Jagan Sridharan
763165803e Merge "Reformat code" 2017-03-10 20:46:29 +00:00
Badhri Jagan Sridharan
c4616503b3 Reformat code
Moving to Intellij coding format

Change-Id: I412232183f50dcb7f66bce2f07a07e242114eaa8
2017-03-10 18:48:12 +00:00
TreeHugger Robot
40cd0544bc Merge "minor cleanup" 2017-03-10 00:42:01 +00:00
Badhri Jagan Sridharan
abd229b71a 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.

Cherry-pick: https://android-review.googlesource.com/#/c/338266/
Bug: 34972898
Test: notification should not be queued for a pixel-c charger not connected
to the power outlet.
Change-Id: I4aa19f9f864fe5b77e65f6a07a3184d8aba1f5fc
2017-03-09 23:23:55 +00:00
Badhri Jagan Sridharan
843aba7745 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.

Cherry-pick: https://android-review.googlesource.com/#/c/338265/
Bug: 34972898
Test: Charging notification should not show for pixel-c chargers.
Change-Id: I8dddcd7727b6af973bd173d2c6e325aa4be2ca3a
2017-03-09 23:17:23 +00:00
Badhri Jagan Sridharan
bb85be4261 minor cleanup
Change-Id: I9531bb03a0bf6e92895caa6b91053445f29b5a46
2017-03-09 11:38:46 -08:00
Glenn Kasten
d929cb1d92 Merge "USB audio: Use 'final' where possible" 2017-03-09 16:22:34 +00:00
Glenn Kasten
cb8724c572 Merge "Comment out unused methods" 2017-03-09 16:22:15 +00:00
Glenn Kasten
e5377dd023 Merge "Fix typo in log" 2017-03-09 16:21:45 +00:00
TreeHugger Robot
eb7ca5ca3a Merge "Skip the MTP notification when the system has the default app." 2017-03-08 03:26:13 +00:00
Glenn Kasten
615c793c31 Add units to variable names
Test: compiles OK
Change-Id: I11ec8025686aea0068ce4353df6afea3b9fc2d13
2017-03-06 17:43:49 -08:00
Glenn Kasten
3fcf85cd91 Comment out unused methods
Test: compiles OK
Change-Id: I6f5513e7c5655e91e4cc3dd8de8ec407b9f7b94e
2017-03-06 17:42:21 -08:00
Glenn Kasten
ff6615f653 USB audio: Use 'final' where possible
Test: compiles OK
Change-Id: I14677ef55b14ae0cc60b6145350e70c475cc987e
2017-03-06 17:41:47 -08:00
Glenn Kasten
7f8cf37da3 Fix typo in log
Change-Id: I5e805f4e4f296e7a9e8d12bf8372515f59099f17
2017-03-06 16:52:20 -08:00
Daichi Hirono
a455dd9f09 Skip the MTP notification when the system has the default app.
Before N, when MTP device is connected to Android, it opened the
activity selector for applications that could handle the MTP device.
For N, we updated the behavior to make it consistent with other storage
devices like USB mass storage. In N, the system showed the notification
first, then showed the activity selector after a user taps the
notification.

The N behavior causes a problem that the user always needs to tap the
MTP notification even after the user select a default application for
the MTP device.

The CLs tweaks the behavior for O so that the system can skip the MTP
notification if the system has the default app for the connected MTP
device.

The default app is one of them:

 * App selected by a user by clicking "Always use" in the activity
   selector
 * System app that is an only application which can handle the MTP
   device in the system
 * App that is an only application which can handle the MTP device in
   the system where config_disableUsbPermissionDialogs=true.

Bug: 32119378
Test: Connecting MTP device to Android, which automatically opens system
      app. Connecting PTP device to Android, which shows a notification.
      Tapping the notifiction opens the acitivity selector.
Change-Id: I51f1d55e8c7d1db87d91ddf966631d275a171546
2017-03-03 09:24:34 +09:00
TreeHugger Robot
7bf141233b Merge "IServiceManager/ITokenManager uses "default" service name" 2017-03-01 23:06:02 +00:00
Geoffrey Pitsch
af759c52ce Channels for Frameworks notifications
Adapts all notifications used by system services to use channels.
Channels are initialized by SystemServer after the NotificationService
has started.

Test: runtest systemui-notification
Change-Id: I25c45293b786adb57787aeab4c2613c9d7c89dab
2017-03-01 10:17:15 -05:00
Tomasz Wasilczyk
4d3453637c Fix few typos.
Test: manual (watching logs)
Bug: b/35805636
Change-Id: I066e8f94e73232eb59bef86fff4a4eef5d84fbb4
2017-02-28 08:27:52 -08:00