OSDN Git Service

Fixes for handling users + default for USB
authorPhilip P. Moltmann <moltmann@google.com>
Sat, 29 Apr 2017 00:25:37 +0000 (17:25 -0700)
committerPhilip P. Moltmann <moltmann@google.com>
Tue, 9 May 2017 17:18:41 +0000 (10:18 -0700)
commitd4b09d4e16a9dc2bb08b1e06b87c02de3f46308c
tree6b672fc42e0bf918f7f76ee1d2765175158f396a
parent7080fa528272d4353e9979cf693e5b4dc1d0db8b
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
services/usb/java/com/android/server/usb/UsbProfileGroupSettingsManager.java