Commit Graph

46 Commits

Author SHA1 Message Date
Eugene Susla
8c2fb0ea1e [DO NOT MERGE] Guard against launching permission backup/restore twice per request
It looks like there is some case where AbstractRemoteService would #run the
same PendingRequest the second time which violates AsyncTask assumption.

Fixes: 135986503
Test: atest android.permission.cts.PermissionControllerTest
Change-Id: I2d072714ee0fad3c365ff7eb191d690056c0931a
2019-06-29 00:20:09 +00:00
Winson
f27394ee70 Expose PermissionManager as TestApi and fix SplitPermissionInfo equality
Bug: 129200416
Bug: 129200610

Test: atest SplitPermissionsTest

Change-Id: I98795944e6440e5b7ebba134bd7735a6f78ebc4f
2019-06-07 15:09:06 -07:00
Nate Myren
17f2159181 set RuntimePermissionPresentationInfo, getAppPermissions, and OnGetAppPermissions as Test Api, added Get Runtime Permissions to shell
Test: Run PermissionControllerTest
Fixes: 129200595

Change-Id: I44cf152e52895d9344b39b978b85ac263a5cb37c
2019-05-28 16:15:16 +00:00
Philip P. Moltmann
1ae81a547e Mark perm DB version as -1 when upgrading from P
So that we can implement different behavior between Android P and Q.

Test: Upgraded P->Q and booted fresh install of Q. Checked DB after boot
Bug: 131427665
Change-Id: I89f9dc1fc11129c95c03834e21628c6be75f2875
2019-05-23 16:14:33 -07:00
Tim Murray
d06c6d2932 Revert "Add optional reasons why permissions were denied"
This reverts commit 3623f3219e.

Reason for revert: 40% startup perf regression

Test: revert
Bug 132129453
Exempt-From-Owner-Approval: critical revert

Change-Id: I19dc33e6a71c9254b4096154f4089c059fe408dd
2019-05-07 07:10:30 +00:00
Philip P. Moltmann
3623f3219e Add optional reasons why permissions were denied
Currently only for the ContextImpl.enforcePermission code paths and only
when 'secure debug_package_permission_check' is set.

This feature is disabled on user-builds.

Test: Enabled permission checking for my app and
      - checked runtime permision denial
      - permission denial because app is instant
Bug: 111075456
Change-Id: Ib85777db69ee490608e9dac32a3b97971c0ba215
2019-05-05 21:05:13 -07:00
Howard Chen
fff50fe62b Remove the Build.VERSION_CODES.P0
The Build.VERSION_CODES.P0 was the stub for a potential new API level
after P. Now it's Q thus the usage for P0 field is not valid any more.
This CL also fixed the android.os.cts.BuildTest test failure for
cf_x86_phone-userdebug

Bug: 131601118
Test: presubmit test on ag/7204147
Change-Id: Iee474e95a35e051e6a3f4f96da5d82387d33d013
2019-04-30 14:35:29 +08:00
Philip P. Moltmann
5ad5cdc394 Merge "Don't use Context#getApplicationContext" into qt-dev 2019-04-26 20:30:18 +00:00
Philip P. Moltmann
d56c6bdfa9 Don't use Context#getApplicationContext
as this might be null. In PermissionControllerManager we need a context
that outlives the passed in context as we bind to a service that will
only get destroyed after a delay.

Test: atest PermissionControllerTest
Bug: 131356152
Change-Id: Iabeac669f6464b84a4b9e8f9b2a27959b116c25b
2019-04-25 16:19:20 -07:00
Philip P. Moltmann
a7f181162e Allow PermissionControllerService implementer control own threading
Hence execute on binder-thread and send callback.

Fixes: 131314749
Test: atest --test-mapping packages/apps/PermissionController/src/com/android/packageinstaller/permission/service:presubmit
Change-Id: Ic5286a1b02532bcc0241877d970d0fc933b27f85
2019-04-25 14:00:28 -07:00
Philip P. Moltmann
188e47bbc5 Call PermissionControllerService on workerthread
As otherwise the mainthread is overwhelmed and blocking.

Test: atest CtsPermissionTestCases:android.permission.cts.PermissionControllerTest
Fixes: 130738002
Change-Id: I1d6cbc60411802cef1c8aedbb6e89430e65b2aa9
2019-04-18 11:05:35 -07:00
Svet Ganov
d8eb8b2690 Restricted permission mechanism - framework
This change adds a mechanism for restricting permissions (only runtime
for now), so that an app cannot hold the permission if it is not white
listed. The whitelisting can happen at install or at any later point.

There are three whitelists: system: OS managed with default grants
and role holders being on it; upgrade: only OS puts on this list
apps when upgrading from a pre to post restriction permission database
version and OS and installer on record can remove; installer: only
the installer on record can add and remove (and the system of course).

Added a permission policy service that sits on top of permissions
and app ops and is responsible to sync between permissions and app
ops when there is an interdependecy in any direction.

Added versioning to the runtime permissions database to allow operations
that need to be done once on upgrade such as adding all permissions held
by apps pre upgrade to the upgrade whitelist if the new permisison version
inctroduces a new restricted permission. The upgrade logic is in the
permission controller and we will eventually put the default grants there.

NOTE: This change is reacting to a VP feedback for how we would handle
SMS/CallLog restriction as we pivoted from role based approach to roles
for things the user would understand plus whitelist for everything else.
This would also help us roll out softly the storage permisison as there
is too much churm coming from developer feedback.

Exempt-From-Owner-Approval: trivial change due to APi adjustment

Test: atest CtsAppSecurityHostTestCases:android.appsecurity.cts.PermissionsHostTest
Test: atest CtsPermissionTestCases
Test: atest CtsPermission2TestCases
Test: atest RoleManagerTestCases

bug:124769181

Change-Id: Ic48e3c728387ecf02f89d517ba1fe785ab9c75fd
2019-04-07 22:39:54 -07:00
Michal Karpinski
322df0bb74 Modify AbstractRemoteService#mBindInstantServiceAllowed to #mBindingFlags
in order to support multiple binding flags

And supply BIND_ALLOW_BACKGROUND_ACTIVITY_STARTS for RemoteFillService.

Test: atest CtsAutoFillServiceTestCases
Test: atest AutofillManagerServiceTest
Bug: 126267782
Change-Id: Id5262d6a4e0fde0ad874020f783cfbf72fe201f4
2019-03-26 11:07:33 +00:00
Joel Galenson
4b4798bb73 Use correct type for permission group name.
I forgot to change the type when I moved this from being the albel to
being the name.

Fixes: 128994612
Test: Call API.
Change-Id: Ie2d7a48512015304fe748c834e60a1ad445c4276
2019-03-20 18:26:33 -07:00
Philip P. Moltmann
4198dd1cd5 Document delayed permission backup mechanism
Test: n/a
Fixes: 127545019
Change-Id: I62494048e2eeda733fabfddc53898b88827d92ef
2019-03-08 15:42:56 -08:00
Hai Zhang
26f37d35f6 Use RoleControllerService for role related APIs.
Move isApplicationQualifiedForRole() and isRoleVisible() from
PermissionControllerService to RoleControllerService.

Bug: 127691087
Test: manual
Change-Id: Ic9277f9e737e59dceafffabbf1e19526db609e78
2019-03-07 22:02:55 -08:00
Hai Zhang
a4959e569d Add RoleControllerManager for role controller service.
This allows us to expose both system-only and app available APIs for
role in RoleControllerService.

Bug: 127691087
Test: manual
Change-Id: I86fe3736fc28516aae25d48efe3ba599ffdf45d5
2019-03-07 21:33:12 -08:00
TreeHugger Robot
983b500cbf Merge "Add PermissionControllerService.isRoleVisible() for app info shortcut." 2019-03-04 22:49:23 +00:00
Philip P. Moltmann
6ce9003ef0 Merge "Add null-checks: RuntimePermissionPresentationInfo" 2019-03-04 20:14:29 +00:00
Philip P. Moltmann
7622add875 Add null-checks: RuntimePermissionPresentationInfo
Also make sure that nullability
- is enforced during creating
- is enforced during un-parceling

Test: Looked at Settings screens that read this data
Fixes: 126702133
Change-Id: I8cdd3a5583f01276702307b40f65fa8d7ac49bf2
2019-03-01 11:31:47 -08:00
Philip P. Moltmann
051f338090 Nullability of PermissionControllerService#onBind
Only set nullability if super-method specified nullability at the same
place too.

Test: Built
Bug: 126701055
Change-Id: I08b9ac43ecb5f200d192a536449a880bc9a91f38
2019-03-01 10:51:08 -08:00
Jeff Sharkey
9e8f83db6d All Parcelable CREATOR fields are @NonNull.
If they were null, then the Parcelable would fail to work.

Bug: 126726802
Test: manual
Change-Id: I7929ffa2f20e5de1c8e68e8263cca99496e9d014
Exempt-From-Owner-Approval: Trivial API annotations
2019-02-28 23:29:04 -07:00
Hai Zhang
d895953d3c Add PermissionControllerService.isRoleVisible() for app info shortcut.
The default app shortcut in app info inside Settings needs to know if
a role is visible, and whether it is visible is controlled logic in
PermissionController, hence add this API.

Bug: 124452117
Bug: 124457823
Test: manual
Change-Id: I6058dea3bbda8b06d2fb9bab35268397227dd37b
2019-02-28 17:01:46 -08:00
TreeHugger Robot
05675bc0cf Merge "Made AbstractRemoteService.getRemoteRequestMillis() optional." 2019-02-23 03:25:46 +00:00
Philip P. Moltmann
41df9f94ae Ask Perm Controller to set policy-fixed perms
This is much slower than the old way as we need to call into a different
process. On the other hand this handles the following cases correctly:
- foreground / background permissions
- pre-M apps
- split permissions

Test: CtsDevicePolicyManagerTestCases:com.android.cts.devicepolicy.MixedManagedProfileOwnerTest#testPermissionGrant,testPermissionPolicy,testPermissionMixedPolicies,testPermissionAppUpdate,testPermissionGrantPreMApp
Change-Id: I5cd139ad29e5b77b77b02e12c75eb774984a7759
Bug: 124128308
2019-02-21 16:56:25 -08:00
Felipe Leme
81299d0d96 Made AbstractRemoteService.getRemoteRequestMillis() optional.
Also split some logic from PendingRequest into BasePendingRequest, so they're
not leaked into the async requests.

Test: atest CtsContentCaptureServiceTestCases CtsAutoFillServiceTestCases
Bug: 117779333
Change-Id: Ife9a3ab3a817944408caf9eae69dd75f48ab90c6
2019-02-21 16:11:26 -08:00
Philip P. Moltmann
cfd2fbc4e3 Make PermissionControllerManager user aware
Most of the commands of PermissionControllerManager should go to the
calling user. If not - and the alternate user is running - we should
use the recommended way to talk to alternate users. This recommended way
is to create a package context for the user and call the method on this
new context.

Hence
- At a time we can have more than one RemoteService (one per user)
- Connect to the user declared in Context#getUser instead of the calling
user

Test: Called methods on work-profiles and saw alternate
PermissionController apps to be spawned.
Change-Id: I9ed87db1f658f18b69d19b39ba9f96361ec5af82
2019-02-16 12:11:38 -08:00
Philip P. Moltmann
4845667a81 Move permission restore code into permission controller.
- Split system-server internal interface in two. One accessible only
  inside of the services part of system server. One accessible
  everywhere. This is necessary as the second part needs to be
  accessible by the PermissionBackupHelper. But the former uses internal
  data structures that should not be moved into android.permission.
- Remove old delayed permission restore code from
  PermissionManagerService and Settings. This code now lives in
  permission controller
- Keep the logic to remember which users still have delayed permissions
  left. It is quite expensive to call into permission controller for
  ever install of an app, hence this check is necessary. Currently this
  mirrors the original logic. This can be improved further later.

Test: Built
Change-Id: Ibc1d5183c361dc55896882db1f7b765e1bee6e84
2019-02-15 08:57:16 -08:00
Philip P. Moltmann
7532c615cb Plumming of perm restore via permission controller
On Android backup restoration first restores and inital state. Then with
the packages getting downloaded the leftover "delayed" backup gets
restored bit by bit.

This currently just created plumming mirroring the previously implemented
behavior.

Bug: 116738135
Test: Built
Change-Id: I528b5f76dfca5bbdc9f69d6402b23b3d2ef11706
2019-02-02 10:00:36 -08:00
Philip P. Moltmann
9b12e37a4f Small fixes in PermissionControllerManager/Service
- better names
- broken javadoc
- missing input paramter checks

Bug: 116738135
Test: Built
Change-Id: I6056b46776cf32937a113b99584d138ff423f039
2019-02-01 11:43:08 -08:00
Philip P. Moltmann
e1436e85ae Flags instead of booleans for countPermissionApps
Test: Checked that the api retunred the results
Change-Id: I3f95bf9beee4a7edae5cbd9457ad4efefe83d1be
Fixes: 123697839
2019-01-31 14:22:39 -08:00
Hai Zhang
1982187691 Add PermissionControllerManager.isApplicationQualifiedForRole().
Settings DefaultAppShortcutPreference needs this info to determine
whether to show the shortcut to default apps on the app info page.

Bug: 110557011
Bug: 123238935
Test: manual
Change-Id: I3ffa62eb199ba9c761bf09a556443f685f6b6b50
2019-01-24 17:38:36 -08:00
Philip P. Moltmann
97142e25d7 Move permission backup into permission controller
As runtime permissions are complex, all runtime permission code is
consolidated into the permission controller app.

Hence the package manager service's permission backup code is now
calling into the PermissionControllerManager which is a interface to the
permission controller app.

Bug: 120907838
Test: Triggered a backup and checked the result via the debugger.
Change-Id: I633162189b728921d902050eee125b4b40b618fd
2019-01-14 16:44:06 -08:00
TreeHugger Robot
4f30490dbe Merge "Call timeout callbacks on executor too" 2019-01-14 21:17:10 +00:00
Joel Galenson
5f63b83949 Add new method to count how many apps have used permissions
Bug: 121256299
Test: Called API and looked at result.
Change-Id: If055093a81598cf36a5d1b745ee5397974ee4106
2019-01-14 10:02:52 -08:00
Philip P. Moltmann
5e5c41e549 Have app global connection as to other managers
Regular ...Manager-s connect to the system server hence there is no
problem establishing a permanent connection via
ServiceManager.getServiceOrThrow.

(1)
PermissionControllerManager connects to an app, hence the binding has to
be dynamic. This is done my using the local RemoteService class.

(2)
...Manager-s are per context. Hence when the context goes away all
service connection started for this service are supposed to also be
cleaned up. There is no callback when the context goes away.

(1) and (2) lead to RemoteService connection to still be bound while the
context goes away which causes a service connection leak.

This change emulates the behavior of regular managers by creating a
permanent RemoteService tied to the application context. Of course
interanlly RemoteService itself binds and unbinds dynamically. Still,
now the RemoteService is not bound to a context that goes away and no
connection is leaked.

Test: atest CtsAppSecurityHostTestCases:android.appsecurity.cts.PermissionsHostTest
      (this test failed before as settings was crashing due to leaked
      remote service connections)
Change-Id: I5b8a4c62070fcce6e390897d046c4b28998e3952
2019-01-13 11:07:26 -08:00
Philip P. Moltmann
1117ca31cc Call timeout callbacks on executor too
Test: atest PermissionControllerTest
Change-Id: I23832d6ff992e7417e0a0128ef94203b2a435cb7
2019-01-12 11:39:31 -08:00
Philip P. Moltmann
7868952db3 Allow apps to bulk revoke permissions with the correct semantics
Test: atest --test-mapping frameworks/base/core/java/android/permission/:presubmit
Fixes: 120269238
Change-Id: Ib9eb244f1c89c09eee1f39e3abb65c1189f7a6f4
2019-01-06 17:51:33 -08:00
Philip P. Moltmann
bc054d8436 Rename RuntimePermissionPresenter to PermissionController
As this has already evolved from just presenting data. In the future any
permission related calls to the permission controller will be added here.

As the calls are protected by different permissions the binding will not
require a permission anymore, but each individual call checks the
permission.

Bug: 120221960
Test: Looked at settings UI showing data from this interface
Change-Id: I6b4a5c3b7ee17b145e11e2c1b6e11a8a232bffed
2019-01-03 11:39:43 -08:00
Philip P. Moltmann
22b8498815 Factor out service handling out of RuntimePermissionPresenter
Fixes: 121270006
Test: Looked at settings page that use RuntimePermissionPresenter
Change-Id: I3030511bce76fd0f30fac1ac922f6ff9f09ca80e
2018-12-19 13:40:17 -08:00
Philip P. Moltmann
08cac8e486 Add new method to count how many apps have permissions
Test: Called API and looked at result
Bug: 120221960
Change-Id: Icb8ee7f46849f26f4625b42e7b482c655409d175
2018-12-04 16:53:23 -08:00
Philip P. Moltmann
dbf78b8127 Move RuntimePermissionPresenter to android.permission
Consolidate all permission related code in a single java package.

Test: atest SettingsLibRoboTests
      Looked at Settings AppInfo UI (uses RuntimePermissionPresenter)
Bug: 120221960
Change-Id: If135e984a8273e9bed80cab9fbf2d70f40a05c7f
2018-12-04 16:53:23 -08:00
Philip P. Moltmann
e1b277a413 Have a map of background -> foreground permssions
This needs to be available before package manager service is ready,
hence set it as soon as possible.

In the future we should also allow access to this mapping from other
processes than the system server.

Test: Built
Change-Id: If4240e5522e175ea9b341e4951ce261f17bbaadc
2018-11-08 09:19:51 -08:00
Zimuzo
cc2932fd81 Grant split permission from config
Instead of defining split permissions in Java file, we now move them to XML allowing us define vendor specific split permissions.

Test: Activity recognition is split correctly and auto granted when below split targetSdk.
Bug: 111411340
Change-Id: Ia5b3f47b73c9feea924373268a4eee142f555091
2018-11-01 16:08:27 +00:00
Philip P. Moltmann
a3ba4d9861 Make PermissionManager use lists
... as requested per API review.

- Sets require iteration via iterators
- Sets are more expensive to construct
- The advantage of sets (faster .contains) is not used
- The system ensures uniqueness of the entires in the list

Test: Built
Bug: 116798569
Change-Id: I2c3b5c6801b78e0bf942073bde1e90299aee39f6
2018-10-11 08:16:16 -07:00
Philip P. Moltmann
039678e13f Add PermissionManager exposing SPLIT_PERMISSIONS
The Permission Controller app (a mainline module) needs to be able to
read the SPLIT_PERMISSIONS. Hence this array needs to be exposed at
least as system-api. We need to make sure that the PackageParser,
PackageManager and Permission Controller app agree on which permissions
are split, hence it is best to define them at a single location.

I think exposing the split permissions to developers is useless and
potentially confusing. The app should never request a permission that
was split. The app should just behave as if split permissions do not
exist. The Permission Controller / Package Manager deal with the
split permissions and add them when needed. Hence I don't think we
should expose this data to 3rd parties.

Bug: 110953302
Test: requested permissions
Change-Id: I6951c52979c89ee5c13a4a14da125e1a01f2e234
2018-09-25 13:48:11 -07:00