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
This commit is contained in:
Jeff Sharkey
2017-05-26 13:10:46 -06:00
parent 1399d3abf5
commit ddff807b76
14 changed files with 409 additions and 511 deletions

View File

@@ -2108,7 +2108,7 @@ public class ApplicationPackageManager extends PackageManager {
public void freeStorageAndNotify(String volumeUuid, long idealStorageSize,
IPackageDataObserver observer) {
try {
mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, observer);
mPM.freeStorageAndNotify(volumeUuid, idealStorageSize, 0, observer);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
@@ -2117,7 +2117,7 @@ public class ApplicationPackageManager extends PackageManager {
@Override
public void freeStorage(String volumeUuid, long freeStorageSize, IntentSender pi) {
try {
mPM.freeStorage(volumeUuid, freeStorageSize, pi);
mPM.freeStorage(volumeUuid, freeStorageSize, 0, pi);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}

View File

@@ -24,6 +24,7 @@ interface IStorageStatsManager {
boolean isQuotaSupported(String volumeUuid, String callingPackage);
long getTotalBytes(String volumeUuid, String callingPackage);
long getFreeBytes(String volumeUuid, String callingPackage);
long getCacheBytes(String volumeUuid, String callingPackage);
long getCacheQuotaBytes(String volumeUuid, int uid, String callingPackage);
StorageStats queryStatsForPackage(String volumeUuid, String packageName, int userId, String callingPackage);
StorageStats queryStatsForUid(String volumeUuid, int uid, String callingPackage);

View File

@@ -142,6 +142,24 @@ public class StorageStatsManager {
return getFreeBytes(convert(uuid));
}
/** {@hide} */
public @BytesLong long getCacheBytes(@NonNull UUID storageUuid) throws IOException {
try {
return mService.getCacheBytes(convert(storageUuid), mContext.getOpPackageName());
} catch (ParcelableException e) {
e.maybeRethrow(IOException.class);
throw new RuntimeException(e);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
/** {@hide} */
@Deprecated
public long getCacheBytes(String uuid) throws IOException {
return getCacheBytes(convert(uuid));
}
/**
* Return storage statistics for a specific package on the requested storage
* volume.

View File

@@ -360,7 +360,7 @@ interface IPackageManager {
* the operation is completed
*/
void freeStorageAndNotify(in String volumeUuid, in long freeStorageSize,
IPackageDataObserver observer);
int storageFlags, IPackageDataObserver observer);
/**
* Free storage by deleting LRU sorted list of cache files across
@@ -384,7 +384,7 @@ interface IPackageManager {
* to indicate that no call back is desired.
*/
void freeStorage(in String volumeUuid, in long freeStorageSize,
in IntentSender pi);
int storageFlags, in IntentSender pi);
/**
* Delete all the cache files in an applications cache directory

View File

@@ -1642,11 +1642,20 @@ public class StorageManager {
*/
@RequiresPermission(android.Manifest.permission.ALLOCATE_AGGRESSIVE)
@SystemApi
public static final int FLAG_ALLOCATE_AGGRESSIVE = 1;
public static final int FLAG_ALLOCATE_AGGRESSIVE = 1 << 0;
/**
* Flag indicating that a disk space allocation request should defy any
* reserved disk space.
*
* @hide
*/
public static final int FLAG_ALLOCATE_DEFY_RESERVED = 1 << 1;
/** @hide */
@IntDef(flag = true, value = {
FLAG_ALLOCATE_AGGRESSIVE,
FLAG_ALLOCATE_DEFY_RESERVED,
})
@Retention(RetentionPolicy.SOURCE)
public @interface AllocateFlags {}