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
This commit is contained in:
Jeff Sharkey
2017-03-14 23:37:35 -06:00
parent b94427d285
commit e730ae877a
3 changed files with 17 additions and 11 deletions

View File

@@ -81,9 +81,9 @@ public class StorageStatsManager {
/**
* Return the free space on the requested storage volume.
* <p>
* The free space is equivalent to {@link File#getFreeSpace()} plus the size
* of any cached data that can be automatically deleted by the system as
* additional space is needed.
* The free space is equivalent to {@link File#getUsableSpace()} plus the
* size of any cached data that can be automatically deleted by the system
* as additional space is needed.
* <p>
* This method may take several seconds to calculate the requested values,
* so it should only be called from a worker thread.

View File

@@ -399,7 +399,7 @@ public class PackageManagerService extends IPackageManager.Stub {
private static final boolean HIDE_EPHEMERAL_APIS = false;
private static final boolean ENABLE_FREE_CACHE_V2 =
SystemProperties.getBoolean("fw.free_cache_v2", false);
SystemProperties.getBoolean("fw.free_cache_v2", true);
private static final int RADIO_UID = Process.PHONE_UID;
private static final int LOG_UID = Process.LOG_UID;

View File

@@ -105,7 +105,7 @@ public class StorageStatsService extends IStorageStatsManager.Stub {
invalidateMounts();
mHandler = new H(IoThread.get().getLooper());
mHandler.sendEmptyMessageDelayed(H.MSG_LOAD_CACHED_QUOTAS_FROM_FILE, DELAY_IN_MILLIS);
mHandler.sendEmptyMessage(H.MSG_LOAD_CACHED_QUOTAS_FROM_FILE);
mStorage.registerListener(new StorageEventListener() {
@Override
@@ -137,7 +137,8 @@ public class StorageStatsService extends IStorageStatsManager.Stub {
android.Manifest.permission.PACKAGE_USAGE_STATS, TAG);
return;
default:
throw new SecurityException("Blocked by mode " + mode);
throw new SecurityException("Package " + callingPackage + " from UID " + callingUid
+ " blocked by mode " + mode);
}
}
@@ -169,16 +170,21 @@ public class StorageStatsService extends IStorageStatsManager.Stub {
enforcePermission(Binder.getCallingUid(), callingPackage);
long cacheBytes = 0;
for (UserInfo user : mUser.getUsers()) {
final StorageStats stats = queryStatsForUser(volumeUuid, user.id, null);
cacheBytes += stats.cacheBytes;
final long token = Binder.clearCallingIdentity();
try {
for (UserInfo user : mUser.getUsers()) {
final StorageStats stats = queryStatsForUser(volumeUuid, user.id, null);
cacheBytes += stats.cacheBytes;
}
} finally {
Binder.restoreCallingIdentity(token);
}
if (volumeUuid == StorageManager.UUID_PRIVATE_INTERNAL) {
return Environment.getDataDirectory().getFreeSpace() + cacheBytes;
return Environment.getDataDirectory().getUsableSpace() + cacheBytes;
} else {
final VolumeInfo vol = mStorage.findVolumeByUuid(volumeUuid);
return vol.getPath().getFreeSpace() + cacheBytes;
return vol.getPath().getUsableSpace() + cacheBytes;
}
}