History log of /frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
c8b29ac6f0340bd0c3c9eb388c4be2d446de9a59 06-Jul-2017 Jeff Sharkey <jsharkey@android.com> Change storage migration to use quota APIs.

New quota APIs are much faster than trying to measure manually, and
removing this last user of calculateDirectorySize() means we can
remove it once and for all.

Bug: 36056324
Test: builds, boots
Change-Id: Ibdf1ee4e8885680e106df6a9269b6309ddc61af8
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
35e46d297255363a20ccde62af3c58c4ce3c13c5 09-Jun-2017 Jeff Sharkey <jsharkey@android.com> Active camera apps can defy reserved cache space.

We normally prevent apps from allocating into the "reserved" cache
space, but this change makes an exception for an active camera app,
since the user is probably trying to capture an important memory.

This change only lets the active camera app clear up to half of the
reserved space, since we don't want to completely destroy the
experience of all other apps.

Test: manual app before/during/after active camera session
Bug: 38267830
Change-Id: Ie9e63884fb2638ca881e10b894629eea84601648
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
ddff807b762a8a455287abc97aea8f97b98fb104 26-May-2017 Jeff Sharkey <jsharkey@android.com> Consistent "low storage" behavior.

When answering the question "how much space is free", use the same
logic for Settings UI and StorageManager.getAllocatableBytes(). That
is, the reported free space is usable bytes plus any cached data the
system is willing to delete automatically.

This does *not* include any reserved cache space, since we don't want
abusive apps to penalize other well-behaved apps that are storing
their data in cache locations. Callers freeing cached data need to
now explicitly request defiance of the reserved cache space. (Most
callers are already doing this by using FLAG_ALLOCATE_AGGRESSIVE.)

Rewrite the core logic of DeviceStorageMonitorService to understand
this new "reserved" cache space, and to be easier to understand. It
also now handles cached data on adopted storage volumes, which had
been ignored until now. Also fix bug where we had skipped "low"
broadcasts when the device skipped directly from/to "full" state.

Bug: 38008706
Test: cts-tradefed run commandAndExit cts-dev -m CtsJobSchedulerTestCases -t android.jobscheduler.cts.StorageConstraintTest
Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.StorageHostTest
Change-Id: Icbdcf3b52775f7ada1ceaeff2f96094c8d8052f9
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
06823d4c2e0fc7d64bff5d3e155d690302e0ab80 10-May-2017 Jeff Sharkey <jsharkey@android.com> Use "real" free space; refresh on large changes.

For volumes where the OS manages cached data, use the "free space" as
reported by StorageStatsManager, which is the same value shown in
the Settings app and other UI elements.

Also, when the storage space changes significantly, invalidate anyone
who was holding a cached "free space" value.

Test: builds, boots
Bug: 38146029
Change-Id: I4b3a484a8bf32cd137a83f1ea441beca6dc6719a
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
5a421ad0ef23675ca3140d3ae9d578c4b8baf0e8 07-May-2017 Jeff Sharkey <jsharkey@google.com> Merge "Defeat @Nullable String[] with empty list." into oc-dev
2abd66c4ffdb7905128b1ca245d4ccb97cbda1c8 05-May-2017 Jeff Sharkey <jsharkey@android.com> Defeat @Nullable String[] with empty list.

Test: builds, boots
Bug: 37577123
Change-Id: I6bf1af565398c30aecc0939a23846c0f85c13ffe
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
fd65813157e4dd7fa9f0b7c5dd4c8f536cc6316a 03-May-2017 Jeff Sharkey <jsharkey@android.com> Offer to wait until broadcasts have drained.

We've seen evidence of lab devices racing with other apps that are
using cache space immediately after tests wipe it clean, which can
cause test failures. To mitigate this, try our best to wait for the
device to go "idle" by watching for broadcast queues to fully drain.

Also improve javadocs along the way.

Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.StorageHostTest
Bug: 37486230, 37566983, 37913442, 37914374
Change-Id: I4d430db443b6fa6d33a625fe07b90279b5d51c12
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
a4d34d971c9566a162a53e6b027ba2bc341ae5b4 27-Apr-2017 Jeff Sharkey <jsharkey@android.com> Respond to API council feedback.

Move aggressive allocation to @SystemApi, which means we can hide
the "flags" API variants.

Remove UUID APIs, since we should use existing Serializable APIs.

Relax permission checks to allow apps to ask for their own stats.

Improve docs.

Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.StorageHostTest
Bug: 37534687, 37534941, 37718184, 37738770
Change-Id: I6a763fb3ab3169c8d3329765bb31e1ee08d9ced7
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
0034788844fd053f87beee60092c1dd44c7046e2 18-Apr-2017 Jeff Sharkey <jsharkey@android.com> Fix code accounting bugs, track external app data.

When counting code size, don't include APKs baked into the system.

Settings already accounts external storage used by apps, so they
need a way to exclude that from the total space used by external
storage; give them new getAppSize() API.

Refine docs to explain that emulated storage might be included in
measured statistics.

Resolve symlinks as part of matching getUuidForPath().

Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.StorageHostTest
Bug: 35812899, 35844919, 37193650
Change-Id: Iec3ce8b336b71dc98a7d25fdd30fa78e9ee826dc
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
789a8fc792725e4988ff43d554b3c8c037c41921 16-Apr-2017 Jeff Sharkey <jsharkey@android.com> Storage API polishing.

Based on API council feedback, switch to using real UUID objects
instead of Strings. Since UUID is a general-purpose utility class
that will be passed around quite a bit, add it to Parcel and Bundle.

Define well-known namespaced UUID values for "default" and "primary
physical" storage devices, which will let us annotate a bunch of
things with @NonNull.

Define new extras for MANAGE_STORAGE intent that apps can use to
signal where and how much space they'd like the user to free up.

Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.StorageHostTest
Bug: 37325923, 35812899, 35806020
Change-Id: I8421b126d680f69141a361c1e77223fe2bf4a325
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
b28c9d6b2d3b52d7c4ac1ad8c18591be99e92772 31-Mar-2017 Daniel Nishi <dhnishi@google.com> Fix crash when measuring storage.

If we are measuring storage and a volume is removed at the same time,
we can enter a state where we previously verified the volume existed,
but it no longer does. This causes an NPE.

By adding in a null check, we can avoid this crash.

Change-Id: Ib8dbf05102a122bdf4bb6063374e993a1de68425
Fixes: 36689190
Test: None
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
dafb17e7eb9a15862ed1314dff2b82d29ad23632 03-Apr-2017 Jeff Sharkey <jsharkey@android.com> We really want f_frsize and f_bavail.

It's confusing, but f_bsize is not the value you're looking for; the
real block size is f_frsize. Fix all those bugs.

Also, the vast majority of clients are interested in the usable
disk space, not including reserved space.

Test: builds, boots
Bug: 36840579
Change-Id: Ib1470389afd49c14cab62282ec1e978ebb2c4791
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
b5a35b8181fc1fc0d854b69e42d277b89d87ad53 23-Mar-2017 Jeff Sharkey <jsharkey@android.com> Refactor cache behavior from "atmoic" to "group".

Using the word "atomic" has too much baggage relating to locking
guarantees, so move to something softer.

Add isQuotaSupported() for CTS tests.

Move CacheQuotaStrategy over to using SparseLongArray, which has a
more efficient memory footprint inside the system server.

Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.StorageHostTest
Bug: 35812899, 35684969, 36482620
Change-Id: I894f53e6f3bc76c77d1bb18c51db14833df14a49
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
d3b1def2ebe1821212b9f110dff2fb0b15491e1b 15-Mar-2017 TreeHugger Robot <treehugger-gerrit@google.com> Merge "Enable cache clearing v2 logic, fix bugs."
e730ae877a24d44f5b3db096f08b0a2d7399aa2d 15-Mar-2017 Jeff Sharkey <jsharkey@android.com> Enable cache clearing v2 logic, fix bugs.

Now that we have CTS tests to verify the cache clearing v2 logic,
we're ready to enable it!

Switch storage APIs over to "usable space" to match implementation
down in installd. Add a missing clearCallingIdentity(), and offer
better logging for missing appop permission.

Load quotas from disk right away at device boot instead of waiting.

Bug: 35685848, 35684969
Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.StorageHostTest
Change-Id: I8167e0322b4662ca6c975da5c50715e2d71332a7
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
6bb5d0fabbe9dfce3d1da8ae94bc1de470e01bb0 14-Mar-2017 Jeff Sharkey <jsharkey@android.com> Allow querying for apps on adopted storage.

Apps that live on adopted storage devices appear to be uninstalled
while ejected. They're technically still valid apps, with allocated
UIDs, so use MATCH_UNINSTALLED_PACKAGES when querying for their
details.

Test: builds, boots
Bug: 36177795
Change-Id: Ia7ed5f0462b1f47609ea8e1ace6fa145e0b5602c
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
f02e97cb25ff7bc4a2bd46dbf271e59a7eafb867 13-Mar-2017 Daniel Nishi <dhnishi@google.com> Merge "Hook up the cache quota query."
2572b967ba5c2f1d3ac5d9ef56a26fb388c3d940 12-Mar-2017 Jeff Sharkey <jsharkey@android.com> Offer flag to force manual calculation.

Can be used to quickly pivot between manual and quota calculations
when running CTS tests.

Bug: 35684969, 35441006, 34945234
Test: cts-tradefed run commandAndExit cts-dev -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.StorageHostTest
Change-Id: I7500dde597a4f3cde20998df45c5d54a053181fc
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
82add8a7145c864ce8a604e145ed6abcaa4640b4 12-Mar-2017 Jeff Sharkey <jsharkey@android.com> Fix two storage measurement bugs.

First, every time installd starts up we need to invalidateMounts()
to ensure we have valid mappings for quotactl() to work. (Without
this forced invalidation, we were falling back to manual calculation
after an installd restart.)

Second, when calculating the disk space for an app, we need to use
the real appId deconstructed from the uid; oops! (Without this we
were always trying to calculate the disk usage for UID 0, which
forced us back into the slow-path.)

Bug: 36032444, 35706513
Test: runtest -x frameworks/base/services/tests/servicestests/src/com/android/server/pm/InstallerTest.java
Change-Id: I1ca55e2b7670678ed55798e2e06857d727ce2487
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
80fdb0149de107347f59b6badbf7386a166f4a92 09-Mar-2017 Daniel Nishi <dhnishi@google.com> Hook up the cache quota query.

Apps should now be able to get the real cache quota
value, instead of a stock 64MB.

Bug: 33965858
Test: Manually verified that an app recevied a non-64MB quota.
Change-Id: Idba47ecba356ffb592694a0d5a72363f3d0e95d0
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
e40da3c1b7d4eb810b6f067075dbbb011d02a379 14-Feb-2017 Daniel Nishi <dhnishi@google.com> Save/load calculated cache quotas to a file.

This will prevent us from unnecessarily redoing calculation work
by loading the last caches on boot and shoving them down to
installd.

Bug: 33965858
Test: Framework services tests
Change-Id: Ie94e269aa72bceb1ebe87911eaa42e2d826c1123
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
6f2c1ea250f957b35c76bcc301d3513433de911f 23-Feb-2017 Jeff Sharkey <jsharkey@google.com> Merge "Add queryStatsForPackage() API."
373d01766f27476e81a174727dcfeee406742417 22-Feb-2017 Jeff Sharkey <jsharkey@android.com> Add queryStatsForPackage() API.

This gives developers a way to collect package-level stats, even if
it means we have to use manual calculation for sharedUserId apps.

Also round size of storage devices to nice power-of-two values so we
do a better job of matching retail packaging.

Test: builds, boots
Bug: 35294241
Change-Id: I24946c443bb9dc4b0411a8149a0656702ac1fd24
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
0f703e64e3e111048acb7abf5792d589ce1e3eb7 22-Feb-2017 Daniel Nishi <dhnishi@google.com> Add a flag to enable/disable the cache quota calc.

Bug: 34770259
Test: ServicesTests
Change-Id: I74155203c4802b1a3b89117859002bf40b1ca435
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
830d4b422db2f2ae4af17403ccd1d34fd6f0bd6f 21-Feb-2017 Jeff Sharkey <jsharkey@google.com> Merge "Clear cache space when allocating bytes."
d5d5e926eb8ff2541a845d6a5657cee5e5c6e7b6 21-Feb-2017 Jeff Sharkey <jsharkey@android.com> Clear cache space when allocating bytes.

Fleshes out remainder of allocation implementation, where we offer
to clear cached data to satisfy the allocation request. To prevent
abuse, we never let apps allocate into either the minimum cache space
or low storage space.

Clean up quota APIs to require the caller to pass in the path they're
interested in, and we resolve the underlying filesystem for them.

Defines settings that can be used to tweak the minimum cache space.

Test: builds, boots
Bug: 34690590
Change-Id: I85bc07399f91ee4aa568a8a54c615646bf748ad4
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
cf9d19e030830fd808d59f1c97edf65e66f675d6 23-Jan-2017 Daniel Nishi <dhnishi@google.com> First pass at adding the cache quota suggestions.

This currently integrates with installd, but not with
any framework API to expose this information to apps.

The first pass, as per the design doc, adds a service
which polls for large changes in the file system free space.
If enough spaces changes, it begins a recalculation of the
cache quotas and pipes the information down to installd.
This calculation is done in the updateable ExtServices.

Further enhancements in later patches include integrating this
to listen to package install and removal events, caching the
last computed quota values into an XML file on disk to load
on boot, and exposing the information to apps.

Bug: 33965858
Test: ExtServices unit test

Change-Id: Ie39f228b73532cb6ce2f98529f7c5df0839202ae
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
9bed070b0910aad8c5800cec731058911d20c3d3 24-Jan-2017 Jeff Sharkey <jsharkey@android.com> 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
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
7d25fafea7b313cf3eee5bbf4eb959f4986ffce4 17-Jan-2017 Jeff Sharkey <jsharkey@android.com> Invalidate installd when mounts change.

Test: builds, boots, common operations work
Bug: 34249218
Change-Id: Ia893b43dd7ff6078d91df50a9e8d644583617982
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
f0707fe34a60da70146db0c79738f93f2149c88c 13-Jan-2017 TreeHugger Robot <treehugger-gerrit@google.com> Merge "Fix a near instant stats permission check false negative."
2f0b45ab6021816752c42065991e71e5afadb162 13-Jan-2017 Daniel Nishi <dhnishi@google.com> 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
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
d85d85394ef96489e0848edd72b275798281d779 13-Jan-2017 Daniel Nishi <dhnishi@google.com> 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
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
8dedad31f7fa604028ee6d28963bcc564e76c467 10-Jan-2017 Jeff Sharkey <jsharkey@android.com> 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
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java
e8cece9f2010388e02d8f4b3150f25168f8b7d76 04-Jan-2017 Jeff Sharkey <jsharkey@android.com> 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
/frameworks/base/services/usage/java/com/android/server/usage/StorageStatsService.java