Merge "Query storage size instead of calculate size of installed APP" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
0eaf329a43
@@ -70,7 +70,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class StorageCategoryFragment extends DashboardFragment
|
public class StorageCategoryFragment extends DashboardFragment
|
||||||
implements
|
implements
|
||||||
LoaderManager.LoaderCallbacks<SparseArray<StorageAsyncLoader.AppsStorageResult>>,
|
LoaderManager.LoaderCallbacks<SparseArray<StorageAsyncLoader.StorageResult>>,
|
||||||
Preference.OnPreferenceClickListener {
|
Preference.OnPreferenceClickListener {
|
||||||
private static final String TAG = "StorageCategoryFrag";
|
private static final String TAG = "StorageCategoryFrag";
|
||||||
private static final String SUMMARY_PREF_KEY = "storage_summary";
|
private static final String SUMMARY_PREF_KEY = "storage_summary";
|
||||||
@@ -83,7 +83,7 @@ public class StorageCategoryFragment extends DashboardFragment
|
|||||||
private UserManager mUserManager;
|
private UserManager mUserManager;
|
||||||
private StorageEntry mSelectedStorageEntry;
|
private StorageEntry mSelectedStorageEntry;
|
||||||
private PrivateStorageInfo mStorageInfo;
|
private PrivateStorageInfo mStorageInfo;
|
||||||
private SparseArray<StorageAsyncLoader.AppsStorageResult> mAppsResult;
|
private SparseArray<StorageAsyncLoader.StorageResult> mAppsResult;
|
||||||
private CachedStorageValuesHelper mCachedStorageValuesHelper;
|
private CachedStorageValuesHelper mCachedStorageValuesHelper;
|
||||||
|
|
||||||
private StorageItemPreferenceController mPreferenceController;
|
private StorageItemPreferenceController mPreferenceController;
|
||||||
@@ -232,7 +232,7 @@ public class StorageCategoryFragment extends DashboardFragment
|
|||||||
* Updates the secondary user controller sizes.
|
* Updates the secondary user controller sizes.
|
||||||
*/
|
*/
|
||||||
private void updateSecondaryUserControllers(List<AbstractPreferenceController> controllers,
|
private void updateSecondaryUserControllers(List<AbstractPreferenceController> controllers,
|
||||||
SparseArray<StorageAsyncLoader.AppsStorageResult> stats) {
|
SparseArray<StorageAsyncLoader.StorageResult> stats) {
|
||||||
for (int i = 0, size = controllers.size(); i < size; i++) {
|
for (int i = 0, size = controllers.size(); i < size; i++) {
|
||||||
final AbstractPreferenceController controller = controllers.get(i);
|
final AbstractPreferenceController controller = controllers.get(i);
|
||||||
if (controller instanceof StorageAsyncLoader.ResultHandler) {
|
if (controller instanceof StorageAsyncLoader.ResultHandler) {
|
||||||
@@ -244,7 +244,7 @@ public class StorageCategoryFragment extends DashboardFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Loader<SparseArray<StorageAsyncLoader.AppsStorageResult>> onCreateLoader(int id,
|
public Loader<SparseArray<StorageAsyncLoader.StorageResult>> onCreateLoader(int id,
|
||||||
Bundle args) {
|
Bundle args) {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
return new StorageAsyncLoader(context, mUserManager,
|
return new StorageAsyncLoader(context, mUserManager,
|
||||||
@@ -254,15 +254,15 @@ public class StorageCategoryFragment extends DashboardFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadFinished(Loader<SparseArray<StorageAsyncLoader.AppsStorageResult>> loader,
|
public void onLoadFinished(Loader<SparseArray<StorageAsyncLoader.StorageResult>> loader,
|
||||||
SparseArray<StorageAsyncLoader.AppsStorageResult> data) {
|
SparseArray<StorageAsyncLoader.StorageResult> data) {
|
||||||
mAppsResult = data;
|
mAppsResult = data;
|
||||||
maybeCacheFreshValues();
|
maybeCacheFreshValues();
|
||||||
onReceivedSizes();
|
onReceivedSizes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoaderReset(Loader<SparseArray<StorageAsyncLoader.AppsStorageResult>> loader) {
|
public void onLoaderReset(Loader<SparseArray<StorageAsyncLoader.StorageResult>> loader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -296,20 +296,20 @@ public class StorageCategoryFragment extends DashboardFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public SparseArray<StorageAsyncLoader.AppsStorageResult> getAppsStorageResult() {
|
public SparseArray<StorageAsyncLoader.StorageResult> getStorageResult() {
|
||||||
return mAppsResult;
|
return mAppsResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void setAppsStorageResult(SparseArray<StorageAsyncLoader.AppsStorageResult> info) {
|
public void setStorageResult(SparseArray<StorageAsyncLoader.StorageResult> info) {
|
||||||
mAppsResult = info;
|
mAppsResult = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void initializeCachedValues() {
|
void initializeCachedValues() {
|
||||||
final PrivateStorageInfo info = mCachedStorageValuesHelper.getCachedPrivateStorageInfo();
|
final PrivateStorageInfo info = mCachedStorageValuesHelper.getCachedPrivateStorageInfo();
|
||||||
final SparseArray<StorageAsyncLoader.AppsStorageResult> loaderResult =
|
final SparseArray<StorageAsyncLoader.StorageResult> loaderResult =
|
||||||
mCachedStorageValuesHelper.getCachedAppsStorageResult();
|
mCachedStorageValuesHelper.getCachedStorageResult();
|
||||||
if (info == null || loaderResult == null) {
|
if (info == null || loaderResult == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -85,7 +85,7 @@ import java.util.List;
|
|||||||
@SearchIndexable
|
@SearchIndexable
|
||||||
public class StorageDashboardFragment extends DashboardFragment
|
public class StorageDashboardFragment extends DashboardFragment
|
||||||
implements
|
implements
|
||||||
LoaderManager.LoaderCallbacks<SparseArray<StorageAsyncLoader.AppsStorageResult>>,
|
LoaderManager.LoaderCallbacks<SparseArray<StorageAsyncLoader.StorageResult>>,
|
||||||
Preference.OnPreferenceClickListener {
|
Preference.OnPreferenceClickListener {
|
||||||
private static final String TAG = "StorageDashboardFrag";
|
private static final String TAG = "StorageDashboardFrag";
|
||||||
private static final String SUMMARY_PREF_KEY = "storage_summary";
|
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 final List<StorageEntry> mStorageEntries = new ArrayList<>();
|
||||||
private StorageEntry mSelectedStorageEntry;
|
private StorageEntry mSelectedStorageEntry;
|
||||||
private PrivateStorageInfo mStorageInfo;
|
private PrivateStorageInfo mStorageInfo;
|
||||||
private SparseArray<StorageAsyncLoader.AppsStorageResult> mAppsResult;
|
private SparseArray<StorageAsyncLoader.StorageResult> mAppsResult;
|
||||||
private CachedStorageValuesHelper mCachedStorageValuesHelper;
|
private CachedStorageValuesHelper mCachedStorageValuesHelper;
|
||||||
|
|
||||||
private StorageItemPreferenceController mPreferenceController;
|
private StorageItemPreferenceController mPreferenceController;
|
||||||
@@ -414,7 +414,7 @@ public class StorageDashboardFragment extends DashboardFragment
|
|||||||
* Updates the secondary user controller sizes.
|
* Updates the secondary user controller sizes.
|
||||||
*/
|
*/
|
||||||
private void updateSecondaryUserControllers(List<AbstractPreferenceController> controllers,
|
private void updateSecondaryUserControllers(List<AbstractPreferenceController> controllers,
|
||||||
SparseArray<StorageAsyncLoader.AppsStorageResult> stats) {
|
SparseArray<StorageAsyncLoader.StorageResult> stats) {
|
||||||
for (int i = 0, size = controllers.size(); i < size; i++) {
|
for (int i = 0, size = controllers.size(); i < size; i++) {
|
||||||
final AbstractPreferenceController controller = controllers.get(i);
|
final AbstractPreferenceController controller = controllers.get(i);
|
||||||
if (controller instanceof StorageAsyncLoader.ResultHandler) {
|
if (controller instanceof StorageAsyncLoader.ResultHandler) {
|
||||||
@@ -455,7 +455,7 @@ public class StorageDashboardFragment extends DashboardFragment
|
|||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Loader<SparseArray<StorageAsyncLoader.AppsStorageResult>> onCreateLoader(int id,
|
public Loader<SparseArray<StorageAsyncLoader.StorageResult>> onCreateLoader(int id,
|
||||||
Bundle args) {
|
Bundle args) {
|
||||||
final Context context = getContext();
|
final Context context = getContext();
|
||||||
return new StorageAsyncLoader(context, mUserManager,
|
return new StorageAsyncLoader(context, mUserManager,
|
||||||
@@ -465,15 +465,15 @@ public class StorageDashboardFragment extends DashboardFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadFinished(Loader<SparseArray<StorageAsyncLoader.AppsStorageResult>> loader,
|
public void onLoadFinished(Loader<SparseArray<StorageAsyncLoader.StorageResult>> loader,
|
||||||
SparseArray<StorageAsyncLoader.AppsStorageResult> data) {
|
SparseArray<StorageAsyncLoader.StorageResult> data) {
|
||||||
mAppsResult = data;
|
mAppsResult = data;
|
||||||
maybeCacheFreshValues();
|
maybeCacheFreshValues();
|
||||||
onReceivedSizes();
|
onReceivedSizes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoaderReset(Loader<SparseArray<StorageAsyncLoader.AppsStorageResult>> loader) {
|
public void onLoaderReset(Loader<SparseArray<StorageAsyncLoader.StorageResult>> loader) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -507,20 +507,20 @@ public class StorageDashboardFragment extends DashboardFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public SparseArray<StorageAsyncLoader.AppsStorageResult> getAppsStorageResult() {
|
public SparseArray<StorageAsyncLoader.StorageResult> getStorageResult() {
|
||||||
return mAppsResult;
|
return mAppsResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void setAppsStorageResult(SparseArray<StorageAsyncLoader.AppsStorageResult> info) {
|
public void setStorageResult(SparseArray<StorageAsyncLoader.StorageResult> info) {
|
||||||
mAppsResult = info;
|
mAppsResult = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void initializeCachedValues() {
|
void initializeCachedValues() {
|
||||||
final PrivateStorageInfo info = mCachedStorageValuesHelper.getCachedPrivateStorageInfo();
|
final PrivateStorageInfo info = mCachedStorageValuesHelper.getCachedPrivateStorageInfo();
|
||||||
final SparseArray<StorageAsyncLoader.AppsStorageResult> loaderResult =
|
final SparseArray<StorageAsyncLoader.StorageResult> loaderResult =
|
||||||
mCachedStorageValuesHelper.getCachedAppsStorageResult();
|
mCachedStorageValuesHelper.getCachedStorageResult();
|
||||||
if (info == null || loaderResult == null) {
|
if (info == null || loaderResult == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -17,7 +17,8 @@
|
|||||||
package com.android.settings.deviceinfo;
|
package com.android.settings.deviceinfo;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.text.TextUtils;
|
||||||
|
import android.text.format.Formatter;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
|
|
||||||
@@ -25,7 +26,6 @@ import androidx.preference.Preference;
|
|||||||
import androidx.preference.PreferenceViewHolder;
|
import androidx.preference.PreferenceViewHolder;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.utils.FileSizeFormatter;
|
|
||||||
|
|
||||||
public class StorageItemPreference extends Preference {
|
public class StorageItemPreference extends Preference {
|
||||||
public int userHandle;
|
public int userHandle;
|
||||||
@@ -49,12 +49,8 @@ public class StorageItemPreference extends Preference {
|
|||||||
|
|
||||||
public void setStorageSize(long size, long total) {
|
public void setStorageSize(long size, long total) {
|
||||||
mStorageSize = size;
|
mStorageSize = size;
|
||||||
setSummary(
|
setSummary(getStorageSummary(size));
|
||||||
FileSizeFormatter.formatFileSize(
|
|
||||||
getContext(),
|
|
||||||
size,
|
|
||||||
getGigabyteSuffix(getContext().getResources()),
|
|
||||||
FileSizeFormatter.GIGABYTE_IN_BYTES));
|
|
||||||
if (total == 0) {
|
if (total == 0) {
|
||||||
mProgressPercent = 0;
|
mProgressPercent = 0;
|
||||||
} else {
|
} else {
|
||||||
@@ -82,7 +78,10 @@ public class StorageItemPreference extends Preference {
|
|||||||
super.onBindViewHolder(view);
|
super.onBindViewHolder(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getGigabyteSuffix(Resources res) {
|
private String getStorageSummary(long bytes) {
|
||||||
return res.getIdentifier("gigabyteShort", "string", "android");
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -35,9 +35,11 @@ public class CachedStorageValuesHelper {
|
|||||||
public static final String FREE_BYTES_KEY = "free_bytes";
|
public static final String FREE_BYTES_KEY = "free_bytes";
|
||||||
public static final String TOTAL_BYTES_KEY = "total_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 GAME_APPS_SIZE_KEY = "game_apps_size";
|
||||||
public static final String MUSIC_APPS_SIZE_KEY = "music_apps_size";
|
public static final String AUDIO_SIZE_KEY = "audio_size";
|
||||||
public static final String VIDEO_APPS_SIZE_KEY = "video_apps_size";
|
public static final String VIDEOS_SIZE_KEY = "videos_size";
|
||||||
public static final String PHOTO_APPS_SIZE_KEY = "photo_apps_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 OTHER_APPS_SIZE_KEY = "other_apps_size";
|
||||||
public static final String CACHE_APPS_SIZE_KEY = "cache_apps_size";
|
public static final String CACHE_APPS_SIZE_KEY = "cache_apps_size";
|
||||||
public static final String EXTERNAL_TOTAL_BYTES = "external_total_bytes";
|
public static final String EXTERNAL_TOTAL_BYTES = "external_total_bytes";
|
||||||
@@ -78,21 +80,27 @@ public class CachedStorageValuesHelper {
|
|||||||
return new PrivateStorageInfo(freeBytes, totalBytes);
|
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()) {
|
if (!isDataValid()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final long gamesSize = mSharedPreferences.getLong(GAME_APPS_SIZE_KEY, -1);
|
final long gamesSize = mSharedPreferences.getLong(GAME_APPS_SIZE_KEY, -1);
|
||||||
final long musicAppsSize = mSharedPreferences.getLong(MUSIC_APPS_SIZE_KEY, -1);
|
final long audioSize = mSharedPreferences.getLong(AUDIO_SIZE_KEY, -1);
|
||||||
final long videoAppsSize = mSharedPreferences.getLong(VIDEO_APPS_SIZE_KEY, -1);
|
final long videosSize = mSharedPreferences.getLong(VIDEOS_SIZE_KEY, -1);
|
||||||
final long photoAppSize = mSharedPreferences.getLong(PHOTO_APPS_SIZE_KEY, -1);
|
final long imagesSize = mSharedPreferences.getLong(IMAGES_SIZE_KEY, -1);
|
||||||
final long otherAppsSize = mSharedPreferences.getLong(OTHER_APPS_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);
|
final long cacheSize = mSharedPreferences.getLong(CACHE_APPS_SIZE_KEY, -1);
|
||||||
if (gamesSize < 0
|
if (gamesSize < 0
|
||||||
|| musicAppsSize < 0
|
|| audioSize < 0
|
||||||
|| videoAppsSize < 0
|
|| videosSize < 0
|
||||||
|| photoAppSize < 0
|
|| imagesSize < 0
|
||||||
|| otherAppsSize < 0
|
|| documentsAndOtherSize < 0
|
||||||
|
|| trashSize < 0
|
||||||
|
|| allAppsExceptGamesSize < 0
|
||||||
|| cacheSize < 0) {
|
|| cacheSize < 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -117,31 +125,34 @@ public class CachedStorageValuesHelper {
|
|||||||
externalVideoBytes,
|
externalVideoBytes,
|
||||||
externalImageBytes,
|
externalImageBytes,
|
||||||
externalAppBytes);
|
externalAppBytes);
|
||||||
final StorageAsyncLoader.AppsStorageResult result =
|
final StorageAsyncLoader.StorageResult result = new StorageAsyncLoader.StorageResult();
|
||||||
new StorageAsyncLoader.AppsStorageResult();
|
|
||||||
result.gamesSize = gamesSize;
|
result.gamesSize = gamesSize;
|
||||||
result.musicAppsSize = musicAppsSize;
|
result.audioSize = audioSize;
|
||||||
result.videoAppsSize = videoAppsSize;
|
result.videosSize = videosSize;
|
||||||
result.photosAppsSize = photoAppSize;
|
result.imagesSize = imagesSize;
|
||||||
result.otherAppsSize = otherAppsSize;
|
result.documentsAndOtherSize = documentsAndOtherSize;
|
||||||
|
result.trashSize = trashSize;
|
||||||
|
result.allAppsExceptGamesSize = allAppsExceptGamesSize;
|
||||||
result.cacheSize = cacheSize;
|
result.cacheSize = cacheSize;
|
||||||
result.externalStats = externalStats;
|
result.externalStats = externalStats;
|
||||||
final SparseArray<StorageAsyncLoader.AppsStorageResult> resultArray = new SparseArray<>();
|
final SparseArray<StorageAsyncLoader.StorageResult> resultArray = new SparseArray<>();
|
||||||
resultArray.append(mUserId, result);
|
resultArray.append(mUserId, result);
|
||||||
return resultArray;
|
return resultArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cacheResult(
|
public void cacheResult(
|
||||||
PrivateStorageInfo storageInfo, StorageAsyncLoader.AppsStorageResult result) {
|
PrivateStorageInfo storageInfo, StorageAsyncLoader.StorageResult result) {
|
||||||
mSharedPreferences
|
mSharedPreferences
|
||||||
.edit()
|
.edit()
|
||||||
.putLong(FREE_BYTES_KEY, storageInfo.freeBytes)
|
.putLong(FREE_BYTES_KEY, storageInfo.freeBytes)
|
||||||
.putLong(TOTAL_BYTES_KEY, storageInfo.totalBytes)
|
.putLong(TOTAL_BYTES_KEY, storageInfo.totalBytes)
|
||||||
.putLong(GAME_APPS_SIZE_KEY, result.gamesSize)
|
.putLong(GAME_APPS_SIZE_KEY, result.gamesSize)
|
||||||
.putLong(MUSIC_APPS_SIZE_KEY, result.musicAppsSize)
|
.putLong(AUDIO_SIZE_KEY, result.audioSize)
|
||||||
.putLong(VIDEO_APPS_SIZE_KEY, result.videoAppsSize)
|
.putLong(VIDEOS_SIZE_KEY, result.videosSize)
|
||||||
.putLong(PHOTO_APPS_SIZE_KEY, result.photosAppsSize)
|
.putLong(IMAGES_SIZE_KEY, result.imagesSize)
|
||||||
.putLong(OTHER_APPS_SIZE_KEY, result.otherAppsSize)
|
.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(CACHE_APPS_SIZE_KEY, result.cacheSize)
|
||||||
.putLong(EXTERNAL_TOTAL_BYTES, result.externalStats.totalBytes)
|
.putLong(EXTERNAL_TOTAL_BYTES, result.externalStats.totalBytes)
|
||||||
.putLong(EXTERNAL_AUDIO_BYTES, result.externalStats.audioBytes)
|
.putLong(EXTERNAL_AUDIO_BYTES, result.externalStats.audioBytes)
|
||||||
|
@@ -168,9 +168,9 @@ public class SecondaryUserController extends AbstractPreferenceController implem
|
|||||||
mTotalSizeBytes = totalSizeBytes;
|
mTotalSizeBytes = totalSizeBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleResult(SparseArray<StorageAsyncLoader.AppsStorageResult> stats) {
|
@Override
|
||||||
int userId = getUser().id;
|
public void handleResult(SparseArray<StorageAsyncLoader.StorageResult> stats) {
|
||||||
StorageAsyncLoader.AppsStorageResult result = stats.get(userId);
|
final StorageAsyncLoader.StorageResult result = stats.get(getUser().id);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
setSize(result.externalStats.totalBytes);
|
setSize(result.externalStats.totalBytes);
|
||||||
}
|
}
|
||||||
|
@@ -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_IMAGE;
|
||||||
import static android.content.pm.ApplicationInfo.CATEGORY_VIDEO;
|
import static android.content.pm.ApplicationInfo.CATEGORY_VIDEO;
|
||||||
|
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.ApplicationInfo;
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.net.Uri;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
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.ArraySet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
@@ -37,7 +44,6 @@ import com.android.settingslib.utils.AsyncLoaderCompat;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,7 +51,7 @@ import java.util.List;
|
|||||||
* users
|
* users
|
||||||
*/
|
*/
|
||||||
public class StorageAsyncLoader
|
public class StorageAsyncLoader
|
||||||
extends AsyncLoaderCompat<SparseArray<StorageAsyncLoader.AppsStorageResult>> {
|
extends AsyncLoaderCompat<SparseArray<StorageAsyncLoader.StorageResult>> {
|
||||||
private UserManager mUserManager;
|
private UserManager mUserManager;
|
||||||
private static final String TAG = "StorageAsyncLoader";
|
private static final String TAG = "StorageAsyncLoader";
|
||||||
|
|
||||||
@@ -64,38 +70,81 @@ public class StorageAsyncLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SparseArray<AppsStorageResult> loadInBackground() {
|
public SparseArray<StorageResult> loadInBackground() {
|
||||||
return loadApps();
|
return getStorageResultsForUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
private SparseArray<AppsStorageResult> loadApps() {
|
private SparseArray<StorageResult> getStorageResultsForUsers() {
|
||||||
mSeenPackages = new ArraySet<>();
|
mSeenPackages = new ArraySet<>();
|
||||||
SparseArray<AppsStorageResult> result = new SparseArray<>();
|
final SparseArray<StorageResult> results = new SparseArray<>();
|
||||||
List<UserInfo> infos = mUserManager.getUsers();
|
final List<UserInfo> infos = mUserManager.getUsers();
|
||||||
|
|
||||||
// Sort the users by user id ascending.
|
// Sort the users by user id ascending.
|
||||||
Collections.sort(
|
Collections.sort(infos,
|
||||||
infos,
|
(userInfo, otherUser) -> Integer.compare(userInfo.id, otherUser.id));
|
||||||
new Comparator<UserInfo>() {
|
|
||||||
@Override
|
for (UserInfo info : infos) {
|
||||||
public int compare(UserInfo userInfo, UserInfo otherUser) {
|
final StorageResult result = getAppsAndGamesSize(info.id);
|
||||||
return Integer.compare(userInfo.id, otherUser.id);
|
|
||||||
}
|
result.imagesSize = getFilesSize(info.id, MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
|
||||||
});
|
null /* queryArgs */);
|
||||||
for (int i = 0, userCount = infos.size(); i < userCount; i++) {
|
result.videosSize = getFilesSize(info.id, MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
|
||||||
final UserInfo info = infos.get(i);
|
null /* queryArgs */);
|
||||||
result.put(info.id, getStorageResultForUser(info.id));
|
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");
|
Log.d(TAG, "Loading apps");
|
||||||
List<ApplicationInfo> applicationInfos =
|
final List<ApplicationInfo> applicationInfos =
|
||||||
mPackageManager.getInstalledApplicationsAsUser(0, userId);
|
mPackageManager.getInstalledApplicationsAsUser(0, userId);
|
||||||
AppsStorageResult result = new AppsStorageResult();
|
final StorageResult result = new StorageResult();
|
||||||
UserHandle myUser = UserHandle.of(userId);
|
final UserHandle myUser = UserHandle.of(userId);
|
||||||
for (int i = 0, size = applicationInfos.size(); i < size; i++) {
|
for (int i = 0, size = applicationInfos.size(); i < size; i++) {
|
||||||
ApplicationInfo app = applicationInfos.get(i);
|
final ApplicationInfo app = applicationInfos.get(i);
|
||||||
|
|
||||||
StorageStatsSource.AppStorageStats stats;
|
StorageStatsSource.AppStorageStats stats;
|
||||||
try {
|
try {
|
||||||
@@ -131,28 +180,9 @@ public class StorageAsyncLoader
|
|||||||
result.gamesSize += blamedSize;
|
result.gamesSize += blamedSize;
|
||||||
break;
|
break;
|
||||||
case CATEGORY_AUDIO:
|
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:
|
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:
|
case CATEGORY_IMAGE:
|
||||||
// TODO(b/170918505): Should revamp image size calculation with the data
|
result.allAppsExceptGamesSize += blamedSize;
|
||||||
// from media provider.
|
|
||||||
result.photosAppsSize += blamedSize;
|
|
||||||
result.photosAppsSize -= stats.getCodeBytes();
|
|
||||||
|
|
||||||
result.otherAppsSize += blamedSize;
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// The deprecated game flag does not set the category.
|
// The deprecated game flag does not set the category.
|
||||||
@@ -160,7 +190,7 @@ public class StorageAsyncLoader
|
|||||||
result.gamesSize += blamedSize;
|
result.gamesSize += blamedSize;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
result.otherAppsSize += blamedSize;
|
result.allAppsExceptGamesSize += blamedSize;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,15 +207,22 @@ public class StorageAsyncLoader
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 gamesSize;
|
||||||
public long musicAppsSize;
|
public long allAppsExceptGamesSize;
|
||||||
public long photosAppsSize;
|
|
||||||
public long videoAppsSize;
|
// File based sizes.
|
||||||
public long otherAppsSize;
|
public long audioSize;
|
||||||
|
public long imagesSize;
|
||||||
|
public long videosSize;
|
||||||
|
public long documentsAndOtherSize;
|
||||||
|
public long trashSize;
|
||||||
|
|
||||||
public long cacheSize;
|
public long cacheSize;
|
||||||
public long duplicateCodeSize;
|
public long duplicateCodeSize;
|
||||||
public StorageStatsSource.ExternalStorageStats externalStats;
|
public StorageStatsSource.ExternalStorageStats externalStats;
|
||||||
@@ -196,6 +233,7 @@ public class StorageAsyncLoader
|
|||||||
* {@link StorageAsyncLoader}.
|
* {@link StorageAsyncLoader}.
|
||||||
*/
|
*/
|
||||||
public interface ResultHandler {
|
public interface ResultHandler {
|
||||||
void handleResult(SparseArray<AppsStorageResult> result);
|
/** Overrides this method to get storage result once it's available. */
|
||||||
|
void handleResult(SparseArray<StorageResult> result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -357,18 +357,18 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
|||||||
updatePrivateStorageCategoryPreferencesOrder();
|
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) {
|
int userId) {
|
||||||
final StorageAsyncLoader.AppsStorageResult data = result.get(userId);
|
final StorageAsyncLoader.StorageResult data = result.get(userId);
|
||||||
|
|
||||||
mImagesPreference.setStorageSize(getImagesSize(data), mTotalSize);
|
mImagesPreference.setStorageSize(data.imagesSize, mTotalSize);
|
||||||
mVideosPreference.setStorageSize(getVideosSize(data), mTotalSize);
|
mVideosPreference.setStorageSize(data.videosSize, mTotalSize);
|
||||||
mAudioPreference.setStorageSize(getAudioSize(data), mTotalSize);
|
mAudioPreference.setStorageSize(data.audioSize, mTotalSize);
|
||||||
mAppsPreference.setStorageSize(getAppsSize(data), mTotalSize);
|
mAppsPreference.setStorageSize(data.allAppsExceptGamesSize, mTotalSize);
|
||||||
mGamesPreference.setStorageSize(getGamesSize(data), mTotalSize);
|
mGamesPreference.setStorageSize(data.gamesSize, mTotalSize);
|
||||||
mDocumentsAndOtherPreference.setStorageSize(getDocumentsAndOtherSize(data),
|
mDocumentsAndOtherPreference.setStorageSize(data.documentsAndOtherSize, mTotalSize);
|
||||||
mTotalSize);
|
mTrashPreference.setStorageSize(data.trashSize, mTotalSize);
|
||||||
mTrashPreference.setStorageSize(getTrashSize(data), mTotalSize);
|
|
||||||
|
|
||||||
if (mSystemPreference != null) {
|
if (mSystemPreference != null) {
|
||||||
// Everything else that hasn't already been attributed is tracked as
|
// Everything else that hasn't already been attributed is tracked as
|
||||||
@@ -377,13 +377,15 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
|||||||
// from media provider.
|
// from media provider.
|
||||||
long attributedSize = 0;
|
long attributedSize = 0;
|
||||||
for (int i = 0; i < result.size(); i++) {
|
for (int i = 0; i < result.size(); i++) {
|
||||||
final StorageAsyncLoader.AppsStorageResult otherData = result.valueAt(i);
|
final StorageAsyncLoader.StorageResult otherData = result.valueAt(i);
|
||||||
attributedSize +=
|
attributedSize +=
|
||||||
otherData.gamesSize
|
otherData.gamesSize
|
||||||
+ otherData.musicAppsSize
|
+ otherData.audioSize
|
||||||
+ otherData.videoAppsSize
|
+ otherData.videosSize
|
||||||
+ otherData.photosAppsSize
|
+ otherData.imagesSize
|
||||||
+ otherData.otherAppsSize;
|
+ otherData.documentsAndOtherSize
|
||||||
|
+ otherData.trashSize
|
||||||
|
+ otherData.allAppsExceptGamesSize;
|
||||||
attributedSize += otherData.externalStats.totalBytes
|
attributedSize += otherData.externalStats.totalBytes
|
||||||
- otherData.externalStats.appBytes;
|
- otherData.externalStats.appBytes;
|
||||||
attributedSize -= otherData.duplicateCodeSize;
|
attributedSize -= otherData.duplicateCodeSize;
|
||||||
@@ -418,18 +420,6 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
|||||||
mContext.startActivityAsUser(intent, new UserHandle(mUserId));
|
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() {
|
private void launchAppsIntent() {
|
||||||
final Bundle args = getWorkAnnotatedBundle(3);
|
final Bundle args = getWorkAnnotatedBundle(3);
|
||||||
args.putString(ManageApplications.EXTRA_CLASSNAME,
|
args.putString(ManageApplications.EXTRA_CLASSNAME,
|
||||||
@@ -446,10 +436,6 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
|||||||
Utils.launchIntent(mFragment, intent);
|
Utils.launchIntent(mFragment, intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getAppsSize(StorageAsyncLoader.AppsStorageResult data) {
|
|
||||||
return data.otherAppsSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void launchGamesIntent() {
|
private void launchGamesIntent() {
|
||||||
final Bundle args = getWorkAnnotatedBundle(1);
|
final Bundle args = getWorkAnnotatedBundle(1);
|
||||||
args.putString(ManageApplications.EXTRA_CLASSNAME,
|
args.putString(ManageApplications.EXTRA_CLASSNAME,
|
||||||
@@ -464,10 +450,6 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
|||||||
Utils.launchIntent(mFragment, intent);
|
Utils.launchIntent(mFragment, intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getGamesSize(StorageAsyncLoader.AppsStorageResult data) {
|
|
||||||
return data.gamesSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Bundle getWorkAnnotatedBundle(int additionalCapacity) {
|
private Bundle getWorkAnnotatedBundle(int additionalCapacity) {
|
||||||
final Bundle args = new Bundle(1 + additionalCapacity);
|
final Bundle args = new Bundle(1 + additionalCapacity);
|
||||||
args.putInt(SettingsActivity.EXTRA_SHOW_FRAGMENT_TAB,
|
args.putInt(SettingsActivity.EXTRA_SHOW_FRAGMENT_TAB,
|
||||||
@@ -475,14 +457,6 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
|||||||
return args;
|
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() {
|
private void launchTrashIntent() {
|
||||||
final Intent intent = new Intent("android.settings.VIEW_TRASH");
|
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,
|
private static long totalValues(StorageMeasurement.MeasurementDetails details, int userId,
|
||||||
String... keys) {
|
String... keys) {
|
||||||
long total = 0;
|
long total = 0;
|
||||||
|
@@ -77,14 +77,14 @@ public class StorageDashboardFragmentTest {
|
|||||||
CachedStorageValuesHelper helper = mock(CachedStorageValuesHelper.class);
|
CachedStorageValuesHelper helper = mock(CachedStorageValuesHelper.class);
|
||||||
PrivateStorageInfo info = new PrivateStorageInfo(0, 0);
|
PrivateStorageInfo info = new PrivateStorageInfo(0, 0);
|
||||||
when(helper.getCachedPrivateStorageInfo()).thenReturn(info);
|
when(helper.getCachedPrivateStorageInfo()).thenReturn(info);
|
||||||
SparseArray<StorageAsyncLoader.AppsStorageResult> result = new SparseArray<>();
|
SparseArray<StorageAsyncLoader.StorageResult> result = new SparseArray<>();
|
||||||
when(helper.getCachedAppsStorageResult()).thenReturn(result);
|
when(helper.getCachedStorageResult()).thenReturn(result);
|
||||||
|
|
||||||
mFragment.setCachedStorageValuesHelper(helper);
|
mFragment.setCachedStorageValuesHelper(helper);
|
||||||
mFragment.initializeCachedValues();
|
mFragment.initializeCachedValues();
|
||||||
|
|
||||||
assertThat(mFragment.getPrivateStorageInfo()).isEqualTo(info);
|
assertThat(mFragment.getPrivateStorageInfo()).isEqualTo(info);
|
||||||
assertThat(mFragment.getAppsStorageResult()).isEqualTo(result);
|
assertThat(mFragment.getStorageResult()).isEqualTo(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -97,20 +97,20 @@ public class StorageDashboardFragmentTest {
|
|||||||
mFragment.initializeCachedValues();
|
mFragment.initializeCachedValues();
|
||||||
|
|
||||||
assertThat(mFragment.getPrivateStorageInfo()).isNull();
|
assertThat(mFragment.getPrivateStorageInfo()).isNull();
|
||||||
assertThat(mFragment.getAppsStorageResult()).isNull();
|
assertThat(mFragment.getStorageResult()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_cacheProviderDoesntProvideValuesIfVolumeInfoMissing() {
|
public void test_cacheProviderDoesntProvideValuesIfVolumeInfoMissing() {
|
||||||
CachedStorageValuesHelper helper = mock(CachedStorageValuesHelper.class);
|
CachedStorageValuesHelper helper = mock(CachedStorageValuesHelper.class);
|
||||||
SparseArray<StorageAsyncLoader.AppsStorageResult> result = new SparseArray<>();
|
SparseArray<StorageAsyncLoader.StorageResult> result = new SparseArray<>();
|
||||||
when(helper.getCachedAppsStorageResult()).thenReturn(result);
|
when(helper.getCachedStorageResult()).thenReturn(result);
|
||||||
|
|
||||||
mFragment.setCachedStorageValuesHelper(helper);
|
mFragment.setCachedStorageValuesHelper(helper);
|
||||||
mFragment.initializeCachedValues();
|
mFragment.initializeCachedValues();
|
||||||
|
|
||||||
assertThat(mFragment.getPrivateStorageInfo()).isNull();
|
assertThat(mFragment.getPrivateStorageInfo()).isNull();
|
||||||
assertThat(mFragment.getAppsStorageResult()).isNull();
|
assertThat(mFragment.getStorageResult()).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -169,7 +169,7 @@ public class StorageDashboardFragmentTest {
|
|||||||
mFragment = spy(mFragment);
|
mFragment = spy(mFragment);
|
||||||
when(mFragment.getView()).thenReturn(fakeView);
|
when(mFragment.getView()).thenReturn(fakeView);
|
||||||
when(mFragment.getListView()).thenReturn(fakeRecyclerView);
|
when(mFragment.getListView()).thenReturn(fakeRecyclerView);
|
||||||
mFragment.setAppsStorageResult(new SparseArray<>());
|
mFragment.setStorageResult(new SparseArray<>());
|
||||||
|
|
||||||
mFragment.maybeSetLoading(true);
|
mFragment.maybeSetLoading(true);
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ public class StorageDashboardFragmentTest {
|
|||||||
when(mFragment.getView()).thenReturn(fakeView);
|
when(mFragment.getView()).thenReturn(fakeView);
|
||||||
when(mFragment.getListView()).thenReturn(fakeRecyclerView);
|
when(mFragment.getListView()).thenReturn(fakeRecyclerView);
|
||||||
|
|
||||||
mFragment.setAppsStorageResult(new SparseArray<>());
|
mFragment.setStorageResult(new SparseArray<>());
|
||||||
PrivateStorageInfo storageInfo = new PrivateStorageInfo(0, 0);
|
PrivateStorageInfo storageInfo = new PrivateStorageInfo(0, 0);
|
||||||
mFragment.setPrivateStorageInfo(storageInfo);
|
mFragment.setPrivateStorageInfo(storageInfo);
|
||||||
|
|
||||||
@@ -203,4 +203,4 @@ public class StorageDashboardFragmentTest {
|
|||||||
assertThat(indexRes).isNotNull();
|
assertThat(indexRes).isNotNull();
|
||||||
assertThat(indexRes.get(0).xmlResId).isEqualTo(mFragment.getPreferenceScreenResId());
|
assertThat(indexRes.get(0).xmlResId).isEqualTo(mFragment.getPreferenceScreenResId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -54,7 +54,7 @@ public class StorageItemPreferenceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testAfterLoad() {
|
public void testAfterLoad() {
|
||||||
mPreference.setStorageSize(MEGABYTE_IN_BYTES * 10, MEGABYTE_IN_BYTES * 100);
|
mPreference.setStorageSize(MEGABYTE_IN_BYTES * 10, MEGABYTE_IN_BYTES * 100);
|
||||||
assertThat(mPreference.getSummary()).isEqualTo("0.01 GB");
|
assertThat(mPreference.getSummary()).isEqualTo("10 MB");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -16,7 +16,9 @@
|
|||||||
|
|
||||||
package com.android.settings.deviceinfo.storage;
|
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.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_APP_BYTES;
|
||||||
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper
|
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper
|
||||||
.EXTERNAL_AUDIO_BYTES;
|
.EXTERNAL_AUDIO_BYTES;
|
||||||
@@ -28,15 +30,15 @@ import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper
|
|||||||
.EXTERNAL_VIDEO_BYTES;
|
.EXTERNAL_VIDEO_BYTES;
|
||||||
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.FREE_BYTES_KEY;
|
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.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.OTHER_APPS_SIZE_KEY;
|
||||||
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.PHOTO_APPS_SIZE_KEY;
|
|
||||||
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper
|
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper
|
||||||
.SHARED_PREFERENCES_NAME;
|
.SHARED_PREFERENCES_NAME;
|
||||||
import static com.android.settings.deviceinfo.storage.CachedStorageValuesHelper.TIMESTAMP_KEY;
|
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.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.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;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
@@ -81,9 +83,9 @@ public class CachedStorageValuesHelperTest {
|
|||||||
mSharedPreferences
|
mSharedPreferences
|
||||||
.edit()
|
.edit()
|
||||||
.putLong(GAME_APPS_SIZE_KEY, 0)
|
.putLong(GAME_APPS_SIZE_KEY, 0)
|
||||||
.putLong(MUSIC_APPS_SIZE_KEY, 10)
|
.putLong(AUDIO_SIZE_KEY, 10)
|
||||||
.putLong(VIDEO_APPS_SIZE_KEY, 100)
|
.putLong(VIDEOS_SIZE_KEY, 100)
|
||||||
.putLong(PHOTO_APPS_SIZE_KEY, 1000)
|
.putLong(IMAGES_SIZE_KEY, 1000)
|
||||||
.putLong(OTHER_APPS_SIZE_KEY, 10000)
|
.putLong(OTHER_APPS_SIZE_KEY, 10000)
|
||||||
.putLong(CACHE_APPS_SIZE_KEY, 100000)
|
.putLong(CACHE_APPS_SIZE_KEY, 100000)
|
||||||
.putLong(EXTERNAL_TOTAL_BYTES, 2)
|
.putLong(EXTERNAL_TOTAL_BYTES, 2)
|
||||||
@@ -104,14 +106,16 @@ public class CachedStorageValuesHelperTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getCachedAppsStorageResult_cachedValuesAreLoaded() {
|
public void getCachedStorageResult_cachedValuesAreLoaded() {
|
||||||
when(mMockClock.getCurrentTime()).thenReturn(10001L);
|
when(mMockClock.getCurrentTime()).thenReturn(10001L);
|
||||||
mSharedPreferences
|
mSharedPreferences
|
||||||
.edit()
|
.edit()
|
||||||
.putLong(GAME_APPS_SIZE_KEY, 1)
|
.putLong(GAME_APPS_SIZE_KEY, 1)
|
||||||
.putLong(MUSIC_APPS_SIZE_KEY, 10)
|
.putLong(AUDIO_SIZE_KEY, 10)
|
||||||
.putLong(VIDEO_APPS_SIZE_KEY, 100)
|
.putLong(VIDEOS_SIZE_KEY, 100)
|
||||||
.putLong(PHOTO_APPS_SIZE_KEY, 1000)
|
.putLong(IMAGES_SIZE_KEY, 1000)
|
||||||
|
.putLong(DOCUMENTS_AND_OTHER_SIZE_KEY, 1001)
|
||||||
|
.putLong(TRASH_SIZE_KEY, 1002)
|
||||||
.putLong(OTHER_APPS_SIZE_KEY, 10000)
|
.putLong(OTHER_APPS_SIZE_KEY, 10000)
|
||||||
.putLong(CACHE_APPS_SIZE_KEY, 100000)
|
.putLong(CACHE_APPS_SIZE_KEY, 100000)
|
||||||
.putLong(EXTERNAL_TOTAL_BYTES, 222222)
|
.putLong(EXTERNAL_TOTAL_BYTES, 222222)
|
||||||
@@ -125,15 +129,17 @@ public class CachedStorageValuesHelperTest {
|
|||||||
.putLong(TIMESTAMP_KEY, 10000L)
|
.putLong(TIMESTAMP_KEY, 10000L)
|
||||||
.apply();
|
.apply();
|
||||||
|
|
||||||
final SparseArray<StorageAsyncLoader.AppsStorageResult> result =
|
final SparseArray<StorageAsyncLoader.StorageResult> result =
|
||||||
mCachedValuesHelper.getCachedAppsStorageResult();
|
mCachedValuesHelper.getCachedStorageResult();
|
||||||
|
|
||||||
StorageAsyncLoader.AppsStorageResult primaryResult = result.get(0);
|
StorageAsyncLoader.StorageResult primaryResult = result.get(0);
|
||||||
assertThat(primaryResult.gamesSize).isEqualTo(1L);
|
assertThat(primaryResult.gamesSize).isEqualTo(1L);
|
||||||
assertThat(primaryResult.musicAppsSize).isEqualTo(10L);
|
assertThat(primaryResult.audioSize).isEqualTo(10L);
|
||||||
assertThat(primaryResult.videoAppsSize).isEqualTo(100L);
|
assertThat(primaryResult.videosSize).isEqualTo(100L);
|
||||||
assertThat(primaryResult.photosAppsSize).isEqualTo(1000L);
|
assertThat(primaryResult.imagesSize).isEqualTo(1000L);
|
||||||
assertThat(primaryResult.otherAppsSize).isEqualTo(10000L);
|
assertThat(primaryResult.documentsAndOtherSize).isEqualTo(1001L);
|
||||||
|
assertThat(primaryResult.trashSize).isEqualTo(1002L);
|
||||||
|
assertThat(primaryResult.allAppsExceptGamesSize).isEqualTo(10000L);
|
||||||
assertThat(primaryResult.cacheSize).isEqualTo(100000L);
|
assertThat(primaryResult.cacheSize).isEqualTo(100000L);
|
||||||
assertThat(primaryResult.externalStats.totalBytes).isEqualTo(222222L);
|
assertThat(primaryResult.externalStats.totalBytes).isEqualTo(222222L);
|
||||||
assertThat(primaryResult.externalStats.audioBytes).isEqualTo(22L);
|
assertThat(primaryResult.externalStats.audioBytes).isEqualTo(22L);
|
||||||
@@ -148,9 +154,9 @@ public class CachedStorageValuesHelperTest {
|
|||||||
mSharedPreferences
|
mSharedPreferences
|
||||||
.edit()
|
.edit()
|
||||||
.putLong(GAME_APPS_SIZE_KEY, 0)
|
.putLong(GAME_APPS_SIZE_KEY, 0)
|
||||||
.putLong(MUSIC_APPS_SIZE_KEY, 10)
|
.putLong(AUDIO_SIZE_KEY, 10)
|
||||||
.putLong(VIDEO_APPS_SIZE_KEY, 100)
|
.putLong(VIDEOS_SIZE_KEY, 100)
|
||||||
.putLong(PHOTO_APPS_SIZE_KEY, 1000)
|
.putLong(IMAGES_SIZE_KEY, 1000)
|
||||||
.putLong(OTHER_APPS_SIZE_KEY, 10000)
|
.putLong(OTHER_APPS_SIZE_KEY, 10000)
|
||||||
.putLong(CACHE_APPS_SIZE_KEY, 100000)
|
.putLong(CACHE_APPS_SIZE_KEY, 100000)
|
||||||
.putLong(EXTERNAL_TOTAL_BYTES, 2)
|
.putLong(EXTERNAL_TOTAL_BYTES, 2)
|
||||||
@@ -169,14 +175,14 @@ public class CachedStorageValuesHelperTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getCachedAppsStorageResult_nullIfDataIsStale() {
|
public void getCachedStorageResult_nullIfDataIsStale() {
|
||||||
when(mMockClock.getCurrentTime()).thenReturn(10000000L);
|
when(mMockClock.getCurrentTime()).thenReturn(10000000L);
|
||||||
mSharedPreferences
|
mSharedPreferences
|
||||||
.edit()
|
.edit()
|
||||||
.putLong(GAME_APPS_SIZE_KEY, 0)
|
.putLong(GAME_APPS_SIZE_KEY, 0)
|
||||||
.putLong(MUSIC_APPS_SIZE_KEY, 10)
|
.putLong(AUDIO_SIZE_KEY, 10)
|
||||||
.putLong(VIDEO_APPS_SIZE_KEY, 100)
|
.putLong(VIDEOS_SIZE_KEY, 100)
|
||||||
.putLong(PHOTO_APPS_SIZE_KEY, 1000)
|
.putLong(IMAGES_SIZE_KEY, 1000)
|
||||||
.putLong(OTHER_APPS_SIZE_KEY, 10000)
|
.putLong(OTHER_APPS_SIZE_KEY, 10000)
|
||||||
.putLong(CACHE_APPS_SIZE_KEY, 100000)
|
.putLong(CACHE_APPS_SIZE_KEY, 100000)
|
||||||
.putLong(EXTERNAL_TOTAL_BYTES, 2)
|
.putLong(EXTERNAL_TOTAL_BYTES, 2)
|
||||||
@@ -190,8 +196,8 @@ public class CachedStorageValuesHelperTest {
|
|||||||
.putLong(TIMESTAMP_KEY, 10000L)
|
.putLong(TIMESTAMP_KEY, 10000L)
|
||||||
.apply();
|
.apply();
|
||||||
|
|
||||||
final SparseArray<StorageAsyncLoader.AppsStorageResult> result =
|
final SparseArray<StorageAsyncLoader.StorageResult> result =
|
||||||
mCachedValuesHelper.getCachedAppsStorageResult();
|
mCachedValuesHelper.getCachedStorageResult();
|
||||||
assertThat(result).isNull();
|
assertThat(result).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,9 +207,9 @@ public class CachedStorageValuesHelperTest {
|
|||||||
mSharedPreferences
|
mSharedPreferences
|
||||||
.edit()
|
.edit()
|
||||||
.putLong(GAME_APPS_SIZE_KEY, 0)
|
.putLong(GAME_APPS_SIZE_KEY, 0)
|
||||||
.putLong(MUSIC_APPS_SIZE_KEY, 10)
|
.putLong(AUDIO_SIZE_KEY, 10)
|
||||||
.putLong(VIDEO_APPS_SIZE_KEY, 100)
|
.putLong(VIDEOS_SIZE_KEY, 100)
|
||||||
.putLong(PHOTO_APPS_SIZE_KEY, 1000)
|
.putLong(IMAGES_SIZE_KEY, 1000)
|
||||||
.putLong(OTHER_APPS_SIZE_KEY, 10000)
|
.putLong(OTHER_APPS_SIZE_KEY, 10000)
|
||||||
.putLong(CACHE_APPS_SIZE_KEY, 100000)
|
.putLong(CACHE_APPS_SIZE_KEY, 100000)
|
||||||
.putLong(EXTERNAL_TOTAL_BYTES, 2)
|
.putLong(EXTERNAL_TOTAL_BYTES, 2)
|
||||||
@@ -222,14 +228,14 @@ public class CachedStorageValuesHelperTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getCachedAppsStorageResult_nullIfWrongUser() {
|
public void getCachedStorageResult_nullIfWrongUser() {
|
||||||
when(mMockClock.getCurrentTime()).thenReturn(10001L);
|
when(mMockClock.getCurrentTime()).thenReturn(10001L);
|
||||||
mSharedPreferences
|
mSharedPreferences
|
||||||
.edit()
|
.edit()
|
||||||
.putLong(GAME_APPS_SIZE_KEY, 0)
|
.putLong(GAME_APPS_SIZE_KEY, 0)
|
||||||
.putLong(MUSIC_APPS_SIZE_KEY, 10)
|
.putLong(AUDIO_SIZE_KEY, 10)
|
||||||
.putLong(VIDEO_APPS_SIZE_KEY, 100)
|
.putLong(VIDEOS_SIZE_KEY, 100)
|
||||||
.putLong(PHOTO_APPS_SIZE_KEY, 1000)
|
.putLong(IMAGES_SIZE_KEY, 1000)
|
||||||
.putLong(OTHER_APPS_SIZE_KEY, 10000)
|
.putLong(OTHER_APPS_SIZE_KEY, 10000)
|
||||||
.putLong(CACHE_APPS_SIZE_KEY, 100000)
|
.putLong(CACHE_APPS_SIZE_KEY, 100000)
|
||||||
.putLong(EXTERNAL_TOTAL_BYTES, 2)
|
.putLong(EXTERNAL_TOTAL_BYTES, 2)
|
||||||
@@ -243,8 +249,8 @@ public class CachedStorageValuesHelperTest {
|
|||||||
.putLong(TIMESTAMP_KEY, 10000L)
|
.putLong(TIMESTAMP_KEY, 10000L)
|
||||||
.apply();
|
.apply();
|
||||||
|
|
||||||
final SparseArray<StorageAsyncLoader.AppsStorageResult> result =
|
final SparseArray<StorageAsyncLoader.StorageResult> result =
|
||||||
mCachedValuesHelper.getCachedAppsStorageResult();
|
mCachedValuesHelper.getCachedStorageResult();
|
||||||
assertThat(result).isNull();
|
assertThat(result).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,9 +261,9 @@ public class CachedStorageValuesHelperTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getCachedAppsStorageResult_nullIfEmpty() {
|
public void getCachedStorageResult_nullIfEmpty() {
|
||||||
final SparseArray<StorageAsyncLoader.AppsStorageResult> result =
|
final SparseArray<StorageAsyncLoader.StorageResult> result =
|
||||||
mCachedValuesHelper.getCachedAppsStorageResult();
|
mCachedValuesHelper.getCachedStorageResult();
|
||||||
assertThat(result).isNull();
|
assertThat(result).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,13 +272,13 @@ public class CachedStorageValuesHelperTest {
|
|||||||
when(mMockClock.getCurrentTime()).thenReturn(10000L);
|
when(mMockClock.getCurrentTime()).thenReturn(10000L);
|
||||||
final StorageStatsSource.ExternalStorageStats externalStats =
|
final StorageStatsSource.ExternalStorageStats externalStats =
|
||||||
new StorageStatsSource.ExternalStorageStats(22222L, 2L, 20L, 200L, 2000L);
|
new StorageStatsSource.ExternalStorageStats(22222L, 2L, 20L, 200L, 2000L);
|
||||||
final StorageAsyncLoader.AppsStorageResult result =
|
final StorageAsyncLoader.StorageResult result =
|
||||||
new StorageAsyncLoader.AppsStorageResult();
|
new StorageAsyncLoader.StorageResult();
|
||||||
result.gamesSize = 1L;
|
result.gamesSize = 1L;
|
||||||
result.musicAppsSize = 10L;
|
result.audioSize = 10L;
|
||||||
result.videoAppsSize = 100L;
|
result.videosSize = 100L;
|
||||||
result.photosAppsSize = 1000L;
|
result.imagesSize = 1000L;
|
||||||
result.otherAppsSize = 10000L;
|
result.allAppsExceptGamesSize = 10000L;
|
||||||
result.cacheSize = 100000L;
|
result.cacheSize = 100000L;
|
||||||
result.externalStats = externalStats;
|
result.externalStats = externalStats;
|
||||||
final PrivateStorageInfo info = new PrivateStorageInfo(1000L, 6000L);
|
final PrivateStorageInfo info = new PrivateStorageInfo(1000L, 6000L);
|
||||||
@@ -280,9 +286,9 @@ public class CachedStorageValuesHelperTest {
|
|||||||
mCachedValuesHelper.cacheResult(info, result);
|
mCachedValuesHelper.cacheResult(info, result);
|
||||||
|
|
||||||
assertThat(mSharedPreferences.getLong(GAME_APPS_SIZE_KEY, -1)).isEqualTo(1L);
|
assertThat(mSharedPreferences.getLong(GAME_APPS_SIZE_KEY, -1)).isEqualTo(1L);
|
||||||
assertThat(mSharedPreferences.getLong(MUSIC_APPS_SIZE_KEY, -1)).isEqualTo(10L);
|
assertThat(mSharedPreferences.getLong(AUDIO_SIZE_KEY, -1)).isEqualTo(10L);
|
||||||
assertThat(mSharedPreferences.getLong(VIDEO_APPS_SIZE_KEY, -1)).isEqualTo(100L);
|
assertThat(mSharedPreferences.getLong(VIDEOS_SIZE_KEY, -1)).isEqualTo(100L);
|
||||||
assertThat(mSharedPreferences.getLong(PHOTO_APPS_SIZE_KEY, -1)).isEqualTo(1000L);
|
assertThat(mSharedPreferences.getLong(IMAGES_SIZE_KEY, -1)).isEqualTo(1000L);
|
||||||
assertThat(mSharedPreferences.getLong(OTHER_APPS_SIZE_KEY, -1)).isEqualTo(10000L);
|
assertThat(mSharedPreferences.getLong(OTHER_APPS_SIZE_KEY, -1)).isEqualTo(10000L);
|
||||||
assertThat(mSharedPreferences.getLong(CACHE_APPS_SIZE_KEY, -1)).isEqualTo(100000L);
|
assertThat(mSharedPreferences.getLong(CACHE_APPS_SIZE_KEY, -1)).isEqualTo(100000L);
|
||||||
assertThat(mSharedPreferences.getLong(EXTERNAL_TOTAL_BYTES, -1)).isEqualTo(22222L);
|
assertThat(mSharedPreferences.getLong(EXTERNAL_TOTAL_BYTES, -1)).isEqualTo(22222L);
|
||||||
|
@@ -103,7 +103,7 @@ public class SecondaryUserControllerTest {
|
|||||||
verify(mGroup).addPreference(argumentCaptor.capture());
|
verify(mGroup).addPreference(argumentCaptor.capture());
|
||||||
|
|
||||||
final Preference preference = argumentCaptor.getValue();
|
final Preference preference = argumentCaptor.getValue();
|
||||||
assertThat(preference.getSummary()).isEqualTo("0.01 GB");
|
assertThat(preference.getSummary()).isEqualTo("10 MB");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -201,9 +201,9 @@ public class SecondaryUserControllerTest {
|
|||||||
mPrimaryUser.name = TEST_NAME;
|
mPrimaryUser.name = TEST_NAME;
|
||||||
mPrimaryUser.id = 10;
|
mPrimaryUser.id = 10;
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
final StorageAsyncLoader.AppsStorageResult userResult =
|
final StorageAsyncLoader.StorageResult userResult =
|
||||||
new StorageAsyncLoader.AppsStorageResult();
|
new StorageAsyncLoader.StorageResult();
|
||||||
final SparseArray<StorageAsyncLoader.AppsStorageResult> result = new SparseArray<>();
|
final SparseArray<StorageAsyncLoader.StorageResult> result = new SparseArray<>();
|
||||||
userResult.externalStats =
|
userResult.externalStats =
|
||||||
new StorageStatsSource.ExternalStorageStats(
|
new StorageStatsSource.ExternalStorageStats(
|
||||||
MEGABYTE_IN_BYTES * 30,
|
MEGABYTE_IN_BYTES * 30,
|
||||||
@@ -217,7 +217,7 @@ public class SecondaryUserControllerTest {
|
|||||||
verify(mGroup).addPreference(argumentCaptor.capture());
|
verify(mGroup).addPreference(argumentCaptor.capture());
|
||||||
final Preference preference = argumentCaptor.getValue();
|
final Preference preference = argumentCaptor.getValue();
|
||||||
|
|
||||||
assertThat(preference.getSummary()).isEqualTo("0.03 GB");
|
assertThat(preference.getSummary()).isEqualTo("30 MB");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -16,6 +16,8 @@
|
|||||||
package com.android.settings.deviceinfo.storage;
|
package com.android.settings.deviceinfo.storage;
|
||||||
|
|
||||||
import static com.android.settings.applications.manageapplications.ManageApplications.EXTRA_WORK_ID;
|
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.android.settings.utils.FileSizeFormatter.MEGABYTE_IN_BYTES;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
@@ -336,12 +338,14 @@ public class StorageItemPreferenceControllerTest {
|
|||||||
mController.displayPreference(mPreferenceScreen);
|
mController.displayPreference(mPreferenceScreen);
|
||||||
|
|
||||||
mController.setUsedSize(MEGABYTE_IN_BYTES * 970); // There should 870MB attributed.
|
mController.setUsedSize(MEGABYTE_IN_BYTES * 970); // There should 870MB attributed.
|
||||||
final StorageAsyncLoader.AppsStorageResult result =
|
final StorageAsyncLoader.StorageResult result = new StorageAsyncLoader.StorageResult();
|
||||||
new StorageAsyncLoader.AppsStorageResult();
|
|
||||||
result.gamesSize = MEGABYTE_IN_BYTES * 80;
|
result.gamesSize = MEGABYTE_IN_BYTES * 80;
|
||||||
result.videoAppsSize = MEGABYTE_IN_BYTES * 160;
|
result.imagesSize = MEGABYTE_IN_BYTES * 350;
|
||||||
result.musicAppsSize = MEGABYTE_IN_BYTES * 40;
|
result.videosSize = GIGABYTE_IN_BYTES * 30;
|
||||||
result.otherAppsSize = MEGABYTE_IN_BYTES * 90;
|
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 =
|
result.externalStats =
|
||||||
new StorageStatsSource.ExternalStorageStats(
|
new StorageStatsSource.ExternalStorageStats(
|
||||||
MEGABYTE_IN_BYTES * 500, // total
|
MEGABYTE_IN_BYTES * 500, // total
|
||||||
@@ -349,17 +353,18 @@ public class StorageItemPreferenceControllerTest {
|
|||||||
MEGABYTE_IN_BYTES * 150, // video
|
MEGABYTE_IN_BYTES * 150, // video
|
||||||
MEGABYTE_IN_BYTES * 200, 0); // image
|
MEGABYTE_IN_BYTES * 200, 0); // image
|
||||||
|
|
||||||
final SparseArray<StorageAsyncLoader.AppsStorageResult> results = new SparseArray<>();
|
final SparseArray<StorageAsyncLoader.StorageResult> results = new SparseArray<>();
|
||||||
results.put(0, result);
|
results.put(0, result);
|
||||||
mController.onLoadFinished(results, 0);
|
mController.onLoadFinished(results, 0);
|
||||||
|
|
||||||
assertThat(mController.mImagesPreference.getSummary().toString()).isEqualTo("0.35 GB");
|
assertThat(mController.mImagesPreference.getSummary().toString()).isEqualTo("350 MB");
|
||||||
assertThat(mController.mVideosPreference.getSummary().toString()).isEqualTo("0.16 GB");
|
assertThat(mController.mVideosPreference.getSummary().toString()).isEqualTo("30 GB");
|
||||||
assertThat(mController.mAudioPreference.getSummary().toString()).isEqualTo("0.14 GB");
|
assertThat(mController.mAudioPreference.getSummary().toString()).isEqualTo("40 MB");
|
||||||
assertThat(mController.mAppsPreference.getSummary().toString()).isEqualTo("0.09 GB");
|
assertThat(mController.mAppsPreference.getSummary().toString()).isEqualTo("90 MB");
|
||||||
assertThat(mController.mGamesPreference.getSummary().toString()).isEqualTo("0.08 GB");
|
assertThat(mController.mGamesPreference.getSummary().toString()).isEqualTo("80 MB");
|
||||||
assertThat(mController.mDocumentsAndOtherPreference.getSummary().toString())
|
assertThat(mController.mDocumentsAndOtherPreference.getSummary().toString())
|
||||||
.isEqualTo("0.05 GB");
|
.isEqualTo("50 MB");
|
||||||
|
assertThat(mController.mTrashPreference.getSummary().toString()).isEqualTo("100 kB");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -101,22 +101,22 @@ public class StorageAsyncLoaderTest {
|
|||||||
addPackage(PACKAGE_NAME_1, 0, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED);
|
addPackage(PACKAGE_NAME_1, 0, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED);
|
||||||
addPackage(PACKAGE_NAME_2, 0, 100, 1000, 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.size()).isEqualTo(1);
|
||||||
assertThat(result.get(PRIMARY_USER_ID).gamesSize).isEqualTo(0L);
|
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
|
@Test
|
||||||
public void testGamesAreFiltered() throws Exception {
|
public void testGamesAreFiltered() throws Exception {
|
||||||
addPackage(PACKAGE_NAME_1, 0, 1, 10, ApplicationInfo.CATEGORY_GAME);
|
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.size()).isEqualTo(1);
|
||||||
assertThat(result.get(PRIMARY_USER_ID).gamesSize).isEqualTo(11L);
|
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
|
@Test
|
||||||
@@ -125,21 +125,21 @@ public class StorageAsyncLoaderTest {
|
|||||||
addPackage(PACKAGE_NAME_1, 0, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED);
|
addPackage(PACKAGE_NAME_1, 0, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED);
|
||||||
info.flags = ApplicationInfo.FLAG_IS_GAME;
|
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.size()).isEqualTo(1);
|
||||||
assertThat(result.get(PRIMARY_USER_ID).gamesSize).isEqualTo(11L);
|
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
|
@Test
|
||||||
public void testCacheIsNotIgnored() throws Exception {
|
public void testCacheIsNotIgnored() throws Exception {
|
||||||
addPackage(PACKAGE_NAME_1, 100, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED);
|
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.size()).isEqualTo(1);
|
||||||
assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(111L);
|
assertThat(result.get(PRIMARY_USER_ID).allAppsExceptGamesSize).isEqualTo(111L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -152,7 +152,7 @@ public class StorageAsyncLoaderTest {
|
|||||||
when(mSource.getExternalStorageStats(anyString(), eq(new UserHandle(SECONDARY_USER_ID))))
|
when(mSource.getExternalStorageStats(anyString(), eq(new UserHandle(SECONDARY_USER_ID))))
|
||||||
.thenReturn(new StorageStatsSource.ExternalStorageStats(10, 3, 3, 4, 0));
|
.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.size()).isEqualTo(2);
|
||||||
assertThat(result.get(PRIMARY_USER_ID).externalStats.totalBytes).isEqualTo(9L);
|
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);
|
addPackage(PACKAGE_NAME_1, 100, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED);
|
||||||
systemApp.flags = ApplicationInfo.FLAG_SYSTEM & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
|
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.size()).isEqualTo(1);
|
||||||
assertThat(result.get(PRIMARY_USER_ID).otherAppsSize).isEqualTo(111L);
|
assertThat(result.get(PRIMARY_USER_ID).allAppsExceptGamesSize).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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -191,44 +180,20 @@ public class StorageAsyncLoaderTest {
|
|||||||
when(mSource.getStatsForPackage(anyString(), anyString(), any(UserHandle.class)))
|
when(mSource.getStatsForPackage(anyString(), anyString(), any(UserHandle.class)))
|
||||||
.thenThrow(new NameNotFoundException());
|
.thenThrow(new NameNotFoundException());
|
||||||
|
|
||||||
SparseArray<StorageAsyncLoader.AppsStorageResult> result = mLoader.loadInBackground();
|
SparseArray<StorageAsyncLoader.StorageResult> result = mLoader.loadInBackground();
|
||||||
|
|
||||||
// Should not crash.
|
// 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
|
@Test
|
||||||
public void testCacheOveragesAreCountedAsFree() throws Exception {
|
public void testCacheOveragesAreCountedAsFree() throws Exception {
|
||||||
addPackage(PACKAGE_NAME_1, DEFAULT_QUOTA + 100, 1, 10, ApplicationInfo.CATEGORY_UNDEFINED);
|
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.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
|
@Test
|
||||||
@@ -237,10 +202,10 @@ public class StorageAsyncLoaderTest {
|
|||||||
addPackage(PACKAGE_NAME_2, 0, 1, 10, ApplicationInfo.CATEGORY_VIDEO);
|
addPackage(PACKAGE_NAME_2, 0, 1, 10, ApplicationInfo.CATEGORY_VIDEO);
|
||||||
addPackage(PACKAGE_NAME_3, 0, 1, 10, ApplicationInfo.CATEGORY_AUDIO);
|
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.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,
|
private ApplicationInfo addPackage(String packageName, long cacheSize, long codeSize,
|
||||||
|
Reference in New Issue
Block a user