Merge "Query storage size instead of calculate size of installed APP" into sc-dev

This commit is contained in:
TreeHugger Robot
2021-05-26 00:13:16 +00:00
committed by Android (Google) Code Review
13 changed files with 279 additions and 286 deletions

View File

@@ -70,7 +70,7 @@ import java.util.List;
*/
public class StorageCategoryFragment extends DashboardFragment
implements
LoaderManager.LoaderCallbacks<SparseArray<StorageAsyncLoader.AppsStorageResult>>,
LoaderManager.LoaderCallbacks<SparseArray<StorageAsyncLoader.StorageResult>>,
Preference.OnPreferenceClickListener {
private static final String TAG = "StorageCategoryFrag";
private static final String SUMMARY_PREF_KEY = "storage_summary";
@@ -83,7 +83,7 @@ public class StorageCategoryFragment extends DashboardFragment
private UserManager mUserManager;
private StorageEntry mSelectedStorageEntry;
private PrivateStorageInfo mStorageInfo;
private SparseArray<StorageAsyncLoader.AppsStorageResult> mAppsResult;
private SparseArray<StorageAsyncLoader.StorageResult> mAppsResult;
private CachedStorageValuesHelper mCachedStorageValuesHelper;
private StorageItemPreferenceController mPreferenceController;
@@ -232,7 +232,7 @@ public class StorageCategoryFragment extends DashboardFragment
* Updates the secondary user controller sizes.
*/
private void updateSecondaryUserControllers(List<AbstractPreferenceController> controllers,
SparseArray<StorageAsyncLoader.AppsStorageResult> stats) {
SparseArray<StorageAsyncLoader.StorageResult> stats) {
for (int i = 0, size = controllers.size(); i < size; i++) {
final AbstractPreferenceController controller = controllers.get(i);
if (controller instanceof StorageAsyncLoader.ResultHandler) {
@@ -244,7 +244,7 @@ public class StorageCategoryFragment extends DashboardFragment
}
@Override
public Loader<SparseArray<StorageAsyncLoader.AppsStorageResult>> onCreateLoader(int id,
public Loader<SparseArray<StorageAsyncLoader.StorageResult>> onCreateLoader(int id,
Bundle args) {
final Context context = getContext();
return new StorageAsyncLoader(context, mUserManager,
@@ -254,15 +254,15 @@ public class StorageCategoryFragment extends DashboardFragment
}
@Override
public void onLoadFinished(Loader<SparseArray<StorageAsyncLoader.AppsStorageResult>> loader,
SparseArray<StorageAsyncLoader.AppsStorageResult> data) {
public void onLoadFinished(Loader<SparseArray<StorageAsyncLoader.StorageResult>> loader,
SparseArray<StorageAsyncLoader.StorageResult> data) {
mAppsResult = data;
maybeCacheFreshValues();
onReceivedSizes();
}
@Override
public void onLoaderReset(Loader<SparseArray<StorageAsyncLoader.AppsStorageResult>> loader) {
public void onLoaderReset(Loader<SparseArray<StorageAsyncLoader.StorageResult>> loader) {
}
@Override
@@ -296,20 +296,20 @@ public class StorageCategoryFragment extends DashboardFragment
}
@VisibleForTesting
public SparseArray<StorageAsyncLoader.AppsStorageResult> getAppsStorageResult() {
public SparseArray<StorageAsyncLoader.StorageResult> getStorageResult() {
return mAppsResult;
}
@VisibleForTesting
public void setAppsStorageResult(SparseArray<StorageAsyncLoader.AppsStorageResult> info) {
public void setStorageResult(SparseArray<StorageAsyncLoader.StorageResult> info) {
mAppsResult = info;
}
@VisibleForTesting
void initializeCachedValues() {
final PrivateStorageInfo info = mCachedStorageValuesHelper.getCachedPrivateStorageInfo();
final SparseArray<StorageAsyncLoader.AppsStorageResult> loaderResult =
mCachedStorageValuesHelper.getCachedAppsStorageResult();
final SparseArray<StorageAsyncLoader.StorageResult> loaderResult =
mCachedStorageValuesHelper.getCachedStorageResult();
if (info == null || loaderResult == null) {
return;
}

View File

@@ -85,7 +85,7 @@ import java.util.List;
@SearchIndexable
public class StorageDashboardFragment extends DashboardFragment
implements
LoaderManager.LoaderCallbacks<SparseArray<StorageAsyncLoader.AppsStorageResult>>,
LoaderManager.LoaderCallbacks<SparseArray<StorageAsyncLoader.StorageResult>>,
Preference.OnPreferenceClickListener {
private static final String TAG = "StorageDashboardFrag";
private static final String SUMMARY_PREF_KEY = "storage_summary";
@@ -100,7 +100,7 @@ public class StorageDashboardFragment extends DashboardFragment
private final List<StorageEntry> mStorageEntries = new ArrayList<>();
private StorageEntry mSelectedStorageEntry;
private PrivateStorageInfo mStorageInfo;
private SparseArray<StorageAsyncLoader.AppsStorageResult> mAppsResult;
private SparseArray<StorageAsyncLoader.StorageResult> mAppsResult;
private CachedStorageValuesHelper mCachedStorageValuesHelper;
private StorageItemPreferenceController mPreferenceController;
@@ -414,7 +414,7 @@ public class StorageDashboardFragment extends DashboardFragment
* Updates the secondary user controller sizes.
*/
private void updateSecondaryUserControllers(List<AbstractPreferenceController> controllers,
SparseArray<StorageAsyncLoader.AppsStorageResult> stats) {
SparseArray<StorageAsyncLoader.StorageResult> stats) {
for (int i = 0, size = controllers.size(); i < size; i++) {
final AbstractPreferenceController controller = controllers.get(i);
if (controller instanceof StorageAsyncLoader.ResultHandler) {
@@ -455,7 +455,7 @@ public class StorageDashboardFragment extends DashboardFragment
};
@Override
public Loader<SparseArray<StorageAsyncLoader.AppsStorageResult>> onCreateLoader(int id,
public Loader<SparseArray<StorageAsyncLoader.StorageResult>> onCreateLoader(int id,
Bundle args) {
final Context context = getContext();
return new StorageAsyncLoader(context, mUserManager,
@@ -465,15 +465,15 @@ public class StorageDashboardFragment extends DashboardFragment
}
@Override
public void onLoadFinished(Loader<SparseArray<StorageAsyncLoader.AppsStorageResult>> loader,
SparseArray<StorageAsyncLoader.AppsStorageResult> data) {
public void onLoadFinished(Loader<SparseArray<StorageAsyncLoader.StorageResult>> loader,
SparseArray<StorageAsyncLoader.StorageResult> data) {
mAppsResult = data;
maybeCacheFreshValues();
onReceivedSizes();
}
@Override
public void onLoaderReset(Loader<SparseArray<StorageAsyncLoader.AppsStorageResult>> loader) {
public void onLoaderReset(Loader<SparseArray<StorageAsyncLoader.StorageResult>> loader) {
}
@Override
@@ -507,20 +507,20 @@ public class StorageDashboardFragment extends DashboardFragment
}
@VisibleForTesting
public SparseArray<StorageAsyncLoader.AppsStorageResult> getAppsStorageResult() {
public SparseArray<StorageAsyncLoader.StorageResult> getStorageResult() {
return mAppsResult;
}
@VisibleForTesting
public void setAppsStorageResult(SparseArray<StorageAsyncLoader.AppsStorageResult> info) {
public void setStorageResult(SparseArray<StorageAsyncLoader.StorageResult> info) {
mAppsResult = info;
}
@VisibleForTesting
void initializeCachedValues() {
final PrivateStorageInfo info = mCachedStorageValuesHelper.getCachedPrivateStorageInfo();
final SparseArray<StorageAsyncLoader.AppsStorageResult> loaderResult =
mCachedStorageValuesHelper.getCachedAppsStorageResult();
final SparseArray<StorageAsyncLoader.StorageResult> loaderResult =
mCachedStorageValuesHelper.getCachedStorageResult();
if (info == null || loaderResult == null) {
return;
}

View File

@@ -17,7 +17,8 @@
package com.android.settings.deviceinfo;
import android.content.Context;
import android.content.res.Resources;
import android.text.TextUtils;
import android.text.format.Formatter;
import android.util.AttributeSet;
import android.widget.ProgressBar;
@@ -25,7 +26,6 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import com.android.settings.R;
import com.android.settings.utils.FileSizeFormatter;
public class StorageItemPreference extends Preference {
public int userHandle;
@@ -49,12 +49,8 @@ public class StorageItemPreference extends Preference {
public void setStorageSize(long size, long total) {
mStorageSize = size;
setSummary(
FileSizeFormatter.formatFileSize(
getContext(),
size,
getGigabyteSuffix(getContext().getResources()),
FileSizeFormatter.GIGABYTE_IN_BYTES));
setSummary(getStorageSummary(size));
if (total == 0) {
mProgressPercent = 0;
} else {
@@ -82,7 +78,10 @@ public class StorageItemPreference extends Preference {
super.onBindViewHolder(view);
}
private static int getGigabyteSuffix(Resources res) {
return res.getIdentifier("gigabyteShort", "string", "android");
private String getStorageSummary(long bytes) {
final Formatter.BytesResult result = Formatter.formatBytes(getContext().getResources(),
bytes, Formatter.FLAG_SHORTER);
return TextUtils.expandTemplate(getContext().getText(R.string.storage_size_large),
result.value, result.units).toString();
}
}

View File

@@ -35,9 +35,11 @@ public class CachedStorageValuesHelper {
public static final String FREE_BYTES_KEY = "free_bytes";
public static final String TOTAL_BYTES_KEY = "total_bytes";
public static final String GAME_APPS_SIZE_KEY = "game_apps_size";
public static final String MUSIC_APPS_SIZE_KEY = "music_apps_size";
public static final String VIDEO_APPS_SIZE_KEY = "video_apps_size";
public static final String PHOTO_APPS_SIZE_KEY = "photo_apps_size";
public static final String AUDIO_SIZE_KEY = "audio_size";
public static final String VIDEOS_SIZE_KEY = "videos_size";
public static final String IMAGES_SIZE_KEY = "images_size";
public static final String DOCUMENTS_AND_OTHER_SIZE_KEY = "documents_and_other_size";
public static final String TRASH_SIZE_KEY = "trash_size";
public static final String OTHER_APPS_SIZE_KEY = "other_apps_size";
public static final String CACHE_APPS_SIZE_KEY = "cache_apps_size";
public static final String EXTERNAL_TOTAL_BYTES = "external_total_bytes";
@@ -78,21 +80,27 @@ public class CachedStorageValuesHelper {
return new PrivateStorageInfo(freeBytes, totalBytes);
}
public SparseArray<StorageAsyncLoader.AppsStorageResult> getCachedAppsStorageResult() {
/** Returns cached storage result or null if it's not available. */
public SparseArray<StorageAsyncLoader.StorageResult> getCachedStorageResult() {
if (!isDataValid()) {
return null;
}
final long gamesSize = mSharedPreferences.getLong(GAME_APPS_SIZE_KEY, -1);
final long musicAppsSize = mSharedPreferences.getLong(MUSIC_APPS_SIZE_KEY, -1);
final long videoAppsSize = mSharedPreferences.getLong(VIDEO_APPS_SIZE_KEY, -1);
final long photoAppSize = mSharedPreferences.getLong(PHOTO_APPS_SIZE_KEY, -1);
final long otherAppsSize = mSharedPreferences.getLong(OTHER_APPS_SIZE_KEY, -1);
final long audioSize = mSharedPreferences.getLong(AUDIO_SIZE_KEY, -1);
final long videosSize = mSharedPreferences.getLong(VIDEOS_SIZE_KEY, -1);
final long imagesSize = mSharedPreferences.getLong(IMAGES_SIZE_KEY, -1);
final long documentsAndOtherSize =
mSharedPreferences.getLong(DOCUMENTS_AND_OTHER_SIZE_KEY, -1);
final long trashSize = mSharedPreferences.getLong(TRASH_SIZE_KEY, -1);
final long allAppsExceptGamesSize = mSharedPreferences.getLong(OTHER_APPS_SIZE_KEY, -1);
final long cacheSize = mSharedPreferences.getLong(CACHE_APPS_SIZE_KEY, -1);
if (gamesSize < 0
|| musicAppsSize < 0
|| videoAppsSize < 0
|| photoAppSize < 0
|| otherAppsSize < 0
|| audioSize < 0
|| videosSize < 0
|| imagesSize < 0
|| documentsAndOtherSize < 0
|| trashSize < 0
|| allAppsExceptGamesSize < 0
|| cacheSize < 0) {
return null;
}
@@ -117,31 +125,34 @@ public class CachedStorageValuesHelper {
externalVideoBytes,
externalImageBytes,
externalAppBytes);
final StorageAsyncLoader.AppsStorageResult result =
new StorageAsyncLoader.AppsStorageResult();
final StorageAsyncLoader.StorageResult result = new StorageAsyncLoader.StorageResult();
result.gamesSize = gamesSize;
result.musicAppsSize = musicAppsSize;
result.videoAppsSize = videoAppsSize;
result.photosAppsSize = photoAppSize;
result.otherAppsSize = otherAppsSize;
result.audioSize = audioSize;
result.videosSize = videosSize;
result.imagesSize = imagesSize;
result.documentsAndOtherSize = documentsAndOtherSize;
result.trashSize = trashSize;
result.allAppsExceptGamesSize = allAppsExceptGamesSize;
result.cacheSize = cacheSize;
result.externalStats = externalStats;
final SparseArray<StorageAsyncLoader.AppsStorageResult> resultArray = new SparseArray<>();
final SparseArray<StorageAsyncLoader.StorageResult> resultArray = new SparseArray<>();
resultArray.append(mUserId, result);
return resultArray;
}
public void cacheResult(
PrivateStorageInfo storageInfo, StorageAsyncLoader.AppsStorageResult result) {
PrivateStorageInfo storageInfo, StorageAsyncLoader.StorageResult result) {
mSharedPreferences
.edit()
.putLong(FREE_BYTES_KEY, storageInfo.freeBytes)
.putLong(TOTAL_BYTES_KEY, storageInfo.totalBytes)
.putLong(GAME_APPS_SIZE_KEY, result.gamesSize)
.putLong(MUSIC_APPS_SIZE_KEY, result.musicAppsSize)
.putLong(VIDEO_APPS_SIZE_KEY, result.videoAppsSize)
.putLong(PHOTO_APPS_SIZE_KEY, result.photosAppsSize)
.putLong(OTHER_APPS_SIZE_KEY, result.otherAppsSize)
.putLong(AUDIO_SIZE_KEY, result.audioSize)
.putLong(VIDEOS_SIZE_KEY, result.videosSize)
.putLong(IMAGES_SIZE_KEY, result.imagesSize)
.putLong(DOCUMENTS_AND_OTHER_SIZE_KEY, result.documentsAndOtherSize)
.putLong(TRASH_SIZE_KEY, result.trashSize)
.putLong(OTHER_APPS_SIZE_KEY, result.allAppsExceptGamesSize)
.putLong(CACHE_APPS_SIZE_KEY, result.cacheSize)
.putLong(EXTERNAL_TOTAL_BYTES, result.externalStats.totalBytes)
.putLong(EXTERNAL_AUDIO_BYTES, result.externalStats.audioBytes)

View File

@@ -168,9 +168,9 @@ public class SecondaryUserController extends AbstractPreferenceController implem
mTotalSizeBytes = totalSizeBytes;
}
public void handleResult(SparseArray<StorageAsyncLoader.AppsStorageResult> stats) {
int userId = getUser().id;
StorageAsyncLoader.AppsStorageResult result = stats.get(userId);
@Override
public void handleResult(SparseArray<StorageAsyncLoader.StorageResult> stats) {
final StorageAsyncLoader.StorageResult result = stats.get(getUser().id);
if (result != null) {
setSize(result.externalStats.totalBytes);
}

View File

@@ -21,13 +21,20 @@ import static android.content.pm.ApplicationInfo.CATEGORY_GAME;
import static android.content.pm.ApplicationInfo.CATEGORY_IMAGE;
import static android.content.pm.ApplicationInfo.CATEGORY_VIDEO;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.UserInfo;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.MediaStore;
import android.provider.MediaStore.Files.FileColumns;
import android.provider.MediaStore.MediaColumns;
import android.util.ArraySet;
import android.util.Log;
import android.util.SparseArray;
@@ -37,7 +44,6 @@ import com.android.settingslib.utils.AsyncLoaderCompat;
import java.io.IOException;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
@@ -45,7 +51,7 @@ import java.util.List;
* users
*/
public class StorageAsyncLoader
extends AsyncLoaderCompat<SparseArray<StorageAsyncLoader.AppsStorageResult>> {
extends AsyncLoaderCompat<SparseArray<StorageAsyncLoader.StorageResult>> {
private UserManager mUserManager;
private static final String TAG = "StorageAsyncLoader";
@@ -64,38 +70,81 @@ public class StorageAsyncLoader
}
@Override
public SparseArray<AppsStorageResult> loadInBackground() {
return loadApps();
public SparseArray<StorageResult> loadInBackground() {
return getStorageResultsForUsers();
}
private SparseArray<AppsStorageResult> loadApps() {
private SparseArray<StorageResult> getStorageResultsForUsers() {
mSeenPackages = new ArraySet<>();
SparseArray<AppsStorageResult> result = new SparseArray<>();
List<UserInfo> infos = mUserManager.getUsers();
final SparseArray<StorageResult> results = new SparseArray<>();
final List<UserInfo> infos = mUserManager.getUsers();
// Sort the users by user id ascending.
Collections.sort(
infos,
new Comparator<UserInfo>() {
@Override
public int compare(UserInfo userInfo, UserInfo otherUser) {
return Integer.compare(userInfo.id, otherUser.id);
}
});
for (int i = 0, userCount = infos.size(); i < userCount; i++) {
final UserInfo info = infos.get(i);
result.put(info.id, getStorageResultForUser(info.id));
Collections.sort(infos,
(userInfo, otherUser) -> Integer.compare(userInfo.id, otherUser.id));
for (UserInfo info : infos) {
final StorageResult result = getAppsAndGamesSize(info.id);
result.imagesSize = getFilesSize(info.id, MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
null /* queryArgs */);
result.videosSize = getFilesSize(info.id, MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
null /* queryArgs */);
result.audioSize = getFilesSize(info.id, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
null /* queryArgs */);
final Bundle documentsAndOtherQueryArgs = new Bundle();
documentsAndOtherQueryArgs.putString(ContentResolver.QUERY_ARG_SQL_SELECTION,
FileColumns.MEDIA_TYPE + "!=" + FileColumns.MEDIA_TYPE_IMAGE
+ " AND " + FileColumns.MEDIA_TYPE + "!=" + FileColumns.MEDIA_TYPE_VIDEO
+ " 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),
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);
results.put(info.id, result);
}
return result;
return results;
}
private AppsStorageResult getStorageResultForUser(int userId) {
private long getFilesSize(int userId, Uri uri, Bundle queryArgs) {
final Context perUserContext;
try {
perUserContext = getContext().createPackageContextAsUser(
getContext().getApplicationContext().getPackageName(),
0 /* flags= */,
UserHandle.of(userId));
} catch (NameNotFoundException e) {
Log.e(TAG, "Not able to get Context for user ID " + userId);
return 0;
}
try (Cursor cursor = perUserContext.getContentResolver().query(
uri,
new String[] {"sum(" + MediaColumns.SIZE + ")"},
queryArgs,
null /* cancellationSignal */)) {
if (cursor == null) {
return 0;
}
return cursor.moveToFirst() ? cursor.getInt(0) : 0;
}
}
private StorageResult getAppsAndGamesSize(int userId) {
Log.d(TAG, "Loading apps");
List<ApplicationInfo> applicationInfos =
final List<ApplicationInfo> applicationInfos =
mPackageManager.getInstalledApplicationsAsUser(0, userId);
AppsStorageResult result = new AppsStorageResult();
UserHandle myUser = UserHandle.of(userId);
final StorageResult result = new StorageResult();
final UserHandle myUser = UserHandle.of(userId);
for (int i = 0, size = applicationInfos.size(); i < size; i++) {
ApplicationInfo app = applicationInfos.get(i);
final ApplicationInfo app = applicationInfos.get(i);
StorageStatsSource.AppStorageStats stats;
try {
@@ -131,28 +180,9 @@ public class StorageAsyncLoader
result.gamesSize += blamedSize;
break;
case CATEGORY_AUDIO:
// TODO(b/170918505): Should revamp audio size calculation with the data
// from media provider.
result.musicAppsSize += blamedSize;
result.musicAppsSize -= stats.getCodeBytes();
result.otherAppsSize += blamedSize;
break;
case CATEGORY_VIDEO:
// TODO(b/170918505): Should revamp video size calculation with the data
// from media provider.
result.videoAppsSize += blamedSize;
result.videoAppsSize -= stats.getCodeBytes();
result.otherAppsSize += blamedSize;
break;
case CATEGORY_IMAGE:
// TODO(b/170918505): Should revamp image size calculation with the data
// from media provider.
result.photosAppsSize += blamedSize;
result.photosAppsSize -= stats.getCodeBytes();
result.otherAppsSize += blamedSize;
result.allAppsExceptGamesSize += blamedSize;
break;
default:
// The deprecated game flag does not set the category.
@@ -160,7 +190,7 @@ public class StorageAsyncLoader
result.gamesSize += blamedSize;
break;
}
result.otherAppsSize += blamedSize;
result.allAppsExceptGamesSize += blamedSize;
break;
}
}
@@ -177,15 +207,22 @@ public class StorageAsyncLoader
}
@Override
protected void onDiscardResult(SparseArray<AppsStorageResult> result) {
protected void onDiscardResult(SparseArray<StorageResult> result) {
}
public static class AppsStorageResult {
/** Storage result for displaying file categories size in Storage Settings. */
public static class StorageResult {
// APP based sizes.
public long gamesSize;
public long musicAppsSize;
public long photosAppsSize;
public long videoAppsSize;
public long otherAppsSize;
public long allAppsExceptGamesSize;
// File based sizes.
public long audioSize;
public long imagesSize;
public long videosSize;
public long documentsAndOtherSize;
public long trashSize;
public long cacheSize;
public long duplicateCodeSize;
public StorageStatsSource.ExternalStorageStats externalStats;
@@ -196,6 +233,7 @@ public class StorageAsyncLoader
* {@link StorageAsyncLoader}.
*/
public interface ResultHandler {
void handleResult(SparseArray<AppsStorageResult> result);
/** Overrides this method to get storage result once it's available. */
void handleResult(SparseArray<StorageResult> result);
}
}

View File

@@ -357,18 +357,18 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
updatePrivateStorageCategoryPreferencesOrder();
}
public void onLoadFinished(SparseArray<StorageAsyncLoader.AppsStorageResult> result,
/** Fragments use it to set storage result and update UI of this controller. */
public void onLoadFinished(SparseArray<StorageAsyncLoader.StorageResult> result,
int userId) {
final StorageAsyncLoader.AppsStorageResult data = result.get(userId);
final StorageAsyncLoader.StorageResult data = result.get(userId);
mImagesPreference.setStorageSize(getImagesSize(data), mTotalSize);
mVideosPreference.setStorageSize(getVideosSize(data), mTotalSize);
mAudioPreference.setStorageSize(getAudioSize(data), mTotalSize);
mAppsPreference.setStorageSize(getAppsSize(data), mTotalSize);
mGamesPreference.setStorageSize(getGamesSize(data), mTotalSize);
mDocumentsAndOtherPreference.setStorageSize(getDocumentsAndOtherSize(data),
mTotalSize);
mTrashPreference.setStorageSize(getTrashSize(data), mTotalSize);
mImagesPreference.setStorageSize(data.imagesSize, mTotalSize);
mVideosPreference.setStorageSize(data.videosSize, mTotalSize);
mAudioPreference.setStorageSize(data.audioSize, mTotalSize);
mAppsPreference.setStorageSize(data.allAppsExceptGamesSize, mTotalSize);
mGamesPreference.setStorageSize(data.gamesSize, mTotalSize);
mDocumentsAndOtherPreference.setStorageSize(data.documentsAndOtherSize, mTotalSize);
mTrashPreference.setStorageSize(data.trashSize, mTotalSize);
if (mSystemPreference != null) {
// Everything else that hasn't already been attributed is tracked as
@@ -377,13 +377,15 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
// from media provider.
long attributedSize = 0;
for (int i = 0; i < result.size(); i++) {
final StorageAsyncLoader.AppsStorageResult otherData = result.valueAt(i);
final StorageAsyncLoader.StorageResult otherData = result.valueAt(i);
attributedSize +=
otherData.gamesSize
+ otherData.musicAppsSize
+ otherData.videoAppsSize
+ otherData.photosAppsSize
+ otherData.otherAppsSize;
+ otherData.audioSize
+ otherData.videosSize
+ otherData.imagesSize
+ otherData.documentsAndOtherSize
+ otherData.trashSize
+ otherData.allAppsExceptGamesSize;
attributedSize += otherData.externalStats.totalBytes
- otherData.externalStats.appBytes;
attributedSize -= otherData.duplicateCodeSize;
@@ -418,18 +420,6 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
mContext.startActivityAsUser(intent, new UserHandle(mUserId));
}
private long getImagesSize(StorageAsyncLoader.AppsStorageResult data) {
return data.photosAppsSize + data.externalStats.imageBytes + data.externalStats.videoBytes;
}
private long getVideosSize(StorageAsyncLoader.AppsStorageResult data) {
return data.videoAppsSize;
}
private long getAudioSize(StorageAsyncLoader.AppsStorageResult data) {
return data.musicAppsSize + data.externalStats.audioBytes;
}
private void launchAppsIntent() {
final Bundle args = getWorkAnnotatedBundle(3);
args.putString(ManageApplications.EXTRA_CLASSNAME,
@@ -446,10 +436,6 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
Utils.launchIntent(mFragment, intent);
}
private long getAppsSize(StorageAsyncLoader.AppsStorageResult data) {
return data.otherAppsSize;
}
private void launchGamesIntent() {
final Bundle args = getWorkAnnotatedBundle(1);
args.putString(ManageApplications.EXTRA_CLASSNAME,
@@ -464,10 +450,6 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
Utils.launchIntent(mFragment, intent);
}
private long getGamesSize(StorageAsyncLoader.AppsStorageResult data) {
return data.gamesSize;
}
private Bundle getWorkAnnotatedBundle(int additionalCapacity) {
final Bundle args = new Bundle(1 + additionalCapacity);
args.putInt(SettingsActivity.EXTRA_SHOW_FRAGMENT_TAB,
@@ -475,14 +457,6 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
return args;
}
private long getDocumentsAndOtherSize(StorageAsyncLoader.AppsStorageResult data) {
return data.externalStats.totalBytes
- data.externalStats.audioBytes
- data.externalStats.videoBytes
- data.externalStats.imageBytes
- data.externalStats.appBytes;
}
private void launchTrashIntent() {
final Intent intent = new Intent("android.settings.VIEW_TRASH");
@@ -493,11 +467,6 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
}
}
private long getTrashSize(StorageAsyncLoader.AppsStorageResult data) {
// TODO(170918505): Implement it.
return 0L;
}
private static long totalValues(StorageMeasurement.MeasurementDetails details, int userId,
String... keys) {
long total = 0;

View File

@@ -77,14 +77,14 @@ public class StorageDashboardFragmentTest {
CachedStorageValuesHelper helper = mock(CachedStorageValuesHelper.class);
PrivateStorageInfo info = new PrivateStorageInfo(0, 0);
when(helper.getCachedPrivateStorageInfo()).thenReturn(info);
SparseArray<StorageAsyncLoader.AppsStorageResult> result = new SparseArray<>();
when(helper.getCachedAppsStorageResult()).thenReturn(result);
SparseArray<StorageAsyncLoader.StorageResult> result = new SparseArray<>();
when(helper.getCachedStorageResult()).thenReturn(result);
mFragment.setCachedStorageValuesHelper(helper);
mFragment.initializeCachedValues();
assertThat(mFragment.getPrivateStorageInfo()).isEqualTo(info);
assertThat(mFragment.getAppsStorageResult()).isEqualTo(result);
assertThat(mFragment.getStorageResult()).isEqualTo(result);
}
@Test
@@ -97,20 +97,20 @@ public class StorageDashboardFragmentTest {
mFragment.initializeCachedValues();
assertThat(mFragment.getPrivateStorageInfo()).isNull();
assertThat(mFragment.getAppsStorageResult()).isNull();
assertThat(mFragment.getStorageResult()).isNull();
}
@Test
public void test_cacheProviderDoesntProvideValuesIfVolumeInfoMissing() {
CachedStorageValuesHelper helper = mock(CachedStorageValuesHelper.class);
SparseArray<StorageAsyncLoader.AppsStorageResult> result = new SparseArray<>();
when(helper.getCachedAppsStorageResult()).thenReturn(result);
SparseArray<StorageAsyncLoader.StorageResult> result = new SparseArray<>();
when(helper.getCachedStorageResult()).thenReturn(result);
mFragment.setCachedStorageValuesHelper(helper);
mFragment.initializeCachedValues();
assertThat(mFragment.getPrivateStorageInfo()).isNull();
assertThat(mFragment.getAppsStorageResult()).isNull();
assertThat(mFragment.getStorageResult()).isNull();
}
@Test
@@ -169,7 +169,7 @@ public class StorageDashboardFragmentTest {
mFragment = spy(mFragment);
when(mFragment.getView()).thenReturn(fakeView);
when(mFragment.getListView()).thenReturn(fakeRecyclerView);
mFragment.setAppsStorageResult(new SparseArray<>());
mFragment.setStorageResult(new SparseArray<>());
mFragment.maybeSetLoading(true);
@@ -185,7 +185,7 @@ public class StorageDashboardFragmentTest {
when(mFragment.getView()).thenReturn(fakeView);
when(mFragment.getListView()).thenReturn(fakeRecyclerView);
mFragment.setAppsStorageResult(new SparseArray<>());
mFragment.setStorageResult(new SparseArray<>());
PrivateStorageInfo storageInfo = new PrivateStorageInfo(0, 0);
mFragment.setPrivateStorageInfo(storageInfo);
@@ -203,4 +203,4 @@ public class StorageDashboardFragmentTest {
assertThat(indexRes).isNotNull();
assertThat(indexRes.get(0).xmlResId).isEqualTo(mFragment.getPreferenceScreenResId());
}
}
}

View File

@@ -54,7 +54,7 @@ public class StorageItemPreferenceTest {
@Test
public void testAfterLoad() {
mPreference.setStorageSize(MEGABYTE_IN_BYTES * 10, MEGABYTE_IN_BYTES * 100);
assertThat(mPreference.getSummary()).isEqualTo("0.01 GB");
assertThat(mPreference.getSummary()).isEqualTo("10 MB");
}
@Test

View File

@@ -16,7 +16,9 @@
package com.android.settings.deviceinfo.storage;
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.AUDIO_SIZE_KEY;
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.CACHE_APPS_SIZE_KEY;
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.DOCUMENTS_AND_OTHER_SIZE_KEY;
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.EXTERNAL_APP_BYTES;
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper
.EXTERNAL_AUDIO_BYTES;
@@ -28,15 +30,15 @@ import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper
.EXTERNAL_VIDEO_BYTES;
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.FREE_BYTES_KEY;
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.GAME_APPS_SIZE_KEY;
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.MUSIC_APPS_SIZE_KEY;
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.IMAGES_SIZE_KEY;
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.OTHER_APPS_SIZE_KEY;
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.PHOTO_APPS_SIZE_KEY;
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper
.SHARED_PREFERENCES_NAME;
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.TIMESTAMP_KEY;
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.TOTAL_BYTES_KEY;
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.TRASH_SIZE_KEY;
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.USER_ID_KEY;
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.VIDEO_APPS_SIZE_KEY;
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.VIDEOS_SIZE_KEY;
import static com.google.common.truth.Truth.assertThat;
@@ -81,9 +83,9 @@ public class CachedStorageValuesHelperTest {
mSharedPreferences
.edit()
.putLong(GAME_APPS_SIZE_KEY, 0)
.putLong(MUSIC_APPS_SIZE_KEY, 10)
.putLong(VIDEO_APPS_SIZE_KEY, 100)
.putLong(PHOTO_APPS_SIZE_KEY, 1000)
.putLong(AUDIO_SIZE_KEY, 10)
.putLong(VIDEOS_SIZE_KEY, 100)
.putLong(IMAGES_SIZE_KEY, 1000)
.putLong(OTHER_APPS_SIZE_KEY, 10000)
.putLong(CACHE_APPS_SIZE_KEY, 100000)
.putLong(EXTERNAL_TOTAL_BYTES, 2)
@@ -104,14 +106,16 @@ public class CachedStorageValuesHelperTest {
}
@Test
public void getCachedAppsStorageResult_cachedValuesAreLoaded() {
public void getCachedStorageResult_cachedValuesAreLoaded() {
when(mMockClock.getCurrentTime()).thenReturn(10001L);
mSharedPreferences
.edit()
.putLong(GAME_APPS_SIZE_KEY, 1)
.putLong(MUSIC_APPS_SIZE_KEY, 10)
.putLong(VIDEO_APPS_SIZE_KEY, 100)
.putLong(PHOTO_APPS_SIZE_KEY, 1000)
.putLong(AUDIO_SIZE_KEY, 10)
.putLong(VIDEOS_SIZE_KEY, 100)
.putLong(IMAGES_SIZE_KEY, 1000)
.putLong(DOCUMENTS_AND_OTHER_SIZE_KEY, 1001)
.putLong(TRASH_SIZE_KEY, 1002)
.putLong(OTHER_APPS_SIZE_KEY, 10000)
.putLong(CACHE_APPS_SIZE_KEY, 100000)
.putLong(EXTERNAL_TOTAL_BYTES, 222222)
@@ -125,15 +129,17 @@ public class CachedStorageValuesHelperTest {
.putLong(TIMESTAMP_KEY, 10000L)
.apply();
final SparseArray<StorageAsyncLoader.AppsStorageResult> result =
mCachedValuesHelper.getCachedAppsStorageResult();
final SparseArray<StorageAsyncLoader.StorageResult> result =
mCachedValuesHelper.getCachedStorageResult();
StorageAsyncLoader.AppsStorageResult primaryResult = result.get(0);
StorageAsyncLoader.StorageResult primaryResult = result.get(0);
assertThat(primaryResult.gamesSize).isEqualTo(1L);
assertThat(primaryResult.musicAppsSize).isEqualTo(10L);
assertThat(primaryResult.videoAppsSize).isEqualTo(100L);
assertThat(primaryResult.photosAppsSize).isEqualTo(1000L);
assertThat(primaryResult.otherAppsSize).isEqualTo(10000L);
assertThat(primaryResult.audioSize).isEqualTo(10L);
assertThat(primaryResult.videosSize).isEqualTo(100L);
assertThat(primaryResult.imagesSize).isEqualTo(1000L);
assertThat(primaryResult.documentsAndOtherSize).isEqualTo(1001L);
assertThat(primaryResult.trashSize).isEqualTo(1002L);
assertThat(primaryResult.allAppsExceptGamesSize).isEqualTo(10000L);
assertThat(primaryResult.cacheSize).isEqualTo(100000L);
assertThat(primaryResult.externalStats.totalBytes).isEqualTo(222222L);
assertThat(primaryResult.externalStats.audioBytes).isEqualTo(22L);
@@ -148,9 +154,9 @@ public class CachedStorageValuesHelperTest {
mSharedPreferences
.edit()
.putLong(GAME_APPS_SIZE_KEY, 0)
.putLong(MUSIC_APPS_SIZE_KEY, 10)
.putLong(VIDEO_APPS_SIZE_KEY, 100)
.putLong(PHOTO_APPS_SIZE_KEY, 1000)
.putLong(AUDIO_SIZE_KEY, 10)
.putLong(VIDEOS_SIZE_KEY, 100)
.putLong(IMAGES_SIZE_KEY, 1000)
.putLong(OTHER_APPS_SIZE_KEY, 10000)
.putLong(CACHE_APPS_SIZE_KEY, 100000)
.putLong(EXTERNAL_TOTAL_BYTES, 2)
@@ -169,14 +175,14 @@ public class CachedStorageValuesHelperTest {
}
@Test
public void getCachedAppsStorageResult_nullIfDataIsStale() {
public void getCachedStorageResult_nullIfDataIsStale() {
when(mMockClock.getCurrentTime()).thenReturn(10000000L);
mSharedPreferences
.edit()
.putLong(GAME_APPS_SIZE_KEY, 0)
.putLong(MUSIC_APPS_SIZE_KEY, 10)
.putLong(VIDEO_APPS_SIZE_KEY, 100)
.putLong(PHOTO_APPS_SIZE_KEY, 1000)
.putLong(AUDIO_SIZE_KEY, 10)
.putLong(VIDEOS_SIZE_KEY, 100)
.putLong(IMAGES_SIZE_KEY, 1000)
.putLong(OTHER_APPS_SIZE_KEY, 10000)
.putLong(CACHE_APPS_SIZE_KEY, 100000)
.putLong(EXTERNAL_TOTAL_BYTES, 2)
@@ -190,8 +196,8 @@ public class CachedStorageValuesHelperTest {
.putLong(TIMESTAMP_KEY, 10000L)
.apply();
final SparseArray<StorageAsyncLoader.AppsStorageResult> result =
mCachedValuesHelper.getCachedAppsStorageResult();
final SparseArray<StorageAsyncLoader.StorageResult> result =
mCachedValuesHelper.getCachedStorageResult();
assertThat(result).isNull();
}
@@ -201,9 +207,9 @@ public class CachedStorageValuesHelperTest {
mSharedPreferences
.edit()
.putLong(GAME_APPS_SIZE_KEY, 0)
.putLong(MUSIC_APPS_SIZE_KEY, 10)
.putLong(VIDEO_APPS_SIZE_KEY, 100)
.putLong(PHOTO_APPS_SIZE_KEY, 1000)
.putLong(AUDIO_SIZE_KEY, 10)
.putLong(VIDEOS_SIZE_KEY, 100)
.putLong(IMAGES_SIZE_KEY, 1000)
.putLong(OTHER_APPS_SIZE_KEY, 10000)
.putLong(CACHE_APPS_SIZE_KEY, 100000)
.putLong(EXTERNAL_TOTAL_BYTES, 2)
@@ -222,14 +228,14 @@ public class CachedStorageValuesHelperTest {
}
@Test
public void getCachedAppsStorageResult_nullIfWrongUser() {
public void getCachedStorageResult_nullIfWrongUser() {
when(mMockClock.getCurrentTime()).thenReturn(10001L);
mSharedPreferences
.edit()
.putLong(GAME_APPS_SIZE_KEY, 0)
.putLong(MUSIC_APPS_SIZE_KEY, 10)
.putLong(VIDEO_APPS_SIZE_KEY, 100)
.putLong(PHOTO_APPS_SIZE_KEY, 1000)
.putLong(AUDIO_SIZE_KEY, 10)
.putLong(VIDEOS_SIZE_KEY, 100)
.putLong(IMAGES_SIZE_KEY, 1000)
.putLong(OTHER_APPS_SIZE_KEY, 10000)
.putLong(CACHE_APPS_SIZE_KEY, 100000)
.putLong(EXTERNAL_TOTAL_BYTES, 2)
@@ -243,8 +249,8 @@ public class CachedStorageValuesHelperTest {
.putLong(TIMESTAMP_KEY, 10000L)
.apply();
final SparseArray<StorageAsyncLoader.AppsStorageResult> result =
mCachedValuesHelper.getCachedAppsStorageResult();
final SparseArray<StorageAsyncLoader.StorageResult> result =
mCachedValuesHelper.getCachedStorageResult();
assertThat(result).isNull();
}
@@ -255,9 +261,9 @@ public class CachedStorageValuesHelperTest {
}
@Test
public void getCachedAppsStorageResult_nullIfEmpty() {
final SparseArray<StorageAsyncLoader.AppsStorageResult> result =
mCachedValuesHelper.getCachedAppsStorageResult();
public void getCachedStorageResult_nullIfEmpty() {
final SparseArray<StorageAsyncLoader.StorageResult> result =
mCachedValuesHelper.getCachedStorageResult();
assertThat(result).isNull();
}
@@ -266,13 +272,13 @@ public class CachedStorageValuesHelperTest {
when(mMockClock.getCurrentTime()).thenReturn(10000L);
final StorageStatsSource.ExternalStorageStats externalStats =
new StorageStatsSource.ExternalStorageStats(22222L, 2L, 20L, 200L, 2000L);
final StorageAsyncLoader.AppsStorageResult result =
new StorageAsyncLoader.AppsStorageResult();
final StorageAsyncLoader.StorageResult result =
new StorageAsyncLoader.StorageResult();
result.gamesSize = 1L;
result.musicAppsSize = 10L;
result.videoAppsSize = 100L;
result.photosAppsSize = 1000L;
result.otherAppsSize = 10000L;
result.audioSize = 10L;
result.videosSize = 100L;
result.imagesSize = 1000L;
result.allAppsExceptGamesSize = 10000L;
result.cacheSize = 100000L;
result.externalStats = externalStats;
final PrivateStorageInfo info = new PrivateStorageInfo(1000L, 6000L);
@@ -280,9 +286,9 @@ public class CachedStorageValuesHelperTest {
mCachedValuesHelper.cacheResult(info, result);
assertThat(mSharedPreferences.getLong(GAME_APPS_SIZE_KEY, -1)).isEqualTo(1L);
assertThat(mSharedPreferences.getLong(MUSIC_APPS_SIZE_KEY, -1)).isEqualTo(10L);
assertThat(mSharedPreferences.getLong(VIDEO_APPS_SIZE_KEY, -1)).isEqualTo(100L);
assertThat(mSharedPreferences.getLong(PHOTO_APPS_SIZE_KEY, -1)).isEqualTo(1000L);
assertThat(mSharedPreferences.getLong(AUDIO_SIZE_KEY, -1)).isEqualTo(10L);
assertThat(mSharedPreferences.getLong(VIDEOS_SIZE_KEY, -1)).isEqualTo(100L);
assertThat(mSharedPreferences.getLong(IMAGES_SIZE_KEY, -1)).isEqualTo(1000L);
assertThat(mSharedPreferences.getLong(OTHER_APPS_SIZE_KEY, -1)).isEqualTo(10000L);
assertThat(mSharedPreferences.getLong(CACHE_APPS_SIZE_KEY, -1)).isEqualTo(100000L);
assertThat(mSharedPreferences.getLong(EXTERNAL_TOTAL_BYTES, -1)).isEqualTo(22222L);

View File

@@ -103,7 +103,7 @@ public class SecondaryUserControllerTest {
verify(mGroup).addPreference(argumentCaptor.capture());
final Preference preference = argumentCaptor.getValue();
assertThat(preference.getSummary()).isEqualTo("0.01 GB");
assertThat(preference.getSummary()).isEqualTo("10 MB");
}
@Test
@@ -201,9 +201,9 @@ public class SecondaryUserControllerTest {
mPrimaryUser.name = TEST_NAME;
mPrimaryUser.id = 10;
mController.displayPreference(mScreen);
final StorageAsyncLoader.AppsStorageResult userResult =
new StorageAsyncLoader.AppsStorageResult();
final SparseArray<StorageAsyncLoader.AppsStorageResult> result = new SparseArray<>();
final StorageAsyncLoader.StorageResult userResult =
new StorageAsyncLoader.StorageResult();
final SparseArray<StorageAsyncLoader.StorageResult> result = new SparseArray<>();
userResult.externalStats =
new StorageStatsSource.ExternalStorageStats(
MEGABYTE_IN_BYTES * 30,
@@ -217,7 +217,7 @@ public class SecondaryUserControllerTest {
verify(mGroup).addPreference(argumentCaptor.capture());
final Preference preference = argumentCaptor.getValue();
assertThat(preference.getSummary()).isEqualTo("0.03 GB");
assertThat(preference.getSummary()).isEqualTo("30 MB");
}
@Test

View File

@@ -16,6 +16,8 @@
package com.android.settings.deviceinfo.storage;
import static com.android.settings.applications.manageapplications.ManageApplications.EXTRA_WORK_ID;
import static com.android.settings.utils.FileSizeFormatter.GIGABYTE_IN_BYTES;
import static com.android.settings.utils.FileSizeFormatter.KILOBYTE_IN_BYTES;
import static com.android.settings.utils.FileSizeFormatter.MEGABYTE_IN_BYTES;
import static com.google.common.truth.Truth.assertThat;
@@ -336,12 +338,14 @@ public class StorageItemPreferenceControllerTest {
mController.displayPreference(mPreferenceScreen);
mController.setUsedSize(MEGABYTE_IN_BYTES * 970); // There should 870MB attributed.
final StorageAsyncLoader.AppsStorageResult result =
new StorageAsyncLoader.AppsStorageResult();
final StorageAsyncLoader.StorageResult result = new StorageAsyncLoader.StorageResult();
result.gamesSize = MEGABYTE_IN_BYTES * 80;
result.videoAppsSize = MEGABYTE_IN_BYTES * 160;
result.musicAppsSize = MEGABYTE_IN_BYTES * 40;
result.otherAppsSize = MEGABYTE_IN_BYTES * 90;
result.imagesSize = MEGABYTE_IN_BYTES * 350;
result.videosSize = GIGABYTE_IN_BYTES * 30;
result.audioSize = MEGABYTE_IN_BYTES * 40;
result.documentsAndOtherSize = MEGABYTE_IN_BYTES * 50;
result.trashSize = KILOBYTE_IN_BYTES * 100;
result.allAppsExceptGamesSize = MEGABYTE_IN_BYTES * 90;
result.externalStats =
new StorageStatsSource.ExternalStorageStats(
MEGABYTE_IN_BYTES * 500, // total
@@ -349,17 +353,18 @@ public class StorageItemPreferenceControllerTest {
MEGABYTE_IN_BYTES * 150, // video
MEGABYTE_IN_BYTES * 200, 0); // image
final SparseArray<StorageAsyncLoader.AppsStorageResult> results = new SparseArray<>();
final SparseArray<StorageAsyncLoader.StorageResult> results = new SparseArray<>();
results.put(0, result);
mController.onLoadFinished(results, 0);
assertThat(mController.mImagesPreference.getSummary().toString()).isEqualTo("0.35 GB");
assertThat(mController.mVideosPreference.getSummary().toString()).isEqualTo("0.16 GB");
assertThat(mController.mAudioPreference.getSummary().toString()).isEqualTo("0.14 GB");
assertThat(mController.mAppsPreference.getSummary().toString()).isEqualTo("0.09 GB");
assertThat(mController.mGamesPreference.getSummary().toString()).isEqualTo("0.08 GB");
assertThat(mController.mImagesPreference.getSummary().toString()).isEqualTo("350 MB");
assertThat(mController.mVideosPreference.getSummary().toString()).isEqualTo("30 GB");
assertThat(mController.mAudioPreference.getSummary().toString()).isEqualTo("40 MB");
assertThat(mController.mAppsPreference.getSummary().toString()).isEqualTo("90 MB");
assertThat(mController.mGamesPreference.getSummary().toString()).isEqualTo("80 MB");
assertThat(mController.mDocumentsAndOtherPreference.getSummary().toString())
.isEqualTo("0.05 GB");
.isEqualTo("50 MB");
assertThat(mController.mTrashPreference.getSummary().toString()).isEqualTo("100 kB");
}
@Test

View File

@@ -101,22 +101,22 @@ public class StorageAsyncLoaderTest {
addPackage(PACKAGE_NAME_1, 0, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED);
addPackage(PACKAGE_NAME_2, 0, 100, 1000, ApplicationInfo.CATEGORY_UNDEFINED);
SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
SparseArray<StorageAsyncLoader.StorageResult> result = mLoader.loadInBackground();
assertThat(result.size()).isEqualTo(1);
assertThat(result.get(PRIMARY_USER_ID).gamesSize).isEqualTo(0L);
assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(1111L);
assertThat(result.get(PRIMARY_USER_ID).allAppsExceptGamesSize).isEqualTo(1111L);
}
@Test
public void testGamesAreFiltered() throws Exception {
addPackage(PACKAGE_NAME_1, 0, 1, 10, ApplicationInfo.CATEGORY_GAME);
SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
SparseArray<StorageAsyncLoader.StorageResult> result = mLoader.loadInBackground();
assertThat(result.size()).isEqualTo(1);
assertThat(result.get(PRIMARY_USER_ID).gamesSize).isEqualTo(11L);
assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(0);
assertThat(result.get(PRIMARY_USER_ID).allAppsExceptGamesSize).isEqualTo(0);
}
@Test
@@ -125,21 +125,21 @@ public class StorageAsyncLoaderTest {
addPackage(PACKAGE_NAME_1, 0, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED);
info.flags = ApplicationInfo.FLAG_IS_GAME;
SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
SparseArray<StorageAsyncLoader.StorageResult> result = mLoader.loadInBackground();
assertThat(result.size()).isEqualTo(1);
assertThat(result.get(PRIMARY_USER_ID).gamesSize).isEqualTo(11L);
assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(0);
assertThat(result.get(PRIMARY_USER_ID).allAppsExceptGamesSize).isEqualTo(0);
}
@Test
public void testCacheIsNotIgnored() throws Exception {
addPackage(PACKAGE_NAME_1, 100, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED);
SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
SparseArray<StorageAsyncLoader.StorageResult> result = mLoader.loadInBackground();
assertThat(result.size()).isEqualTo(1);
assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(111L);
assertThat(result.get(PRIMARY_USER_ID).allAppsExceptGamesSize).isEqualTo(111L);
}
@Test
@@ -152,7 +152,7 @@ public class StorageAsyncLoaderTest {
when(mSource.getExternalStorageStats(anyString(), eq(new UserHandle(SECONDARY_USER_ID))))
.thenReturn(new StorageStatsSource.ExternalStorageStats(10, 3, 3, 4, 0));
SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
SparseArray<StorageAsyncLoader.StorageResult> result = mLoader.loadInBackground();
assertThat(result.size()).isEqualTo(2);
assertThat(result.get(PRIMARY_USER_ID).externalStats.totalBytes).isEqualTo(9L);
@@ -165,21 +165,10 @@ public class StorageAsyncLoaderTest {
addPackage(PACKAGE_NAME_1, 100, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED);
systemApp.flags = ApplicationInfo.FLAG_SYSTEM & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
SparseArray<StorageAsyncLoader.StorageResult> result = mLoader.loadInBackground();
assertThat(result.size()).isEqualTo(1);
assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(111L);
}
@Test
public void testVideoAppsAreFiltered() throws Exception {
addPackage(PACKAGE_NAME_1, 0, 1, 10, ApplicationInfo.CATEGORY_VIDEO);
SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
assertThat(result.size()).isEqualTo(1);
// Code size is not included for file based video category.
assertThat(result.get(PRIMARY_USER_ID).videoAppsSize).isEqualTo(10L);
assertThat(result.get(PRIMARY_USER_ID).allAppsExceptGamesSize).isEqualTo(111L);
}
@Test
@@ -191,44 +180,20 @@ public class StorageAsyncLoaderTest {
when(mSource.getStatsForPackage(anyString(), anyString(), any(UserHandle.class)))
.thenThrow(new NameNotFoundException());
SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
SparseArray<StorageAsyncLoader.StorageResult> result = mLoader.loadInBackground();
// Should not crash.
}
@Test
public void testPackageIsNotDoubleCounted() throws Exception {
UserInfo info = new UserInfo();
info.id = SECONDARY_USER_ID;
mUsers.add(info);
when(mSource.getExternalStorageStats(anyString(), eq(UserHandle.SYSTEM)))
.thenReturn(new StorageStatsSource.ExternalStorageStats(9, 2, 3, 4, 0));
when(mSource.getExternalStorageStats(anyString(), eq(new UserHandle(SECONDARY_USER_ID))))
.thenReturn(new StorageStatsSource.ExternalStorageStats(10, 3, 3, 4, 0));
addPackage(PACKAGE_NAME_1, 0, 1, 10, ApplicationInfo.CATEGORY_VIDEO);
ArrayList<ApplicationInfo> secondaryUserApps = new ArrayList<>();
ApplicationInfo appInfo = new ApplicationInfo();
appInfo.packageName = PACKAGE_NAME_1;
appInfo.category = ApplicationInfo.CATEGORY_VIDEO;
secondaryUserApps.add(appInfo);
SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
assertThat(result.size()).isEqualTo(2);
// Code size is not included for file based video category.
assertThat(result.get(PRIMARY_USER_ID).videoAppsSize).isEqualTo(10L);
// No code size for the second user.
assertThat(result.get(SECONDARY_USER_ID).videoAppsSize).isEqualTo(10L);
}
@Test
public void testCacheOveragesAreCountedAsFree() throws Exception {
addPackage(PACKAGE_NAME_1, DEFAULT_QUOTA + 100, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED);
SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
SparseArray<StorageAsyncLoader.StorageResult> result = mLoader.loadInBackground();
assertThat(result.size()).isEqualTo(1);
assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(DEFAULT_QUOTA + 11);
assertThat(result.get(PRIMARY_USER_ID).allAppsExceptGamesSize)
.isEqualTo(DEFAULT_QUOTA + 11);
}
@Test
@@ -237,10 +202,10 @@ public class StorageAsyncLoaderTest {
addPackage(PACKAGE_NAME_2, 0, 1, 10, ApplicationInfo.CATEGORY_VIDEO);
addPackage(PACKAGE_NAME_3, 0, 1, 10, ApplicationInfo.CATEGORY_AUDIO);
SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
SparseArray<StorageAsyncLoader.StorageResult> result = mLoader.loadInBackground();
assertThat(result.size()).isEqualTo(1);
assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(33L);
assertThat(result.get(PRIMARY_USER_ID).allAppsExceptGamesSize).isEqualTo(33L);
}
private ApplicationInfo addPackage(String packageName, long cacheSize, long codeSize,