75 Commits

Author SHA1 Message Date
Eugene Susla
0d3dd12fa0 Move CompanionDeviceManagerService to a place of its own
Fixes: 37473452
Test: Ensure companion devi9ce functionality still works
Change-Id: I89624217373b3e77296c71f9429387d99d15e236
2017-04-18 12:00:11 -07:00
Eugene Susla
cf00adebec API for notification listener for Companioon apps
Test: 1. Trigger the confitrmation dialog.
Ensure it looks exactly like the one from settings.
2. Call an API without associating the appa first
Ensure exception is thrown with a message mentioning the need to associate 1st
Change-Id: I94d4116e1988db869ed445ae3fd018c50590e3f4
2017-04-14 19:01:53 -07:00
Eugene Susla
4df89bcb31 [DO NOT MERGE] Fix associations serialization optimization bug
There mas a missing defensive copy causing false positive detections of
"associations not changed" case, leading to xml file not being updated once
at least one record is present

Bug: 30932767
Test: Associate at least two different devices and ensure the xml has both.
Change-Id: Ic0dc615dd2b847e137555c1084c616831b4dde83
2017-04-14 23:21:44 +00:00
Eugene Susla
200c37f413 [DO NOT MERGE] Stop scan on device chooser activity backgrounded
This effectively treats chooser activity pause event as cancel.

Bug: 30932767
Test: Install two toy apps and call associate API from both.
  Ensure foreground app always end up showing fresh data.

Change-Id: I7f5742e9878245550f678efd244bf84c427baef3
2017-04-14 23:17:04 +00:00
Eugene Susla
adce09b9a4 Add ICompanionDeviceManager.getAssociation overload with explicit userId
Bug: 30932767
Test: ensure getAssociations works as before
Change-Id: I58dc4dac5bf7aae83fe3611890116a928e290a43
(cherry picked from commit 544d714626db38714f826a31a5483c647510a743)
2017-04-07 17:51:52 +00:00
Philip P. Moltmann
7e01895e69 Return inet addr for discoverable printers
... by extending the RecommendationInfo to store the inet addresses not
just the count. Thankfully the recommendation plugins already contained
all the printers, not only the count.

Also expose the print service state as system APIs as they will be used
by the default print service.

Bug: 35765644
Test: Ran AddPrinterActivity on network that had printers to discover
Change-Id: I929a177adb75f6848848ba30a472cf0343d2e67e
2017-04-06 11:54:53 -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
Eugene Susla
a38fbf63fd Unbind from service on app killed and dedup association requests
1. Listen to calling package binder death stopping the scanning on that.
2. Don't restart scanning when a request with the same values was made.

Bug: 30932767
Test: 1.:
  - Using a test app start scanning and kill the app.
  - In debug mode ensure that DeviceDiscoveryService#stopScan gets triggered
2.:
  - Start scanning and rotate the device while device chooser is visible
  - Ensure no visible loss of state is happening
Change-Id: If126a2c963da90172a956fbd88e6b3dcd7ac8b01
2017-03-24 14:03:17 -07:00
Eugene Susla
6a7006a968 Register PackageMonitor for CompanionDeviceManagerService
1. On package removed -> remove all its associations
2. On package updated -> if had associations, update special access permission
in accordance with (potentially changed) permission entries in manifest

Bug: 30932767
Test: 1. Remove app, and ensure xml entries for it got removed.
2. adb install new version of app without special permissions in manifest, and
ensure whitelist removal method got called
Change-Id: I87261c05ddcf40a18332d160b44ee2f8284df5e4
2017-03-20 13:38:58 -07:00
Eugene Susla
36e866b8e0 Support multiple filters per association request
By supporting multiple filters per one request we should be able to cover
multiple kinds of use cases such as:
 - Letting the user select from a list of devices of more then one medium
 type (e.g. Bluetooth and BLE)
 - Allowing to provide multiple criteria for any field (e.g. filtering by
 more than one service UUID)

Bug: 30932767
Test: Provide multiple filters and ensure that devices matching either are
shown in the list to choose from.
Ensure wifi SSIDs are shown in the list if wifi filter is provided

Change-Id: I0a978787551a1ee5750ec5544b241d3bbfed5a7c
2017-03-09 17:52:49 -08:00
Hector Tellez
d66c95fa90 Revert "Support multiple filters per association request"
This reverts commit e70e6aa62c6f3a9a79624a4f9d97df95edda0364.

Change-Id: I12857cbbea0a0c74521191ab5e3713db230626ab
2017-03-09 17:55:43 +00:00
Eugene Susla
e70e6aa62c Support multiple filters per association request
By supporting multiple filters per one request we should be able to cover
multiple kinds of use cases such as:
 - Letting the user select from a list of devices of more then one medium
 type (e.g. Bluetooth and BLE)
 - Allowing to provide multiple criteria for any field (e.g. filtering by
 more than one service UUID)

Bug: 30932767
Test: Provide multiple filters and ensure that devices matching either are
shown in the list to choose from.
Ensure wifi SSIDs are shown in the list if wifi filter is provided
Change-Id: I6621da388e2bf4ed97c5af2692629a321d0b63c7
2017-03-08 16:52:14 -08:00
Eugene Susla
47aafbe033 Record app<->device association to xml file
Bug: 30932767
Test: Ensure file not exists -> query associations -> ensure result is empty list
  Associate device -> cat xml file -> ensure record appears as extected
  Disassociate device -> cat xml file -> ensure record is no longer present
Change-Id: Ibe456a6d9292e05e2391f5138e43fdaa37f87e1b
2017-03-06 16:53:32 -08:00
Svet Ganov
da0acdf938 Auto-grant background execution and data access
Companion apps can declare they want background access and
background execution exceptions via dedicated permissions
in their manifest. If such a permission is requested we
auto-grant the corresponding exception after the user has
chosen a device from the companion UI. These permissions
are appop ones allowing us to use the app ops for gauging
whether the user has made a change after we auto-granted
the permission since we would like to revoke these special
privileges when the app disassociates itself from the
companion device if the user did not make an excplicit
choice otherwise.

While at this auto-grant fixed location permission to the
companion device discovery service.

Test: manual

Change-Id: I46ee4291e5e5a8f7613f0dd75eb61d6b9341f306
2017-02-15 20:32:41 -08:00
Eugene Susla
6ed45d8cd3 CompanionDeviceManager
This introduces an API for apps that support companion devices to provide a
more streamlined flow for pairing and setting up the device

Bug: 30932767
Test: Using a toy app, invoke the newly introduced API (CompanionDeviceManager),
 and go through the flow. Ensure filtering works, and device is returned to
 the calling app. Ensure the calling app can pair to the selected device.
Change-Id: I0aeb653afd65e4adead13ea9c7248ec20971b04a
2017-02-06 12:50:55 -08:00
Philip P. Moltmann
126913cb3a Ignore commands if service connection is destroyed.
Test: Print CTS tests (currently affected by b/33449823). Print spooler
      unit test
Fixes: 33106285
Change-Id: I5c771b17992ef627ce5ac3a66a02358c4540893c
2016-12-15 10:53:02 -08:00
Philip P. Moltmann
76932df9ec Merge "Wait when other thread is binding to print spooler" 2016-11-21 19:21:24 +00:00
Sudheer Shanka
dc589ac82b Update usage of ActivityManagerNative.
- Remove references to ActivityManagerProxy.
- Add isSystemReady to ActivityManager.

Bug: 30977067
Test: cts/hostsidetests/services/activityandwindowmanager/util/run-test android.server.cts
      adb shell am instrument -e class com.android.server.am.ActivityManagerTest,com.android.server.am.TaskStackChangedListenerTest \
          -w com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
Change-Id: I07390b6124fb1515821f5c0b37baf6ae74adc8fa
2016-11-14 11:27:12 -08:00
Philip P. Moltmann
93a2249369 Wait when other thread is binding to print spooler
Fixes: 32581183
Test: print cts and workflow tests
Change-Id: I3c6ccc40a1ea6504d2e25ec402cecf31d724865b
2016-11-10 14:25:32 -08:00
TreeHugger Robot
c4f65e0da8 Merge "Move dump() to dumpAsync(), more oneway calls." 2016-11-09 21:08:01 +00:00
Jeff Sharkey
850c83e6da Move dump() to dumpAsync(), more oneway calls.
When calling out to dump services hosted by external apps, use
dumpAsync() to avoid hanging if the remote process is wedged.

Test: builds, boots, runs with minimal logs triggered
Bug: 32715088
Change-Id: I70aa2666ae21dae8f09ded2063bed359c0b210c5
2016-11-09 12:25:48 -07:00
Tamas Berghammer
383db5ebcc Update package names to work with the proto3 compiler
Bug: b/28974522
Change-Id: I5f3adf4946ee4ba1e09e4f40afe83c151405972a
2016-11-08 14:06:09 +00:00
Fyodor Kupolov
e5d91213d0 Do not enforce unlocked state for system calls
isUserUnlockingOrUnlocked should be enforced for calls made by apps.
Calls from system server should be handled gracefully.

Test: manual
Bug: 31833240
Change-Id: If56b0f9994209eb45a47072e0377d11293a9cbad
2016-10-06 14:22:11 -07:00
Philip P. Moltmann
e2ad85d230 Hold no locks when calling RemotePrintSpooler
The calls might be blocking and need the main thread of to be unblocked
to finish. Hence do not call while holding any monitors that might need
to be acquired the main thread.

The calls that have been moved out of the lock:
- Icon related calls: These are just caches. Hence we flush the cache we
  just request the icon again
- Prune call: This just removes not installed print service from some
  data structure. The order of two of these calls does not matter as
  the end result of both removals will be the same, regardless of order.

Testing done: Reinstalled a print service multiple times. Before the
first reinstallation locked up the userState, now not anymore

Change-Id: I4f4cdaba65132dc2ef054877cbb097b499a723f6
Fixes: 31043684
2016-08-24 09:27:46 -07:00
Philip P. Moltmann
df4a7ad5d1 Merge \\"Always reload print services\\" into nyc-mr1-dev am: fd28d8ebd1
am: 14a4ec6574

Change-Id: I4d6afaca275e5596d601c707eeea928d4f089932
2016-06-28 18:37:39 +00:00
Philip P. Moltmann
0de4834dd8 Always reload print services
We want to reload print service if anything relevant changed. E.g. this can
be the label. Which label is loaded depends on the the resolve info and
the package manager. Hence short of reverse engineering what fields are
used to determine how this is done it is very hard to say how we figure
out the label.

Hence the only option we have is to reload the print services every time
a print services is added, removed or changed.

Change-Id: Iff5a05dd1cad923da42c360a88559a2cc61c95aa
Fixes: 29765394
2016-06-27 23:25:23 +00:00
Philip P. Moltmann
2e3012624b Add event tracking to print UI.
Bug: 29391676
Change-Id: Iec09ac7296e50329e87268bcb70f5e60d566961c
2016-06-20 11:50:44 -07:00
Philip P. Moltmann
e8bffdccd1 Reconnect to service when it is updated
- Remove service from mActiveServices when the binder died. (before update)
- Treat the failure to bind as if when the binder dies. (while updating)

If the service is removed for mActiveServices, onConfigurationChanged will
automatically restart the service.

Fixes: 27977706
Change-Id: I643248f56a9f2f4b7dce63cc1489a60739ab4537
2016-05-10 15:50:12 -07:00
Philip P. Moltmann
f8a765bce2 Merge "Check if records is inited before removing items" into nyc-dev 2016-05-02 23:32:39 +00:00
Philip P. Moltmann
640918f911 Check if records is inited before removing items
The record might already be removed and the records array set to null
when the binder dies, hence handle the scenario.

Bug: 28512952
Change-Id: Id21b03b6d14d1dc8cb792ee4ec0519287a289a33
2016-05-02 09:46:22 -07:00
Philip P. Moltmann
efb1950263 Check if user is unlocked when handler is executed
When the user gets unlocked we schedule a handler-runnable to do cleanup work.
This runnable might be executed after the user is already locked again.

Fixes: 28512952
Change-Id: I6c05cbc8adab699e451565d74d56ad0f9b965954
2016-05-02 09:44:08 -07:00
Jeff Sharkey
ce18c81677 Introduce "unlocking" vs "unlocked" nuance.
There is a narrow window of time during user unlock where we're
reconciling user storage and dispatching the "unlock" status to
various internal system services.  While in this "unlocking" state,
apps need to be told that the user still isn't actually "unlocked"
so they don't try making calls to AccountManager, etc.

The majority of internal services are interested in merging together
both the "unlocking" and "unlocked" state, so update them.

Clarify naming in AccountManagerService to make it clear that a local
list is being used, which mirrors the naming in MountService.

To match UX/PM requested behavior, move PRE_BOOT_COMPLETED dispatch
after the user is unlocked, but block BOOT_COMPLETED dispatch until
after all PRE_BOOT receivers are finished to avoid ANRs.

Bug: 28040947, 28164677
Change-Id: I57af2351633d9159f4483f19657ce0b62118d1ce
2016-04-28 10:51:39 -06:00
Philip P. Moltmann
4bd8fac48e Send update notifications when the status of a print job updates and
make sure to only access mPrintServicesChangeListenerRecords when
locked.

Bug: 28315242
Change-Id: Ie41ee695e6b1b0394e55538b9d9edaee0610f1e0
2016-04-21 15:33:42 -07:00
Philip P. Moltmann
9dcb86a48d Add the print service recommendation service
This service connects through the print manager to the print spooler:

PrintSpooler.AddPrintersActivity <-> PrintManager <-> PrintManagerService <-> UserState <-> RemotePrintServiceRecommendationService <-> PrintRecommendationService <-> PrintRecommendationServiceImpl

Hence there is a lot of mindless plumming.

The actual changes are only in the AddPrintersActivity which is extended
to show another list of services: The recommended services.

The PrintServiceRecommendationService is based on the experimenal print
service stubs provider. This provider was contributed the Android by
Mopria. As this services uses Android own network discovery service most
code from the experimental provider goes away. In fact the only logic
left over is the selections of mdns-txt fields to look at and the
printer vendor configuration.

This relies on the Android MDNS to get fixed (Bug: 27696905). This also
does not deal with how to update the recommendation service.

Bug: 24533249
Change-Id: I6edc6e25fc08a50d478b61c71bb8ea158b08624c
2016-03-30 17:21:07 -07:00
Philip P. Moltmann
59d1c9430a Merge "If the print spooler gets started onUserUnlock use less of a priority to have less impact on the system." into nyc-dev 2016-03-26 18:15:49 +00:00
Philip P. Moltmann
d74d1e5491 Change hasCustomPrintIcon and setStatus as requested by API council.
Bonus: null advanced keys produced a exception deep in the print
       spooler. Hence prevent null keys on the surface from now on.

Bug: 27716355
Change-Id: I3c064956f4e670cd7091437ade06605aa8d797b0
2016-03-24 16:53:36 -07:00
Philip P. Moltmann
e8ae15482e If the print spooler gets started onUserUnlock use less of a priority to have less impact on the system.
Bug: 27746455
Change-Id: I3ae0a755e8f4c212a111d76ec6ef042654589510
2016-03-24 09:29:33 -07:00
Philip P. Moltmann
f0847871ea If services are enabled, services might become enabled in the future
Hence we always, always want to start a session if this is requested.

Bug: 27643066
Change-Id: I0fbf3ea8554de83d5ec6dc61b6b36f3783aab427
2016-03-14 10:14:59 -07:00
Philip P. Moltmann
852c950bbf Correct how to deal with print service installation
- Deal with case that there are currently no print services installed
- Deal with the case that a package modification adds a print service

Bug: 27530312
Change-Id: I67a647bd0982a092a4810d6c1285d0c7b64e104e
2016-03-07 15:32:25 -08:00
Jae Seo
c2c83eeda6 Fix NPE in PrintManagerService
Bug: 27530312
Change-Id: I86800572a93fbcf37f2e073a1eaee6fbe6658de1
2016-03-07 14:30:33 -08:00
Philip P. Moltmann
66c96591e2 Add "app printer activity" and always keep the print service state
updated. Also fiddle with the UI to use more standard values.

To be sure the print service state alwasy updated I changed
PrintManager.getPrintServices to return a loader which just wraps a
registerListener/getList/removeListener combo.

I also added a new function to enabled/disable a print service to be
keep all updating logic inside the PrintManagerService->UserState.

Then I changed all code to use this new interface.

Detailed comments:

PrintServiceInfo:
- I had to add the enabled state to the PrintServiceInfo as some users
  of PrintManager.getPrintServices want all services but then display
  different data depending on the enabled state. Of course I could have
  created two PrintManager.getPrintServices-loaders to load the two
  separate list of services. I think it is much easier to add this
  property though. It is updated every time new data is returned to the
  PrintManager.getPrintServices-loader.

AddPrinterActivity:
- This is shown as a dialog-style overlay to indicate that the user will
  return to the select-printers activity. It contains of three list that
  are updated via separate loaders.
- The recommended services will be added later to keep this path set
  small.

PrintActivity:
- There are two small places where we have to update the data when we
  get a new list of print services.
  - In very, very rare conditions it can happen that the print service
    of the current printer gains or looses the "advancedOptions"
    activity
  - If we have no enabled print services we want to show "Add printer"
    instead of "All printers...".
- Also the print registry is not the only loader anymore, hence we have
  to assign loader ids to it to not conflict with the other loaders in
  this activity.
- Small bug in onPrintersChanged: If a printer is selected and the print
  service of this printer gets disabled the holder goes into "removed"
  state which disables the printer. When the print service is then
  enabled again, we forgot to re-enable the holder.

PrinterRegistry:
- The registry assumed that the FusedPrinterProvider was the only loader
  in the activity. This is not true anymore, hence it has to assign the
  appropriate loader ids.
- The FusedPrinterProvider has an internal loader, hence we have to
  forward a loader Id into it.
- The PrintRegistry is only called backed for a single loader, hence no
  need to check the loader-id.

SelectPrinterActivity:
- The AddPrinterDialog was removed as we now have the
  AddPrinterActivity.
- Added a loader for the enabled services to update the empty state.
- Added dedicated loader Id for the PrinterRegistry again.
- If we have no enabled services, the SelectPrinterActivity chainloads
  the AddPrinterActivity as this is the only thing the user can do
  anyway. "Save a click". This should only happen when the activity is
  create the first time.
- Moved the "add printer" from the menu item to the list of printers as
  suggested by UX and Zach.

PrintManagerService, UserState and IPrintManagerParamtersTest:
- As the only place where the print service state is updated is now the
  userstate, we have no more sychronization problems. Whohoo.
- The users can now register for changes to the print services similar
  as they can register for changes to the print jobs.
- UserState.getPrintServices is the only function can exposes any
  knowledge of the print services to the outside world.

Change-Id: I9be2c7300431e06aaff9bdf7eb36120d869b56ac
2016-03-07 09:58:08 -08:00
Philip P. Moltmann
76d7e3ee70 Check parameters for callers of IPrintManager
- Propagate nullness and non-null-ness up and down from the interfaces.
- Add non-CTS print tests for IPrintManager binder.

Change-Id: I0c310d9cea8aefba5ce386931521ffaf19712bbb
2016-01-21 13:27:30 -08:00
Philip P. Moltmann
cdf2b40034 Enforce non-nullness in PrinterId and exploit it.
Change-Id: Ifdf3b2329548a665d609dd66b738baab5c765b54
2016-01-14 15:59:44 -08:00
Philip P. Moltmann
05e3423070 Deal with UserState#getEnabledPrintServices returning null.
Bug: 26492364
Change-Id: I234b1632168c88d32bdd134630442756701118b6
2016-01-12 09:13:21 -08:00
Jeff Sharkey
cd65448ccd Even more PackageManager caller triage.
Finish moving all UID/GID callers to single AIDL method that requires
callers to provide flags.

Triage AppWidgets and PrintServices, which currently can only live on
internal storage; we should revisit that later.

Fix two bugs where we'd drop pending install sessions and persisted
Uri grants for apps installed on external storage.

Bug: 26471205
Change-Id: I66fdfc737fda0042050d81ff8839de55c2b4effd
2016-01-08 18:35:54 -07:00
Jeff Sharkey
f0e4daecc9 Skip package updates when user is locked.
Bug: 26464060
Change-Id: If762ce799f402571fd0387947f19c824f4a1b000
2016-01-08 12:02:45 -07:00
Philip P. Moltmann
8141bdfa56 Store which print services are disabled instead of which are enabled
This make services that appreared while the print manager was not active
by default enabled.

In the case we upgrade from pre-N we convert the enabled-list into a
disabled-list.

Bug: 26249649
Change-Id: Iae783a8dd19f1a9d75d675710ea4348fdfbd34f3
2016-01-07 09:30:43 -08:00
Philip P. Moltmann
bb36206f08 Rename variable that hides the contatining classes name.
Change-Id: Iad0a9b341a866d33d10b7a389d243e677a65057c
2015-12-22 20:24:58 -08:00
Philip P. Moltmann
bb9f686b40 Allow a print service to specify per printer icons, description and
info-activities

The icon is loaded from the discovery session only when it is displayed
to avoid having to store too many icons in memory.

Also the icons are not maintained in the historical printers. Only if
the printers are available nice icons are shown. A historical printer is
updated with the appropriate properties (including icon) once it becomes
available.

Bug: 24135005
Change-Id: Iec389bab514b024634be8fb5fc8928371cba8740
2015-12-21 09:54:57 -08:00
Jeff Sharkey
0999c0d6e9 Make printing framework encryption-aware.
Only create UserState objects when a user has been unlocked, meaning
we can connect to the spooler.  Ignore package events that occur
while a user is locked, since we'll kick off updateIfNeededLocked()
when that user is eventually unlocked.

In all other cases, throw if someone tries obtaining UserState for
a still-locked user.  This should help catch any edge cases in the
system, and communicate clearly through public APIs that printing
isn't available until the user is unlocked.

Bug: 26246836
Change-Id: If15744621890baee206d355484fe20933afc65d8
2015-12-17 15:12:26 -07:00