116 Commits

Author SHA1 Message Date
Jeff Sharkey
7d5420eda7 Enable kernel UID state updates.
Test: builds, boots
Bug: 34364961
Change-Id: Ia20c666063cb2e5cd91b401cc3be48fc83959010
2017-01-24 15:17:18 -07:00
Jeff Sharkey
9bed070b09 More APIs for cache status and behavior.
Add APIs for apps to query their cache usage compared to their
currently allocated quota.  Since an app's private storage may live
on a different storage volume than the primary shared/external
storage, offer APIs to retrieve those values separately.

Add APIs to control two new cache purging behaviors:

-- setCacheBehaviorAtomic() which causes a marked directory and its
contents to be treated as an atomic unit.
-- setCacheBehaviorTombstone() which causes the OS to truncate
files instead of deleting them.

Test: builds, boots
Bug: 33811826, 33965858, 27948817
Change-Id: I45de165623775c359f78b4ee544c2b5831b8d483
2017-01-23 21:02:12 -07:00
Jeff Sharkey
063c454b07 Disable kernel UID updates until update lands.
Current prebuilt kernel can result in the framework banging its head
against the wall writing the first duplicate update; it does this by
returning 0 for write().

We can revert this or flip the flag once an updated kernel lands.

Test: builds, boots
Bug: 33755020
Change-Id: Idb3e5ad40e2e6681848b47ce2b29dff9db3d4f6f
2017-01-19 20:25:06 -07:00
Jeff Sharkey
24caec2dad Merge "Write bg/fg status updates to kernel for stats." 2017-01-18 04:47:04 +00:00
Jeff Sharkey
f3b0ef2f40 Write bg/fg status updates to kernel for stats.
New procfs file written by the system_server to communicate fg/bg
state of UIDs to switch the statistics counter sets used.

Test: builds, boots, counter sets updated
Bug: 34360629
Change-Id: I3339a93bce6aec65779a4a4aee52f5328896bb29
2017-01-17 18:41:03 -07:00
Jeff Sharkey
7d25fafea7 Invalidate installd when mounts change.
Test: builds, boots, common operations work
Bug: 34249218
Change-Id: Ia893b43dd7ff6078d91df50a9e8d644583617982
2017-01-16 20:58:43 -07:00
Kang Li
9fa2a2cd46 Adds annotations to Intent, and enables ChooserActivity to rank apps
according to annotations.

Test: Unit tests and manul tests. More unit tests to be added.
Change-Id: I3cbfd0cc10007290585fa3e7e3c92e1731f1f7b8
2017-01-13 17:40:44 -08:00
TreeHugger Robot
f0707fe34a Merge "Fix a near instant stats permission check false negative." 2017-01-13 19:36:46 +00:00
Daniel Nishi
2f0b45ab60 Initialize the Installer in the StorageStatsService.
Without this, the Installer never connects to the underlying
installd service, which results in NPEs when the service is used.

Bug: 34261458
Test: builds and runs w/o crashing
Change-Id: I9222c26cf6e411710e07a74f29b019f7c5754316
2017-01-12 17:19:50 -08:00
Daniel Nishi
d85d85394e Fix a near instant stats permission check false negative.
The MODE_DEFAULT enforcePermission behavior fell through to
the switch default case, even if the calling permission was
granted.

Bug: 34258237
Test: Manual
Change-Id: I823fb4dc3657c15eb1fa3d12d4f4c7e1e9e21cd5
2017-01-12 16:10:57 -08:00
Jeff Sharkey
8dedad31f7 Wire up storage stats API to installd.
Now that installd has the implementation details we need, we can wire
up the public APIs to use them.

Shuffle APIs around a bit so that StorageStats can be reused for both
UID and UserHandle results, and rename StorageSummary to
ExternalStorageStats.  Provide getTotalBytes() and getFreeBytes() as
first-class methods so we can answer those questions quickly without
paying the cost of measuring external storage details.

Current costs on a typical device with a test account after flushing
dentry caches:

queryStatsForUid() manual: 6922ms
queryStatsForUid() quota: 525ms

queryStatsForUser() manual: 1686ms
queryStatsForUser() quota: 113ms

queryExternalStatsForUser() manual: 42ms
queryExternalStatsForUser() quota: 2ms

For verification purposes, a new "fw.verify_storage" system property
can be set to compute both manual and quota statistics, and log any
discrepancies.

Test: builds, boots
Bug: 27948817, 32206268
Change-Id: I4ea3df3372a7379aa8cf4c20c44120c8f0702c15
2017-01-09 22:30:58 -07:00
Jeff Sharkey
e8cece9f20 Initial API shape for storage statistics.
This API is designed to provide both UID-level stats and overall
summary data for a given storage device, as identified by UUID.

The use of UID-level granularity might appear a bit clunky, but it
matches other usage statistics (such as network and battery), and it
allows us to implement it using an extremely fast quota kernel
feature.

A future CL will wire up the implementation to installd.

Test: builds, boots
Bug: 32206268
Change-Id: I7b51877682d0370c2402c19346f57809f0e7ac53
2017-01-05 15:39:16 -07:00
Kang Li
b431d715a3 Merge "Add Sharing Histories to UsageStatsManager." 2016-12-14 19:26:34 +00:00
Kang Li
53b4314ad9 Add Sharing Histories to UsageStatsManager.
This CL is for Android O Smart-Sharing (b/30982298). By this CL, sharing
counts are logged with UsageStatsManager.

Bug: 30982298
Test: manual - shared images in Camera and texts in Chrome using a mobile device.

Change-Id: I0b4aa0506f99b3083d140a48f7b4bdd5b1c5afb6
2016-12-13 17:35:38 -08:00
Amith Yamasani
0d1fd8d091 Secure MATCH_UNINSTALLED_PACKAGES across users
Introduce a new internal flag MATCH_ANY_USER for genuine uses
of searching through all apps on the device.

Some temporary accommodations for Launchers that reach across
to the work profile until we have a new LauncherApps API to do
that officially.

Bug: 31000380
Test: CTS tests added
Change-Id: I2e43dc49d6c2e11814a8f8d1eb07ef557f31af34
2016-11-30 13:24:53 -08:00
Sudheer Shanka
dc589ac82b Update usage of ActivityManagerNative.
- Remove references to ActivityManagerProxy.
- Add isSystemReady to ActivityManager.

Bug: 30977067
Test: cts/hostsidetests/services/activityandwindowmanager/util/run-test android.server.cts
      adb shell am instrument -e class com.android.server.am.ActivityManagerTest,com.android.server.am.TaskStackChangedListenerTest \
          -w com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
Change-Id: I07390b6124fb1515821f5c0b37baf6ae74adc8fa
2016-11-14 11:27:12 -08:00
Amith Yamasani
693d869b32 Handle charging state separately from temporary parole
Don't use the parole state to deal with the plugged-in trigger.
Otherwise standby apps will only be paroled for a few minutes
after plugging in to charge and not the entire duration.

Use a different intent for charging state, since the CHARGING
intent takes several seconds to be received.

A refactor some time ago changed the charging state behavior
that caused this regression.

Bug: 31399882
Change-Id: Ic036de5e136b3151b225473d0c3f440adb3b48e7
2016-09-15 13:38:43 -07:00
Adam Lesinski
f2d87eba75 AppIdleHistory: Only write screen on durations during regular sync
Stop writing to disk every time the display goes off. Only write to
disk periodically.

Consequences

Previously, if the device rebooted after the screen duration was written
to disk, apps would appear more stale than they actually were.

Now apps will always look fresher, which is a better scenario.

Bug:30807864
Change-Id: Ia69a2e51fc9e397789215b449fae56fa3e29c74a
2016-08-17 16:42:46 -07:00
Tony Mak
589fca469f Whitelisting device provisioning package from app standby
Change-Id: Ib9cb7a3fdf7aa16a97f22eacbed872880b7f9fbe
Fix: 29892977
2016-07-15 03:41:41 +00:00
Makoto Onuki
ac042501c8 ShortcutManager: Implement usage report API
Bug 28536054

Change-Id: I293e8eaad523e3b0d76d562fc381601633451ed3
2016-06-02 15:57:40 -07:00
Dianne Hackborn
5fb47f3ed7 Fix issue #28118215: Crash during system boot due to null carrier apps
Change-Id: I607ccc4baf769c2fb78b0d745bf9fddc3d240855
2016-04-11 13:02:08 -07:00
David Brazdil
ae4cde1cce Do not update idle apps on OTA
Modifies the PackageManagerService.updatePackagesIfNeeded to filter
out packages which are considered idle by the UsageStatsManager.

Bug: 27902702
Change-Id: I8847dfc283e0246265009effb6394bb774848eb3
2016-04-06 15:21:31 +01:00
Amith Yamasani
bdda1e076e Clear app idle state for removed packages
On a package being added or removed, remove
app idle state for the app.

Bug: 27570398
Bug: 26182816
Change-Id: I14bdc1f951bbd99bda8111bea56f8c9dda04148d
2016-03-14 11:55:38 -07:00
Jeff Sharkey
c53962d4ed When system server goes down, crash apps more.
Apps making calls into the system server may end up persisting
internal state or making security decisions based on the perceived
success or failure of a call, or the default values returned.

The reality is that if the system process just died, init will be
along shortly to kill all running apps, so we should have no problem
rethrowing the RemoteException as a RuntimeException.

Bug: 27364859
Change-Id: Ife0bcb079636c88d54c44d17eb580409fd79028b
2016-03-01 19:29:16 -07:00
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