From 587207150b76260b07063564300403643a07495b Mon Sep 17 00:00:00 2001 From: Daniel Nishi Date: Wed, 6 Sep 2017 14:34:41 -0700 Subject: [PATCH] Cap user-visible cache size at quota. Anything over the quota is considered free for storage purposes because the system can clear it out at will. This is reflected in the top level Storage Settings, but not in the ApplicationsState-based views. This change makes ApplicationsState cap the cache size as well. Change-Id: I733a39da7fea993065d767978b4191cc82f908b8 Fixes: 65384688 Test: b/34768986 --- .../applications/ApplicationsState.java | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java b/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java index 87bf0de2b2c86..d5038e4a02511 100644 --- a/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java +++ b/packages/SettingsLib/src/com/android/settingslib/applications/ApplicationsState.java @@ -339,26 +339,35 @@ public class ApplicationsState { synchronized (mEntriesMap) { AppEntry entry = mEntriesMap.get(userId).get(packageName); if (entry != null && (entry.info.flags & ApplicationInfo.FLAG_INSTALLED) != 0) { - mBackgroundHandler.post(() -> { - try { - final StorageStats stats = mStats.queryStatsForPackage( - entry.info.storageUuid, packageName, UserHandle.of(userId)); - final PackageStats legacy = new PackageStats(packageName, userId); - legacy.codeSize = stats.getCodeBytes(); - legacy.dataSize = stats.getDataBytes(); - legacy.cacheSize = stats.getCacheBytes(); - try { - mBackgroundHandler.mStatsObserver.onGetStatsCompleted(legacy, true); - } catch (RemoteException ignored) { - } - } catch (NameNotFoundException | IOException e) { - Log.w(TAG, "Failed to query stats: " + e); - try { - mBackgroundHandler.mStatsObserver.onGetStatsCompleted(null, false); - } catch (RemoteException ignored) { - } - } - }); + mBackgroundHandler.post( + () -> { + try { + final StorageStats stats = + mStats.queryStatsForPackage( + entry.info.storageUuid, + packageName, + UserHandle.of(userId)); + final long cacheQuota = + mStats.getCacheQuotaBytes( + entry.info.storageUuid.toString(), entry.info.uid); + final PackageStats legacy = new PackageStats(packageName, userId); + legacy.codeSize = stats.getCodeBytes(); + legacy.dataSize = stats.getDataBytes(); + legacy.cacheSize = Math.min(stats.getCacheBytes(), cacheQuota); + try { + mBackgroundHandler.mStatsObserver.onGetStatsCompleted( + legacy, true); + } catch (RemoteException ignored) { + } + } catch (NameNotFoundException | IOException e) { + Log.w(TAG, "Failed to query stats: " + e); + try { + mBackgroundHandler.mStatsObserver.onGetStatsCompleted( + null, false); + } catch (RemoteException ignored) { + } + } + }); } if (DEBUG_LOCKING) Log.v(TAG, "...requestSize releasing lock"); }