Fix incorrect storage calculation when SD card is inserted

The displayed internal storage is incorrect when an SD card
is inserted into the device.

Bug: 209962845
Test: Insert an SD card with some content. The System
storage calculation should remain unchanged.

Change-Id: I0a338bc306c0ade68747356714cd291e209a5069
This commit is contained in:
Xingbin Feng
2022-07-07 08:49:20 +02:00
committed by David Magno
parent e27d1790f8
commit 3cbff800a3

View File

@@ -85,13 +85,15 @@ public class StorageAsyncLoader
for (UserInfo info : infos) {
final StorageResult result = getAppsAndGamesSize(info.id);
final Bundle media = new Bundle();
media.putString(ContentResolver.QUERY_ARG_SQL_SELECTION, MediaColumns.VOLUME_NAME
+ "= '" + MediaStore.VOLUME_EXTERNAL_PRIMARY + "'");
result.imagesSize = getFilesSize(info.id, MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
null /* queryArgs */);
media /* queryArgs */);
result.videosSize = getFilesSize(info.id, MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
null /* queryArgs */);
media /* queryArgs */);
result.audioSize = getFilesSize(info.id, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
null /* queryArgs */);
media /* queryArgs */);
final Bundle documentsAndOtherQueryArgs = new Bundle();
documentsAndOtherQueryArgs.putString(ContentResolver.QUERY_ARG_SQL_SELECTION,
@@ -100,13 +102,14 @@ public class StorageAsyncLoader
+ " AND " + FileColumns.MEDIA_TYPE + "!=" + FileColumns.MEDIA_TYPE_AUDIO
+ " AND " + FileColumns.MIME_TYPE + " IS NOT NULL");
result.documentsAndOtherSize = getFilesSize(info.id,
MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL),
MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY),
documentsAndOtherQueryArgs);
final Bundle trashQueryArgs = new Bundle();
trashQueryArgs.putInt(MediaStore.QUERY_ARG_MATCH_TRASHED, MediaStore.MATCH_ONLY);
result.trashSize = getFilesSize(info.id,
MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL), trashQueryArgs);
MediaStore.Files.getContentUri(MediaStore.VOLUME_EXTERNAL_PRIMARY),
trashQueryArgs);
results.put(info.id, result);
}