1122 Commits

Author SHA1 Message Date
Pavel Grafov
3bca09f308 Start SecurityLogMonitor after broadcasts are allowed.
Otherwise if boot takes long enough, DO broadcast will be sent while
ActivityManagerSerivce is not ready, causing IllegalStateException.

Change-Id: I6b55ed45ed7b1f3ed9ad6ec20695907b4fa6f3b1
Fixes: 109746888
Test: atest CtsDevicePolicyManagerTestCases:com.android.cts.devicepolicy.DeviceOwnerTest#testSecurityLoggingWithSingleUser
Test: provisioned TestDPC as DO in SuW, enabled logging.
2018-06-07 11:16:46 +01:00
Dianne Hackborn
d52544183e Allow device/profile owners to change app ops modes.
This allows them to continue to have this capability the
same as before we locked down access to it.

Bug: 78480444
Test: manual
Change-Id: If2b0722945235eb67676ace3f54efaa71a64bcde
2018-05-14 11:29:43 -07:00
Pavel Grafov
9cf46fd625 Merge "Log wipe failure" into pi-dev 2018-05-09 19:46:05 +00:00
Pavel Grafov
a0d201b548 Log wipe failure
Test: injected an error into RecoverySystem.rebootWipeUserData
Fixes: 79417596
Change-Id: I3fef4bdd2f6357b08be4976c35c651908e9b3599
2018-05-09 18:27:45 +01:00
Pavel Grafov
517260ecef Acquire lock before calling getDeviceOwnerAdminLocked
Change-Id: I318c7cea8e9b7de2dc9fa05f786524848c9c76dd
Fixes: 79418618
Test: atest CtsDevicePolicyManagerTestCases:com.android.cts.devicepolicy.DeviceOwnerTest#testKeyManagement
2018-05-09 17:42:06 +01:00
Eran Messeri
9ecde42164 Save password requirements on the right user
When changing the password requirements, two changes have to be saved:
(1) Whether the current password complies with the new password
requirements.
(2) The new password requirements themselves.

(1) is stored on the credential owner of the user, (2) is stored on the
user itself.

In ag/3729963 (Change-ID: Ide5b2e53cf100b087822844ca51b3bc69e7ddf82),
we've switched from saving the password sufficiency flag (1) in the
user to the credential owner.
A side effect was that the password requirements themselves, (2), which
were changed on the original user the call related to, were not saved.

This fixes the bug introduced in the aforementioned CL.

Bug: 78499736
Test: Manual with TestDPC.
Change-Id: I11faef37fa6f0e8e8e558069e77021c48ee36cd4
2018-05-01 14:12:23 +01:00
Eran Messeri
24ba8398fe Merge "Remove unnecessary WTFs from password state check" into pi-dev 2018-04-25 09:28:15 +00:00
Eran Messeri
3c26b8f92e Remove unnecessary WTFs from password state check
It is possible to have null PasswordMetrics object for a given user -
if, for example, the user never had a password set.

Do not WTF in that case.

Bug: 78191197
Test: That it compiles.
Change-Id: I807c2755890b0772e295b4cb0095cac1bf2d0aef
2018-04-24 19:28:57 +01:00
Suprabh Shukla
7ea5378f89 Failing setPackagesSuspended if user has a DO / PO
Device or profile owners should be suspending packages via
DevicePolicyManager. If an app with SUSPEND_APPS tries use the
PackageManager api on a user with a DO or a PO, the call should fail

Test: gts-tradefed run gts-dev -m SuspendApps

Bug: 78132137
Change-Id: If478db0726073c2e59dba3a7049cc16c56d9f3d5
2018-04-19 21:31:10 -07:00
Makoto Onuki
49392d335a Add stats logging to ServiceManager and NPMS
ServiceManager:
- Do an event log every N getService() calls with total time spent
in getService().
where N = 100 for core UIDs and 200 for other apps.

- Do an event log if getService() takes longer than N ms.
where N = 10 for core UIDs and 50 for other apps.

... with some extra throttling.

NPMS:
- Do the basic "stats logger" log for updateNetworkEnabledNL() and
isUidNetworkingBlocked()

This CL also enhances StatsLogegr so it now can show the slowest call
and the max # of calls per-second.

Bug: 77853238
Test: Manual test:
- Insert a SIM card
- Set data limit
- toggle airplane mode
- toggle wifi
- toggle mobile data

Then
- "dumpsys netpolicy" and "dumpsys activity processes" and check the stats
- also check "adb logcat -b all | grep ' service_manager'"

Change-Id: I5789541063f95d0eac501189816c8604a4571ba0
2018-04-11 16:37:57 -07:00
Eric Sandness
5ab98de315 Permission Check For DPM.getPermittedAccessibilityServices
Require the callers of DPM.getPermittedAccessibilityServices(userId) to
hold the MANAGE_USERS permission.  The only known callers of this API
are settings apps that already hold this permission.

Bug: 62343414
Test: com.android.server.devicepolicy.DevicePolicyManagerTest
Test: com.google.android.gts.devicepolicy.DeviceOwnerTest
Test: Manually checked accessibility settings in DO and PO modes
Change-Id: I8ee3f876fcaffa63636645f0f59709cd147254ef
2018-04-09 07:47:13 +00:00
Suprabh Shukla
3c3af1406e Activity interceptor dialog for suspended apps
Added an AlertActivity to intercept the start for an activity belonging
to a suspended app. More details will be shown if the suspending app
also defines an activity to handle the API action
SHOW_SUSPENDED_APP_DETAILS.

Test: Added tests to existing classes. Can be run via:
atest com.android.server.pm.SuspendPackagesTest
atest com.android.server.pm.PackageManagerSettingsTests
atest com.android.server.pm.PackageUserStateTest

Bug: 75332201
Change-Id: I85dc4e9efd15eedba306ed5b856f651e3abd3e99
2018-04-04 18:40:19 -07:00
Makoto Onuki
eed5b5a31c Add basic inversion lock detection to DPMS.
For now enable it on ENG builds only.
(I'll change the condition in master so I'll get WTFs from qt-release devices
too.)

This will detect calling into DPMS with the following locks held:

APP_OPS
POWER
USER
PACKAGES
STORAGE
WINDOW
ACTIVITY
DPMS

On marlin-eng pi-dev, each guard() takes ~25us.
    LockGuard.guard(): count=7246, total=175.1ms, avg=0.024ms

Used the following command to ensure all locks are replaced.
$ grep synchronized /android/pi-dev/frameworks/base/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java | sed -e 's/  *//' | uniq

Bug: 74553426
Test: Manual test with an intentional lock inversion.
Change-Id: Id59d562d7c275b6ea127a211284496f5d64f9f93
2018-04-04 12:18:54 -07:00
Rubin Xu
69196f6fad Merge "Remove password blacklist API" into pi-dev 2018-03-30 13:38:31 +00:00
yuemingw
c0281f10f5 Allow PO to call setSystemSetting.
As system setting is per user, we should allow PO to call it.

Bug: 77204777
Test: runtest -x services/tests/servicestests/src/
com/android/server/devicepolicy/DevicePolicyManagerTest.java

Change-Id: I84152fa04adb441955b48b676be6e792134b52c2
2018-03-29 20:23:52 +00:00
Rubin Xu
3a021b3762 Remove password blacklist API
Bug: 73750934
Test: compiles
Change-Id: I4a73ea47285b7d0be06f84d45a5166a6642c29cf
2018-03-29 20:36:51 +01:00
Eran Messeri
6169239b94 Utilize verbose KeyChain errors
As KeyChain reports detailed error codes about failure to generate keys
or attestation records for them, log these detailed errors and throw an
exception if the hardware does not support Device ID attestation.

Bug: 72642093
Bug: 73448533
Test: cts-tradefed run commandAndExit  cts-dev -s 127.0.0.1:50487 -a x86_64 -m CtsDevicePolicyManagerTestCases -t com.android.cts.devicepolicy.DeviceOwnerTest#testKeyManagement -l DEBUG
Change-Id: Ib12efcf48c158373e1fc28cc51d67e70282d029e
2018-03-29 10:58:20 +01:00
Benjamin Franz
3a5dabbb10 Merge "Update to lock task features API" into pi-dev 2018-03-29 09:02:17 +00:00
Eric Sandness
78931a0f95 Merge "Permission Check For DPM Get IME API" into pi-dev 2018-03-29 08:25:09 +00:00
TreeHugger Robot
631f55ba54 Merge "Change MeteredDataDisabled function names for clarity" into pi-dev 2018-03-28 23:18:01 +00:00
Benjamin Franz
78ae1060c6 Update to lock task features API
1. Throw if notifications is given without home feature, as this
configuration allows potential escape routes.

2. Default power button menu to be on in order to be consistent with
existing lock task behaviour before P.

Bug: 71790952
Bug: 74381063
Test: manual
Change-Id: I2383c087a18739a158d55edcd84d22d1abdb887a
2018-03-28 12:38:31 +01:00
Eric Sandness
57378939c5 Permission Check For DPM Get IME API
Require the caller of DPM.getPermittedInputMethodsForCurrentUser() to
hold the MANAGE_USERS permission.  The only callers should be settings
apps which already hold this permission.

Bug: 62343414
Test: Manage IME list in the Settings app
Test: com.google.android.gts.devicepolicy.DeviceOwnerTest#testPermitInputMethods
Change-Id: I0d162f8f51d16e403a950ee5d942502c2cf20181
2018-03-27 17:30:30 +00:00
Eric Sandness
9f36c26f83 Merge "Permission Check For DPM.isDeviceProvisioned" into pi-dev 2018-03-27 12:25:53 +00:00
TreeHugger Robot
734a8c9964 Merge "DPM: Separate storage of PasswordMetrics from other state" into pi-dev 2018-03-27 10:22:46 +00:00
Eric Sandness
1ad8367249 Merge "Permission Check For DPM.getUserProvisioningState" into pi-dev 2018-03-27 09:52:58 +00:00
Eric Sandness
df30c7d2e0 Permission Check For DPM.isDeviceProvisioned
Require the caller of DPM.isDeviceProvisioned() to hold the MANAGE_USERS
permission.  The only callers should be within the framework itself, or
apps involved in device provisioning which already hold this permission.

Bug: 62343414
Test: Set TestDPC as Device Owner and use it to reset password
Test: com.android.server.devicepolicy.DevicePolicyManagerTest
Test: com.android.server.locksettings.LockSettingsServiceTests
Test: com.google.android.gts.devicepolicy.DevicePolicyManagerTest
Change-Id: Ie53deb5ba8679a5b431f2a8da60ec9710c44d56f
2018-03-27 09:13:11 +00:00
TreeHugger Robot
ee7802f577 Merge "Fix OTA info persistence logic" into pi-dev 2018-03-27 06:22:16 +00:00
Jeff Sharkey
0472a26d0c Give DPM callers unsafe labels.
Tests want the full label, so give it to them.

Test: none
Bug: 74254785
Change-Id: Ia358ee54396ee0a0684fd352c7133f54d9f8c4a7
2018-03-26 19:19:26 -06:00
Eran Messeri
81845a9b89 DPM: Separate storage of PasswordMetrics from other state
Keep the PasswordMetrics for each user on a separate map from the rest
of the profile data (kept in the DevicePolicyData object).

The PasswordMetrics are not persisted to disk, unlike other fields of
DevicePolicyData (to avoid making it easy for an attacker to brute-force
the password).

Additionally, and the cause of the bug mentioned below, the
PasswordMetrics should not be cleared when a user is started, but
persisted.

Bug: 73899116
Test: Manual with TestDPC
Test: atest FrameworksServicesTests:DevicePolicyManagerTest
Test: runtest -c com.android.server.devicepolicy.DevicePolicyManagerTest frameworks-services
Change-Id: Id42145665f9ff477ea67fe44e8e55fc6586b8edf
2018-03-26 17:39:58 +01:00
Rubin Xu
32c82e4e75 Fix OTA info persistence logic
Code to persist OTA info was accidentally removed by a previous CL.
Add it back.

Bug: 73505100
Test: gts-tradefed run gts-dev --module GtsGmscoreHostTestCases --test com.google.android.gts.devicepolicy.DeviceOwnerTest#testPendingSystemUpdate
Change-Id: I9eba522641fd8f95cd6af32431498c2c8ac5ff0e
2018-03-26 17:24:08 +01:00
Eric Sandness
3780c09c76 Permission Check For DPM.getUserProvisioningState
Require the caller of DPM.getUserProvisioningState() to hold the
MANAGE_USERS permission.  All callers should be apps involved in device
provisioning, which already hold this permission.

Bug: 62343414
Test: Run Device Owner sync auth provisioning manually
Test: Set up work profile with managed account manually
Test: com.android.server.devicepolicy.DevicePolicyManagerTest
Test:
com.android.managedprovisioning.finalization.UserProvisioningStateHelperTest
Test: com.google.android.setupwizard.tests.activity.QrScanControllerTest
Change-Id: Ib85433586d4dfb89019ca223fb925aca3d4bbf67
2018-03-23 18:59:41 +00:00
TreeHugger Robot
6affc07065 Merge "APIs to suspend packages with SUSPEND_APPS permission" into pi-dev 2018-03-22 22:15:31 +00:00
Suprabh Shukla
021b57ab8d APIs to suspend packages with SUSPEND_APPS permission
Changed the existing hidden api setPackagesSuspendedAsUser to a system
api setPackagesSuspended that can be called by apps with either
MANAGE_USERS or SUSPEND_APPS permission. Additionally, the suspending
app can now specify optional extra information meant to be used by the
suspended apps and the launcher to deal with this state.

The following other APIs are added:
 - isPackageSuspended(): Apps can query whether they are in a suspended
 state
 - @SystemApi getPackageSuspendedAppExtras(String): Apps with permission
 SUSPEND_APPS can get the appExtras passed to PM when suspending the
 app.
 - @SystemApi setPackageSuspendedAppExtras(String, PersistableBundle):
 Apps with permission SUSPEND_APPS can update app extras for a
 suspended package.
 - getPackageSuspendedAppExtras(): Apps can call to get the appExtras
 passed in to PM when they were suspended.

Test: Can be run via:
atest com.android.server.pm.PackageManagerSettingsTests
atest com.android.server.pm.PackageUserStateTest
atest com.android.server.pm.SuspendPackagesTest

Bug: 74336673
Change-Id: I3b9ed2c8478b34ee2e8986f5f5fddb2839d102e3
2018-03-22 12:59:57 -07:00
Lenka Trochtova
56681f761e Return a boolean from the mandatory backup transport setter.
Bug: 73813043
Bug: 64012357
Test: cts-tradefed run cts -m CtsDevicePolicyManagerTestCases --test com.android.cts.devicepolicy.DeviceOwnerTest#testGetAndSetMandatoryBackupTransport
Test: cts-tradefed run cts -m CtsBackupHostTestCase --test android.cts.backup.BackupDeviceOwnerHostSideTest

Change-Id: I7f47a41070b767a6be8b986be485b4ad782690cf
2018-03-21 15:48:41 +01:00
Alex Kershaw
56be97edd0 Merge "Fix Javadoc of DevicePolicyManager#setStorageEncryption to reflect that it's a no-op (and silent fail) when called from a non-system user." into pi-dev 2018-03-19 18:17:23 +00:00
TreeHugger Robot
31ac587b43 Merge "DPM: Fix isActivePasswordSufficient for non-FBE devices" into pi-dev 2018-03-19 11:20:27 +00:00
Alex Kershaw
61ec825598 Fix Javadoc of DevicePolicyManager#setStorageEncryption to reflect that
it's a no-op (and silent fail) when called from a non-system user.

DevicePolicyManagerService#setStorageEncryption also has its Javadoc
fixed.

Bug: 74591983
Change-Id: Ie191ad255cbfcade921d172641f134d6c49a17b1
Fixes: 74591983
Test: N/A - just javadoc changed
2018-03-19 10:57:12 +00:00
Eran Messeri
90df3552c5 DPM: Fix isActivePasswordSufficient for non-FBE devices
For non-FBE devices (devices will full disk encryption or no encryption
at all) the password metrics are not kept in plaintext anymore, so it
is not possible to evaluate the sufficiency of the password when new
password quality requirements are set. Instead, the sufficiency value is
stored in a checkpoint that gets loaded after boot and used before the
user has entered any credentials.

However this checkpoint value was not evaluated correctly (there was a
circular dependency between setting it and reading it) and was not
stored on the right DevicePolicyData object.

Fix the checkpoint value to be the correct one and stored on the right
object, by doing the following:
* Removing the short-circuit introduced in ag/2866930.
* Change the default checkpoint value to true, to prevent re-introducing
b/63887564, and because a newly-created profile, before any password
requirements are set, has a sufficient password.
* Get rid of the circular dependency between setting and reading
mPasswordValidAtLastCheckpoint, by extracting from
isActivePasswordSufficientForUserLocked a function that does not look at
the checkpoint value.
* Store the checkpoint value in the DevicePolicyData object of the
credential owner, as this is where isActivePasswordSufficient reads it.

More details can be found in https://docs.google.com/document/d/15CRewlsy1lyonjAWg3VmhLC5jAyVKazUMKlcPnnId58/edit#

Bug: 71697938,73347414
Test: cts-tradefed run commandAndExit cts-dev -s 127.0.0.1:56619 -a x86_64 -m CtsDevicePolicyManagerTestCases -t com.android.cts.devicepolicy.DeviceAdminHostSideTestApi23#testResetPassword_nycRestrictions -l DEBUG on a  gce instance.
Change-Id: Ide5b2e53cf100b087822844ca51b3bc69e7ddf82
2018-03-16 09:48:47 +00:00
Makoto Onuki
70d24a0b1f Merge "Fix deadlock regarding screen-capture-disabled" into pi-dev 2018-03-15 21:01:49 +00:00
Antoan Angelov
675db3f236 Merge "Move the support_transfer_ownership_metadata inside the device admin descriptor XML." into pi-dev 2018-03-15 19:40:13 +00:00
Michael Wachenschwanz
5416468217 Change MeteredDataDisabled function names for clarity
Add the word Packages to several functions to clarify Metered Data is
disabled on a per Package basis.

setMeteredDataDisabled to setMeteredDataDisabledPackages
getMeteredDataDisabled to getMeteredDataDisabledPackages
isMeteredDataDisabledForUser to isMeteredDataDisabledForUserPackage

Change-Id: Ied755b4422f8689e34bdb68d733d60fbfc47c692
Fixes: 73803958
Test: cts-tradefed run singleCommand cts-dev -m CtsDevicePolicyManagerTestCases -t com.android.cts.devicepolicy.MixedDeviceOwnerTest#testSetMeteredDataDisabledPackages
Test: cts-tradefed run singleCommand cts-dev -m CtsDevicePolicyManagerTestCases -t com.android.cts.devicepolicy.MixedProfileOwnerTest#testSetMeteredDataDisabledPackages
Test: atest com.android.server.devicepolicy.DevicePolicyManagerTest#testSetGetMeteredDataDisabledPackages
2018-03-14 14:34:29 -07:00
Makoto Onuki
04ef44761d Fix deadlock regarding screen-capture-disabled
- Introduced DevicePolicyCache, which stores a copy of device policies
that can be accessed with any lock held.

- Removed "wm screen-capture". According to code search, it's not being used,
and this command wasn't really working as intended, since DPM can always
override the manually set value.

Bug: 74277398
Test: atest /android/pi-dev/cts/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/MixedDeviceOwnerTest.java#testScreenCaptureDisabled,testScreenCaptureDisabled_assist ; \
Test: atest /android/pi-dev/cts/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/MixedProfileOwnerTest.java#testScreenCaptureDisabled,testScreenCaptureDisabled_assist ; \
Test: atest /android/pi-dev/cts/hostsidetests/devicepolicy/src/com/android/cts/devicepolicy/MixedManagedProfileOwnerTest.java#testScreenCaptureDisabled,testScreenCaptureDisabled_assist
Change-Id: I1968d1c32145a715d0343f25cb9d58939514b597
2018-03-14 12:21:54 -07:00
dalyk
28011a4180 Add BaseNetdEventCallback class that provides no-op implementations for INetdEventCallback.
Test: None
Bug: 71828272
Merged-In: I261015d0d3e7e4159bb514742a6c588bfd34e795
Merged-In: I3a701fc52641615bf197f980022a61518c7347f4
Merged-In: I1ed5ede74ca14718e6d4f8a9a8d57de6026c9e93
Merged-In: Ib0c4b69a24144d27f672ec716fb9a8f06987ce7d
Change-Id: I75e0620f82195f18befe9dc079492a8c69bb764b
(cherry picked from commit 985d89a6e0412a3b0e8b1519de8ebffdbf708d31)
2018-03-09 19:41:56 +09:00
arangelov
c8ee263d6e Move the support_transfer_ownership_metadata inside the device admin
descriptor XML.

Bug: 73750678
Test: cts-tradefed run cts-dev --module CtsDevicePolicyManagerTestCases --test com.android.cts.devicepolicy.MixedDeviceOwnerHostSideTransferTest#testTransferOwner
Test: cts-tradefed run cts-dev --module CtsDevicePolicyManagerTestCases --test com.android.cts.devicepolicy.MixedProfileOwnerHostSideTransferTest#testTransferOwner
Test: cts-tradefed run cts-dev --module CtsDevicePolicyManagerTestCases --test com.android.cts.devicepolicy.MixedDeviceOwnerHostSideTransferTest#testTransferOwnerNoMetadata
Test: cts-tradefed run cts-dev --module CtsDevicePolicyManagerTestCases --test com.android.cts.devicepolicy.MixedProfileOwnerHostSideTransferTest#testTransferOwnerNoMetadata
Test: cts-tradefed run cts-dev --module CtsAdminTestCases --test android.admin.cts.DeviceAdminInfoTest
Change-Id: I8df63af29dbcb23332e2f291b64b8782f25a751b
2018-03-08 13:45:12 +00:00
Rubin Xu
255cb771f8 Move com.android.managedprovisioning package constant to config.xml
Fixes: 71839817
Test: builds
Change-Id: Ia48b2812d54192447cf3a76c8d2b73d776400bb2
2018-03-05 17:44:30 +00:00
TreeHugger Robot
7e96e0a137 Merge "createAndManageUser should communicate reason of failure to caller" 2018-02-28 00:39:33 +00:00
Alex Chau
89386bacc6 createAndManageUser should communicate reason of failure to caller
Bug: 71844474
Test: cts-tradefed run singleCommand cts -m CtsDevicePolicyManagerTestCases --test com.android.cts.devicepolicy.DeviceOwnerTest#testCreateAndManageUser_LowStorage
Test: cts-tradefed run singleCommand cts -m CtsDevicePolicyManagerTestCases --test com.android.cts.devicepolicy.DeviceOwnerTest#testCreateAndManageUser_MaxUsers
Change-Id: I3c069ba86822178fa3f51f1d31cd4792883151cc
2018-02-27 09:12:45 +00:00
Christine Franks
26449eda7a Add DevicePolicyManager#setDefaultSmsApplication
Bug: 73788187
Test: make -j100
Change-Id: I4f379743b9d12109bb8ecae109591abb922463ec
2018-02-26 22:58:05 +00:00
Vladislav Kuzkokov
0ec75beab7 Merge "Check printing restriction for correct user." 2018-02-26 16:11:10 +00: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