114 Commits

Author SHA1 Message Date
Daulet Zhanguzin
c8df11aa79 Replace com.android.internal.util.Preconditions.checkNotNull with
java.util.Objects.requireNonNull

Removing variable self assignments. This wasn't an issue with
checNotNull because of difference in input and output types, but
requireNonNull doesn't add any attributes.

Bug: 126528330

Test: Treehugger
Change-Id: I6dc5c489ceec1f118bf7f3c21c3206f0b4477f70
2020-01-02 13:00:48 +00:00
Jiyong Park
bae2e90796 Add filegroups for services.* libraries
... in preparation for creating a stub library from services.jar

Bug: 139391334
Test: m
Change-Id: Ifd6cfc77acf2284804a2f64011c2733b5c222369
2019-11-17 14:05:08 +09:00
Philip P. Moltmann
c137f1c679 Add TEST_MAPPING for print and pdf tests
Test: TH
Change-Id: I7157c630fccb8b4d50672ac014e5cd020f1ac71f
2019-10-11 14:53:15 -07:00
Philip P. Moltmann
be538c26d5 Bind print svcs as "in foreground" for location
Test: Interacted with wifi-direct printers
Fixes: 132715500
Change-Id: Icead54500bf1557e88139a3b37085d3579d526fc
2019-05-14 13:50:48 -07:00
Julia Reynolds
25c0e878bc Post system_server toasts as system_server
Test: atest com.android.cts.devicepolicy.MixedProfileOwnerTest#testPrintingPolicy
Change-Id: I7ac337dee93bc3843ef2440c2ce7a3b6f7ce094e
Fixes: 119169211
2018-11-26 19:32:43 +00:00
Gopal Krishna Shukla
11e9d9d1ba Merge "Avoid onServiceDisconnected() for unbind Service" am: a37c252248 am: c38e0f19c1 am: 2a126b05a2
am: 4775d87ca7

Change-Id: Ibdff3b0f1f0f5a631161ca11794e8e1fbc2f2d59
2018-07-23 14:00:31 -07:00
Gopal Krishna Shukla
c38e0f19c1 Merge "Avoid onServiceDisconnected() for unbind Service"
am: a37c252248

Change-Id: I825afa6ce1a341f37687fb453a1eeda1ad19ae86
2018-07-23 12:10:57 -07:00
Gopal Krishna Shukla
9117037dd3 Avoid onServiceDisconnected() for unbind Service
onServiceDisconnected() and unbindLocked() both
are responsible to make mRemoteInstanceas null,
so ensure that the service is not unbinded already
while calling onServiceDisconnected()

Fixes:111631529
Test: Build Successful and device Running.
Change-Id: I505d97e32c4e76f06a358850e91fe189bf02654c
2018-07-23 15:44:28 +00:00
Jeff Sharkey
5aae0c9df7 Utility methods useful for working with files.
Part of getting DocumentsUI ready for building against public API.

Test: builds
Bug: 110959821
Change-Id: I7cc0acd5ac3bcc89790cb49f34291ae523e44019
2018-07-11 14:41:24 -06:00
Philip P. Moltmann
b3baaab4af Allow Print subsystem to work with services provided by instant app
Most functionality works, but the PrintActivity cannot directly interact
with the instant service.

As instant services should only appear in tests this functionality needs
to be enabled via shell commands.

Fixes: 79484768
Test: cts-tradefed run commandAndExit cts-instant-dev -m CtsPrintTestCases
      cts-tradefed run commandAndExit cts-dev -m CtsPrintTestCases

Change-Id: Ie4663c72b8c0f959b5d172ef28875479d120e386
2018-05-10 15:26:39 -07:00
Vladislav Kuzkokov
0ec75beab7 Merge "Check printing restriction for correct user." 2018-02-26 16:11:10 +00:00
TreeHugger Robot
1dcd645789 Merge "Use PooledLambda in print code" 2018-02-23 21:21:20 +00:00
Eugene Susla
9f35ca9964 Use PooledLambda in print code
This replaces the usage of handler message types with PooledLambda

Test: atest CtsPrintTestCases
Change-Id: I19b01278b67b5fe18d48a2e0bb8300bbe1413a63
2018-02-23 11:09:29 -08:00
Vladislav Kuzkokov
bc630497b4 Check printing restriction for correct user.
Work profile uses the same instance of PrintManager and DPM
as the primary user. We have to explicitly check restriction for calling user.

Bug: 73768054
Test: Set restriction in Work profile, check that it applies only in work profile.
Change-Id: Iaa63ce000fc84b7d0ee2bd0ff008f1c0f7272a87
2018-02-23 17:49:14 +01:00
Philip P. Moltmann
e65a9b8ebe Create print job when print activity starts
This guarantees that the print job is created before the print activity
deals with it.

Test: CtsPrintTestCases
Change-Id: I3451fff71bd981beb45882b7b42d4cc49d63a91c
Fixes: 73127052
2018-02-21 14:40:17 -08:00
Andreas Gampe
bbab23ff97 Frameworks: Annotate trivial @GuardedBy in services/ misc
Add @GuardedBy for simple functions that require a single lock
and are named XYZLocked.

Derived by errorprone.

Bug: 73000847
Test: m
Test: m javac-check-framework RUN_ERROR_PRONE=true
Change-Id: Id1d9fbe5018250e3b9d1466fc5f670d5ad902fa3
2018-02-08 02:19:42 -08:00
Vladislav Kuzkokov
622b9f9212 Make printing policy a restriction.
Use existing API instead of creating new method.

Bug: 64140119
Test: cts-tradefed run cts-dev --module CtsDevicePolicyManagerTestCases --test com.android.cts.devicepolicy.MixedDeviceOwnerTest#testPrintingPolicy

Change-Id: I9ff94f4d73824e7bf9aedbb64811ad60fccf9779
2018-02-05 22:30:05 +01:00
Philip P. Moltmann
371a3b879b Dump usb as DualDump
This allows to dump the USB state as proto-buf. This in turn allows to
automatically process this data.

Test: adb shell dumpsys usb
      incident_report usb
      No automated test possible as no field is guaranteed to be set
Change-Id: Ifdf22bfaf9c78226c420b11c43278013ce69f849
2018-02-02 16:40:26 -08:00
Vladislav Kuzkokov
fef75eee1d Fix Printing policy in profile owner.
Sometimes app inside profile can't get package info for its owner.
Instead of relying on calling user id, we make PrintManagerService switch to
system id and pass user that called print() explicitly.

Bug: 72309652
Test: cts-tradefed run cts-dev --module CtsDevicePolicyManagerTestCases --test com.android.cts.devicepolicy.MixedDeviceOwnerTest#testPrintingPolicy
Test: cts-tradefed run cts-dev --module CtsDevicePolicyManagerTestCases --test com.android.cts.devicepolicy.MixedManagedProfileOwnerTest#testPrintingPolicy
Test: cts-tradefed run cts-dev --module CtsDevicePolicyManagerTestCases --test com.android.cts.devicepolicy.MixedProfileOwnerTest#testPrintingPolicy
Test: bit FrameworksServicesTests:com.android.server.devicepolicy.DevicePolicyManagerTest
Change-Id: Ib97018f56693549fbca506dba6efaadb6dd010b3
2018-01-24 15:24:08 +01:00
Vladislav Kuzkokov
792d58fbce Implement Policy to disable printing.
This adds a new "isPrintingEnabled" policy (true by default)
and hooks it into PrintManagerService.

Bug: 64140119
Test: manual

Change-Id: Ifb0f6772af51e6185135e9dcf5551e9ef0d88af3
2018-01-18 17:18:54 +01:00
Philip P. Moltmann
bd62e9ae14 Follow up I1f0c56651eaa59f0ce90cdb08c71e89a96c48dd4
Beside addressing the comments on this change, this adds a check that
the token in end( is correct and prints a message if not. This is useful
when creating new dumping methods.

Test: adb shell dumpsys print
Change-Id: Ic2e6152cbd82f98d9d305a15edffc69c55fd1fd3
2018-01-17 09:33:14 -08:00
Philip P. Moltmann
9a534c01ec Only have one way of dumping print manager state
Add a class DualDumpOutputStream that maps proto-dump commands onto
print writer commands.

The effect of this is that there is only one - very proto dump like -
way to dump the print manager which is much easier to maintain.

The DualDumpOutputStream tries to produce a result similar to the
incident-report tool.

Test: adb shell dumpsys print
Change-Id: I1f0c56651eaa59f0ce90cdb08c71e89a96c48dd4
2018-01-16 14:06:13 -08:00
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
Colin Cross
e0b2ee52d2 Convert services to Android.bp
See build/soong/README.md for more information.

Test: m checkbuild
Exempt-From-Owner-Approval: trivial conversion
Change-Id: I417409281c928ea667d937090d2a0d9d72a449a2
2017-12-08 21:00:15 +00:00
Eugene Susla
2f5ee71ec8 PooledLambda
This introduces PooledLambda - a way of obtaining lambdas without the
allocations overhead.

See PooledLambda javadoc for a guide and PooledLambdaSample for code samples
of useful usages.

Test: ensure samples of PooledLambdaSample work as described.
Change-Id: I46f8ad27bc1de07e19f6e39f89d2cafe4238497a
2017-12-05 10:46:59 -08: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
a9a65af6ac Merge "Stop observing death of PrintManager listener when it is removed" am: e7240a52e2 am: 5cb172d17e
am: 9e3ff42caa

Change-Id: I3d643e52e86bbd4ff9bd588fba51fce82fbb35e9
2017-11-14 12:09:39 +00:00
Koji Fukui
9e3ff42caa Merge "Stop observing death of PrintManager listener when it is removed" am: e7240a52e2
am: 5cb172d17e

Change-Id: I2169c5d3a0a1d8b4bd6729c4ca56b7a1de2a6249
2017-11-14 01:51:30 +00: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
Philip P. Moltmann
4b89d63b63 Don't dump print state while holding lock
This causes ANRs as we are trying to the the print spooler connection
while holding a lock that can also be aquired on the system server's
main thread.

Fixes: 63159459
Test: cts-tradefed run singleCommand cts-dev -m Print
      adb shell dumpsys print
      incident_report print
Change-Id: I228fc5ddc10c1c89f61e8a6d8eb8ea9e384197a8
2017-08-29 10:15:07 -07:00
Narayan Kamath
0515c80d01 Merge "PrintManagerService: Don't prune services on all package change events." into oc-mr1-dev am: 735ed6c011
am: e81a350a45

Change-Id: I3964de47b70c27c372d80cfce5107fd216ded6cd
2017-08-01 11:57:28 +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
c0a128dc2b Dump print manager as proto
Test: incident_report print. Having no entries
Change-Id: I3c7d611e44c0d3bf8e00775b1708bd82a334121a
2017-07-25 11:32:24 -07: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