Merge "Cap user-visible cache size at quota." into oc-mr1-dev

This commit is contained in:
Daniel Nishi
2017-09-08 21:42:56 +00:00
committed by Android (Google) Code Review

View File

@@ -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");
}