347 Commits

Author SHA1 Message Date
Dianne Hackborn
bef28feba5 Initial stab at background check.
Actually, this implementation is more what we want for ephemeral
apps.  I am realizing the two are not really the same thing. :(

For this implementation, we now keep track of how long a uid has
been in the background, and after a certain amount of time
(currently 1 minute) we mark it as "idle".  Any packages associated
with that uid are then no longer allowed to run in the background.
This means, until the app next goes in the foreground:

- No manifest broadcast receivers in the app will execute.
- No services can be started (binding services is still okay,
  as this is outside dependencies on the app that should still
  be represented).
- All alarms for the app are cancelled and no more can be set.
- All jobs for the app are cancelled and no more can be scheduled.
- All syncs for the app are cancelled and no more can be requested.

Change-Id: If53714ca4beed35faf2e89f916ce9eaaabd9290d
2015-11-16 17:58:32 -08:00
Makoto Onuki
219bbafc3f Revert "Do not call into ActivityManager from DPMS within DPMS lock"
Bug 25567963

This reverts commit 53de36f9c40c9a4ac1eb9cca8f458aa6c998c1fd.

Change-Id: I4faaa0b4c50d75e208f37b99bc1d6e2f0fff8127
2015-11-12 01:38:47 +00:00
Makoto Onuki
53de36f9c4 Do not call into ActivityManager from DPMS within DPMS lock
This will allow AMS to call into DPMS within the AMS lock instead,
which will help  I1537bd57b34696768ee81a979d53bb396efbc12a.

- AM.clearApplicationUserData() will not be allowed for any DA
apps.

Bug 25567963

Change-Id: I9f0d071c815a011be4f4c85c502c39d0fe0fe5e8
2015-11-10 14:55:30 -08:00
Makoto Onuki
6d2beef6a8 Merge "Add DPM.getUserRestrictions()" 2015-11-06 18:32:35 +00:00
Makoto Onuki
3a3092fab0 Add DPM.getUserRestrictions()
This returns per-DO/PO restrictions.

Bug 23902097

Change-Id: I225c1b01444fe2f60e5a6674d327182cc9bb15dc
2015-11-06 10:30:08 -08:00
Makoto Onuki
803d6757fd Do not allow DO and PO running on the same user.
Bug 25346603

Change-Id: Ic5fbed82466a538fbf64ef802fc2624dd67313bb
2015-11-05 14:11:53 -08:00
Fyodor Kupolov
8240275381 Introduced short-term lock for UMS internal state
Added mUsersLock - short-term lock for internal state, when interaction and
synchronization with PM is not required. Modifications to mUsers and
mRemovingUserIds must be guarded by 3 locks: mInstallLock, mPackagesLock and
mUsersLock. While reads can use mUsersLock.

Testing revealed that the following methods in UMS often cause contention:
- exists
- getUserInfo
- getProfileParent

They all now use a short-term lock mUsersLock for reads.

Bug: 24979571
Change-Id: Ie3a22ea7cbb450c7969800fe2a4a2b2516165e5b
2015-11-03 11:56:33 -08:00
Christopher Tate
14a7bb0d37 Introduce direct listener API for alarm delivery
The Alarm Manager now supports a set() variant that takes a listener
callback to invoke at alarm trigger time rather than a PendingIntent.
This is much lower overhead and has guaranteed low delivery latency
from the trigger time.  The tradeoff is that the app must be running
*continuously* from the time the alarm is set to the time it is
delivered.  If the app exits for any reason before the alarm fires,
the listener becomes invalid and the alarm will be dropped.  This is
more or less equivalent to setting an alarm with a broadcast
PendingIntent that matches only a runtime-registered receiver.

The app's alarm listener can be any object that implements the new
AlarmManager.OnAlarmListener interface and implements its onAlarm()
method.  There is no data delivered at alarm trigger time: whatever
state needs to be associated with the specific alarm instance should
simply be packaged inside the OnAlarmListener instance.

An alarm using OnAlarmListener can request that the onAlarm() method
be called on an arbitrary handler.  If the program passes 'null' for
this parameter when setting the alarm, the callback occurs on the
application's main Looper thread.

Bug 20157436

Change-Id: I2eb030a24efdd466a2eee1666c5231201b43684b
2015-10-30 12:14:15 -07:00
Makoto Onuki
068c54a5be Layer user restrictions
- Now DPMS remembers user restrictions set by DO / PO in their ActiveAdmin.

- User restrictions set by DO/PO will no longer be saved by UserManger.  Instead,
when needed, UMS will consult DPMS to build "effective" user restrictions.

- UM.getUserRestrictions() will now always return "effective" user restrictions.

- DPMS migrates existing user restrictions per the eng spec.

- Also now UM.setUserRestrictions() will crash.  UMS.setUserRestrictions() has
been removed.
This was needed because UM.setUserRestrctions(UM.getUserRestrictions()) will no
longer be a valid use like it used to be.

- Also introduced a fined-grained lock for user restrictions in UM to avoid
deadlock between DPMS and also for better performance.

Bug 23902097

Change-Id: If0e1e49344e2f3e9226532d00777976d1eaa7df3
2015-10-27 14:26:06 -07:00
Matthew Williams
b3b91ceaef Merge "Sync extras bundle comparison can throw NPE" 2015-10-20 18:55:09 +00:00
Matthew Williams
9ad2c84033 Sync extras bundle comparison can throw NPE
BUG: 23591205
Change-Id: Ic6404c0befe70c34b078e0eae6a627826173d82c
2015-10-20 18:54:28 +00:00
Matthew Williams
fa8e5084ee Sanity check loaded periodics and cap runtime.
BUG: 24900376
We've seen an issue where periodic run times can be massively
inflated after loading from disk.
As a safeguard, cap the period's loaded runtime to be [p, 2p]
from the time of loading.

Change-Id: Ie4464490c8d6702fee8efe9190c3da5dc5f013f6
2015-10-16 13:07:22 -07:00
Lorenzo Colitti
eda0ea4190 am 3d3f766c: am 871d96b4: am 13c5dd5c: am eb0bbd45: Merge changes Id6a0b0de,I5f03b8b2,I62464b92 into mnc-dr-dev
* commit '3d3f766c8b37dcf495235ca4a500494498712eed':
  Support DHCP replies with multiple default gateways.
  Accept DHCP responses from non-67 server source ports
  Improve logging of DHCP parse errors using exceptions.
2015-10-12 17:12:08 +00:00
Lorenzo Colitti
025f4a5aae Support DHCP replies with multiple default gateways.
Just use the first one for compatibility with the legacy client.

Bug: 23975855
Change-Id: Id6a0b0de32e8947c12c02eb9a3be417e2f82c99a
2015-10-08 16:28:02 +09:00
Erik Kline
b19238c488 Accept DHCP responses from non-67 server source ports
Bug: 24687559
Change-Id: I5f03b8b2780c558281d8a50d0893fd64f2812add
2015-10-08 15:40:41 +09:00
Erik Kline
496906ee70 Improve logging of DHCP parse errors using exceptions.
Bug: 23975855
Change-Id: I62464b92f0bb568e57bf5e1a63bc75f22c75aac1
2015-10-08 15:40:31 +09:00
Makoto Onuki
a52562ca9a setDeviceOwner() now requires a full component name.
Bug 20149907

Change-Id: I24e66159d1d966925aa3a494b1e2839b07cdafa2
2015-10-05 16:05:15 -07:00
Makoto Onuki
a4f119790e First cut of user restriction layering.
- Start persisting restrictions set by DO/PO.

- Also dump user restrictions on dumpsys

- More changes will follow, including migration.

- Now System settings are mockable.

Bug 23902097
Bug 23902477

Change-Id: I0bda22f484e1a8e259a1feb2df83c5f4a29116da
2015-10-05 15:20:07 -07:00
Craig Lafayette
c3cdf1c614 Merge "Remove device initializer agent" 2015-10-05 17:52:05 +00:00
Xiaohui Chen
bb7e5ac58e Merge "Cleanup USER_OWNER in mount service" 2015-10-02 21:54:17 +00:00
Xiaohui Chen
621b3fc7a9 Cleanup USER_OWNER in mount service
Also removed a failing unit test and the related code which is
now deprecated.

Bug: 19913735
Bug: 24064753
Change-Id: I9b11130b52caeb0ad890cc6adaaf7fb2fc7b5db6
2015-10-02 14:41:42 -07:00
Craig Lafayette
e7ee54ee7f Remove device initializer agent
Bug: 23216982
Change-Id: I867c0b5f4165983d1ed2623a655f6a2a5e3770bb
2015-10-02 13:11:57 -04:00
Makoto Onuki
d932f7689d Refactor DPMS tests to be able to test more different cases.
- DpmMockContext.addUser() allows to create more users.  This will set up
UserManager properly and create a data directory.

- Updated DevicePolicyManagerTest so it can now easily emulate calls from
different secondary users.

Change-Id: Ic9d3e8d0d1e7f41e184c82e6dc323c244535b8d8
2015-10-01 12:47:45 -07:00
Makoto Onuki
72a3a0c7d2 Fix OwnersTest when run with -e package
It was because UserManager.get() returns a static cached instance but
we should always be using the mock instance that's created for each test.

Bug 24378326

Change-Id: Id4663e7676d2d0130622055a97fbde0884714349
2015-09-25 16:01:43 -07:00
Makoto Onuki
b643fb0e67 Use a factory class for dependency injection, add more tests.
- Extracting into a factory allows us to use mocks in other classes.
(Such as Owners.)

- Also removed broken test ApplicationRestrictionsTest.  Instead added a new
simplified test to DevicePolicyManagerTest.

- Also stop caching rarely used instances in DPMS.

Bug 24061108
Bug 24275172

Change-Id: Ice9e57204b18e7b5f6b115126dab2209041439c2
2015-09-25 15:36:29 -07:00
Makoto Onuki
5932fbb923 Merge "Test more DPM APIs." 2015-09-24 18:28:45 +00:00
Erik Kline
02cc5a030a Refactor netlink and IpReachabilityMonitor into services/net
- netlink from core to services/net/netlink
    - IpReachabilityMonitor from core to services/net/ip

Change-Id: I45ac3f591bade45dd5ec441111b02b621234c0e4
2015-09-24 12:50:36 +09:00
Makoto Onuki
f76b06a6b5 Test more DPM APIs.
Bug 24061108

Change-Id: Ia9da19f62c0f4edf53ca1f4c213f0368ec1983ba
2015-09-23 13:26:31 -07:00
Makoto Onuki
cc4bbeb76a Make DPM/DPMS unit-testable
- Now all services that DPMS uses are injectable.
- Introduce some wrappers to make static methods and final class mockable.
(e.g. for Binder.getCallingUid())

- In unit tests we replace those with Mockito mocks, except we use a partial
mock for PackageManager, because we use way too many methods of this and
most of them are okay to use directly.

- To install a partial mock to PackageManager, I needed to make
ApplicationPackageManager @hide public non-final.

- For a starter, added tests for DPM.setAmin().

Bug 24061108

Change-Id: I2afd51d8bc0038992d5f9be38c686260be775b75
2015-09-22 12:47:44 -07:00
Svetoslav
f3f02ac931 Add get_accounts app op
For each runtime permission we have an app op to toggle the
permission for legacy apps as they cannot handle permission
revocations. We were lacking an app op for get_accounts
which prevented the user from controlling access to accounts
regardelss that they change the state of the permission
toggle in the UI. Even worse the permission UI is written
with the assumption that every runtime permission has an
app op and as a result revoking the contacts group (if the
app requests the get_accounts permission) is reset back to
allowed in the UI.

bug:23854618

Change-Id: I12b83dfd22974d130e5b8e7a195421120813e2db
2015-09-09 07:31:17 -07:00
Svetoslav Ganov
f57d98564b am 4f7d0bc7: Merge "Add get_accounts app op" into mnc-dev
* commit '4f7d0bc7af5fbb65796d24b130b7e9e63107bc5d':
  Add get_accounts app op
2015-09-09 01:42:56 +00:00
Lorenzo Colitti
51c61ee23a am fd183706: am 22262f31: am 0bc35668: am 017223ac: Merge changes from topic \'packet-keepalive-fixes\' into mnc-dr-dev
* commit 'fd18370675f8794807747a18276dd7385e25f06e':
  Require the new PACKET_KEEPALIVE_OFFLOAD permission.
  Add an error code for generic hardware error.
  Fix bugs and crashes in PacketKeepalive API.
  Add tests for the PacketKeepalive API.
  Add a PACKET_KEEPALIVE_OFFLOAD permission.
  Use a CountDownLatch instead of sleep() in NetworkFactory tests.
  Get rid of shortSleep() in ConnectivityServiceTest.
  Make ConnectivityServiceTest a bit more readable.
2015-09-09 01:04:38 +00:00
Svetoslav
ce852ddcec Add get_accounts app op
For each runtime permission we have an app op to toggle the
permission for legacy apps as they cannot handle permission
revocations. We were lacking an app op for get_accounts
which prevented the user from controlling access to accounts
regardelss that they change the state of the permission
toggle in the UI. Even worse the permission UI is written
with the assumption that every runtime permission has an
app op and as a result revoking the contacts group (if the
app requests the get_accounts permission) is reset back to
allowed in the UI.

bug:23854618

Change-Id: I9e3f9bfeb320bed561d718db99ee285915d5701b
2015-09-08 17:54:37 -07:00
Makoto Onuki
58b684f1cd [split system] Tentatively support running DO on meat user
- setDeviceOwner() now takes a user ID.  (We can infer it from Binder, but
we still need it for the dpm command.)

- Change broadcast target UID for DO to the DO user

- Start the DO user on boot complete.
TODO Investigate whether this is actually the good timing.

TODO Prevent the DO user from being killed

Bug 23827706

Change-Id: I227dbd444f1f4e94d98c317489d151554fe79d91
2015-09-08 11:24:58 -07:00
Lorenzo Colitti
7914ce5dd4 Add tests for the PacketKeepalive API.
This currently fails in many different ways, but it tells us what
to fix.

Bug: 22606153
Bug: 23884210
Change-Id: If2e5ee0a8d7b26cad67d3d566ed5b1383e0db096
2015-09-09 00:16:56 +09:00
Lorenzo Colitti
ffa390b6f3 Use a CountDownLatch instead of sleep() in NetworkFactory tests.
This makes testNetworkFactoryRequests 2-3 times faster.

Bug: 22606153
Change-Id: I9657b6929e77f23ec811d0ab57b2ba974f0b6a69
2015-09-08 16:41:47 +09:00
Lorenzo Colitti
e58961aa5f Get rid of shortSleep() in ConnectivityServiceTest.
Instead, use IdleHandler to wait for things to become idle.

Bug: 22606153
Change-Id: Ic6ab93ad4d336b40962f9be1096629a44b63ee2f
2015-09-08 16:41:47 +09:00
Lorenzo Colitti
83fa2588f6 Make ConnectivityServiceTest a bit more readable.
1. Make TestNetworkCallback a bit smarter and rename it to
   SingleUseNetworkCallback. This allows us to get rid of all the
   calls to TestNetworkCallback#getConditionVariable.
2. Delete the commented out code that used to test a
   ConnectivityService model that has not been used since KK.
3. Remove unused imports, etc.

Bug: 22606153
Change-Id: I81a2d0b970d19e5f4515490d8c2f88d416445fa1
2015-09-07 20:41:51 +09:00
Makoto Onuki
3403b74429 Merge "Replace all occurrences of HashMap/HashSet with ArrayMap/ArraySet." 2015-09-04 17:48:09 +00:00
Ian Pedowitz
988f378587 am 7b0f661d: am 1635e818: am cb92577a: am 7d223aee: am 0a76afb9: Merge "Don\'t crash on (invalid) hardware address lengths > 127." into mnc-dev
* commit '7b0f661d405a1c53067ec104a6c6ddd7abbae1e6':
  Don't crash on (invalid) hardware address lengths > 127.
2015-09-03 18:52:14 +00:00
Ian Pedowitz
7d223aeef8 am 0a76afb9: Merge "Don\'t crash on (invalid) hardware address lengths > 127." into mnc-dev
* commit '0a76afb93e6f303921ab84e2f26747c3ebf19b62':
  Don't crash on (invalid) hardware address lengths > 127.
2015-09-03 17:34:50 +00:00
Xiaohui Chen
e2796c216e Merge "Cleanup USER_OWNER in a11y manager and tests" 2015-09-03 17:24:47 +00:00
Xiaohui Chen
1d52f9f16a Merge "Cleanup USER_OWNER in a11y service and tests" 2015-09-03 17:22:52 +00:00
Lorenzo Colitti
d64144a37c Don't crash on (invalid) hardware address lengths > 127.
These would cause us to crash with a NegativeArraySizeException
when trying to create the clientMac array. Instead, if the length
is > 16 (invalid, because the field is only 16 bytes long), fudge
it to 6 (Ethernet / wifi).  This is a bit less liberal than the
legacy client, which doesn't check the length at all.

Bug: 23725795
Change-Id: I83f47bfc400ffa8ce85dd9d1b8eb96be5afe51a5
2015-09-03 21:28:48 +09:00
Makoto Onuki
2714d448b1 Replace all occurrences of HashMap/HashSet with ArrayMap/ArraySet.
Also fix the command line for OwnersTest in javadoc.

Change-Id: I53c222aa13eee179c5abf7e6ba95c6cbe9a7f47f
2015-09-02 16:57:30 -07:00
Xiaohui Chen
9daa916a4d Cleanup USER_OWNER in a11y manager and tests
Bug: 19913735
Change-Id: Icc2b55e685e7f9c212326bf2317ea9a7afce0359
2015-09-02 13:15:33 -07:00
Xiaohui Chen
a826b8c24c Cleanup USER_OWNER in a11y service and tests
I need to make some changes to get the tests pass.  First a11y service
will now disable when no service is specified, I need to re-enable
a11y after services are enabled.  Second the old event used in tests
seems to be filtered out by the service, I need to pick a new event.
Also the timeout waiting for mock service to start is extended, I hit
the old timeout quite often with N9.

Bug: 19913735
Change-Id: I8fe1b7b5d93b6a52df0a8940a08761ea5fbf5084
2015-09-02 13:15:21 -07:00
Makoto Onuki
c9754cf0df Add unit tests for file persisting in Onwers.
Bug 23432442

Change-Id: If10ed5a46084695b2aca1286713b8baea8c2a418
2015-09-01 09:33:41 -07:00
Makoto Onuki
99aeac27eb Rename DeviceOwner to Owners
Bug 23432442

Change-Id: Ic59c880d45126fbcf50b1bd31e37b2b64e2f3a6d
2015-08-31 11:44:44 -07:00
Makoto Onuki
39e784dd46 Split device owner config files
DPMS.mDeviceOwner is now always non-null, so no null checks are needed.

Bug 22802261
Bug 23432442

Change-Id: Ia8e5f114ecfc0add44b0d1be7d043ef6e37019ef
2015-08-28 12:12:49 -07:00