92 Commits

Author SHA1 Message Date
Amith Yamasani
4ec6368f13 Optimize calls to TelephonyManager to check for privileged apps
Calling into TelephonyManager each of hundreds of apps to check
if the app is carrier privileged was very expensive, especially
when there aren't even any carrier access rules specified. This
change fetches all the carrier privileged apps in one call,
reducing the number of IPC calls to the radio process and checks
the package names locally.

If the carrier rules change or packages are modified, the list
will be computed and fetched again.

Other optimizations in Telephony help speed up the individual calls
to check if a package is privileged, as well.

Bug: 27271861
Change-Id: I5a77b6da4f2cdc603d2a73bd8569c5c38f06b42d
2016-02-24 11:30:00 -08:00
Amith Yamasani
b1e153bcd2 Reduce locking duration when checking idle states
Synchronize only the methods that need to be, so that
the lock is not held for a few hundred milliseconds, blocking
other usagestats operations.

Bug: 27208519
Change-Id: I43bda0791dd8b2576a8af506bcdc67a09a5830f2
2016-02-18 11:22:30 -08:00
Amith Yamasani
ca5d6d2a81 Clean up App Standby code
Don't continue to check idle states for removed / stopped users.
No need to check for uninstalled packages for all users.

Bug: 27208519
Change-Id: I9a3a3bbec560dd380ce90df9fef102d7f62769ca
2016-02-17 13:36:48 -08:00
Ritesh Reddy
c170204541 Merge "UsageStatsBackup Bug Fix" 2016-02-06 19:42:14 +00:00
Amith Yamasani
a93542f9d3 Rewrite app standby stats
Don't mix up with usage stats. Keep a separate db and history
based on elapsed time and screen on time.

Unit tests for AppIdleHistory class.

Bug: 26989006
Change-Id: If343785b46da1db67f7c1c1263854c2732a232c6
2016-02-05 11:38:29 -08:00
Ritesh Reddy
e35ae5cce1 UsageStatsBackup Bug Fix
Fixed a bug which caused a null pointer exception on restore
in deleteDirectoryContents() method.
Also made other cosmetic changes.

Change-Id: I75712ec585fdfdbca462c468acf2229a47331b59
2016-02-04 11:48:02 +00:00
Jeff Sharkey
538c11cf21 Hack to get devices booting again.
If we try scheduling a pass before the system is ready, record a
pending event and dispatch once we're actually ready.

Bug: 26863668
Change-Id: I028285383c8bbe8b653aeaa7544eefe3d41277bc
2016-01-29 10:46:09 -07:00
Adam Lesinski
63668e8ab0 Merge commit '5142a2d5b3f70c2017792ce04d3f254221ab3d21' into manual_merge_5142a2d5b3
Change-Id: I6681b0e132e95bd7e861e183e7369b4da07738eb
2016-01-28 11:55:58 -08:00
Adam Lesinski
b2d3ffaa20 Don't change screen on time on time changes
Screen on time should be measured in elapsed realtime, not wallclock.

Cause a checkIdleStates to occur when reloading stats
(on rollover and on time change).

When time changes occur in the negative direction, the new stats file
we create can overlap the previous one with regards to its end timestamp.
Use the begin timestamp to determine which of the latest stats to merge.
(b/22716352)

Bug: 26488100
Change-Id: If31b29bbbee9e98401205b5e26bce86e181286e7
2016-01-27 17:51:47 -08:00
Ritesh Reddy
8a6ce2cb64 Enabled Backup/Restore of Package UsageStatistics
Backing up UsageStatistics using a new API in
UsageStatsService like the Notifications backup.
The backup logic is in the same package as UsageStatsDatabase
while the BackupAgentHelper resides in the android package
alongside SystemBackupAgent.

Bug: 26179323
Change-Id: I022d85fbcd4abb763230bec6eea50a7e723b5152
2016-01-26 20:29:15 +00:00
Amith Yamasani
9b4716b531 Check apps idle states on time changes am: c465e71cdc am: d4bd4cb4b1
am: 375901244c

* commit '375901244c051d85a63d7ca83807e5f1ca7a5d0a':
  Check apps idle states on time changes
2016-01-22 21:49:37 +00:00
Amith Yamasani
c465e71cdc Check apps idle states on time changes
And ensure that the listeners are informed of app standby transitions
that might occur during time changes.

Fix for apps that sometimes don't have network access until reboot.

Bug: 26488100
Change-Id: Ic342c188a6cd19faee88f50b2c6a342a6968cb23
2016-01-22 11:27:16 -08:00
Adam Lesinski
89a697a7e7 Merge "UsageStats: Use new settings key idle_duration2 for app idle" into mnc-dr1.5-dev am: d2e215978b am: a5c7106017
am: 6a8c328d73

* commit '6a8c328d7386d19f4590dfbfc71338b1ec208fb7':
  UsageStats: Use new settings key idle_duration2 for app idle
2016-01-14 01:05:24 +00:00
Adam Lesinski
f0ef3c1126 UsageStats: Use new settings key idle_duration2 for app idle
Ignores the old, re-appropriated key "idle_duration" which is now
set to a high value in order to force disable app idle on devices
with bug b/26355386

Bug:26355386
Change-Id: Iff9de843ad6e547d29c1583687fc7f7ce7e15090
2016-01-13 12:48:50 -08:00
Adam Lesinski
7856f3c283 UsageStats: Fix issue where initializing data for first time would cause crash
With the updated rolling window of stats for app idleness, we need to make sure
it is populated before we initialize some defaults.

Now that we look at older entries to figure out idleness, if those
entries are in the future (due to time change), set them to the current
screen on time.

Bug:26504153
Change-Id: I4c21e8f094a1a6727373368d043f523053280d7d
2016-01-13 11:03:35 -08:00
Adam Lesinski
76e9d76c22 UsageStats: Fix issue where initializing data for first time would cause crash
With the updated rolling window of stats for app idleness, we need to make sure
it is populated before we initialize some defaults.

Now that we look at older entries to figure out idleness, if those
entries are in the future (due to time change), set them to the current
screen on time.
Bug:26504153

Change-Id: Ia22add0e8eaf0f137002bbe3e91d747fef5b7d69
2016-01-12 16:52:45 -08:00
Adam Lesinski
881f6f9266 resolve merge conflicts of 551fc6823a to master.
Change-Id: I2778bf2a364c103fc0d351f2afc4fc73bede2f19
2016-01-12 16:41:48 -08:00
Adam Lesinski
da4a377573 UsageStatsService: Fix app idle issue at rollover time
App Idle queries are very frequent and so they only check in memory stats.
However, in memory stats can be missing some entries, especially after a rollover, but also
due to a larger bug fixed in master (too risky to take now).

The fix is to do a deep query (reading older files from disk) and maintain a parallel cache
of stats for app idle. That way the rolling window of data required to serve app idle queries
stays in memory.

Bug:26355386
Change-Id: I2dd3946b45d7d893410715bb0534b2b48694ced6
2016-01-09 05:58:52 +00:00
Jeff Sharkey
cd65448ccd Even more PackageManager caller triage.
Finish moving all UID/GID callers to single AIDL method that requires
callers to provide flags.

Triage AppWidgets and PrintServices, which currently can only live on
internal storage; we should revisit that later.

Fix two bugs where we'd drop pending install sessions and persisted
Uri grants for apps installed on external storage.

Bug: 26471205
Change-Id: I66fdfc737fda0042050d81ff8839de55c2b4effd
2016-01-08 18:35:54 -07:00
Jeff Sharkey
c5967e9862 More progress on triaging PackageManager callers.
Catch a bunch of simple cases where the PackageManager flags are
obvious.  Add the ability to use the MATCH_SYSTEM_ONLY flag on
PackageInfo and ApplicationInfo queries.

Re-examine recent tasks after a user is unlocked, since some of the
activities may now be available and runnable.

Bug: 26471205, 26253870
Change-Id: I989d9f8409070e5cae13202b47e2c7de85bf4a5b
2016-01-08 16:10:33 -07:00
Jeff Sharkey
e06b4d1d9f Consistent naming for PackageManager methods.
When hidden PackageManager methods take a userId argument, they
should be named explicitly with the "AsUser" suffix.  This fixes
several lagging examples so that we can pave the way to safely
start passing flags to new methods without scary overloading.

Also fix spacing issues in various logging statements.

Change-Id: I1e42f7f66427410275df713bea04f6e0445fba28
2016-01-06 15:21:06 -07:00
Mark Lu
8877120173 Fix system watchdog timeout when reading too many usage events.
Symptom:
As issue link:
https://code.google.com/p/android/issues/detail?id=193100

RootCause:
UsageStatsService.onDisplayChanged executed in system main thread,
If calling UsageStatsManager.queryEvents with too many events before it
(i.e. in daily usage event file,
too many activity resume / pause events or configuration change
during monkey test),
System will be blocked then watchdog timeout.

Solution:
Let display listener executed in background thread handler

BUG: 25355086

Change-Id: Ic894d112612400ed8fb7ba843b3309fdc4f66fe1
(Cherrypicked from 4e59db328d8b0cc163d2e3eb0f7f3a108f20a58d)
(cherry picked from commit 7018f60b06fd0c647ebf13225320d7e15d02e075)
2015-12-18 00:03:16 +00:00
Amith Yamasani
ccf7d9e8ce Use correct lock for reading/writing usage stats files
Bug: 25355086
Change-Id: I65946e5afa841215f161fc25ad70b31a108a33c3
2015-11-11 12:53:26 -08:00
Amith Yamasani
bdb94fe2ce Merge "Fix system watchdog timeout when reading too many usage events." am: 10b0bae06f am: b3d48f18a9
am: f12ffe6d76

* commit 'f12ffe6d762f281cbda56322be83a1da80b707ea':
  Fix system watchdog timeout when reading too many usage events.
2015-11-11 20:45:29 +00:00
Amith Yamasani
f12ffe6d76 Merge "Fix system watchdog timeout when reading too many usage events." am: 10b0bae06f
am: b3d48f18a9

* commit 'b3d48f18a94c586823462c93fc0f739c83f3db78':
  Fix system watchdog timeout when reading too many usage events.
2015-11-11 20:38:15 +00:00
Amith Yamasani
b3d48f18a9 Merge "Fix system watchdog timeout when reading too many usage events."
am: 10b0bae06f

* commit '10b0bae06ffdeb79494ddd1aff19387b56770960':
  Fix system watchdog timeout when reading too many usage events.
2015-11-11 20:30:32 +00:00
Mark Lu
4e59db328d Fix system watchdog timeout when reading too many usage events.
Symptom:
As issue link:
https://code.google.com/p/android/issues/detail?id=193100

RootCause:
UsageStatsService.onDisplayChanged executed in system main thread,
If calling UsageStatsManager.queryEvents with too many events before it
(i.e. in daily usage event file,
too many activity resume / pause events or configuration change
during monkey test),
System will be blocked then watchdog timeout.

Solution:
Let display listener executed in background thread handler

Change-Id: Ic894d112612400ed8fb7ba843b3309fdc4f66fe1
2015-11-09 07:24:48 +00:00
Dianne Hackborn
24937d235d resolve merge conflicts of 3aee38c86e to master.
Change-Id: I9ff3f92b37e24f5f0527a0034b159920f6d7ffe1
2015-11-03 12:47:12 -08:00
Dianne Hackborn
fcc95a6d2c Fix issue #25357209: Could not send SMS or MMS messages, had to reboot
I think what probably happened is that since we only report an app
going in to the "interaction" state as an interaction event to usage
stats, apps that sit around in that state forever will only see one
interaction at the start and never again.  So usage stats could start
thinking they are idle.

Fix this by having the activity manager report an interaction event
for such long running applications at least once a day.

Also, because it is correct and for paranoia by protected us another
way, system uids should never go in to standby.

Change-Id: I8a3805bfca86cbe78560488a649ecd07427da99a
2015-11-02 16:15:35 -08:00
Jeff Sharkey
9d77be8383 am d2c95f98: am 97604b42: am 9f1ae4dc: am fe9c950a: Merge "Fix parole scheduling bugs." into mnc-dr-dev
* commit 'd2c95f9821c98604ab06fb3d7c6f617bd88ada3e':
  Fix parole scheduling bugs.
2015-10-13 00:55:17 +00:00
Adam Lesinski
7cba1d46d3 UsageStats: Fix time change handling
When the time changed, we would end up creating a new stats file, even if we could
reuse an old one. On systems where the time toggled a lot, this would generate
hundreds of files and slow down other IO operations on this set.

Now we properly reuse stats files after time changes. The time at which a particular
file began recording was always clamped to the start of the interval (day, month, year).
However, this makes no sense when the time changes, and clamping to the start of the interval
would always cause a new file to be created, since the current time no longer fell into that
time interval. So now the time is just offset from the last file's end time.

Bug:22716352
Change-Id: I6cec156e2e93b4402116600fa09c1018f3b870fe
2015-09-15 17:40:01 +00:00
Jeff Sharkey
5ded7af622 Fix parole scheduling bugs.
There were a few subtle bugs in app idle parole scheduling that
would cause us to never end a parole period we had entered.  The
updated logic in this change concentrates the registration for the
next event in one place in setAppIdleParoled().

Bug: 24050462
Change-Id: I1efe43cd6e00a547f70c4a4a37e1f3ef52a7e706
2015-09-14 15:49:53 -07:00
Dianne Hackborn
35eb8d6205 am 1559f1c5: am 217d4568: am 8100b3fa: am 4439dcdc: am af75c17b: Fix issue #23270878: NPE in UsageStatsService while running UserManagementTest
* commit '1559f1c5a0a4db23b8338b8c4792dcb351c541f8':
  Fix issue #23270878: NPE in UsageStatsService while running UserManagementTest
2015-08-19 02:21:23 +00:00
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
908109c1f9 am 0385e3e9: am 8e63bbfd: am efa4dee1: am 977d421a: am f0e5501e: Merge "Fix issue #22989030: Separate battery whitelists" into mnc-dev
* commit '0385e3e908fb9988bb2d2d0d15e32cb6a819b34e':
  Fix issue #22989030: Separate battery whitelists
2015-08-08 02:49:41 +00: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
Xiaohui Chen
233d94c0df clean up UserHandle.USER_OWNER reference
cleaning up a few in framework/base/services.

Bug: 19913735
Change-Id: I1af5f24d9b39d6712ad3a665effa6166e32ce3d3
2015-08-03 13:05:33 -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