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());
|
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(STORAGE_JOB_ID, Bundle.EMPTY, this);
|
||||||
getLoaderManager()
|
getLoaderManager()
|
||||||
.restartLoader(VOLUME_SIZE_JOB_ID, Bundle.EMPTY, new VolumeSizeCallbacks());
|
.restartLoader(VOLUME_SIZE_JOB_ID, Bundle.EMPTY, new VolumeSizeCallbacks());
|
||||||
getLoaderManager().restartLoader(ICON_JOB_ID, Bundle.EMPTY, new IconLoaderCallbacks());
|
getLoaderManager().restartLoader(ICON_JOB_ID, Bundle.EMPTY, new IconLoaderCallbacks());
|
||||||
} else {
|
} 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) {
|
public void setVolume(VolumeInfo volume) {
|
||||||
mVolume = 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() {
|
private void setFilesPreferenceVisibility() {
|
||||||
@@ -251,7 +271,7 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
|||||||
mSystemPreference = screen.findPreference(SYSTEM_KEY);
|
mSystemPreference = screen.findPreference(SYSTEM_KEY);
|
||||||
mFilePreference = screen.findPreference(FILES_KEY);
|
mFilePreference = screen.findPreference(FILES_KEY);
|
||||||
|
|
||||||
setFilesPreferenceVisibility();
|
updateCategoryPreferencesVisibility();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onLoadFinished(SparseArray<StorageAsyncLoader.AppsStorageResult> result,
|
public void onLoadFinished(SparseArray<StorageAsyncLoader.AppsStorageResult> result,
|
||||||
@@ -296,17 +316,6 @@ public class StorageItemPreferenceController extends AbstractPreferenceControlle
|
|||||||
mTotalSize = totalSizeBytes;
|
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.
|
* 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.deviceinfo.StorageVolumeProvider;
|
||||||
import com.android.settingslib.utils.AsyncLoaderCompat;
|
import com.android.settingslib.utils.AsyncLoaderCompat;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class VolumeSizesLoader extends AsyncLoaderCompat<PrivateStorageInfo> {
|
public class VolumeSizesLoader extends AsyncLoaderCompat<PrivateStorageInfo> {
|
||||||
@@ -50,11 +49,6 @@ public class VolumeSizesLoader extends AsyncLoaderCompat<PrivateStorageInfo> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PrivateStorageInfo loadInBackground() {
|
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;
|
PrivateStorageInfo volumeSizes;
|
||||||
try {
|
try {
|
||||||
volumeSizes = getVolumeSize(mVolumeProvider, mStats, mVolume);
|
volumeSizes = getVolumeSize(mVolumeProvider, mStats, mVolume);
|
||||||
@@ -68,14 +62,8 @@ public class VolumeSizesLoader extends AsyncLoaderCompat<PrivateStorageInfo> {
|
|||||||
static PrivateStorageInfo getVolumeSize(
|
static PrivateStorageInfo getVolumeSize(
|
||||||
StorageVolumeProvider storageVolumeProvider, StorageStatsManager stats, VolumeInfo info)
|
StorageVolumeProvider storageVolumeProvider, StorageStatsManager stats, VolumeInfo info)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (info.getType() == VolumeInfo.TYPE_PRIVATE) {
|
long privateTotalBytes = storageVolumeProvider.getTotalBytes(stats, info);
|
||||||
return new PrivateStorageInfo(storageVolumeProvider.getFreeBytes(stats, info),
|
long privateFreeBytes = storageVolumeProvider.getFreeBytes(stats, info);
|
||||||
storageVolumeProvider.getTotalBytes(stats, info));
|
return new PrivateStorageInfo(privateFreeBytes, privateTotalBytes);
|
||||||
}
|
|
||||||
// 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());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -34,10 +34,8 @@ import org.junit.runner.RunWith;
|
|||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class VolumeSizesLoaderTest {
|
public class VolumeSizesLoaderTest {
|
||||||
@Test
|
@Test
|
||||||
public void getVolumeSize_privateMountedVolume_getsValidSizes() throws Exception {
|
public void getVolumeSize_getsValidSizes() throws Exception {
|
||||||
VolumeInfo info = mock(VolumeInfo.class);
|
VolumeInfo info = mock(VolumeInfo.class);
|
||||||
when(info.getType()).thenReturn(VolumeInfo.TYPE_PRIVATE);
|
|
||||||
when(info.getState()).thenReturn(VolumeInfo.STATE_MOUNTED);
|
|
||||||
StorageVolumeProvider storageVolumeProvider = mock(StorageVolumeProvider.class);
|
StorageVolumeProvider storageVolumeProvider = mock(StorageVolumeProvider.class);
|
||||||
when(storageVolumeProvider.getTotalBytes(any(), any())).thenReturn(10000L);
|
when(storageVolumeProvider.getTotalBytes(any(), any())).thenReturn(10000L);
|
||||||
when(storageVolumeProvider.getFreeBytes(any(), any())).thenReturn(1000L);
|
when(storageVolumeProvider.getFreeBytes(any(), any())).thenReturn(1000L);
|
||||||
@@ -48,19 +46,4 @@ public class VolumeSizesLoaderTest {
|
|||||||
assertThat(storageInfo.freeBytes).isEqualTo(1000L);
|
assertThat(storageInfo.freeBytes).isEqualTo(1000L);
|
||||||
assertThat(storageInfo.totalBytes).isEqualTo(10000L);
|
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