Move private volume storage calculations into a shared lib.
Bug: 30895163 Test: m RunStorageManagerRoboTests Change-Id: I3e464c8b721373ebc1527eb5411622c69bf587d1
This commit is contained in:
@@ -53,6 +53,8 @@ import com.android.settings.search.BaseSearchIndexProvider;
|
|||||||
import com.android.settings.search.Indexable;
|
import com.android.settings.search.Indexable;
|
||||||
import com.android.settings.search.SearchIndexableRaw;
|
import com.android.settings.search.SearchIndexableRaw;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
|
import com.android.settingslib.deviceinfo.PrivateStorageInfo;
|
||||||
|
import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
|
||||||
import com.android.settingslib.drawer.SettingsDrawerActivity;
|
import com.android.settingslib.drawer.SettingsDrawerActivity;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -167,7 +169,8 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
|
|||||||
|
|
||||||
for (VolumeInfo vol : volumes) {
|
for (VolumeInfo vol : volumes) {
|
||||||
if (vol.getType() == VolumeInfo.TYPE_PRIVATE) {
|
if (vol.getType() == VolumeInfo.TYPE_PRIVATE) {
|
||||||
final long volumeTotalBytes = getTotalSize(vol);
|
final long volumeTotalBytes = PrivateStorageInfo.getTotalSize(vol,
|
||||||
|
sTotalInternalStorage);
|
||||||
final int color = COLOR_PRIVATE[privateCount++ % COLOR_PRIVATE.length];
|
final int color = COLOR_PRIVATE[privateCount++ % COLOR_PRIVATE.length];
|
||||||
mInternalCategory.addPreference(
|
mInternalCategory.addPreference(
|
||||||
new StorageVolumePreference(context, vol, color, volumeTotalBytes));
|
new StorageVolumePreference(context, vol, color, volumeTotalBytes));
|
||||||
@@ -276,7 +279,8 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
|
|||||||
if (vol.getType() == VolumeInfo.TYPE_PRIVATE) {
|
if (vol.getType() == VolumeInfo.TYPE_PRIVATE) {
|
||||||
final Bundle args = new Bundle();
|
final Bundle args = new Bundle();
|
||||||
args.putString(VolumeInfo.EXTRA_VOLUME_ID, vol.getId());
|
args.putString(VolumeInfo.EXTRA_VOLUME_ID, vol.getId());
|
||||||
PrivateVolumeSettings.setVolumeSize(args, getTotalSize(vol));
|
PrivateVolumeSettings.setVolumeSize(args, PrivateStorageInfo.getTotalSize(vol,
|
||||||
|
sTotalInternalStorage));
|
||||||
startFragment(this, PrivateVolumeSettings.class.getCanonicalName(),
|
startFragment(this, PrivateVolumeSettings.class.getCanonicalName(),
|
||||||
-1, 0, args);
|
-1, 0, args);
|
||||||
return true;
|
return true;
|
||||||
@@ -506,47 +510,15 @@ public class StorageSettings extends SettingsPreferenceFragment implements Index
|
|||||||
private void updateSummary() {
|
private void updateSummary() {
|
||||||
// TODO: Register listener.
|
// TODO: Register listener.
|
||||||
final StorageManager storageManager = mContext.getSystemService(StorageManager.class);
|
final StorageManager storageManager = mContext.getSystemService(StorageManager.class);
|
||||||
if (sTotalInternalStorage <= 0) {
|
PrivateStorageInfo info = PrivateStorageInfo.getPrivateStorageInfo(
|
||||||
sTotalInternalStorage = storageManager.getPrimaryStorageSize();
|
new StorageManagerVolumeProvider(storageManager));
|
||||||
}
|
long privateUsedBytes = info.totalBytes - info.freeBytes;
|
||||||
final List<VolumeInfo> volumes = storageManager.getVolumes();
|
|
||||||
long privateFreeBytes = 0;
|
|
||||||
long privateTotalBytes = 0;
|
|
||||||
for (VolumeInfo info : volumes) {
|
|
||||||
final File path = info.getPath();
|
|
||||||
if (info.getType() != VolumeInfo.TYPE_PRIVATE || path == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
privateTotalBytes += getTotalSize(info);
|
|
||||||
privateFreeBytes += path.getFreeSpace();
|
|
||||||
}
|
|
||||||
long privateUsedBytes = privateTotalBytes - privateFreeBytes;
|
|
||||||
mLoader.setSummary(this, mContext.getString(R.string.storage_summary,
|
mLoader.setSummary(this, mContext.getString(R.string.storage_summary,
|
||||||
Formatter.formatFileSize(mContext, privateUsedBytes),
|
Formatter.formatFileSize(mContext, privateUsedBytes),
|
||||||
Formatter.formatFileSize(mContext, privateTotalBytes)));
|
Formatter.formatFileSize(mContext, info.totalBytes)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static long getTotalSize(VolumeInfo info) {
|
|
||||||
// Device could have more than one primary storage, which could be located in the
|
|
||||||
// internal flash (UUID_PRIVATE_INTERNAL) or in an external disk.
|
|
||||||
// If it's internal, try to get its total size from StorageManager first
|
|
||||||
// (sTotalInternalStorage), since that size is more precise because it accounts for
|
|
||||||
// the system partition.
|
|
||||||
if (info.getType() == VolumeInfo.TYPE_PRIVATE
|
|
||||||
&& Objects.equals(info.getFsUuid(), StorageManager.UUID_PRIVATE_INTERNAL)
|
|
||||||
&& sTotalInternalStorage > 0) {
|
|
||||||
return sTotalInternalStorage;
|
|
||||||
} else {
|
|
||||||
final File path = info.getPath();
|
|
||||||
if (path == null) {
|
|
||||||
// Should not happen, caller should have checked.
|
|
||||||
Log.e(TAG, "info's path is null on getTotalSize(): " + info);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return path.getTotalSpace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
|
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
|
||||||
= new SummaryLoader.SummaryProviderFactory() {
|
= new SummaryLoader.SummaryProviderFactory() {
|
||||||
|
Reference in New Issue
Block a user