Correct used size of Storage Settings.

Since StorageManager rounded the totalBytes of device storage but
they don't do that rounding for freeBytes.
So in some cases the freeBytes can be greater than totalBytes.

We propose to get totalBytes of device storage directly to calculate
correct privateUsedBytes.

Test: robotest
Bug: 281955532
Change-Id: I4f137c20e7c2f54f4e037d50e81b3176edc1a83a
This commit is contained in:
Edgar Wang
2023-05-31 18:42:11 +08:00
parent 0df79b1ccc
commit e52320e755
5 changed files with 28 additions and 6 deletions

View File

@@ -63,6 +63,7 @@ import android.os.BatteryManager;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.IBinder;
import android.os.INetworkManagementService;
import android.os.RemoteException;
@@ -97,7 +98,6 @@ import android.widget.TabWidget;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.annotation.VisibleForTesting;
import androidx.core.graphics.drawable.IconCompat;
import androidx.core.graphics.drawable.RoundedBitmapDrawable;
@@ -1309,4 +1309,15 @@ public final class Utils extends com.android.settingslib.Utils {
com.android.internal.R.bool.config_dreamsOnlyEnabledForDockUser);
return dreamsSupported && (!dreamsOnlyEnabledForDockUser || canCurrentUserDream(context));
}
/**
* Get private total size directly.
* Referred from StorageManager
*/
public static long getPrimaryStorageSize() {
// TODO(b/288103116): remove this method once support by StorageManager.
return Environment.getDataDirectory().getTotalSpace()
+ Environment.getRootDirectory().getTotalSpace();
}
}