57 Commits

Author SHA1 Message Date
Dianne Hackborn
af75c17bca Fix issue #23270878: NPE in UsageStatsService while running UserManagementTest
Change-Id: I34d4fcdc103b3a6ea5c4ed78895f2fe18597237a
2015-08-18 11:08:10 -07:00
Dianne Hackborn
4a503b1ece Fix issue #22989030: Separate battery whitelists
We now have a new whitelist you can put apps in, which
opts them out of the old battery saver mode and new app idle,
but doesn't keep them from going in to doze.  This is for a few
special cases that we had previously whitelisted for battery saver,
and inherited to the new modes...  ultimately we should figure out
how to get these apps out of the whitelist completely, but this
will help for now.

Apps in this new whitelist are not shown in the UI, because they
are still significantly restricted by not being able to operate
normally in doze.  This also means they are still visible in the
list of all apps for the user to be able to put them on/off the
complete whitelist if that is what they really want.

In the course of doing this, I needed to clean up code in the
network policy manager to better separate management of the
two firewall rules that now have different whitelists applied
to them.  This also hopefully just generally simplifies and cleans
up that code.  Hopefully!

Change-Id: I92e15f2f85899571dd8b049b5e3eb1354f55f353
2015-08-07 14:23:32 -07:00
Wenchao Tong
bf3a24d5ec Merge "Ignore the active network scorer when checking for idleness" into mnc-dev 2015-07-23 18:14:47 +00:00
Adam Lesinski
2dfb91412c UsageStats: Reduce log spam during time change
With lots of usage stats files, the log gets spammy
when the time changes and we are moving files around.

Bug:22549399
Change-Id: I9da39399b090066d52568dea6fc5b59aba063c5a
2015-07-22 17:35:46 -07:00
Wenchao Tong
7cc902bea7 Ignore the active network scorer when checking for idleness
Bug: 22667334
Change-Id: I97085e653c146eff148458440bbac0a2ac64d6d2
2015-07-22 16:29:49 -07:00
Adam Lesinski
e03f17c82e UsageStats: Gracefully handle corrupt filenames
Not sure how useful this is, since renames should be atomic. If the filesystem
is corrupt I'm sure other parts of the system will break. Good to be safe though!

Bug:22172659
Change-Id: Iad339be2869d170bcf736c59feb93830a51905e1
2015-07-22 16:01:45 -07:00
Dianne Hackborn
fd854ee58c Fix issue #21626564: MMS should be receivied while Dozing
We now place whoever is receiving the MMS on the temporary
whitelist while doing so, so they can get network access to
download it.

There was also an issue that needed to be fixed where we
were no longer updating the list of allowed uids while
dozing based on their proc states...  we now do that.

Also did a bit of optimization of the temp white list update
path do the network policy manager, instead of going through
a broadcast we now directly call in to the network policy
manager.  This also allows us to have a synchronous version
of updating the list, so we can know the app has network access
before we tell it to do anything.

Finally added battery stats events for things going on and off
the whitelist so we can diagnose the behavior there.

Change-Id: Ic7fe010af680034d9f8cb014bb135b2addef7455
2015-07-14 18:33:08 -07:00
Xiaohui Chen
8dca36dc8a system_server: optimize app idle parole state change
Currently when app idle parole state changes, all idle apps' states
are updated one by one including firewall modifications which are
very expensive.  This optimization gets rid of individual firewall
rule changes and makes sure we only modify the firewall once at child
chain level.

BUG: 21446713
Change-Id: Iafc415fe0bc127826fe17894d4fedcf1755cb17d
2015-06-22 15:35:19 -07:00
Dianne Hackborn
92617036fc Fix issue #21930140: Add config to turn off auto power features
Doze and app standby are now off in the default platform config.
The Google overlay turns them on.  Other people can do that as
well, if they are feeling like it.

Change-Id: Ic8a87f696df94f2d8354fe0772d03b672f464e32
2015-06-22 10:09:45 -07:00
Amith Yamasani
37a40c24de App Standby : Association between content providers and their sync adapter
Set sync adapters to active if the associated content providers are used
at foreground process state.

Minimize how frequently published content providers are reported by
keeping track of last reported time.

Also cache sync adapters associated with an authority in SyncManager.

Bug: 21785111
Change-Id: Ic2c8cb6a27f005d1a1d0aad21d36b1510160753a
2015-06-19 15:04:58 -07:00
Dianne Hackborn
a750a63d63 Fix issue #21814207 and issue #21814212 (alarm manager)
Issue #21814207: AlarmManager.setAndAllowWhileIdle should also allow wake locks.

Introduce a whole new infrastructure for providing options when
sending broadcasts, much like ActivityOptions.  There is a single
option right now, asking the activity manager to apply a tempory
whitelist to each receiver of the broadcast.

Issue #21814212: Need to allow configuration of alarm manager parameters

The various alarm manager timing configurations are not modifiable
through settings, much like DeviceIdleController.  Also did a few
tweaks in the existing DeviceIdleController impl.

Change-Id: Ifd01013185acc4de668617b1e46e78e30ebed041
2015-06-17 11:41:45 -07:00
Dianne Hackborn
1958e5e787 Fix issue #21813831: Need API for asking to be added to power whitelist
Add the API.  Clean up a few related things.

Change-Id: I190adad1812f36f6095b98a1001fedb94874e8b5
2015-06-15 11:53:59 -07:00
Amith Yamasani
480d6eb953 Merge "Fix negative inactiveTime on creating a new user" into mnc-dev 2015-06-12 23:38:26 +00:00
Amith Yamasani
d82dbb3ffe Fix negative inactiveTime on creating a new user
Initialize the beginIdleTime to 0 rather than current time.

Bug: 21699099
Change-Id: Ib94a9198c4e80aea5d9de68c5cf5d6f8cfc79e0a
2015-06-12 16:35:17 -07:00
Adam Lesinski
a6232df053 App Standby: Convert constants to Settings.Global
Use settings instead of hardcoded constants, and listen for their changes.

Bug:21640379
Change-Id: Id8305bb234f93f7c64c1a5e82e26b31504624324
2015-06-12 16:19:07 -07:00
Amith Yamasani
6776849dc5 Report app standby state to batterystats
Also reduce idle checks to the target user if possible.
Optimized calls to some internal methods

Bug: 21639147
Change-Id: If1faf26f862e5c4ca905f2603a4ba52a8d1af954
2015-06-12 09:05:22 -07:00
Adam Lesinski
c8e8729244 UsageStats: Change INTERACTION to SYSTEM_INTERACTION
SYSTEM_INTERACTION events are signals to the system for a package's
implicit actions (service bound, etc).

These should not affect the API visible stats like lastTimeUsed, etc.
USER_INTERACTION is for user initiated actions (notification interaction, etc).

Bug:21761781
Change-Id: I4585cf35fbb158612a3c737710108bec34e89183
2015-06-11 22:01:45 +00:00
Zach Johnson
b4b9ca7580 Ignore carrier apps when checking for idleness
Also introduce a way to check if a package has
carrier privileges for any active phone.

Change-Id: If5c5fe07f05ffc90fc21431eb27cf48030c0175b
2015-06-08 13:49:13 -07:00
Amith Yamasani
af575b9f8e Temporarily whitelist an app for network during doze
API to allow an app to be whitelisted for network and wakelock
access for a short period. So even if the device is in idle
mode, such apps can be given a chance to download the payload
related to a high priority cloud-to-device message.

This API is meant for system apps only.

A new permission CHANGE_DEVICE_IDLE_TEMP_WHITELIST is required
to make this call.

Bug: 21525864
Change-Id: Id7a761a664f21af5d7ff55aa56e8df98d15511ca
2015-06-02 11:05:03 -07:00
Amith Yamasani
547116ea62 Use screen-on time and wallclock time for idleness calc
12 hours of screen-on time and 2 days of wallclock time
must elapse before considering an app idle.

Bug: 20066058
Change-Id: Ie7b584b40e644d868aa2708876723c3391fd432e
2015-05-20 15:40:37 -07:00
Amith Yamasani
901e924392 Allow settings to change app inactive state
Change-Id: I57efb4b5fa69c9a268025fb1ef83de36c4cc83ca
2015-05-13 18:21:33 -07:00
Amith Yamasani
0a11e69428 Track app idle history and dump it
"dumpsys usagestats history" will show the
active state of each app for the last 100 hours,
if the device hasn't rebooted.

Bug: 20066058
Change-Id: I703e5bc121298e4363c202da56fffb0b8534bcaf
2015-05-13 11:49:35 -07:00
Amith Yamasani
520d8f2ac6 Allow exemption to idle apps at periodic intervals
Triggers are device idle mode changing as well as
internal delayed message handlers.

Bug: 20066058
Change-Id: I0627cfbcc16cfc2b8ac7d298fd2c681a5a6571dd
2015-05-12 16:08:50 -07:00
Amith Yamasani
06bf824628 Idle timebase
Use screen on time as timebase for idling out apps
that have been inactive.

Store the time when an app was last active as an additional
package state in UsageStats. Compare it to screenOnTime to decide
if it's inactive.

Exclude device idle whitelist from apps that can go inactive.

Bug: 20066058

Change-Id: I709f9f31a9affa7ca6e1ae3e4c5729c5fb221669
2015-05-11 17:46:14 -07:00
Amith Yamasani
e5f330456b Rename *AppIdle to *AppInactive per api-council
Change to setAppInactive and isAppInactive in a few places.

Bug: 20823737
Change-Id: Ie57dbc0dd2842e771bb5fd9f69b8041aacaa005c
2015-05-08 13:20:22 -07:00
Amith Yamasani
e4a8da8ea2 Exclude bound app widgets from idle app list
Track package names of bound app widgets and use the list when
querying for idle apps.

Bug: 20066058
Change-Id: If8039397a061ef04bb13aa38d57cd7f0221f5fc7
2015-05-01 11:17:27 -07:00
Amith Yamasani
15e47235c0 Remove network access for idle apps
Track apps going in and out of idle in the NetworkPolicyManagerService.
Apply DROP rules in firewall controller if app is to be blacklisted
for network access.

Firewall can now be in whitelist (old) or blacklist mode. When in
blacklist, it allows all by default and we can selectively DENY
some uids.

Track app idle in UsageStats and update periodically.
Track charging/discharging states.

TODO: Check for appidle temporary parole state

Bug: 20066058
Change-Id: Ia65d7544204b3bcb78a517310ef4adcc05aac6fb
2015-04-29 14:21:53 -07:00
Amith Yamasani
f47e51ec60 More usage tracking
Notification listeners can now report that a notification
has been seen by the user and that package is then marked
as active.

Bug: 20066058
Change-Id: I336040a52c44c21fd0d78b02ec9a19d448c64b40
2015-04-24 16:12:01 -07:00
Amith Yamasani
cf76872a62 Add ability to get and set idle state of apps
Add am shell command to set and get idle
Add public API to check if an app is idle

Bug: 20534955
Bug: 20493806
Change-Id: Ib48b3fe847c71f05ef3905563f6e903cf060c498
2015-04-24 12:58:46 -07:00
Amith Yamasani
96a0fd65e1 Delay syncs for idle apps
Apps that haven't been in use for a while and are considered idle
are not synced until the device is charging or the app is used.

Bug: 20066058
Change-Id: I3471e3a11edae04777163b0dbd74e86495743caa
2015-04-13 15:36:32 -07:00
Amith Yamasani
55717a613c Mark apps as not-idle at least once
On a fresh boot or update to M, mark existing apps
as being used if there is no existing entry in the
usage stats. On subsequent OTAs, make sure that at
least the new system apps are marked as used.

Reduce idle threshold to 1 day.

Bug: 20066058
Change-Id: I9a273c051d04432877bacd381c85bf6e721c1a85
2015-04-06 12:52:53 -07:00
Amith Yamasani
b0ff32245c Throttle jobs for idle apps
First pass at delaying jobs from apps that are idle.

TODO: Throttle syncs
TODO: Provide a periodic point at which apps are checked for idleness.

Apps that switch to foreground process state are tracked by UsageStats
as an INTERACTION event that affects the last-used timestamp.

JobScheduler's logic for when an app is ready is trumped by the idleness
of the app, and only if the battery is not charging. When charging state
changes, we update the idle state of all the tracked jobs.

android package is whitelisted.

Bug: 20066058
Change-Id: I0a0acb517b100a5c7b11e3f435f4141375f3451f
2015-04-03 13:20:19 -07:00
Adam Lesinski
f55187767e Merge "Fix issue where pruned UsageStats files would not be removed from index" 2015-03-02 22:23:44 +00:00
Adam Lesinski
a4005662c7 Merge "Add generic "INTERACTION" event type to UsageStatsManager" 2015-03-02 22:22:58 +00:00
Adam Lesinski
3a0831bfe6 Fix issue where pruned UsageStats files would not be removed from index
This would cause an exception to be thrown when querying stats
that included a deleted file and cause only in-memory stats to be
returned.

This change now re-indexes after deleting files.

Furthermore, we continue reading UsageStats files in order
to return more useful data if some other issue (file corruption)
leads us to fail reading a file.

Change-Id: I4a52739624d68e719e3d7d324a0b16709a62ac7a
2015-03-02 13:06:46 -08:00
Adam Lesinski
978a1ed5aa Add generic "INTERACTION" event type to UsageStatsManager
This will allow for updating a package's last time used
property for packages that are interacted in ways other than
launching their activities (interacting with notifications, etc.)

Change-Id: Ic6f9519f46fa04abd37ea6fc9475bcd9ea721003
2015-03-02 12:54:14 -08:00
Edward Cunningham
690f78adf1 Fix UsageStats to report correct endTime from XML
Bug: 19529542
Change-Id: Iacb1a245a40c6b88ae15740797217f59d5fca1e6
2015-02-27 00:33:30 +01:00
Adam Lesinski
0fb25fae8f UsageStatsService: Update file index to prevent double checkin
We seem to have renamed a file as checked-in twice, which means
we checked it in twice and created a malformed name with the suffix
"-c-c" instead of the correct suffix "-c".

Bug:18280677
Change-Id: Ie3164010898a333e5d9b97151d285ea376de799e
2014-11-07 17:36:27 -08:00
Adam Lesinski
32e580604d Fix bug where checking-in more than once would cause an infinite loop in UsageStatsService
- Forgot to increment loop variable :S

Bug:18239732
Change-Id: Ie37a83584d7849108dbfd3bd4cbb595520d488b1
2014-11-04 13:38:46 -08:00
Adam Lesinski
720a5c51be Merge "Add dumpsys output to UsageStatsService, along with --checkin support" into lmp-mr1-dev 2014-10-29 23:11:54 +00:00
Adam Lesinski
1bb18c435d Add dumpsys output to UsageStatsService, along with --checkin support
Bug:17814138
Change-Id: If414ae5f4b8e4a2838f63f52d80e764915cee934
2014-10-24 18:01:04 -07:00
Jeff Hao
7eb599b267 Get UsageStats if no PackageUsage is available for boot dexopt filtering.
Bug: 17191977
Change-Id: I33e18459e49afa42b8e8218574a2434e5205a6da
2014-10-23 11:27:42 -07:00
Brian Carlstrom
a39871ef5e Use VMRuntime.isBootClassPathOnDisk
Bug: 17679443
Change-Id: If53c236058a7237d735c2344a715cf0a36301f9b
2014-09-30 16:49:32 -07:00
Adam Lesinski
3bab7c188d Merge "UsageStats should deal with changing time" into lmp-dev 2014-09-12 01:42:21 +00:00
Adam Lesinski
66143fa5b3 UsageStats should deal with changing time
When the system time is changed, the UsageStats API
will modify all existing entries to correspond with the
new time change. If the time changed when the device was
off, stats in the future will be deleted.

Change-Id: Ica3e9917d4d1a180f97700e52ab390e3673e1e82
2014-09-11 18:39:01 -07:00
Amith Yamasani
8cd28b57ed Apply cross-user restrictions to Shell
Even though Shell user is allowed to perform cross-user actions,
lock that path down if the target user has restrictions imposed by
the profile owner device admin that prevents access via adb.

If the profile owner has imposed DISALLOW_DEBUGGING_FEATURES, don't
allow the shell user to make the following types of calls:
start activities, make service calls, access content providers,
send broadcasts, block/unblock packages, clear user data, etc.

Bug: 15086577
Change-Id: I9669fc165953076f786ed51cbc17d20d6fa995c3
2014-09-10 17:15:06 -07:00
Adam Lesinski
37a46b48dc Store time offsets for UsageStats XML
This will make adjusting for time changes easier
in the future.

Change-Id: I49d2dda4cc6dcb1378a58c814849924f585e0417
2014-09-05 23:57:42 +00:00
Adam Lesinski
d26bea3a14 Returns UsageEvents from previous days
- Avoid writing to disk when querying UsageStats.
- Use new UnixCalendar to avoid issues with Locale and TimeZone.

Bug: 16951313

Change-Id: I2473b8ef8dc1e2f6be22d4c689b96e346bdcafd5
2014-09-05 23:09:27 +00:00
Adam Lesinski
7f61e96db7 Add Configuration changes to UsageStats
Bug:17354208
Change-Id: I9b2f595e51b656607e30e798926cfb7e25134944
2014-09-04 12:15:32 -07:00
Adam Lesinski
9d9607527f Split up ComponentName in UsageEvents.Event
Some events in the future may not have originated
from a class, so we shouldn't be using ComponentName.

Bug:17259858
Change-Id: Id7fe3245b91596cf27ae4ec51655602f01665622
2014-08-26 12:41:31 -07:00