Don't attribute a blob to a user if there are leasees from other users.

Bug: 187460239
Test: atest --test-mapping apex/blobstore
Change-Id: I5e9c0473e4c058d430ed012a3ca3ee63f3595821
This commit is contained in:
Sudheer Shanka
2021-06-02 00:23:09 -07:00
parent 1dfd948440
commit 0bfffa6b25
2 changed files with 16 additions and 2 deletions

View File

@@ -403,6 +403,19 @@ class BlobMetadata {
return null;
}
boolean shouldAttributeToUser(int userId) {
synchronized (mMetadataLock) {
for (int i = 0, size = mLeasees.size(); i < size; ++i) {
final Leasee leasee = mLeasees.valueAt(i);
// Don't attribute the blob to userId if there is a lease on it from another user.
if (userId != UserHandle.getUserId(leasee.uid)) {
return false;
}
}
}
return true;
}
boolean shouldAttributeToLeasee(@NonNull String packageName, int userId,
boolean callerHasStatsPermission) {
if (!isALeaseeInUser(packageName, INVALID_UID, userId)) {

View File

@@ -1333,9 +1333,10 @@ public class BlobStoreManagerService extends SystemService {
blobsDataSize.getAndAdd(session.getSize());
}, userHandle.getIdentifier());
// TODO(http://b/187460239): Update this to only include blobs available to userId.
forEachBlob(blobMetadata -> {
blobsDataSize.getAndAdd(blobMetadata.getSize());
if (blobMetadata.shouldAttributeToUser(userHandle.getIdentifier())) {
blobsDataSize.getAndAdd(blobMetadata.getSize());
}
});
stats.dataSize += blobsDataSize.get();