Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4bd401ad authored by Edgar Wang's avatar Edgar Wang
Browse files

Update the API usage to get total size of devices

StorageStatsManager fixed in StorageStatsService#getTotalBytes
So that we should change back to call the API.

Bug: 295358118
Bug: 288103116
Test: verified manually
Change-Id: I3dcc9698403612f961cf0de41925dcbcb43e260b
(cherry picked from commit 2d57d002)
parent 3ec1e1f1
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
@@ -63,7 +63,6 @@ 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;
@@ -1296,14 +1295,4 @@ public final class Utils extends com.android.settingslib.Utils {
        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();
    }

}
+1 −3
Original line number Diff line number Diff line
@@ -211,9 +211,7 @@ public class StorageCategoryFragment extends DashboardFragment

        setLoading(false /* loading */, false /* animate */);

        // TODO(b/288103116): replace with  new API to get TotalBytes before rounding
        //  once support by StorageManager.
        final long privateUsedBytes = Utils.getPrimaryStorageSize() - mStorageInfo.freeBytes;
        final long privateUsedBytes = mStorageInfo.totalBytes - mStorageInfo.freeBytes;
        mPreferenceController.setVolume(mSelectedStorageEntry.getVolumeInfo());
        mPreferenceController.setUsedSize(privateUsedBytes);
        mPreferenceController.setTotalSize(mStorageInfo.totalBytes);
+1 −3
Original line number Diff line number Diff line
@@ -387,9 +387,7 @@ public class StorageDashboardFragment extends DashboardFragment

        setLoading(false /* loading */, false /* animate */);

        // TODO(b/288103116): replace with  new API to get TotalBytes before rounding
        //  once support by StorageManager.
        final long privateUsedBytes = Utils.getPrimaryStorageSize() - mStorageInfo.freeBytes;
        final long privateUsedBytes = mStorageInfo.totalBytes - mStorageInfo.freeBytes;
        mPreferenceController.setVolume(mSelectedStorageEntry.getVolumeInfo());
        mPreferenceController.setUsedSize(privateUsedBytes);
        mPreferenceController.setTotalSize(mStorageInfo.totalBytes);
+1 −3
Original line number Diff line number Diff line
@@ -75,9 +75,7 @@ public class TopLevelStoragePreferenceController extends BasePreferenceControlle
            final PrivateStorageInfo info = PrivateStorageInfo.getPrivateStorageInfo(
                    getStorageManagerVolumeProvider());

            // TODO(b/288103116): replace with  new API to get TotalBytes before rounding
            //  once support by StorageManager.
            long usedBytes = Utils.getPrimaryStorageSize() - info.freeBytes;
            long usedBytes = info.totalBytes - info.freeBytes;
            storageCacheHelper.cacheUsedSize(usedBytes);
            ThreadUtils.postOnMainThread(() -> {
                preference.setSummary(
+1 −4
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;

import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.utils.ThreadUtils;
import com.android.settingslib.widget.UsageProgressBarPreference;
@@ -93,9 +92,7 @@ public class StorageUsageProgressBarPreferenceController extends BasePreferenceC
                if (mStorageEntry.isPrivate()) {
                    // StorageStatsManager can only query private storages.
                    mTotalBytes = mStorageStatsManager.getTotalBytes(mStorageEntry.getFsUuid());
                    // TODO(b/288103116): replace with  new API to get TotalBytes before rounding
                    //  once support by StorageManager.
                    mUsedBytes = Utils.getPrimaryStorageSize()
                    mUsedBytes = mTotalBytes
                            - mStorageStatsManager.getFreeBytes(mStorageEntry.getFsUuid());
                } else {
                    final File rootFile = mStorageEntry.getPath();