diff --git a/core/java/android/app/usage/StorageStatsManager.java b/core/java/android/app/usage/StorageStatsManager.java index 82762293a241c..b808c2b75203a 100644 --- a/core/java/android/app/usage/StorageStatsManager.java +++ b/core/java/android/app/usage/StorageStatsManager.java @@ -81,9 +81,9 @@ public class StorageStatsManager { /** * Return the free space on the requested storage volume. *
- * 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. *
* This method may take several seconds to calculate the requested values, * so it should only be called from a worker thread. diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index c27806d80ac92..e348051bb15f6 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -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; diff --git a/services/usage/java/com/android/server/usage/StorageStatsService.java b/services/usage/java/com/android/server/usage/StorageStatsService.java index ebd4b019790a8..0a3f596ad5631 100644 --- a/services/usage/java/com/android/server/usage/StorageStatsService.java +++ b/services/usage/java/com/android/server/usage/StorageStatsService.java @@ -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; } }