85 Commits

Author SHA1 Message Date
Colin Cross
eb652a47a1 Convert services to Android.bp
See build/soong/README.md for more information.

Test: m checkbuild
Change-Id: I417409281c928ea667d937090d2a0d9d72a449a2
Merged-In: I417409281c928ea667d937090d2a0d9d72a449a2
Exempt-From-Owner-Approval: trivial conversion
(cherry-picked from commit e0b2ee52d2f274a2d46b2e6695e42d2764c39fa7)
2017-12-12 23:22:25 +00:00
Xin Li
220871a697 Merge commit '98e12851336b7db16e583f9afac63ecc97465980' from
oc-mr1-dev-plus-aosp-without-vendor into stage-aosp-master.

Change-Id: Ia7b8da4a00d215160e4a4fa40f6044208d1297b7
Merged-In: I19846d2a3ee27aecbae2367a74ee49082eea154d
2017-11-14 12:31:11 -08:00
Koji Fukui
05b6857f6b Stop observing death of PrintManager listener when it is removed
Symptom:
Global reference table overflow happens on system_server.

Root cause:
When a listener is added to the PrintManager, death notification for
the listener is registered. So the listener is added to global
reference table.
But the death notification is not unregistered when the listener is
removed from PrintManager. The listener isn't removed from the global
reference table until client process die. If client process repeatedly
add/remove listener, the global reference table overflow.

Solution:
Call unlinkToDeath() when the listener is removed from PrintManager.

Test: cts-tradefed run cts-dev -m Print
Bug: 68746445
Change-Id: I0b133e4607317a15e51bdf6e1248552dcc920d6d
2017-11-13 08:27:21 +00:00
Narayan Kamath
973d8af11b PrintManagerService: Don't prune services on all package change events.
We should only need to prune services if the package that changed
had a print service or has been changed to have a print service.

Bug: 63019430
Test: Manual; observed that the print spooler isn't started up.
Test: run cts -m CtsPrintTestCases

Change-Id: I32df27e4b1d11615cf6053dd3d35c2b60068d0d3
2017-08-01 10:09:33 +00:00
Philip P. Moltmann
6870033d37 Enforce permission for print system APIs
The permission is preinstalled as we want to leave the PrintSpooler
unpriviledged.

Test: Checked that Settings, PrintSpooler and BuiltInPrintService still
      behave as expected.
Fixes: 62350107
Change-Id: Id33896f2899533f2d05cafa926df29cf1c6bfa77
2017-07-14 16:16:13 -07:00
Jeff Sharkey
5ab0243330 Only require that system UIDs tag their sockets.
Apps with a normal UID are typically isolated enough to not require
socket tagging; we're mostly interested in tracking down internal
UIDs that have lots of code sharing the same UID.

Also fix up everyone doing manual string checks of Build.TYPE, since
we now have first-class fields for those.

Bug: 38126076
Test: builds, boots
Change-Id: I3a40348196bd8459289f2b9355d9783a07f1e7dd
2017-06-27 11:11:06 -06:00
yangbingqian
a76f1cbd1d Merge "remove the lock-use for prunePrintService in case blocking main thread" am: b124bea782
am: 60246acdbf

Change-Id: If773ac8166bee1e92168f4df7a9de2dd7cea190f
2017-06-13 20:48:10 +00:00
yangbingqian
82cff68a3a remove the lock-use for prunePrintService in case blocking main thread
As in the change: I4f4cdaba65132dc2ef054877cbb097b499a723f6
the lock object is removed when calling RemotePrintSpooler
and so as it in the method prunePrintService(). But in the
constructor of UserState, the mLock is still held when calling
prunePrintService(), it may also block the main thread

It is better to take it out of the synchronized block

Test: null

Change-Id: I709b491d611dbcbf21a5fd493b879ed290dd0247
Signed-off-by: yangbingqian <yangbingqian@xiaomi.com>
2017-06-12 22:45:50 +08:00
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
Jeff Sharkey
c06f184ae9 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-12-02 15:17:20 -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
1d6e7cc536 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-29 21:29:34 +00: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