Merge "Only show storage category stats preferences for private volumes" into sc-dev
This commit is contained in:
@@ -248,13 +248,15 @@ public class StorageDashboardFragment extends DashboardFragment
|
||||
|
||||
mPreferenceController.setVolume(mSelectedStorageEntry.getVolumeInfo());
|
||||
|
||||
if (mSelectedStorageEntry.isMounted()) {
|
||||
if (mSelectedStorageEntry.isPrivate() && mSelectedStorageEntry.isMounted()) {
|
||||
// Stats data is only available on private volumes.
|
||||
getLoaderManager().restartLoader(STORAGE_JOB_ID, Bundle.EMPTY, this);
|
||||
getLoaderManager()
|
||||
.restartLoader(VOLUME_SIZE_JOB_ID, Bundle.EMPTY, new VolumeSizeCallbacks());
|
||||
getLoaderManager().restartLoader(ICON_JOB_ID, Bundle.EMPTY, new IconLoaderCallbacks());
|
||||
} else {
|
||||
mPreferenceController.clearStorageSizeDisplay();
|
||||
// Set null volume to hide category stats.
|
||||
mPreferenceController.setVolume(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -192,7 +192,27 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
||||
*/
|
||||
public void setVolume(VolumeInfo volume) {
|
||||
mVolume = volume;
|
||||
setFilesPreferenceVisibility();
|
||||
updateCategoryPreferencesVisibility();
|
||||
}
|
||||
|
||||
private void updateCategoryPreferencesVisibility() {
|
||||
// Stats data is only available on private volumes.
|
||||
final boolean isValidVolume = mVolume != null
|
||||
&& mVolume.getType() == VolumeInfo.TYPE_PRIVATE
|
||||
&& (mVolume.getState() == VolumeInfo.STATE_MOUNTED
|
||||
|| mVolume.getState() == VolumeInfo.STATE_MOUNTED_READ_ONLY);
|
||||
|
||||
mPhotoPreference.setVisible(isValidVolume);
|
||||
mAudioPreference.setVisible(isValidVolume);
|
||||
mGamePreference.setVisible(isValidVolume);
|
||||
mMoviesPreference.setVisible(isValidVolume);
|
||||
mAppPreference.setVisible(isValidVolume);
|
||||
mFilePreference.setVisible(isValidVolume);
|
||||
mSystemPreference.setVisible(isValidVolume);
|
||||
|
||||
if (isValidVolume) {
|
||||
setFilesPreferenceVisibility();
|
||||
}
|
||||
}
|
||||
|
||||
private void setFilesPreferenceVisibility() {
|
||||
@@ -251,7 +271,7 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
||||
mSystemPreference = screen.findPreference(SYSTEM_KEY);
|
||||
mFilePreference = screen.findPreference(FILES_KEY);
|
||||
|
||||
setFilesPreferenceVisibility();
|
||||
updateCategoryPreferencesVisibility();
|
||||
}
|
||||
|
||||
public void onLoadFinished(SparseArray<StorageAsyncLoader.AppsStorageResult> result,
|
||||
@@ -296,17 +316,6 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
||||
mTotalSize = totalSizeBytes;
|
||||
}
|
||||
|
||||
/** Set storage size to 0 for each preference. */
|
||||
public void clearStorageSizeDisplay() {
|
||||
mPhotoPreference.setStorageSize(0L, 0L);
|
||||
mAudioPreference.setStorageSize(0L, 0L);
|
||||
mGamePreference.setStorageSize(0L, 0L);
|
||||
mMoviesPreference.setStorageSize(0L, 0L);
|
||||
mAppPreference.setStorageSize(0L, 0L);
|
||||
mFilePreference.setStorageSize(0L, 0L);
|
||||
mSystemPreference.setStorageSize(0L, 0L);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of keys used by this preference controller.
|
||||
*/
|
||||
|
@@ -26,7 +26,6 @@ import com.android.settingslib.deviceinfo.PrivateStorageInfo;
|
||||
import com.android.settingslib.deviceinfo.StorageVolumeProvider;
|
||||
import com.android.settingslib.utils.AsyncLoaderCompat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class VolumeSizesLoader extends AsyncLoaderCompat<PrivateStorageInfo> {
|
||||
@@ -50,11 +49,6 @@ public class VolumeSizesLoader extends AsyncLoaderCompat<PrivateStorageInfo> {
|
||||
|
||||
@Override
|
||||
public PrivateStorageInfo loadInBackground() {
|
||||
if (mVolume == null || (mVolume.getState() != VolumeInfo.STATE_MOUNTED
|
||||
&& mVolume.getState() != VolumeInfo.STATE_MOUNTED_READ_ONLY)) {
|
||||
return new PrivateStorageInfo(0L /* freeBytes */, 0L /* totalBytes */);
|
||||
}
|
||||
|
||||
PrivateStorageInfo volumeSizes;
|
||||
try {
|
||||
volumeSizes = getVolumeSize(mVolumeProvider, mStats, mVolume);
|
||||
@@ -68,14 +62,8 @@ public class VolumeSizesLoader extends AsyncLoaderCompat<PrivateStorageInfo> {
|
||||
static PrivateStorageInfo getVolumeSize(
|
||||
StorageVolumeProvider storageVolumeProvider, StorageStatsManager stats, VolumeInfo info)
|
||||
throws IOException {
|
||||
if (info.getType() == VolumeInfo.TYPE_PRIVATE) {
|
||||
return new PrivateStorageInfo(storageVolumeProvider.getFreeBytes(stats, info),
|
||||
storageVolumeProvider.getTotalBytes(stats, info));
|
||||
}
|
||||
// TODO(b/174964885): It's confusing to use PrivateStorageInfo for a public storage,
|
||||
// replace it with a new naming or a different object.
|
||||
final File rootFile = info.getPath();
|
||||
return rootFile == null ? new PrivateStorageInfo(0L /* freeBytes */, 0L /* totalBytes */)
|
||||
: new PrivateStorageInfo(rootFile.getFreeSpace(), rootFile.getTotalSpace());
|
||||
long privateTotalBytes = storageVolumeProvider.getTotalBytes(stats, info);
|
||||
long privateFreeBytes = storageVolumeProvider.getFreeBytes(stats, info);
|
||||
return new PrivateStorageInfo(privateFreeBytes, privateTotalBytes);
|
||||
}
|
||||
}
|
||||
|
@@ -34,10 +34,8 @@ import org.junit.runner.RunWith;
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class VolumeSizesLoaderTest {
|
||||
@Test
|
||||
public void getVolumeSize_privateMountedVolume_getsValidSizes() throws Exception {
|
||||
public void getVolumeSize_getsValidSizes() throws Exception {
|
||||
VolumeInfo info = mock(VolumeInfo.class);
|
||||
when(info.getType()).thenReturn(VolumeInfo.TYPE_PRIVATE);
|
||||
when(info.getState()).thenReturn(VolumeInfo.STATE_MOUNTED);
|
||||
StorageVolumeProvider storageVolumeProvider = mock(StorageVolumeProvider.class);
|
||||
when(storageVolumeProvider.getTotalBytes(any(), any())).thenReturn(10000L);
|
||||
when(storageVolumeProvider.getFreeBytes(any(), any())).thenReturn(1000L);
|
||||
@@ -48,19 +46,4 @@ public class VolumeSizesLoaderTest {
|
||||
assertThat(storageInfo.freeBytes).isEqualTo(1000L);
|
||||
assertThat(storageInfo.totalBytes).isEqualTo(10000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getVolumeSize_unmountedVolume_getsValidSizes() throws Exception {
|
||||
VolumeInfo info = mock(VolumeInfo.class);
|
||||
when(info.getState()).thenReturn(VolumeInfo.STATE_UNMOUNTED);
|
||||
StorageVolumeProvider storageVolumeProvider = mock(StorageVolumeProvider.class);
|
||||
when(storageVolumeProvider.getTotalBytes(any(), any())).thenReturn(10000L);
|
||||
when(storageVolumeProvider.getFreeBytes(any(), any())).thenReturn(1000L);
|
||||
|
||||
PrivateStorageInfo storageInfo =
|
||||
VolumeSizesLoader.getVolumeSize(storageVolumeProvider, null, info);
|
||||
|
||||
assertThat(storageInfo.freeBytes).isEqualTo(0L);
|
||||
assertThat(storageInfo.totalBytes).isEqualTo(0L);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user