Change how we calculate system size.

As per storage discussions, the best way to calculate storage for the
System is to just take all known data and subtract it from the used
bytes. There is more to the system than just the /system partition and,
even if we ignore the partitions and use the underlying block device
method of calculating it, we run into the problem of it not adding up to
the actual device size.

Change-Id: I6e1f775ea3f3b8b2cc78d734623934651e2fb7b4
Fixes: 37166310
Test: Robotests
This commit is contained in:
Daniel Nishi
2017-04-17 17:25:06 -07:00
parent d4ce883c64
commit 0cd1f73b21
3 changed files with 25 additions and 23 deletions

View File

@@ -19,7 +19,6 @@ package com.android.settings.deviceinfo;
import android.app.Activity;
import android.app.LoaderManager;
import android.content.Context;
import android.content.Intent;
import android.content.Loader;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@@ -29,16 +28,11 @@ import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.provider.SearchIndexableResource;
import android.support.annotation.VisibleForTesting;
import android.util.Log;
import android.util.SparseArray;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.applications.PackageManagerWrapper;
import com.android.settings.applications.PackageManagerWrapperImpl;
import com.android.settings.applications.UserManagerWrapper;
import com.android.settings.applications.UserManagerWrapperImpl;
@@ -58,7 +52,6 @@ import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
public class StorageDashboardFragment extends DashboardFragment
implements LoaderManager.LoaderCallbacks<SparseArray<StorageAsyncLoader.AppsStorageResult>> {
@@ -101,8 +94,7 @@ public class StorageDashboardFragment extends DashboardFragment
final long usedBytes = totalSize - mVolume.getPath().getFreeSpace();
mSummaryController.updateBytes(usedBytes, totalSize);
mPreferenceController.setVolume(mVolume);
mPreferenceController.setSystemSize(systemSize);
mPreferenceController.setUsedSize(usedBytes);
mPreferenceController.setTotalSize(totalSize);
for (int i = 0, size = mSecondaryUsers.size(); i < size; i++) {
PreferenceController controller = mSecondaryUsers.get(i);

View File

@@ -78,7 +78,7 @@ public class StorageItemPreferenceController extends PreferenceController {
private final StorageVolumeProvider mSvp;
private VolumeInfo mVolume;
private int mUserId;
private long mSystemSize;
private long mUsedBytes;
private long mTotalSize;
private StorageItemPreference mPhotoPreference;
@@ -226,17 +226,29 @@ public class StorageItemPreferenceController extends PreferenceController {
mGamePreference.setStorageSize(data.gamesSize, mTotalSize);
mMoviesPreference.setStorageSize(data.videoAppsSize, mTotalSize);
mAppPreference.setStorageSize(data.otherAppsSize, mTotalSize);
long unattributedExternalBytes =
data.externalStats.totalBytes
- data.externalStats.audioBytes
- data.externalStats.videoBytes
- data.externalStats.imageBytes;
mFilePreference.setStorageSize(unattributedExternalBytes, mTotalSize);
// We define the system size as everything we can't classify.
if (mSystemPreference != null) {
mSystemPreference.setStorageSize(mSystemSize + data.systemSize, mTotalSize);
mSystemPreference.setStorageSize(
mUsedBytes
- data.externalStats.totalBytes
- data.musicAppsSize
- data.gamesSize
- data.videoAppsSize
- data.otherAppsSize,
mTotalSize);
}
}
long unattributedBytes = data.externalStats.totalBytes - data.externalStats.audioBytes
- data.externalStats.videoBytes - data.externalStats.imageBytes;
mFilePreference.setStorageSize(unattributedBytes, mTotalSize);
}
public void setSystemSize(long systemSizeBytes) {
mSystemSize = systemSizeBytes;
public void setUsedSize(long usedSizeBytes) {
mUsedBytes = usedSizeBytes;
}
public void setTotalSize(long totalSizeBytes) {

View File

@@ -242,21 +242,19 @@ public class StorageItemPreferenceControllerTest {
eq(StorageItemPreferenceController.FILES_KEY))).thenReturn(files);
mController.displayPreference(screen);
mController.setSystemSize(KILOBYTE * 6);
mController.setUsedSize(KILOBYTE * 200); // There should 87kB attributed.
StorageAsyncLoader.AppsStorageResult result = new StorageAsyncLoader.AppsStorageResult();
result.gamesSize = KILOBYTE * 8;
result.videoAppsSize = KILOBYTE * 16;
result.musicAppsSize = KILOBYTE * 4;
result.otherAppsSize = KILOBYTE * 9;
result.systemSize = KILOBYTE * 10;
result.systemSize = KILOBYTE * 10; // This value is ignored and overriden now.
result.externalStats = new StorageStatsSource.ExternalStorageStats(
KILOBYTE * 50, // total
KILOBYTE * 10, // audio
KILOBYTE * 15, // video
KILOBYTE * 20); // image
result.gamesSize = KILOBYTE * 8;
result.otherAppsSize = KILOBYTE * 9;
mController.onLoadFinished(result);
assertThat(audio.getSummary().toString()).isEqualTo("14.00KB"); // 4KB apps + 10KB files
@@ -264,7 +262,7 @@ public class StorageItemPreferenceControllerTest {
assertThat(games.getSummary().toString()).isEqualTo("8.00KB");
assertThat(movies.getSummary().toString()).isEqualTo("16.00KB");
assertThat(apps.getSummary().toString()).isEqualTo("9.00KB");
assertThat(system.getSummary().toString()).isEqualTo("16.00KB");
assertThat(system.getSummary().toString()).isEqualTo("113KB");
assertThat(files.getSummary().toString()).isEqualTo("5.00KB");
}