summaryrefslogtreecommitdiff
path: root/services/usage/java
diff options
context:
space:
mode:
author Jeff Sharkey <jsharkey@android.com> 2017-05-26 13:10:46 -0600
committer Jeff Sharkey <jsharkey@android.com> 2017-05-30 22:17:23 -0600
commitddff807b762a8a455287abc97aea8f97b98fb104 (patch)
tree9f5dc24ea84eb9d64e575d7210b99718ff318fd3 /services/usage/java
parent1399d3abf51265915a3d6cbd2b04be2a3142c609 (diff)
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
Diffstat (limited to 'services/usage/java')
-rw-r--r--services/usage/java/com/android/server/usage/StorageStatsService.java43
1 files changed, 29 insertions, 14 deletions
diff --git a/services/usage/java/com/android/server/usage/StorageStatsService.java b/services/usage/java/com/android/server/usage/StorageStatsService.java
index 16b73d5515e5..562443f53546 100644
--- a/services/usage/java/com/android/server/usage/StorageStatsService.java
+++ b/services/usage/java/com/android/server/usage/StorageStatsService.java
@@ -62,6 +62,8 @@ import com.android.server.pm.Installer;
import com.android.server.pm.Installer.InstallerException;
import com.android.server.storage.CacheQuotaStrategy;
+import java.io.File;
+import java.io.FileNotFoundException;
import java.io.IOException;
public class StorageStatsService extends IStorageStatsManager.Stub {
@@ -181,29 +183,42 @@ public class StorageStatsService extends IStorageStatsManager.Stub {
public long getFreeBytes(String volumeUuid, String callingPackage) {
// NOTE: No permissions required
- long cacheBytes = 0;
final long token = Binder.clearCallingIdentity();
try {
+ final File path;
+ try {
+ path = mStorage.findPathForUuid(volumeUuid);
+ } catch (FileNotFoundException e) {
+ throw new ParcelableException(e);
+ }
+
+ // Free space is usable bytes plus any cached data that we're
+ // willing to automatically clear. To avoid user confusion, this
+ // logic should be kept in sync with getAllocatableBytes().
if (isQuotaSupported(volumeUuid, callingPackage)) {
- for (UserInfo user : mUser.getUsers()) {
- final StorageStats stats = queryStatsForUser(volumeUuid, user.id, null);
- cacheBytes += stats.cacheBytes;
- }
+ final long cacheTotal = getCacheBytes(volumeUuid, callingPackage);
+ final long cacheReserved = mStorage.getStorageCacheBytes(path);
+ final long cacheClearable = Math.max(0, cacheTotal - cacheReserved);
+
+ return path.getUsableSpace() + cacheClearable;
+ } else {
+ return path.getUsableSpace();
}
} finally {
Binder.restoreCallingIdentity(token);
}
+ }
- if (volumeUuid == StorageManager.UUID_PRIVATE_INTERNAL) {
- return Environment.getDataDirectory().getFreeSpace() + cacheBytes;
- } else {
- final VolumeInfo vol = mStorage.findVolumeByUuid(volumeUuid);
- if (vol == null) {
- throw new ParcelableException(
- new IOException("Failed to find storage device for UUID " + volumeUuid));
- }
- return vol.getPath().getFreeSpace() + cacheBytes;
+ @Override
+ public long getCacheBytes(String volumeUuid, String callingPackage) {
+ enforcePermission(Binder.getCallingUid(), callingPackage);
+
+ long cacheBytes = 0;
+ for (UserInfo user : mUser.getUsers()) {
+ final StorageStats stats = queryStatsForUser(volumeUuid, user.id, null);
+ cacheBytes += stats.cacheBytes;
}
+ return cacheBytes;
}
@Override